Java Drawing DrawTop

Language

JP  US  UK

 

Information Dialog

 H. Jyounishi, Tokyo Japan
 

Frame (Index), No frame                 version:0.3(latest)  

Summary: This page describes the method to show the shape format dialog.
Classes on this page: DialogOfShapeFormat, ShapeFormatListener, SpinnersChangeListener, ShapeFormatAction, DialogOfDrawPanel, DialogOfDrawPanelListener, DialogOfDrawPanelAction

1. Shape format dialog
Select the "shape format" item from the popup menu, then the following dialog will be displayed.
See=> The type of the popup menu, User's Guide: property tab

Figure 1.1 (a) The position, size tab for a line

Figure 1.1 (b) The position, size tab for other shape



Figure 1.2(a) Specify line type, color and so on

Figure 1.2 (b) Pull down menue of the line stroke button


Figure 1.3 The property tab

Figure 1.4 The data tab


Figure 1.5 The text box tab

Figure 1.6 The text tab

Figure 1. Shape format dialog



1.1 Class DialogOfShapeFormat return=>page top

public class DialogOfShapeFormat extends JDialog


Field

Description

action

ShapeFormatAction action

The ActionListener object (ShapeFormatAction)

dataScrollPane

JScrollPane dataScrollPane

The ScrollPane in the data tab (Figure 1.4).

textScrollPane

JScrollPane textScrollPane

The ScrollPane in the text info tab (Figure 1.6).

shapeContainer

ShapeContainer shapeContainer

The ShapeContainer object which is specified by the parameter of the showDialog method.

pixelButton

JRadioButton pixelButton

The button to set the unit of length in pixels in the position, size tab (Figure 1.1).

mmButton

JRadioButton mmButton

The button to set the unit of length in millimeters in the position, size tab (Figure 1.1).

unresizableBox

JCheckBox unresizableBox

The check box to set "unresizable" property (Figure 1.3).

ratioBox

JCheckBox ratioBox

The check box to set "keep aspect ratio" property (Figure 1.3).

directionBox

JCheckBox directionBox

The check box to set "keep line direction" property (Figure 1.3).

unableConnectorBox

JCheckBox unableConnectorBox

The check box to set "unable to drag connectors" property (Figure 1.3).

ungroupBox

JCheckBox ungroupBox

The check box to set "unable ungrouping" property (Figure 1.3).

dialogDimension

Dimension dialogDimension=new Dimension(400,330);

The initial size of the dialog.

buttonSize

Dimension buttonSize=new Dimension(80,22)

positionSpinners

JSpinner[] positionSpinners=new JSpinner[4]

The x-min, x-max, y-min and y-max Spinners (Figure 1.1 (b)).

positionSpinnerModels

SpinnerNumberModel[] positionSpinnerModels=new SpinnerNumberModel[4]

The x-min, x-max, y-min and y-max SpinnerModels.

centerSpinners

JSpinner[] centerSpinners=new JSpinner[2];

The center point Spinners (Figure 1.1 (b)).

centerSpinnerModels

SpinnerNumberModel[] centerSpinnerModels=new SpinnerNumberModel[2];

The center point SpinnerModels.

sizeSpinners

JSpinner[] sizeSpinners=new JSpinner[2]

The width and height Spinners (Figure 1.1 (b)).

sizeSpinnerModels

SpinnerNumberModel[] sizeSpinnerModels=new SpinnerNumberModel[2]

The width and height SpinnerModels.

startSpinners

JSpinner[] startSpinners=new JSpinner[2]

The start point Spinners (Figure 1.1 (a)).

startSpinnerModels

SpinnerNumberModel[] startSpinnerModels=new SpinnerNumberModel[2]

The start point SpinnerModels.

endSpinners

JSpinner[] endSpinners=new JSpinner[2]

The end point Spinners (Figure 1.1 (a)).

endSpinnerModels SpinnerNumberModel[] endSpinnerModels=new SpinnerNumberModel[2]
The end point SpinnerModels.
lineSpinners

JSpinner[] lineSpinners=new JSpinner[2]

The angle and length Spinners (Figure 1.1 (a)).

lineSpinnerModels SpinnerNumberModel[] lineSpinnerModels=new SpinnerNumberModel[2]
The angle and length SpinnerModels.

marginSpinners

JSpinner[] marginSpinners=new JSpinner[4]

The margin Spinners inside the text box (Figure 1.5).

marginSpinnerModels

SpinnerNumberModel[] marginSpinnerModels=new SpinnerNumberModel[4]

The margin SpinnerModels inside the text box.

lineSpaceSpinner

JSpinner lineSpaceSpinner=null

The line space Spinner in the text box (Figure 1.5).

lineSpaceSpinnerModel

SpinnerNumberModel lineSpaceSpinnerModel=null

The line space SpinnerModel in the text box.


Method

Description

Constructor

public DialogOfShapeFormat()

Sets the following.

super(ObjectTable.getDrawMain(), "Shape Format");
this.setName("DialogOfShapeFormat");
this.action=new ShapeFormatAction(this);
this.addWindowListener(action);

showDialog

public void showDialog(ShapeContainer container)

Paremeters:

container - The ShapeContainer object whose information is shown in the dialog.

Processing:

∙ Set the container parameter to the shapeContainer.

∙ Adds the ShapeFormatListener object to this dialog.

∙ Calculates the dialog position on the canvas.

Determines the dialog position based on the rectangle enclosing the shapeContainer.

∙ Creates the JTabbedPane and adds the seven panels to the JTabbedPane.

The seven panels are created by the createLinePanel, createRectangularPanel, createPaintStylePanel, createPropertyPanel, createDataPanel, createTextBoxPanel and createTextInfoPanel methods.

If the shapeContainer is a line, set the panel of the createLinePanel to the "position, size" tab, otherwise set the panel of the createRectangularPanel to the "position, size" tab.

∙ Calls setVisible method for this object to show the dialog.

∙ If other DialogOfShapeFormat object is shown on the screen, removes it from the screen by the removeDialog method.

removeDialog protected void removeDialog()
Sets invisible to this object by the setVisible(false)
and removes this dialog from the menuComponentList by the removeMenuComponent of the menuUtil.
setScrollViewPosition

protected void setScrollViewPosition()

Sets the view position to the dataScrollPane and the textScrollPane.

this.dataScrollPane.getViewport().setViewPosition(new Point(0,0));
if(this.textScrollPane!=null) this.textScrollPane.getViewport().setViewPosition(new Point(0,0));

: Calls this method in the componentShown method of the ShapeFormatListener.

createRectangularPanel

private JPanel createRectangularPanel()

Processing:

Creates the panel (Figure 1.1 (b)) to be added to the JTabbedPane.
Calls the showRectangular method to sets the values to the spinners.

showRectangular protected void showRectangular(int unitOfLength)

Parameters:

unitOfLength - 0: pixels, 1: milimeters

Processing:

∙ Sets values to the positionSpinners, centerSpinners and sizeSpinners.

∙ If the "unresizable" property is true, disable the sizeSpinners.

createLinePanel

private JPanel createLinePanel()

Processing:

Creates the panel (Figure 1.1 (a)) to be added to the JTabbedPane.
Calls the showLine method to sets the values to the spinners.

showLine protected void showLine(int unitOfLength)

Parameters:

unitOfLength - 0: pixels, 1: milimeters

Processing:

∙ Sets values to the startSpinners, endSpinners and lineSpinners.

∙ If the "unresizable" property is true, disable the lineSpinners.
∙ If the "keep line direction" property is true, disable the lineSpinners[0] (angle spinner).

createPaintStylePanel

private JPanel createPaintStylePanel()

Processing:

Creates the panel (Figure 1.2) to be added to the JTabbedPane.

∙ The button objects

Creates the button objects (ButtonOfPulldownMenu) by the createFillColorChooserButton method, createLineColorChooserButton method and so on.

∙ Layout: uses the Box object

Box box=Box.createVerticalBox();

createPropertyPanel

private JPanel createPropertyPanel()

Processing:

Creates the panel (Figure 1.3) to be added to the JTabbedPane.

∙ Sets the unresizableBox, ratioBox, directionBox, unableConnectorBox and ungroupBox check boxes to the panel.

showProperty

protected void showProperty()

Processing:

∙ Gets the property values using the ShapeContainer.getBooleanProperty method.

∙ Sets boolean true/false to the unresizableBox, ratioBox, directionBox, unableConnectorBox and ungroupBox check boxes.

createDataPanel

private JPanel createPropertyPanel()

Processing:

Creates the panel (Figure 1.4) to be added to the JTabbedPane.

∙ The JTextArea

Creates a new object of the JTextPane to display the information of this.shapeContainer.

∙ The JScrollPane

Creates a new object of the JScrollPane (dataScrollPane) and adds the new JTextPane object to the JScrollPane.

createTextBoxPanel

private JPanel createTextBoxPanel()

Processing:

Creates the panel (Figure 1.5) to be added to the JTabbedPane.

∙ The button objects

Creates the button objects (ButtonOfToggle) by the createButton method.

∙ The spinners

Creates the spinners (marginSpinners, lineSpaceSpinner) and their associated spinner models and sets the values to the spinner models.

createTextInfoPanel

private JPanel createTextInfoPanel()

Processing:

Creates the panel (Figure 1.6) to be added to the JTabbedPane.

∙ The JTextParea

Creates a new object of the JTxtArea to display the text information of this.shapeContainer.

∙ The JScrollPane

Creates a new object of the JScrollPane (textScrollPane) and adds the new JTextPane object to the JScrollPane.

getShapeContainer

public ShapeContainer getShapeContainer()

Returns the shapeContainer.

getDataScrollPane

public JScrollPane getDataScrollPane()

Returns the dataScrollPane.

getTextScrollPane

public JScrollPane getTextScrollPane()

Returns the textScrollPane.

getPositionSpinners

public JSpinner[] getPositionSpinners()

Returns the positionSpinners.

getPositionSpinner
Models

public SpinnerNumberModel[] getPositionSpinnerModels()

Returns the positionSpinnerModels.

getSizeSpinners

public JSpinner[] getSizeSpinners()

Returns the sizeSpinners.

getSizeSpinner
Models

public SpinnerNumberModel[] getSizeSpinnerModels()

Returns the sizeSpinnerModels.

getCenterSpinners

public JSpinner[] getCenterSpinners()

Returns the centerSpinners.

getCenterSpinner
Models

public SpinnerNumberModel[] getCenterSpinnerModels()

Returns the centerSpinnerModels.

getStartSpinners

public JSpinner[] getStartSpinners()

Returns the startSpinners.

getStartSpinner
Models

public SpinnerNumberModel[] getStartSpinnerModels()

Returns the startSpinnerModels.

getEndSpinners

public JSpinner[] getEndSpinners()

Returns theendSpinners.

getEndSpinner
Models

public SpinnerNumberModel[] getEndSpinnerModels()

Returns the endSpinnerModels.

getLineSpinners

public JSpinner[] getLineSpinners()

Returns the lineSpinners.

getLineSpinner
Models

public SpinnerNumberModel[] getLineSpinnerModels()

Returns the lineSpinnerModels.

getMarginSpinners

public JSpinner[] getMarginSpinners()

Returns the marginSpinners.

getMarginSpinner
Models

public SpinnerNumberModel[] getMarginSpinnerModels()

Returns the marginSpinnerModels.

getLineSpaceSpinner

public JSpinner getLineSpaceSpinner()

Returns the lineSpaceSpinner.

getLineSpaceSpinner
Models

public SpinnerNumberModel getLineSpaceSpinnerModels()

Returns the lineSpaceSpinnerModel.

getUnResizableBox

public JCheckBox getUnResizableBox()

Returns the unresizableBox.

getRatioBox

public JCheckBox getRatioBox()

Returns the ratioBox.

getDirectionBox

public JCheckBox getDirectionBox()

Returns the directionBox.

getUnableConnectorBox

public JCheckBox getUnableConnectorBox()

Returns the unableConnectorBox.

getUngroupBox

public JCheckBox getUngroupBox()

Returns the ungroupBox.



1.2 Class ShapeFormtListener return=>page top

class ShapeFormatListener implements ComponentListener

Field

Description

dialog

DialogOfShapeFormat dialog

The DialogOfShapeFormat object.


Method

Description

Constructor ShapeFormatListener(DialogOfShapeFormat dialog)
Sets the parameter to the field.

componentResized

public void componentResized(ComponentEvent e)

This method is called if the DialogOfShapeFormat is resized.

∙ Resizes the dataScrollPane and the textScrollPane according to the size of the DialogOfShapeFormat.

Sets the new size of the dataScrollPane and the textScrollPane by the setPreferredSize method, calls revalidate method for dataScrollPane and the textScrollPane and calls the validate method for the DialogOfShapeFormat as follows.

dataScrollPane.setPreferredSize(newSize);
dataScrollPane.revalidate();
textScrollPane.setPreferredSize(newSize);
textScrollPane.revalidate();
this.dialog.validate();

componentShown

public void componentShown(ComponentEvent e)

Calls the setScrollViewPosition method of the DialogOfShapeFormat.



1.3 Class SpinnersChangeListener return=>page top

class SpinnersChangeListener implements ChangeListener

Field

Description

dialog

DialogOfShapeFormat dialog

The DialogOfShapeFormat object.

shapeContainer

ShapeContainer shapeContainer

The same as the shapeContainer.


Method

Description

Constructor SpinnersChangeListener(DialogOfShapeFormat dialog)
Sets the parameter to the field.

stateChanged

public void stateChanged(ChangeEvent e)

If the shapeContainer is a line, call the lineChanged method, otherwise the rectangularChanged method.

rectangularChanged

public void rectangularChanged(ChangeEvent e)

When a spinner's value of "position, size" tab is changed, update the related spinners' values to keep the consistency and display the shapeContainer object on the canvas. This method works considering the properties of the selected shape.

See=> User's Guide position, size tab, property tab, The property of a shape and the spinners' values

∙ This method moves or resizes the selected shape using the ConnectionUtil.moveResize static method.

lineChanged

public void lineChanged(ChangeEvent e)

When a spinner's value of "position, size" tab is changed, update the related spinners' values to keep the consistency and display the shapeContainer object (line) on the canvas. This method works considering the properties of the selected shape.

See=> User's Guide position, size tab, property tab, The property of a shape and the spinners' values

∙ This method moves or resizes the selected shape using the ConnectionUtil.moveResize and moveEndPoint static method.

getMoveVector

private Vector2D getMoveVector(Vector2D Tvec, Vector2D move)

This method is called from the lineChanged method and calcurates the end point when the directionBox is selected.,

removeChangeListener

private void removeChangeListener()

Removes the ChangeListener from the positionSpinners - lineSpinners to deter the spinners' events while the spinners' values are updated.

addChangeListener

private void addChangeListener()

Adds the ChangeListenerto the positionSpinners - lineSpinners.



1.4 Class ShapeFormatAction return=>page top

class ShapeFormatAction extends AbstractAction implements WindowListener

Field

Description

dialog

DialogOfShapeFormat dialog

The DialogOfShapeFormat object.

shapeContainer

ShapeContainer shapeContainer

The same as the shapeContainer.

execCommand

ExecCommand execCommand=ObjectTable.getExecCommand("DialogOfShapeFormat")

Sets the ExecCommand object.


Method

Description

Constructor ShapeFormatAction(DialogOfShapeFormat dialog)
Sets the parameter to the field.

actionPerformed

public void actionPerformed(ActionEvent e)

(1) If the "pixel" or "mm" button (Figure 1.1 (a)) is pressed, then calls the showLine or showRectangular method of the DialogOfShapeFormat to display the values to the spinners in the specified unit of length.

(2) If a check box on the property panel (Figure 1.3) is clicked, then handles as follows.

If the selected value of the check box is other than the default value, then writes it to the selected shape (shapeContainer) by the next setProperty method.
Additionally, sets "on" or "off" (setSelected(true) or setSelected(false)) to other properties according to the relations between properties and changes spinners' state enable or disables (setEnabled(true) or setEnabled(false)). For examples, when the "enable resizing" property is changed to "off", then changes the states of other check boxes and spinners as follows.

① Sets "off" (setSelected(false)) to the ratioBox and directionBox and disable them (setEnabled(false)).
② If the selected shape (shapeContainer) is a line, then disables the lineSpinners, and if it is not a line, then disables the sizeSpinners.

See=> User's Guide The property of a shape and the spinners' values

(3) If the "OK" button (Figure 1.3) in the property tab is pressed, then sets the selected properties are set to the shapeContainer and calls the closedDialog method to close the dialog.

(4) If the "Cancel" button (Figure 1.3) in the property tab is pressed, then calls the closedDialog method to close the dialog.

(5) If the OK button (Figure 1.5) on the text box tab is pressed, then generates the "TEXTBOX_LAYOUT" command and calls exec method of the ExecCommand. Finally calls the closedDialog method.

(6) If the "Cancel" button (Figure 1.5) on the text box tab is pressed, then calls the closedDialog method.

setProperty

private void setProperty()

If the selected value of the check box is other than the default value, then writes it to the selected shape by the setProperty method of the shapeContainer. 

closeDialog

private void closeDialog()

Sets invisible to the dialog by the setVisible(false) and removes this dialog from the menuComponentList by the removeMenuComponent of the menuUtil.

windowClosing

public void windowClosing(WindowEvent e)

Calls the closedDialog method.



2. DrawPanel dialog return=>page top
This class is called from theExecCommand.exec method.
public class DialogOfShapeFormat extends JDialog

Figure 2.1 Display the list of the shape objects

Figure 2.2 Display the list of the MouseListeners



2.1 Class DialogOfDrawPanel return=>page top
This class is called from the ExecCommand.exec method.

public class DialogOfDrawPanel extends JDialog

Field

Description

action

DialogOfDrawPanelAction action

The ActionListener object (DialogOfDrawPanelAction)

shapeScrollPane

JScrollPane shapesScrollPanePane

The ScrollPane in the shape information tab (Figure 2.1).

listenerScrollPane

JScrollPane ListenerScrollPane

The ScrollPane in the listener information tab (Figure 2.2).

dialogPaneDimension

Dimension dialogDimension=new Dimension(500,300);

The initial size of the dialog.


Method

Description

Constructor

public DialogOfDrawPanel()

Sets the following.

super(ObjectTable.getDrawMain(),"Draw Panel Information");
this.setName("DialogOfDrawPanel");
this.action=new DialogOfDrawPanelAction(this);
this.addWindowListener(action);

showDialog

public static void showDialog(Point mousePosition)

Parameters:

mousePosition - The mouse position if the command is specified by the right button press of the mouse.

Processing:

∙ Sets the DialogOfDrawPanelListener object to this dialog.

∙ Creates the JTabbedPane and adds the five panels to the JTabbedPane.

The five panels are created by the createShapeInfoPanel, createListenerInfo
Panel
methods.

∙ Calls setVisible method for this object to show the dialog.

∙ If other DialogOfDrawPanel object is shown on the screen, removes it from the screen by the removeDialog method.

removeDialog protected void removeDialog()
Sets invisible to this object by the setVisible(false)
and removes this dialog from the menuComponentList by the removeMenuComponent of the menuUtil.
setScrollViewPosition

protected void setScrollViewPosition()

Sets the view position to the shapeScrollPane and the listenerScrollPane.

this.shapescrollPane.getViewport().setViewPosition(new Point(0,0));
this.listenerScrollPane.getViewport().setViewPosition(new Point(0,0));

: Calls this method in the componentShown method of the DialogOfDrawPanelListener.

createShapeInfoPanel

private static JPanel createShapeInfoPanel()

Processing:

Creates the panel (Figure 2.1) to be added to the JTabbedPane.

∙ The JTextArea

Creates a new object of the JTextArea to display the information of all the shape objects on the canvas.
Read all the shapes from the ContainerList and get the strings of the shapes by the ShapeContainer.toString method.

∙ The JScrollPane

Creates a new object of the JScrollPane (shapeScrollPane) and adds the new JTextArea object to the JScrollPane.

createListenerInfo
Panel

private static JPanel createListenerInfoPanel()

Processing:

Creates the panel (Figure 2.2) to be added to the JTabbedPane.

∙ The JTextArea

Creates a new object of the JTextArea to display the information of mouse listeners on the DrawPanel (ListenerPanel).

∙ The JScrollPane

Creates a new object of the JScrollPane (listenerScrollPane) and adds the new JTextArea object to the JScrollPane.

getShapeScrollPane public JScrollPane getShapeScrollPane()
Returns the shapeScrollPane.
getListenerScrollPane public JScrollPane getListenerScrollPane()
Returns the listenerScrollPane.


2.2 DialogOfDrawPanelListener return=>page top

class DialogOfDrawPanelListener implements ComponentListener

Field

Description

dialog

DialogOfDrawPanel dialog

The DialogOfDrawPanel object.


Method

Description

Constructor DialogOfDrawPanelListener(DialogOfDrawPanel dialog)
Sets the parameter to the field.

componentResized

public void componentResized(ComponentEvent e)

This method is callded if the DialogOfDrawPanel is resized.

∙ Resizes the shapeScrollPane and the listenerScrollPane according to the size of the DialogOfDrawPanel.

Sets the new size of the shapeScrollPane and the listenerScrollPane by the setPreferredSize method, calls revalidate method for shapeScrollPane and the listenerScrollPane and calls the validate method for the DialogOfDrawPanel as follows.

shapesScrollPane.setPreferredSize(newSize);
shapesScrollPane.revalidate();
listenersScrollPane.setPreferredSize(newSize);
listenersScrollPane.revalidate();
this.dialog.validate();

componentShown

public void componentShown(ComponentEvent e)

Calls the setScrollViewPosition method of the DialogOfDrawPanel.



2.3 Class DialogOfDrawPanelAction return=>page top

class DialogOfDrawPanelAction extends AbstractAction


Field

Description

dialog

DialogOfDrawPanel dialog

The DialogOfDrawPanel object.


Method

Description

Constructor DialogOfDrawPanelAction(DialogOfShapeFormat dialog)
Sets the parameter to the field.

actionPerformed

public void actionPerformed(ActionEvent e)

Currently this method does nothing.

closeDialog

private void closeDialog()

Sets invisible to the dialog by the setVisible(false) and removes this dialog from the menuComponentList by the removeMenuComponent of the menuUtil.

windowClosing

public void windowClosing(WindowEvent e)

Calls the closedDialog method.



Copyright (c) 2009-2013
All other trademarks are property of their respective owners.