public class Line
extends javax.swing.JPanel
Modifier and Type | Class and Description |
---|---|
static class |
Line.ColorPolicy
The different ways to draw the edges of the graph.
|
Modifier and Type | Field and Description |
---|---|
static java.awt.Color |
DEFAULT_COLOR
Default color of lines when they are drawn on the GUI
|
static java.awt.Color |
GRADIENT_LONG_COLOR
Color of the lines representing the longest edges, if DISTANCE_GRADIENT is selected
|
static java.awt.Color |
GRADIENT_SHORT_COLOR
Color of the lines representing the shortest edges, if DISTANCE_GRADIENT is selected
|
static int |
LINE_THICKNESS
Default thickness of lines when they are drawn on the GUI
|
static int |
ON_LINE_TOLERANCE
Number of pixels of tolerance for a point to be considered on the line
|
static java.awt.Color |
TRAVELING_COLOR
Color of lines when they are being traveled by a truck, if HIGHLIGHT_TRAVEL is selected
|
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
Line(Circle c1,
Circle c2,
BoardElement r)
Constructor: a line from c1 to c2 representing r and colored according
to the color policy.
|
Modifier and Type | Method and Description |
---|---|
double |
distanceTo(java.awt.Point p)
Return the distance from p to this line.
|
void |
fixBounds()
Dynamically resize the drawing boundaries of this line based on the
height and width of the line, with a minimum sized box of (40,40).
|
Circle |
getC1()
Return the first end of this line.
|
Circle |
getC2()
Return the second end of this line.
|
java.awt.Color |
getColor()
Return the current color of this line, which is determined by the color policy.
|
static Line.ColorPolicy |
getColorPolicy()
Return the color policy for painting roads.
|
int |
getLineHeight()
Return the height (y diff) of the line.
|
int |
getLineWidth()
Return the width (x diff) of the line.
|
java.awt.Point |
getMid()
Return the midpoint of this line.
|
java.awt.Dimension |
getPreferredSize()
Return the size of the line, as a rectangular bounding box (x2 - x1, y2 - y1).
|
int |
getX1()
Return the x coordinate of the first end of this line.
|
int |
getX2()
Return the x coordinate of the second end of this line.
|
int |
getXMid()
Return the x value of the midpoint of this line.
|
int |
getY1()
Return the y coordinate of the first end of this line.
|
int |
getY2()
Return the y coordinate of the second end of this line.
|
int |
getYMid()
Return the y value of the midpoint of this line.
|
boolean |
intersects(Line l)
Return true iff l intersects this line.
|
boolean |
isOnLine(java.awt.Point p)
Return true iff Point p is within ON_LINE_TOLERANCE pixels of this line.
|
void |
paintComponent(java.awt.Graphics g)
Paint this line
|
double |
radAngle(Line l)
Return the angle between this line and line l, in radians.
|
static void |
setColorPolicy(Line.ColorPolicy policy)
Set the colorPolicy to policy.
|
java.lang.String |
toString()
Return a String representation of this line
|
void |
updateToColorPolicy()
Update the Color of this Line according to the currently selected color policy.
|
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
public static final int LINE_THICKNESS
public static final java.awt.Color DEFAULT_COLOR
public static final java.awt.Color TRAVELING_COLOR
public static final java.awt.Color GRADIENT_SHORT_COLOR
public static final java.awt.Color GRADIENT_LONG_COLOR
public static final int ON_LINE_TOLERANCE
public Line(Circle c1, Circle c2, BoardElement r)
c1
- - the Circle that marks the first end of this linec2
- - the Circle that marks the second end of this liner
- - the MapElement this Line represents when drawn on the GUIpublic Circle getC1()
public Circle getC2()
public int getX1()
public int getY1()
public int getX2()
public int getY2()
public java.awt.Point getMid()
public int getXMid()
public int getYMid()
public int getLineWidth()
public int getLineHeight()
public void fixBounds()
public java.awt.Color getColor()
public void updateToColorPolicy()
public static Line.ColorPolicy getColorPolicy()
Line.ColorPolicy
public static void setColorPolicy(Line.ColorPolicy policy)
Line.ColorPolicy
public boolean isOnLine(java.awt.Point p)
public double distanceTo(java.awt.Point p)
public double radAngle(Line l) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public boolean intersects(Line l)
public java.lang.String toString()
toString
in class java.awt.Component
public void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
public java.awt.Dimension getPreferredSize()
getPreferredSize
in class javax.swing.JComponent