From b8eb85fbadfa395928e999124efbe064f01762b6 Mon Sep 17 00:00:00 2001 From: codistmonk Date: Sun, 18 Sep 2011 16:15:38 +0000 Subject: [PATCH] [Aprog] Added some methods to SwingTools (horizontal/verticalBox, horizontal/verticalSplit) + tests. git-svn-id: https://aprog.svn.sourceforge.net/svnroot/aprog/trunk@184 7cbf5e2b-b55d-4b93-acdd-c0d7b961df51 --- Aprog/nbproject/project.properties | 2 +- .../net/sourceforge/aprog/swing/SwingTools.java | 74 ++++++++++++++++++++++ .../sourceforge/aprog/swing/SwingToolsTest.java | 54 ++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) diff --git a/Aprog/nbproject/project.properties b/Aprog/nbproject/project.properties index 6cc60f3..a51630d 100644 --- a/Aprog/nbproject/project.properties +++ b/Aprog/nbproject/project.properties @@ -21,7 +21,7 @@ debug.test.classpath=\ ${run.test.classpath} # This directory is removed when the project is cleaned: dist.dir=dist -dist.jar=${dist.dir}/aprog-1.0.0-M5.jar +dist.jar=${dist.dir}/aprog.jar dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= diff --git a/Aprog/src/net/sourceforge/aprog/swing/SwingTools.java b/Aprog/src/net/sourceforge/aprog/swing/SwingTools.java index e50585d..7fe8243 100644 --- a/Aprog/src/net/sourceforge/aprog/swing/SwingTools.java +++ b/Aprog/src/net/sourceforge/aprog/swing/SwingTools.java @@ -47,11 +47,13 @@ import java.util.logging.Level; import javax.imageio.ImageIO; import javax.swing.AbstractButton; +import javax.swing.Box; import javax.swing.ImageIcon; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JScrollPane; +import javax.swing.JSplitPane; import javax.swing.SwingUtilities; import javax.swing.UIManager; @@ -562,4 +564,76 @@ public final class SwingTools { }; } + /** + * @param components + *
Not null + * @return + *
Not null + *
New + */ + public static final Box horizontalBox(final Component... components) { + checkAWT(); + + final Box result = Box.createHorizontalBox(); + + for (final Component component : components) { + result.add(component); + } + + return result; + } + + /** + * @param components + *
Not null + * @return + *
Not null + *
New + */ + public static final Box verticalBox(final Component... components) { + checkAWT(); + + final Box result = Box.createVerticalBox(); + + for (final Component component : components) { + result.add(component); + } + + return result; + } + + /** + * @param leftComponent + *
Maybe null + *
Will become reference + * @param rightComponent + *
Maybe null + *
Will become reference + * @return + *
Not null + *
New + */ + public static final JSplitPane horizontalSplit(final Component leftComponent, final Component rightComponent) { + checkAWT(); + + return new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftComponent, rightComponent); + } + + /** + * @param leftComponent + *
Maybe null + *
Will become reference + * @param rightComponent + *
Maybe null + *
Will become reference + * @return + *
Not null + *
New + */ + public static final JSplitPane verticalSplit(final Component leftComponent, final Component rightComponent) { + checkAWT(); + + return new JSplitPane(JSplitPane.VERTICAL_SPLIT, leftComponent, rightComponent); + } + } diff --git a/Aprog/test/net/sourceforge/aprog/swing/SwingToolsTest.java b/Aprog/test/net/sourceforge/aprog/swing/SwingToolsTest.java index ed74c2d..8e7714c 100644 --- a/Aprog/test/net/sourceforge/aprog/swing/SwingToolsTest.java +++ b/Aprog/test/net/sourceforge/aprog/swing/SwingToolsTest.java @@ -35,6 +35,7 @@ import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.concurrent.Semaphore; +import javax.swing.Box; import javax.swing.JButton; import javax.swing.JLabel; @@ -43,6 +44,7 @@ import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.JSplitPane; import javax.swing.SwingUtilities; import org.junit.Test; @@ -148,6 +150,58 @@ public final class SwingToolsTest { } @Test + public final void testHorizontalBox() { + if (SwingTools.canInvokeThisMethodInAWT(this)) { + final JLabel component1 = new JLabel("1"); + final JLabel component2 = new JLabel("2"); + final Box box = SwingTools.horizontalBox(component1, component2); + + assertNotNull(box); + assertArrayEquals(array(component1, component2), box.getComponents()); + } + } + + @Test + public final void testVerticalBox() { + if (SwingTools.canInvokeThisMethodInAWT(this)) { + final JLabel component1 = new JLabel("1"); + final JLabel component2 = new JLabel("2"); + final Box box = SwingTools.verticalBox(component1, component2); + + assertNotNull(box); + assertArrayEquals(array(component1, component2), box.getComponents()); + } + } + + @Test + public final void testHorizontalSplit() { + if (SwingTools.canInvokeThisMethodInAWT(this)) { + final JLabel component1 = new JLabel("1"); + final JLabel component2 = new JLabel("2"); + final JSplitPane splitPane = SwingTools.horizontalSplit(component1, component2); + + assertNotNull(splitPane); + assertEquals(JSplitPane.HORIZONTAL_SPLIT, splitPane.getOrientation()); + assertEquals(splitPane, component1.getParent()); + assertEquals(splitPane, component2.getParent()); + } + } + + @Test + public final void testVerticalSplit() { + if (SwingTools.canInvokeThisMethodInAWT(this)) { + final JLabel component1 = new JLabel("1"); + final JLabel component2 = new JLabel("2"); + final JSplitPane splitPane = SwingTools.verticalSplit(component1, component2); + + assertNotNull(splitPane); + assertEquals(JSplitPane.VERTICAL_SPLIT, splitPane.getOrientation()); + assertEquals(splitPane, component1.getParent()); + assertEquals(splitPane, component2.getParent()); + } + } + + @Test public final void testGetFiles() { // TODO debugPrint("TODO"); -- 2.11.4.GIT