001    /*
002     * @(#)MohrControls.java
003     */
004    
005    import java.awt.*;
006    import java.awt.event.*;
007    import javax.swing.*;
008    
009    /**
010     * MohrControls.java - Controles do programa do círculo de Mohr.
011     *
012     * <p>
013     * Descrição:
014     * <p>
015     * ===============================================================
016     * <p>
017     * Este arquivo implementa as classes dos objetos de interface 
018     * para controle do programa do círculo de Mohr.
019     *
020     * <p>
021     * ===============================================================
022     *
023     * @version    1.0 05/09/2004
024     * @author     Luiz Fernando Martha
025     * @author     Alonso Juvinao Carbono
026     * @author     Anderson Resende Pereira
027     * @author     Fernando Busato Ramires
028     * @author     Paôla Reginal Dalcanal
029     * @author     Ricardo Rodrigues de Araujo  
030     *
031     */
032    class MohrControls extends JToolBar
033    {
034     protected MohrFrame owner;
035     protected MohrPanel target;
036     protected MohrAboutBox infodlg;
037     protected MohrTheory theorydlg;
038    
039     protected ImageIcon i_ptflag;
040     protected ImageIcon i_ptflagpress;
041     protected ImageIcon i_ptflagroll;
042    
043     protected ImageIcon i_ukflag;
044     protected ImageIcon i_ukflagpress;
045     protected ImageIcon i_ukflagroll;
046    
047     protected ImageIcon i_showorigin;
048     protected ImageIcon i_showoriginpress;
049     protected ImageIcon i_showoriginroll;
050    
051     protected ImageIcon i_fitoncircle;
052     protected ImageIcon i_fitoncirclepress;
053     protected ImageIcon i_fitoncircleroll;
054    
055     protected ImageIcon i_state;
056     protected ImageIcon i_statepress;
057     protected ImageIcon i_stateroll;
058    
059     protected ImageIcon i_theta;
060     protected ImageIcon i_thetapress;
061     protected ImageIcon i_thetaroll;
062    
063     protected ImageIcon i_principal;
064     protected ImageIcon i_principalpress;
065     protected ImageIcon i_principalroll;
066    
067     protected ImageIcon i_info;
068     protected ImageIcon i_infopress;
069     protected ImageIcon i_inforoll;
070    
071     protected ImageIcon i_theory;
072     protected ImageIcon i_theorypress;
073     protected ImageIcon i_theoryroll;
074    
075     protected static JCheckBox cb_setportuguese;
076     protected static JCheckBox cb_setenglish;
077    
078     protected static JCheckBox cb_showorigin;
079     protected static JCheckBox cb_fitoncircle;
080    
081     protected static JCheckBox cb_statestrs;
082     protected static JCheckBox cb_principalstrs;
083     protected static JCheckBox cb_thetastrs;
084    
085     protected static JCheckBox cb_infodlg;
086     protected static JCheckBox cb_theorydlg;
087    
088    
089    /*=========================  Constructor  ==========================*/
090    
091     MohrControls( MohrFrame owner, MohrPanel target )
092     {
093      this.owner = owner;
094      this.target = target;
095      setFloatable( false );
096    
097      infodlg = new MohrAboutBox( this );
098      theorydlg = new MohrTheory( this );
099    
100      Insets insets0 = new Insets(0,0,0,0);
101      
102      i_ptflag 
103           = new ImageIcon(getClass().getResource("images/ptflag.gif"));
104      i_ptflagpress 
105           = new ImageIcon(getClass().getResource("images/ptflagpress.gif"));
106      i_ptflagroll 
107           = new ImageIcon(getClass().getResource("images/ptflagroll.gif"));
108      
109      i_ukflag 
110           = new ImageIcon(getClass().getResource("images/ukflag.gif"));
111      i_ukflagpress 
112           = new ImageIcon(getClass().getResource("images/ukflagpress.gif"));
113      i_ukflagroll 
114           = new ImageIcon(getClass().getResource("images/ukflagroll.gif"));
115      
116      i_showorigin 
117           = new ImageIcon(getClass().getResource("images/showorigin.gif"));
118      i_showoriginpress 
119           = new ImageIcon(getClass().getResource("images/showoriginpress.gif"));
120      i_showoriginroll 
121           = new ImageIcon(getClass().getResource("images/showoriginroll.gif"));
122    
123      i_fitoncircle 
124           = new ImageIcon(getClass().getResource("images/fitoncircle.gif"));
125      i_fitoncirclepress 
126           = new ImageIcon(getClass().getResource("images/fitoncirclepress.gif"));
127      i_fitoncircleroll 
128           = new ImageIcon(getClass().getResource("images/fitoncircleroll.gif"));
129    
130      i_state 
131           = new ImageIcon(getClass().getResource("images/statestrs.gif"));
132      i_statepress 
133           = new ImageIcon(getClass().getResource("images/statestrspress.gif"));
134      i_stateroll 
135           = new ImageIcon(getClass().getResource("images/statestrsroll.gif"));
136    
137      i_theta 
138           = new ImageIcon(getClass().getResource("images/thetastrs.gif"));
139      i_thetapress 
140           = new ImageIcon(getClass().getResource("images/thetastrspress.gif"));
141      i_thetaroll 
142           = new ImageIcon(getClass().getResource("images/thetastrsroll.gif"));
143    
144      i_principal 
145           = new ImageIcon(getClass().getResource("images/principalstrs.gif"));
146      i_principalpress 
147           = new ImageIcon(getClass().getResource("images/principalstrspress.gif"));
148      i_principalroll 
149           = new ImageIcon(getClass().getResource("images/principalstrsroll.gif"));
150    
151      i_info 
152           = new ImageIcon(getClass().getResource("images/info.gif"));
153      i_infopress 
154           = new ImageIcon(getClass().getResource("images/infopress.gif"));
155      i_inforoll 
156           = new ImageIcon(getClass().getResource("images/inforoll.gif"));
157    
158      i_theory 
159           = new ImageIcon(getClass().getResource("images/theory.gif"));
160      i_theorypress 
161           = new ImageIcon(getClass().getResource("images/theorypress.gif"));
162      i_theoryroll 
163           = new ImageIcon(getClass().getResource("images/theoryroll.gif"));
164      
165      cb_setportuguese = new JCheckBox( i_ptflagpress );
166      cb_setportuguese.setMargin( insets0 );
167      cb_setportuguese.setSelected( true );
168      cb_setportuguese.setToolTipText( "Língua Portuguesa" );
169      cb_setportuguese.addActionListener( new ActionListener()
170      {
171       public void actionPerformed( ActionEvent e )
172       {
173        setPortuguese( false ); 
174       }
175      } );
176    
177      cb_setenglish = new JCheckBox( i_ukflag );
178      cb_setenglish.setMargin( insets0 );
179      cb_setenglish.setSelected( false );
180      cb_setenglish.setRolloverIcon( i_ukflagroll );
181      cb_setenglish.setToolTipText( "English Language" );
182      cb_setenglish.addActionListener( new ActionListener()
183      {
184       public void actionPerformed( ActionEvent e )
185       {
186        setEnglish( false ); 
187       }
188      } );
189      
190      cb_showorigin = new JCheckBox( i_showoriginpress );
191      cb_showorigin.setMargin( insets0 );
192      cb_showorigin.setSelected( true );
193      cb_showorigin.setToolTipText( "Mostra origem dos eixos" );
194      cb_showorigin.addActionListener( new ActionListener()
195      {
196       public void actionPerformed( ActionEvent e )
197       {
198        setShowOrigin(); 
199       }
200      } );
201    
202      cb_fitoncircle = new JCheckBox( i_fitoncircle );
203      cb_fitoncircle.setMargin( insets0 );
204      cb_fitoncircle.setSelected( false );
205      cb_fitoncircle.setRolloverIcon( i_fitoncircleroll );
206      cb_fitoncircle.setToolTipText( "Enquadra no círculo" );
207      cb_fitoncircle.addActionListener( new ActionListener()
208      {
209       public void actionPerformed( ActionEvent e )
210       {
211        setFitOnCircle(); 
212       }
213      } );
214    
215      cb_statestrs = new JCheckBox( i_statepress );
216      cb_statestrs.setMargin( insets0 );
217      cb_statestrs.setSelected( true );
218      cb_statestrs.setToolTipText( "Inabilita o estado de tensões x-y" );
219      cb_statestrs.addActionListener( new ActionListener()
220      {
221       public void actionPerformed( ActionEvent e )
222       {
223        setStateStrs(); 
224       }
225      } );
226    
227      cb_thetastrs = new JCheckBox( i_thetapress );
228      cb_thetastrs.setMargin( insets0 );
229      cb_thetastrs.setSelected( true );
230      cb_thetastrs.setToolTipText( "Inabilita as tensões no plano theta" );
231      cb_thetastrs.addActionListener( new ActionListener()
232      {
233       public void actionPerformed( ActionEvent e )
234       {
235        setThetaStrs(); 
236       }
237      } );
238    
239      cb_principalstrs = new JCheckBox( i_principalpress );
240      cb_principalstrs.setMargin( insets0 );
241      cb_principalstrs.setSelected( true );
242      cb_principalstrs.setToolTipText( "Inabilita as tensões principais" );
243      cb_principalstrs.addActionListener( new ActionListener()
244      {
245       public void actionPerformed( ActionEvent e )
246       {
247        setPrincipalStrs(); 
248       }
249      } );
250          
251      cb_infodlg = new JCheckBox( i_info );
252      cb_infodlg.setMargin( insets0 );
253      cb_infodlg.setSelected( false );
254      cb_infodlg.setRolloverIcon( i_inforoll );
255      cb_infodlg.setToolTipText( "Sobre o programa de círculo de Mohr" );
256      cb_infodlg.addActionListener( new ActionListener()
257      {
258       public void actionPerformed( ActionEvent e )
259       {
260        showInfoDlg();
261       }
262      } );
263    
264      cb_theorydlg = new JCheckBox( i_theory );
265      cb_theorydlg.setMargin( insets0 );
266      cb_theorydlg.setSelected( false );
267      cb_theorydlg.setRolloverIcon( i_theoryroll );
268      cb_theorydlg.setToolTipText( "Teoria do círculo de Mohr" );
269      cb_theorydlg.addActionListener( new ActionListener()
270      {
271       public void actionPerformed( ActionEvent e )
272       {
273        showTheoryDlg();
274       }
275      } );
276    
277      add( cb_setportuguese );
278      add( cb_setenglish );
279      addSeparator( );
280      add( cb_showorigin );
281      add( cb_fitoncircle );
282      addSeparator( );
283      add( cb_statestrs );
284      add( cb_thetastrs );
285      add( cb_principalstrs );
286      addSeparator( );
287      add( cb_infodlg );
288      add( cb_theorydlg );
289     }
290    
291    /*=============================  setPortuguese  ============================*/
292    
293     public void setPortuguese( boolean first_time )
294     {
295      if( cb_setportuguese.getIcon() != i_ptflagpress )
296      {
297       cb_setportuguese.setIcon( i_ptflagpress );
298       cb_setportuguese.setSelected( true );
299       cb_setenglish.setIcon( i_ukflag );
300       cb_setenglish.setSelected( false );
301       cb_setenglish.setRolloverIcon( i_ukflagroll );
302    
303       if( (! first_time) && (owner != null) )
304        owner.setPortuguese();
305       target.setPortuguese();
306       infodlg.setPortuguese();
307       theorydlg.setPortuguese();
308    
309       cb_setportuguese.setToolTipText( "Língua Portuguesa" );
310       cb_setenglish.setToolTipText( "English Language" );
311       cb_showorigin.setToolTipText( "Mostra origem dos eixos" );
312       cb_fitoncircle.setToolTipText( "Enquadra no círculo" );
313       if( cb_statestrs.getIcon() == i_statepress )
314        cb_statestrs.setToolTipText( "Inabilita o estado de tensões x-y" );
315       else
316        cb_statestrs.setToolTipText( "Habilita o estado de tensões x-y" );
317       if( cb_thetastrs.getIcon() == i_thetapress )
318        cb_thetastrs.setToolTipText( "Inabilita as tensões no plano inclinado" );
319       else
320        cb_thetastrs.setToolTipText( "Habilita as tensões no plano inclinado" );
321       if( cb_principalstrs.getIcon() == i_principalpress )
322        cb_principalstrs.setToolTipText( "Inabilita as tensões principais" );
323       else
324        cb_principalstrs.setToolTipText( "Habilita as tensões principais" );
325       cb_infodlg.setToolTipText( "Sobre o programa de círculo de Mohr" );
326       cb_theorydlg.setToolTipText( "Teoria do círculo de Mohr" );
327      }
328      else
329      {
330       cb_setportuguese.setSelected( true );
331      }
332     }
333    
334    /*=============================  setEnglish  ============================*/
335    
336     public void setEnglish( boolean first_time )
337     {
338      if( cb_setenglish.getIcon() != i_ukflagpress )
339      {
340       cb_setenglish.setIcon( i_ukflagpress );
341       cb_setenglish.setSelected( true );
342       cb_setportuguese.setIcon( i_ptflag );
343       cb_setportuguese.setSelected( false );
344       cb_setportuguese.setRolloverIcon( i_ptflagroll );
345    
346       if( (! first_time) && (owner != null) )
347        owner.setEnglish();
348       target.setEnglish();
349       infodlg.setEnglish();
350       theorydlg.setEnglish();
351    
352       cb_setportuguese.setToolTipText( "Portuguese Language" );
353       cb_setenglish.setToolTipText( "English Language" );
354       cb_showorigin.setToolTipText( "Show origin of axes" );
355       cb_fitoncircle.setToolTipText( "Fit on circle" );
356       if( cb_statestrs.getIcon() == i_statepress )
357        cb_statestrs.setToolTipText( "Disable x-y stress state" );
358       else
359        cb_statestrs.setToolTipText( "Enable x-y stress state" );
360       if( cb_thetastrs.getIcon() == i_thetapress )
361        cb_thetastrs.setToolTipText( "Disable stress on inclined plane" );
362       else
363        cb_thetastrs.setToolTipText( "Enable stress on inclined plane" );
364       if( cb_principalstrs.getIcon() == i_principalpress )
365        cb_principalstrs.setToolTipText( "Disable principal stresses" );
366       else
367        cb_principalstrs.setToolTipText( "Enable principal stresses" );
368       cb_infodlg.setToolTipText( "About the Mohr's circle program" );
369       cb_theorydlg.setToolTipText( "Theory of Mohr's circle" );
370      }
371      else
372      {
373       cb_setenglish.setSelected( true );
374      }
375     }
376    
377    /*=============================  setShowOrigin  ============================*/
378    
379     protected void setShowOrigin( )
380     {
381      if( cb_showorigin.getIcon() != i_showoriginpress )
382      {
383       cb_showorigin.setIcon( i_showoriginpress );
384       cb_showorigin.setSelected( true );
385       cb_fitoncircle.setIcon( i_fitoncircle );
386       cb_fitoncircle.setSelected( false );
387       cb_fitoncircle.setRolloverIcon( i_fitoncircleroll );
388       target.circle_canvas.setFitType( MohrCircleCanvas.SHOW_ORIGIN );
389       target.circle_canvas.update();
390      }
391      else
392      {
393       cb_showorigin.setSelected( true );
394      }
395     }
396    
397    /*=============================  setFitOnCircle  ============================*/
398    
399     protected void setFitOnCircle( )
400     {
401      if( cb_fitoncircle.getIcon() != i_fitoncirclepress )
402      {
403       cb_fitoncircle.setIcon( i_fitoncirclepress );
404       cb_fitoncircle.setSelected( true );
405       cb_showorigin.setIcon( i_showorigin );
406       cb_showorigin.setSelected( false );
407       cb_showorigin.setRolloverIcon( i_showoriginroll );
408       target.circle_canvas.setFitType( MohrCircleCanvas.FIT_ON_CIRCLE );
409       target.circle_canvas.update();
410      }
411      else
412      {
413       cb_fitoncircle.setSelected( true );
414      }
415     }
416    
417    /*=============================  setStateStrs  ============================*/
418    
419     protected void setStateStrs( )
420     {
421      if( cb_statestrs.getIcon() == i_statepress )
422      {
423       cb_statestrs.setIcon( i_state );
424       cb_statestrs.setSelected( false );
425       cb_statestrs.setRolloverIcon( i_stateroll );
426       if( cb_showorigin.getIcon() == i_ptflagpress )
427        cb_statestrs.setToolTipText( "Habilita o estado de tensões x-y" );
428       else
429        cb_statestrs.setToolTipText( "Enable x-y stress state" );
430       target.circle_canvas.setVisStateStrs( false );
431      }
432      else
433      {
434       cb_statestrs.setIcon( i_statepress );
435       cb_statestrs.setSelected( true );
436       if( cb_showorigin.getIcon() == i_ptflagpress )
437        cb_statestrs.setToolTipText( "Inabilita o estado de tensões x-y" );
438       else
439        cb_statestrs.setToolTipText( "Disable x-y stress state" );
440       target.circle_canvas.setVisStateStrs( true );
441      }
442      target.circle_canvas.update();
443     }
444    
445    /*=============================  setThetaStrs  ===========================*/
446    
447     protected void setThetaStrs( )
448     {
449      if( cb_thetastrs.getIcon() == i_thetapress )
450      {
451       cb_thetastrs.setIcon( i_theta );
452       cb_thetastrs.setSelected( false );
453       cb_thetastrs.setRolloverIcon( i_thetaroll );
454       if( cb_showorigin.getIcon() == i_ptflagpress )
455        cb_thetastrs.setToolTipText( "Habilita as tensões no plano inclinado" );
456       else
457        cb_thetastrs.setToolTipText( "Enable stress on inclined plane" );
458       target.circle_canvas.setVisThetaStrs( false );
459      }
460      else
461      {
462       cb_thetastrs.setIcon( i_thetapress );
463       cb_thetastrs.setSelected( true );
464       if( cb_showorigin.getIcon() == i_ptflagpress )
465        cb_thetastrs.setToolTipText( "Inabilita as tensões no plano inclinado" );
466       else
467        cb_thetastrs.setToolTipText( "Disable stress on inclined plane" );
468       target.circle_canvas.setVisThetaStrs( true );
469      }
470      target.circle_canvas.update();
471     }
472     
473    /*=============================  setPrincipalStrs  ===========================*/
474    
475     protected void setPrincipalStrs( )
476     {
477      if( cb_principalstrs.getIcon() == i_principalpress )
478      {
479       cb_principalstrs.setIcon( i_principal );
480       cb_principalstrs.setSelected( false );
481       cb_principalstrs.setRolloverIcon( i_principalroll );
482       if( cb_showorigin.getIcon() == i_ptflagpress )
483        cb_principalstrs.setToolTipText( "Habilita as tensões principais" );
484       else
485        cb_principalstrs.setToolTipText( "Enable principal stresses" );
486       target.circle_canvas.setVisPrincipalStrs( false );
487      }
488      else
489      {
490       cb_principalstrs.setIcon( i_principalpress );
491       cb_principalstrs.setSelected( true );
492       if( cb_showorigin.getIcon() == i_ptflagpress )
493        cb_principalstrs.setToolTipText( "Inabilita as tensões principais" );
494       else
495        cb_principalstrs.setToolTipText( "Disable principal stresses" );
496       target.circle_canvas.setVisPrincipalStrs( true );
497      }
498      target.circle_canvas.update();
499     }
500    
501    /*=============================  showInfoDlg  ===========================*/
502    
503     protected void showInfoDlg( )
504     {
505      cb_infodlg.setIcon( i_infopress );
506      cb_infodlg.setSelected( true );
507      Dimension d1 = infodlg.getSize();
508      Dimension d2;
509      if( owner != null )
510      {
511       d2 = owner.getSize();
512       int x = Math.max( (d2.width-d1.width)/2, 0 );
513       int y = Math.max( (d2.height-d1.height)/2, 0 );
514       infodlg.setBounds( x+owner.getX(), y+owner.getY(), d1.width, d1.height );
515      }
516      else
517      {
518       infodlg.setBounds( 0, 0, d1.width, d1.height );
519      }
520      infodlg.show( );
521     }
522    
523    /*=============================  resetInfoDlg  ===========================*/
524    
525     void resetInfoDlg( )
526     {
527      cb_infodlg.setIcon( i_info );
528      cb_infodlg.setSelected( false );
529      cb_infodlg.setRolloverIcon( i_inforoll );
530     }
531    
532    /*============================  showTheoryDlg  ===========================*/
533    
534     protected void showTheoryDlg( )
535     {
536      cb_theorydlg.setIcon( i_theorypress );
537      cb_theorydlg.setSelected( true );
538      Dimension d1 = theorydlg.getSize();
539      Dimension d2;
540      if( owner != null )
541      {
542       d2 = owner.getSize();
543       int x = Math.max( (d2.width-d1.width)/2, 0 );
544       int y = Math.max( (d2.height-d1.height)/2, 0 );
545       theorydlg.setBounds( x+owner.getX(), y+owner.getY(), d1.width, d1.height );
546      }
547      else
548      {
549       theorydlg.setBounds( 0, 0, d1.width, d1.height );
550      }
551      theorydlg.show( );
552     }
553    
554    /*===========================  resetTheoryDlg  ===========================*/
555    
556     void resetTheoryDlg( )
557     {
558      cb_theorydlg.setIcon( i_theory );
559      cb_theorydlg.setSelected( false );
560      cb_theorydlg.setRolloverIcon( i_theoryroll );
561     }
562       
563    }
564