1 /*
   2  *
   3  * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  *
   9  *   - Redistributions of source code must retain the above copyright
  10  *     notice, this list of conditions and the following disclaimer.
  11  *
  12  *   - Redistributions in binary form must reproduce the above copyright
  13  *     notice, this list of conditions and the following disclaimer in the
  14  *     documentation and/or other materials provided with the distribution.
  15  *
  16  *   - Neither the name of Oracle nor the names of its
  17  *     contributors may be used to endorse or promote products derived
  18  *     from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31  */
  32 package java2d;
  33 
  34 
  35 import static java2d.CustomControlsContext.State.START;
  36 import static java2d.CustomControlsContext.State.STOP;
  37 import static java2d.DemoImages.newDemoImages;
  38 import static java2d.DemoFonts.newDemoFonts;
  39 import static java2d.RunWindow.RunWindowSettings;
  40 import java.awt.BorderLayout;
  41 import java.awt.Color;
  42 import java.awt.Component;
  43 import java.awt.Cursor;
  44 import java.awt.Dimension;
  45 import java.awt.Font;
  46 import java.awt.Graphics;
  47 import java.awt.Graphics2D;
  48 import java.awt.GridBagConstraints;
  49 import java.awt.GridBagLayout;
  50 import java.awt.Insets;
  51 import java.awt.RenderingHints;
  52 import java.awt.Toolkit;
  53 import java.awt.event.ActionEvent;
  54 import java.awt.event.ActionListener;
  55 import java.awt.event.ItemEvent;
  56 import java.awt.event.ItemListener;
  57 import java.awt.event.WindowAdapter;
  58 import java.awt.event.WindowEvent;
  59 import java.awt.event.WindowListener;
  60 import java.awt.font.FontRenderContext;
  61 import java.awt.font.TextLayout;
  62 import javax.swing.Box;
  63 import javax.swing.BoxLayout;
  64 import javax.swing.Icon;
  65 import javax.swing.JCheckBoxMenuItem;
  66 import javax.swing.JColorChooser;
  67 import javax.swing.JFrame;
  68 import javax.swing.JLabel;
  69 import javax.swing.JMenu;
  70 import javax.swing.JMenuBar;
  71 import javax.swing.JMenuItem;
  72 import javax.swing.JOptionPane;
  73 import javax.swing.JPanel;
  74 import javax.swing.JPopupMenu;
  75 import javax.swing.JProgressBar;
  76 import javax.swing.JSeparator;
  77 import javax.swing.JTabbedPane;
  78 import javax.swing.SwingUtilities;
  79 import javax.swing.UIManager;
  80 import javax.swing.border.EtchedBorder;
  81 
  82 
  83 /**
  84  * A demo that shows Java 2D(TM) API features.
  85  */
  86 @SuppressWarnings("serial")
  87 public class J2Ddemo extends JPanel implements ItemListener, ActionListener, DemoInstVarsAccessor {
  88     private final GlobalControls controls;
  89     private final MemoryMonitor memorymonitor;
  90     private final PerformanceMonitor performancemonitor;
  91     private final JTabbedPane tabbedPane;
  92     private final DemoGroup[] group;
  93     private JCheckBoxMenuItem verboseCB;
  94     private JCheckBoxMenuItem ccthreadCB;
  95     private JCheckBoxMenuItem printCB = new JCheckBoxMenuItem("Default Printer");
  96     private Color backgroundColor;
  97     private JCheckBoxMenuItem memoryCB, perfCB;
  98     private final Intro intro;
  99     public static final String[][] demos = {
 100         { "Arcs_Curves", "Arcs", "BezierAnim", "Curves", "Ellipses" },
 101         { "Clipping", "Areas", "ClipAnim", "Intersection", "Text" },
 102         { "Colors", "BullsEye", "ColorConvert", "Rotator3D" },
 103         { "Composite", "ACimages", "ACrules", "FadeAnim" },
 104         { "Fonts", "AttributedStr", "Highlighting", "Outline", "Tree" },
 105         { "Images", "DukeAnim", "ImageOps", "JPEGFlip", "WarpImage" },
 106         { "Lines", "Caps", "Dash", "Joins", "LineAnim" },
 107         { "Mix", "Balls", "BezierScroller", "Stars3D" },
 108         { "Paint", "GradAnim", "Gradient", "Texture", "TextureAnim" },
 109         { "Paths", "Append", "CurveQuadTo", "FillStroke", "WindingRule" },
 110         { "Transforms", "Rotate", "SelectTx", "TransformAnim" }
 111     };
 112     private final boolean demoIsInApplet;
 113     private JCheckBoxMenuItem controlsCB;
 114     private JMenuItem runMI, cloneMI, fileMI, backgMI;
 115 //    private JMenuItem ccthreadMI, verboseMI;
 116     private RunWindow runwindow;
 117     private RunWindowSettings runWndSetts;
 118     private CloningFeature cloningfeature;
 119     private JFrame rf, cf;
 120 //    private GlobalPanel gp;
 121 
 122     /**
 123      * Construct the J2D Demo.
 124      */
 125     public J2Ddemo(boolean demoIsInApplet, DemoProgress progress, RunWindowSettings runWndSetts) {
 126         this.demoIsInApplet = demoIsInApplet;
 127         this.runWndSetts = runWndSetts;
 128 
 129         setLayout(new BorderLayout());
 130         setBorder(new EtchedBorder());
 131 
 132         add(createMenuBar(), BorderLayout.NORTH);
 133 
 134         // hard coding 14 = 11 demo dirs + images + fonts + Intro
 135         progress.setMaximum(13);
 136         progress.setText("Loading images");
 137         newDemoImages();
 138         progress.setValue(progress.getValue() + 1);
 139         progress.setText("Loading fonts");
 140         newDemoFonts();
 141         progress.setValue(progress.getValue() + 1);
 142         progress.setText("Loading Intro");
 143         intro = new Intro();
 144         progress.setValue(progress.getValue() + 1);
 145         UIManager.put("Button.margin", new Insets(0, 0, 0, 0));
 146 
 147         controls = new GlobalControls(this);
 148         memorymonitor = new MemoryMonitor();
 149         performancemonitor = new PerformanceMonitor();
 150 
 151         GlobalPanel gp = new GlobalPanel(this);
 152 
 153         tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT);
 154         tabbedPane.setFont(new Font(Font.SERIF, Font.PLAIN, 12));
 155         tabbedPane.addTab("", new J2DIcon(this), gp);
 156         tabbedPane.addChangeListener(gp);
 157 
 158         group = new DemoGroup[demos.length];
 159         for (int i = 0; i < demos.length; i++) {
 160             progress.setText("Loading demos." + demos[i][0]);
 161             group[i] = new DemoGroup(demos[i][0], this);
 162             tabbedPane.addTab(demos[i][0], null);
 163             progress.setValue(progress.getValue() + 1);
 164         }
 165 
 166         add(tabbedPane, BorderLayout.CENTER);
 167     }
 168 
 169     private JMenuBar createMenuBar() {
 170 
 171         JPopupMenu.setDefaultLightWeightPopupEnabled(false);
 172         JMenuBar menuBar = new JMenuBar();
 173 
 174         if (!demoIsInApplet) {
 175             JMenu file = menuBar.add(new JMenu("File"));
 176             fileMI = file.add(new JMenuItem("Exit"));
 177             fileMI.addActionListener(this);
 178         }
 179 
 180         JMenu options = menuBar.add(new JMenu("Options"));
 181 
 182         controlsCB = (JCheckBoxMenuItem) options.add(
 183                 new JCheckBoxMenuItem("Global Controls", true));
 184         controlsCB.addItemListener(this);
 185 
 186         memoryCB = (JCheckBoxMenuItem) options.add(
 187                 new JCheckBoxMenuItem("Memory Monitor", true));
 188         memoryCB.addItemListener(this);
 189 
 190         perfCB = (JCheckBoxMenuItem) options.add(
 191                 new JCheckBoxMenuItem("Performance Monitor", true));
 192         perfCB.addItemListener(this);
 193 
 194         options.add(new JSeparator());
 195 
 196         ccthreadCB = (JCheckBoxMenuItem) options.add(
 197                 new JCheckBoxMenuItem("Custom Controls Thread"));
 198         ccthreadCB.addItemListener(this);
 199 
 200         printCB = (JCheckBoxMenuItem) options.add(printCB);
 201 
 202         verboseCB = (JCheckBoxMenuItem) options.add(
 203                 new JCheckBoxMenuItem("Verbose"));
 204 
 205         options.add(new JSeparator());
 206 
 207         backgMI = options.add(new JMenuItem("Background Color"));
 208         backgMI.addActionListener(this);
 209 
 210         runMI = options.add(new JMenuItem("Run Window"));
 211         runMI.addActionListener(this);
 212 
 213         cloneMI = options.add(new JMenuItem("Cloning Feature"));
 214         cloneMI.addActionListener(this);
 215 
 216         return menuBar;
 217     }
 218 
 219     public void createRunWindow() {
 220         if (rf != null) {
 221             rf.toFront();
 222             return;
 223         }
 224         runwindow = new RunWindow(this, runWndSetts);
 225         WindowListener l = new WindowAdapter() {
 226 
 227             @Override
 228             public void windowClosing(WindowEvent e) {
 229                 runwindow.stop();
 230                 rf.dispose();
 231             }
 232 
 233             @Override
 234             public void windowClosed(WindowEvent e) {
 235                 rf = null;
 236             }
 237         };
 238         rf = new JFrame("Run");
 239         rf.addWindowListener(l);
 240         rf.getContentPane().add("Center", runwindow);
 241         rf.pack();
 242         if (!demoIsInApplet) {
 243             rf.setSize(new Dimension(200, 125));
 244         } else {
 245             rf.setSize(new Dimension(200, 150));
 246         }
 247         rf.setVisible(true);
 248     }
 249 
 250     public void startRunWindow() {
 251         SwingUtilities.invokeLater(new Runnable() {
 252 
 253             @Override
 254             public void run() {
 255                 runwindow.doRunAction();
 256             }
 257         });
 258     }
 259 
 260     @Override
 261     public void actionPerformed(ActionEvent e) {
 262         if (e.getSource().equals(fileMI)) {
 263             System.exit(0);
 264         } else if (e.getSource().equals(runMI)) {
 265             createRunWindow();
 266         } else if (e.getSource().equals(cloneMI)) {
 267             if (cloningfeature == null) {
 268                 cloningfeature = new CloningFeature(this);
 269                 WindowListener l = new WindowAdapter() {
 270 
 271                     @Override
 272                     public void windowClosing(WindowEvent e) {
 273                         cloningfeature.stop();
 274                         cf.dispose();
 275                     }
 276 
 277                     @Override
 278                     public void windowClosed(WindowEvent e) {
 279                         cloningfeature = null;
 280                     }
 281                 };
 282                 cf = new JFrame("Cloning Demo");
 283                 cf.addWindowListener(l);
 284                 cf.getContentPane().add("Center", cloningfeature);
 285                 cf.pack();
 286                 cf.setSize(new Dimension(320, 330));
 287                 cf.setVisible(true);
 288             } else {
 289                 cf.toFront();
 290             }
 291         } else if (e.getSource().equals(backgMI)) {
 292             backgroundColor =
 293                     JColorChooser.showDialog(this, "Background Color",
 294                     Color.white);
 295             for (int i = 1; i < tabbedPane.getTabCount(); i++) {
 296                 JPanel p = group[i - 1].getPanel();
 297                 for (int j = 0; j < p.getComponentCount(); j++) {
 298                     DemoPanel dp = (DemoPanel) p.getComponent(j);
 299                     if (dp.surface != null) {
 300                         dp.surface.setBackground(backgroundColor);
 301                     }
 302                 }
 303             }
 304         }
 305     }
 306 
 307     @Override
 308     public void itemStateChanged(ItemEvent e) {
 309         if (e.getSource().equals(controlsCB)) {
 310             boolean newVisibility = !controls.isVisible();
 311             controls.setVisible(newVisibility);
 312             for (Component cmp : controls.texturechooser.getComponents()) {
 313                 cmp.setVisible(newVisibility);
 314             }
 315         } else if (e.getSource().equals(memoryCB)) {
 316             if (memorymonitor.isVisible()) {
 317                 memorymonitor.setVisible(false);
 318                 memorymonitor.surf.setVisible(false);
 319                 memorymonitor.surf.stop();
 320             } else {
 321                 memorymonitor.setVisible(true);
 322                 memorymonitor.surf.setVisible(true);
 323                 memorymonitor.surf.start();
 324             }
 325         } else if (e.getSource().equals(perfCB)) {
 326             if (performancemonitor.isVisible()) {
 327                 performancemonitor.setVisible(false);
 328                 performancemonitor.surf.setVisible(false);
 329                 performancemonitor.surf.stop();
 330             } else {
 331                 performancemonitor.setVisible(true);
 332                 performancemonitor.surf.setVisible(true);
 333                 performancemonitor.surf.start();
 334             }
 335         } else if (e.getSource().equals(ccthreadCB)) {
 336             CustomControlsContext.State state =
 337                     ccthreadCB.isSelected() ? START : STOP;
 338             if (tabbedPane.getSelectedIndex() != 0) {
 339                 JPanel p = group[tabbedPane.getSelectedIndex() - 1].getPanel();
 340                 for (int i = 0; i < p.getComponentCount(); i++) {
 341                     DemoPanel dp = (DemoPanel) p.getComponent(i);
 342                     if (dp.ccc != null) {
 343                         dp.ccc.handleThread(state);
 344                     }
 345                 }
 346             }
 347         }
 348         revalidate();
 349     }
 350 
 351     public void start() {
 352         if (tabbedPane.getSelectedIndex() == 0) {
 353             intro.start();
 354         } else {
 355             group[tabbedPane.getSelectedIndex() - 1].setup(false);
 356             if (memorymonitor.surf.thread == null && memoryCB.getState()) {
 357                 memorymonitor.surf.start();
 358             }
 359             if (performancemonitor.surf.thread == null && perfCB.getState()) {
 360                 performancemonitor.surf.start();
 361             }
 362         }
 363     }
 364 
 365     public void stop() {
 366         if (tabbedPane.getSelectedIndex() == 0) {
 367             intro.stop();
 368         } else {
 369             memorymonitor.surf.stop();
 370             performancemonitor.surf.stop();
 371             int i = tabbedPane.getSelectedIndex() - 1;
 372             group[i].shutDown(group[i].getPanel());
 373         }
 374     }
 375 
 376     /**
 377      * Start of 'DemoInstVarsAccessor' implementation.
 378      */
 379     @Override
 380     public GlobalControls getControls() {
 381         return controls;
 382     }
 383 
 384     @Override
 385     public MemoryMonitor getMemoryMonitor() {
 386         return memorymonitor;
 387     }
 388 
 389     @Override
 390     public PerformanceMonitor getPerformanceMonitor() {
 391         return performancemonitor;
 392     }
 393 
 394     @Override
 395     public JTabbedPane getTabbedPane() {
 396         return tabbedPane;
 397     }
 398 
 399     @Override
 400     public DemoGroup[] getGroup() {
 401         return group;
 402     }
 403 
 404     @Override
 405     public void setGroupColumns(int columns) {
 406         for (DemoGroup dg : group) {
 407             if (dg != null) {
 408                 dg.columns = columns;
 409             }
 410         }
 411     }
 412 
 413     @Override
 414     public JCheckBoxMenuItem getVerboseCB() {
 415         return verboseCB;
 416     }
 417 
 418     @Override
 419     public JCheckBoxMenuItem getCcthreadCB() {
 420         return ccthreadCB;
 421     }
 422 
 423     @Override
 424     public JCheckBoxMenuItem getPrintCB() {
 425         return printCB;
 426     }
 427 
 428     @Override
 429     public Color getBackgroundColor() {
 430         return backgroundColor;
 431     }
 432 
 433     @Override
 434     public JCheckBoxMenuItem getMemoryCB() {
 435         return memoryCB;
 436     }
 437 
 438     @Override
 439     public JCheckBoxMenuItem getPerfCB() {
 440         return perfCB;
 441     }
 442 
 443     @Override
 444     public Intro getIntro() {
 445         return intro;
 446     }
 447     /**
 448      * End of 'DemoInstVarsAccessor' implementation.
 449      */
 450 
 451     static void addToGridBag(JPanel panel, Component comp,
 452             int x, int y, int w, int h, double weightx, double weighty) {
 453 
 454         GridBagLayout gbl = (GridBagLayout) panel.getLayout();
 455         GridBagConstraints c = new GridBagConstraints();
 456         c.fill = GridBagConstraints.BOTH;
 457         c.gridx = x;
 458         c.gridy = y;
 459         c.gridwidth = w;
 460         c.gridheight = h;
 461         c.weightx = weightx;
 462         c.weighty = weighty;
 463         panel.add(comp);
 464         gbl.setConstraints(comp, c);
 465     }
 466 
 467 
 468     /**
 469      * The Icon for the Intro tab.
 470      */
 471     static class J2DIcon implements Icon {
 472         private final DemoInstVarsAccessor demoInstVars;
 473         private static final Color myBlue = new Color(94, 105, 176);
 474         private static final Color myBlack = new Color(20, 20, 20);
 475         private static final Font font = new Font(Font.SERIF, Font.BOLD, 12);
 476         private FontRenderContext frc = new FontRenderContext(null, true, true);
 477         private TextLayout tl = new TextLayout("J2D demo", font, frc);
 478 
 479         public J2DIcon(DemoInstVarsAccessor demoInstVars) {
 480             this.demoInstVars = demoInstVars;
 481         }
 482 
 483         @Override
 484         public void paintIcon(Component c, Graphics g, int x, int y) {
 485             Graphics2D g2 = (Graphics2D) g;
 486             g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
 487                     RenderingHints.VALUE_ANTIALIAS_ON);
 488             g2.setFont(font);
 489             if (demoInstVars.getTabbedPane().getSelectedIndex() == 0) {
 490                 g2.setColor(myBlue);
 491             } else {
 492                 g2.setColor(myBlack);
 493             }
 494             tl.draw(g2, x, y + (float)(tl.getBounds().getHeight()));
 495         }
 496 
 497         @Override
 498         public int getIconWidth() {
 499             return (int)(tl.getAdvance())+5;
 500         }
 501 
 502         @Override
 503         public int getIconHeight() {
 504             return (int)(tl.getBounds().getHeight());
 505         }
 506     }
 507 
 508     /**
 509      * This class eliminates the need in presence of static 'JLabel', 'JProgressBar'
 510      * variables in 'J2Ddemo' class. It is a part of the fix which changed static
 511      * variables for instance variables in certain demo classes.
 512      */
 513     public static class DemoProgress {
 514         private final JLabel progressLabel;
 515         private final JProgressBar progressBar;
 516 
 517         public DemoProgress(JLabel progressLabel, JProgressBar progressBar) {
 518             if (progressLabel == null) {
 519                 throw new IllegalArgumentException("null was transferred as 'progressLabel' argument");
 520             }
 521             if (progressBar == null) {
 522                 throw new IllegalArgumentException("null was transferred as 'progressBar' argument");
 523             }
 524 
 525             this.progressLabel = progressLabel;
 526             this.progressBar = progressBar;
 527         }
 528 
 529         public void setText(String text) {
 530             progressLabel.setText(text);
 531         }
 532 
 533         public void setMaximum(int n) {
 534             progressBar.setMaximum(n);
 535         }
 536 
 537         public int getValue() {
 538             return progressBar.getValue();
 539         }
 540 
 541         public void setValue(int n) {
 542             progressBar.setValue(n);
 543         }
 544     }
 545 
 546     private static void initFrame(String[] args, RunWindowSettings runWndSetts) {
 547         final J2Ddemo[] demoOneInstArr = new J2Ddemo[1];
 548 
 549         JFrame frame = new JFrame("Java 2D(TM) Demo");
 550         frame.getAccessibleContext().setAccessibleDescription(
 551                 "A sample application to demonstrate Java2D(TM) features");
 552         int FRAME_WIDTH = 400, FRAME_HEIGHT = 200;
 553         frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
 554         Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
 555         frame.setLocation(d.width / 2 - FRAME_WIDTH / 2, d.height / 2 - FRAME_HEIGHT
 556                 / 2);
 557         frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
 558         frame.addWindowListener(new WindowAdapter() {
 559 
 560             @Override
 561             public void windowClosing(WindowEvent e) {
 562                 System.exit(0);
 563             }
 564 
 565             @Override
 566             public void windowDeiconified(WindowEvent e) {
 567                 J2Ddemo demo = demoOneInstArr[0];
 568                 if (demo != null) {
 569                     demo.start();
 570                 }
 571             }
 572 
 573             @Override
 574             public void windowIconified(WindowEvent e) {
 575                 J2Ddemo demo = demoOneInstArr[0];
 576                 if (demo != null) {
 577                     demo.stop();
 578                 }
 579             }
 580         });
 581         JOptionPane.setRootFrame(frame);
 582 
 583         JPanel progressPanel = new JPanel() {
 584 
 585             @Override
 586             public Insets getInsets() {
 587                 return new Insets(40, 30, 20, 30);
 588             }
 589         };
 590         progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.Y_AXIS));
 591         frame.getContentPane().add(progressPanel, BorderLayout.CENTER);
 592 
 593         Dimension labelSize = new Dimension(400, 20);
 594         JLabel progressLabel = new JLabel("Loading, please wait...");
 595         progressLabel.setAlignmentX(CENTER_ALIGNMENT);
 596         progressLabel.setMaximumSize(labelSize);
 597         progressLabel.setPreferredSize(labelSize);
 598         progressPanel.add(progressLabel);
 599         progressPanel.add(Box.createRigidArea(new Dimension(1, 20)));
 600 
 601         JProgressBar progressBar = new JProgressBar();
 602         progressBar.setStringPainted(true);
 603         progressLabel.setLabelFor(progressBar);
 604         progressBar.setAlignmentX(CENTER_ALIGNMENT);
 605         progressBar.setMinimum(0);
 606         progressBar.setValue(0);
 607         progressBar.getAccessibleContext().setAccessibleName(
 608                                   "J2D demo loading progress");
 609         progressPanel.add(progressBar);
 610         DemoProgress demoProgress = new DemoProgress(progressLabel, progressBar);
 611 
 612         frame.setVisible(true);
 613 
 614         J2Ddemo demo = new J2Ddemo(false, demoProgress, runWndSetts);
 615         demoOneInstArr[0] = demo;
 616 
 617         frame.getContentPane().removeAll();
 618         frame.getContentPane().setLayout(new BorderLayout());
 619         frame.getContentPane().add(demo, BorderLayout.CENTER);
 620         FRAME_WIDTH = 850;
 621         FRAME_HEIGHT = 600;
 622         frame.setLocation(d.width / 2 - FRAME_WIDTH / 2, d.height / 2 - FRAME_HEIGHT
 623                 / 2);
 624         frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
 625         frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
 626 
 627         for (int i = 0; i < args.length; i++) {
 628             String arg = args[i];
 629             String s = arg.substring(arg.indexOf('=') + 1);
 630             if (arg.startsWith("-runs=")) {
 631                 runWndSetts.setNumRuns(Integer.parseInt(s));
 632                 runWndSetts.setExit(true);
 633                 demo.createRunWindow();
 634             } else if (arg.startsWith("-screen=")) {
 635                 demo.getControls().screenCombo.setSelectedIndex(Integer.parseInt(s));
 636             } else if (arg.startsWith("-antialias=")) {
 637                 demo.controls.aliasCB.setSelected(s.endsWith("true"));
 638             } else if (arg.startsWith("-rendering=")) {
 639                 demo.controls.renderCB.setSelected(s.endsWith("true"));
 640             } else if (arg.startsWith("-texture=")) {
 641                 demo.controls.textureCB.setSelected(s.endsWith("true"));
 642             } else if (arg.startsWith("-composite=")) {
 643                 demo.controls.compositeCB.setSelected(s.endsWith("true"));
 644             } else if (arg.startsWith("-verbose")) {
 645                 demo.verboseCB.setSelected(true);
 646             } else if (arg.startsWith("-print")) {
 647                 demo.printCB.setSelected(true);
 648                 runWndSetts.setPrintCBIsSelected(true);
 649             } else if (arg.startsWith("-columns=")) {
 650                 demo.setGroupColumns(Integer.parseInt(s));
 651             } else if (arg.startsWith("-buffers=")) {
 652                 // usage -buffers=3,10
 653                 runWndSetts.setBuffersFlag(true);
 654                 int i1 = arg.indexOf('=') + 1;
 655                 int i2 = arg.indexOf(',');
 656                 String s1 = arg.substring(i1, i2);
 657                 runWndSetts.setBufBeg(Integer.parseInt(s1));
 658                 s1 = arg.substring(i2 + 1, arg.length());
 659                 runWndSetts.setBufEnd(Integer.parseInt(s1));
 660             } else if (arg.startsWith("-ccthread")) {
 661                 demo.ccthreadCB.setSelected(true);
 662             } else if (arg.startsWith("-zoom")) {
 663                 runWndSetts.setZoomCBSelected(true);
 664             } else if (arg.startsWith("-maxscreen")) {
 665                 frame.setLocation(0, 0);
 666                 frame.setSize(d.width, d.height);
 667             }
 668         }
 669 
 670         frame.validate();
 671         frame.repaint();
 672         frame.getFocusTraversalPolicy().getDefaultComponent(frame).requestFocus();
 673         demo.start();
 674 
 675         if (runWndSetts.getExit()) {
 676             demo.startRunWindow();
 677         }
 678 
 679     }
 680 
 681     public static void main(final String args[]) {
 682         SwingUtilities.invokeLater(new Runnable() {
 683             @Override
 684             public void run() {
 685                 RunWindowSettings runWndSetts = new RunWindowSettings();
 686                 for (int i = 0; i < args.length; i++) {
 687                     if (args[i].startsWith("-h") || args[i].startsWith("-help")) {
 688                         String s = "\njava -jar J2Ddemo.jar -runs=5 -delay=5 -screen=5 "
 689                                 + "-antialias=true -rendering=true -texture=true "
 690                                 + "-composite=true -verbose -print -columns=3 "
 691                                 + "-buffers=5,10 -ccthread -zoom -maxscreen \n";
 692                         System.out.println(s);
 693                         s =
 694                                 "    -runs=5       Number of runs to execute\n"
 695                                 + "    -delay=5      Sleep amount between tabs\n"
 696                                 + "    -antialias=   true or false for antialiasing\n"
 697                                 + "    -rendering=   true or false for quality or speed\n"
 698                                 + "    -texture=     true or false for texturing\n"
 699                                 + "    -composite=   true or false for compositing\n"
 700                                 + "    -verbose      output Surface graphic states \n"
 701                                 + "    -print        during run print the Surface, "
 702                                 + "use the Default Printer\n"
 703                                 + "    -columns=3    # of columns to use in clone layout \n"
 704                                 + "    -screen=3     demos all use this screen type \n"
 705                                 + "    -buffers=5,10 during run - clone to see screens "
 706                                 + "five through ten\n"
 707                                 + "    -ccthread     Invoke the Custom Controls Thread \n"
 708                                 + "    -zoom         mouseClick on surface for zoom in  \n"
 709                                 + "    -maxscreen    take up the entire monitor screen \n";
 710                         System.out.println(s);
 711                         s =
 712                                 "Examples : \n" + "    Print all of the demos : \n"
 713                                 + "        java -jar J2Ddemo.jar -runs=1 -delay=60 -print \n"
 714                                 + "    Run zoomed in with custom control thread \n"
 715                                 + "        java -jar J2Ddemo.jar -runs=10 -zoom -ccthread\n";
 716                         System.out.println(s);
 717                         System.exit(0);
 718                     } else if (args[i].startsWith("-delay=")) {
 719                         String s = args[i].substring(args[i].indexOf('=') + 1);
 720                         runWndSetts.setDelay(Integer.parseInt(s));
 721                     }
 722                 }
 723 
 724                 initFrame(args, runWndSetts);
 725             }
 726         });
 727     }
 728 }