7fd59977 |
1 | |
2 | //Title: Viewer3D Sample |
3 | //Version: |
4 | //Copyright: Copyright (c) 1999 |
5 | //Author: User Interface group |
6 | //Company: Matra Datavision |
7 | //Description: |
8 | |
9 | |
10 | import java.awt.*; |
11 | import java.awt.event.*; |
12 | import javax.swing.*; |
13 | import util.*; |
14 | import CASCADESamplesJni.*; |
15 | import SampleAISDisplayModeJni.*; |
16 | // import SampleAISDisplayModeJni.SampleAISDisplayModePackage; |
17 | import jcas.Standard_Real; |
18 | |
19 | |
20 | public class AttributesPanel extends JPanel |
21 | implements ActionListener |
22 | { |
23 | SamplePanel myDocument = null; |
24 | AIS_InteractiveContext myAISContext = null; |
25 | |
26 | //=======================================================================// |
27 | // Construction |
28 | //=======================================================================// |
29 | public AttributesPanel(SamplePanel aDoc, AIS_InteractiveContext aContext) |
30 | { |
31 | myDocument = aDoc; |
32 | myAISContext = aContext; |
33 | |
34 | try |
35 | { |
36 | jbInit(); |
37 | } |
38 | catch(Exception ex) |
39 | { |
40 | ex.printStackTrace(); |
41 | } |
42 | } |
43 | |
44 | void jbInit() throws Exception |
45 | { |
46 | setLayout(new GridLayout(0, 1)); |
47 | setBounds(10, 10, 10, 10); |
48 | |
49 | JButton button; |
50 | |
51 | button = new JButton("WireFrame"); |
52 | button.addActionListener(this); |
53 | button.setActionCommand("WireFrame"); |
54 | add(button); |
55 | |
56 | button = new JButton("Shading"); |
57 | button.addActionListener(this); |
58 | button.setActionCommand("Shading"); |
59 | add(button); |
60 | |
61 | button = new JButton("Color..."); |
62 | button.addActionListener(this); |
63 | button.setActionCommand("Color"); |
64 | add(button); |
65 | |
66 | button = new JButton("Brass"); |
67 | button.addActionListener(this); |
68 | button.setActionCommand("Brass"); |
69 | add(button); |
70 | |
71 | button = new JButton("Bronze"); |
72 | button.addActionListener(this); |
73 | button.setActionCommand("Bronze"); |
74 | add(button); |
75 | |
76 | button = new JButton("Copper"); |
77 | button.addActionListener(this); |
78 | button.setActionCommand("Copper"); |
79 | add(button); |
80 | |
81 | button = new JButton("Gold"); |
82 | button.addActionListener(this); |
83 | button.setActionCommand("Gold"); |
84 | add(button); |
85 | |
86 | button = new JButton("Pewter"); |
87 | button.addActionListener(this); |
88 | button.setActionCommand("Pewter"); |
89 | add(button); |
90 | |
91 | button = new JButton("Plaster"); |
92 | button.addActionListener(this); |
93 | button.setActionCommand("Plaster"); |
94 | add(button); |
95 | |
96 | button = new JButton("Plastic"); |
97 | button.addActionListener(this); |
98 | button.setActionCommand("Plastic"); |
99 | add(button); |
100 | |
101 | button = new JButton("Silver"); |
102 | button.addActionListener(this); |
103 | button.setActionCommand("Silver"); |
104 | add(button); |
105 | |
106 | button = new JButton("Steel"); |
107 | button.addActionListener(this); |
108 | button.setActionCommand("Steel"); |
109 | add(button); |
110 | |
111 | button = new JButton("Stone"); |
112 | button.addActionListener(this); |
113 | button.setActionCommand("Stone"); |
114 | add(button); |
115 | |
116 | button = new JButton("Shiny Plastic"); |
117 | button.addActionListener(this); |
118 | button.setActionCommand("ShinyPlastic"); |
119 | add(button); |
120 | |
121 | button = new JButton("Satin"); |
122 | button.addActionListener(this); |
123 | button.setActionCommand("Satin"); |
124 | add(button); |
125 | |
126 | button = new JButton("Transparency..."); |
127 | button.addActionListener(this); |
128 | button.setActionCommand("Transparency"); |
129 | add(button); |
130 | } |
131 | |
132 | |
133 | //=======================================================================// |
134 | // Commands |
135 | //=======================================================================// |
136 | private void onWireFrame() |
137 | { |
138 | TCollection_AsciiString message = new TCollection_AsciiString(); |
139 | SampleAISDisplayModePackage.SetObjectDisplayMode(myAISContext, (short)0, message); |
140 | |
141 | myDocument.traceMessage(message.ToCString().GetValue(), "Wireframe"); |
142 | } |
143 | |
144 | //=======================================================================// |
145 | private void onShading() |
146 | { |
147 | TCollection_AsciiString message = new TCollection_AsciiString(); |
148 | SampleAISDisplayModePackage.SetObjectDisplayMode(myAISContext, (short)1, message); |
149 | |
150 | myDocument.traceMessage(message.ToCString().GetValue(), "Shading"); |
151 | } |
152 | |
153 | //=======================================================================// |
154 | private void onColor() |
155 | { |
156 | Quantity_Color aColor = SampleAISDisplayModePackage.GetObjectColor(myAISContext); |
157 | int red = (int) (aColor.Red()*255); |
158 | int green = (int) (aColor.Green()*255); |
159 | int blue = (int) (aColor.Blue()*255); |
160 | Color theColor = new Color(red, green, blue); |
161 | |
162 | Color theNewColor = JColorChooser.showDialog(SamplesStarter.getFrame(), |
163 | "Choose the color", theColor); |
164 | |
165 | if (theNewColor != null) |
166 | { |
167 | Quantity_Color aNewColor = new Quantity_Color(theNewColor.getRed()/255., |
168 | theNewColor.getGreen()/255., |
169 | theNewColor.getBlue()/255., |
170 | Quantity_TypeOfColor.Quantity_TOC_RGB); |
171 | TCollection_AsciiString message = new TCollection_AsciiString(); |
172 | SampleAISDisplayModePackage.SetObjectColor(myAISContext, aNewColor, message); |
173 | |
174 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Color"); |
175 | } |
176 | } |
177 | |
178 | //=======================================================================// |
179 | private void onBrass() |
180 | { |
181 | TCollection_AsciiString message = new TCollection_AsciiString(); |
182 | SampleAISDisplayModePackage.SetObjectMaterial(myAISContext, |
183 | Graphic3d_NameOfMaterial.Graphic3d_NOM_BRASS, message); |
184 | |
185 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Material"); |
186 | } |
187 | |
188 | //=======================================================================// |
189 | private void onBronze() |
190 | { |
191 | TCollection_AsciiString message = new TCollection_AsciiString(); |
192 | SampleAISDisplayModePackage.SetObjectMaterial(myAISContext, |
193 | Graphic3d_NameOfMaterial.Graphic3d_NOM_BRONZE, message); |
194 | |
195 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Material"); |
196 | } |
197 | |
198 | //=======================================================================// |
199 | private void onCopper() |
200 | { |
201 | TCollection_AsciiString message = new TCollection_AsciiString(); |
202 | SampleAISDisplayModePackage.SetObjectMaterial(myAISContext, |
203 | Graphic3d_NameOfMaterial.Graphic3d_NOM_COPPER, message); |
204 | |
205 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Material"); |
206 | } |
207 | |
208 | //=======================================================================// |
209 | private void onGold() |
210 | { |
211 | TCollection_AsciiString message = new TCollection_AsciiString(); |
212 | SampleAISDisplayModePackage.SetObjectMaterial(myAISContext, |
213 | Graphic3d_NameOfMaterial.Graphic3d_NOM_GOLD, message); |
214 | |
215 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Material"); |
216 | } |
217 | |
218 | //=======================================================================// |
219 | private void onPewter() |
220 | { |
221 | TCollection_AsciiString message = new TCollection_AsciiString(); |
222 | SampleAISDisplayModePackage.SetObjectMaterial(myAISContext, |
223 | Graphic3d_NameOfMaterial.Graphic3d_NOM_PEWTER, message); |
224 | |
225 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Material"); |
226 | } |
227 | |
228 | //=======================================================================// |
229 | private void onPlaster() |
230 | { |
231 | TCollection_AsciiString message = new TCollection_AsciiString(); |
232 | SampleAISDisplayModePackage.SetObjectMaterial(myAISContext, |
233 | Graphic3d_NameOfMaterial.Graphic3d_NOM_PLASTER, message); |
234 | |
235 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Material"); |
236 | } |
237 | |
238 | //=======================================================================// |
239 | private void onPlastic() |
240 | { |
241 | TCollection_AsciiString message = new TCollection_AsciiString(); |
242 | SampleAISDisplayModePackage.SetObjectMaterial(myAISContext, |
243 | Graphic3d_NameOfMaterial.Graphic3d_NOM_PLASTIC, message); |
244 | |
245 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Material"); |
246 | } |
247 | |
248 | //=======================================================================// |
249 | private void onSilver() |
250 | { |
251 | TCollection_AsciiString message = new TCollection_AsciiString(); |
252 | SampleAISDisplayModePackage.SetObjectMaterial(myAISContext, |
253 | Graphic3d_NameOfMaterial.Graphic3d_NOM_SILVER, message); |
254 | |
255 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Material"); |
256 | } |
257 | |
258 | //=======================================================================// |
259 | private void onSteel() |
260 | { |
261 | TCollection_AsciiString message = new TCollection_AsciiString(); |
262 | SampleAISDisplayModePackage.SetObjectMaterial(myAISContext, |
263 | Graphic3d_NameOfMaterial.Graphic3d_NOM_STEEL, message); |
264 | |
265 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Material"); |
266 | } |
267 | |
268 | //=======================================================================// |
269 | private void onStone() |
270 | { |
271 | TCollection_AsciiString message = new TCollection_AsciiString(); |
272 | SampleAISDisplayModePackage.SetObjectMaterial(myAISContext, |
273 | Graphic3d_NameOfMaterial.Graphic3d_NOM_STONE, message); |
274 | |
275 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Material"); |
276 | } |
277 | |
278 | //=======================================================================// |
279 | private void onShinyPlastic() |
280 | { |
281 | TCollection_AsciiString message = new TCollection_AsciiString(); |
282 | SampleAISDisplayModePackage.SetObjectMaterial(myAISContext, |
283 | Graphic3d_NameOfMaterial.Graphic3d_NOM_SHINY_PLASTIC, message); |
284 | |
285 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Material"); |
286 | } |
287 | |
288 | //=======================================================================// |
289 | private void onSatin() |
290 | { |
291 | TCollection_AsciiString message = new TCollection_AsciiString(); |
292 | SampleAISDisplayModePackage.SetObjectMaterial(myAISContext, |
293 | Graphic3d_NameOfMaterial.Graphic3d_NOM_SATIN, message); |
294 | |
295 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Material"); |
296 | } |
297 | |
298 | //=======================================================================// |
299 | private void onTransparency() |
300 | { |
301 | double aValue = SampleAISDisplayModePackage.GetObjectTransparency(myAISContext); |
302 | |
303 | TransparencyDlg aDlg = new TransparencyDlg(SamplesStarter.getFrame(), aValue); |
304 | Position.centerWindow(aDlg); |
305 | aDlg.show(); |
306 | |
307 | if (aDlg.isOK()) |
308 | { |
309 | TCollection_AsciiString message = new TCollection_AsciiString(); |
310 | SampleAISDisplayModePackage.SetObjectTransparency(myAISContext, aDlg.getValue(), message); |
311 | |
312 | myDocument.traceMessage(message.ToCString().GetValue(), "Setting Transparency"); |
313 | } |
314 | } |
315 | |
316 | |
317 | //=======================================================================// |
318 | // Action listener interface |
319 | //=======================================================================// |
320 | public void actionPerformed(ActionEvent event) |
321 | { |
322 | String nameAction = event.getActionCommand(); |
323 | |
324 | if (myAISContext.NbCurrents() > 0) |
325 | { |
326 | if (nameAction.equals("WireFrame")) onWireFrame(); |
327 | else if (nameAction.equals("Shading")) onShading(); |
328 | else if (nameAction.equals("Color")) onColor(); |
329 | else if (nameAction.equals("Brass")) onBrass(); |
330 | else if (nameAction.equals("Bronze")) onBronze(); |
331 | else if (nameAction.equals("Copper")) onCopper(); |
332 | else if (nameAction.equals("Gold")) onGold(); |
333 | else if (nameAction.equals("Pewter")) onPewter(); |
334 | else if (nameAction.equals("Plaster")) onPlaster(); |
335 | else if (nameAction.equals("Plastic")) onPlastic(); |
336 | else if (nameAction.equals("Silver")) onSilver(); |
337 | else if (nameAction.equals("Steel")) onSteel(); |
338 | else if (nameAction.equals("Stone")) onStone(); |
339 | else if (nameAction.equals("ShinyPlastic")) onShinyPlastic(); |
340 | else if (nameAction.equals("Satin")) onSatin(); |
341 | else if (nameAction.equals("Transparency")) onTransparency(); |
342 | } |
343 | } |
344 | |
345 | } |