View Javadoc
1 /***************************************************************************** 2 * Virtual Mockup for Machine Vision 3 * Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr., 4 * Carlos S. Santos. 5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP 6 * 7 * Permission is granted to redistribute and/or modify this 8 * software under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html) 16 * for more details. 17 * 18 *****************************************************************************/ 19 20 package camera3d.gui; 21 22 import java.awt.*; 23 import javax.swing.*; 24 import java.awt.event.*; 25 import camera3d.VcLight; 26 import camera3d.VcLaserArray; 27 28 /*** 29 * Simple dialog for specifying type and name of a light to be created. 30 * 31 * @author Fábio Roberto de Miranda 32 * @version 1.0 33 */ 34 class LightChooserDialog extends JDialog { 35 36 public static final int OK_SELECTED = 0; 37 public static final int CANCEL_SELECTED = 1; 38 39 public static final int POINT_LIGHT = 0; 40 public static final int SPOT_LIGHT = 1; 41 public static final int DIRECTIONAL_LIGHT = 2; 42 public static final int AMBIENT_LIGHT = 3; 43 public static final int LASER_ARRAY = 4; 44 45 String[] lightStrings = {"Point", "Spot", "Directional", "Ambient","Laser Array"}; 46 JComboBox lightCombo = new JComboBox(lightStrings); 47 JLabel jLabel1 = new JLabel(); 48 JLabel jLabel2 = new JLabel(); 49 JLabel jLabel3 = new JLabel(); 50 JTextField lightNameLabel = new JTextField(); 51 JButton okBtn = new JButton(); 52 JButton cancelBtn = new JButton(); 53 54 String name; 55 private int lightType; 56 private int lastUserAction; 57 private int lastLightSelection; 58 59 JFrame owner; 60 61 GridBagLayout gridBagLayout1 = new GridBagLayout(); 62 63 /*** 64 * Creates a new dialog. 65 * @param owner Window that owns the dialog. 66 */ 67 public LightChooserDialog(JFrame owner){ 68 super(owner, "Please specify light parameters", true); 69 try { 70 jbInit(); 71 } 72 catch(Exception e) { 73 e.printStackTrace(); 74 } 75 76 this.owner = owner; 77 this.setSize(340, 220); 78 } 79 80 public LightChooserDialog() { 81 try { 82 jbInit(); 83 } 84 catch(Exception e) { 85 e.printStackTrace(); 86 } 87 } 88 89 private void jbInit() throws Exception { 90 lightNameLabel.setText("Light"); 91 this.setResizable(false); 92 this.setModal(true); 93 jLabel3.setText("Light name:"); 94 jLabel2.setText("Light type:"); 95 jLabel1.setText("Light Parameters"); 96 this.getContentPane().setLayout(gridBagLayout1); 97 okBtn.setText("OK"); 98 okBtn.addActionListener(new java.awt.event.ActionListener() { 99 public void actionPerformed(ActionEvent e) { 100 okBtn_actionPerformed(e); 101 } 102 }); 103 cancelBtn.setMargin(new Insets(2, 10, 2, 10)); 104 cancelBtn.setText("Cancel"); 105 cancelBtn.addActionListener(new java.awt.event.ActionListener() { 106 public void actionPerformed(ActionEvent e) { 107 cancelBtn_actionPerformed(e); 108 } 109 }); 110 this.getContentPane().add(lightCombo, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0 111 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(15, 35, 0, 56), 0, 0)); 112 this.getContentPane().add(lightNameLabel, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0 113 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(14, 34, 0, 56), 70, 5)); 114 this.getContentPane().add(jLabel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 115 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(21, 35, 0, 0), 16, -1)); 116 this.getContentPane().add(jLabel1, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0 117 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(14, 9, 0, 91), 22, 0)); 118 this.getContentPane().add(jLabel3, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 119 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(19, 35, 0, 7), 2, 0)); 120 this.getContentPane().add(okBtn, new GridBagConstraints(0, 3, 2, 1, 0.0, 0.0 121 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(29, 97, 11, 0), 17, 9)); 122 this.getContentPane().add(cancelBtn, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0 123 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(29, 0, 11, 96), 3, 9)); 124 125 } 126 127 /*** 128 * Makes the dialog visible. 129 */ 130 public void showDialog(){ 131 this.setLocation(owner.getX()+(owner.getWidth()-this.getWidth())/2, owner.getY()+(owner.getHeight()-this.getHeight())/2); 132 this.lightNameLabel.setText("Light"+(VcLight.getInstanceCounter())); 133 this.setVisible(true); 134 } 135 136 /*** 137 * Tells whether user has closed the dialog pushing OK or Cancel. 138 */ 139 public int getUserAction(){ 140 return lastUserAction; 141 } 142 143 void okBtn_actionPerformed(ActionEvent e) { 144 lastUserAction = LightChooserDialog.OK_SELECTED; 145 lastLightSelection = lightCombo.getSelectedIndex(); 146 name =lightNameLabel.getText(); 147 this.setVisible(false); 148 } 149 150 /*** 151 * Returns an integer identifying the type of light chosen when dialog has been shown last. 152 * Return value can be one of LightChooserDialog.AMBIENT_LIGHT, LightChooserDialog.POINT_LIGHT, 153 * LightChooserDialog.SPOT_LIGHT, LightChooserDialog.DIRECTIONAL_LIGHT or LightChooserDialog.LASER_ARRAY. 154 */ 155 public int getLightSelection(){ 156 return this.lastLightSelection; 157 } 158 159 /*** 160 * Returns the name of the light specified when dialog has been shown last. 161 */ 162 public String getLightName(){ 163 return this.name; 164 } 165 166 void cancelBtn_actionPerformed(ActionEvent e) { 167 lastUserAction = LightChooserDialog.CANCEL_SELECTED; 168 this.setVisible(false); 169 } 170 }

This page was automatically generated by Maven