diff --git a/examples/src/main/java/edu/umd/cs/piccolo/examples/ExampleRunner.java b/examples/src/main/java/edu/umd/cs/piccolo/examples/ExampleRunner.java index 886db72..c08041f 100644 --- a/examples/src/main/java/edu/umd/cs/piccolo/examples/ExampleRunner.java +++ b/examples/src/main/java/edu/umd/cs/piccolo/examples/ExampleRunner.java @@ -29,9 +29,12 @@ package edu.umd.cs.piccolo.examples; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.ActionEvent; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.swing.AbstractAction; import javax.swing.JButton; @@ -40,67 +43,31 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.WindowConstants; +import javax.swing.border.TitledBorder; import edu.umd.cs.piccolo.util.PDebug; import edu.umd.cs.piccolox.PFrame; public class ExampleRunner extends JFrame { - - /** - * - */ private static final long serialVersionUID = 1L; public ExampleRunner() { setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Piccolo Example Runner"); - setSize(426, 335); + setSize(650, 600); getContentPane().setLayout(new BorderLayout()); createExampleButtons(); + + getContentPane().setBackground(new Color(200, 200, 200)); validate(); - pack(); setVisible(true); } public void createExampleButtons() { final Container c = getContentPane(); - JPanel panel = new JPanel(new GridLayout(0, 1)); - c.add(BorderLayout.NORTH, panel); - - panel.add(new JCheckBox(new AbstractAction("Print Frame Rates to Console") { - /** - * - */ - private static final long serialVersionUID = 1L; - - public void actionPerformed(final ActionEvent e) { - PDebug.debugPrintFrameRate = !PDebug.debugPrintFrameRate; - } - })); - - panel.add(new JCheckBox(new AbstractAction("Show Region Managment") { - /** - * - */ - private static final long serialVersionUID = 1L; - - public void actionPerformed(final ActionEvent e) { - PDebug.debugRegionManagement = !PDebug.debugRegionManagement; - } - })); - - panel.add(new JCheckBox(new AbstractAction("Show Full Bounds") { - /** - * - */ - private static final long serialVersionUID = 1L; - - public void actionPerformed(final ActionEvent e) { - PDebug.debugFullBounds = !PDebug.debugFullBounds; - } - })); - - panel = new JPanel(new GridLayout(0, 2)); + + c.add(buildOptions(), BorderLayout.NORTH); + JPanel panel= new JPanel(new GridLayout(0, 2)); c.add(BorderLayout.CENTER, panel); addExampleButtons(panel, new Class[] { ActivityExample.class, AngleNodeExample.class, @@ -110,12 +77,41 @@ HandleExample.class, HelloWorldExample.class, HierarchyZoomExample.class, HtmlViewExample.class, KeyEventFocusExample.class, LayoutExample.class, LensExample.class, NavigationExample.class, NodeCacheExample.class, NodeEventExample.class, NodeExample.class, NodeLinkExample.class, - P3DRectExample.class, PanToExample.class, PathExample.class, PositionExample.class, PositionPathActivityExample.class, - PulseExample.class, ScrollingExample.class, SelectionExample.class, ShadowExample.class, - SquiggleExample.class, StickyExample.class, StickyHandleLayerExample.class, StrokeExample.class, - TextExample.class, TooltipExample.class, TwoCanvasExample.class, WaitForActivitiesExample.class }); + P3DRectExample.class, PanToExample.class, PathExample.class, PositionExample.class, + PositionPathActivityExample.class, PulseExample.class, ScrollingExample.class, SelectionExample.class, + ShadowExample.class, SquiggleExample.class, StickyExample.class, StickyHandleLayerExample.class, + StrokeExample.class, TextExample.class, TooltipExample.class, TwoCanvasExample.class, + WaitForActivitiesExample.class }); } + /** + * @param c + */ + private JPanel buildOptions() { + JPanel optionsPanel = new JPanel(new GridLayout(3, 1)); + optionsPanel.setBorder(new TitledBorder("Display Options")); + + optionsPanel.add(new JCheckBox(new AbstractAction("Print Frame Rates to Console") { + public void actionPerformed(final ActionEvent e) { + PDebug.debugPrintFrameRate = !PDebug.debugPrintFrameRate; + } + })); + + optionsPanel.add(new JCheckBox(new AbstractAction("Show Region Managment") { + public void actionPerformed(final ActionEvent e) { + PDebug.debugRegionManagement = !PDebug.debugRegionManagement; + } + })); + + optionsPanel.add(new JCheckBox(new AbstractAction("Show Full Bounds") { + public void actionPerformed(final ActionEvent e) { + PDebug.debugFullBounds = !PDebug.debugFullBounds; + } + })); + + return optionsPanel; + } + private void addExampleButtons(final JPanel panel, final Class[] exampleClasses) { for (int i = 0; i < exampleClasses.length; i++) { panel.add(buildExampleButton(exampleClasses[i])); @@ -125,7 +121,8 @@ private JButton buildExampleButton(final Class exampleClass) { final String fullClassName = exampleClass.getName(); final String simpleClassName = fullClassName.substring(fullClassName.lastIndexOf('.') + 1); - return new JButton(new AbstractAction(simpleClassName) { + final String exampleLabel = camelToProper(simpleClassName); + JButton button = new JButton(new AbstractAction(exampleLabel) { public void actionPerformed(final ActionEvent event) { try { final PFrame example = (PFrame) exampleClass.newInstance(); @@ -136,7 +133,25 @@ "A problem was encountered running the example.\n\n" + e.getMessage()); } } - }); + }); + button.setBackground(Color.WHITE); + button.setHorizontalAlignment(JButton.LEFT); + return button; + } + + private String camelToProper(String camel) { + Pattern pattern = Pattern.compile("[a-z]([A-Z])"); + Matcher matcher = pattern.matcher(camel); + StringBuffer result = new StringBuffer(); + int lastIndex = 0; + while (matcher.find()) { + int nextWord = matcher.start(1); + result.append(camel.substring(lastIndex, nextWord)); + result.append(' '); + lastIndex = nextWord; + } + result.append(camel.substring(lastIndex, camel.length())); + return result.toString(); } public static void main(final String[] args) {