00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 package ikayaki.gui;
00024
00025 import com.intellij.uiDesigner.core.GridConstraints;
00026 import com.intellij.uiDesigner.core.GridLayoutManager;
00027 import com.intellij.uiDesigner.core.Spacer;
00028 import ikayaki.Settings;
00029
00030 import javax.comm.CommPortIdentifier;
00031 import javax.swing.*;
00032 import javax.swing.event.DocumentEvent;
00033 import javax.swing.event.DocumentListener;
00034 import javax.swing.text.NumberFormatter;
00035 import java.awt.*;
00036 import java.awt.event.ActionEvent;
00037 import java.awt.event.ActionListener;
00038 import java.awt.event.KeyEvent;
00039 import java.text.DecimalFormat;
00040 import java.text.NumberFormat;
00041 import java.util.ArrayList;
00042 import java.util.Collections;
00043 import java.util.Enumeration;
00044
00051 public class DeviceSettingsPanel extends JPanel {
00052
00056 private JComboBox magnetometerPort;
00057
00061 private JComboBox demagnetizerPort;
00062
00066 private JComboBox handlerPort;
00067
00071 private JFormattedTextField xAxisCalibration;
00072
00076 private JFormattedTextField yAxisCalibration;
00077
00081 private JFormattedTextField zAxisCalibration;
00082
00086 private JComboBox demagRamp;
00087
00091 private JComboBox demagDelay;
00092
00096 private JFormattedTextField acceleration;
00097
00101 private JFormattedTextField deceleration;
00102
00106 private JFormattedTextField velocity;
00107
00111 private JFormattedTextField measurementVelocity;
00112
00116 private JFormattedTextField transverseYAFPosition;
00117
00121 private JFormattedTextField axialAFPosition;
00122
00126 private JFormattedTextField sampleLoadPosition;
00127
00131 private JFormattedTextField backgroundPosition;
00132
00136 private JFormattedTextField measurementPosition;
00137
00141 private JFormattedTextField rotation;
00142
00146 private JFormattedTextField rotationVelocity;
00147
00151 private JFormattedTextField rotationAcc;
00152
00156 private JFormattedTextField rotationDec;
00157
00161 private JFormattedTextField maximumField;
00162
00166 private JPanel contentPane;
00167 private JLabel warningLabel;
00168
00169 private JButton saveButton;
00170 private JButton cancelButton;
00171 private Action saveAction;
00172 private Action cancelAction;
00173
00174 private JDialog creator;
00175
00180 public DeviceSettingsPanel(JDialog creator) {
00181
00182 this.creator = creator;
00183
00184 $$$setupUI$$$();
00185 setLayout(new BorderLayout());
00186 add(contentPane, BorderLayout.CENTER);
00187
00188
00189 warningLabel.setFont(warningLabel.getFont().deriveFont(Font.BOLD, 14.0F));
00190 warningLabel.setForeground(new Color(0x993333));
00191
00192
00193 this.acceleration.setValue(Settings.getHandlerAcceleration());
00194 this.deceleration.setValue(Settings.getHandlerDeceleration());
00195 this.axialAFPosition.setValue(Settings.getHandlerAxialAFPosition());
00196 this.transverseYAFPosition.setValue(Settings.getHandlerTransverseYAFPosition());
00197 this.measurementPosition.setValue(Settings.getHandlerMeasurementPosition());
00198 this.velocity.setValue(Settings.getHandlerVelocity());
00199 this.measurementVelocity.setValue(Settings.getHandlerMeasurementVelocity());
00200 this.xAxisCalibration.setValue(Settings.getMagnetometerXAxisCalibration());
00201 this.yAxisCalibration.setValue(Settings.getMagnetometerYAxisCalibration());
00202 this.zAxisCalibration.setValue(Settings.getMagnetometerZAxisCalibration());
00203 this.demagRamp.addItem(new Integer(3));
00204 this.demagRamp.addItem(new Integer(5));
00205 this.demagRamp.addItem(new Integer(7));
00206 this.demagRamp.addItem(new Integer(9));
00207 int rampValue = Settings.getDegausserRamp();
00208 if (rampValue == 3 || rampValue == 5 || rampValue == 7 || rampValue == 9) {
00209 demagRamp.setSelectedItem(new Integer(rampValue));
00210 } else {
00211 demagRamp.setSelectedItem(new Integer(3));
00212 }
00213 for (int i = 1; i < 10; i++) {
00214 this.demagDelay.addItem(new Integer(i));
00215 }
00216 this.demagDelay.setSelectedItem(new Integer(Settings.getDegausserDelay()));
00217 this.sampleLoadPosition.setValue(Settings.getHandlerSampleLoadPosition());
00218 this.backgroundPosition.setValue(Settings.getHandlerBackgroundPosition());
00219 this.rotation.setValue(Settings.getHandlerRotation());
00220 this.rotationVelocity.setValue(Settings.getHandlerRotationVelocity());
00221 this.rotationAcc.setValue(Settings.getHandlerAcceleration());
00222 this.rotationDec.setValue(Settings.getHandlerDeceleration());
00223 this.maximumField.setValue(Settings.getDegausserMaximumField());
00224
00225
00226 MyFormatterFactory factory = new MyFormatterFactory();
00227 acceleration.setFormatterFactory(factory);
00228 deceleration.setFormatterFactory(factory);
00229 velocity.setFormatterFactory(factory);
00230 measurementVelocity.setFormatterFactory(factory);
00231 transverseYAFPosition.setFormatterFactory(factory);
00232 axialAFPosition.setFormatterFactory(factory);
00233 sampleLoadPosition.setFormatterFactory(factory);
00234 backgroundPosition.setFormatterFactory(factory);
00235 measurementPosition.setFormatterFactory(factory);
00236 rotation.setFormatterFactory(factory);
00237 rotationVelocity.setFormatterFactory(factory);
00238 rotationAcc.setFormatterFactory(factory);
00239 rotationDec.setFormatterFactory(factory);
00240 xAxisCalibration.setFormatterFactory(factory);
00241 yAxisCalibration.setFormatterFactory(factory);
00242 zAxisCalibration.setFormatterFactory(factory);
00243 maximumField.setFormatterFactory(factory);
00244
00245
00246 Enumeration ports = CommPortIdentifier.getPortIdentifiers();
00247
00248 ArrayList<String> portList = new ArrayList<String>();
00249
00250 if (!ports.hasMoreElements()) {
00251 System.err.println("No comm ports found!");
00252 } else {
00253 while (ports.hasMoreElements()) {
00254
00255
00256
00257 CommPortIdentifier portId = (CommPortIdentifier) ports.nextElement();
00258
00259 if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
00260 portList.add(portId.getName());
00261 }
00262 }
00263 }
00264 Collections.sort(portList);
00265
00266
00267 for (int i = 0; i < portList.size(); i++) {
00268 this.magnetometerPort.addItem(portList.get(i));
00269 this.handlerPort.addItem(portList.get(i));
00270 this.demagnetizerPort.addItem(portList.get(i));
00271 }
00272
00273
00274 this.magnetometerPort.setSelectedItem(Settings.getMagnetometerPort());
00275 this.handlerPort.setSelectedItem(Settings.getHandlerPort());
00276 this.demagnetizerPort.setSelectedItem(Settings.getDegausserPort());
00277
00278
00279 saveButton.setAction(this.getSaveAction());
00280 getSaveAction().setEnabled(false);
00281 cancelButton.setAction(this.getCancelAction());
00282
00283
00284 DocumentListener saveListener = new DocumentListener() {
00285 public void insertUpdate(DocumentEvent e) {
00286 if (correctValues()) {
00287 getSaveAction().setEnabled(true);
00288 } else {
00289 getSaveAction().setEnabled(false);
00290 }
00291 }
00292
00293 public void removeUpdate(DocumentEvent e) {
00294 if (correctValues()) {
00295 getSaveAction().setEnabled(true);
00296 } else {
00297 getSaveAction().setEnabled(false);
00298 }
00299 }
00300
00301 public void changedUpdate(DocumentEvent e) {
00302 }
00303 };
00304
00305
00306 ActionListener propertiesActionListener = new ActionListener() {
00307 public void actionPerformed(ActionEvent e) {
00308 if (correctValues()) {
00309 getSaveAction().setEnabled(true);
00310 } else {
00311 getSaveAction().setEnabled(false);
00312 }
00313 }
00314 };
00315
00316
00317 magnetometerPort.addActionListener(propertiesActionListener);
00318 demagnetizerPort.addActionListener(propertiesActionListener);
00319 handlerPort.addActionListener(propertiesActionListener);
00320
00321 xAxisCalibration.getDocument().addDocumentListener(saveListener);
00322 yAxisCalibration.getDocument().addDocumentListener(saveListener);
00323 zAxisCalibration.getDocument().addDocumentListener(saveListener);
00324
00325 demagRamp.addActionListener(propertiesActionListener);
00326 demagDelay.addActionListener(propertiesActionListener);
00327
00328 acceleration.getDocument().addDocumentListener(saveListener);
00329 deceleration.getDocument().addDocumentListener(saveListener);
00330 velocity.getDocument().addDocumentListener(saveListener);
00331 measurementVelocity.getDocument().addDocumentListener(saveListener);
00332
00333 transverseYAFPosition.getDocument().addDocumentListener(saveListener);
00334 axialAFPosition.getDocument().addDocumentListener(saveListener);
00335 sampleLoadPosition.getDocument().addDocumentListener(saveListener);
00336 backgroundPosition.getDocument().addDocumentListener(saveListener);
00337 measurementPosition.getDocument().addDocumentListener(saveListener);
00338
00339 rotation.getDocument().addDocumentListener(saveListener);
00340 rotationVelocity.addActionListener(propertiesActionListener);
00341 rotationAcc.addActionListener(propertiesActionListener);
00342 rotationDec.addActionListener(propertiesActionListener);
00343
00344 maximumField.addActionListener(propertiesActionListener);
00345
00346 saveButton.setEnabled(correctValues());
00347 }
00348
00352 public void saveSettings() {
00353 try {
00354 Settings.setDegausserPort((String) this.demagnetizerPort.getSelectedItem());
00355 Settings.setDegausserDelay(((Number) this.demagDelay.getSelectedItem()).intValue());
00356 Settings.setDegausserRamp(((Number) this.demagRamp.getSelectedItem()).intValue());
00357 Settings.setDegausserMaximumField(((Number) this.maximumField.getValue()).doubleValue());
00358 Settings.setHandlerPort((String) this.handlerPort.getSelectedItem());
00359 Settings.setHandlerAcceleration(((Number) this.acceleration.getValue()).intValue());
00360 Settings.setHandlerAxialAFPosition(((Number) this.axialAFPosition.getValue()).intValue());
00361 Settings.setHandlerBackgroundPosition(((Number) this.backgroundPosition.getValue()).intValue());
00362 Settings.setHandlerDeceleration(((Number) this.deceleration.getValue()).intValue());
00363 Settings.setHandlerMeasurementPosition(((Number) this.measurementPosition.getValue()).intValue());
00364 Settings.setHandlerMeasurementVelocity(((Number) this.measurementVelocity.getValue()).intValue());
00365 Settings.setHandlerRotation(((Number) this.rotation.getValue()).intValue());
00366 Settings.setHandlerSampleLoadPosition(((Number) this.sampleLoadPosition.getValue()).intValue());
00367 Settings.setHandlerTransverseYAFPosition(((Number) this.transverseYAFPosition.getValue()).intValue());
00368 Settings.setHandlerVelocity(((Number) this.velocity.getValue()).intValue());
00369 Settings.setHandlerRotationVelocity(((Number) this.rotationVelocity.getValue()).intValue());
00370 Settings.setHandlerRotationDeceleration(((Number) this.rotationDec.getValue()).intValue());
00371 Settings.setHandlerRotationAcceleration(((Number) this.rotationAcc.getValue()).intValue());
00372
00373 Settings.setMagnetometerPort((String) this.magnetometerPort.getSelectedItem());
00374 Settings.setMagnetometerXAxisCalibration(((Number) this.xAxisCalibration.getValue()).doubleValue());
00375 Settings.setMagnetometerYAxisCalibration(((Number) this.yAxisCalibration.getValue()).doubleValue());
00376 Settings.setMagnetometerZAxisCalibration(((Number) this.zAxisCalibration.getValue()).doubleValue());
00377 creator.setVisible(false);
00378 } catch (Exception e) {
00379 e.printStackTrace();
00380 }
00381 }
00382
00388 private boolean correctValues() {
00389 try {
00390
00391 } catch (Exception e) {
00392 e.printStackTrace();
00393 return false;
00394 }
00395 return true;
00396 }
00397
00398 public Action getSaveAction() {
00399 if (saveAction == null) {
00400 saveAction = new AbstractAction() {
00401 public void actionPerformed(ActionEvent e) {
00402 saveSettings();
00403 }
00404 };
00405 saveAction.putValue(Action.NAME, "Save");
00406 }
00407 return saveAction;
00408 }
00409
00410 public Action getCancelAction() {
00411 if (cancelAction == null) {
00412 cancelAction = new AbstractAction() {
00413 public void actionPerformed(ActionEvent e) {
00414 creator.setVisible(false);
00415 }
00416 };
00417
00418 cancelAction.putValue(Action.NAME, "Cancel");
00419 cancelAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_C);
00420
00421 cancelAction.putValue(Action.ACCELERATOR_KEY,
00422 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
00423 }
00424 return cancelAction;
00425 }
00426
00427 {
00428
00429
00430
00431 $$$setupUI$$$();
00432 }
00433
00438 private void $$$setupUI$$$() {
00439 contentPane = new JPanel();
00440 contentPane.setLayout(new GridLayoutManager(3, 3, new Insets(11, 11, 11, 11), -1, -1));
00441 final JPanel panel1 = new JPanel();
00442 panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 4, 4, 4), -1, -1));
00443 contentPane.add(panel1,
00444 new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00445 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00446 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null));
00447 panel1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Magnetometer"));
00448 final JPanel panel2 = new JPanel();
00449 panel2.setLayout(new GridLayoutManager(7, 3, new Insets(0, 0, 0, 0), -1, -1));
00450 panel1.add(panel2,
00451 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00452 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00453 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null));
00454 magnetometerPort = new JComboBox();
00455 panel2.add(magnetometerPort,
00456 new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00457 GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00458 final JLabel label1 = new JLabel();
00459 label1.setText("COM port:");
00460 panel2.add(label1,
00461 new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00462 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00463 final JLabel label2 = new JLabel();
00464 label2.setText("Calibration constant with polarity (Amē/flux quantum)");
00465 panel2.add(label2,
00466 new GridConstraints(2, 0, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00467 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00468 final JLabel label3 = new JLabel();
00469 label3.setText("X");
00470 panel2.add(label3,
00471 new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00472 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00473 final JLabel label4 = new JLabel();
00474 label4.setText("Y");
00475 panel2.add(label4,
00476 new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00477 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00478 final JLabel label5 = new JLabel();
00479 label5.setText("Z");
00480 panel2.add(label5,
00481 new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00482 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00483 yAxisCalibration = new JFormattedTextField();
00484 yAxisCalibration.setHorizontalAlignment(4);
00485 panel2.add(yAxisCalibration,
00486 new GridConstraints(4, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00487 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00488 new Dimension(150, -1), null));
00489 xAxisCalibration = new JFormattedTextField();
00490 xAxisCalibration.setHorizontalAlignment(4);
00491 panel2.add(xAxisCalibration,
00492 new GridConstraints(3, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00493 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00494 new Dimension(150, -1), null));
00495 zAxisCalibration = new JFormattedTextField();
00496 zAxisCalibration.setHorizontalAlignment(4);
00497 panel2.add(zAxisCalibration,
00498 new GridConstraints(5, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00499 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00500 new Dimension(150, -1), null));
00501 final Spacer spacer1 = new Spacer();
00502 panel2.add(spacer1,
00503 new GridConstraints(6, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1,
00504 GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null));
00505 final JPanel panel3 = new JPanel();
00506 panel3.setLayout(new GridLayoutManager(1, 1, new Insets(0, 4, 4, 4), -1, -1));
00507 contentPane.add(panel3,
00508 new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00509 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00510 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null));
00511 panel3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Demagnetizer"));
00512 final JPanel panel4 = new JPanel();
00513 panel4.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
00514 panel3.add(panel4,
00515 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00516 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00517 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null));
00518 final Spacer spacer2 = new Spacer();
00519 panel4.add(spacer2,
00520 new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1,
00521 GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null));
00522 final JPanel panel5 = new JPanel();
00523 panel5.setLayout(new GridLayoutManager(8, 3, new Insets(0, 0, 0, 0), -1, -1));
00524 panel4.add(panel5,
00525 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00526 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00527 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null));
00528 final JLabel label6 = new JLabel();
00529 label6.setText("COM port:");
00530 panel5.add(label6,
00531 new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00532 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00533 final JLabel label7 = new JLabel();
00534 label7.setText("Ramp");
00535 panel5.add(label7,
00536 new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00537 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00538 final JLabel label8 = new JLabel();
00539 label8.setText("Delay");
00540 panel5.add(label8,
00541 new GridConstraints(7, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00542 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00543 final JLabel label9 = new JLabel();
00544 label9.setText("Maximum Field");
00545 panel5.add(label9,
00546 new GridConstraints(5, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00547 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00548 maximumField = new JFormattedTextField();
00549 maximumField.setHorizontalAlignment(4);
00550 panel5.add(maximumField,
00551 new GridConstraints(5, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00552 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00553 new Dimension(150, -1), null));
00554 demagRamp = new JComboBox();
00555 panel5.add(demagRamp,
00556 new GridConstraints(6, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00557 GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00558 demagDelay = new JComboBox();
00559 panel5.add(demagDelay,
00560 new GridConstraints(7, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00561 GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00562 demagnetizerPort = new JComboBox();
00563 panel5.add(demagnetizerPort,
00564 new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00565 GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00566 final JPanel panel6 = new JPanel();
00567 panel6.setLayout(new GridLayoutManager(1, 1, new Insets(0, 4, 4, 4), -1, -1));
00568 contentPane.add(panel6,
00569 new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00570 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00571 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null));
00572 panel6.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Handler"));
00573 final JPanel panel7 = new JPanel();
00574 panel7.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
00575 panel6.add(panel7,
00576 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00577 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00578 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null));
00579 final JPanel panel8 = new JPanel();
00580 panel8.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
00581 panel7.add(panel8,
00582 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00583 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00584 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null));
00585 final JPanel panel9 = new JPanel();
00586 panel9.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
00587 panel8.add(panel9,
00588 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00589 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00590 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null));
00591 final JPanel panel10 = new JPanel();
00592 panel10.setLayout(new GridLayoutManager(17, 2, new Insets(0, 0, 0, 0), -1, -1));
00593 panel9.add(panel10,
00594 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00595 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00596 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null));
00597 rotation = new JFormattedTextField();
00598 rotation.setHorizontalAlignment(4);
00599 panel10.add(rotation,
00600 new GridConstraints(15, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00601 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00602 new Dimension(150, -1), null));
00603 final JLabel label10 = new JLabel();
00604 label10.setText("Rotation counts");
00605 panel10.add(label10,
00606 new GridConstraints(15, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00607 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00608 final Spacer spacer3 = new Spacer();
00609 panel10.add(spacer3,
00610 new GridConstraints(16, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1,
00611 GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null));
00612 deceleration = new JFormattedTextField();
00613 deceleration.setHorizontalAlignment(4);
00614 panel10.add(deceleration,
00615 new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00616 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00617 new Dimension(150, -1), null));
00618 final JLabel label11 = new JLabel();
00619 label11.setText("Velocity");
00620 panel10.add(label11,
00621 new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00622 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00623 velocity = new JFormattedTextField();
00624 velocity.setHorizontalAlignment(4);
00625 panel10.add(velocity,
00626 new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00627 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00628 new Dimension(150, -1), null));
00629 final JLabel label12 = new JLabel();
00630 label12.setText("Velocity Meas.");
00631 panel10.add(label12,
00632 new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00633 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00634 measurementVelocity = new JFormattedTextField();
00635 measurementVelocity.setHorizontalAlignment(4);
00636 panel10.add(measurementVelocity,
00637 new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00638 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00639 new Dimension(150, -1), null));
00640 final JLabel label13 = new JLabel();
00641 label13.setText("Transverse Y AF");
00642 panel10.add(label13,
00643 new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00644 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00645 transverseYAFPosition = new JFormattedTextField();
00646 transverseYAFPosition.setHorizontalAlignment(4);
00647 panel10.add(transverseYAFPosition,
00648 new GridConstraints(6, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00649 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00650 new Dimension(150, -1), null));
00651 final JLabel label14 = new JLabel();
00652 label14.setText("Translation positions");
00653 panel10.add(label14,
00654 new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00655 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00656 final JLabel label15 = new JLabel();
00657 label15.setText("Axial AF");
00658 panel10.add(label15,
00659 new GridConstraints(7, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00660 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00661 axialAFPosition = new JFormattedTextField();
00662 axialAFPosition.setHorizontalAlignment(4);
00663 panel10.add(axialAFPosition,
00664 new GridConstraints(7, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00665 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00666 new Dimension(150, -1), null));
00667 final JLabel label16 = new JLabel();
00668 label16.setText("Sample Load");
00669 panel10.add(label16,
00670 new GridConstraints(8, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00671 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00672 sampleLoadPosition = new JFormattedTextField();
00673 sampleLoadPosition.setHorizontalAlignment(4);
00674 panel10.add(sampleLoadPosition,
00675 new GridConstraints(8, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00676 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00677 new Dimension(150, -1), null));
00678 final JLabel label17 = new JLabel();
00679 label17.setText("Background");
00680 panel10.add(label17,
00681 new GridConstraints(9, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00682 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00683 backgroundPosition = new JFormattedTextField();
00684 backgroundPosition.setHorizontalAlignment(4);
00685 panel10.add(backgroundPosition,
00686 new GridConstraints(9, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00687 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00688 new Dimension(150, -1), null));
00689 final JLabel label18 = new JLabel();
00690 label18.setText("Measurement");
00691 panel10.add(label18,
00692 new GridConstraints(10, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00693 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00694 measurementPosition = new JFormattedTextField();
00695 measurementPosition.setHorizontalAlignment(4);
00696 panel10.add(measurementPosition,
00697 new GridConstraints(10, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00698 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00699 new Dimension(150, -1), null));
00700 rotationAcc = new JFormattedTextField();
00701 rotationAcc.setHorizontalAlignment(4);
00702 panel10.add(rotationAcc,
00703 new GridConstraints(13, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00704 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00705 new Dimension(150, -1), null));
00706 rotationVelocity = new JFormattedTextField();
00707 rotationVelocity.setHorizontalAlignment(4);
00708 rotationVelocity.setText("");
00709 panel10.add(rotationVelocity,
00710 new GridConstraints(12, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00711 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00712 new Dimension(150, -1), null));
00713 rotationDec = new JFormattedTextField();
00714 rotationDec.setHorizontalAlignment(4);
00715 panel10.add(rotationDec,
00716 new GridConstraints(14, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00717 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00718 new Dimension(150, -1), null));
00719 final JLabel label19 = new JLabel();
00720 label19.setText("Rotation acc.");
00721 panel10.add(label19,
00722 new GridConstraints(13, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00723 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00724 final JLabel label20 = new JLabel();
00725 label20.setText("Rotation velocity");
00726 panel10.add(label20,
00727 new GridConstraints(12, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00728 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00729 final JLabel label21 = new JLabel();
00730 label21.setText("Rotation dec.");
00731 panel10.add(label21,
00732 new GridConstraints(14, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00733 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00734 final JLabel label22 = new JLabel();
00735 label22.setText("COM port:");
00736 panel10.add(label22,
00737 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00738 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00739 handlerPort = new JComboBox();
00740 panel10.add(handlerPort,
00741 new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00742 GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00743 final JLabel label23 = new JLabel();
00744 label23.setText("Acceleration");
00745 panel10.add(label23,
00746 new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00747 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00748 acceleration = new JFormattedTextField();
00749 acceleration.setHorizontalAlignment(4);
00750 panel10.add(acceleration,
00751 new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00752 GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00753 new Dimension(150, -1), null));
00754 final JLabel label24 = new JLabel();
00755 label24.setText("Deceleration");
00756 panel10.add(label24,
00757 new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00758 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00759 final JPanel panel11 = new JPanel();
00760 panel11.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
00761 contentPane.add(panel11,
00762 new GridConstraints(2, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00763 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00764 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null));
00765 panel11.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null));
00766 final JPanel panel12 = new JPanel();
00767 panel12.setLayout(new GridLayoutManager(1, 5, new Insets(0, 0, 0, 0), -1, -1));
00768 panel11.add(panel12,
00769 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00770 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00771 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null));
00772 cancelButton = new JButton();
00773 cancelButton.setText("Cancel");
00774 panel12.add(cancelButton,
00775 new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
00776 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00777 GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00778 final Spacer spacer4 = new Spacer();
00779 panel12.add(spacer4,
00780 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
00781 GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null));
00782 saveButton = new JButton();
00783 saveButton.setText("Save");
00784 panel12.add(saveButton,
00785 new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
00786 GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00787 GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00788 final Spacer spacer5 = new Spacer();
00789 panel12.add(spacer5,
00790 new GridConstraints(0, 4, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
00791 GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null));
00792 warningLabel = new JLabel();
00793 warningLabel.setHorizontalAlignment(0);
00794 warningLabel.setHorizontalTextPosition(0);
00795 warningLabel.setText("WARNING! Incorrect configuration may damage the equipment.");
00796 contentPane.add(warningLabel,
00797 new GridConstraints(0, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00798 GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00799 }
00800
00804 private class MyFormatterFactory
00805 extends JFormattedTextField.AbstractFormatterFactory {
00814 public JFormattedTextField.AbstractFormatter getFormatter(JFormattedTextField tf) {
00815 NumberFormatter formatter;
00816
00817 if (tf == xAxisCalibration || tf == yAxisCalibration ||
00818 tf == zAxisCalibration) {
00819
00820 DecimalFormat format = new DecimalFormat();
00821 format.setDecimalSeparatorAlwaysShown(true);
00822 format.setGroupingUsed(true);
00823 format.setMaximumFractionDigits(12);
00824 formatter = new NumberFormatter(format);
00825 } else if (tf == maximumField) {
00826 DecimalFormat format = new DecimalFormat();
00827 format.setDecimalSeparatorAlwaysShown(true);
00828 format.setGroupingUsed(true);
00829 format.setMinimumFractionDigits(1);
00830 format.setMaximumFractionDigits(1);
00831 formatter = new NumberFormatter(format);
00832
00833 } else {
00834
00835 NumberFormat format = NumberFormat.getIntegerInstance();
00836 format.setGroupingUsed(true);
00837 formatter = new NumberFormatter(format);
00838 }
00839
00840
00841 if (tf == acceleration || tf == deceleration || tf == rotationAcc || tf == rotationDec) {
00842 formatter.setMinimum(new Integer(0));
00843 formatter.setMaximum(new Integer(127));
00844 } else if (tf == velocity || tf == measurementVelocity || tf == rotationVelocity) {
00845 formatter.setMinimum(new Integer(50));
00846 formatter.setMaximum(new Integer(20000));
00847 } else if (tf == measurementPosition || tf == sampleLoadPosition ||
00848 tf == backgroundPosition
00849 || tf == axialAFPosition || tf == transverseYAFPosition ||
00850 tf == measurementPosition) {
00851 formatter.setMinimum(new Integer(0));
00852 formatter.setMaximum(new Integer(16777215));
00853 } else if (tf == rotation) {
00854 formatter.setMinimum(new Integer(Integer.MIN_VALUE));
00855 formatter.setMaximum(new Integer(Integer.MAX_VALUE));
00856 } else if (tf == maximumField) {
00857 formatter.setMinimum(new Double(1.1));
00858 formatter.setMaximum(new Double(300.0));
00859 }
00860 return formatter;
00861 }
00862 }
00863 }