📄 demopanel.java
字号:
/* ==================================================================== * * Skin Look And Feel 6.7 License. * * Copyright (c) 2000-2006 L2FProd.com. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by L2FProd.com * (http://www.L2FProd.com/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "Skin Look And Feel", "SkinLF" and "L2FProd.com" must not * be used to endorse or promote products derived from this software * without prior written permission. For written permission, please * contact info@L2FProd.com. * * 5. Products derived from this software may not be called "SkinLF" * nor may "SkinLF" appear in their names without prior written * permission of L2FProd.com. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL L2FPROD.COM OR ITS CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== */package examples;import com.l2fprod.gui.plaf.skin.SkinLookAndFeel;import com.l2fprod.util.AccessUtils;import com.l2fprod.util.OS;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyVetoException;import java.beans.VetoableChangeListener;import java.util.Enumeration;import javax.swing.*;import javax.swing.border.Border;import javax.swing.border.EmptyBorder;import javax.swing.table.AbstractTableModel;import javax.swing.table.DefaultTableCellRenderer;import javax.swing.table.TableCellRenderer;import javax.swing.table.TableColumn;/** * Simple Test Panel for a Look And Feel * * @author $Author: l2fprod $ * @created 27 avril 2002 * @version $Revision: 1.12 $, $Date: 2006/07/22 11:41:19 $ */public class demoPanel extends JPanel { demoWelcome m_Welcome; /** * Constructor for the demoPanel object * * @param themes Description of Parameter */ public demoPanel(String[] themes) { setLayout(new BorderLayout(3, 3)); // Create the menu bar JMenuBar menubar = new JMenuBar(); JMenu menu = new JMenu("File"); menu.setMnemonic('f'); menu.add(new JMenuItem("Save")); menu.add( new AbstractAction("Open") { public void actionPerformed(ActionEvent event) { try { // are we running in JavaWebStart? Class serviceClass = Class.forName("javax.jnlp.ServiceManager"); Object fileOpenService = serviceClass. getMethod("lookup", new Class[]{String.class}). invoke(null, new Object[]{"javax.jnlp.FileOpenService"}); fileOpenService.getClass(). getMethod("openFileDialog", new Class[]{String.class, String[].class}). invoke(fileOpenService, new Object[]{null, null}); } catch (Exception e) { System.err.println("Error trying JavaWebStart, will default to JFileChooser:" + e.getMessage()); JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); if (JFileChooser.APPROVE_OPTION==chooser.showDialog(demoPanel.this, "Ok")) { JOptionPane.showMessageDialog(demoPanel.this, "You selected " + chooser.getSelectedFile()); } else { JOptionPane.showMessageDialog(demoPanel.this, "You pressed Cancel"); } } } }); menu.addSeparator(); JMenuItem item = new JMenuItem("Exit"); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { exit(); } }); menu.add(item); menubar.add(menu); menu = new JMenu("Edit"); menu.setMnemonic('e'); menu.add(new JCheckBoxMenuItem("CheckBoxMenu Item (selected)", true)); menu.add(new JCheckBoxMenuItem("CheckBoxMenu Item (unselected)")); menu.addSeparator(); menu.add(new JCheckBoxMenuItem("CheckBoxMenu Item (disabled/selected)", true)).setEnabled(false); menu.add(new JCheckBoxMenuItem("CheckBoxMenu Item (disabled/unselected)")).setEnabled(false); menu.addSeparator(); menu.add(new JRadioButtonMenuItem("RadioButtonMenu Item (selected)", true)); menu.add(new JRadioButtonMenuItem("RadioButtonMenu Item (unselected)")); menu.addSeparator(); menu.add(new JRadioButtonMenuItem("RadioButtonMenu Item (disabled/selected)", true)).setEnabled(false); menu.add(new JRadioButtonMenuItem("RadioButtonMenu Item (disabled/unselected)")).setEnabled(false); menubar.add(menu); add("North", menubar); JPanel buttonPane = new JPanel(new VerticalLayout(3)); JButton button = new JButton("Rollover"); ButtonModel model = new DefaultButtonModel() { public boolean isSelected() { return true; } public boolean isRollover() { return true; } }; button.setModel(model); buttonPane.add(button); buttonPane.add(button = new JButton("Normal")); button.setBackground(Color.green); button = new JButton("Pressed"); button.setForeground(Color.red); model = new DefaultButtonModel() { public boolean isPressed() { return true; } public boolean isArmed() { return true; } public boolean isSelected() { return true; } }; button.setModel(model); buttonPane.add(button); button = new JButton("Disabled"); button.setEnabled(false); buttonPane.add(button); buttonPane.add(new JButton("<html><b>With HTML</b></html>")); JPanel common = new JPanel(new GridLayout(5, 2)); JCheckBox check = new JCheckBox("Check", true); common.add(check); JRadioButton select = new JRadioButton("Select", true); common.add(select); check = new JCheckBox("<html>Check box<br>with<br>multiple lines", false); check.setBackground(Color.red); common.add(check); select = new JRadioButton("Select", false); common.add(select); check = new JCheckBox("Check", true); check.setEnabled(false); common.add(check); select = new JRadioButton("Select", true); select.setEnabled(false); common.add(select); check = new JCheckBox("Check", false); check.setEnabled(false); common.add(check); select = new JRadioButton("Select", false); select.setEnabled(false); common.add(select); ButtonGroup toggleGroup = new ButtonGroup(); JToggleButton toggle = new JToggleButton("Standard Toggle", true); common.add(toggle); toggleGroup.add(toggle); toggle = new JToggleButton("<html><i>With</i><b>HTML</b>"); common.add(toggle); toggleGroup.add(toggle); JPanel grid = new JPanel(new GridLayout(OS.isOneDotFour()?3:2, 1)); // add the progress bar with indeterminate state if JDK1.4 if (OS.isOneDotFour()) { JProgressBar indeterminate = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100); AccessUtils.invoke(indeterminate, "setIndeterminate", new Class[]{boolean.class}, new Object[]{Boolean.TRUE}); grid.add(indeterminate); } JProgressBar progress = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100); progress.setValue(75); progress.setPreferredSize(new Dimension(10, 25)); JSlider slider = new JSlider(progress.getModel()); slider.setPaintTicks(true); grid.add(progress); grid.add(slider); JPanel mainPane = new BasePanel(new BorderLayout(3, 3)); mainPane.add("North", new MemoryPanel()); mainPane.add("Center", common); mainPane.add("South", grid); mainPane.add("East", buttonPane); mainPane.setBorder(new EmptyBorder(10, 10, 10, 10)); final JTabbedPane tabs = new JTabbedPane(); tabs.addTab("SkinLF", m_Welcome = new demoWelcome(themes)); tabs.addTab("Common", mainPane); tabs.addTab("Unselected", new BasePanel(new JScrollPane(new JTree()))); tabs.addTab("Disabled", new JPanel()); tabs.addTab("InternalFrame", new InternalTest()); tabs.addTab("TextComponent", new TextTest()); tabs.addTab("Combo and List", new ComboList()); tabs.addTab("Table", new TablePanel()); tabs.addTab("List", new ListPanel()); tabs.addTab("Split", new SplitTest()); tabs.addTab("Chooser", new ChooserPanel()); tabs.setEnabledAt(3, false); JMenu tabPlacement = new JMenu("Tab Placement"); tabPlacement.setMnemonic('t'); tabPlacement.add( new AbstractAction("TOP") { public void actionPerformed(ActionEvent event) { tabs.setTabPlacement(JTabbedPane.TOP); } }); tabPlacement.add( new AbstractAction("BOTTOM") { public void actionPerformed(ActionEvent event) { tabs.setTabPlacement(JTabbedPane.BOTTOM); } }); tabPlacement.add( new AbstractAction("LEFT") { public void actionPerformed(ActionEvent event) { tabs.setTabPlacement(JTabbedPane.LEFT); } }); tabPlacement.add( new AbstractAction("RIGHT") { public void actionPerformed(ActionEvent event) { tabs.setTabPlacement(JTabbedPane.RIGHT); } }); menubar.add(tabPlacement); add("Center", tabs); JScrollBar hsb = new JScrollBar(JScrollBar.HORIZONTAL, 50, 20, 0, 100); add("South", hsb); JScrollBar vsb = new JScrollBar(JScrollBar.VERTICAL, 50, 20, 0, 100); add("East", vsb); JProgressBar vprogress = new JProgressBar(JProgressBar.VERTICAL, 0, 100); vprogress.setModel(progress.getModel()); vprogress.setPreferredSize(new Dimension(25, 10)); add("West", vprogress); menu = new JMenu("Help"); menu.setMnemonic('h'); menu.setToolTipText("Show the help!"); menu.add( new AbstractAction("About " + SkinLookAndFeel.version()) { public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog(demoPanel.this, "SkinLookAndFeel " + SkinLookAndFeel.version() + " build " + SkinLookAndFeel.date() + "\n" + "(c) 2000-2006 L2FProd.com"); } }); menubar.add(menu); } /** * Description of the Method */ void exit() { System.exit(0); } final static Border EMPTY_BORDER = new EmptyBorder(4,4,4,4); static class BasePanel extends JPanel { public BasePanel() { super(); setBorder(EMPTY_BORDER); } public BasePanel(LayoutManager p_Layout) { super(p_Layout); setBorder(EMPTY_BORDER); } public BasePanel(Component c) { this(new BorderLayout()); add("Center", c); } } /** * Description of the Class * * @author fred * @created 27 avril 2002 */ static class MemoryPanel extends JPanel { /** * Constructor for the MemoryPanel object */ MemoryPanel() { setLayout(new FlowLayout(FlowLayout.LEFT)); JButton b = new JButton("gc()"); b.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { Runtime.getRuntime().gc(); } }); add(b); final JLabel memory; add(memory = new JLabel(" ")); Timer t = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { memory.setText(" Free: " + Runtime.getRuntime().freeMemory() + " Total: " + Runtime.getRuntime().totalMemory()); } }); t.setRepeats(true); t.start(); } } /** * Description of the Class * * @author fred * @created 27 avril 2002 */ static class SplitTest extends BasePanel { /** * Constructor for the SplitTest object */ SplitTest() { setLayout(new BorderLayout()); JButton button; final JSplitPane innerSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(new JTree()), button = new JButton("Split!")); final JSplitPane split1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(new JTree()), innerSplit); add("Center", split1); innerSplit.setBorder(null); split1.setBorder(null);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -