swingset2.java
来自「一个小公司要求给写的很简单的任务管理系统。」· Java 代码 · 共 1,408 行 · 第 1/4 页
JAVA
1,408 行
tb.setAction(a); add(tb); return tb; } } // ******************************************************* // ********* ToolBar Panel / Docking Listener *********** // ******************************************************* class ToolBarPanel extends JPanel implements ContainerListener { public boolean contains(int x, int y) { Component c = getParent(); if (c != null) { Rectangle r = c.getBounds(); return (x >= 0) && (x < r.width) && (y >= 0) && (y < r.height); } else { return super.contains(x,y); } } public void componentAdded(ContainerEvent e) { Container c = e.getContainer().getParent(); if (c != null) { c.getParent().validate(); c.getParent().repaint(); } } public void componentRemoved(ContainerEvent e) { Container c = e.getContainer().getParent(); if (c != null) { c.getParent().validate(); c.getParent().repaint(); } } } // ******************************************************* // ****************** Runnables *********************** // ******************************************************* /** * Generic SwingSet2 runnable. This is intended to run on the * 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 * as arguments, which gives subtypes of this class the two * "must haves" needed in most runnables for this demo. */ class SwingSetRunnable implements Runnable { protected SwingSet2 swingset; protected Object obj; public SwingSetRunnable(SwingSet2 swingset, Object obj) { this.swingset = swingset; this.obj = obj; } public void run() { } } // ******************************************************* // ******************** Actions *********************** // ******************************************************* public class SwitchToDemoAction extends AbstractAction { SwingSet2 swingset; DemoModule demo; public SwitchToDemoAction(SwingSet2 swingset, DemoModule demo) { super(demo.getName(), demo.getIcon()); this.swingset = swingset; this.demo = demo; } public void actionPerformed(ActionEvent e) { swingset.setDemo(demo); } } class OkAction extends AbstractAction { JDialog aboutBox; protected OkAction(JDialog aboutBox) { super("OkAction"); this.aboutBox = aboutBox; } public void actionPerformed(ActionEvent e) { aboutBox.setVisible(false); } } class ChangeLookAndFeelAction extends AbstractAction { SwingSet2 swingset; String laf; protected ChangeLookAndFeelAction(SwingSet2 swingset, String laf) { super("ChangeTheme"); this.swingset = swingset; this.laf = laf; } public void actionPerformed(ActionEvent e) { swingset.setLookAndFeel(laf); } } class ActivatePopupMenuAction extends AbstractAction { SwingSet2 swingset; JPopupMenu popup; protected ActivatePopupMenuAction(SwingSet2 swingset, JPopupMenu popup) { super("ActivatePopupMenu"); this.swingset = swingset; this.popup = popup; } public void actionPerformed(ActionEvent e) { Dimension invokerSize = getSize(); Dimension popupSize = popup.getPreferredSize(); popup.show(swingset, (invokerSize.width - popupSize.width) / 2, (invokerSize.height - popupSize.height) / 2); } } // Turns on all possible auditory feedback class OnAudioAction extends AbstractAction { SwingSet2 swingset; protected OnAudioAction(SwingSet2 swingset) { super("Audio On"); this.swingset = swingset; } public void actionPerformed(ActionEvent e) { UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.allAuditoryCues")); swingset.updateLookAndFeel(); } } // Turns on the default amount of auditory feedback class DefaultAudioAction extends AbstractAction { SwingSet2 swingset; protected DefaultAudioAction(SwingSet2 swingset) { super("Audio Default"); this.swingset = swingset; } public void actionPerformed(ActionEvent e) { UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.defaultCueList")); swingset.updateLookAndFeel(); } } // Turns off all possible auditory feedback class OffAudioAction extends AbstractAction { SwingSet2 swingset; protected OffAudioAction(SwingSet2 swingset) { super("Audio Off"); this.swingset = swingset; } public void actionPerformed(ActionEvent e) { UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.noAuditoryCues")); swingset.updateLookAndFeel(); } } // Turns on or off the tool tips for the demo. class ToolTipAction extends AbstractAction { protected ToolTipAction() { super("ToolTip Control"); } public void actionPerformed(ActionEvent e) { boolean status = ((JCheckBoxMenuItem)e.getSource()).isSelected(); ToolTipManager.sharedInstance().setEnabled(status); } } class DragSupportAction extends AbstractAction { protected DragSupportAction() { 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) { super("ChangeTheme"); this.swingset = swingset; this.theme = theme; } public void actionPerformed(ActionEvent e) { MetalLookAndFeel.setCurrentTheme(theme); swingset.updateLookAndFeel(); } } class ExitAction extends AbstractAction { SwingSet2 swingset; protected ExitAction(SwingSet2 swingset) { super("ExitAction"); this.swingset = swingset; } public void actionPerformed(ActionEvent e) { System.exit(0); } } class AboutAction extends AbstractAction { SwingSet2 swingset; protected AboutAction(SwingSet2 swingset) { super("AboutAction"); this.swingset = swingset; } public void actionPerformed(ActionEvent e) { if(aboutBox == null) { // JPanel panel = new JPanel(new BorderLayout()); JPanel panel = new AboutPanel(swingset); panel.setLayout(new BorderLayout()); aboutBox = new JDialog(swingset.getFrame(), getString("AboutBox.title"), false); aboutBox.setResizable(false); aboutBox.getContentPane().add(panel, BorderLayout.CENTER); // JButton button = new JButton(getString("AboutBox.ok_button_text")); JPanel buttonpanel = new JPanel(); buttonpanel.setBorder(new javax.swing.border.EmptyBorder(0, 0, 3, 0)); buttonpanel.setOpaque(false); JButton button = (JButton) buttonpanel.add( new JButton(getString("AboutBox.ok_button_text")) ); 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; int screen; protected MultiScreenAction(SwingSet2 swingset, int screen) { super("MultiScreenAction"); this.screen = screen; } public void actionPerformed(ActionEvent e) { 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); } } } // ******************************************************* // ********************** Misc ************************* // ******************************************************* class DemoLoadThread extends Thread { SwingSet2 swingset; public DemoLoadThread(SwingSet2 swingset) { this.swingset = swingset; } public void run() { swingset.loadDemos(); } } class AboutPanel extends JPanel { ImageIcon aboutimage = null; SwingSet2 swingset = null; public AboutPanel(SwingSet2 swingset) { this.swingset = swingset; aboutimage = swingset.createImageIcon("About.jpg", "AboutBox.accessible_description"); setOpaque(false); } public void paint(Graphics g) { aboutimage.paintIcon(this, g, 0, 0); super.paint(g); } public Dimension getPreferredSize() { return new Dimension(aboutimage.getIconWidth(), aboutimage.getIconHeight()); } } private class ChangeFontAction extends AbstractAction { private SwingSet2 swingset; private boolean plain; ChangeFontAction(SwingSet2 swingset, boolean plain) { super("FontMenu"); this.swingset = swingset; this.plain = plain; } public void actionPerformed(ActionEvent e) { 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(); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?