001    /*
002     * @(#)MohrThetaStrs.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    import javax.swing.JSlider;
015    import javax.swing.event.*;
016    
017    /**
018     * MohrThetaStrs.java - Define o painel com os objetos 
019     * texto com os valores das componentes de tensão no 
020     * plano definido pelo ângulo theta. 
021     *
022     * <p>
023     * Descrição:
024     * <p>
025     * ===============================================================
026     * <p>
027     * Este arquivo contém a implementação do objetos JTextField para
028     * definição e visualização dos valores do componentes de tensão 
029     * no plano definido pelo ângulo theta.
030     *
031     * <p>
032     * ===============================================================
033     *
034     * @version    1.0 05/09/2004
035     * @author     Luiz Fernando Martha
036     * @author     Alonso Juvinao Carbono
037     * @author     Anderson Resende Pereira
038     * @author     Fernando Busato Ramires
039     * @author     Paôla Reginal Dalcanal
040     * @author     Ricardo Rodrigues de Araujo  
041     *
042     */
043    class MohrThetaStrs extends JPanel
044    {
045     /** Driver do programa Mohr-Circle */
046     protected MohrDriver driver;
047    
048     protected ImageIcon i_theta;
049     protected ImageIcon i_sigtheta;
050     protected ImageIcon i_tautheta;
051    
052     protected JTextField f_theta;
053     protected JTextField f_sigtheta;
054     protected JTextField f_tautheta;
055     protected JSlider    s_theta;
056    
057     protected DecimalFormat frm_str;
058     protected DecimalFormat frm_ang;
059    
060     protected SliderListener s_listener;
061    
062    
063     MohrThetaStrs( MohrDriver driver )
064     {
065             
066      this.driver = driver;
067    
068      Dimension d_label = new Dimension( 30, 20 );
069      Dimension d_slider = new Dimension( 30, 20 );
070      frm_str = new DecimalFormat( "####0.00" );
071      frm_ang = new DecimalFormat( "###0.0" );
072      Font fnt = new Font( "Times New Roman", Font.BOLD | Font.ITALIC, 14 );
073    
074      s_listener = new SliderListener();
075    
076      f_theta = new JTextField( 5 );
077      f_theta.setHorizontalAlignment( JTextField.RIGHT );
078      f_theta.setToolTipText( "Ângulo do plano inclinado" );
079      JPanel p_theta = new JPanel();
080      i_theta = new ImageIcon( getClass().getResource("images/label_theta.gif") );
081      JLabel l_theta = new JLabel( i_theta );
082      l_theta.setFont( fnt );
083      l_theta.setHorizontalAlignment( JLabel.RIGHT );
084      l_theta.setPreferredSize( d_label );
085      l_theta.setLabelFor( f_theta );
086      p_theta.add( l_theta );
087      p_theta.add( f_theta );
088      f_theta.addActionListener(new ActionListener() {
089        public void actionPerformed(ActionEvent ev) {
090         double theta;
091         try {
092          theta = frm_ang.parse( f_theta.getText() ).doubleValue();
093         }
094         catch( ParseException e ) {
095          updateTheta( );
096          return;
097         }
098         setSolverTheta( theta );
099        }
100      });
101    
102      f_sigtheta = new JTextField( 5 );
103      f_sigtheta.setEnabled( false );
104      f_sigtheta.setHorizontalAlignment( JTextField.RIGHT );
105      f_sigtheta.setToolTipText( "Tensão normal do plano inclinado" );
106      JPanel p_sigtheta = new JPanel();
107      i_sigtheta = 
108              new ImageIcon( getClass().getResource("images/label_sigtheta.gif") );
109      JLabel l_sigtheta = new JLabel( i_sigtheta );
110      l_sigtheta.setFont( fnt );
111      l_sigtheta.setPreferredSize( d_label );
112      l_sigtheta.setHorizontalAlignment( JLabel.RIGHT );
113      l_sigtheta.setLabelFor( f_sigtheta );
114      p_sigtheta.add( l_sigtheta );
115      p_sigtheta.add( f_sigtheta );
116    
117      f_tautheta = new JTextField( 5 );
118      f_tautheta.setEnabled( false );
119      f_tautheta.setHorizontalAlignment( JTextField.RIGHT );
120      f_tautheta.setToolTipText( "Tensão de cisalhamento do plano inclinado" );
121      JPanel p_tautheta = new JPanel();
122      i_tautheta = 
123              new ImageIcon( getClass().getResource("images/label_tautheta.gif") );
124      JLabel l_tautheta = new JLabel( i_tautheta );
125      l_tautheta.setFont( fnt );
126      l_tautheta.setPreferredSize( d_label );
127      l_tautheta.setHorizontalAlignment( JLabel.RIGHT );
128      l_tautheta.setLabelFor( f_tautheta );
129      p_tautheta.add( l_tautheta );
130      p_tautheta.add( f_tautheta );
131    
132      s_theta = new JSlider( 0, 1800, 
133                     (int)(Math.toDegrees( driver.getSolver().getTheta( ) )*10.0) );
134      s_theta.setToolTipText( "Ajuste do ângulo do plano inclinado" );
135      s_theta.setPreferredSize( d_slider );  
136      s_theta.addChangeListener( s_listener );
137      
138      setLayout( new GridLayout( 2, 0 ) );
139      add( p_theta );
140      add( s_theta );
141      add( p_sigtheta );
142      add( p_tautheta );
143    
144      update( );
145     }
146    
147     public void setPortuguese( )
148     {
149      f_theta.setToolTipText( "Ângulo do plano inclinado" );
150      f_sigtheta.setToolTipText( "Tensão normal do plano inclinado" );
151      f_tautheta.setToolTipText( "Tensão de cisalhamento do plano inclinado" );
152      s_theta.setToolTipText( "Ajuste do ângulo do plano inclinado" );
153     }
154    
155     public void setEnglish( )
156     {
157      f_theta.setToolTipText( "Angle of inclined plane" );
158      f_sigtheta.setToolTipText( "Normal stress of inclined plane" );
159      f_tautheta.setToolTipText( "Shear stress of inclined plane" );
160      s_theta.setToolTipText( "Adjust the angle of inclined plane" );
161     }
162    
163     protected void setSolverTheta( double theta )
164     {
165      theta = Math.toRadians( theta );
166      driver.getSolver().setTheta( theta );
167      driver.update( );
168     }
169    
170     protected void updateTheta( )
171     {
172      double theta = driver.getSolver().getTheta( );
173      f_theta.setText( frm_ang.format( Math.toDegrees( theta ) ) + "°" );
174     }
175    
176     protected void updateSigmaTheta( )
177     {
178      double sigtheta = driver.getSolver().SigmaTheta( );
179      f_sigtheta.setText( frm_str.format( sigtheta ) );
180     }
181     
182     protected void updateTauTheta( )
183     {
184      double tautheta = driver.getSolver().TauTheta( );
185      f_tautheta.setText( frm_str.format( tautheta ) );
186     }
187    
188     protected void updateSlider( )
189     {
190      int val = (int)(Math.toDegrees( driver.getSolver().getTheta( ) )*10.0);
191      s_theta.setValue( val );
192     }
193    
194     void update( )
195     {
196      updateTheta( );
197      updateSlider( );
198      updateSigmaTheta( );
199      updateTauTheta( );
200     }
201    
202     class SliderListener implements ChangeListener
203     { 
204       public void stateChanged(ChangeEvent e) 
205       {
206        setSolverTheta( s_theta.getValue()/10.0 );
207        updateTheta( );
208        updateSigmaTheta( );
209        updateTauTheta( );
210       }
211     }
212    
213    }
214