001    /*
002     * @(#)MohrStateStrs.java
003     */
004    
005    import java.awt.GridLayout;
006    import java.awt.Dimension;
007    import java.text.*;
008    import java.awt.Font;
009    import java.awt.event.*;
010    import javax.swing.JPanel;
011    import javax.swing.ImageIcon;
012    import javax.swing.JLabel;
013    import javax.swing.JTextField;
014    
015    /**
016     * MohrStateStrs.java - Define o painel com os objetos 
017     * texto com os valores das componentes do estado de tensão. 
018     *
019     * <p>
020     * Descrição:
021     * <p>
022     * ===============================================================
023     * <p>
024     * Este arquivo contém a implementação do objetos JTextField para
025     * definição e visualização dos valores do componentes de tensão 
026     * do estado corrente.
027     *
028     * <p>
029     * ===============================================================
030     *
031     * @version    1.0 05/09/2004
032     * @author     Luiz Fernando Martha
033     * @author     Alonso Juvinao Carbono
034     * @author     Anderson Resende Pereira
035     * @author     Fernando Busato Ramires
036     * @author     Paôla Reginal Dalcanal
037     * @author     Ricardo Rodrigues de Araujo  
038     *
039     */
040    class MohrStateStrs extends JPanel
041    {
042     /** Driver do programa Mohr-Circle */
043     protected MohrDriver driver;
044    
045     protected ImageIcon i_sigx;
046     protected ImageIcon i_sigy;
047     protected ImageIcon i_tauxy;
048    
049     protected JTextField f_sigx;
050     protected JTextField f_sigy;
051     protected JTextField f_tauxy;
052    
053     protected DecimalFormat frm_str;
054     protected DecimalFormat frm_ang;
055    
056    
057     MohrStateStrs( MohrDriver driver )
058     {
059      this.driver = driver;
060    
061      Dimension d_label = new Dimension( 30, 20 );
062      frm_str = new DecimalFormat( "####0.00" );
063      frm_ang = new DecimalFormat( "###0.0" );
064      Font fnt = new Font( "Times New Roman", Font.BOLD | Font.ITALIC, 14 );
065    
066      f_sigx = new JTextField( 5 );
067      f_sigx.setHorizontalAlignment( JTextField.RIGHT );
068      f_sigx.setToolTipText( "Tensão normal na direção horizontal" );
069      JPanel p_sigx = new JPanel();
070      i_sigx = new ImageIcon( getClass().getResource("images/label_sigx.gif") );
071      JLabel l_sigx = new JLabel( i_sigx );
072      l_sigx.setFont( fnt );
073      l_sigx.setPreferredSize( d_label );
074      l_sigx.setHorizontalAlignment( JLabel.RIGHT );
075      l_sigx.setLabelFor( f_sigx );
076      p_sigx.add( l_sigx );
077      p_sigx.add( f_sigx );
078      f_sigx.addActionListener(new ActionListener() {
079        public void actionPerformed(ActionEvent ev) {
080         double sigx;
081         try {
082          sigx = frm_str.parse( f_sigx.getText() ).doubleValue();
083         }
084         catch( ParseException e ) {
085          updateSigmaX( );
086          return;
087         }
088         setSolverSigmaX( sigx );
089        }
090      });
091     
092      f_sigy = new JTextField( 5 );
093      f_sigy.setHorizontalAlignment( JTextField.RIGHT );
094      f_sigy.setToolTipText( "Tensão normal na direção vertical" );
095      JPanel p_sigy = new JPanel();
096      i_sigy = new ImageIcon( getClass().getResource("images/label_sigy.gif") );
097      JLabel l_sigy = new JLabel( i_sigy );
098      l_sigy.setFont( fnt );
099      l_sigy.setPreferredSize( d_label );
100      l_sigy.setHorizontalAlignment( JLabel.RIGHT );
101      l_sigy.setLabelFor( f_sigy );
102      p_sigy.add( l_sigy );
103      p_sigy.add( f_sigy );
104      f_sigy.addActionListener(new ActionListener() {
105        public void actionPerformed(ActionEvent ev) {
106         double sigy;
107         try {
108          sigy = frm_str.parse( f_sigy.getText() ).doubleValue();
109         }
110         catch( ParseException e ) {
111          updateSigmaY( );
112          return;
113         }
114         setSolverSigmaY( sigy );
115        }
116      });
117    
118      f_tauxy = new JTextField( 5 );
119      f_tauxy.setHorizontalAlignment( JTextField.RIGHT );
120      f_tauxy.setToolTipText( "Tensão de cisalhamento para o elemento horizontal" );
121      JPanel p_tauxy = new JPanel();
122      i_tauxy = new ImageIcon( getClass().getResource("images/label_tauxy.gif") );
123      JLabel l_tauxy = new JLabel( i_tauxy );
124      l_tauxy.setFont( fnt );
125      l_tauxy.setHorizontalAlignment( JLabel.RIGHT );
126      l_tauxy.setPreferredSize( d_label );
127      l_tauxy.setLabelFor( f_tauxy );
128      p_tauxy.add( l_tauxy );
129      p_tauxy.add( f_tauxy );
130      f_tauxy.addActionListener(new ActionListener() {
131        public void actionPerformed(ActionEvent ev) {
132         double tauxy;
133         try {
134          tauxy = frm_str.parse( f_tauxy.getText() ).doubleValue();
135         }
136         catch( ParseException e ) {
137          updateTauXY( );
138          return;
139         }
140         setSolverTauXY( tauxy );
141        }
142      });
143    
144      setLayout( new GridLayout( 0, 2 ) );
145      add( p_sigx );
146      add( p_sigy );
147      add( p_tauxy );
148    
149      update( );
150     }
151    
152     public void setPortuguese( )
153     {
154      f_sigx.setToolTipText( "Tensão normal na direção horizontal" );
155      f_sigy.setToolTipText( "Tensão normal na direção vertical" );
156      f_tauxy.setToolTipText( "Tensão de cisalhamento para o elemento horizontal" );
157     }
158    
159     public void setEnglish( )
160     {
161      f_sigx.setToolTipText( "Normal stress in the horizontal direction" );
162      f_sigy.setToolTipText( "Normal stress in the vertical direction" );
163      f_tauxy.setToolTipText( "Shear stress for the horizontal element" );
164     }
165    
166     protected void setSolverSigmaX( double sigx )
167     {
168      driver.getSolver().setSigmaX( sigx );
169      driver.update( );
170     }
171    
172     protected void setSolverSigmaY( double sigy )
173     {
174      driver.getSolver().setSigmaY( sigy );
175      driver.update( );
176     }
177    
178     protected void setSolverTauXY( double tauxy )
179     {
180      driver.getSolver().setTauXY( tauxy );
181      driver.update( );
182     }
183    
184     protected void updateSigmaX( )
185     {
186      double sigx = driver.getSolver().getSigmaX( );
187      f_sigx.setText( frm_str.format( sigx ) );
188     }
189    
190     protected void updateSigmaY( )
191     {
192      double sigy = driver.getSolver().getSigmaY( );
193      f_sigy.setText( frm_str.format( sigy ) );
194     }
195    
196     protected void updateTauXY( )
197     {
198      double tauxy = driver.getSolver().getTauXY( );
199      f_tauxy.setText( frm_str.format( tauxy ) );
200     }
201    
202     void update( )
203     {
204      updateSigmaX( );
205      updateSigmaY( );
206      updateTauXY( );
207     }
208    }
209