📄 java2demo.java
字号:
/* * @(#)Java2Demo.java 1.50 06/08/29 * * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * -Redistribution of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * -Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Sun Microsystems, Inc. or the names of contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed, licensed or intended * for use in the design, construction, operation or maintenance of any * nuclear facility. *//* * @(#)Java2Demo.java 1.50 06/08/29 */package java2d;import java.awt.*;import java.awt.event.*;import java.awt.font.TextLayout;import java.awt.font.FontRenderContext;import javax.swing.*;import javax.swing.border.*;import static java2d.CustomControlsContext.State.*;/** * A demo that shows Java 2D(TM) features. * * @version @(#)Java2Demo.java 1.33 99/08/16 * @author Brian Lichtenwalter (Framework, Intro, demos) * @author Jim Graham (demos) */public class Java2Demo extends JPanel implements ItemListener, ActionListener{ static Java2Demo demo; static GlobalControls controls; static MemoryMonitor memorymonitor; static PerformanceMonitor performancemonitor; static JTabbedPane tabbedPane; static JLabel progressLabel; static JProgressBar progressBar; static DemoGroup group[]; static JCheckBoxMenuItem verboseCB; static JCheckBoxMenuItem ccthreadCB; static JCheckBoxMenuItem printCB = new JCheckBoxMenuItem("Default Printer"); static Color backgroundColor; static JCheckBoxMenuItem memoryCB, perfCB; static Intro intro; static String[][] demos = { {"Arcs_Curves", "Arcs", "BezierAnim", "Curves", "Ellipses"}, {"Clipping", "Areas", "ClipAnim", "Intersection", "Text"}, {"Colors", "BullsEye", "ColorConvert", "Rotator3D"}, {"Composite", "ACimages", "ACrules", "FadeAnim"}, {"Fonts", "AttributedStr", "Highlighting", "Outline", "Tree"}, {"Images", "DukeAnim", "ImageOps", "JPEGFlip", "WarpImage"}, {"Lines", "Caps", "Dash", "Joins", "LineAnim"}, {"Mix", "Balls", "BezierScroller", "Stars3D"}, {"Paint", "GradAnim", "Gradient", "Texture", "TextureAnim"}, {"Paths", "Append", "CurveQuadTo", "FillStroke", "WindingRule"}, {"Transforms", "Rotate", "SelectTx", "TransformAnim"} }; private JCheckBoxMenuItem controlsCB; private JMenuItem runMI, cloneMI, fileMI, backgMI; private JMenuItem ccthreadMI, verboseMI; private RunWindow runwindow; private CloningFeature cloningfeature; private JFrame rf, cf; private GlobalPanel gp; /** * Construct the Java2D Demo. */ public Java2Demo() { setLayout(new BorderLayout()); setBorder(new EtchedBorder()); add(createMenuBar(), BorderLayout.NORTH); // hard coding 14 = 11 demo dirs + images + fonts + Intro progressBar.setMaximum(13); progressLabel.setText("Loading images"); new DemoImages(); progressBar.setValue(progressBar.getValue() + 1); progressLabel.setText("Loading fonts"); new DemoFonts(); progressBar.setValue(progressBar.getValue() + 1); progressLabel.setText("Loading Intro"); intro = new Intro(); progressBar.setValue(progressBar.getValue() + 1); UIManager.put("Button.margin", new Insets(0,0,0,0)); controls = new GlobalControls(); memorymonitor = new MemoryMonitor(); performancemonitor = new PerformanceMonitor(); GlobalPanel gp = new GlobalPanel(); tabbedPane = new JTabbedPane(); tabbedPane.setFont(new Font("serif", Font.PLAIN, 12)); tabbedPane.addTab("", new J2DIcon(), gp); tabbedPane.addChangeListener(gp); group = new DemoGroup[demos.length]; for (int i = 0; i < demos.length; i++) { progressLabel.setText("Loading demos." + demos[i][0]); group[i] = new DemoGroup(demos[i][0]); tabbedPane.addTab(demos[i][0], null); progressBar.setValue(progressBar.getValue() + 1); } add(tabbedPane, BorderLayout.CENTER); } private JMenuBar createMenuBar() { JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); if (Java2DemoApplet.applet == null) { JMenu file = (JMenu) menuBar.add(new JMenu("File")); fileMI = (JMenuItem) file.add(new JMenuItem("Exit")); fileMI.addActionListener(this); } JMenu options = (JMenu) menuBar.add(new JMenu("Options")); controlsCB = (JCheckBoxMenuItem) options.add( new JCheckBoxMenuItem("Global Controls", true)); controlsCB.addItemListener(this); memoryCB = (JCheckBoxMenuItem) options.add( new JCheckBoxMenuItem("Memory Monitor", true)); memoryCB.addItemListener(this); perfCB = (JCheckBoxMenuItem) options.add( new JCheckBoxMenuItem("Performance Monitor", true)); perfCB.addItemListener(this); options.add(new JSeparator()); ccthreadCB = (JCheckBoxMenuItem) options.add( new JCheckBoxMenuItem("Custom Controls Thread")); ccthreadCB.addItemListener(this); printCB = (JCheckBoxMenuItem) options.add(printCB); verboseCB = (JCheckBoxMenuItem) options.add( new JCheckBoxMenuItem("Verbose")); options.add(new JSeparator()); backgMI = (JMenuItem) options.add(new JMenuItem("Background Color")); backgMI.addActionListener(this); runMI = (JMenuItem) options.add(new JMenuItem("Run Window")); runMI.addActionListener(this); cloneMI = (JMenuItem) options.add(new JMenuItem("Cloning Feature")); cloneMI.addActionListener(this); return menuBar; } public void createRunWindow() { if (rf != null) { rf.toFront(); return; } runwindow = new RunWindow(); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { runwindow.stop(); rf.dispose(); } public void windowClosed(WindowEvent e) { rf = null; } }; rf = new JFrame("Run"); rf.addWindowListener(l); rf.getContentPane().add("Center", runwindow); rf.pack(); if (Java2DemoApplet.applet == null) { rf.setSize(new Dimension(200,125)); } else { rf.setSize(new Dimension(200,150)); } rf.setVisible(true); } public void startRunWindow() { SwingUtilities.invokeLater(new Runnable() { public void run() { runwindow.doRunAction(); } }); } public void actionPerformed(ActionEvent e) { if (e.getSource().equals(fileMI)) { System.exit(0); } else if (e.getSource().equals(runMI)) { createRunWindow(); } else if (e.getSource().equals(cloneMI)) { if (cloningfeature == null) { cloningfeature = new CloningFeature(); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { cloningfeature.stop(); cf.dispose(); } public void windowClosed(WindowEvent e) { cloningfeature = null; } }; cf = new JFrame("Cloning Demo"); cf.addWindowListener(l); cf.getContentPane().add("Center", cloningfeature); cf.pack(); cf.setSize(new Dimension(320,330)); cf.setVisible(true); } else { cf.toFront(); } } else if (e.getSource().equals(backgMI)) { backgroundColor = JColorChooser.showDialog(this, "Background Color", Color.white); for (int i = 1; i < tabbedPane.getTabCount(); i++) { JPanel p = group[i-1].getPanel(); for (int j = 0; j < p.getComponentCount(); j++) { DemoPanel dp = (DemoPanel) p.getComponent(j); if (dp.surface != null) { dp.surface.setBackground(backgroundColor); } } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -