< prev index next >
src/demo/share/jfc/SwingSet2/SwingSet2.java
Print this page
*** 69,84 ****
"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
--- 69,79 ----
*** 124,136 ****
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
--- 119,128 ----
*** 149,179 ****
private static int numSSs = 0;
private static Vector<SwingSet2> swingSets = new Vector<SwingSet2>();
private boolean dragEnabled = false;
! public SwingSet2(SwingSet2Applet applet) {
! this(applet, 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;
!
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
--- 141,165 ----
private static int numSSs = 0;
private static Vector<SwingSet2> swingSets = new Vector<SwingSet2>();
private boolean dragEnabled = false;
! public SwingSet2() {
! this(null);
}
/**
* SwingSet2 Constructor
*/
! public SwingSet2(GraphicsConfiguration gc) {
String lafClassName = UIManager.getLookAndFeel().getClass().getName();
lookAndFeelData = getInstalledLookAndFeelData();
currentLookAndFeel = Arrays.stream(lookAndFeelData)
.filter(laf -> lafClassName.equals(laf.className))
.findFirst().get();
frame = createFrame(gc);
// set the layout
setLayout(new BorderLayout());
// set the preferred size of the demo
*** 196,206 ****
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.
getLocalGraphicsEnvironment().
getDefaultScreenDevice().
getDefaultConfiguration());
});
}
--- 182,192 ----
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(GraphicsEnvironment.
getLocalGraphicsEnvironment().
getDefaultScreenDevice().
getDefaultConfiguration());
});
}
*** 216,230 ****
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();
--- 202,212 ----
*** 307,323 ****
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")));
--- 289,303 ----
*** 429,439 ****
}
// ***** create the multiscreen menu, if we have multiple screens
- if (!isApplet()) {
GraphicsDevice[] screens = GraphicsEnvironment.
getLocalGraphicsEnvironment().
getScreenDevices();
if (screens.length > 1) {
--- 409,418 ----
*** 447,457 ****
createMultiscreenMenuItem(multiScreenMenu, MultiScreenAction.ALL_SCREENS);
for (int i = 0; i < screens.length; i++) {
createMultiscreenMenuItem(multiScreenMenu, i);
}
}
- }
return menuBar;
}
/**
--- 426,435 ----
*** 576,586 ****
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),
"postMenuAction");
map.put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0), "postMenuAction");
getActionMap().put("postMenuAction", new ActivatePopupMenuAction(this, popup));
return popup;
--- 554,564 ----
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_DOWN_MASK),
"postMenuAction");
map.put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0), "postMenuAction");
getActionMap().put("postMenuAction", new ActivatePopupMenuAction(this, popup));
return popup;
*** 657,671 ****
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);
*/
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();
--- 635,647 ----
tabbedPane.setToolTipTextAt(0, demo.getToolTip());
}
/**
! * Bring up the SwingSet2 demo by showing the frame
*/
public void showSwingSet2() {
// 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,698 ****
centerHeight = centerHeight < screenInsets.top ?
screenInsets.top : centerHeight;
f.setLocation(centerWidth, centerHeight);
! f.show();
numSSs++;
swingSets.add(this);
}
- }
// *******************************************************
// ****************** Utility Methods ********************
// *******************************************************
--- 660,673 ----
centerHeight = centerHeight < screenInsets.top ?
screenInsets.top : centerHeight;
f.setLocation(centerWidth, centerHeight);
! f.setVisible(true);
numSSs++;
swingSets.add(this);
}
// *******************************************************
// ****************** Utility Methods ********************
// *******************************************************
*** 701,735 ****
*/
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});
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;
}
--- 676,695 ----
*/
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});
demo = (DemoModule) demoConstructor.newInstance(new Object[]{this});
addDemo(demo);
} catch (Exception e) {
System.out.println("Error occurred loading demo: " + classname);
}
}
/**
* Returns the frame instance
*/
public JFrame getFrame() {
return frame;
}
*** 761,772 ****
*/
public Container getContentPane() {
if(contentPane == null) {
if(getFrame() != null) {
contentPane = getFrame().getContentPane();
- } else if (getApplet() != null) {
- contentPane = getApplet().getContentPane();
}
}
return contentPane;
}
--- 721,730 ----
*** 884,903 ****
}
}
}
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);
}
--- 842,857 ----
*** 907,923 ****
* 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);
}
}
--- 861,873 ----
*** 1140,1158 ****
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) {
--- 1090,1104 ----
*** 1206,1221 ****
panel.add(buttonpanel, BorderLayout.SOUTH);
button.addActionListener(new OkAction(aboutBox));
}
aboutBox.pack();
- if (isApplet()) {
- aboutBox.setLocationRelativeTo(getApplet());
- } else {
aboutBox.setLocationRelativeTo(getFrame());
! }
! aboutBox.show();
}
}
class MultiScreenAction extends AbstractAction {
static final int ALL_SCREENS = -1;
--- 1152,1163 ----
panel.add(buttonpanel, BorderLayout.SOUTH);
button.addActionListener(new OkAction(aboutBox));
}
aboutBox.pack();
aboutBox.setLocationRelativeTo(getFrame());
! aboutBox.setVisible(true);
}
}
class MultiScreenAction extends AbstractAction {
static final int ALL_SCREENS = -1;
*** 1229,1245 ****
GraphicsDevice[] gds = GraphicsEnvironment.
getLocalGraphicsEnvironment().
getScreenDevices();
if (screen == ALL_SCREENS) {
for (int i = 0; i < gds.length; i++) {
! SwingSet2 swingset = new SwingSet2(null,
gds[i].getDefaultConfiguration());
swingset.setDragEnabled(dragEnabled);
}
}
else {
! SwingSet2 swingset = new SwingSet2(null,
gds[screen].getDefaultConfiguration());
swingset.setDragEnabled(dragEnabled);
}
}
}
--- 1171,1187 ----
GraphicsDevice[] gds = GraphicsEnvironment.
getLocalGraphicsEnvironment().
getScreenDevices();
if (screen == ALL_SCREENS) {
for (int i = 0; i < gds.length; i++) {
! SwingSet2 swingset = new SwingSet2(
gds[i].getDefaultConfiguration());
swingset.setDragEnabled(dragEnabled);
}
}
else {
! SwingSet2 swingset = new SwingSet2(
gds[screen].getDefaultConfiguration());
swingset.setDragEnabled(dragEnabled);
}
}
}
< prev index next >