1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
public class ChangePaletteLimitsDialog extends MyDialog {
private boolean isOK = false;
private float minValue, maxValue;
private MyButton bOK, bCancel;
private MyFormattedTextField txtMin, txtMax;
public ChangePaletteLimitsDialog(JFrame parent, float minValue, float maxValue){
super(parent, "Modification des limites", true);
setResizable(false);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
getContentPane().setLayout(new GridBagLayout());
/** Constantes */
Insets leftComponentInsets = new Insets(15,30,0,5);
Insets rightComponentInsets = new Insets(15,5,0,30);
Insets buttonsInsets = new Insets(8,5,8,5);
int txtWidth = 60;
int txtHeight = 22;
DecimalFormat format = Texts.formatFactory("###0.###");
/** Création des composants */
MyLabel labelMin = new MyLabel("Valeur minimale :");
txtMin = new MyFormattedTextField(format);
txtMin.setHorizontalAlignment(JTextField.RIGHT);
txtMin.setAlignmentX(JTextField.RIGHT_ALIGNMENT);
txtMin.setSizes(txtWidth, txtHeight);
txtMin.setText(""+minValue);
txtMin.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent ke) {
keyPressed_actionPerformed(ke);
}
});
txtMin.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent arg0) {
txtMin.selectAll();
}
});
// txtMin.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent arg0) {
// txtMin.selectAll();
// }
// });
MyLabel labelMax = new MyLabel("Valeur maximale :");
txtMax = new MyFormattedTextField(format);
txtMax.setHorizontalAlignment(JTextField.RIGHT);
txtMax.setAlignmentX(JTextField.RIGHT_ALIGNMENT);
txtMax.setSizes(txtWidth, txtHeight);
txtMax.setText(""+maxValue);
txtMax.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent ke) {
keyPressed_actionPerformed(ke);
}
});
txtMax.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent arg0) {
txtMax.selectAll();
}
});
// txtMax.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent arg0) {
// txtMax.selectAll();
// }
// });
MyPanel panel = new MyPanel();
bOK = new MyButton("OK");
bOK.setSizes(60,25);
bOK.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae) {
bOK_actionPerformed();
}
});
bCancel = new MyButton("Annuler");
bCancel.setSizes(60,25);
bCancel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae) {
bCancel_actionPerformed();
}
});
/** Contraintes */
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.CENTER;
/** Agencement des composants */
constraints.gridx = 1;
constraints.gridy = 0;
constraints.gridwidth = 2;
constraints.insets = leftComponentInsets;
getContentPane().add(labelMin, constraints);
constraints.gridx = 3;
constraints.insets = rightComponentInsets;
getContentPane().add(txtMin, constraints);
constraints.gridx = 1;
constraints.gridy = 1;
constraints.insets = leftComponentInsets;
getContentPane().add(labelMax, constraints);
constraints.gridx = 3;
constraints.insets = rightComponentInsets;
getContentPane().add(txtMax, constraints);
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.insets = buttonsInsets;
panel.add(bOK, constraints);
constraints.gridx = 1;
panel.setLayout(new GridBagLayout());
panel.add(bCancel, constraints);
constraints.gridx = 0;
constraints.gridy = 3;
constraints.gridwidth = 6;
constraints.anchor = GridBagConstraints.CENTER;
getContentPane().add(panel, constraints);
this.pack();
setLocationRelativeTo(parent);
txtMin.requestFocus();
// bOK.requestFocus();
// getRootPane().setDefaultButton(bOK);
setVisible(true);
}
/**
* @return
*/
public boolean isOK() {
return isOK;
}
public void bOK_actionPerformed(){
isOK=true;
minValue = new Float(txtMin.getText()).floatValue();
maxValue = new Float(txtMax.getText()).floatValue();
dispose(); //st11870 : à faire en dehors ou là?
}
public void bCancel_actionPerformed(){
escapeActionPerformed();
}
private void keyPressed_actionPerformed(KeyEvent ke) {
if (ke.getKeyChar() == KeyEvent.VK_ESCAPE) {
escapeActionPerformed();
}
else if (ke.getKeyChar() == KeyEvent.VK_ENTER) {
bOK_actionPerformed();
}
}
protected void escapeActionPerformed() {
isOK=false;
dispose();
}
public float getMaxValue() {
return maxValue;
}
public float getMinValue() {
return minValue;
}
} |
Partager