/* * $Id: SidePaneDemo.java,v 1.7 2005/11/23 05:14:55 zfq Exp $ * * Copyright (C) 2001-2003 Extreme Component, Inc. All rights reserved. * Use is subject to license terms. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; import com.zfqjava.swing.JSidePane; import com.zfqjava.swing.ModelFactory; import com.zfqjava.swing.ValueAction; import com.zfqjava.swing.JBean; import com.zfqjava.swing.JCommonPane; /** * JSidePane Demo * * @author $Author: zfq $ * @version $Revision: 1.7 $ $Date: 2005/11/23 05:14:55 $ */ public class SidePaneDemo extends JPanel { private static final String[] A = { "Alice", "Bob", "Mike", "Scott" }; private JSidePane sidePane; public SidePaneDemo() { super(new BorderLayout()); sidePane = createSidePane(); add(sidePane, BorderLayout.CENTER); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(createPropertyPanel(), BorderLayout.NORTH); panel.add(createDialogPanel(), BorderLayout.SOUTH); add(panel, BorderLayout.EAST); } private JSidePane createSidePane() { JSidePane sidePane = new JSidePane(); sidePane.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); sidePane.addGroup(new JTree(), new ValueAction("tree")); sidePane.addGroup(new JList(ModelFactory.createListModel(A))); sidePane.addGroup(new JTree(), new ValueAction("dir")); sidePane.addGroup(new JTree(), new ValueAction("file")); return sidePane; } private JPanel createPropertyPanel() { JPanel panel = new JPanel(); Border titledBorder = BorderFactory.createTitledBorder("Change Property"); Border emptyBorder = BorderFactory.createEmptyBorder(12, 12, 12, 12); panel.setBorder(BorderFactory.createCompoundBorder(titledBorder, emptyBorder)); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); panel.setLayout(gridbag); c.weightx = 0.5; c.weighty = 0.5; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(0, 0, 5, 0); JLabel label = new JLabel("Selection Mode: "); addPanel(panel, c, label); Object[] headStyles = { "Single Selection", "Multiple Selection" }; final JComboBox headStyleCB = new JComboBox(headStyles); headStyleCB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int index = headStyleCB.getSelectedIndex(); if(index == 0) { sidePane.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else { sidePane.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } } }); label.setLabelFor(headStyleCB); c.gridwidth = GridBagConstraints.REMAINDER; addPanel(panel, c, headStyleCB); return panel; } private JPanel createDialogPanel() { JPanel panel = new JPanel(); Border titledBorder = BorderFactory.createTitledBorder("Dialog and Frame"); Border emptyBorder = BorderFactory.createEmptyBorder(12, 12, 12, 12); panel.setBorder(BorderFactory.createCompoundBorder(titledBorder, emptyBorder)); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); panel.setLayout(gridbag); // c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.CENTER; c.insets = new Insets(0, 0, 5, 0); c.gridwidth = GridBagConstraints.REMAINDER; JButton b = new JButton("Show Frame"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFrame frame = new JFrame("JSidePane"); frame.getContentPane().add(createSidePane()); frame.pack(); centerOnScreen(frame); frame.show(); } }); addPanel(panel, c, b); return panel; } private static void addPanel(Container container, GridBagConstraints c, Component component) { GridBagLayout gridbag = (GridBagLayout)container.getLayout(); gridbag.setConstraints(component, c); container.add(component); } public static void main(String[] args) { DemoPanel demoPanel = new DemoPanel(); demoPanel.addDemo(new SidePaneDemo()); demoPanel.setTitle("JSidePane Demo"); demoPanel.setDefaultCloseOperation(JBean.EXIT_ON_CLOSE); demoPanel.showFrame(); } private static void centerOnScreen(Window window) { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); window.setLocation((d.width - window.getWidth())/2, (d.height - window.getHeight())/2); } }