📄 jwizard.java
字号:
b_next.setPressedIcon(im_nextdo);
b_next.setDisabledIcon(im_nextun);
b_next.setBorderPainted(false);
b_next.setContentAreaFilled(false);
b_next.setFocusPainted(false);
b_next.setActionCommand("next");
b_next.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e) {
nextStep = null;
if( !currentStep.onNext(getContext(),JWizard.this) )
return;
if(nextStep==null) {
// End of JWizard ?
if( currentStep.getParameters().getIsLastStep() ) {
onFinished(getContext()); // End of Wizard
setVisible(false);
mainPanel.removeAll();
stepFactory.clear();
dispose();
currentStep=null;
}
return;
}
showNextStep();
}
});
// *** Cancel ***
b_cancel = new JButton(im_cancelup);
b_cancel.setRolloverIcon(im_canceldo);
b_cancel.setPressedIcon(im_canceldo);
b_cancel.setDisabledIcon(im_cancelun);
b_cancel.setBorderPainted(false);
b_cancel.setContentAreaFilled(false);
b_cancel.setFocusPainted(false);
b_cancel.setActionCommand("cancel");
b_cancel.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e) {
int value = JOptionPane.showConfirmDialog(null, "Are you sure ?", "Cancel", JOptionPane.YES_NO_OPTION);
if( value != JOptionPane.YES_OPTION )
return;
onCanceled(getContext());
setVisible(false);
mainPanel.removeAll();
stepFactory.clear();
dispose();
currentStep=null;
nextStep=null;
}
});
// *** Add the buttons to buttonsPanel ***
buttonsPanel.add(b_previous);
buttonsPanel.add(new JLabel(" "));
buttonsPanel.add(b_cancel);
buttonsPanel.add(b_next);
buttonsPanel.setPreferredSize( new Dimension(width-10,45) );
// *** Add buttonsPanel ***
JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
southPanel.setBackground(Color.white);
southPanel.add(buttonsPanel);
southPanel.setPreferredSize( new Dimension(width-10,60) );
wizardPanel.add(southPanel, BorderLayout.SOUTH);
// *** Window listener
addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e) {
b_cancel.doClick();
}
});
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); // close is close ! not hide !
}
/*------------------------------------------------------------------------------------*/
/** Initialize this JWizard with its first JWizarStep. Displays the JWizard.
* It is your responsablity to call this method.
*
* @param parameters parameters for the first step
* @exception thrown if the given parameters are wrong...
*/
protected void init( JWizardStepParameters parameters ) throws WizardException {
if( !setNextStep(parameters) )
throw new WizardException("failed to create first step.");
showNextStep();
}
/*------------------------------------------------------------------------------------*/
/** Initialize this JWizard with its first JWizarStep. Displays the JWizard.
* It is your responsablity to call this method.
*
* @param parametersFile file containing the JWizardStepParameters for the first step
* @exception thrown if the given parameters are wrong...
*/
protected void init( String parametersFile ) throws WizardException {
if( !setNextStep(parametersFile) )
throw new WizardException("failed to create first step.");
showNextStep();
}
/*------------------------------------------------------------------------------------*/
/** To set the current JWizardStep. Given its parameters we create the step using
* our JWizardStepFactory.
*
* @param parameters step parameters
* @return true the current step was changed successfully, false otherwise.
*/
public boolean setNextStep( JWizardStepParameters parameters ) {
nextStep = stepFactory.getJWizardStep( parameters );
if(nextStep==null)
return false;
return true;
}
/*------------------------------------------------------------------------------------*/
/** To set the current JWizardStep. Given a file containing the JWizardStepParameters
* we try to create the step using our JWizardStepFactory.
*
* @param parametersFile file containing the JWizardStepParameters to use for the step's
* creation.
* @return true the current step was changed successfully, false otherwise.
*/
public boolean setNextStep( String parametersFile ) {
nextStep = stepFactory.getJWizardStepFromFile( parametersFile );
if(nextStep==null)
return false;
return true;
}
/*------------------------------------------------------------------------------------*/
/** To show the next selected step on the wizard
*/
protected void showNextStep() {
// Step Cleaning
if(nextStep==null)
return; // no step !!!
mainPanel.removeAll();
// Step Update
currentStep = nextStep;
nextStep = null;
mainPanel.add(currentStep, BorderLayout.SOUTH);
// Parameters update
t_title.setText( currentStep.getParameters().getStepTitle() );
b_next.setEnabled( currentStep.getParameters().getIsNextButtonEnabled() );
b_previous.setEnabled( currentStep.getParameters().getIsPrevButtonEnabled() );
if( currentStep.getParameters().getIsLastStep() ) {
b_next.setIcon(im_okup);
b_next.setRolloverIcon(im_okdo);
b_next.setPressedIcon(im_okdo);
b_next.setDisabledIcon(im_okun);
}
else {
b_next.setIcon(im_nextup);
b_next.setRolloverIcon(im_nextdo);
b_next.setPressedIcon(im_nextdo);
b_next.setDisabledIcon(im_nextun);
}
// Screen Show
mainPanel.repaint();
show();
currentStep.onShow(context,this);
}
/*------------------------------------------------------------------------------------*/
/** To set the context object which is given to JWizardSteps onXXX methods.
*/
public void setContext(Object context) {
this.context = context;
}
/*------------------------------------------------------------------------------------*/
/** To get the context object which is given to JWizardSteps onXXX methods.
*/
protected Object getContext() {
return context;
}
/*------------------------------------------------------------------------------------*/
/** To set if the next button is enabled.
*/
public void setIsNextButtonEnabled(boolean enabled) {
b_next.setEnabled( enabled );
}
/*------------------------------------------------------------------------------------*/
/** To awake the current step.
*/
public void awakeCurrentStep() {
if(currentStep!=null)
currentStep.awake();
}
/*------------------------------------------------------------------------------------*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -