home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / JBuilder8.iso / Solaris / resource / jre / demo / plugin / jfc / Java2D / src / java2d / GlobalControls.java < prev    next >
Encoding:
Java Source  |  2002-09-06  |  5.6 KB  |  152 lines

  1. /*
  2.  * Copyright (c) 2002 Sun Microsystems, Inc. All  Rights Reserved.
  3.  * 
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  * 
  8.  * -Redistributions of source code must retain the above copyright
  9.  *  notice, this list of conditions and the following disclaimer.
  10.  * 
  11.  * -Redistribution in binary form must reproduct the above copyright
  12.  *  notice, this list of conditions and the following disclaimer in
  13.  *  the documentation and/or other materials provided with the distribution.
  14.  * 
  15.  * Neither the name of Sun Microsystems, Inc. or the names of contributors
  16.  * may be used to endorse or promote products derived from this software
  17.  * without specific prior written permission.
  18.  * 
  19.  * This software is provided "AS IS," without a warranty of any kind. ALL
  20.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
  21.  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
  22.  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT
  23.  * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
  24.  * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
  25.  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
  26.  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
  27.  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
  28.  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
  29.  * IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  30.  * 
  31.  * You acknowledge that Software is not designed, licensed or intended for
  32.  * use in the design, construction, operation or maintenance of any nuclear
  33.  * facility.
  34.  */
  35.  
  36. /*
  37.  * @(#)GlobalControls.java    1.27 02/06/13
  38.  */
  39.  
  40.  
  41. package java2d;
  42.  
  43. import java.awt.*;
  44. import javax.swing.*;
  45. import java.awt.event.ItemListener;
  46. import java.awt.event.ItemEvent;
  47. import javax.swing.event.ChangeListener;
  48. import javax.swing.event.ChangeEvent;
  49. import javax.swing.border.TitledBorder;
  50. import javax.swing.border.EtchedBorder;
  51.  
  52.  
  53. /**
  54.  * Global Controls panel for changing graphic attributes of
  55.  * the demo surface.
  56.  */
  57. public class GlobalControls extends JPanel implements ItemListener, ChangeListener {
  58.  
  59.     static String[] screenNames = { 
  60.             "Auto Screen", "On Screen", "Off Screen",
  61.             "INT_xRGB", "INT_ARGB", "INT_ARGB_PRE", "INT_BGR",
  62.             "3BYTE_BGR", "4BYTE_ABGR", "4BYTE_ABGR_PRE", "USHORT_565_RGB",
  63.             "USHORT_x555_RGB", "BYTE_GRAY", "USHORT_GRAY",
  64.         "BYTE_BINARY", "BYTE_INDEXED", "BYTE_BINARY 2 bit", "BYTE_BINARY 4 bit",
  65.         "INT_RGBx", "USHORT_555x_RGB"};
  66.     static JComboBox screenCombo;
  67.     public TextureChooser texturechooser;
  68.     public JCheckBox aliasCB, renderCB, toolBarCB;
  69.     public JCheckBox compositeCB, textureCB;
  70.     public JSlider slider;
  71.     public Object obj;
  72.  
  73.     private Font font = new Font("serif", Font.PLAIN, 12);
  74.  
  75.  
  76.     public GlobalControls() {
  77.         setLayout(new GridBagLayout());
  78.         setBorder(new TitledBorder(new EtchedBorder(), "Global Controls"));
  79.  
  80.         aliasCB = createCheckBox("Anti-Aliasing", true, 0);
  81.         renderCB = createCheckBox("Rendering Quality", false, 1);
  82.         textureCB = createCheckBox("Texture", false, 2);
  83.         compositeCB = createCheckBox("AlphaComposite", false, 3);
  84.  
  85.         screenCombo = new JComboBox();
  86.         screenCombo.setPreferredSize(new Dimension(120, 18));
  87.         screenCombo.setLightWeightPopupEnabled(true);
  88.         screenCombo.setFont(font);
  89.         for (int i = 0; i < screenNames.length; i++) {
  90.             screenCombo.addItem(screenNames[i]);
  91.         } 
  92.         screenCombo.addItemListener(this);
  93.         Java2Demo.addToGridBag(this, screenCombo, 0, 4, 1, 1, 0.0, 0.0);
  94.  
  95.         toolBarCB = createCheckBox("Tools", false, 5);
  96.  
  97.         slider = new JSlider(JSlider.HORIZONTAL, 0, 200, 30);
  98.         slider.addChangeListener(this);
  99.         TitledBorder tb = new TitledBorder(new EtchedBorder());
  100.         tb.setTitleFont(font);
  101.         tb.setTitle("Anim delay = 30 ms");
  102.         slider.setBorder(tb);
  103.         slider.setMinimumSize(new Dimension(80,46));
  104.         Java2Demo.addToGridBag(this, slider, 0, 6, 1, 1, 1.0, 1.0);
  105.  
  106.         texturechooser = new TextureChooser(0);
  107.         Java2Demo.addToGridBag(this, texturechooser, 0, 7, 1, 1, 1.0, 1.0);
  108.     }
  109.  
  110.  
  111.     private JCheckBox createCheckBox(String s, boolean b, int y) {
  112.         JCheckBox cb = new JCheckBox(s, b);
  113.         cb.setFont(font);
  114.         cb.setHorizontalAlignment(JCheckBox.LEFT);
  115.         cb.addItemListener(this);
  116.         Java2Demo.addToGridBag(this, cb, 0, y, 1, 1, 1.0, 1.0);
  117.         return cb;
  118.     }
  119.  
  120.  
  121.     public void stateChanged(ChangeEvent e) {
  122.         int value = slider.getValue();
  123.         TitledBorder tb = (TitledBorder) slider.getBorder();
  124.         tb.setTitle("Anim delay = " + String.valueOf(value) + " ms");
  125.         int index = Java2Demo.tabbedPane.getSelectedIndex()-1;
  126.         DemoGroup dg = Java2Demo.group[index];
  127.         JPanel p = dg.getPanel();
  128.         for (int i = 0; i < p.getComponentCount(); i++) {
  129.             DemoPanel dp = (DemoPanel) p.getComponent(i);
  130.             if (dp.tools != null && dp.tools.slider != null) {
  131.                 dp.tools.slider.setValue(value);
  132.             }
  133.         } 
  134.         slider.repaint();
  135.     }
  136.  
  137.  
  138.     public void itemStateChanged(ItemEvent e) {
  139.         if (Java2Demo.tabbedPane.getSelectedIndex() != 0) {
  140.             obj = e.getSource();
  141.             int index = Java2Demo.tabbedPane.getSelectedIndex()-1;
  142.             Java2Demo.group[index].setup(true);
  143.             obj = null;
  144.         }
  145.     }
  146.  
  147.  
  148.     public Dimension getPreferredSize() {
  149.         return new Dimension(135,260);
  150.     }
  151. }
  152.