📄 wizardprocesspanel.java
字号:
/* * WizardProcessPanel.java * * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */package org.underworldlabs.swing.wizard;import java.awt.BorderLayout;import java.awt.CardLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.LayoutManager;import java.awt.Paint;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import java.util.List;import javax.swing.Action;import javax.swing.BorderFactory;import javax.swing.BoxLayout;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.UIManager;import javax.swing.border.Border;import org.underworldlabs.swing.plaf.UIUtils;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the * release of version 3.0.0beta1 has meant a * resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * Base wizard process panel. * * @author Takis Diakoumis * @version $Revision: 1.6 $ * @date $Date: 2006/07/15 12:51:31 $ */public abstract class WizardProcessPanel extends JPanel implements ActionListener { /** the selection model */ private WizardProcessModel model; /** the left panel */ private JPanel leftPanel; /** the right panel */ private JPanel rightPanel; /** the base content panel */ private JPanel contentPanel; /** the right panel layout */ private CardLayout cardLayout; /** the next button */ private JButton nextButton; /** the previous button */ private JButton backButton; /** the cancel button */ private JButton cancelButton; /** the help button */ protected JButton helpButton; /** the title label */ private JLabel titleLabel; /** the step label list */ private List<JLabel> stepLabels; /** the normal label font */ private Font labelFont; /** the selected label font */ private Font selectedLabelFont; /** whether buttons are enabled */ private boolean buttonsEnabled; /** Creates a new instance of WizardProcessPanel */ public WizardProcessPanel() { this(null); } /** Creates a new instance of WizardProcessPanel */ public WizardProcessPanel(WizardProcessModel model) { super(new BorderLayout()); this.model = model; try { init(); } catch (Exception e) { e.printStackTrace(); } } private void init() throws Exception { buttonsEnabled = true; Border labelBorder = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK); // setup the title label and right panel cardLayout = new CardLayout(); rightPanel = new JPanel(cardLayout); titleLabel = new JLabel("", JLabel.LEFT); titleLabel.setBorder(labelBorder); // store the fonts Font font = titleLabel.getFont(); selectedLabelFont = font.deriveFont(Font.BOLD); labelFont = font.deriveFont(Font.PLAIN); titleLabel.setFont(selectedLabelFont); JPanel rightContentPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridy++; gbc.gridx = 0; gbc.insets.top = 5; gbc.insets.left = 5; gbc.insets.right = 5; gbc.insets.bottom = 0; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.NORTHWEST; rightContentPanel.add(titleLabel, gbc); gbc.gridy++; gbc.weighty = 1.0; gbc.insets.bottom = 5; gbc.fill = GridBagConstraints.BOTH; rightContentPanel.add(rightPanel, gbc); // setup the left panel JLabel stepsLabel = new JLabel("Steps", JLabel.LEFT); stepsLabel.setOpaque(false); stepsLabel.setBorder(labelBorder); stepsLabel.setFont(selectedLabelFont); leftPanel = new JPanel(); leftPanel.setOpaque(false); leftPanel.setPreferredSize(new Dimension(170, getHeight())); leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS)); JPanel leftContentPanel = new StepListPanel(new GridBagLayout()); gbc.gridy = 0; gbc.weighty = 0; gbc.insets.bottom = 0; gbc.fill = GridBagConstraints.HORIZONTAL; leftContentPanel.add(stepsLabel, gbc); gbc.gridy++; gbc.weighty = 1.0; gbc.insets.bottom = 5; gbc.fill = GridBagConstraints.BOTH; leftContentPanel.add(leftPanel, gbc); // add the panels to the base JPanel base = new JPanel(new BorderLayout()); base.add(leftContentPanel, BorderLayout.WEST); base.add(rightContentPanel, BorderLayout.CENTER); add(base, BorderLayout.CENTER); // setup the button panel nextButton = new JButton("Next"); nextButton.setMnemonic('N'); backButton = new JButton("Back"); backButton.setMnemonic('B'); cancelButton = new JButton("Cancel"); cancelButton.setMnemonic('C'); nextButton.addActionListener(this); backButton.addActionListener(this); cancelButton.addActionListener(this); helpButton = new JButton("Help"); helpButton.setMnemonic('H'); Dimension btnDim = new Dimension(75,25); nextButton.setPreferredSize(btnDim); backButton.setPreferredSize(btnDim); cancelButton.setPreferredSize(btnDim); helpButton.setPreferredSize(btnDim); Insets buttonInsets = new Insets(2, 2, 2, 2); nextButton.setMargin(buttonInsets); backButton.setMargin(buttonInsets); cancelButton.setMargin(buttonInsets); backButton.setEnabled(false); JPanel buttonPanel = new JPanel(new GridBagLayout()); gbc.gridy = 0; gbc.gridx = 0; gbc.insets.left = 5; gbc.insets.top = 7; gbc.insets.bottom = 5; gbc.insets.right = 0; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; gbc.weighty = 0; gbc.weightx = 0.5; buttonPanel.add(helpButton, gbc); gbc.anchor = GridBagConstraints.EAST; gbc.gridx = 1; gbc.weightx = 0; gbc.insets.left = 7; buttonPanel.add(backButton, gbc); gbc.gridx = 2; buttonPanel.add(nextButton, gbc); gbc.gridx = 3; gbc.insets.right = 5; buttonPanel.add(cancelButton, gbc); // add a border to the button panel buttonPanel.setBorder( BorderFactory.createMatteBorder(1, 0, 0, 0, UIManager.getColor("controlDkShadow"))); add(buttonPanel, BorderLayout.SOUTH); } protected void prepare() { // setup the step labels String[] steps = model.getSteps(); stepLabels = new ArrayList<JLabel>(steps.length); for (int i = 0; i < steps.length; i++) { JLabel label = new WizardStepLabel(i + 1, steps[i]); label.setFont(labelFont); leftPanel.add(label); stepLabels.add(label); } // prepare the first panel setTitleLabelText(model.getTitle(0)); rightPanel.add(model.getPanelAt(0), String.valueOf(0)); cardLayout.first(rightPanel); setSelectedStep(0); } /** * Reformats the label display at the specified index. * * @param index - the label index */ protected void setSelectedStep(int index) { for (int i = 0, n = stepLabels.size(); i < n; i++) { JLabel label = stepLabels.get(i); if (i != index) { label.setFont(labelFont); } else { label.setFont(selectedLabelFont); } } } /** * Sets the action for the help button to that specified. * * @param a - the help action to be applied
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -