mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-23 22:29:55 +00:00
8197948: Create test for SwingSet2 main window
Reviewed-by: prr
This commit is contained in:
parent
0b2ecd51c9
commit
cbc02cd8d1
195
test/jdk/sanity/client/SwingSet/src/SwingSet2DemoTest.java
Normal file
195
test/jdk/sanity/client/SwingSet/src/SwingSet2DemoTest.java
Normal file
@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import static org.jemmy2ext.JemmyExt.EXACT_STRING_COMPARATOR;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JRadioButtonMenuItem;
|
||||
import javax.swing.ToolTipManager;
|
||||
import javax.swing.plaf.metal.MetalLookAndFeel;
|
||||
|
||||
import org.jtregext.GuiTestListener;
|
||||
import org.netbeans.jemmy.ClassReference;
|
||||
import org.netbeans.jemmy.ComponentChooser;
|
||||
import org.netbeans.jemmy.TimeoutExpiredException;
|
||||
import org.netbeans.jemmy.operators.ComponentOperator;
|
||||
import org.netbeans.jemmy.operators.JButtonOperator;
|
||||
import org.netbeans.jemmy.operators.JCheckBoxMenuItemOperator;
|
||||
import org.netbeans.jemmy.operators.JFrameOperator;
|
||||
import org.netbeans.jemmy.operators.JMenuOperator;
|
||||
import org.netbeans.jemmy.operators.JRadioButtonMenuItemOperator;
|
||||
import org.netbeans.jemmy.operators.JToggleButtonOperator;
|
||||
import org.netbeans.jemmy.util.NameComponentChooser;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @summary Verifies check box menu item, radio button menu item, nested menus
|
||||
* and themes using SwingSet2 main window. Testing of other swing components
|
||||
* are covered in SwingSet3 demo tests.
|
||||
*
|
||||
* @library /sanity/client/lib/jemmy/src
|
||||
* @library /sanity/client/lib/Extensions/src
|
||||
* @library /sanity/client/lib/SwingSet2/src
|
||||
* @modules java.desktop
|
||||
* java.logging
|
||||
* @build org.jemmy2ext.JemmyExt
|
||||
* @build SwingSet2
|
||||
* @run testng SwingSet2DemoTest
|
||||
*/
|
||||
@Listeners(GuiTestListener.class)
|
||||
public class SwingSet2DemoTest {
|
||||
|
||||
private static final String OCEAN_THEME_NAME = "Ocean";
|
||||
private static final String STEEL_THEME_NAME = "Steel";
|
||||
private static final int TOOLTIP_DISMISS_DELAY = 60000;
|
||||
|
||||
/**
|
||||
* Testing check box menu item, radio button menu item, nested menus and
|
||||
* themes. Testing of all other main swing components are covered in
|
||||
* SwingSet3 demo tests.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
|
||||
new ClassReference(SwingSet2.class.getCanonicalName()).startApplication();
|
||||
JFrameOperator frameOperator = new JFrameOperator(SwingSet2.FRAME_TITLE);
|
||||
frameOperator.setComparator(EXACT_STRING_COMPARATOR);
|
||||
|
||||
checkCheckBoxMenuItem(frameOperator);
|
||||
JMenuOperator themesMenu = new JMenuOperator(frameOperator, SwingSet2.THEMES_MENU_TEXT);
|
||||
// Themes menu will be enabled only on MetalLookAndFeel
|
||||
if(themesMenu.isEnabled()) {
|
||||
checkMenuOnMenuAndRadioButtonMenuItem(frameOperator, themesMenu);
|
||||
checkThemes(frameOperator, themesMenu);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the properties of nested menu and radio button menu item
|
||||
* @param frameOperator
|
||||
* @param themesMenu
|
||||
*/
|
||||
private void checkMenuOnMenuAndRadioButtonMenuItem(
|
||||
JFrameOperator frameOperator, JMenuOperator themesMenu) {
|
||||
|
||||
themesMenu.push();
|
||||
themesMenu.waitSelected(true);
|
||||
// Font menu is a nested menu, selecting that and verifying its
|
||||
// sub menu items are launched
|
||||
JMenuOperator fontMenu = new JMenuOperator(frameOperator, SwingSet2.FONT_MENU_TEXT);
|
||||
JRadioButtonMenuItemOperator fontPlainMenuItem = new JRadioButtonMenuItemOperator(
|
||||
(JRadioButtonMenuItem)fontMenu.showMenuItem(
|
||||
SwingSet2.FONT_PLAIN_MENU_TEXT, "/").getSource());
|
||||
JRadioButtonMenuItemOperator fontBoldMenuItem = new JRadioButtonMenuItemOperator(
|
||||
(JRadioButtonMenuItem)fontMenu.showMenuItem(
|
||||
SwingSet2.FONT_BOLD_MENU_TEXT, "/").getSource());
|
||||
JButtonOperator testComp =
|
||||
new JButtonOperator(frameOperator, OptionPaneDemo.INPUT_BUTTON);
|
||||
checkRadioButtonMenuItem(fontBoldMenuItem, fontPlainMenuItem, testComp,
|
||||
component -> component.getFont().isBold());
|
||||
checkRadioButtonMenuItem(fontPlainMenuItem, fontBoldMenuItem, testComp,
|
||||
component -> component.getFont().isPlain());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the properties of radio button menu item
|
||||
* @param pressMenuItem
|
||||
* @param unPressMenuItem
|
||||
* @param testComp
|
||||
* @param validator
|
||||
*/
|
||||
private void checkRadioButtonMenuItem(JRadioButtonMenuItemOperator pressMenuItem,
|
||||
JRadioButtonMenuItemOperator unPressMenuItem,
|
||||
ComponentOperator testComp, ComponentChooser validator){
|
||||
|
||||
// Selecting a radio button menu item and verifying the pressed menu
|
||||
// item is selected, other one is unselected and corresponding ui
|
||||
// changes also happened
|
||||
pressMenuItem.push();
|
||||
pressMenuItem.waitSelected(true);
|
||||
unPressMenuItem.waitSelected(false);
|
||||
testComp.waitStateOnQueue(validator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the properties of check box menu item
|
||||
* @param frameOperator
|
||||
*/
|
||||
private void checkCheckBoxMenuItem(JFrameOperator frameOperator) {
|
||||
|
||||
ToolTipManager.sharedInstance().setDismissDelay(TOOLTIP_DISMISS_DELAY);
|
||||
JToggleButtonOperator testComp = new JToggleButtonOperator(
|
||||
frameOperator, new NameComponentChooser(SwingSet2.getString(
|
||||
OptionPaneDemo.DEMO_NAME + SwingSet2.NAME_PROP_SUFFIX)));
|
||||
JMenuOperator optionsMenu = new JMenuOperator(frameOperator, SwingSet2.OPTIONS_MENU_TEXT);
|
||||
JCheckBoxMenuItemOperator toolTipMenuItem = new JCheckBoxMenuItemOperator(
|
||||
(JCheckBoxMenuItem)optionsMenu.showMenuItem(
|
||||
SwingSet2.TOOLTIP_MENU_TEXT, "/").getSource());
|
||||
// Selecting and deselecting tooltip checkbox menu item and verifying
|
||||
// tooltip is showing for demo toggle button
|
||||
toolTipMenuItem.push();
|
||||
toolTipMenuItem.waitSelected(false);
|
||||
boolean isToolTipTimeout = false;
|
||||
try {
|
||||
testComp.showToolTip();
|
||||
} catch (TimeoutExpiredException e) {
|
||||
isToolTipTimeout = true;
|
||||
}
|
||||
assertTrue(isToolTipTimeout, "Tooltip is showing even after unchecking the checkbox menu"
|
||||
+ " item 'Enable Tool Tips'");
|
||||
toolTipMenuItem.push();
|
||||
toolTipMenuItem.waitSelected(true);
|
||||
testComp.showToolTip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the different themes by applying different themes
|
||||
* @param frameOperator
|
||||
* @param themesMenu
|
||||
*/
|
||||
private void checkThemes(JFrameOperator frameOperator, JMenuOperator themesMenu) {
|
||||
String themeMenuNames [] = {SwingSet2.OCEAN_MENU_TEXT, SwingSet2.AQUA_MENU_TEXT,
|
||||
SwingSet2.STEEL_MENU_TEXT, SwingSet2.CHARCOAL_MENU_TEXT,
|
||||
SwingSet2.CONTRAST_MENU_TEXT, SwingSet2.EMERALD_MENU_TEXT, SwingSet2.RUBY_MENU_TEXT};
|
||||
String themeNames [] = {OCEAN_THEME_NAME, AquaTheme.NAME, STEEL_THEME_NAME,
|
||||
CharcoalTheme.NAME, ContrastTheme.NAME, EmeraldTheme.NAME, RubyTheme.NAME};
|
||||
|
||||
for (int i = 0; i < themeMenuNames.length; i++) {
|
||||
int themeIndex = i;
|
||||
JRadioButtonMenuItemOperator menuItem = new JRadioButtonMenuItemOperator(
|
||||
(JRadioButtonMenuItem)themesMenu.showMenuItem(
|
||||
themeMenuNames[themeIndex], "/").getSource());
|
||||
menuItem.push();
|
||||
menuItem.waitSelected(true);
|
||||
menuItem.waitStateOnQueue(comp -> themeNames[themeIndex].
|
||||
equals(MetalLookAndFeel.getCurrentTheme().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
4
test/jdk/sanity/client/lib/SwingSet2/README
Normal file
4
test/jdk/sanity/client/lib/SwingSet2/README
Normal file
@ -0,0 +1,4 @@
|
||||
The content of this src folder was originally taken from openjdk SwingSet2 demo: http://hg.openjdk.java.net/jdk/jdk/file/2d5d75263e77/src/demo/share/jfc/SwingSet2.
|
||||
Then it was modified to increase testability and removed extra content and extra dependencies.
|
||||
|
||||
This is NOT the official location of the SwingSet2 demo.
|
||||
46
test/jdk/sanity/client/lib/SwingSet2/src/AquaTheme.java
Normal file
46
test/jdk/sanity/client/lib/SwingSet2/src/AquaTheme.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
import javax.swing.plaf.metal.DefaultMetalTheme;
|
||||
|
||||
/**
|
||||
* This class describes a theme using "blue-green" colors.
|
||||
*
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public class AquaTheme extends DefaultMetalTheme {
|
||||
|
||||
public static String NAME = "Aqua";
|
||||
|
||||
public String getName() { return NAME; }
|
||||
|
||||
private final ColorUIResource primary1 = new ColorUIResource(102, 153, 153);
|
||||
private final ColorUIResource primary2 = new ColorUIResource(128, 192, 192);
|
||||
private final ColorUIResource primary3 = new ColorUIResource(159, 235, 235);
|
||||
|
||||
protected ColorUIResource getPrimary1() { return primary1; }
|
||||
protected ColorUIResource getPrimary2() { return primary2; }
|
||||
protected ColorUIResource getPrimary3() { return primary3; }
|
||||
|
||||
}
|
||||
60
test/jdk/sanity/client/lib/SwingSet2/src/CharcoalTheme.java
Normal file
60
test/jdk/sanity/client/lib/SwingSet2/src/CharcoalTheme.java
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
import javax.swing.plaf.metal.DefaultMetalTheme;
|
||||
|
||||
/**
|
||||
* This class describes a theme using gray colors.
|
||||
*
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public class CharcoalTheme extends DefaultMetalTheme {
|
||||
|
||||
public static String NAME = "Charcoal";
|
||||
|
||||
public String getName() { return NAME; }
|
||||
|
||||
private final ColorUIResource primary1 = new ColorUIResource(66, 33, 66);
|
||||
private final ColorUIResource primary2 = new ColorUIResource(90, 86, 99);
|
||||
private final ColorUIResource primary3 = new ColorUIResource(99, 99, 99);
|
||||
|
||||
private final ColorUIResource secondary1 = new ColorUIResource(0, 0, 0);
|
||||
private final ColorUIResource secondary2 = new ColorUIResource(51, 51, 51);
|
||||
private final ColorUIResource secondary3 = new ColorUIResource(102, 102, 102);
|
||||
|
||||
private final ColorUIResource black = new ColorUIResource(222, 222, 222);
|
||||
private final ColorUIResource white = new ColorUIResource(0, 0, 0);
|
||||
|
||||
protected ColorUIResource getPrimary1() { return primary1; }
|
||||
protected ColorUIResource getPrimary2() { return primary2; }
|
||||
protected ColorUIResource getPrimary3() { return primary3; }
|
||||
|
||||
protected ColorUIResource getSecondary1() { return secondary1; }
|
||||
protected ColorUIResource getSecondary2() { return secondary2; }
|
||||
protected ColorUIResource getSecondary3() { return secondary3; }
|
||||
|
||||
protected ColorUIResource getBlack() { return black; }
|
||||
protected ColorUIResource getWhite() { return white; }
|
||||
|
||||
}
|
||||
93
test/jdk/sanity/client/lib/SwingSet2/src/ContrastTheme.java
Normal file
93
test/jdk/sanity/client/lib/SwingSet2/src/ContrastTheme.java
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import javax.swing.UIDefaults;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.LineBorder;
|
||||
import javax.swing.plaf.BorderUIResource;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
import javax.swing.plaf.basic.BasicBorders;
|
||||
import javax.swing.plaf.metal.DefaultMetalTheme;
|
||||
|
||||
/**
|
||||
* This class describes a higher-contrast Metal Theme.
|
||||
*
|
||||
* @author Michael C. Albers
|
||||
*/
|
||||
|
||||
public class ContrastTheme extends DefaultMetalTheme {
|
||||
|
||||
public static String NAME = "Contrast";
|
||||
|
||||
public String getName() { return NAME; }
|
||||
|
||||
private final ColorUIResource primary1 = new ColorUIResource(0, 0, 0);
|
||||
private final ColorUIResource primary2 = new ColorUIResource(204, 204, 204);
|
||||
private final ColorUIResource primary3 = new ColorUIResource(255, 255, 255);
|
||||
private final ColorUIResource primaryHighlight = new ColorUIResource(102,102,102);
|
||||
|
||||
private final ColorUIResource secondary2 = new ColorUIResource(204, 204, 204);
|
||||
private final ColorUIResource secondary3 = new ColorUIResource(255, 255, 255);
|
||||
|
||||
protected ColorUIResource getPrimary1() { return primary1; }
|
||||
protected ColorUIResource getPrimary2() { return primary2; }
|
||||
protected ColorUIResource getPrimary3() { return primary3; }
|
||||
public ColorUIResource getPrimaryControlHighlight() { return primaryHighlight;}
|
||||
|
||||
protected ColorUIResource getSecondary2() { return secondary2; }
|
||||
protected ColorUIResource getSecondary3() { return secondary3; }
|
||||
public ColorUIResource getControlHighlight() { return super.getSecondary3(); }
|
||||
|
||||
public ColorUIResource getFocusColor() { return getBlack(); }
|
||||
|
||||
public ColorUIResource getTextHighlightColor() { return getBlack(); }
|
||||
public ColorUIResource getHighlightedTextColor() { return getWhite(); }
|
||||
|
||||
public ColorUIResource getMenuSelectedBackground() { return getBlack(); }
|
||||
public ColorUIResource getMenuSelectedForeground() { return getWhite(); }
|
||||
public ColorUIResource getAcceleratorForeground() { return getBlack(); }
|
||||
public ColorUIResource getAcceleratorSelectedForeground() { return getWhite(); }
|
||||
|
||||
|
||||
public void addCustomEntriesToTable(UIDefaults table) {
|
||||
|
||||
Border blackLineBorder = new BorderUIResource(new LineBorder( getBlack() ));
|
||||
|
||||
Object textBorder = new BorderUIResource( new CompoundBorder(
|
||||
blackLineBorder,
|
||||
new BasicBorders.MarginBorder()));
|
||||
|
||||
table.put( "ToolTip.border", blackLineBorder);
|
||||
table.put( "TitledBorder.border", blackLineBorder);
|
||||
|
||||
table.put( "TextField.border", textBorder);
|
||||
table.put( "PasswordField.border", textBorder);
|
||||
table.put( "TextArea.border", textBorder);
|
||||
table.put( "TextPane.border", textBorder);
|
||||
table.put( "EditorPane.border", textBorder);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
223
test/jdk/sanity/client/lib/SwingSet2/src/DemoModule.java
Normal file
223
test/jdk/sanity/client/lib/SwingSet2/src/DemoModule.java
Normal file
@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JApplet;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.border.SoftBevelBorder;
|
||||
|
||||
/**
|
||||
* A generic SwingSet2 demo module
|
||||
*
|
||||
* @author Jeff Dinkins
|
||||
*/
|
||||
public class DemoModule extends JApplet {
|
||||
|
||||
// The preferred size of the demo
|
||||
private int PREFERRED_WIDTH = 680;
|
||||
private int PREFERRED_HEIGHT = 600;
|
||||
|
||||
Border loweredBorder = new CompoundBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED),
|
||||
new EmptyBorder(5,5,5,5));
|
||||
|
||||
// Premade convenience dimensions, for use wherever you need 'em.
|
||||
public static Dimension HGAP2 = new Dimension(2,1);
|
||||
public static Dimension VGAP2 = new Dimension(1,2);
|
||||
|
||||
public static Dimension HGAP5 = new Dimension(5,1);
|
||||
public static Dimension VGAP5 = new Dimension(1,5);
|
||||
|
||||
public static Dimension HGAP10 = new Dimension(10,1);
|
||||
public static Dimension VGAP10 = new Dimension(1,10);
|
||||
|
||||
public static Dimension HGAP15 = new Dimension(15,1);
|
||||
public static Dimension VGAP15 = new Dimension(1,15);
|
||||
|
||||
public static Dimension HGAP20 = new Dimension(20,1);
|
||||
public static Dimension VGAP20 = new Dimension(1,20);
|
||||
|
||||
public static Dimension HGAP25 = new Dimension(25,1);
|
||||
public static Dimension VGAP25 = new Dimension(1,25);
|
||||
|
||||
public static Dimension HGAP30 = new Dimension(30,1);
|
||||
public static Dimension VGAP30 = new Dimension(1,30);
|
||||
|
||||
private SwingSet2 swingset = null;
|
||||
private JPanel panel = null;
|
||||
private String resourceName = null;
|
||||
private String iconPath = null;
|
||||
private String sourceCode = null;
|
||||
|
||||
public DemoModule(SwingSet2 swingset) {
|
||||
this(swingset, null, null);
|
||||
}
|
||||
|
||||
public DemoModule(SwingSet2 swingset, String resourceName, String iconPath) {
|
||||
UIManager.put("swing.boldMetal", Boolean.FALSE);
|
||||
panel = new JPanel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
|
||||
this.resourceName = resourceName;
|
||||
this.iconPath = iconPath;
|
||||
this.swingset = swingset;
|
||||
|
||||
loadSourceCode();
|
||||
}
|
||||
|
||||
public String getResourceName() {
|
||||
return resourceName;
|
||||
}
|
||||
|
||||
public JPanel getDemoPanel() {
|
||||
return panel;
|
||||
}
|
||||
|
||||
public SwingSet2 getSwingSet2() {
|
||||
return swingset;
|
||||
}
|
||||
|
||||
|
||||
public String getString(String key) {
|
||||
|
||||
if (getSwingSet2() != null) {
|
||||
return getSwingSet2().getString(key);
|
||||
}else{
|
||||
return "nada";
|
||||
}
|
||||
}
|
||||
|
||||
public char getMnemonic(String key) {
|
||||
return (getString(key)).charAt(0);
|
||||
}
|
||||
|
||||
public ImageIcon createImageIcon(String filename, String description) {
|
||||
if(getSwingSet2() != null) {
|
||||
return getSwingSet2().createImageIcon(filename, description);
|
||||
} else {
|
||||
String path = "/resources/images/" + filename;
|
||||
return new ImageIcon(getClass().getResource(path), description);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getSourceCode() {
|
||||
return sourceCode;
|
||||
}
|
||||
|
||||
public void loadSourceCode() {
|
||||
if(getResourceName() != null) {
|
||||
String filename = getResourceName() + ".java";
|
||||
sourceCode = new String("<html><body bgcolor=\"#ffffff\"><pre>");
|
||||
InputStream is;
|
||||
InputStreamReader isr;
|
||||
URL url;
|
||||
|
||||
try {
|
||||
url = getClass().getResource(filename);
|
||||
is = url.openStream();
|
||||
isr = new InputStreamReader(is, "UTF-8");
|
||||
BufferedReader reader = new BufferedReader(isr);
|
||||
|
||||
// Read one line at a time, htmlize using super-spiffy
|
||||
// html java code formating utility from www.CoolServlets.com
|
||||
String line = reader.readLine();
|
||||
while(line != null) {
|
||||
sourceCode += line + " \n ";
|
||||
line = reader.readLine();
|
||||
}
|
||||
sourceCode += new String("</pre></body></html>");
|
||||
} catch (Exception ex) {
|
||||
sourceCode = "Could not load file: " + filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return getString(getResourceName() + ".name");
|
||||
};
|
||||
|
||||
public Icon getIcon() {
|
||||
return createImageIcon(iconPath, getResourceName() + ".name");
|
||||
};
|
||||
|
||||
public String getToolTip() {
|
||||
return getString(getResourceName() + ".tooltip");
|
||||
};
|
||||
|
||||
public void mainImpl() {
|
||||
JFrame frame = new JFrame(getName());
|
||||
frame.getContentPane().setLayout(new BorderLayout());
|
||||
frame.getContentPane().add(getDemoPanel(), BorderLayout.CENTER);
|
||||
getDemoPanel().setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
||||
frame.pack();
|
||||
frame.show();
|
||||
}
|
||||
|
||||
public JPanel createHorizontalPanel(boolean threeD) {
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
|
||||
p.setAlignmentY(TOP_ALIGNMENT);
|
||||
p.setAlignmentX(LEFT_ALIGNMENT);
|
||||
if(threeD) {
|
||||
p.setBorder(loweredBorder);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public JPanel createVerticalPanel(boolean threeD) {
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
|
||||
p.setAlignmentY(TOP_ALIGNMENT);
|
||||
p.setAlignmentX(LEFT_ALIGNMENT);
|
||||
if(threeD) {
|
||||
p.setBorder(loweredBorder);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
DemoModule demo = new DemoModule(null);
|
||||
demo.mainImpl();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
getContentPane().add(getDemoPanel(), BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
void updateDragEnabled(boolean dragEnabled) {}
|
||||
}
|
||||
46
test/jdk/sanity/client/lib/SwingSet2/src/EmeraldTheme.java
Normal file
46
test/jdk/sanity/client/lib/SwingSet2/src/EmeraldTheme.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
import javax.swing.plaf.metal.DefaultMetalTheme;
|
||||
|
||||
/**
|
||||
* This class describes a theme using glowing green colors.
|
||||
*
|
||||
* @author Jeff Dinkins
|
||||
*/
|
||||
public class EmeraldTheme extends DefaultMetalTheme {
|
||||
|
||||
public static String NAME = "Emerald";
|
||||
|
||||
public String getName() { return NAME; }
|
||||
|
||||
private final ColorUIResource primary1 = new ColorUIResource(51, 142, 71);
|
||||
private final ColorUIResource primary2 = new ColorUIResource(102, 193, 122);
|
||||
private final ColorUIResource primary3 = new ColorUIResource(153, 244, 173);
|
||||
|
||||
protected ColorUIResource getPrimary1() { return primary1; }
|
||||
protected ColorUIResource getPrimary2() { return primary2; }
|
||||
protected ColorUIResource getPrimary3() { return primary3; }
|
||||
|
||||
}
|
||||
222
test/jdk/sanity/client/lib/SwingSet2/src/OptionPaneDemo.java
Normal file
222
test/jdk/sanity/client/lib/SwingSet2/src/OptionPaneDemo.java
Normal file
@ -0,0 +1,222 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
/**
|
||||
* JOptionPaneDemo
|
||||
*
|
||||
* @author Jeff Dinkins
|
||||
*/
|
||||
public class OptionPaneDemo extends DemoModule {
|
||||
|
||||
public static final String DEMO_NAME = "OptionPaneDemo";
|
||||
public static final String INPUT_BUTTON = "Show Input Dialog";
|
||||
|
||||
/**
|
||||
* main method allows us to run as a standalone demo.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
OptionPaneDemo demo = new OptionPaneDemo(null);
|
||||
demo.mainImpl();
|
||||
}
|
||||
|
||||
/**
|
||||
* OptionPaneDemo Constructor
|
||||
*/
|
||||
public OptionPaneDemo(SwingSet2 swingset) {
|
||||
// Set the title for this demo, and an icon used to represent this
|
||||
// demo inside the SwingSet2 app.
|
||||
super(swingset, DEMO_NAME, "toolbar/JOptionPane.gif");
|
||||
|
||||
JPanel demo = getDemoPanel();
|
||||
|
||||
demo.setLayout(new BoxLayout(demo, BoxLayout.X_AXIS));
|
||||
|
||||
JPanel bp = new JPanel() {
|
||||
public Dimension getMaximumSize() {
|
||||
return new Dimension(getPreferredSize().width, super.getMaximumSize().height);
|
||||
}
|
||||
};
|
||||
bp.setLayout(new BoxLayout(bp, BoxLayout.Y_AXIS));
|
||||
|
||||
bp.add(Box.createRigidArea(VGAP30));
|
||||
bp.add(Box.createRigidArea(VGAP30));
|
||||
|
||||
bp.add(createInputDialogButton()); bp.add(Box.createRigidArea(VGAP15));
|
||||
bp.add(createWarningDialogButton()); bp.add(Box.createRigidArea(VGAP15));
|
||||
bp.add(createMessageDialogButton()); bp.add(Box.createRigidArea(VGAP15));
|
||||
bp.add(createComponentDialogButton()); bp.add(Box.createRigidArea(VGAP15));
|
||||
bp.add(createConfirmDialogButton()); bp.add(Box.createVerticalGlue());
|
||||
|
||||
demo.add(Box.createHorizontalGlue());
|
||||
demo.add(bp);
|
||||
demo.add(Box.createHorizontalGlue());
|
||||
}
|
||||
|
||||
public JButton createWarningDialogButton() {
|
||||
Action a = new AbstractAction(getString("OptionPaneDemo.warningbutton")) {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JOptionPane.showMessageDialog(
|
||||
getDemoPanel(),
|
||||
getString("OptionPaneDemo.warningtext"),
|
||||
getString("OptionPaneDemo.warningtitle"),
|
||||
JOptionPane.WARNING_MESSAGE
|
||||
);
|
||||
}
|
||||
};
|
||||
return createButton(a);
|
||||
}
|
||||
|
||||
public JButton createMessageDialogButton() {
|
||||
Action a = new AbstractAction(getString("OptionPaneDemo.messagebutton")) {
|
||||
URL img = getClass().getResource("/resources/images/optionpane/bottle.gif");
|
||||
String imagesrc = "<img src=\"" + img + "\" width=\"284\" height=\"100\">";
|
||||
String message = getString("OptionPaneDemo.messagetext");
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JOptionPane.showMessageDialog(
|
||||
getDemoPanel(),
|
||||
"<html>" + imagesrc + "<br><center>" + message + "</center><br></html>"
|
||||
);
|
||||
}
|
||||
};
|
||||
return createButton(a);
|
||||
}
|
||||
|
||||
public JButton createConfirmDialogButton() {
|
||||
Action a = new AbstractAction(getString("OptionPaneDemo.confirmbutton")) {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int result = JOptionPane.showConfirmDialog(getDemoPanel(), getString("OptionPaneDemo.confirmquestion"));
|
||||
if(result == JOptionPane.YES_OPTION) {
|
||||
JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.confirmyes"));
|
||||
} else if(result == JOptionPane.NO_OPTION) {
|
||||
JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.confirmno"));
|
||||
}
|
||||
}
|
||||
};
|
||||
return createButton(a);
|
||||
}
|
||||
|
||||
public JButton createInputDialogButton() {
|
||||
Action a = new AbstractAction(getString("OptionPaneDemo.inputbutton")) {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String result = JOptionPane.showInputDialog(getDemoPanel(), getString("OptionPaneDemo.inputquestion"));
|
||||
if ((result != null) && (result.length() > 0)) {
|
||||
JOptionPane.showMessageDialog(getDemoPanel(),
|
||||
result + ": " +
|
||||
getString("OptionPaneDemo.inputresponse"));
|
||||
}
|
||||
}
|
||||
};
|
||||
return createButton(a);
|
||||
}
|
||||
|
||||
public JButton createComponentDialogButton() {
|
||||
Action a = new AbstractAction(getString("OptionPaneDemo.componentbutton")) {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// In a ComponentDialog, you can show as many message components and
|
||||
// as many options as you want:
|
||||
|
||||
// Messages
|
||||
Object[] message = new Object[4];
|
||||
message[0] = getString("OptionPaneDemo.componentmessage");
|
||||
message[1] = new JTextField(getString("OptionPaneDemo.componenttextfield"));
|
||||
|
||||
JComboBox cb = new JComboBox();
|
||||
cb.addItem(getString("OptionPaneDemo.component_cb1"));
|
||||
cb.addItem(getString("OptionPaneDemo.component_cb2"));
|
||||
cb.addItem(getString("OptionPaneDemo.component_cb3"));
|
||||
message[2] = cb;
|
||||
|
||||
message[3] = getString("OptionPaneDemo.componentmessage2");
|
||||
|
||||
// Options
|
||||
String[] options = {
|
||||
getString("OptionPaneDemo.component_op1"),
|
||||
getString("OptionPaneDemo.component_op2"),
|
||||
getString("OptionPaneDemo.component_op3"),
|
||||
getString("OptionPaneDemo.component_op4"),
|
||||
getString("OptionPaneDemo.component_op5")
|
||||
};
|
||||
int result = JOptionPane.showOptionDialog(
|
||||
getDemoPanel(), // the parent that the dialog blocks
|
||||
message, // the dialog message array
|
||||
getString("OptionPaneDemo.componenttitle"), // the title of the dialog window
|
||||
JOptionPane.DEFAULT_OPTION, // option type
|
||||
JOptionPane.INFORMATION_MESSAGE, // message type
|
||||
null, // optional icon, use null to use the default icon
|
||||
options, // options string array, will be made into buttons
|
||||
options[3] // option that should be made into a default button
|
||||
);
|
||||
switch(result) {
|
||||
case 0: // yes
|
||||
JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.component_r1"));
|
||||
break;
|
||||
case 1: // no
|
||||
JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.component_r2"));
|
||||
break;
|
||||
case 2: // maybe
|
||||
JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.component_r3"));
|
||||
break;
|
||||
case 3: // probably
|
||||
JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.component_r4"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
return createButton(a);
|
||||
}
|
||||
|
||||
public JButton createButton(Action a) {
|
||||
JButton b = new JButton() {
|
||||
public Dimension getMaximumSize() {
|
||||
int width = Short.MAX_VALUE;
|
||||
int height = super.getMaximumSize().height;
|
||||
return new Dimension(width, height);
|
||||
}
|
||||
};
|
||||
// setting the following client property informs the button to show
|
||||
// the action text as it's name. The default is to not show the
|
||||
// action text.
|
||||
b.putClientProperty("displayActionText", Boolean.TRUE);
|
||||
b.setAction(a);
|
||||
// b.setAlignmentX(JButton.CENTER_ALIGNMENT);
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
||||
46
test/jdk/sanity/client/lib/SwingSet2/src/RubyTheme.java
Normal file
46
test/jdk/sanity/client/lib/SwingSet2/src/RubyTheme.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
import javax.swing.plaf.metal.DefaultMetalTheme;
|
||||
|
||||
/**
|
||||
* This class describes a theme using red colors.
|
||||
*
|
||||
* @author Jeff Dinkins
|
||||
*/
|
||||
public class RubyTheme extends DefaultMetalTheme {
|
||||
|
||||
public static String NAME = "Ruby";
|
||||
|
||||
public String getName() { return NAME; }
|
||||
|
||||
private final ColorUIResource primary1 = new ColorUIResource(80, 10, 22);
|
||||
private final ColorUIResource primary2 = new ColorUIResource(193, 10, 44);
|
||||
private final ColorUIResource primary3 = new ColorUIResource(244, 10, 66);
|
||||
|
||||
protected ColorUIResource getPrimary1() { return primary1; }
|
||||
protected ColorUIResource getPrimary2() { return primary2; }
|
||||
protected ColorUIResource getPrimary3() { return primary3; }
|
||||
|
||||
}
|
||||
1261
test/jdk/sanity/client/lib/SwingSet2/src/SwingSet2.java
Normal file
1261
test/jdk/sanity/client/lib/SwingSet2/src/SwingSet2.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* <code>TextAndMnemonicUtils</code> allows to extract text and mnemonic values
|
||||
* from the unified text & mnemonic strings. For example:
|
||||
* LafMenu.laf.labelAndMnemonic=&Look && Feel
|
||||
* The extracted text is "Look & Feel" and the extracted mnemonic mnemonic is "L".
|
||||
*
|
||||
* There are several patterns for the text and mnemonic suffixes which are used
|
||||
* in the resource file. The patterns format is:
|
||||
* (resource key -> unified text & mnemonic resource key).
|
||||
*
|
||||
* Keys that have label suffixes:
|
||||
* (xxx_label -> xxx.labelAndMnemonic)
|
||||
*
|
||||
* Keys that have mnemonic suffixes:
|
||||
* (xxx_mnemonic -> xxx.labelAndMnemonic)
|
||||
*
|
||||
* Keys that do not have definite suffixes:
|
||||
* (xxx -> xxx.labelAndMnemonic)
|
||||
*
|
||||
* @author Alexander Scherbatiy
|
||||
*/
|
||||
public class TextAndMnemonicUtils {
|
||||
|
||||
// Label suffix for the text & mnemonic resource
|
||||
private static final String LABEL_SUFFIX = ".labelAndMnemonic";
|
||||
|
||||
// Resource bundle for internationalized and accessible text
|
||||
private static ResourceBundle bundle = null;
|
||||
|
||||
// Resource properties for the mnemonic key defenition
|
||||
private static Properties properties = null;
|
||||
|
||||
static {
|
||||
bundle = ResourceBundle.getBundle("resources.swingset");
|
||||
properties = new Properties();
|
||||
try {
|
||||
properties.load(TextAndMnemonicUtils.class.getResourceAsStream("resources/swingset.properties"));
|
||||
} catch (IOException ex) {
|
||||
System.out.println("java.io.IOException: Couldn't load properties from: resources/swingset.properties");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns accessible and internationalized strings or mnemonics from the
|
||||
* resource bundle. The key is converted to the text & mnemonic key.
|
||||
*
|
||||
* The following patterns are checked:
|
||||
* Keys that have label suffixes:
|
||||
* (xxx_label -> xxx.labelAndMnemonic)
|
||||
*
|
||||
* Keys that have mnemonic suffixes:
|
||||
* (xxx_mnemonic -> xxx.labelAndMnemonic)
|
||||
*
|
||||
* Keys that do not have definite suffixes:
|
||||
* (xxx -> xxx.labelAndMnemonic)
|
||||
*
|
||||
* Properties class is used to check if a key created for mnemonic exists.
|
||||
*/
|
||||
public static String getTextAndMnemonicString(String key) {
|
||||
|
||||
if (key.endsWith("_label")) {
|
||||
String compositeKey = composeKey(key, 6, LABEL_SUFFIX);
|
||||
String textAndMnemonic = bundle.getString(compositeKey);
|
||||
return getTextFromTextAndMnemonic(textAndMnemonic);
|
||||
}
|
||||
|
||||
if (key.endsWith("_mnemonic")) {
|
||||
|
||||
String compositeKey = composeKey(key, 9, LABEL_SUFFIX);
|
||||
Object value = properties.getProperty(compositeKey);
|
||||
|
||||
if (value != null) {
|
||||
String textAndMnemonic = bundle.getString(compositeKey);
|
||||
return getMnemonicFromTextAndMnemonic(textAndMnemonic);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String compositeKey = composeKey(key, 0, LABEL_SUFFIX);
|
||||
Object value = properties.getProperty(compositeKey);
|
||||
|
||||
if (value != null) {
|
||||
String textAndMnemonic = bundle.getString(compositeKey);
|
||||
return getTextFromTextAndMnemonic(textAndMnemonic);
|
||||
}
|
||||
|
||||
String textAndMnemonic = bundle.getString(key);
|
||||
return getTextFromTextAndMnemonic(textAndMnemonic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the text & mnemonic string to text string
|
||||
*
|
||||
* The '&' symbol is treated as the mnemonic pointer
|
||||
* The double "&&" symbols are treated as the single '&'
|
||||
*
|
||||
* For example the string "&Look && Feel" is converted to "Look & Feel"
|
||||
*/
|
||||
public static String getTextFromTextAndMnemonic(String text) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int prevIndex = 0;
|
||||
int nextIndex = text.indexOf('&');
|
||||
int len = text.length();
|
||||
|
||||
while (nextIndex != -1) {
|
||||
|
||||
String s = text.substring(prevIndex, nextIndex);
|
||||
sb.append(s);
|
||||
|
||||
nextIndex++;
|
||||
|
||||
if (nextIndex != len && text.charAt(nextIndex) == '&') {
|
||||
sb.append('&');
|
||||
nextIndex++;
|
||||
}
|
||||
|
||||
prevIndex = nextIndex;
|
||||
nextIndex = text.indexOf('&', nextIndex + 1);
|
||||
}
|
||||
|
||||
sb.append(text.substring(prevIndex, text.length()));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the text & mnemonic string to mnemonic
|
||||
*
|
||||
* The '&' symbol is treated the mnemonic pointer
|
||||
* The double "&&" symbols are treated as the single '&'
|
||||
*
|
||||
* For example the string "&Look && Feel" is converted to "L"
|
||||
*/
|
||||
public static String getMnemonicFromTextAndMnemonic(String text) {
|
||||
int index = text.indexOf('&');
|
||||
|
||||
while (0 <= index && index < text.length() - 1) {
|
||||
index++;
|
||||
if (text.charAt(index) == '&') {
|
||||
index = text.indexOf('&', index + 1);
|
||||
} else {
|
||||
char c = text.charAt(index);
|
||||
return String.valueOf(Character.toUpperCase(c));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the last n characters and adds the suffix
|
||||
*/
|
||||
private static String composeKey(String key, int reduce, String sufix) {
|
||||
return key.substring(0, key.length() - reduce) + sufix;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 881 B |
@ -0,0 +1,194 @@
|
||||
# This properties file is used to create a PropertyResourceBundle
|
||||
# It contains Locale specific strings used in the SwingSet demo.
|
||||
#
|
||||
# @author Jeff Dinkins
|
||||
|
||||
#################################
|
||||
### SwingSet Infrastructure ###
|
||||
#################################
|
||||
|
||||
### About Box ###
|
||||
|
||||
AboutBox.title=About Swing!
|
||||
AboutBox.ok_button_text=OK
|
||||
AboutBox.accessible_description=SwingSet2 demo is Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
|
||||
### Source Code ###
|
||||
SourceCode.loading=<html><body bgcolor=\"#ffffff\">Loading and formatting source code, please wait...</body></html>
|
||||
|
||||
### Status ###
|
||||
|
||||
Status.loading=Loading:
|
||||
Status.popupMenuAccessible=Press Shift-F10 to activate popup menu
|
||||
|
||||
### Menu Bar ###
|
||||
|
||||
MenuBar.accessible_description=Swing demo menu bar
|
||||
|
||||
|
||||
### Frame ###
|
||||
|
||||
Frame.title=SwingSet2
|
||||
|
||||
|
||||
### Tabbed Pane ###
|
||||
|
||||
TabbedPane.src.labelAndMnemonic=Source Code
|
||||
TabbedPane.src_tooltip=Look at the source code for this demo
|
||||
|
||||
|
||||
### Look & Feel Menu ###
|
||||
|
||||
LafMenu.laf.labelAndMnemonic=&Look && Feel
|
||||
LafMenu.laf_accessible_description=Menu that allows Look && Feel switching
|
||||
|
||||
LafMenu.java.labelAndMnemonic=&Java Look && Feel
|
||||
LafMenu.java_accessible_description=The Java Look && Feel
|
||||
|
||||
LafMenu.nimbus.labelAndMnemonic=&Nimbus Look && Feel
|
||||
LafMenu.nimbus_accessible_description=The Nimbus Look && Feel
|
||||
|
||||
LafMenu.mac.labelAndMnemonic=&Mac OS X Look && Feel
|
||||
LafMenu.mac_accessible_description=The Mac OS X Look && Feel
|
||||
|
||||
LafMenu.motif.labelAndMnemonic=M&otif Look && Feel
|
||||
LafMenu.motif_accessible_description=The Motif Look && Feel
|
||||
|
||||
LafMenu.windows.labelAndMnemonic=&Windows Style Look && Feel
|
||||
LafMenu.windows_accessible_description=Windows Style Look && Feel
|
||||
|
||||
LafMenu.gtk.labelAndMnemonic=>K Style Look && Feel
|
||||
LafMenu.gtk_accessible_description=GTK Style Look && Feel
|
||||
|
||||
### Themes Menu ###
|
||||
|
||||
ThemesMenu.themes.labelAndMnemonic=&Themes
|
||||
ThemesMenu.themes_accessible_description=Menu to switch Metal color themes
|
||||
|
||||
ThemesMenu.aqua.labelAndMnemonic=A&qua
|
||||
ThemesMenu.aqua_accessible_description=A Metal Theme that uses bluish-green colors
|
||||
|
||||
ThemesMenu.charcoal.labelAndMnemonic=&Charcoal
|
||||
ThemesMenu.charcoal_accessible_description=A Metal Theme that uses dark grey colors
|
||||
|
||||
ThemesMenu.contrast.labelAndMnemonic=&High Contrast
|
||||
ThemesMenu.contrast_accessible_description=A High Contrast Theme
|
||||
|
||||
ThemesMenu.ocean.labelAndMnemonic=&Ocean
|
||||
ThemesMenu.ocean_accessible_description=The Ocean Metal Theme
|
||||
|
||||
ThemesMenu.steel.labelAndMnemonic=&Steel
|
||||
ThemesMenu.steel_accessible_description=The blue/purple Metal Theme
|
||||
|
||||
ThemesMenu.emerald.labelAndMnemonic=&Emerald
|
||||
ThemesMenu.emerald_accessible_description=A Metal Theme that uses green colors
|
||||
|
||||
ThemesMenu.ruby.labelAndMnemonic=&Ruby
|
||||
ThemesMenu.ruby_accessible_description=A Metal Theme that uses red colors
|
||||
|
||||
|
||||
### Font SubMenu (under Themes)
|
||||
FontMenu.fonts.labelAndMnemonic=&Fonts
|
||||
FontMenu.fonts_accessible_description=Menu to choose fonts for the Java look and feel
|
||||
|
||||
FontMenu.bold.labelAndMnemonic=&Bold
|
||||
FontMenu.bold_accessible_description=Turns on bold fonts for the Java look and feel
|
||||
|
||||
FontMenu.plain.labelAndMnemonic=&Plain
|
||||
FontMenu.plain_accessible_description=Turns on plain fonts for the Java look and feel
|
||||
|
||||
|
||||
### Audio SubMenu (under Themes) ###
|
||||
|
||||
AudioMenu.audio.labelAndMnemonic=&Audio
|
||||
AudioMenu.audio_accessible_description=Menu to switch the amount of auditory feedback available within the Java look and feel
|
||||
|
||||
AudioMenu.on.labelAndMnemonic=&On
|
||||
AudioMenu.on_accessible_description=Turn on all auditory feedback for the Java look and feel
|
||||
|
||||
AudioMenu.default.labelAndMnemonic=&Default
|
||||
AudioMenu.default_accessible_description=Turn on the standard amount of auditory feedback for the Java look and feel
|
||||
|
||||
AudioMenu.off.labelAndMnemonic=O&ff
|
||||
AudioMenu.off_accessible_description=Turn off all auditory feedback for the Java look and feel
|
||||
|
||||
### Options Menu ###
|
||||
|
||||
OptionsMenu.options.labelAndMnemonic=O&ptions
|
||||
OptionsMenu.options_accessible_description=Menu containing other options
|
||||
|
||||
OptionsMenu.tooltip.labelAndMnemonic=Enable &Tool Tips
|
||||
OptionsMenu.tooltip_accessible_description=Enable or disable tool tips
|
||||
|
||||
OptionsMenu.dragEnabled.labelAndMnemonic=Enable &Drag Support
|
||||
OptionsMenu.dragEnabled_accessible_description=Enable or disable drag support
|
||||
|
||||
### File Menu ###
|
||||
|
||||
FileMenu.file.labelAndMnemonic=&File
|
||||
FileMenu.accessible_description=File Menu
|
||||
FileMenu.about.labelAndMnemonic=A&bout
|
||||
FileMenu.about_accessible_description=Find out about the SwingSet2 application
|
||||
FileMenu.open.labelAndMnemonic=&Open
|
||||
FileMenu.open_accessible_description=Placeholder menu item for opening a file
|
||||
FileMenu.save.labelAndMnemonic=&Save
|
||||
FileMenu.save_accessible_description=Placeholder menu item for saving a file
|
||||
FileMenu.save_as.labelAndMnemonic=Save &As...
|
||||
FileMenu.save_as_accessible_description=Placeholder menu item for saving a file with a new name
|
||||
FileMenu.exit.labelAndMnemonic=E&xit
|
||||
FileMenu.exit_accessible_description=Exit the SwingSet2 application
|
||||
|
||||
### Multi-Screen menu ###
|
||||
MultiMenu.multi.labelAndMnemonic=&Multiscreen
|
||||
MultiMenu.multi_accessible_description=Multiscreen Menu
|
||||
MultiMenu.all.labelAndMnemonic=Cre&ate SwingSet2 on all screens
|
||||
MultiMenu.all_accessible_description=Create a SwingSet2 window on every screen
|
||||
MultiMenu.single.labelAndMnemonic=Create SwingSet2 on screen
|
||||
MultiMenu.single_accessible_description=Create a SwingSet2 window on screen
|
||||
|
||||
|
||||
################################
|
||||
### DEMOS ###
|
||||
################################
|
||||
### OptionPane Demo ###
|
||||
|
||||
OptionPaneDemo.accessible_description=The OptionPane Demo shows examples of using JOptionPane to generate different common option dialog boxes
|
||||
OptionPaneDemo.tooltip=JOptionPane Demo
|
||||
OptionPaneDemo.name=Option Pane Demo
|
||||
|
||||
OptionPaneDemo.warningbutton=Show Warning Dialog
|
||||
OptionPaneDemo.componentbutton=Show Component Dialog
|
||||
OptionPaneDemo.inputbutton=Show Input Dialog
|
||||
OptionPaneDemo.confirmbutton=Show Confirmation Dialog
|
||||
OptionPaneDemo.messagebutton=Show Message Dialog
|
||||
|
||||
OptionPaneDemo.warningtitle=Warning Dialog Example
|
||||
OptionPaneDemo.warningtext=<html><P><font color=black>This is a test of the <font color=red><b>Emergency Broadcast System</b></font>. <i><b>This is <br> only a test</b></i>. The webmaster of your local intranet, in voluntary <br> cooperation with the <font color=blue><b>Federal</b></font> and <font color=blue><b>State</b></font> authorities, have <br> developed this system to keep you informed in the event of an <br> emergency. If this had been an actual emergency, the signal you <br> just heard would have been followed by official information, news <br> or instructions. This concludes this test of the <font color=red><b>Emergency <br> Broadcast System</b></font>.</font></P><P><br>Developer Note: This dialog demo used HTML for text formatting.</P></html>
|
||||
|
||||
OptionPaneDemo.messagetext=Message in a Bottle (yeah)
|
||||
|
||||
OptionPaneDemo.confirmquestion=Is the sun shining outside today?
|
||||
OptionPaneDemo.confirmyes=<html>Well what are you doing playing on the computer?<br> Get outside! Take a trip to the beach! Get a little sun!</html>
|
||||
OptionPaneDemo.confirmno=Well good thing you're inside protected from the elements!
|
||||
|
||||
OptionPaneDemo.inputquestion=What is your favorite movie?
|
||||
OptionPaneDemo.inputresponse=That was a pretty good movie!
|
||||
|
||||
OptionPaneDemo.componenttitle=Component Dialog Example
|
||||
OptionPaneDemo.componentmessage=<html>JOptionPane can contain as many components <br> as you want, such as a text field:</html>
|
||||
OptionPaneDemo.componenttextfield=or a combobox:
|
||||
OptionPaneDemo.component_cb1=item 1
|
||||
OptionPaneDemo.component_cb2=item 2
|
||||
OptionPaneDemo.component_cb3=item 3
|
||||
OptionPaneDemo.componentmessage2=<html>JOptionPane can also show as many options <br> as you want:</html>
|
||||
OptionPaneDemo.component_op1=Yes
|
||||
OptionPaneDemo.component_op2=No
|
||||
OptionPaneDemo.component_op3=Maybe
|
||||
OptionPaneDemo.component_op4=Probably
|
||||
OptionPaneDemo.component_op5=Cancel
|
||||
|
||||
OptionPaneDemo.component_r1=Upbeat and positive! I like that! Good choice.
|
||||
OptionPaneDemo.component_r2=Definitely not, I wouldn't do it either.
|
||||
OptionPaneDemo.component_r3=<html><font color=black> Mmmm.. yes, the situation is unclear at this <br> time. Check back when you know for sure.</font></html>
|
||||
OptionPaneDemo.component_r4=<html><font color=black>You know you want to. I think you should <br> have gone for broke and pressed "Yes".</font></html>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user