1. Class DialogOfZoom
return=>page top
1.1 Dialog
Specifies the scale (zoom) factor by the dialog of the Figure 1.
∙ The left-side component in the dialog is a combo box and
the right-side component is a spinner whose step size is 1%.
∙ If the scale factor specified by the spinner doesn't match any of the
items of the combo box, then a space is displayed in the combo box
∙ Whenever the scale factor is specified in the combo box or the spinner,
the canvas will be refreshed at the specified scale factor.
∙ If the "Cancel button" is clicked, then the canvas is redrawn
at the scale factor before changed by the dialog.
∙ The property tab isn't currently used.
|
Figure 1
|
1.2 DialogOfZoom API
戻る=>page top
public class DialogOfZoom extends JDialog
Field
|
Description
|
main
(static)
|
public static DialogOfZoom main
Sets this object to main. This field is referred by the DialogOfZommAction,
ZoomItemListener and
ZoomSpinnerChangeListener class.
|
dialogDimension
|
Dimension dialogDimension
The size of the dialog.
|
zoomComboBox
|
JComboBox zoomComboBox
The JCombobox object in the dialog.
|
zoomSpinner
|
JSpinner zoomSpinner
The JSpinner object in the dialog.
|
zoomSpinnerModel
|
SpinnerNumberModel zoomSpinnerModel
The SpinnerNumber model for the JSpinner.
|
scaleSave |
double scaleSave
Saves the scale factor when this object is created. If the "Cancel
button" is clicked, then refers this field. |
Method
|
Description
|
Constructor
|
public DialogOfZoom()
super(ObjectTable.getDrawMain(), "zoom");
this.main=this
|
showDialog
|
public void showDialog()
∙ Sets the dialog position at the left upper of the window.
∙ Creates the the ZoomPanel by the
createZoomPanel method
and sets it to the dialog
∙ Shows the dialog by the setVisible method.
|
createZoomPanel
|
private JPanel createZoomPanel()
∙ Places the combo box and spinner to the ZoomPanel.
Adds the action listener (DialogOfZoomAction)
and item listener (ZoomItemListener) to the combo box
and sets the action command "Zoom" to the combo box.
Add the change listener (ZoomSpinnerChangeListener) to the spinner.
∙ Places "OK" button and "Cancel" button to the
dialog.
Adds the action listener (DialogOfZoomAction) to the buttons.
Sets the action command "OK Zoom" to the "OK" button
and sets the action command "Cancel Zoom" to the "Cancel"
button
|
2. Class DialogOfZoomAction
class DialogOfZoomAction extends AbstractAction
Field
|
Description
|
main
|
static DialogOfZoomAction main
Sets this object to the main.
|
Method
|
Description
|
actionPerformed
|
public void actionPerformed(ActionEvent e)
This method is called, when the scale factor is specified to the combo
box or the "OK", "Cancel" buttons are clicked.
∙ The action command equals "Zoom".
If the selected item of the zoomComboBox doesn't equal "",
then gets the scale factor by the getScale method,
otherwise gets the scale factor from the zoomSpinnerModel.
Generate the "ZOOM_TO" command and calls the
ExecCommand.exec method.
∙ The action command equals "OK Zoom".
The "OK" button was clicked. Close the dialog and returns.
∙ The action command equals "Cancel Zoom".
The "Cancel" button was clicked.
Generate the "ZOOM_TO" command with the parameter of the
scaleSave and executes the command.
|
getScale
|
protected double getScale(String scaleString)
Parameters:
scaleString - The string representing the selected item of the combo box.
Returns:
Returns the scale factor.
|
3.Class ZoomItemListener
戻る=>page top
class ZoomItemListener implements ItemListener
This listener is set to the combo box (zoomComboBox).
Method
|
Description
|
itemStateChanged
|
public void itemStateChanged(ItemEvent e)
When a item is selected in the combo box, this method sets the scale factor
of the selected item to the spinner.
|
4. Class ZoomSpinnerChangeListener
戻る=>page top
class ZoomSpinnerChangeListener implements ChangeListener
This listener is set to the spinner (zoomSpinner).
Method
|
Description
|
stateChanged
|
public void stateChanged(ChangeEvent e)
When a scale factor is set in the spinner, this method sets the
scale factor to the combo box. If the scale factor in the spinner doesn't
correspond to any item of the combo box, then this method show space item
in the combo box.
|
|