📄 wizard.java
字号:
WizardPanelDescriptor oldPanelDescriptor = wizardModel.getCurrentPanelDescriptor();
if (oldPanelDescriptor != null)
oldPanelDescriptor.aboutToHidePanel();
wizardModel.setCurrentPanel(id);
wizardModel.getCurrentPanelDescriptor().aboutToDisplayPanel();
// Show the panel in the dialog.
cardLayout.show(cardPanel, id.toString());
wizardModel.getCurrentPanelDescriptor().displayingPanel();
}
/**
* Method used to listen for property change events from the model and update the
* dialog's graphical components as necessary.
* @param evt PropertyChangeEvent passed from the model to signal that one of its properties has changed value.
*/
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(WizardModel.CURRENT_PANEL_DESCRIPTOR_PROPERTY)) {
wizardController.resetButtonsToPanelRules();
} else if (evt.getPropertyName().equals(WizardModel.NEXT_FINISH_BUTTON_TEXT_PROPERTY)) {
nextButton.setText(evt.getNewValue().toString());
} else if (evt.getPropertyName().equals(WizardModel.BACK_BUTTON_TEXT_PROPERTY)) {
backButton.setText(evt.getNewValue().toString());
} else if (evt.getPropertyName().equals(WizardModel.CANCEL_BUTTON_TEXT_PROPERTY)) {
cancelButton.setText(evt.getNewValue().toString());
} else if (evt.getPropertyName().equals(WizardModel.NEXT_FINISH_BUTTON_ENABLED_PROPERTY)) {
nextButton.setEnabled(((Boolean)evt.getNewValue()).booleanValue());
} else if (evt.getPropertyName().equals(WizardModel.BACK_BUTTON_ENABLED_PROPERTY)) {
backButton.setEnabled(((Boolean)evt.getNewValue()).booleanValue());
} else if (evt.getPropertyName().equals(WizardModel.CANCEL_BUTTON_ENABLED_PROPERTY)) {
cancelButton.setEnabled(((Boolean)evt.getNewValue()).booleanValue());
} else if (evt.getPropertyName().equals(WizardModel.NEXT_FINISH_BUTTON_ICON_PROPERTY)) {
nextButton.setIcon((Icon)evt.getNewValue());
} else if (evt.getPropertyName().equals(WizardModel.BACK_BUTTON_ICON_PROPERTY)) {
backButton.setIcon((Icon)evt.getNewValue());
} else if (evt.getPropertyName().equals(WizardModel.CANCEL_BUTTON_ICON_PROPERTY)) {
cancelButton.setIcon((Icon)evt.getNewValue());
}
}
/**
* Retrieves the last return code set by the dialog.
* @return An integer that identifies how the dialog was closed. See the *_RETURN_CODE
* constants of this class for possible values.
*/
public int getReturnCode() {
return returnCode;
}
/**
* Mirrors the WizardModel method of the same name.
* @return A boolean indicating if the button is enabled.
*/
public boolean getBackButtonEnabled() {
return wizardModel.getBackButtonEnabled().booleanValue();
}
/**
* Mirrors the WizardModel method of the same name.
* @param boolean newValue The new enabled status of the button.
*/
public void setBackButtonEnabled(boolean newValue) {
wizardModel.setBackButtonEnabled(new Boolean(newValue));
}
/**
* Mirrors the WizardModel method of the same name.
* @return A boolean indicating if the button is enabled.
*/
public boolean getNextFinishButtonEnabled() {
return wizardModel.getNextFinishButtonEnabled().booleanValue();
}
/**
* Mirrors the WizardModel method of the same name.
* @param boolean newValue The new enabled status of the button.
*/
public void setNextFinishButtonEnabled(boolean newValue) {
wizardModel.setNextFinishButtonEnabled(new Boolean(newValue));
}
/**
* Mirrors the WizardModel method of the same name.
* @return A boolean indicating if the button is enabled.
*/
public boolean getCancelButtonEnabled() {
return wizardModel.getCancelButtonEnabled().booleanValue();
}
/**
* Mirrors the WizardModel method of the same name.
* @param boolean newValue The new enabled status of the button.
*/
public void setCancelButtonEnabled(boolean newValue) {
wizardModel.setCancelButtonEnabled(new Boolean(newValue));
}
/**
* Closes the dialog and sets the return code to the integer parameter.
* @param code The return code.
*/
void close(int code) {
returnCode = code;
wizardDialog.dispose();
}
/**
* This method initializes the components for the wizard dialog: it creates a JDialog
* as a CardLayout panel surrounded by a small amount of space on each side, as well
* as three buttons at the bottom.
*/
private void initComponents() {
wizardModel.addPropertyChangeListener(this);
wizardController = new WizardController(this);
wizardDialog.getContentPane().setLayout(new BorderLayout());
wizardDialog.addWindowListener(this);
// Create the outer wizard panel, which is responsible for three buttons:
// Next, Back, and Cancel. It is also responsible a JPanel above them that
// uses a CardLayout layout manager to display multiple panels in the
// same spot.
JPanel buttonPanel = new JPanel();
JSeparator separator = new JSeparator();
Box buttonBox = new Box(BoxLayout.X_AXIS);
cardPanel = new JPanel();
cardPanel.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
cardLayout = new CardLayout();
cardPanel.setLayout(cardLayout);
backButton = new JButton(new ImageIcon("com/nexes/wizard/backIcon.gif"));
nextButton = new JButton();
cancelButton = new JButton();
backButton.setActionCommand(BACK_BUTTON_ACTION_COMMAND);
nextButton.setActionCommand(NEXT_BUTTON_ACTION_COMMAND);
cancelButton.setActionCommand(CANCEL_BUTTON_ACTION_COMMAND);
backButton.addActionListener(wizardController);
nextButton.addActionListener(wizardController);
cancelButton.addActionListener(wizardController);
// Create the buttons with a separator above them, then place them
// on the east side of the panel with a small amount of space between
// the back and the next button, and a larger amount of space between
// the next button and the cancel button.
buttonPanel.setLayout(new BorderLayout());
buttonPanel.add(separator, BorderLayout.NORTH);
buttonBox.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
buttonBox.add(backButton);
buttonBox.add(Box.createHorizontalStrut(10));
buttonBox.add(nextButton);
buttonBox.add(Box.createHorizontalStrut(30));
buttonBox.add(cancelButton);
buttonPanel.add(buttonBox, java.awt.BorderLayout.EAST);
wizardDialog.getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH);
wizardDialog.getContentPane().add(cardPanel, java.awt.BorderLayout.CENTER);
}
private static Object getImage(String name) {
URL url = null;
try {
Class c = Class.forName("com.nexes.wizard.Wizard");
url = c.getResource(name);
} catch (ClassNotFoundException cnfe) {
System.err.println("Unable to find Wizard class");
}
return url;
}
/**
* If the user presses the close box on the dialog's window, treat it
* as a cancel.
* @param WindowEvent The event passed in from AWT.
*/
public void windowClosing(WindowEvent e) {
returnCode = CANCEL_RETURN_CODE;
}
static {
try {
PropertyResourceBundle resources = (PropertyResourceBundle)
ResourceBundle.getBundle("com.nexes.wizard.wizard");
BACK_TEXT = (String)(resources.getObject("backButtonText"));
NEXT_TEXT = (String)(resources.getObject("nextButtonText"));
CANCEL_TEXT = (String)(resources.getObject("cancelButtonText"));
FINISH_TEXT = (String)(resources.getObject("finishButtonText"));
BACK_ICON = new ImageIcon((URL)getImage((String)(resources.getObject("backButtonIcon"))));
NEXT_ICON = new ImageIcon((URL)getImage((String)(resources.getObject("nextButtonIcon"))));
CANCEL_ICON = new ImageIcon((URL)getImage((String)(resources.getObject("cancelButtonIcon"))));
FINISH_ICON = new ImageIcon((URL)getImage((String)(resources.getObject("finishButtonIcon"))));
} catch (MissingResourceException mre) {
System.out.println(mre);
System.exit(1);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -