I redesigned the Swing demo a little. What I did:
1. throw away the 'XXXWorld' tabbed pane in the center.
2. 'Outsourced' the XXXWorld stuff in separate demos just like the
other demos. This is TreeDemo, ListDemo and TabbedPaneDemo. The
ButtonWorld and DesktopWorld are no longer there. IMO the ButtonWorld
was quite useless and confusing. Eventually we would write a BorderDemo
to replace it. The DesktopWorld is replaced by point#3
3. Added a desktop. This desktop shows a GNU Classpath badge in the
middle.
4. Made the subdemos appear as internal frames inside the new desktop.
IMO this makes the Swing activity board more clear. Eventually we should
move all those buttons in the toolbar with icons instead of labels. But
that is not that important.
Note that I added a PNG file (the GNU Classpath badge). I hope it shows
up for everybody. Otherwise the Makefiles must be tweaked a little so
that png files are included in the examples.zip. I must say that I
always start the demo without the examples.zip so I have no problems
there.
2006-03-15 Roman Kennke <[EMAIL PROTECTED]>
* examples/gnu/classpath/examples/swing/Demo.java:
(desktop): New field.
(mkMenuBar): Added new subdemos.
(mkButtonWorld): Removed.
(CheckCellRenderer): Moved to ListDemo.
(LabelCellRenderer): Moved to ListDemo.
(mkTreeWorld): Moved to TreeDemo.
(mkDesktopWorld): Removed.
(mkTabWorld): Moved to TabbedPaneDemo.
(mkTabbedPane): Removed.
(Demo): Replaced 'worlds' tabbed pane with desktop.
(PopupAction): Made class non-static.
(PopupAction.actionPerformed): Bring up subdemos in internal
frame.
(mkButtonBar): Added new demos.
(createDesktop): New method.
* examples/gnu/classpath/examples/swing/DemoDesktop.java: New
class.
* examples/gnu/classpath/examples/swing/ListDemo.java: New demo.
* examples/gnu/classpath/examples/swing/TreeDemo.java: New demo.
* examples/gnu/classpath/examples/swing/TabbedPaneDemo.java: New
demo.
* examples/gnu/classpath/examples/swing/badge.png: New image file.
/Roman
Index: examples/gnu/classpath/examples/swing/Demo.java
===================================================================
RCS file: /cvsroot/classpath/classpath/examples/gnu/classpath/examples/swing/Demo.java,v
retrieving revision 1.37
diff -u -r1.37 Demo.java
--- examples/gnu/classpath/examples/swing/Demo.java 15 Mar 2006 11:18:05 -0000 1.37
+++ examples/gnu/classpath/examples/swing/Demo.java 15 Mar 2006 16:39:15 -0000
@@ -27,7 +27,6 @@
import javax.swing.*;
import javax.swing.tree.*;
-import javax.swing.border.*;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;
@@ -39,6 +38,13 @@
public class Demo
{
JFrame frame;
+
+ /**
+ * The main desktop. This is package private to avoid synthetic accessor
+ * method.
+ */
+ JDesktopPane desktop;
+
static Color blueGray = new Color(0xdc, 0xda, 0xd5);
private static Icon stockIcon(String s)
@@ -129,6 +135,12 @@
examples.add(new JMenuItem(new PopupAction("Table",
TableDemo.createDemoFactory())));
+ examples.add(new JMenuItem(new PopupAction("List",
+ ListDemo.createDemoFactory())));
+ examples.add(new JMenuItem(new PopupAction("TabbedPane",
+ TabbedPaneDemo.createDemoFactory())));
+ examples.add(new JMenuItem(new PopupAction("Tree",
+ TreeDemo.createDemoFactory())));
final JMenuItem vmMenu;
@@ -277,92 +289,6 @@
}
- static JPanel mkButtonWorld()
- {
- Icon ii = bigStockIcon("home");
- int CENTER = SwingConstants.CENTER;
- int TOP = SwingConstants.TOP;
- int BOTTOM = SwingConstants.BOTTOM;
-
- int[] valigns = new int[] {SwingConstants.CENTER,
- SwingConstants.TOP,
- SwingConstants.BOTTOM};
-
- int[] haligns = new int[] {SwingConstants.CENTER,
- SwingConstants.RIGHT,
- SwingConstants.LEFT};
-
- Border[] borders = new Border[] {
- new SoftBevelBorder(BevelBorder.RAISED),
- new SoftBevelBorder(BevelBorder.LOWERED),
- new BevelBorder(BevelBorder.RAISED),
-
- LineBorder.createBlackLineBorder(),
- new MatteBorder(2, 2, 2, 2, Color.GREEN),
- LineBorder.createGrayLineBorder(),
-
- new BevelBorder(BevelBorder.LOWERED),
- new EtchedBorder(EtchedBorder.RAISED),
- new EtchedBorder(EtchedBorder.LOWERED)
- };
-
- JComponent[] comps = new JComponent[3*3];
-
- int q = 0;
-
- JPanel panel = new JPanel();
- panel.setLayout(new GridLayout(3, 3));
-
- for (int i = 0; i < 3; ++i)
- for (int j = 0; j < 3; ++j)
- {
- JButton b = mkButton(halign2str(haligns[i])
- + valign2str(valigns[j]),
- ii,
- -1, -1, haligns[i], valigns[j]);
- b.setBorder(borders[q++]);
- JPanel tmp = new JPanel();
- tmp.setBorder(new MatteBorder(5, 5, 5, 5, blueGray));
- tmp.add(b);
- panel.add(tmp);
- }
-
- return panel;
- }
-
- private static class CheckCellRenderer
- extends JCheckBox implements ListCellRenderer
- {
- public Component getListCellRendererComponent(JList list,
- Object value,
- int index,
- boolean isSelected,
- boolean cellHasFocus)
- {
- setSelected(isSelected);
- setText(value.toString());
-
- return this;
- }
- }
-
- private static class LabelCellRenderer
- extends DefaultListCellRenderer
- {
- public Component getListCellRendererComponent(JList list,
- Object value,
- int index,
- boolean isSelected,
- boolean cellHasFocus)
- {
- Component c = super.getListCellRendererComponent(list, value, index,
- isSelected,
- cellHasFocus);
-
- return c;
- }
- }
-
private static JScrollPane mkScrollPane(JComponent inner)
{
JScrollPane jsp;
@@ -373,261 +299,6 @@
return jsp;
}
- private static JPanel mkTreeWorld()
- {
- // non-leafs
- DefaultMutableTreeNode root = new DefaultMutableTreeNode("Exotic Subsistence");
- DefaultMutableTreeNode fruit = new DefaultMutableTreeNode("Interesting Fruit");
- DefaultMutableTreeNode veg = new DefaultMutableTreeNode("Extraordinary Vegetables");
- DefaultMutableTreeNode liq = new DefaultMutableTreeNode("Peculiar Liquids");
-
- // leafs
- DefaultMutableTreeNode f1 = new DefaultMutableTreeNode("Abiu");
- DefaultMutableTreeNode f2 = new DefaultMutableTreeNode("Bamboo Shoots");
- DefaultMutableTreeNode f3 = new DefaultMutableTreeNode("Breadfruit");
- DefaultMutableTreeNode f4 = new DefaultMutableTreeNode("Canistel");
- DefaultMutableTreeNode f5 = new DefaultMutableTreeNode("Duku");
- DefaultMutableTreeNode f6 = new DefaultMutableTreeNode("Guava");
- DefaultMutableTreeNode f7 = new DefaultMutableTreeNode("Jakfruit");
- DefaultMutableTreeNode f8 = new DefaultMutableTreeNode("Quaribea");
-
- DefaultMutableTreeNode v1 = new DefaultMutableTreeNode("Amaranth");
- DefaultMutableTreeNode v2 = new DefaultMutableTreeNode("Kiwano");
- DefaultMutableTreeNode v3 = new DefaultMutableTreeNode("Leeks");
- DefaultMutableTreeNode v4 = new DefaultMutableTreeNode("Luffa");
- DefaultMutableTreeNode v5 = new DefaultMutableTreeNode("Chayote");
- DefaultMutableTreeNode v6 = new DefaultMutableTreeNode("Jicama");
- DefaultMutableTreeNode v7 = new DefaultMutableTreeNode("Okra");
-
- DefaultMutableTreeNode l1 = new DefaultMutableTreeNode("Alcoholic");
- DefaultMutableTreeNode l11 = new DefaultMutableTreeNode("Caipirinha");
- DefaultMutableTreeNode l21 = new DefaultMutableTreeNode("Mojito");
- DefaultMutableTreeNode l31 = new DefaultMutableTreeNode("Margarita");
- DefaultMutableTreeNode l41 = new DefaultMutableTreeNode("Martini");
- DefaultMutableTreeNode l5 = new DefaultMutableTreeNode("Non Alcoholic");
- DefaultMutableTreeNode l55 = new DefaultMutableTreeNode("Babaji");
- DefaultMutableTreeNode l65 = new DefaultMutableTreeNode("Chikita");
-
- root.add(fruit);
- root.add(veg);
- root.add(liq);
- fruit.add(f1);
- fruit.add(f2);
- fruit.add(f3);
- fruit.add(f4);
- fruit.add(f5);
- fruit.add(f6);
- fruit.add(f7);
- fruit.add(f8);
- veg.add(v1);
- veg.add(v2);
- veg.add(v3);
- veg.add(v4);
- veg.add(v5);
- veg.add(v6);
- veg.add(v7);
- liq.add(l1);
- l1.add(l11);
- l1.add(l21);
- l1.add(l31);
- l1.add(l41);
- liq.add(l5);
- l5.add(l55);
- l5.add(l65);
-
- final JTree tree = new JTree(root);
- tree.setLargeModel(true);
- tree.setEditable(true);
- DefaultTreeSelectionModel dtsm = new DefaultTreeSelectionModel();
- dtsm.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
- tree.setSelectionModel(dtsm);
-
- // buttons to add and delete
- JButton add = mkButton("add element");
- add.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- for (int i = 0; i < tree.getRowCount(); i++)
- {
- if (tree.isRowSelected(i))
- {
- TreePath p = tree.getPathForRow(i);
- DefaultMutableTreeNode n = (DefaultMutableTreeNode) p.
- getLastPathComponent();
- n.add(new DefaultMutableTreeNode("New Element"));
- tree.repaint();
- break;
- }
- }
- }
- });
-
-
- JPanel p1 = new JPanel();
- p1.setLayout(new BorderLayout());
-
- JPanel p2 = new JPanel();
- p2.add(add);
-
- p1.add(p2, BorderLayout.NORTH);
- p1.add(mkScrollPane(tree), BorderLayout.CENTER);
-
- return p1;
- }
-
- public static JPanel mkListWorld()
- {
-
- String foo[] = new String[] {
- "non alcoholic ",
- "carbonated ",
- "malted ",
- "fresh squeezed ",
- "imported ",
- "high fructose ",
- "enriched "
- };
-
- String bar[] = new String[] {
- "orange juice",
- "ginger beer",
- "yak milk",
- "corn syrup",
- "herbal remedy"
- };
-
- final DefaultListModel mod = new DefaultListModel();
- final JList list1 = new JList(mod);
- final JList list2 = new JList(mod);
-
- list2.setSelectionModel(list1.getSelectionModel());
- for (int i = 0; i < bar.length; ++i)
- for (int j = 0; j < foo.length; ++j)
- mod.addElement(foo[j] + bar[i]);
-
- list1.setCellRenderer(new LabelCellRenderer());
- list2.setCellRenderer(new CheckCellRenderer());
-
- JButton add = mkButton("add element");
- add.addActionListener(new ActionListener()
- {
- int i = 0;
- public void actionPerformed(ActionEvent e)
- {
- mod.addElement("new element " + i);
- ++i;
- }
- });
-
- JButton del = mkButton("delete selected");
- del.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- for (int i = 0; i < mod.getSize(); ++i)
- if (list1.isSelectedIndex(i))
- mod.remove(i);
- }
- });
-
-
- JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
- splitter.add(mkScrollPane(list1), JSplitPane.LEFT);
- splitter.add(mkScrollPane(list2), JSplitPane.RIGHT);
-
- JPanel p1 = new JPanel();
- p1.setLayout(new BorderLayout());
-
- JPanel p2 = new JPanel();
- p2.setLayout(new GridLayout(1, 2));
- p2.add(add);
- p2.add(del);
-
- p1.add(p2, BorderLayout.NORTH);
- p1.add(splitter, BorderLayout.CENTER);
- return p1;
- }
-
-
- static JPanel mkDesktopWorld()
- {
-
- final JDesktopPane desk = new JDesktopPane();
- desk.setDesktopManager(new DefaultDesktopManager());
- desk.setPreferredSize(new Dimension(300,300));
- desk.setMinimumSize(new Dimension(300,300));
- JButton but = mkButton("add frame");
- but.addActionListener(new ActionListener()
- {
- int i = 10;
- public void actionPerformed(ActionEvent e)
- {
- JInternalFrame f;
- f = new JInternalFrame("internal", true, true, true, true);
- f.getContentPane().setLayout(new BorderLayout());
- f.getContentPane().add(mkToolBar(), BorderLayout.NORTH);
- f.getContentPane().add(mkButton(bigStockIcon("fullscreen")),
- BorderLayout.CENTER);
- desk.add(f);
- f.setBounds(i, i, 250, 200);
- f.setVisible(true);
- i += 30;
- }
- });
-
- JPanel panel = new JPanel();
- panel.setLayout(new BorderLayout());
- panel.add(desk, BorderLayout.CENTER);
- panel.add(but, BorderLayout.NORTH);
- but.doClick();
- but.doClick();
- JInternalFrame palette = new JInternalFrame("Palette", true, true, true,
- true);
- palette.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
- desk.add(palette, JDesktopPane.PALETTE_LAYER);
- JLabel label = new JLabel("This is a floating palette!");
- palette.getContentPane().add(label);
- palette.pack();
- palette.setVisible(true);
- return panel;
- }
-
- static JPanel mkTabWorld()
- {
- JPanel panel = new JPanel(new GridLayout(2, 2));
- panel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
- JTabbedPane tabs1 = new JTabbedPane(SwingConstants.TOP);
- tabs1.add("Top Item 1", new JButton("Button"));
- tabs1.add("Top Item 2", new JButton("Button"));
- JTabbedPane tabs2 = new JTabbedPane(SwingConstants.LEFT);
- tabs2.add("Left Item 1", new JButton("Button"));
- tabs2.add("Left Item 2", new JButton("Button"));
- JTabbedPane tabs3 = new JTabbedPane(SwingConstants.BOTTOM);
- tabs3.add("Bottom Item 1", new JButton("Button"));
- tabs3.add("Bottom Item 2", new JButton("Button"));
- JTabbedPane tabs4 = new JTabbedPane(SwingConstants.RIGHT);
- tabs4.add("Right Item 1", new JButton("Button"));
- tabs4.add("Right Item 2", new JButton("Button"));
- panel.add(tabs1);
- panel.add(tabs2);
- panel.add(tabs3);
- panel.add(tabs4);
- return panel;
- }
-
- static JTabbedPane mkTabbedPane()
- {
- JTabbedPane tabs = new JTabbedPane();
-
- tabs.add("Button world!", mkButtonWorld());
- tabs.add("List world!", mkListWorld());
- tabs.add("Desktop world!", mkDesktopWorld());
- tabs.add("Tree world!", mkTreeWorld());
- tabs.add("Tab world!", mkTabWorld());
- return tabs;
- }
-
public Demo()
{
frame = new JFrame("Swing Activity Board");
@@ -637,7 +308,8 @@
component.add(mkToolBar(), BorderLayout.NORTH);
JPanel main = new JPanel();
main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
- main.add(mkTabbedPane());
+ desktop = createDesktop();
+ main.add(desktop);
main.add(mkButtonBar());
component.add(main, BorderLayout.CENTER);
frame.pack();
@@ -696,7 +368,7 @@
/**
* This action brings up a new Window with the specified content.
*/
- private static class PopupAction
+ private class PopupAction
extends AbstractAction
{
/**
@@ -725,17 +397,15 @@
*/
public void actionPerformed(ActionEvent e)
{
- JFrame frame = new JFrame((String) getValue(NAME));
- frame.getContentPane().setLayout(new BorderLayout());
- frame.getContentPane().add(demoFactory.createDemo(),
- BorderLayout.CENTER);
- frame.getContentPane().add(mkDisposerButton(frame), BorderLayout.SOUTH);
+ JInternalFrame frame = new JInternalFrame((String) getValue(NAME));
+ frame.setClosable(true);
+ frame.setIconifiable(true);
+ frame.setMaximizable(true);
+ frame.setResizable(true);
+ frame.setContentPane(demoFactory.createDemo());
frame.pack();
- // TODO: Maybe find a more elegant solution to the problem that the
- // component stored in the PopupAction must at some point have
- // its theme updated.
- SwingUtilities.updateComponentTreeUI(frame);
- frame.show();
+ desktop.add(frame);
+ frame.setVisible(true);
}
}
@@ -808,6 +478,12 @@
ComboBoxDemo.createDemoFactory())));
panel.add(new JButton(new PopupAction("Table",
TableDemo.createDemoFactory())));
+ panel.add(new JButton(new PopupAction("List",
+ ListDemo.createDemoFactory())));
+ panel.add(new JButton(new PopupAction("TabbedPane",
+ TabbedPaneDemo.createDemoFactory())));
+ panel.add(new JButton(new PopupAction("Tree",
+ TreeDemo.createDemoFactory())));
JButton exitDisposer = mkDisposerButton(frame);
panel.add(exitDisposer);
exitDisposer.addActionListener(new ActionListener()
@@ -821,6 +497,18 @@
}
/**
+ * Creates and returns the main desktop.
+ *
+ * @return the main desktop
+ */
+ private JDesktopPane createDesktop()
+ {
+ JDesktopPane d = new DemoDesktop();
+ d.setPreferredSize(new Dimension(900, 500));
+ return d;
+ }
+
+ /**
* This Action is used to switch Metal themes.
*/
class ChangeThemeAction extends AbstractAction
Index: examples/gnu/classpath/examples/swing/DemoDesktop.java
===================================================================
RCS file: examples/gnu/classpath/examples/swing/DemoDesktop.java
diff -N examples/gnu/classpath/examples/swing/DemoDesktop.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ examples/gnu/classpath/examples/swing/DemoDesktop.java 15 Mar 2006 16:39:15 -0000
@@ -0,0 +1,81 @@
+/* DemoDesktop.java -- A custom desktop for the demo
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath 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, or (at your option)
+any later version.
+
+GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.classpath.examples.swing;
+
+import java.awt.Graphics;
+
+import javax.swing.ImageIcon;
+import javax.swing.JDesktopPane;
+
+/**
+ * A customized Desktop for the GNU Classpath Swing demo that paints the
+ * GNU Classpath Icon in the middle of the desktop.
+ *
+ * @author Roman Kennke ([EMAIL PROTECTED])
+ */
+public class DemoDesktop
+ extends JDesktopPane
+{
+
+ /**
+ * The icon that's painted centered on the desktop.
+ */
+ private ImageIcon image;
+
+ /**
+ * Creates a new desktop.
+ */
+ DemoDesktop()
+ {
+ super();
+ image = new ImageIcon(getClass().getResource("badge.png"));
+ }
+
+ /**
+ * Paints the desktop including the icon.
+ *
+ * @param g the graphics to use for painting
+ */
+ protected void paintComponent(Graphics g)
+ {
+ super.paintComponent(g);
+ image.paintIcon(this, g, (getWidth() - image.getIconWidth()) / 2,
+ (getHeight() - image.getIconHeight()) / 2);
+ }
+}
Index: examples/gnu/classpath/examples/swing/ListDemo.java
===================================================================
RCS file: examples/gnu/classpath/examples/swing/ListDemo.java
diff -N examples/gnu/classpath/examples/swing/ListDemo.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ examples/gnu/classpath/examples/swing/ListDemo.java 15 Mar 2006 16:39:15 -0000
@@ -0,0 +1,231 @@
+/* ListDemo.java -- Demostrates JList
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath 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, or (at your option)
+any later version.
+
+GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.classpath.examples.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.ListCellRenderer;
+import javax.swing.SwingUtilities;
+
+public class ListDemo
+ extends JPanel
+ implements ActionListener
+{
+
+ private static class LabelCellRenderer
+ extends DefaultListCellRenderer
+ {
+ public Component getListCellRendererComponent(JList list,
+ Object value,
+ int index,
+ boolean isSelected,
+ boolean cellHasFocus)
+ {
+ Component c = super.getListCellRendererComponent(list, value, index,
+ isSelected,
+ cellHasFocus);
+ return c;
+ }
+ }
+
+ private static class CheckCellRenderer
+ extends JCheckBox
+ implements ListCellRenderer
+ {
+ public Component getListCellRendererComponent(JList list,
+ Object value,
+ int index,
+ boolean isSelected,
+ boolean cellHasFocus)
+ {
+ setSelected(isSelected);
+ setText(value.toString());
+
+ return this;
+ }
+ }
+
+ ListDemo()
+ {
+ super();
+ createContent();
+ }
+
+ private void createContent()
+ {
+
+ String foo[] = new String[] {
+ "non alcoholic ",
+ "carbonated ",
+ "malted ",
+ "fresh squeezed ",
+ "imported ",
+ "high fructose ",
+ "enriched "
+ };
+
+ String bar[] = new String[] {
+ "orange juice",
+ "ginger beer",
+ "yak milk",
+ "corn syrup",
+ "herbal remedy"
+ };
+
+ final DefaultListModel mod = new DefaultListModel();
+ final JList list1 = new JList(mod);
+ final JList list2 = new JList(mod);
+
+ list2.setSelectionModel(list1.getSelectionModel());
+ for (int i = 0; i < bar.length; ++i)
+ for (int j = 0; j < foo.length; ++j)
+ mod.addElement(foo[j] + bar[i]);
+
+ list1.setCellRenderer(new LabelCellRenderer());
+ list2.setCellRenderer(new CheckCellRenderer());
+
+ JButton add = new JButton("add element");
+ add.addActionListener(new ActionListener()
+ {
+ int i = 0;
+ public void actionPerformed(ActionEvent e)
+ {
+ mod.addElement("new element " + i);
+ ++i;
+ }
+ });
+
+ JButton del = new JButton("delete selected");
+ del.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ for (int i = 0; i < mod.getSize(); ++i)
+ if (list1.isSelectedIndex(i))
+ mod.remove(i);
+ }
+ });
+
+
+ JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
+ splitter.add(new JScrollPane(list1), JSplitPane.LEFT);
+ splitter.add(new JScrollPane(list2), JSplitPane.RIGHT);
+
+ setLayout(new BorderLayout());
+ JPanel p2 = new JPanel();
+ p2.setLayout(new GridLayout(1, 2));
+ p2.add(add);
+ p2.add(del);
+
+ add(p2, BorderLayout.NORTH);
+ add(splitter, BorderLayout.CENTER);
+ }
+
+ public void actionPerformed(ActionEvent e)
+ {
+ if (e.getActionCommand().equals("CLOSE"))
+ {
+ System.exit(0);
+ }
+ }
+
+ /**
+ * When the demo is run independently, the frame is displayed, so we should
+ * initialise the content panel (including the demo content and a close
+ * button). But when the demo is run as part of the Swing activity board,
+ * only the demo content panel is used, the frame itself is never displayed,
+ * so we can avoid this step.
+ */
+ void initFrameContent()
+ {
+ JPanel closePanel = new JPanel();
+ JButton closeButton = new JButton("Close");
+ closeButton.setActionCommand("CLOSE");
+ closeButton.addActionListener(this);
+ closePanel.add(closeButton);
+ add(closePanel, BorderLayout.SOUTH);
+ }
+
+ public static void main(String[] args)
+ {
+ SwingUtilities.invokeLater
+ (new Runnable()
+ {
+ public void run()
+ {
+ ListDemo app = new ListDemo();
+ app.initFrameContent();
+ JFrame frame = new JFrame("List Demo");
+ frame.getContentPane().add(app);
+ frame.pack();
+ frame.setVisible(true);
+ }
+ });
+ }
+
+ /**
+ * Returns a DemoFactory that creates a ListDemo.
+ *
+ * @return a DemoFactory that creates a ListDemo
+ */
+ public static DemoFactory createDemoFactory()
+ {
+ return new DemoFactory()
+ {
+ public JComponent createDemo()
+ {
+ return new ListDemo();
+ }
+ };
+ }
+}
Index: examples/gnu/classpath/examples/swing/TabbedPaneDemo.java
===================================================================
RCS file: examples/gnu/classpath/examples/swing/TabbedPaneDemo.java
diff -N examples/gnu/classpath/examples/swing/TabbedPaneDemo.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ examples/gnu/classpath/examples/swing/TabbedPaneDemo.java 15 Mar 2006 16:39:16 -0000
@@ -0,0 +1,145 @@
+/* TabbedPaneDemo.java -- Demonstrates JTabbedPane
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath 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, or (at your option)
+any later version.
+
+GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.classpath.examples.swing;
+
+import java.awt.BorderLayout;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
+
+public class TabbedPaneDemo
+ extends JPanel
+ implements ActionListener
+{
+ TabbedPaneDemo()
+ {
+ super();
+ createContent();
+ }
+
+ private void createContent()
+ {
+ JPanel p = new JPanel();
+ p.setLayout(new GridLayout(2, 2));
+ JTabbedPane tabs1 = new JTabbedPane(SwingConstants.TOP);
+ tabs1.add("Top Item 1", new JButton("Button"));
+ tabs1.add("Top Item 2", new JButton("Button"));
+ JTabbedPane tabs2 = new JTabbedPane(SwingConstants.LEFT);
+ tabs2.add("Left Item 1", new JButton("Button"));
+ tabs2.add("Left Item 2", new JButton("Button"));
+ JTabbedPane tabs3 = new JTabbedPane(SwingConstants.BOTTOM);
+ tabs3.add("Bottom Item 1", new JButton("Button"));
+ tabs3.add("Bottom Item 2", new JButton("Button"));
+ JTabbedPane tabs4 = new JTabbedPane(SwingConstants.RIGHT);
+ tabs4.add("Right Item 1", new JButton("Button"));
+ tabs4.add("Right Item 2", new JButton("Button"));
+ p.add(tabs1);
+ p.add(tabs2);
+ p.add(tabs3);
+ p.add(tabs4);
+ setLayout(new BorderLayout());
+ add(p, BorderLayout.CENTER);
+ }
+
+ public void actionPerformed(ActionEvent e)
+ {
+ if (e.getActionCommand().equals("CLOSE"))
+ {
+ System.exit(0);
+ }
+ }
+
+ /**
+ * When the demo is run independently, the frame is displayed, so we should
+ * initialise the content panel (including the demo content and a close
+ * button). But when the demo is run as part of the Swing activity board,
+ * only the demo content panel is used, the frame itself is never displayed,
+ * so we can avoid this step.
+ */
+ void initFrameContent()
+ {
+ JPanel closePanel = new JPanel();
+ JButton closeButton = new JButton("Close");
+ closeButton.setActionCommand("CLOSE");
+ closeButton.addActionListener(this);
+ closePanel.add(closeButton);
+ add(closePanel, BorderLayout.SOUTH);
+ }
+
+ public static void main(String[] args)
+ {
+ SwingUtilities.invokeLater
+ (new Runnable()
+ {
+ public void run()
+ {
+ TabbedPaneDemo app = new TabbedPaneDemo();
+ app.initFrameContent();
+ JFrame frame = new JFrame("TabbedPane Demo");
+ frame.getContentPane().add(app);
+ frame.pack();
+ frame.setVisible(true);
+ }
+ });
+ }
+
+ /**
+ * Returns a DemoFactory that creates a TabbedPaneDemo.
+ *
+ * @return a DemoFactory that creates a TabbedPaneDemo
+ */
+ public static DemoFactory createDemoFactory()
+ {
+ return new DemoFactory()
+ {
+ public JComponent createDemo()
+ {
+ return new TabbedPaneDemo();
+ }
+ };
+ }
+}
Index: examples/gnu/classpath/examples/swing/TreeDemo.java
===================================================================
RCS file: examples/gnu/classpath/examples/swing/TreeDemo.java
diff -N examples/gnu/classpath/examples/swing/TreeDemo.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ examples/gnu/classpath/examples/swing/TreeDemo.java 15 Mar 2006 16:39:16 -0000
@@ -0,0 +1,224 @@
+/* TreeDemo.java -- Demostrates JTree
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath 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, or (at your option)
+any later version.
+
+GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.classpath.examples.swing;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTree;
+import javax.swing.SwingUtilities;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeSelectionModel;
+import javax.swing.tree.TreePath;
+
+public class TreeDemo
+ extends JPanel
+ implements ActionListener
+{
+
+ TreeDemo()
+ {
+ super();
+ createContent();
+ }
+
+ private void createContent()
+ {
+ // non-leafs
+ DefaultMutableTreeNode root = new DefaultMutableTreeNode("Exotic Subsistence");
+ DefaultMutableTreeNode fruit = new DefaultMutableTreeNode("Interesting Fruit");
+ DefaultMutableTreeNode veg = new DefaultMutableTreeNode("Extraordinary Vegetables");
+ DefaultMutableTreeNode liq = new DefaultMutableTreeNode("Peculiar Liquids");
+
+ // leafs
+ DefaultMutableTreeNode f1 = new DefaultMutableTreeNode("Abiu");
+ DefaultMutableTreeNode f2 = new DefaultMutableTreeNode("Bamboo Shoots");
+ DefaultMutableTreeNode f3 = new DefaultMutableTreeNode("Breadfruit");
+ DefaultMutableTreeNode f4 = new DefaultMutableTreeNode("Canistel");
+ DefaultMutableTreeNode f5 = new DefaultMutableTreeNode("Duku");
+ DefaultMutableTreeNode f6 = new DefaultMutableTreeNode("Guava");
+ DefaultMutableTreeNode f7 = new DefaultMutableTreeNode("Jakfruit");
+ DefaultMutableTreeNode f8 = new DefaultMutableTreeNode("Quaribea");
+
+ DefaultMutableTreeNode v1 = new DefaultMutableTreeNode("Amaranth");
+ DefaultMutableTreeNode v2 = new DefaultMutableTreeNode("Kiwano");
+ DefaultMutableTreeNode v3 = new DefaultMutableTreeNode("Leeks");
+ DefaultMutableTreeNode v4 = new DefaultMutableTreeNode("Luffa");
+ DefaultMutableTreeNode v5 = new DefaultMutableTreeNode("Chayote");
+ DefaultMutableTreeNode v6 = new DefaultMutableTreeNode("Jicama");
+ DefaultMutableTreeNode v7 = new DefaultMutableTreeNode("Okra");
+
+ DefaultMutableTreeNode l1 = new DefaultMutableTreeNode("Alcoholic");
+ DefaultMutableTreeNode l11 = new DefaultMutableTreeNode("Caipirinha");
+ DefaultMutableTreeNode l21 = new DefaultMutableTreeNode("Mojito");
+ DefaultMutableTreeNode l31 = new DefaultMutableTreeNode("Margarita");
+ DefaultMutableTreeNode l41 = new DefaultMutableTreeNode("Martini");
+ DefaultMutableTreeNode l5 = new DefaultMutableTreeNode("Non Alcoholic");
+ DefaultMutableTreeNode l55 = new DefaultMutableTreeNode("Babaji");
+ DefaultMutableTreeNode l65 = new DefaultMutableTreeNode("Chikita");
+
+ root.add(fruit);
+ root.add(veg);
+ root.add(liq);
+ fruit.add(f1);
+ fruit.add(f2);
+ fruit.add(f3);
+ fruit.add(f4);
+ fruit.add(f5);
+ fruit.add(f6);
+ fruit.add(f7);
+ fruit.add(f8);
+ veg.add(v1);
+ veg.add(v2);
+ veg.add(v3);
+ veg.add(v4);
+ veg.add(v5);
+ veg.add(v6);
+ veg.add(v7);
+ liq.add(l1);
+ l1.add(l11);
+ l1.add(l21);
+ l1.add(l31);
+ l1.add(l41);
+ liq.add(l5);
+ l5.add(l55);
+ l5.add(l65);
+
+ final JTree tree = new JTree(root);
+ tree.setLargeModel(true);
+ tree.setEditable(true);
+ DefaultTreeSelectionModel dtsm = new DefaultTreeSelectionModel();
+ dtsm.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
+ tree.setSelectionModel(dtsm);
+
+ // buttons to add and delete
+ JButton add = new JButton("add element");
+ add.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ for (int i = 0; i < tree.getRowCount(); i++)
+ {
+ if (tree.isRowSelected(i))
+ {
+ TreePath p = tree.getPathForRow(i);
+ DefaultMutableTreeNode n = (DefaultMutableTreeNode) p.
+ getLastPathComponent();
+ n.add(new DefaultMutableTreeNode("New Element"));
+ tree.repaint();
+ break;
+ }
+ }
+ }
+ });
+
+
+ setLayout(new BorderLayout());
+
+ JPanel p2 = new JPanel();
+ p2.add(add);
+
+ add(p2, BorderLayout.NORTH);
+ add(new JScrollPane(tree), BorderLayout.CENTER);
+ }
+
+ public void actionPerformed(ActionEvent e)
+ {
+ if (e.getActionCommand().equals("CLOSE"))
+ {
+ System.exit(0);
+ }
+ }
+
+ /**
+ * When the demo is run independently, the frame is displayed, so we should
+ * initialise the content panel (including the demo content and a close
+ * button). But when the demo is run as part of the Swing activity board,
+ * only the demo content panel is used, the frame itself is never displayed,
+ * so we can avoid this step.
+ */
+ void initFrameContent()
+ {
+ JPanel closePanel = new JPanel();
+ JButton closeButton = new JButton("Close");
+ closeButton.setActionCommand("CLOSE");
+ closeButton.addActionListener(this);
+ closePanel.add(closeButton);
+ add(closePanel, BorderLayout.SOUTH);
+ }
+
+ public static void main(String[] args)
+ {
+ SwingUtilities.invokeLater
+ (new Runnable()
+ {
+ public void run()
+ {
+ TreeDemo app = new TreeDemo();
+ app.initFrameContent();
+ JFrame frame = new JFrame("Tree Demo");
+ frame.getContentPane().add(app);
+ frame.pack();
+ frame.setVisible(true);
+ }
+ });
+ }
+
+ /**
+ * Returns a DemoFactory that creates a TreeDemo.
+ *
+ * @return a DemoFactory that creates a TreeDemo
+ */
+ public static DemoFactory createDemoFactory()
+ {
+ return new DemoFactory()
+ {
+ public JComponent createDemo()
+ {
+ return new TreeDemo();
+ }
+ };
+ }
+}
Index: examples/gnu/classpath/examples/swing/badge.png
===================================================================
RCS file: examples/gnu/classpath/examples/swing/badge.png
diff -N examples/gnu/classpath/examples/swing/badge.png
Binary files /dev/null and badge.png differ