001    /*
002     * @(#)MohrFrame.java
003     */
004    
005    import java.awt.*;
006    import java.awt.event.*;
007    import javax.swing.*;
008    import javax.swing.event.*;
009    
010    /**
011     * MohrFrame.java - Define a janela principal do programa.
012     *
013     * <p>
014     * Descrição:
015     * <p>
016     * ===============================================================
017     * <p>
018     * Esta classe define a janela principal do programa para 
019     * demonstração do funcionamento do círculo de Mohr para 
020     * estado plano de tensões.
021     *
022     * <p>
023     * ===============================================================
024     *
025     * @version    1.0 04/09/2004
026     * @author     Luiz Fernando Martha
027     * @author     Alonso Juvinao Carbono
028     * @author     Anderson Resende Pereira
029     * @author     Fernando Busato Ramires
030     * @author     Paôla Reginal Dalcanal
031     * @author     Ricardo Rodrigues de Araujo  
032     *
033     */
034    public class MohrFrame extends JFrame
035    {
036     private MohrPanel target;
037     private JMenuBar menu_bar;
038     private JMenu file_menu;
039     private JMenuItem exitoption;
040     private MohrDriver driver;
041     private boolean is_portuguese;
042    
043     MohrFrame( int width, int height, boolean is_portuguese )
044     {
045      addWindowListener( new WindowAdapter()
046      {
047       public void windowClosing( WindowEvent e )
048       {
049        dispose();
050        System.exit(0);
051       }
052      } );
053      this.is_portuguese = is_portuguese;
054      setTitle( "e-Mohr: círculo de Mohr para estado plano de tensões" );
055      target = new MohrPanel( this, is_portuguese );
056      buildMenus();
057      getContentPane().add( target, BorderLayout.CENTER );
058      pack();
059      setSize( new Dimension( width, height) );
060      if( ! is_portuguese )
061       setEnglish();
062      show();
063     }
064    
065     MohrFrame( )
066     {
067      this( 800, 576, true );
068     }
069    
070     MohrFrame( int width, int height )
071     {
072      this( width, height, true );
073     }
074    
075     MohrFrame( boolean is_portuguese )
076     {
077      this( 800, 576, is_portuguese );
078     }
079    
080     /*
081     ** ---------------------------------------------------------------
082     ** Public methods: 
083     */
084    
085     /*===========================  setPortuguese  ========================*/
086    
087     public void setPortuguese( )
088     {
089      is_portuguese = true;
090      setTitle( "e-Mohr: círculo de Mohr para estado plano de tensões" );
091      file_menu.setText( "Arquivo" );
092      exitoption.setText( "Sair..." );
093     }
094    
095    /*===========================  setEnglish  ========================*/
096    
097     public void setEnglish( )
098     {
099      is_portuguese = false;
100      setTitle( "e-Mohr: Mohr's circle for plane stress state" );
101      file_menu.setText( "File" );
102      exitoption.setText( "Exit..." );
103     }
104    
105     /*
106     ** ---------------------------------------------------------------
107     ** Private and Protected methods: 
108     */
109    
110     /*===========================  buildMenus  ========================*/
111     /**
112      * Cria o menu bar.
113      */
114     private void buildMenus( )
115     {
116      menu_bar = new JMenuBar();
117      file_menu = new JMenu( "Arquivo" );
118      addExitItem();
119      menu_bar.add( file_menu );
120      setJMenuBar( menu_bar );
121     }
122    
123     /*==========================  addExitItem  ========================*/
124     /**
125      * Adiciona a opção para sair do programa.
126      */
127     private void addExitItem()
128     {
129      exitoption = new JMenuItem( "Sair..." );
130      exitoption.setMnemonic('r'); 
131      exitoption.addActionListener( new ActionListener()
132      {
133       public void actionPerformed( ActionEvent e )
134       {
135        if( exitDialog() == 0 )
136        {
137         dispose();
138         System.exit(0);
139        }
140       }
141      } );
142      file_menu.add( exitoption );
143     }
144    
145     /*==========================  exitDialog  =========================*/
146     /**
147      * Dialogo para pedir confirmação para sair do programa.
148      */
149     private int exitDialog()
150     {
151       int confirm;
152       if( is_portuguese )
153       {
154        confirm = JOptionPane.showOptionDialog( getContentPane(),
155                     "Realmente quer sair?", "Confirmação de saída",
156                     JOptionPane.YES_NO_OPTION, 
157                     JOptionPane.QUESTION_MESSAGE,
158                     null, null, null);
159       }
160       else
161       {
162        confirm = JOptionPane.showOptionDialog( getContentPane(),
163                     "Do you really want to exit?", "Exit Confirmation",
164                     JOptionPane.YES_NO_OPTION, 
165                     JOptionPane.QUESTION_MESSAGE,
166                     null, null, null);
167       }
168       return( confirm );
169     }
170    
171    }
172