< prev index next >
src/demo/share/jfc/SwingSet2/SwingSet2.java
Print this page
@@ -69,16 +69,11 @@
"TreeDemo"
};
void loadDemos() {
for(int i = 0; i < demos.length;) {
- if(isApplet() && demos[i].equals("FileChooserDemo")) {
- // don't load the file chooser demo if we are
- // an applet
- } else {
loadDemo(demos[i]);
- }
i++;
}
}
// The current Look & Feel
@@ -124,13 +119,10 @@
private ButtonGroup popupMenuGroup = new ButtonGroup();
// Used only if swingset is an application
private JFrame frame = null;
- // Used only if swingset is an applet
- private SwingSet2Applet applet = null;
-
// To debug or not to debug, that is the question
private boolean DEBUG = true;
private int debugCounter = 0;
// The tab pane that holds the demo
@@ -149,31 +141,25 @@
private static int numSSs = 0;
private static Vector<SwingSet2> swingSets = new Vector<SwingSet2>();
private boolean dragEnabled = false;
- public SwingSet2(SwingSet2Applet applet) {
- this(applet, null);
+ public SwingSet2() {
+ this(null);
}
/**
* SwingSet2 Constructor
*/
- public SwingSet2(SwingSet2Applet applet, GraphicsConfiguration gc) {
-
- // Note that applet may be null if this is started as an application
- this.applet = applet;
-
+ public SwingSet2(GraphicsConfiguration gc) {
String lafClassName = UIManager.getLookAndFeel().getClass().getName();
lookAndFeelData = getInstalledLookAndFeelData();
currentLookAndFeel = Arrays.stream(lookAndFeelData)
.filter(laf -> lafClassName.equals(laf.className))
.findFirst().get();
- if (!isApplet()) {
frame = createFrame(gc);
- }
// set the layout
setLayout(new BorderLayout());
// set the preferred size of the demo
@@ -196,11 +182,11 @@
public static void main(final String[] args) {
// must run in EDT when constructing the GUI components
SwingUtilities.invokeLater(() -> {
// Create SwingSet on the default monitor
UIManager.put("swing.boldMetal", Boolean.FALSE);
- SwingSet2 swingset = new SwingSet2(null, GraphicsEnvironment.
+ SwingSet2 swingset = new SwingSet2(GraphicsEnvironment.
getLocalGraphicsEnvironment().
getDefaultScreenDevice().
getDefaultConfiguration());
});
}
@@ -216,15 +202,11 @@
top.setLayout(new BorderLayout());
add(top, BorderLayout.NORTH);
menuBar = createMenus();
- if (isApplet()) {
- applet.setJMenuBar(menuBar);
- } else {
frame.setJMenuBar(menuBar);
- }
// creates popup menu accessible via keyboard
popupMenu = createPopupMenu();
ToolBarPanel toolbarPanel = new ToolBarPanel();
@@ -307,17 +289,15 @@
createMenuItem(fileMenu, "FileMenu.save_as_label", "FileMenu.save_as_mnemonic",
"FileMenu.save_as_accessible_description", null);
- if(!isApplet()) {
fileMenu.addSeparator();
createMenuItem(fileMenu, "FileMenu.exit_label", "FileMenu.exit_mnemonic",
"FileMenu.exit_accessible_description", new ExitAction(this)
);
- }
// Create these menu items for the first SwingSet only.
if (numSSs == 0) {
// ***** create laf switcher menu
lafMenu = (JMenu) menuBar.add(new JMenu(getString("LafMenu.laf_label")));
@@ -429,11 +409,10 @@
}
// ***** create the multiscreen menu, if we have multiple screens
- if (!isApplet()) {
GraphicsDevice[] screens = GraphicsEnvironment.
getLocalGraphicsEnvironment().
getScreenDevices();
if (screens.length > 1) {
@@ -447,11 +426,10 @@
createMultiscreenMenuItem(multiScreenMenu, MultiScreenAction.ALL_SCREENS);
for (int i = 0; i < screens.length; i++) {
createMultiscreenMenuItem(multiScreenMenu, i);
}
}
- }
return menuBar;
}
/**
@@ -576,11 +554,11 @@
createPopupMenuItem(popup, lafData);
}
// register key binding to activate popup menu
InputMap map = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
- map.put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, InputEvent.SHIFT_MASK),
+ map.put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, InputEvent.SHIFT_DOWN_MASK),
"postMenuAction");
map.put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0), "postMenuAction");
getActionMap().put("postMenuAction", new ActivatePopupMenuAction(this, popup));
return popup;
@@ -657,15 +635,13 @@
tabbedPane.setToolTipTextAt(0, demo.getToolTip());
}
/**
- * Bring up the SwingSet2 demo by showing the frame (only
- * applicable if coming up as an application, not an applet);
+ * Bring up the SwingSet2 demo by showing the frame
*/
public void showSwingSet2() {
- if(!isApplet() && getFrame() != null) {
// put swingset in a frame and show it
JFrame f = getFrame();
f.setTitle(getString("Frame.title"));
f.getContentPane().add(this, BorderLayout.CENTER);
f.pack();
@@ -684,15 +660,14 @@
centerHeight = centerHeight < screenInsets.top ?
screenInsets.top : centerHeight;
f.setLocation(centerWidth, centerHeight);
- f.show();
+ f.setVisible(true);
numSSs++;
swingSets.add(this);
}
- }
// *******************************************************
// ****************** Utility Methods ********************
// *******************************************************
@@ -701,35 +676,20 @@
*/
void loadDemo(String classname) {
setStatus(getString("Status.loading") + getString(classname + ".name"));
DemoModule demo = null;
try {
- Class demoClass = Class.forName(classname);
- Constructor demoConstructor = demoClass.getConstructor(new Class[]{SwingSet2.class});
+ Class<?> demoClass = Class.forName(classname);
+ Constructor<?> demoConstructor = demoClass.getConstructor(new Class[]{SwingSet2.class});
demo = (DemoModule) demoConstructor.newInstance(new Object[]{this});
addDemo(demo);
} catch (Exception e) {
System.out.println("Error occurred loading demo: " + classname);
}
}
/**
- * Determines if this is an applet or application
- */
- public boolean isApplet() {
- return (applet != null);
- }
-
- /**
- * Returns the applet instance
- */
- public SwingSet2Applet getApplet() {
- return applet;
- }
-
-
- /**
* Returns the frame instance
*/
public JFrame getFrame() {
return frame;
}
@@ -761,12 +721,10 @@
*/
public Container getContentPane() {
if(contentPane == null) {
if(getFrame() != null) {
contentPane = getFrame().getContentPane();
- } else if (getApplet() != null) {
- contentPane = getApplet().getContentPane();
}
}
return contentPane;
}
@@ -884,20 +842,16 @@
}
}
}
private void updateThisSwingSet() {
- if (isApplet()) {
- SwingUtilities.updateComponentTreeUI(getApplet());
- } else {
JFrame frame = getFrame();
if (frame == null) {
SwingUtilities.updateComponentTreeUI(this);
} else {
SwingUtilities.updateComponentTreeUI(frame);
}
- }
SwingUtilities.updateComponentTreeUI(popupMenu);
if (aboutBox != null) {
SwingUtilities.updateComponentTreeUI(aboutBox);
}
@@ -907,17 +861,13 @@
* Sets the current L&F on each demo module
*/
public void updateLookAndFeel() {
try {
UIManager.setLookAndFeel(currentLookAndFeel.className);
- if (isApplet()) {
- updateThisSwingSet();
- } else {
for (SwingSet2 ss : swingSets) {
ss.updateThisSwingSet();
}
- }
} catch (Exception ex) {
System.out.println("Failed loading L&F: " + currentLookAndFeel);
System.out.println(ex);
}
}
@@ -1140,19 +1090,15 @@
super("DragSupport Control");
}
public void actionPerformed(ActionEvent e) {
boolean dragEnabled = ((JCheckBoxMenuItem)e.getSource()).isSelected();
- if (isApplet()) {
- setDragEnabled(dragEnabled);
- } else {
for (SwingSet2 ss : swingSets) {
ss.setDragEnabled(dragEnabled);
}
}
}
- }
class ChangeThemeAction extends AbstractAction {
SwingSet2 swingset;
MetalTheme theme;
protected ChangeThemeAction(SwingSet2 swingset, MetalTheme theme) {
@@ -1206,16 +1152,12 @@
panel.add(buttonpanel, BorderLayout.SOUTH);
button.addActionListener(new OkAction(aboutBox));
}
aboutBox.pack();
- if (isApplet()) {
- aboutBox.setLocationRelativeTo(getApplet());
- } else {
aboutBox.setLocationRelativeTo(getFrame());
- }
- aboutBox.show();
+ aboutBox.setVisible(true);
}
}
class MultiScreenAction extends AbstractAction {
static final int ALL_SCREENS = -1;
@@ -1229,17 +1171,17 @@
GraphicsDevice[] gds = GraphicsEnvironment.
getLocalGraphicsEnvironment().
getScreenDevices();
if (screen == ALL_SCREENS) {
for (int i = 0; i < gds.length; i++) {
- SwingSet2 swingset = new SwingSet2(null,
+ SwingSet2 swingset = new SwingSet2(
gds[i].getDefaultConfiguration());
swingset.setDragEnabled(dragEnabled);
}
}
else {
- SwingSet2 swingset = new SwingSet2(null,
+ SwingSet2 swingset = new SwingSet2(
gds[screen].getDefaultConfiguration());
swingset.setDragEnabled(dragEnabled);
}
}
}
< prev index next >