|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
verinec.gui.core.DrawPanel
public class DrawPanel
This panel holds all the nodes, hubs, interfaces etc of the configuration. The main work of the panel itself (i.e. programmed in this class) is to listen to events and to perform corresponding actions. For achieving these functionalities, a lot of communictation between nodes and this panel is required.
A note on moving the nodes using the mouse:
| Nested Class Summary | |
|---|---|
(package private) class |
DrawPanel.ViewConfig
Configuration panel for the drawing options. |
| Nested classes/interfaces inherited from class javax.swing.JPanel |
|---|
JPanel.AccessibleJPanel |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
private static Dimension |
canvasSize
The canvas size. |
private static String |
configName
Name of the configuration data within the VerinecStudio.saveConfig(String, Document) method. |
static int |
CREATE
Show preview rectangle where the node would be placed if you press the button. |
private int |
dragEndX
Coordinate where we did drag to until now NOTHING: undefined CREATE, SELECT, WIRE: relative to the DrawPanel MOVE: relative to the center of node where the drag click was on |
private int |
dragEndY
Coordinate where we did drag to until now NOTHING: undefined CREATE, SELECT, WIRE: relative to the DrawPanel MOVE: relative to the center of node where the drag click was on |
private int |
dragLastEndX
Helper variable for repainting: old value of dragEndX. |
private int |
dragLastEndY
Helper variable for repainting: old value of dragEndY. |
private int |
dragStartX
Coordinate where dragging started. |
private int |
dragStartY
Coordinate where dragging started. |
private int |
editState
Current state (one of the above). |
private VerinecStudio |
gui
The main application class. |
static int |
MOVE
Draw an outline of the new position for every node and interface when moving some nodes. |
private static Color |
networkBackground
Background color for the network windows. |
static int |
NOTHING
Do not draw any outline. |
private int |
scaledSnapRaster
Scaled snap raster width. |
static int |
SELECT
Draw a blue selection rectangle to show what will be selected in multiple selection. |
private boolean |
showNodeNames
Whether node names must be displayed. |
private int |
snapRaster
Constant for the snap to grid coordinates. |
private boolean |
snapToGrid
Whether nodes moved should snap to grid. |
private StandardToolbar |
stdToolbar
The toolbar instance. |
static int |
WIRE
Draw an outline of the wire. |
private float |
zoomFactor
The current zoom factor. |
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
DrawPanel(VerinecStudio gui,
StandardToolbar stdToolbar)
Initializes the panel, registers several listeners. |
|
| Method Summary | |
|---|---|
int |
deleteSelectedNodes()
Deletes all selected Nodes in the panel. |
private void |
drawPreview(Graphics g,
NwComponent c)
Draw a preview rectangle for a component when dragging nodes. |
void |
focusSelectedNode()
Give focus to a selected node. |
NwBinding |
getBinding(String id)
Return a reference to the binding identified by the id. |
ConfigPanel |
getConfigPanel()
Return a config panel, as in IVerinecModule. |
int |
getEditState()
Get the current outline state. |
PCNode |
getPCNode(String name)
Get a node by name which is visible on the panel. |
private Document |
getSavedConfig()
Load stored configuration or create default if none found. |
int |
getScaledSnapRaster()
Get the snap raster width in pixels, adjusted to current scaling. |
int |
getSnappedCoordinate(int c)
Rounds the coordinate to the nearest snap point. |
float |
getZoomFactor()
Get the current zoom factor. |
private void |
initConfig(Document config)
Initialise configuration from config element. |
void |
initialize()
(Re)set the panel to its initial state. |
void |
invertNodeSelection()
Unselect all selected nodes and select all unselected ones. |
boolean |
isSnapToGrid()
Return whether nodes should snap to grid. |
void |
mouseClicked(MouseEvent e)
Empty procedure, only added because the listener needs it. |
private void |
mouseCreateMove(MouseEvent e)
Execute moving of the preview square. |
void |
mouseDragged(MouseEvent e)
Performs one of the following action, according to the type of dragging: if a Node is dragged, update the dragging position if the user draws a selection rectangle, save new coordinates |
void |
mouseEntered(MouseEvent e)
Repaint the view, just in case. |
void |
mouseExited(MouseEvent e)
Repaint the view, just in case |
void |
mouseMoved(MouseEvent e)
If we are in create mode - Save Coordinates into variables - repaint the Component to draw the new node outline |
void |
mousePressed(MouseEvent e)
Right click deselects all selected nodes. |
void |
mouseReleased(MouseEvent e)
Performs one of the following action according to the type of release. |
void |
moveSelectedNodes(int x,
int y)
Move all selected nodes in the panel. |
void |
paint(Graphics g)
Adjust the paint method to call paintOverlays after painting of the rest. |
void |
paintComponent(Graphics g)
Draws the wires. |
void |
paintOverlays(Graphics g)
Paint selection rectangle or placement preview. |
void |
saveConfiguration(Document config)
Save the config and update values from xml. |
void |
selectAllNodes()
Select all nodes. |
void |
setEditState(int s)
Set the current state for the panel. |
void |
setShowNames(boolean show)
Hides or shows the node name display. |
void |
setSnapToGrid(boolean snap)
Enables or disables snap to grid behaviour when moving nodes. |
void |
setZoomFactor(float factor)
Set the new zoom factor to apply. |
void |
unselectAllComponents()
Sets the selection property of every NwComponent to false |
| Methods inherited from class javax.swing.JPanel |
|---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int NOTHING
public static final int CREATE
public static final int SELECT
public static final int MOVE
public static final int WIRE
private int editState
private static final String configName
VerinecStudio.saveConfig(String, Document) method.
private static final Dimension canvasSize
private static Color networkBackground
private int dragStartX
private int dragStartY
private int dragEndX
private int dragEndY
private int dragLastEndX
private int dragLastEndY
private int snapRaster
private int scaledSnapRaster
private boolean snapToGrid
private boolean showNodeNames
private float zoomFactor
private VerinecStudio gui
private StandardToolbar stdToolbar
| Constructor Detail |
|---|
public DrawPanel(VerinecStudio gui,
StandardToolbar stdToolbar)
throws VerinecException
gui - The main application.stdToolbar - The toolbar instance to update zoom etc.
VerinecException - If no saved configuration and no default can be found.| Method Detail |
|---|
public void initialize()
private Document getSavedConfig()
throws VerinecException
VerinecException - if configuration can not be loaded (inexisting or invalid).
private void initConfig(Document config)
throws VerinecException
config - XML document containing the new configuration.
VerinecException - if the configuration parameter is incomplete.public PCNode getPCNode(String name)
name - The name of the node to retreive.
public NwBinding getBinding(String id)
id - The id of the desired binding.
public void selectAllNodes()
public void invertNodeSelection()
public void unselectAllComponents()
public void focusSelectedNode()
public int deleteSelectedNodes()
public void moveSelectedNodes(int x,
int y)
VerinecStudio.isModifyAllowed() is false, will do nothing.
x - Amount to move in direction of x.y - Amount to move in direction of y.public void setZoomFactor(float factor)
factor - The zoom factor.public float getZoomFactor()
1 is no zoom, 2 is zoom 200%, 0.5 is zoom 50% ecc...
public int getScaledSnapRaster()
public void setEditState(int s)
s - The new outline state.public int getEditState()
setEditState(int)public void setShowNames(boolean show)
show - True if names should be shown, false otherwise.public void setSnapToGrid(boolean snap)
snap - Enables snap to grid if true, disables if false.public boolean isSnapToGrid()
public int getSnappedCoordinate(int c)
c - The coordinate
public ConfigPanel getConfigPanel()
throws VerinecException
getConfigPanel in interface IConfigurableVerinecException - If the configuration xml can not be found and no default is available.public void saveConfiguration(Document config)
initConfig(Document) internally as does the constructor.
saveConfiguration in interface IConfigurableconfig - The new configuration.public void paint(Graphics g)
paint in class JComponentg - The graphics object to draw on.public void paintComponent(Graphics g)
paintComponent in class JComponentg - The graphics object to draw on.public void paintOverlays(Graphics g)
g - The graphics object to draw on.
private void drawPreview(Graphics g,
NwComponent c)
g - The graphics object to paint on.c - The component to get the coordinates from.public void mousePressed(MouseEvent e)
mousePressed in interface MouseListenere - The mouse click event.public void mouseReleased(MouseEvent e)
mouseReleased in interface MouseListenere - The mouse event.public void mouseDragged(MouseEvent e)
mouseDragged in interface MouseMotionListenere - The event.public void mouseMoved(MouseEvent e)
mouseMoved in interface MouseMotionListenere - The event.private void mouseCreateMove(MouseEvent e)
e - The mouse event.public void mouseClicked(MouseEvent e)
mouseClicked in interface MouseListenere - The event.public void mouseExited(MouseEvent e)
mouseExited in interface MouseListenere - The event.public void mouseEntered(MouseEvent e)
mouseEntered in interface MouseListenere - The event.
|
Copyright © 2005 Verinec, DIUF | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||