2023-02-05 17:46:02 +01:00
package action ;
2022-06-19 21:01:30 +02:00
import java.awt.event.ActionEvent ;
import javax.swing.AbstractAction ;
import javax.swing.Action ;
2022-12-21 17:54:28 +01:00
import javax.swing.Box ;
2022-06-19 21:01:30 +02:00
import javax.swing.ImageIcon ;
2022-12-21 17:54:28 +01:00
import javax.swing.JLabel ;
2022-06-19 21:01:30 +02:00
import javax.swing.JOptionPane ;
2022-12-21 17:54:28 +01:00
import javax.swing.JPanel ;
import javax.swing.JTextField ;
2022-06-19 21:01:30 +02:00
import cXML.node ;
import fenetres.baliseStyle ;
import fenetres.create ;
public class actCoefficient extends AbstractAction {
/ * *
*
* /
private static final long serialVersionUID = 1L ;
{
putValue ( Action . NAME , " Coefficient (poids) " ) ;
putValue ( Action . SMALL_ICON , new ImageIcon ( create . class . getResource ( " /resources/poidsmini.png " ) ) ) ;
putValue ( Action . SHORT_DESCRIPTION , " Coefficient (poids) " ) ;
}
@Override
public void actionPerformed ( ActionEvent e ) {
node nod = ( node ) fenetres . create . getSelectNode ( ) . getUserObject ( ) ;
double poids = 1 . 00 ;
if ( nod . getAttributs ( ) . get ( " poids " ) ! = null ) {
try {
poids = Double . valueOf ( nod . getAttributs ( ) . get ( " poids " ) ) ;
} catch ( Exception e2 ) {
System . out . println ( e2 . toString ( ) ) ;
}
}
2022-12-21 17:54:28 +01:00
JTextField poidsField = new JTextField ( 8 ) ;
poidsField . setText ( String . valueOf ( poids ) ) ;
JPanel myPanel = new JPanel ( ) ;
myPanel . add ( new JLabel ( " Coef. : " ) ) ;
myPanel . add ( Box . createHorizontalStrut ( 2 ) ) ; // a spacer
myPanel . add ( poidsField ) ;
int result = JOptionPane . showConfirmDialog ( null , myPanel , " Saisissez le coefficient " , JOptionPane . OK_CANCEL_OPTION ) ;
if ( result = = JOptionPane . OK_OPTION ) {
try {
poids = Double . valueOf ( poidsField . getText ( ) ) ;
if ( poids < = 0 ) {
nod . poids ( Double . valueOf ( 1 ) ) ;
fenetres . create . getTextNodeSelect ( ) . setText ( baliseStyle . balise ( ) ) ;
2023-01-01 18:42:29 +01:00
fenetres . create . getTextNodeSelect ( ) . setText ( " <h2>Erreur la valeur doit être un nombre POSITIF supérieur à zéro.<br>Cependant,la valeur a été modifiée.<br>poids=1.</h2> " ) ;
2022-12-21 17:54:28 +01:00
} else {
nod . poids ( Double . valueOf ( poids ) ) ;
fenetres . create . getTextNodeSelect ( ) . refreshAffichage ( nod ) ;
}
} catch ( Exception e2 ) {
2022-06-19 21:01:30 +02:00
fenetres . create . getTextNodeSelect ( ) . setText ( baliseStyle . balise ( ) ) ;
2022-12-21 17:54:28 +01:00
fenetres . create . getTextNodeSelect ( ) . setText ( " <h2>Erreur la valeur doit être un nombre entier.<br>La valeur n'a pas été modifiée.</h2> " ) ;
2022-06-19 21:01:30 +02:00
}
2022-12-21 17:54:28 +01:00
}
2022-06-19 21:01:30 +02:00
}
}