📄 wizardprocesspanel.java
字号:
*/ protected void setHelpAction(Action a) { helpButton.setAction(a); helpButton.setIcon(null); helpButton.setText("Help"); } /** * Sets the action for the help button to that specified with * the specified action command string. * This will also set a null icon value and set the button * text to 'Help'. * * @param a - the help action to be applied * @param actionCommand - the action command string */ protected void setHelpAction(Action a, String actionCommand) { helpButton.setAction(a); helpButton.setIcon(null); helpButton.setText("Help"); helpButton.setActionCommand(actionCommand); } /** * Sets the title label text to that specified. * * @param text - the title text */ protected void setTitleLabelText(String text) { titleLabel.setText(text); Dimension dim = titleLabel.getSize(); titleLabel.paintImmediately(0, 0, dim.width, dim.height); } /** * Returns whether the buttons are enabled. * If the buttons are not set enabled, any changes * to them using setEnabled(..) is ignored. * * @return true | false */ public boolean isButtonsEnabled() { return buttonsEnabled; } /** * Sets the buttons to be enabled. * * @param buttonsEnabled - true | false */ public void setButtonsEnabled(boolean buttonsEnabled) { this.buttonsEnabled = buttonsEnabled; } /** * Sets the text label on the next button to that specified. * * @param text - the 'NEXT' button text */ public void setNextButtonText(String text) { nextButton.setText(text); } /** * Sets the text label on the back (previous) button to that specified. * * @param text - the 'BACK' button text */ public void setBackButtonText(String text) { backButton.setText(text); } /** * Sets the text label on the cancel button to that specified. * * @param text - the 'CANCEL' button text */ public void setCancelButtonText(String text) { cancelButton.setText(text); } /** * Enables/disables the next button. * * @param true | false */ public void setNextButtonEnabled(boolean enable) { if (buttonsEnabled) { nextButton.setEnabled(enable); } } /** * Enables/disables the next button. * * @param true | false */ public void setBackButtonEnabled(boolean enable) { if (buttonsEnabled) { backButton.setEnabled(enable); } } /** * Enables/disables the next button. * * @param true | false */ public void setCancelButtonEnabled(boolean enable) { if (buttonsEnabled) { cancelButton.setEnabled(enable); } } /** * Returns the currently selected index. * * @return the current index */ public int getSelectedIndex() { return model.getSelectedIndex(); } /** * Adds the specified panel to the layout with the specified name. * * The name must be the string value of the index of the specified panel. * * @param panel - the panel * @param title - the layout name */ public void addPanel(JPanel panel, String title) { rightPanel.add(panel, title); } /** * Enables/diables buttons based on the current selected index. */ protected void resetButtons() { setNextButtonEnabled(model.hasNext()); setBackButtonEnabled(model.hasPrevious()); } /** * Performs the cancel action. */ public abstract void cancel(); /** * Performs the action on the selection on next. */ protected void next() { if (model.hasNext() && model.next()) { int index = model.getSelectedIndex(); String layoutName = String.valueOf(index); rightPanel.add(model.getPanelAt(index), layoutName); setTitleLabelText(model.getTitle(index)); cardLayout.show(rightPanel, layoutName); setSelectedStep(index); resetButtons(); } } /** * Performs the action on the selection on back. */ protected void back() { if (model.hasPrevious() && model.previous()) { int index = model.getSelectedIndex(); String layoutName = String.valueOf(index); setTitleLabelText(model.getTitle(index)); cardLayout.show(rightPanel, layoutName); setSelectedStep(index); resetButtons(); } } /** * Executes the actions associated with the button selctions. * * @param e - the originating event */ public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == nextButton) { next(); } else if (source == backButton) { back(); } else if (source == cancelButton) { cancel(); } } /** * Returns the wizard model for this instance. * * @return the model */ public WizardProcessModel getModel() { return model; } /** * Sets the wizard model to that specified. * * @param model - the model to be used */ public void setModel(WizardProcessModel model) { this.model = model; } // the top labels for each panel private class WizardLabel extends JLabel { public WizardLabel(String text, int alignment) { super(text, alignment); } public Dimension getPreferredSize() { return new Dimension(getParent().getWidth(), getHeight()); } } // the steps left hand panel private class StepListPanel extends JPanel { private Color darkColor; private Color lightColor; public StepListPanel(LayoutManager layout) { super(layout); darkColor = UIUtils.getDefaultActiveBackgroundColour(); lightColor = getBackground(); } public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D)g; /* g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); */ super.paintComponent(g); int width = getWidth(); int height = getHeight(); Paint originalPaint = g2.getPaint(); GradientPaint fade = new GradientPaint(0, height, darkColor, 0, (int)(height * 0.2), lightColor); g2.setPaint(fade); g2.fillRect(0,0, width, height); g2.setPaint(originalPaint); } public boolean isOpaque() { return false; } } private class WizardStepLabel extends JLabel { public WizardStepLabel(int index, String text) { StringBuffer sb = new StringBuffer(); sb.append("<html><table border=\"0\" cellpadding=\"2\"><tr><td valign=\"top\" nowrap>"); sb.append(index); sb.append(".</td><td>"); sb.append(text.replaceAll("\n", "<br>")); sb.append("</td></tr></table></html>"); setText(sb.toString()); } public boolean isOpaque() { return false; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -