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 * Title: Câmera Virtual - LIVES 23 * Description: Câmera Virtual para Controle via Sockets 24 * Copyright: Copyright (c) 2001 25 * Company: Centro de Educação em Informática - SENAC - SP 26 */ 27 import javax.swing.*; 28 import java.awt.*; 29 import java.awt.event.*; 30 import javax.media.j3d.*; 31 import javax.vecmath.*; 32 import java.util.*; 33 import java.io.*; 34 import camera3d.*; 35 import camera3d.gui.CustomFileFilter; 36 import camera3d.event.*; 37 38 /*** 39 * Pane that concentrates components whose actions affect the viewport, such as 40 * changing the view, taking snapshots, etc. 41 * 42 * @author Fábio Roberto de Miranda 43 * @version 1.0 44 * @see camera3d.Viewport 45 */ 46 47 class ViewportCommandPane extends JPanel implements ViewportChangeListener { 48 private boolean debugflag = true; 49 private JComboBox viewCombo = new JComboBox(); 50 51 private boolean isComboListenerEnabled = true; 52 53 private GUIControl guiControl; 54 private Viewport viewport; 55 56 private JFileChooser fileChooser = new JFileChooser(); 57 private SavedImageSizeDialog sizeDialog = new SavedImageSizeDialog(); 58 59 60 61 private Vector viewList = new Vector(20, 10); 62 private JButton snapshotBtn = new JButton(); 63 private JButton frameCameraBtn = new JButton(); 64 private ImageIcon frameIcon = new ImageIcon(ViewportCommandPane.class.getResource("icons/frame.gif")); 65 private GridBagLayout gridBagLayout1 = new GridBagLayout(); 66 67 68 ViewportCommandPane(Viewport viewport){ 69 this(); 70 this.setViewport(viewport); 71 } 72 73 ViewportCommandPane() { 74 try { 75 jbInit(); 76 } 77 catch(Exception e) { 78 e.printStackTrace(); 79 } 80 viewCombo.setLightWeightPopupEnabled(false); 81 } 82 private void jbInit() throws Exception { 83 this.setLayout(gridBagLayout1); 84 viewCombo.setFont(new java.awt.Font("Dialog", 1, 11)); 85 viewCombo.setToolTipText("Changes the view associated with this viewport"); 86 viewCombo.addActionListener(new java.awt.event.ActionListener() { 87 public void actionPerformed(ActionEvent e) { 88 viewCombo_actionPerformed(e); 89 } 90 }); 91 this.setBorder(BorderFactory.createEtchedBorder()); 92 snapshotBtn.setFont(new java.awt.Font("Dialog", 1, 10)); 93 snapshotBtn.setToolTipText("Saves this image to a file"); 94 snapshotBtn.setMargin(new Insets(2, 8, 2, 8)); 95 snapshotBtn.setText("snapshot"); 96 snapshotBtn.addActionListener(new java.awt.event.ActionListener() { 97 public void actionPerformed(ActionEvent e) { 98 snapshotBtn_actionPerformed(e); 99 } 100 }); 101 frameCameraBtn.setIcon(frameIcon); 102 frameCameraBtn.setMargin(new Insets(2, 8, 2, 8)); 103 frameCameraBtn.addActionListener(new java.awt.event.ActionListener() { 104 public void actionPerformed(ActionEvent e) { 105 frameCameraBtn_actionPerformed(e); 106 } 107 }); 108 this.add(frameCameraBtn, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 109 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 0, 6, 0), -11, -5)); 110 this.add(snapshotBtn, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 111 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 29, 6, 0), 9, -3)); 112 this.add(viewCombo, new GridBagConstraints(2, 0, 1, 1, 1.0, 0.0 113 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 0, 6, 20), 15, -3)); 114 } 115 116 /*** 117 * Sets Viewport which owns this ViewportCommandPane. 118 */ 119 void setViewport(Viewport vp){ 120 this.viewport = vp; 121 } 122 123 void setGUIControl(GUIControl guiControl){ 124 this.guiControl = guiControl; 125 } 126 /* 127 void translateBtn_actionPerformed(ActionEvent e) { 128 // testing code... 129 Transform3D tempT3D = new Transform3D(); 130 viewport.getCanvas3D().getImagePlateToVworld(tempT3D); 131 System.out.println(tempT3D); 132 Point3d p3d = new Point3d(); 133 Point2d p2d = new Point2d(); 134 viewport.getCanvas3D().getPixelLocationFromImagePlate(p3d, p2d); 135 System.out.println("View´s bg live?"+viewport.getView().isLive()); 136 System.out.println("Is view running?"+viewport.getCanvas3D().getView().isViewRunning()); 137 java.util.Enumeration enum = viewport.getCanvas3D().getView().getAllCanvas3Ds(); 138 System.out.println("Printing a marker (-+) for each canvas"); 139 while(enum.hasMoreElements()){ 140 Object o = enum.nextElement(); 141 System.out.println("_+"); 142 } 143 System.out.println("Printing a view of viewport´s canvas:"); 144 javax.media.j3d.View j3dView= viewport.getCanvas3D().getView(); 145 System.out.println(j3dView); 146 147 // end of testing code 148 }*/ 149 150 151 152 void viewCombo_actionPerformed(ActionEvent e) { 153 if (isComboListenerEnabled){ 154 //d String sel = viewCombo.getSelectedItem().toString(); 155 //d String sel = ""; 156 //d debugln("Selected item: "+sel); 157 int index = viewCombo.getSelectedIndex(); 158 VcView view; 159 if(index<viewList.size()&&index>=0){ 160 debugln("Selected Index: "+index); 161 debugln("viewList.size(): "+viewList.size()); 162 view = (VcView)viewList.get(index); 163 } 164 else{ 165 debugln("______________________WARNING______________________"); 166 debugln("Selected index is out of viewList bounds; index == "+index); 167 debugln("___________________________________________________"); 168 return; 169 } 170 debugln("Label of selected view: "+view.getLabel()); 171 /* 172 * Then viewport we want to change has the same name as the 173 * view it is displaying 174 */ 175 176 if (viewport==null){ 177 debugln("Viewport is null"); 178 } 179 if (viewport.getView()==null){ 180 debugln("Viewport's View is null"); 181 } 182 183 String viewportName = viewport.getView().getLabel(); 184 String newName = view.getLabel(); 185 //guiControl.changeViewInViewport(viewportName, newName); 186 guiControl.changeViewInViewport(viewport, view); 187 } 188 } 189 190 void addView(VcView view){ 191 setComboActionListener(false); 192 String viewName = view.getLabel(); 193 if(!viewList.contains(view)){ 194 viewList.add(view); 195 } 196 viewCombo.addItem(viewName); 197 setComboActionListener(true); 198 } 199 200 void removeView(VcView view){ 201 setComboActionListener(false); 202 String viewName = view.getLabel(); 203 viewList.remove(view); 204 viewCombo.removeItem(viewName); 205 setComboActionListener(true); 206 } 207 208 void replaceLabel(String newLabel, String oldLabel){ 209 setComboActionListener(false); 210 for(int i=0; i<viewCombo.getItemCount();i++){ 211 if(viewCombo.getItemAt(i).toString().equals(oldLabel)){ 212 // 213 int selObj = viewCombo.getSelectedIndex(); 214 viewCombo.removeItemAt(i); 215 viewCombo.insertItemAt(newLabel,i); 216 viewCombo.setSelectedIndex(selObj); 217 break; 218 } 219 } 220 setComboActionListener(true); 221 } 222 223 224 void setListOfViews(Vector views){ 225 setComboActionListener(false); // turns off combo events 226 /* 227 * Updates combo box to show an updated list of views 228 */ 229 debugln("CommandPane: setListOfViews called"); 230 this.viewList = views; 231 //viewList.clear(); 232 //viewList.addAll(views); 233 234 // empties combo box 235 viewCombo.removeAllItems(); 236 for (int i=0; i<viewList.size(); i++){ 237 Object obj = viewList.get(i); 238 if (obj != null){ 239 viewCombo.insertItemAt(((VcView)obj).getLabel(), i); 240 } 241 } 242 setComboActionListener(true); 243 } 244 245 void setSelectedView(VcView view){ 246 /* 247 * Searches view list to find the index of selected view in comboBox makes that the selected index 248 */ 249 // System.out.println("ViewportCommandPane: setSelectedView called"); 250 for (int i=0; i<viewCombo.getItemCount(); i++){ 251 Object obj = viewCombo.getItemAt(i); 252 if ((obj.toString()).equals(view.getLabel())){ 253 viewCombo.setSelectedIndex(i); 254 break; 255 } 256 } 257 } 258 259 void debugln(String s){ 260 if ((debugflag)&&(GUIControl.debugflag)){ 261 System.out.println(s); 262 } 263 264 } 265 266 public void viewportChanged(ViewportEvent viewportEvent){ 267 //VcView view = viewport.getView(); 268 //this.setSelectedView(view); 269 } 270 271 void setComboActionListener(boolean b){ 272 this.isComboListenerEnabled = b; 273 } 274 275 void snapshotBtn_actionPerformed(ActionEvent e) { 276 int w = viewport.getCanvas3D().getWidth(); 277 int h = viewport.getCanvas3D().getHeight(); 278 sizeDialog.setImageSize(w, h); 279 sizeDialog.setLocation(this.getX(), this.getY()); 280 sizeDialog.show(); 281 int sizeReturn = sizeDialog.getUserAction(); 282 if (sizeReturn == sizeDialog.CANCEL_SELECTED){ 283 return; 284 } 285 286 w = sizeDialog.getWidth(); 287 h = sizeDialog.getHeight(); 288 289 290 //added 16/08/2002 291 fileChooser.resetChoosableFileFilters(); 292 CustomFileFilter filter = new CustomFileFilter(); 293 filter.addExtension("jpg"); 294 filter.setDescription("JPEG File"); 295 fileChooser.setFileFilter(filter); 296 // 297 int returnVal = fileChooser.showSaveDialog(this); 298 if (returnVal == JFileChooser.APPROVE_OPTION){ 299 File file = fileChooser.getSelectedFile(); 300 String filename = null; 301 try { 302 filename = file.getCanonicalPath(); 303 } catch (IOException exc){ 304 } 305 if (filename!=null){ 306 debugln(filename); 307 if(!filename.endsWith(".jpg")) filename = filename+ ".jpg"; 308 guiControl.saveJPGFile(viewport, filename,w,h); 309 //guiControl.saveJPGFile(viewport, filename); 310 guiControl.saveTXTFile(filename); 311 } else { 312 debugln("Selected file was null."); 313 } 314 } 315 } 316 317 void frameCameraBtn_actionPerformed(ActionEvent e) { 318 VcView view = viewport.getView(); 319 if (view != null){ 320 guiControl.frameObjectsInView(view); 321 } 322 } 323 324 void makeExternalBtn_actionPerformed(ActionEvent e) { 325 //guiControl.makeExternalFrame(); 326 } 327 }

This page was automatically generated by Maven