Browse Source

提交 demo 代码

master
VIVIMAN 3 years ago
parent
commit
19dd082f7b
  1. 28
      src/main/java/com/insigma/demos/DemoModule.java
  2. 393
      src/main/java/com/insigma/demos/SwingSet2.java
  3. 47
      src/main/java/com/insigma/demos/SwingSet2Applet.java
  4. 3
      src/main/java/com/insigma/ui/SwingFrame.java

28
src/main/java/com/insigma/demos/DemoModule.java

@ -1,26 +1,7 @@
package com.insigma.demos;/* package com.insigma.demos;
* Copyright (C) 2015 Jack Jiang(cngeeker.com) The BeautyEye Project.
* All rights reserved.
* Project URL:https://github.com/JackJiang2011/beautyeye
* Version 3.6
*
* Jack Jiang PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
* DemoModule.java at 2015-2-1 20:25:40, original version by Jack Jiang.
* You can contact author with jb2011@163.com.
*/
/*
* @(#)DemoModule.java 1.23 05/11/17
*/
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Dimension; import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@ -37,8 +18,6 @@ import javax.swing.border.EmptyBorder;
import org.jb2011.lnf.beautyeye.widget.N9ComponentFactory; import org.jb2011.lnf.beautyeye.widget.N9ComponentFactory;
// TODO: Auto-generated Javadoc
/** /**
* A generic SwingSet2 demo module. * A generic SwingSet2 demo module.
* *
@ -47,7 +26,6 @@ import org.jb2011.lnf.beautyeye.widget.N9ComponentFactory;
*/ */
public class DemoModule extends JApplet { public class DemoModule extends JApplet {
// The preferred size of the demo
/** /**
* The PREFERRE d_ width. * The PREFERRE d_ width.
*/ */
@ -61,10 +39,8 @@ public class DemoModule extends JApplet {
/** /**
* The lowered border. * The lowered border.
*/ */
Border loweredBorder = //new CompoundBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED), Border loweredBorder = new EmptyBorder(15, 10, 5, 10);
new EmptyBorder(15, 10, 5, 10);//);
// Premade convenience dimensions, for use wherever you need 'em.
/** /**
* The HGA p2. * The HGA p2.
*/ */

393
src/main/java/com/insigma/demos/SwingSet2.java

@ -1,7 +1,7 @@
/* /*
* Copyright (C) 2015 Jack Jiang(cngeeker.com) The BeautyEye Project. * Copyright (C) 2015 Jack Jiang(cngeeker.com) The BeautyEye Project.
* All rights reserved. * All rights reserved.
* Project URL:https://github.com/JackJiang2011/beautyeye * Project URL:https:
* Version 3.6 * Version 3.6
* *
* Jack Jiang PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * Jack Jiang PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
@ -66,35 +66,26 @@ public class SwingSet2 extends JPanel {
"com.insigma.demos.TextAreaDemo" "com.insigma.demos.TextAreaDemo"
}; };
// Possible Look & Feels
// private static final String mac =
// "com.sun.java.swing.plaf.mac.MacLookAndFeel";
/** /**
* The Constant metal. * The Constant metal.
*/ */
private static final String metal = private static final String metal = "javax.swing.plaf.metal.MetalLookAndFeel";
"javax.swing.plaf.metal.MetalLookAndFeel";
// private static final String motif =
// "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
/** /**
* The Constant windows. * The Constant windows.
*/ */
private static final String windows = private static final String windows = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
/** /**
* The Constant gtk. * The Constant gtk.
*/ */
private static final String gtk = private static final String gtk = "org.jb2011.lnf.windows2.Windows2LookAndFeel";
"org.jb2011.lnf.windows2.Windows2LookAndFeel";
// The current Look & Feel
/** /**
* The current look and feel. * The current look and feel.
*/ */
private static String currentLookAndFeel = metal; private static String currentLookAndFeel = metal;
// The preferred size of the demo
/** /**
* The Constant PREFERRED_WIDTH. * The Constant PREFERRED_WIDTH.
*/ */
@ -105,7 +96,7 @@ public class SwingSet2 extends JPanel {
*/ */
private static final int PREFERRED_HEIGHT = 640; private static final int PREFERRED_HEIGHT = 640;
// Box spacers
/** /**
* The HGAP. * The HGAP.
*/ */
@ -116,7 +107,7 @@ public class SwingSet2 extends JPanel {
*/ */
private Dimension VGAP = new Dimension(5, 1); private Dimension VGAP = new Dimension(5, 1);
// Resource bundle for internationalized and accessible text
/** /**
* The bundle. * The bundle.
*/ */
@ -127,19 +118,19 @@ public class SwingSet2 extends JPanel {
*/ */
private JPanel demoPanel = null; private JPanel demoPanel = null;
// About Box
/** /**
* The about box. * The about box.
*/ */
private JDialog aboutBox = null; private JDialog aboutBox = null;
// Status Bar
/** /**
* The status field. * The status field.
*/ */
private JLabel statusField = null; private JLabel statusField = null;
// Tool Bar
/** /**
* The toolbar. * The toolbar.
*/ */
@ -150,7 +141,6 @@ public class SwingSet2 extends JPanel {
*/ */
private ButtonGroup toolbarGroup = new ButtonGroup(); private ButtonGroup toolbarGroup = new ButtonGroup();
// Menus
/** /**
* The menu bar. * The menu bar.
*/ */
@ -191,7 +181,7 @@ public class SwingSet2 extends JPanel {
*/ */
private ButtonGroup audioMenuGroup = new ButtonGroup(); private ButtonGroup audioMenuGroup = new ButtonGroup();
// Popup menu
/** /**
* The popup menu. * The popup menu.
*/ */
@ -202,13 +192,11 @@ public class SwingSet2 extends JPanel {
*/ */
private ButtonGroup popupMenuGroup = new ButtonGroup(); private ButtonGroup popupMenuGroup = new ButtonGroup();
// Used only if swingset is an application
/** /**
* The frame. * The frame.
*/ */
private JFrame frame = null; private JFrame frame = null;
// To debug or not to debug, that is the question
/** /**
* The DEBUG. * The DEBUG.
*/ */
@ -218,8 +206,7 @@ public class SwingSet2 extends JPanel {
* The debug counter. * The debug counter.
*/ */
private int debugCounter = 0; private int debugCounter = 0;
// The tab pane that holds the demo
/** /**
* The tabbed pane. * The tabbed pane.
*/ */
@ -230,17 +217,11 @@ public class SwingSet2 extends JPanel {
*/ */
private JEditorPane demoSrcPane = null; private JEditorPane demoSrcPane = null;
// contentPane cache, saved from the applet or application frame
/** /**
* The content pane. * The content pane.
*/ */
Container contentPane = null; Container contentPane = null;
// number of swingsets - for multiscreen
// keep track of the number of SwingSets created - we only want to exit
// the program when the last one has been closed.
/** /**
* The num s ss. * The num s ss.
*/ */
@ -256,6 +237,10 @@ public class SwingSet2 extends JPanel {
*/ */
private boolean dragEnabled = false; private boolean dragEnabled = false;
/**
* The applet.
*/
private SwingSet2Applet applet = null;
/** /**
* SwingSet2 Main. Called only if we're an application, not an applet. * SwingSet2 Main. Called only if we're an application, not an applet.
@ -264,9 +249,13 @@ public class SwingSet2 extends JPanel {
* @throws Exception the exception * @throws Exception the exception
*/ */
public static void main(String[] args) { public static void main(String[] args) {
// Create SwingSet on the default monitor
initBeautyStyle(); initBeautyStyle();
SwingSet2 swingset = new SwingSet2(null, GraphicsEnvironment.
getLocalGraphicsEnvironment().
getDefaultScreenDevice().
getDefaultConfiguration());
log.info("启动成功:{}", swingset);
} }
public static void initBeautyStyle() { public static void initBeautyStyle() {
@ -280,10 +269,40 @@ public class SwingSet2 extends JPanel {
} }
} }
// ******************************************************* /**
// *************** Demo Loading Methods ****************** * Instantiates a new swing set2.
// ******************************************************* *
* @param applet the applet
*/
public SwingSet2(SwingSet2Applet applet) {
this(applet, null);
}
/**
* SwingSet2 Constructor.
*
* @param applet the applet
* @param gc the gc
*/
public SwingSet2(SwingSet2Applet applet, GraphicsConfiguration gc) {
// Note that applet may be null if this is started as an application
this.applet = applet;
if (!isApplet()) {
frame = createFrame(gc);
}
// set the layout
setLayout(new BorderLayout());
// set the preferred size of the demo
setPreferredSize(new Dimension(PREFERRED_WIDTH,PREFERRED_HEIGHT));
initializeDemo();
// Show the demo. Must do this on the GUI thread using invokeLater.
SwingUtilities.invokeLater(() -> showSwingSet2());
}
/** /**
* Initialize demo. * Initialize demo.
@ -292,8 +311,7 @@ public class SwingSet2 extends JPanel {
JPanel top = new JPanel(); JPanel top = new JPanel();
top.setLayout(new BorderLayout()); top.setLayout(new BorderLayout());
//* 由jb2011修改 this.setBorder(BorderFactory.createEmptyBorder(2, 0, 4, 0));
this.setBorder(BorderFactory.createEmptyBorder(2, 0, 4, 0));//2,2,4,2));
add(top, BorderLayout.NORTH); add(top, BorderLayout.NORTH);
@ -328,7 +346,7 @@ public class SwingSet2 extends JPanel {
demoPanel.setBorder(new DemoPanelBorder()); demoPanel.setBorder(new DemoPanelBorder());
tabbedPane.addTab("Hi There!", demoPanel); tabbedPane.addTab("Hi There!", demoPanel);
// Add html src code viewer
demoSrcPane = new JEditorPane("text/html", getString("SourceCode.loading")); demoSrcPane = new JEditorPane("text/html", getString("SourceCode.loading"));
demoSrcPane.setEditable(false); demoSrcPane.setEditable(false);
@ -336,7 +354,6 @@ public class SwingSet2 extends JPanel {
scroller.getViewport().add(demoSrcPane); scroller.getViewport().add(demoSrcPane);
tabbedPane.addTab( tabbedPane.addTab(
// getString("TabbedPane.src_label"),
"Java源代码", "Java源代码",
null, null,
scroller, scroller,
@ -351,19 +368,13 @@ public class SwingSet2 extends JPanel {
*/ */
public JMenuBar createMenus() { public JMenuBar createMenus() {
JMenuItem mi; JMenuItem mi;
// ***** create the menubar ****
JMenuBar menuBar = new JMenuBar(); JMenuBar menuBar = new JMenuBar();
menuBar.getAccessibleContext().setAccessibleName( menuBar.getAccessibleContext().setAccessibleName(
getString("MenuBar.accessible_description")); getString("MenuBar.accessible_description"));
// ***** create File menu
JMenu fileMenu = (JMenu) menuBar.add(new JMenu(getString("FileMenu.file_label"))); JMenu fileMenu = (JMenu) menuBar.add(new JMenu(getString("FileMenu.file_label")));
//TODO 以下代码用来测试项级Menu上设置图标
// fileMenu.setIcon(
// org.jb2011.lnf.beautyeye.ch9_menu
// .__IconFactory__.getInstance().getRadioButtonMenuItemCheckIcon());
fileMenu.setMnemonic(getMnemonic("FileMenu.file_mnemonic")); fileMenu.setMnemonic(getMnemonic("FileMenu.file_mnemonic"));
fileMenu.getAccessibleContext().setAccessibleDescription(getString("FileMenu.accessible_description")); fileMenu.getAccessibleContext().setAccessibleDescription(getString("FileMenu.accessible_description"));
@ -381,15 +392,14 @@ public class SwingSet2 extends JPanel {
createMenuItem(fileMenu, "FileMenu.save_as_label", "FileMenu.save_as_mnemonic", createMenuItem(fileMenu, "FileMenu.save_as_label", "FileMenu.save_as_mnemonic",
"FileMenu.save_as_accessible_description", null); "FileMenu.save_as_accessible_description", null);
fileMenu.addSeparator(); fileMenu.addSeparator();
createMenuItem(fileMenu, "FileMenu.exit_label", "FileMenu.exit_mnemonic", createMenuItem(fileMenu, "FileMenu.exit_label", "FileMenu.exit_mnemonic",
"FileMenu.exit_accessible_description", new ExitAction(this) "FileMenu.exit_accessible_description", new ExitAction(this)
); );
// Create these menu items for the first SwingSet only.
if (numSSs == 0) { if (numSSs == 0) {
// ***** create laf switcher menu
lafMenu = (JMenu) menuBar.add(new JMenu(getString("LafMenu.laf_label"))); lafMenu = (JMenu) menuBar.add(new JMenu(getString("LafMenu.laf_label")));
lafMenu.setMnemonic(getMnemonic("LafMenu.laf_mnemonic")); lafMenu.setMnemonic(getMnemonic("LafMenu.laf_mnemonic"));
lafMenu.getAccessibleContext().setAccessibleDescription( lafMenu.getAccessibleContext().setAccessibleDescription(
@ -397,20 +407,20 @@ public class SwingSet2 extends JPanel {
mi = createLafMenuItem(lafMenu, "LafMenu.java_label", "LafMenu.java_mnemonic", mi = createLafMenuItem(lafMenu, "LafMenu.java_label", "LafMenu.java_mnemonic",
"LafMenu.java_accessible_description", metal); "LafMenu.java_accessible_description", metal);
mi.setSelected(true); // this is the default l&f mi.setSelected(true);
createLafMenuItem(lafMenu, "LafMenu.windows_label", "LafMenu.windows_mnemonic", createLafMenuItem(lafMenu, "LafMenu.windows_label", "LafMenu.windows_mnemonic",
"LafMenu.windows_accessible_description", windows); "LafMenu.windows_accessible_description", windows);
createLafMenuItem(lafMenu, "LafMenu.gtk_label", "LafMenu.gtk_mnemonic", createLafMenuItem(lafMenu, "LafMenu.gtk_label", "LafMenu.gtk_mnemonic",
"LafMenu.gtk_accessible_description", gtk); "LafMenu.gtk_accessible_description", gtk);
// ***** create themes menu
themesMenu = (JMenu) menuBar.add(new JMenu(getString("ThemesMenu.themes_label"))); themesMenu = (JMenu) menuBar.add(new JMenu(getString("ThemesMenu.themes_label")));
themesMenu.setMnemonic(getMnemonic("ThemesMenu.themes_mnemonic")); themesMenu.setMnemonic(getMnemonic("ThemesMenu.themes_mnemonic"));
themesMenu.getAccessibleContext().setAccessibleDescription( themesMenu.getAccessibleContext().setAccessibleDescription(
getString("ThemesMenu.themes_accessible_description")); getString("ThemesMenu.themes_accessible_description"));
// ***** create the audio submenu under the theme menu
audioMenu = (JMenu) themesMenu.add(new JMenu(getString("AudioMenu.audio_label"))); audioMenu = (JMenu) themesMenu.add(new JMenu(getString("AudioMenu.audio_label")));
audioMenu.setMnemonic(getMnemonic("AudioMenu.audio_mnemonic")); audioMenu.setMnemonic(getMnemonic("AudioMenu.audio_mnemonic"));
audioMenu.getAccessibleContext().setAccessibleDescription( audioMenu.getAccessibleContext().setAccessibleDescription(
@ -425,7 +435,7 @@ public class SwingSet2 extends JPanel {
"AudioMenu.default_mnemonic", "AudioMenu.default_mnemonic",
"AudioMenu.default_accessible_description", "AudioMenu.default_accessible_description",
new DefaultAudioAction(this)); new DefaultAudioAction(this));
mi.setSelected(true); // This is the default feedback setting mi.setSelected(true);
createAudioMenuItem(audioMenu, "AudioMenu.off_label", createAudioMenuItem(audioMenu, "AudioMenu.off_label",
"AudioMenu.off_mnemonic", "AudioMenu.off_mnemonic",
@ -433,7 +443,7 @@ public class SwingSet2 extends JPanel {
new OffAudioAction(this)); new OffAudioAction(this));
// ***** create the font submenu under the theme menu
JMenu fontMenu = (JMenu) themesMenu.add(new JMenu(getString("FontMenu.fonts_label"))); JMenu fontMenu = (JMenu) themesMenu.add(new JMenu(getString("FontMenu.fonts_label")));
fontMenu.setMnemonic(getMnemonic("FontMenu.fonts_mnemonic")); fontMenu.setMnemonic(getMnemonic("FontMenu.fonts_mnemonic"));
fontMenu.getAccessibleContext().setAccessibleDescription( fontMenu.getAccessibleContext().setAccessibleDescription(
@ -450,26 +460,26 @@ public class SwingSet2 extends JPanel {
new ChangeFontAction(this, false), fontButtonGroup); new ChangeFontAction(this, false), fontButtonGroup);
// *** now back to adding color/font themes to the theme menu
mi = createThemesMenuItem(themesMenu, "ThemesMenu.ocean_label", mi = createThemesMenuItem(themesMenu, "ThemesMenu.ocean_label",
"ThemesMenu.ocean_mnemonic", "ThemesMenu.ocean_mnemonic",
"ThemesMenu.ocean_accessible_description", "ThemesMenu.ocean_accessible_description",
new OceanTheme()); new OceanTheme());
mi.setSelected(true); // This is the default theme mi.setSelected(true);
createThemesMenuItem(themesMenu, "ThemesMenu.steel_label", createThemesMenuItem(themesMenu, "ThemesMenu.steel_label",
"ThemesMenu.steel_mnemonic", "ThemesMenu.steel_mnemonic",
"ThemesMenu.steel_accessible_description", "ThemesMenu.steel_accessible_description",
new DefaultMetalTheme()); new DefaultMetalTheme());
// ***** create the options menu
optionsMenu = (JMenu) menuBar.add( optionsMenu = (JMenu) menuBar.add(
new JMenu(getString("OptionsMenu.options_label"))); new JMenu(getString("OptionsMenu.options_label")));
optionsMenu.setMnemonic(getMnemonic("OptionsMenu.options_mnemonic")); optionsMenu.setMnemonic(getMnemonic("OptionsMenu.options_mnemonic"));
optionsMenu.getAccessibleContext().setAccessibleDescription( optionsMenu.getAccessibleContext().setAccessibleDescription(
getString("OptionsMenu.options_accessible_description")); getString("OptionsMenu.options_accessible_description"));
// ***** create tool tip submenu item.
mi = createCheckBoxMenuItem(optionsMenu, "OptionsMenu.tooltip_label", mi = createCheckBoxMenuItem(optionsMenu, "OptionsMenu.tooltip_label",
"OptionsMenu.tooltip_mnemonic", "OptionsMenu.tooltip_mnemonic",
"OptionsMenu.tooltip_accessible_description", "OptionsMenu.tooltip_accessible_description",
@ -568,7 +578,7 @@ public class SwingSet2 extends JPanel {
String accessibleDescription, Action action) { String accessibleDescription, Action action) {
JMenuItem mi = (JMenuItem) menu.add(new JMenuItem(getString(label))); JMenuItem mi = (JMenuItem) menu.add(new JMenuItem(getString(label)));
// mi.setBorder(BorderFactory.createEmptyBorder());
mi.setMnemonic(getMnemonic(mnemonic)); mi.setMnemonic(getMnemonic(mnemonic));
mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription)); mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription));
mi.addActionListener(action); mi.addActionListener(action);
@ -594,7 +604,7 @@ public class SwingSet2 extends JPanel {
themesMenuGroup.add(mi); themesMenuGroup.add(mi);
mi.setMnemonic(getMnemonic(mnemonic)); mi.setMnemonic(getMnemonic(mnemonic));
mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription)); mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription));
// mi.addActionListener(new ChangeThemeAction(this, theme));
return mi; return mi;
} }
@ -611,13 +621,10 @@ public class SwingSet2 extends JPanel {
*/ */
public JMenuItem createLafMenuItem(JMenu menu, String label, String mnemonic, public JMenuItem createLafMenuItem(JMenu menu, String label, String mnemonic,
String accessibleDescription, String laf) { String accessibleDescription, String laf) {
JMenuItem mi = (JRadioButtonMenuItem) menu.add(new JRadioButtonMenuItem(getString(label))); JMenuItem mi = menu.add(new JRadioButtonMenuItem(getString(label)));
lafMenuGroup.add(mi); lafMenuGroup.add(mi);
mi.setMnemonic(getMnemonic(mnemonic)); mi.setMnemonic(getMnemonic(mnemonic));
mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription)); mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription));
// mi.addActionListener(new ChangeLookAndFeelAction(this, laf));
// mi.setEnabled(isAvailableLookAndFeel(laf));
return mi; return mi;
} }
@ -639,7 +646,7 @@ public class SwingSet2 extends JPanel {
createPopupMenuItem(popup, "LafMenu.gtk_label", "LafMenu.gtk_mnemonic", createPopupMenuItem(popup, "LafMenu.gtk_label", "LafMenu.gtk_mnemonic",
"LafMenu.gtk_accessible_description", gtk); "LafMenu.gtk_accessible_description", gtk);
// register key binding to activate popup menu
InputMap map = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); 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_MASK),
"postMenuAction"); "postMenuAction");
@ -665,8 +672,8 @@ public class SwingSet2 extends JPanel {
popupMenuGroup.add(mi); popupMenuGroup.add(mi);
mi.setMnemonic(getMnemonic(mnemonic)); mi.setMnemonic(getMnemonic(mnemonic));
mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription)); mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription));
// mi.addActionListener(new ChangeLookAndFeelAction(this, laf));
// mi.setEnabled(isAvailableLookAndFeel(laf));
return mi; return mi;
} }
@ -678,18 +685,18 @@ public class SwingSet2 extends JPanel {
*/ */
public void showSwingSet2() { public void showSwingSet2() {
if (getFrame() != null) { if (getFrame() != null) {
// put swingset in a frame and show it
JFrame f = getFrame(); JFrame f = getFrame();
f.setTitle(getString("Frame.title") + " - BeautyEye L&F v3.6 "); f.setTitle(getString("Frame.title") + " - BeautyEye L&F v3.6 ");
f.getContentPane().add(this, BorderLayout.CENTER); f.getContentPane().add(this, BorderLayout.CENTER);
// f.pack();
f.setSize(1024, 750); f.setSize(1024, 750);
Rectangle screenRect = f.getGraphicsConfiguration().getBounds(); Rectangle screenRect = f.getGraphicsConfiguration().getBounds();
Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets( Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(
f.getGraphicsConfiguration()); f.getGraphicsConfiguration());
// Make sure we don't place the demo off the screen.
int centerWidth = screenRect.width < f.getSize().width ? int centerWidth = screenRect.width < f.getSize().width ?
screenRect.x : screenRect.x :
screenRect.x + screenRect.width / 2 - f.getSize().width / 2; screenRect.x + screenRect.width / 2 - f.getSize().width / 2;
@ -706,33 +713,6 @@ public class SwingSet2 extends JPanel {
} }
} }
// *******************************************************
// ****************** Utility Methods ********************
// *******************************************************
/**
* A utility function that layers on top of the LookAndFeel's
* isSupportedLookAndFeel() method. Returns true if the LookAndFeel
* is supported. Returns false if the LookAndFeel is not supported
* and/or if there is any kind of error checking if the LookAndFeel
* is supported.
* <p>
* The L&F menu will use this method to detemine whether the various
* L&F options should be active or inactive.
*
* @param laf the laf
* @return true, if is available look and feel
*/
protected boolean isAvailableLookAndFeel(String laf) {
try {
Class lnfClass = Class.forName(laf);
LookAndFeel newLAF = (LookAndFeel) (lnfClass.newInstance());
return newLAF.isSupportedLookAndFeel();
} catch (Exception e) { // If ANYTHING weird happens, return false
return false;
}
}
/** /**
* Returns the frame instance. * Returns the frame instance.
* *
@ -742,49 +722,6 @@ public class SwingSet2 extends JPanel {
return frame; return frame;
} }
/**
* Returns the menubar.
*
* @return the menu bar
*/
public JMenuBar getMenuBar() {
return menuBar;
}
/**
* Returns the toolbar.
*
* @return the tool bar
*/
public ToggleButtonToolBar getToolBar() {
return toolbar;
}
/**
* Returns the toolbar button group.
*
* @return the tool bar group
*/
public ButtonGroup getToolBarGroup() {
return toolbarGroup;
}
/**
* Set the status.
*
* @param s the new status
*/
public void setStatus(String s) {
// do the following on the gui thread
SwingUtilities.invokeLater(new SwingSetRunnable(this, s) {
@Override
public void run() {
swingset.statusField.setText((String) obj);
}
});
}
/** /**
* This method returns a string from the demo's resource bundle. * This method returns a string from the demo's resource bundle.
@ -931,9 +868,9 @@ public class SwingSet2 extends JPanel {
} }
} }
// *******************************************************
// ************** ToggleButtonToolbar *****************
// *******************************************************
/** /**
* The zero insets. * The zero insets.
*/ */
@ -950,7 +887,7 @@ public class SwingSet2 extends JPanel {
public ToggleButtonToolBar() { public ToggleButtonToolBar() {
super(); super();
this.setFloatable(true); this.setFloatable(true);
// this.putClientProperty("ToolBar.isPaintPlainBackground", Boolean.TRUE);
} }
/** /**
@ -962,10 +899,10 @@ public class SwingSet2 extends JPanel {
JToggleButton addToggleButton(Action a) { JToggleButton addToggleButton(Action a) {
JToggleButton tb = new JToggleButton( JToggleButton tb = new JToggleButton(
(String) a.getValue(Action.NAME), null (String) a.getValue(Action.NAME), null
// (Icon)a.getValue(Action.SMALL_ICON)
); );
// tb.setMargin(zeroInsets);
// tb.setText(null);
tb.setEnabled(a.isEnabled()); tb.setEnabled(a.isEnabled());
tb.setToolTipText((String) a.getValue(Action.SHORT_DESCRIPTION)); tb.setToolTipText((String) a.getValue(Action.SHORT_DESCRIPTION));
tb.setAction(a); tb.setAction(a);
@ -974,9 +911,9 @@ public class SwingSet2 extends JPanel {
} }
} }
// *******************************************************
// ********* ToolBar Panel / Docking Listener ***********
// *******************************************************
/** /**
* The Class ToolBarPanel. * The Class ToolBarPanel.
@ -1022,53 +959,15 @@ public class SwingSet2 extends JPanel {
} }
} }
// *******************************************************
// ****************** Runnables ***********************
// *******************************************************
/** /**
* Generic SwingSet2 runnable. This is intended to run on the * Determines if this is an applet or application.
* AWT gui event thread so as not to muck things up by doing *
* gui work off the gui thread. Accepts a SwingSet2 and an Object * @return true, if is applet
* as arguments, which gives subtypes of this class the two
* "must haves" needed in most runnables for this demo.
*/ */
class SwingSetRunnable implements Runnable { public boolean isApplet() {
return (applet != null);
/**
* The swingset.
*/
protected SwingSet2 swingset;
/**
* The obj.
*/
protected Object obj;
/**
* Instantiates a new swing set runnable.
*
* @param swingset the swingset
* @param obj the obj
*/
public SwingSetRunnable(SwingSet2 swingset, Object obj) {
this.swingset = swingset;
this.obj = obj;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
}
} }
// *******************************************************
// ******************** Actions ***********************
// *******************************************************
/** /**
* The Class OkAction. * The Class OkAction.
*/ */
@ -1173,7 +1072,7 @@ public class SwingSet2 extends JPanel {
} }
} }
// Turns on all possible auditory feedback
/** /**
* The Class OnAudioAction. * The Class OnAudioAction.
@ -1200,14 +1099,14 @@ public class SwingSet2 extends JPanel {
*/ */
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
//* Jack Jiang 于2012-09-11日注释掉
// UIManager.put("AuditoryCues.playList",
// UIManager.get("AuditoryCues.allAuditoryCues"));
// swingset.updateLookAndFeel();
} }
} }
// Turns on the default amount of auditory feedback
/** /**
* The Class DefaultAudioAction. * The Class DefaultAudioAction.
@ -1234,14 +1133,14 @@ public class SwingSet2 extends JPanel {
*/ */
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
//* Jack Jiang 于2012-09-11日注释掉
// UIManager.put("AuditoryCues.playList",
// UIManager.get("AuditoryCues.defaultCueList"));
// swingset.updateLookAndFeel();
} }
} }
// Turns off all possible auditory feedback
/** /**
* The Class OffAudioAction. * The Class OffAudioAction.
@ -1268,14 +1167,35 @@ public class SwingSet2 extends JPanel {
*/ */
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
//* Jack Jiang 于2012-09-11日注释掉
// UIManager.put("AuditoryCues.playList",
// UIManager.get("AuditoryCues.noAuditoryCues"));
// swingset.updateLookAndFeel();
} }
} }
// Turns on or off the tool tips for the demo. /**
* Create a frame for SwingSet2 to reside in if brought up
* as an application.
*
* @param gc the gc
* @return the j frame
*/
public static JFrame createFrame(GraphicsConfiguration gc) {
JFrame frame = new JFrame(gc);
if (numSSs == 0) {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} else {
WindowListener l = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
numSSs--;
swingSets.remove(this);
}
};
frame.addWindowListener(l);
}
frame.setMinimumSize(new Dimension(100,100));
return frame;
}
/** /**
* The Class ToolTipAction. * The Class ToolTipAction.
@ -1391,7 +1311,7 @@ public class SwingSet2 extends JPanel {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (aboutBox == null) { if (aboutBox == null) {
// JPanel panel = new JPanel(new BorderLayout());
JPanel panel = new AboutPanel(swingset); JPanel panel = new AboutPanel(swingset);
panel.setLayout(new BorderLayout()); panel.setLayout(new BorderLayout());
@ -1399,7 +1319,7 @@ public class SwingSet2 extends JPanel {
aboutBox.setResizable(false); aboutBox.setResizable(false);
aboutBox.getContentPane().add(panel, BorderLayout.CENTER); aboutBox.getContentPane().add(panel, BorderLayout.CENTER);
// JButton button = new JButton(getString("AboutBox.ok_button_text"));
JPanel buttonpanel = new JPanel(); JPanel buttonpanel = new JPanel();
buttonpanel.setBorder(new javax.swing.border.EmptyBorder(0, 0, 3, 0)); buttonpanel.setBorder(new javax.swing.border.EmptyBorder(0, 0, 3, 0));
buttonpanel.setOpaque(false); buttonpanel.setOpaque(false);
@ -1416,9 +1336,9 @@ public class SwingSet2 extends JPanel {
} }
} }
// *******************************************************
// ********************** Misc *************************
// *******************************************************
/** /**
* The Class AboutPanel. * The Class AboutPanel.
@ -1498,21 +1418,13 @@ public class SwingSet2 extends JPanel {
*/ */
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
//* Jack Jiang 于2012-09-11日注释掉
// if (plain) {
// UIManager.put("swing.boldMetal", Boolean.FALSE);
// }
// else {
// UIManager.put("swing.boldMetal", Boolean.TRUE);
// }
// // Change the look and feel to force the settings to take effect.
// updateLookAndFeel();
} }
} }
//------------------------------------------------------------- 由jb2011于2012-06-20实现
//用于DemoPanel的边框实现,视觉目标是:简洁。
//原EtchedBorder边框太土,但是没边框将导致整体效果稍显单调,所以做此边框
/** /**
* The Class DemoPanelBorder. * The Class DemoPanelBorder.
@ -1531,28 +1443,23 @@ public class SwingSet2 extends JPanel {
@Override @Override
public void paintBorder(Component c, Graphics g, int x, int y, public void paintBorder(Component c, Graphics g, int x, int y,
int width, int height) { int width, int height) {
// g.drawLine(x,y, widthheight); // draw top
// g.drawLine(x,y, x,height-1); // draw left
// g.drawLine(width-1,y, width-1,height-1); // draw right
//** 绘制border的底线
//虚线样式
Stroke oldStroke = ((Graphics2D) g).getStroke(); Stroke oldStroke = ((Graphics2D) g).getStroke();
Stroke sroke = new BasicStroke(1, BasicStroke.CAP_BUTT, Stroke sroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_BEVEL, 0, new float[]{1, 2}, 0);//实线,空白 BasicStroke.JOIN_BEVEL, 0, new float[]{1, 2}, 0);
((Graphics2D) g).setStroke(sroke); ((Graphics2D) g).setStroke(sroke);
//底边上(浅灰色)
g.setColor(new Color(200, 200, 200)); g.setColor(new Color(200, 200, 200));
g.drawLine(x, height - 2, width - 1, height - 2); // draw bottom1 g.drawLine(x, height - 2, width - 1, height - 2);
//底边下(白色):绘制一条白色虚线的目的是与上面的灰线产生较强对比度从而形成立体效果
//,本L&F实现中因与Panel的底色对比度不够强烈而立体感不明显(颜色越深的底色最终效果越明显)
g.setColor(Color.white); g.setColor(Color.white);
g.drawLine(x, height - 1, width - 1, height - 1);//draw bottom2 g.drawLine(x, height - 1, width - 1, height - 1);
((Graphics2D) g).setStroke(oldStroke); ((Graphics2D) g).setStroke(oldStroke);
} }
//border只有底边,且高度为2像素
/* (non-Javadoc) /* (non-Javadoc)
* @see javax.swing.border.AbstractBorder#getBorderInsets(java.awt.Component) * @see javax.swing.border.AbstractBorder#getBorderInsets(java.awt.Component)
*/ */
@ -1566,8 +1473,8 @@ public class SwingSet2 extends JPanel {
*/ */
@Override @Override
public Insets getBorderInsets(Component c, Insets insets) { public Insets getBorderInsets(Component c, Insets insets) {
// insets.top = insets.left = insets.bottom = insets.right = 1;
return getBorderInsets(c);//insets; return getBorderInsets(c);
} }
} }
} }

47
src/main/java/com/insigma/demos/SwingSet2Applet.java

@ -0,0 +1,47 @@
/*
* Copyright (C) 2015 Jack Jiang(cngeeker.com) The BeautyEye Project.
* All rights reserved.
* Project URL:https://github.com/JackJiang2011/beautyeye
* Version 3.6
*
* Jack Jiang PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
* SwingSet2Applet.java at 2015-2-1 20:25:39, original version by Jack Jiang.
* You can contact author with jb2011@163.com.
*/
/*
* @(#)SwingSet2Applet.java 1.10 05/11/17
*/
package com.insigma.demos;
import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;
import javax.swing.*;
import java.awt.*;
import java.net.URL;
// TODO: Auto-generated Javadoc
/**
* The Class SwingSet2Applet.
*
* @version 1.10 11/17/05
* @author Jeff Dinkins
*/
public class SwingSet2Applet extends JApplet {
@Override
public void init() {
try {
BeautyEyeLNFHelper.launchBeautyEyeLNF();
} catch (Exception e) {
System.err.println("BeautyEyeLNF运行失败,原因是:"+e.getMessage());
}
getContentPane().setLayout(new BorderLayout());
getContentPane().add(new SwingSet2(this), BorderLayout.CENTER);
}
}

3
src/main/java/com/insigma/ui/SwingFrame.java

@ -36,6 +36,9 @@ import javax.swing.Timer;
import javax.swing.JTextPane; import javax.swing.JTextPane;
import java.awt.Component; import java.awt.Component;
/**
* @author BeiJing-GWY
*/
@Slf4j @Slf4j
public class SwingFrame extends JFrame implements ActionListener { public class SwingFrame extends JFrame implements ActionListener {

Loading…
Cancel
Save