diff options
author | Kenneth Russel <[email protected]> | 2005-10-24 19:21:28 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2005-10-24 19:21:28 +0000 |
commit | 6873f65775af236ed270fcbd08661f5b53ba3598 (patch) | |
tree | 6fcefdc3a9429d7d3071b1464c11d40fa7bc3ab9 /src/demos/xtrans/Main.java | |
parent | 538be101e7bce7788c82e1b254a66deb5d35bb56 (diff) |
Merged JSR-231 branch on to the main JOGL trunk. The main trunk now
contains the evolving JSR-231 Reference Implementation and the JSR-231
branch is permanently closed.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@144 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos/xtrans/Main.java')
-rwxr-xr-x | src/demos/xtrans/Main.java | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/src/demos/xtrans/Main.java b/src/demos/xtrans/Main.java new file mode 100755 index 0000000..07ee010 --- /dev/null +++ b/src/demos/xtrans/Main.java @@ -0,0 +1,229 @@ +package demos.xtrans; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.table.*; +import javax.swing.tree.*; + +/** Demonstration showing off XTDesktopPane. */ + +public class Main { + private XTDesktopPane desktop; + private XTBasicTransitionManager transManager; + + private static final int TABLE = 1; + private static final int TREE = 2; + + private Point loc = new Point(); + + private boolean scrollingEnabled = true; + private boolean rotationEnabled = true; + private boolean fadesEnabled = true; + private Random random; + + private void chooseNextTransition() { + // Only choose one if the user's constraints force us to + if (scrollingEnabled && rotationEnabled && fadesEnabled) { + return; + } + if (random == null) { + random = new Random(); + } + boolean fade = random.nextBoolean(); + if (!fadesEnabled) { + fade = false; + } + + XTBasicTransitionManager.Style style = XTBasicTransitionManager.STYLE_NO_MOTION; + if (scrollingEnabled) { + style = XTBasicTransitionManager.STYLE_SCROLL; + } else if (rotationEnabled) { + style = XTBasicTransitionManager.STYLE_ROTATE; + } + XTBasicTransitionManager.Direction direction = null; + switch (random.nextInt(4)) { + case 0: direction = XTBasicTransitionManager.DIR_LEFT; break; + case 1: direction = XTBasicTransitionManager.DIR_RIGHT; break; + case 2: direction = XTBasicTransitionManager.DIR_UP; break; + default: direction = XTBasicTransitionManager.DIR_DOWN; break; + } + transManager.setNextTransition(style, direction, fade); + } + + private void addWindow(int which) { + JInternalFrame frame = new JInternalFrame(); + frame.setResizable(true); + frame.setClosable(true); + frame.setVisible(true); + + switch (which) { + case TABLE: + { + frame.setTitle("Table Example"); + Object[][] data = produceTableData(3, 20); + DefaultTableModel model = new DefaultTableModel(data, new String[] { "A", "B", "C" }); + JTable table = new JTable(model); + JScrollPane scrollPane = new JScrollPane(table); + frame.getContentPane().add(scrollPane); + break; + } + + case TREE: + { + frame.setTitle("Tree Example"); + DefaultMutableTreeNode root = new DefaultMutableTreeNode(); + populateTree(root, 2); + JTree tree = new JTree(root); + tree.setRootVisible(false); + frame.getContentPane().add(tree); + break; + } + + default: + throw new IllegalArgumentException(); + } + + frame.setLocation(loc); + loc = new Point((loc.x + 20) % desktop.getWidth(), (loc.y + 20) % desktop.getHeight()); + frame.addInternalFrameListener(new InternalFrameAdapter() { + public void internalFrameClosing(InternalFrameEvent e) { + chooseNextTransition(); + } + }); + frame.pack(); + int sz = Math.min(desktop.getWidth() / 3, desktop.getHeight()); + frame.setSize(sz, sz); + chooseNextTransition(); + desktop.add(frame); + desktop.moveToFront(frame); + } + + private Object[][] produceTableData(int cols, int rows) { + Object[][] res = new Object[rows][]; + + Random r = new Random(); + + for (int i = 0; i < rows; i++) { + Object[] row = new Object[cols]; + for (int j = 0; j < cols; j++) { + row[j] = new Integer(r.nextInt(1000)); + } + res[i] = row; + } + + return res; + } + + private void populateTree(DefaultMutableTreeNode node, int depth) { + node.add(new DefaultMutableTreeNode("A")); + node.add(new DefaultMutableTreeNode("B")); + node.add(new DefaultMutableTreeNode("C")); + + if (depth > 0) { + for (Enumeration e = node.children(); e.hasMoreElements(); ) { + populateTree((DefaultMutableTreeNode) e.nextElement(), depth - 1); + } + } + } + + private void run(String[] args) { + JFrame frame = new JFrame("Desktop Demo"); + + JMenu menu = new JMenu("Actions"); + JMenuBar menuBar = new JMenuBar(); + JMenuItem item; + + item = new JMenuItem("Add Table"); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + addWindow(TABLE); + } + }); + menu.add(item); + + item = new JMenuItem("Add Tree"); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + addWindow(TREE); + } + }); + menu.add(item); + + item = new JMenuItem("Close all"); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Component[] cs = desktop.getComponents(); + for (int i = 0; i < cs.length; i++) { + chooseNextTransition(); + desktop.remove(cs[i]); + } + } + }); + menu.add(item); + + item = new JMenuItem("Quit"); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + }); + item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_MASK)); + menu.add(item); + + menuBar.add(menu); + + menu = new JMenu("Options"); + JCheckBoxMenuItem ckitem = new JCheckBoxMenuItem("Enable Scrolling"); + ckitem.setState(true); + ckitem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + scrollingEnabled = ((JCheckBoxMenuItem) e.getSource()).getState(); + } + }); + menu.add(ckitem); + + ckitem = new JCheckBoxMenuItem("Enable Rotation"); + ckitem.setState(true); + ckitem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + rotationEnabled = ((JCheckBoxMenuItem) e.getSource()).getState(); + } + }); + menu.add(ckitem); + + ckitem = new JCheckBoxMenuItem("Enable Fades"); + ckitem.setState(true); + ckitem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + fadesEnabled = ((JCheckBoxMenuItem) e.getSource()).getState(); + } + }); + menu.add(ckitem); + + menuBar.add(menu); + + frame.setJMenuBar(menuBar); + + desktop = new XTDesktopPane(); + transManager = (XTBasicTransitionManager) desktop.getTransitionManager(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.getContentPane().add(desktop); + + DisplayMode cur = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode(); + int width = (int) (cur.getWidth() * 0.75f); + int height = (int) (width * 3.0f / 4.0f); + if (height >= 95.0f * cur.getHeight()) { + height = (int) (cur.getHeight() * 0.75f); + width = (int) (height * 4.0f / 3.0f); + } + frame.setSize(width, height); + frame.setVisible(true); + } + + public static void main(String[] args) { + new Main().run(args); + } +} |