/* * @(#)Controls.java 1.11 98/06/29 * * Copyright 1998 by Sun Microsystems, Inc., * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. * All rights reserved. * * This software is the confidential and proprietary information * of Sun Microsystems, Inc. ("Confidential Information"). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with Sun. */ import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Font; import com.sun.java.swing.JPanel; import com.sun.java.swing.JCheckBox; import com.sun.java.swing.JComboBox; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; import com.sun.java.swing.border.TitledBorder; import com.sun.java.swing.border.EtchedBorder; /** * Global Controls panel for changing graphic attributes of * the J2DCanvas demos. */ public class Controls extends JPanel implements ItemListener { public TextureChooser texturechooser; public JCheckBox aliasCB, renderCB, toolBarCB; public JCheckBox compositeCB, textureCB; public JComboBox screenCombo; public JCheckBox verboseCB; private JPanel panel; private Font font = new Font("Times New Roman", Font.PLAIN, 10); public Controls() { setLayout(new GridBagLayout()); setBorder(new TitledBorder(new EtchedBorder(), "Global Controls")); aliasCB = createCheckBox("Anti-Aliasing", true, 0); renderCB = createCheckBox("Rendering Quality", false, 1); textureCB = createCheckBox("Texture", false, 2); compositeCB = createCheckBox("AlphaComposite", false, 3); screenCombo = new JComboBox(); screenCombo.setLightWeightPopupEnabled(false); screenCombo.setPreferredSize(new Dimension(120, 18)); screenCombo.setAlignmentX(LEFT_ALIGNMENT); screenCombo.setFont(font); screenCombo.addItem("Auto Screen"); screenCombo.addItem("On Screen"); screenCombo.addItem("Off Screen"); screenCombo.addItem("INT_RGB"); screenCombo.addItem("INT_ARGB"); screenCombo.addItem("INT_ARGB_PRE"); screenCombo.addItem("INT_BGR"); screenCombo.addItem("3BYTE_BGR"); screenCombo.addItem("4BYTE_ABGR"); screenCombo.addItem("4BYTE_ABGR_PRE"); screenCombo.addItem("USHORT_565_RGB"); screenCombo.addItem("USHORT_555_RGB"); screenCombo.addItem("BYTE_GRAY"); // must create ColorModels for these types, FCS todo. //screenCombo.addItem("USHORT_GRAY"); //screenCombo.addItem("BYTE_BINARY"); //screenCombo.addItem("BYTE_INDEXED"); screenCombo.setSelectedIndex(0); screenCombo.addItemListener(this); Java2Demo.addToGridBag(this, screenCombo, 0, 4, 1, 1, 0.0, 0.0); toolBarCB = createCheckBox("ToolBar", false, 5); verboseCB = createCheckBox("Verbose", false, 6); texturechooser = new TextureChooser(0); Java2Demo.addToGridBag(this, texturechooser, 0, 7, 1, 1, 1.0, 1.0); } private JCheckBox createCheckBox(String s, boolean b, int y) { JCheckBox cb = new JCheckBox(s, b); cb.setFont(font); cb.setHorizontalAlignment(JCheckBox.LEFT); cb.addItemListener(this); Java2Demo.addToGridBag(this, cb, 0, y, 1, 1, 1.0, 1.0); return cb; } public void setup(JPanel panel) { this.panel = panel; } public void itemStateChanged(ItemEvent e) { for (int i = 0; i < panel.getComponentCount(); i++) { Component cmp = panel.getComponent(i); if (cmp instanceof CanvasPanel) { CanvasPanel cp = (CanvasPanel) cmp; if (cp.toolbar == null || cp.canvas == null) continue; if (e.getSource().equals(toolBarCB)) { cp.toolbar.setVisible(toolBarCB.isSelected()); cp.validate(); } else if (e.getSource().equals(verboseCB)) { if (verboseCB.isSelected()) cp.canvas.verbose(); } else if (e.getSource().equals(screenCombo)) { if (e.getStateChange() == ItemEvent.DESELECTED) return; cp.toolbar.screenCombo.setSelectedIndex(screenCombo.getSelectedIndex()); cp.toolbar.screenCombo.repaint(); } else { cp.toolbar.setup(true); } } } } public Dimension getMinimumSize() { return getPreferredSize(); } public Dimension getMaximumSize() { return getPreferredSize(); } public Dimension getPreferredSize() { return new Dimension(140,240); } }