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 javax.swing.*;
23 import java.awt.*;
24 import camera3d.event.*;
25 import camera3d.*;
26
27 /*
28 * Title: Câmera Virtual - LIVES
29 * Description: Câmera Virtual para Controle via LabVIEW
30 * Copyright: Copyright (c) 2001
31 * Company: Centro de Educação em Informática - SENAC - SP
32 */
33
34 /*
35 * This class was changed in June 2002 so that it doesn't have to know all possible icons of
36 * objects. Each object now knows its own icon
37 */
38
39 /***
40 * Graphical representation of entries in the list of objects available for selection.
41 * The entries can be added to a container, making it possible to select/unselect an
42 * object by clicking with the mouse over its entry.
43 *
44 * @author Fábio Roberto de Miranda
45 * @version 1.0
46 */
47 class SelectionListEntry extends JToggleButton implements VcObjectChangeListener {
48
49 private VcObject vcObject;
50
51 private ImageIcon defaultIcon = new ImageIcon(this.getClass().getResource("icons/default_item.gif"));
52
53 /***
54 * Default constructor.
55 */
56 public SelectionListEntry() {
57 super();
58 this.setPreferredSize(new Dimension(130, 20));
59 //this.setAlignmentX(Component.CENTER_ALIGNMENT);
60
61 try {
62 jbInit();
63 }
64 catch(Exception e) {
65 e.printStackTrace();
66 }
67 setTooltip();
68 }
69
70 void initialize(){
71 }
72
73 private void jbInit() throws Exception {
74 this.setMargin(new Insets(5, 7, 2, 7));
75 this.setPreferredSize(new Dimension(130,20));
76 this.setMinimumSize(new Dimension(130, 20));
77 this.setAlignmentX((float) 0.5);
78 this.setPreferredSize(new Dimension(130,20));
79 this.setMaximumSize(new Dimension(160, 20));
80
81 this.setHorizontalAlignment(SwingConstants.LEFT);
82 }
83
84 /***
85 * Sets the VcObject which is referred to by this entry.
86 * @param vc the new VcObject.
87 */
88 public void setVcObject(VcObject vc){
89 this.vcObject = vc;
90 this.setText(vc.getLabel());
91 this.vcObject.addChangeListener(this);
92 setTooltip();
93 }
94
95 /***
96 * Called when the VcObject referred to by this entry undergoes a change.
97 * If the change affected the label of the VcObject, the entry is modified
98 * accordingly.
99 * @param event specifies the change made to the VcObject.
100 */
101 public void vcObjectChanged(VcObjectEvent event){
102 if(vcObject == event.getSource()){
103 if(event.getType()==VcObjectEvent.LABEL_CHANGED){
104 setText(vcObject.getLabel());
105 setTooltip();
106 }
107 }
108 }
109
110 /***
111 * Returns the VcObject referred to by this entry.
112 */
113 public VcObject getVcObject(){
114 return this.vcObject;
115 }
116
117 /***
118 * Returns a flag indicating whether this entry is currently referring to a
119 * valid VcObject.
120 * @return true if VcObject referred to is null, false otherwise.
121 */
122 public boolean isEmpty(){
123 return (vcObject == null);
124 }
125
126 /***
127 * Sets to null the VcObject referred to by this entry.
128 */
129 public void clear(){
130 vcObject = null;
131 }
132
133 public void setTooltip(){
134 if (vcObject!=null){
135 Icon icon = vcObject.getIcon();
136 if (icon==null){
137 this.setIcon(defaultIcon);
138 } else {
139 this.setIcon(vcObject.getIcon());
140 }
141
142 this.setToolTipText(vcObject.getTooltipText());
143 }
144 }
145
146
147
148
149 }
This page was automatically generated by Maven