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 ikayaki.MeasurementEvent;
00026 import ikayaki.MeasurementListener;
00027 import ikayaki.Project;
00028 import ikayaki.Settings;
00029 import ikayaki.squid.Squid;
00030
00031 import javax.swing.*;
00032 import java.awt.*;
00033 import java.awt.event.ActionEvent;
00034 import java.awt.event.ActionListener;
00035 import java.util.TreeMap;
00036
00044 public class MagnetometerStatusPanel extends JPanel implements MeasurementListener {
00045
00046 public static final Color DEMAGNETIZING_COLOR = new Color(0xFFCCCC);
00047 public static final Color MEASURING_COLOR = new Color(0xFFFF99);
00048 public static final Color MOVING_COLOR = new Color(0xCCCCFF);
00049 public static final Color IDLE_COLOR = Color.WHITE;
00050
00054 final ManualControlsPanel manualControlsPanel;
00055
00056
00057
00058
00059
00060
00065 private Squid squid = null;
00066
00067
00068 private int position = 0;
00069 private int rotation = 0;
00070 private boolean moving = false;
00071 private boolean rotating = false;
00072
00073
00074 private boolean demagnetizing = false;
00075 private boolean measuring = false;
00076
00077
00078
00079 private int maxposition = 50000, maxrotation = 360;
00080
00081
00082
00083 private int posMove = -2;
00084 private int posLeft = -1;
00085 private int posHome;
00086 private int posDemagZ;
00087 private int posDemagY;
00088 private int posBG;
00089 private int posMeasure;
00090 private int posRight = 2 << 24 - 1;
00091
00095 private TreeMap<Integer, JComponent> moveButtons = new TreeMap<Integer, JComponent>();
00096
00100 public MagnetometerStatusPanel() {
00101 this.setLayout(new OverlayLayout(this));
00102
00103 this.manualControlsPanel = new ManualControlsPanel();
00104
00105
00106
00107 add(manualControlsPanel.moveLabel);
00108 add(manualControlsPanel.moveLeft);
00109 add(manualControlsPanel.moveHome);
00110 add(manualControlsPanel.moveDemagZ);
00111 add(manualControlsPanel.moveDemagY);
00112 add(manualControlsPanel.moveBG);
00113 add(manualControlsPanel.moveMeasure);
00114 add(manualControlsPanel.moveRight);
00115
00116 setPreferredSize(new Dimension(150, 400));
00117
00118
00119 updatePositions();
00120 updateStatus();
00121
00122
00123 new Timer(50, new ActionListener() {
00124 public void actionPerformed(ActionEvent e) {
00125 updateStatus();
00126 }
00127 }).start();
00128 }
00129
00134 public void setSquid(Squid squid) {
00135 this.squid = squid;
00136 updateStatus();
00137 manualControlsPanel.setEnabled();
00138 }
00139
00144 private void updatePositions() {
00145 posHome = Settings.getHandlerSampleLoadPosition();
00146 posDemagZ = Settings.getHandlerAxialAFPosition();
00147 posDemagY = Settings.getHandlerTransverseYAFPosition();
00148 posBG = Settings.getHandlerBackgroundPosition();
00149 posMeasure = Settings.getHandlerMeasurementPosition();
00150
00151 maxposition = 1;
00152 for (int pos : new int[]{posHome, posDemagZ, posDemagY, posBG, posMeasure}) {
00153 if (pos > maxposition) maxposition = pos;
00154 }
00155 maxposition *= 1.2;
00156
00157
00158
00159 moveButtons.clear();
00160 moveButtons.put(new Integer(posMove), manualControlsPanel.moveLabel);
00161 moveButtons.put(new Integer(posLeft), manualControlsPanel.moveLeft);
00162 moveButtons.put(new Integer(posHome), manualControlsPanel.moveHome);
00163 moveButtons.put(new Integer(posDemagZ), manualControlsPanel.moveDemagZ);
00164 moveButtons.put(new Integer(posDemagY), manualControlsPanel.moveDemagY);
00165 moveButtons.put(new Integer(posBG), manualControlsPanel.moveBG);
00166 moveButtons.put(new Integer(posMeasure), manualControlsPanel.moveMeasure);
00167 moveButtons.put(new Integer(posRight), manualControlsPanel.moveRight);
00168
00169
00170
00171 }
00172
00176 private void updateButtonPositions() {
00177 int height = getHeight(), nextpos = 0;
00178 for (Integer position : moveButtons.keySet()) {
00179 JComponent c = moveButtons.get(position);
00180 int cheight = c.getHeight();
00181 int pos = (int) ((long) height * position / maxposition);
00182 if (pos > height - cheight) pos = height - cheight;
00183 if (pos < nextpos) pos = nextpos;
00184 c.setLocation(c.getX(), pos);
00185 nextpos = pos + cheight;
00186 }
00187 }
00188
00192 public void updateStatus() {
00193 if (squid != null) {
00194 position = squid.getHandler().getEstimatedPosition();
00195 rotation = squid.getHandler().getEstimatedRotation();
00196 moving = squid.getHandler().isMoving();
00197 rotating = squid.getHandler().isRotating();
00198 measuring = squid.getMagnetometer().isMeasuring();
00199 demagnetizing = squid.getDegausser().isDemagnetizing();
00200 }
00201
00202 repaint();
00203 }
00204
00208 public void measurementUpdated(MeasurementEvent e) {
00209
00210 if (e == null) updatePositions();
00211
00212 updateStatus();
00213
00214
00215 manualControlsPanel.setEnabled();
00216 }
00217
00223 protected void paintComponent(Graphics g) {
00224
00225
00226 updateButtonPositions();
00227
00228
00229 super.paintComponent(g);
00230
00231
00232 Graphics2D g2 = (Graphics2D) g.create();
00233 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
00234 g2.setStroke(new BasicStroke(2));
00235 Color saved = g2.getColor();
00236
00237
00238 int w = getWidth();
00239 int h = getHeight();
00240
00241
00242 g2.translate(80, 0);
00243 w -= 100;
00244
00245
00246 int basex = w / 2;
00247
00248
00249 int box1y = (int) ((long) h * posDemagZ / maxposition);
00250 int box2y = (int) ((long) h * posBG / maxposition);
00251 int box1w = w * 3 / 5;
00252 int box2w = w * 4 / 5;
00253
00254
00255 int samplew = w / 3;
00256 int sampleh = w / 4;
00257 int sampled = h / 12;
00258 int arrowlength = w / 6;
00259
00260
00261 int sampley = (int) ((long) h * position / maxposition);
00262
00263
00264
00265
00266 g2.drawLine(basex, 24, basex, box1y);
00267 g2.setColor(Color.LIGHT_GRAY);
00268 g2.drawLine(basex, box1y, basex, h);
00269 g2.setColor(saved);
00270
00271
00272 g2.drawRect(basex - box1w / 2, box1y, box1w, box2y - box1y);
00273 g2.drawRect(basex - box2w / 2, box2y, box2w, h - box2y - 2);
00274
00275
00276 Color bg;
00277 if (demagnetizing) {
00278 bg = DEMAGNETIZING_COLOR;
00279 } else if (measuring) {
00280 bg = MEASURING_COLOR;
00281 } else if (moving || rotating) {
00282 bg = MOVING_COLOR;
00283 } else {
00284 bg = IDLE_COLOR;
00285 }
00286 drawFillOval(g2, bg, basex - samplew / 2, sampley - sampled, samplew, sampleh);
00287 drawFillSideRect(g2, bg, basex - samplew / 2, sampley - sampled + sampleh / 2, samplew, sampled);
00288 drawFillOval(g2, bg, basex - samplew / 2, sampley, samplew, sampleh);
00289
00290
00291 drawArrow(g2, basex, sampley + sampleh / 2, arrowlength, -rotation);
00292
00293
00294
00295 g2.drawString("position: " + position, basex - box2w / 2 + 6, h - 18);
00296 g2.drawString("rotation: " + rotation, basex - box2w / 2 + 6, h - 6);
00297
00298
00299 g2.dispose();
00300 }
00301
00305 private void drawFillOval(Graphics2D g2, Color fill, int x, int y, int width, int height) {
00306 Color saved = g2.getColor();
00307 g2.setColor(fill);
00308 g2.fillOval(x, y, width, height);
00309 g2.setColor(saved);
00310 g2.drawOval(x, y, width, height);
00311 }
00312
00316 private void drawFillSideRect(Graphics2D g2, Color fill, int x, int y, int width, int height) {
00317 Color saved = g2.getColor();
00318 g2.setColor(fill);
00319 g2.fillRect(x, y, width, height);
00320 g2.setColor(saved);
00321 g2.drawLine(x, y, x, y + height);
00322 g2.drawLine(x + width, y, x + width, y + height);
00323 }
00324
00334 private void drawArrow(Graphics2D g2, int x, int y, int length, int rotation) {
00335 double rot = Math.PI * 2 * rotation / maxrotation;
00336 g2.translate(x, y);
00337 g2.rotate(rot);
00338 g2.drawLine(0, -length / 2, 0, length / 2);
00339 g2.drawLine(0, -length / 2, -length / 4, -length / 4);
00340 g2.drawLine(0, -length / 2, length / 4, -length / 4);
00341 g2.rotate(-rot);
00342 g2.translate(-x, -y);
00343 }
00344
00350 private class MagnetometerStatusAnimator implements Runnable {
00351
00352 private int updateDelay;
00353
00354
00355 private int sps, msps, rps;
00356
00357
00358 private int posFrom, rotateFrom, posAmount, rotateAmount, posDirection, rotateDirection;
00359
00360 private long startTime;
00361 private boolean going;
00362
00363 private Thread animatorThread;
00364
00365 public MagnetometerStatusAnimator() {
00366 this(50);
00367 }
00368
00369 public MagnetometerStatusAnimator(int updateDelay) {
00370 this.sps = Settings.getHandlerVelocity();
00371 this.sps = Settings.getHandlerMeasurementVelocity();
00372 this.rps = Settings.getHandlerRotationVelocity();
00373 this.updateDelay = updateDelay;
00374 }
00375
00381 synchronized public void going(int posTo, int rotateTo) {
00382 if (true) {
00383 this.going = true;
00384 return;
00385 }
00386
00387
00388 killAnimatorThread();
00389
00390 this.posFrom = position;
00391 this.rotateFrom = rotation;
00392
00393 this.posAmount = Math.abs(posTo - posFrom);
00394 this.rotateAmount = Math.abs(rotateTo - rotateFrom);
00395 this.posDirection = posTo < posFrom ? -1 : 1;
00396 this.rotateDirection = rotateTo < rotateFrom ? -1 : 1;
00397
00398 this.startTime = System.currentTimeMillis();
00399 this.going = true;
00400
00401 animatorThread = new Thread(this);
00402 animatorThread.setPriority(animatorThread.getPriority() - 1);
00403 animatorThread.start();
00404 }
00405
00409 synchronized public void gone() {
00410 if (true) {
00411 this.going = false;
00412 return;
00413 }
00414
00415 if (animatorThread != null) {
00416 long time = System.currentTimeMillis() - startTime;
00417
00418
00419 this.sps = ((int) (posAmount * 1000L / time) + sps) / 2;
00420 this.rps = ((int) (rotateAmount * 1000L / time) + rps) / 2;
00421
00422
00423 }
00424
00425 killAnimatorThread();
00426 }
00427
00428 private void killAnimatorThread() {
00429 this.going = false;
00430 if (animatorThread != null) {
00431 animatorThread.interrupt();
00432 try {
00433 animatorThread.join();
00434 } catch (InterruptedException e) {
00435 }
00436 animatorThread = null;
00437 }
00438 }
00439
00440 public void run() {
00441 while (going) {
00442 try {
00443 Thread.sleep(updateDelay);
00444 } catch (InterruptedException e) {
00445 }
00446
00447 position = squid.getHandler().getEstimatedPosition();
00448 rotation = squid.getHandler().getEstimatedRotation();
00449
00450
00451
00452 if (!squid.getHandler().isMoving()) going = false;
00453
00454 MagnetometerStatusPanel.this.repaint();
00455 }
00456 }
00457
00461 public void run_old() {
00462 while (going) {
00463 try {
00464 Thread.sleep(updateDelay);
00465 } catch (InterruptedException e) {
00466 }
00467
00468 if (!going) break;
00469
00470 long time = System.currentTimeMillis() - startTime;
00471
00472
00473 int pos = (int) (sps * time / 1000);
00474 int rotate = (int) (rps * time / 1000);
00475 if (pos > posAmount) pos = posAmount;
00476 if (rotate > rotateAmount) rotate = rotateAmount;
00477
00478 position = posFrom + pos * posDirection;
00479 rotation = rotateFrom + rotate * rotateDirection;
00480
00481 MagnetometerStatusPanel.this.repaint();
00482
00483 if (pos == posAmount && rotate == rotateAmount) break;
00484 }
00485 }
00486 }
00487
00492 public class ManualControlsPanel extends JPanel {
00496 private Project project;
00497
00501 private final ButtonGroup moveButtonGroup = new ButtonGroup();
00502
00506 private final JRadioButton moveLeft = new JRadioButton("Left limit");
00507
00511 private final JRadioButton moveHome = new JRadioButton("Home");
00512
00516 private final JRadioButton moveDemagZ = new JRadioButton("Demag Z");
00517
00521 private final JRadioButton moveDemagY = new JRadioButton("Demag Y");
00522
00526 private final JRadioButton moveBG = new JRadioButton("BG");
00527
00531 private final JRadioButton moveMeasure = new JRadioButton("Measure");
00532
00536 private final JRadioButton moveRight = new JRadioButton("Right limit");
00537
00541 private final ButtonGroup rotateButtonGroup = new ButtonGroup();
00542
00546 private final JRadioButton rotate0 = new JRadioButton("0°");
00547
00551 private final JRadioButton rotate90 = new JRadioButton("90°");
00552
00556 private final JRadioButton rotate180 = new JRadioButton("180°");
00557
00561 private final JRadioButton rotate270 = new JRadioButton("270°");
00562
00566 private final JButton measureAllButton = new JButton();
00567 private final ComponentFlasher measureAllButtonFlasher = new ComponentFlasher(measureAllButton);
00568 private final String measureAllButtonBaseText = "Measure ";
00569
00573 private final JButton resetAllButton = new JButton("Reset XYZ");
00574 private final ComponentFlasher resetAllButtonFlasher = new ComponentFlasher(resetAllButton);
00575
00579 private final JButton nextLineButton = new JButton("Next Line");
00580 private final ComponentFlasher nextLineButtonFlasher = new ComponentFlasher(nextLineButton);
00581
00585 private final JTextField demagAmplitudeField = new JTextField();
00586 private final JLabel demagAmplitudeLabel = new JLabel("mT");
00587 private final ComponentFlasher demagAmplitudeFieldFlasher = new ComponentFlasher(demagAmplitudeField);
00588
00592 private final JButton demagButton = new JButton();
00593 private final ComponentFlasher demagButtonFlasher = new ComponentFlasher(demagButton);
00594 private final String demagButtonBaseText = "Demag ";
00595 private boolean demagButtonIsY = false;
00596
00600 private final JButton demagZButton = new JButton("Demag in Z");
00601 private final ComponentFlasher demagZButtonFlasher = new ComponentFlasher(demagZButton);
00602
00606 private final JButton demagYButton = new JButton("Demag in Y");
00607 private final ComponentFlasher demagYButtonFlasher = new ComponentFlasher(demagYButton);
00608
00609
00610 private final JLabel moveLabel = new JLabel("Move");
00611 private final JLabel rotateLabel = new JLabel("Rotate");
00612 private final JLabel measureLabel = new JLabel("Measure");
00613 private final JLabel demagLabel = new JLabel("Demagnetize");
00614
00615
00616 private final Component[] components = new Component[]{
00617 moveLeft, moveHome, moveDemagZ, moveDemagY, moveBG, moveMeasure, moveRight,
00618 rotate0, rotate90, rotate180, rotate270,
00619 measureAllButton, resetAllButton, nextLineButton,
00620 demagAmplitudeField, demagAmplitudeLabel, demagButton, demagZButton, demagYButton,
00621 moveLabel, rotateLabel, measureLabel, demagLabel
00622 };
00623
00627 public ManualControlsPanel() {
00628 moveButtonGroup.add(moveLeft);
00629 moveButtonGroup.add(moveHome);
00630 moveButtonGroup.add(moveDemagZ);
00631 moveButtonGroup.add(moveDemagY);
00632 moveButtonGroup.add(moveBG);
00633 moveButtonGroup.add(moveMeasure);
00634 moveButtonGroup.add(moveRight);
00635
00636 rotateButtonGroup.add(rotate0);
00637 rotateButtonGroup.add(rotate90);
00638 rotateButtonGroup.add(rotate180);
00639 rotateButtonGroup.add(rotate270);
00640
00641 moveLabel.setFont(moveLabel.getFont().deriveFont(Font.BOLD));
00642 rotateLabel.setFont(rotateLabel.getFont().deriveFont(Font.BOLD));
00643 measureLabel.setFont(measureLabel.getFont().deriveFont(Font.BOLD));
00644 demagLabel.setFont(demagLabel.getFont().deriveFont(Font.BOLD));
00645
00646 moveHome.setMargin(new Insets(0, 0, 0, 0));
00647 moveDemagZ.setMargin(new Insets(0, 0, 0, 0));
00648 moveDemagY.setMargin(new Insets(0, 0, 0, 0));
00649 moveBG.setMargin(new Insets(0, 0, 0, 0));
00650 moveMeasure.setMargin(new Insets(0, 0, 0, 0));
00651
00652 measureAllButton.setMargin(new Insets(1, 1, 1, 1));
00653 resetAllButton.setMargin(new Insets(1, 1, 1, 1));
00654 nextLineButton.setMargin(new Insets(1, 1, 1, 1));
00655 demagButton.setMargin(new Insets(1, 1, 1, 1));
00656 demagZButton.setMargin(new Insets(1, 1, 1, 1));
00657 demagYButton.setMargin(new Insets(1, 1, 1, 1));
00658
00659 JPanel rotatePanel = new JPanel(new BorderLayout());
00660 JPanel rotateButtonPanel = new JPanel(new BorderLayout());
00661 rotate0.setHorizontalAlignment(JRadioButton.CENTER);
00662 rotate180.setHorizontalAlignment(JRadioButton.CENTER);
00663 rotateButtonPanel.add(rotate0, BorderLayout.NORTH);
00664 rotateButtonPanel.add(rotate90, BorderLayout.WEST);
00665 rotateButtonPanel.add(rotate180, BorderLayout.SOUTH);
00666 rotateButtonPanel.add(rotate270, BorderLayout.EAST);
00667 rotatePanel.add(rotateLabel, BorderLayout.NORTH);
00668 rotatePanel.add(rotateButtonPanel, BorderLayout.CENTER);
00669
00670 JPanel measurePanel = new JPanel(new BorderLayout());
00671 JPanel measureButtonPanel = new JPanel(new GridLayout(3, 1, 0, 4));
00672 measureButtonPanel.add(measureAllButton);
00673 measureButtonPanel.add(resetAllButton);
00674 measureButtonPanel.add(nextLineButton);
00675 measurePanel.add(measureLabel, BorderLayout.NORTH);
00676 measurePanel.add(measureButtonPanel, BorderLayout.CENTER);
00677
00678 JPanel demagPanel = new JPanel(new BorderLayout());
00679 JPanel demagButtonPanel = new JPanel(new GridLayout(3, 1, 0, 4));
00680 JPanel demagAmplitudePanel = new JPanel(new BorderLayout(4, 0));
00681 demagAmplitudePanel.add(demagAmplitudeField, BorderLayout.CENTER);
00682 demagAmplitudePanel.add(demagAmplitudeLabel, BorderLayout.EAST);
00683 demagButtonPanel.add(demagAmplitudePanel);
00684 demagButtonPanel.add(demagButton);
00685
00686
00687 demagPanel.add(demagLabel, BorderLayout.NORTH);
00688 demagPanel.add(demagButtonPanel, BorderLayout.CENTER);
00689
00690 setLayout(new FlowLayout(FlowLayout.LEFT, 8, 0));
00691 add(rotatePanel);
00692 add(measurePanel);
00693 add(demagPanel);
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705 moveLeft.addActionListener(new ActionListener() {
00706 public void actionPerformed(ActionEvent e) {
00707 project.doManualMoveLeftLimit();
00708 }
00709 });
00710
00711 moveHome.addActionListener(new ActionListener() {
00712 public void actionPerformed(ActionEvent e) {
00713 project.doManualMoveHome();
00714 }
00715 });
00716
00717 moveDemagZ.addActionListener(new ActionListener() {
00718 public void actionPerformed(ActionEvent e) {
00719 project.doManualMoveDegausserZ();
00720 }
00721 });
00722
00723 moveDemagY.addActionListener(new ActionListener() {
00724 public void actionPerformed(ActionEvent e) {
00725 project.doManualMoveDegausserY();
00726 }
00727 });
00728
00729 moveBG.addActionListener(new ActionListener() {
00730 public void actionPerformed(ActionEvent e) {
00731 project.doManualMoveBackground();
00732 }
00733 });
00734
00735 moveMeasure.addActionListener(new ActionListener() {
00736 public void actionPerformed(ActionEvent e) {
00737 project.doManualMoveMeasurement();
00738 }
00739 });
00740
00741 moveRight.addActionListener(new ActionListener() {
00742 public void actionPerformed(ActionEvent e) {
00743 project.doManualMoveRightLimit();
00744 }
00745 });
00746
00747
00748
00749
00750
00751
00752 rotate0.addActionListener(new ActionListener() {
00753 public void actionPerformed(ActionEvent e) {
00754 project.doManualRotate(0);
00755 }
00756 });
00757
00758 rotate90.addActionListener(new ActionListener() {
00759 public void actionPerformed(ActionEvent e) {
00760 project.doManualRotate(90);
00761 }
00762 });
00763
00764 rotate180.addActionListener(new ActionListener() {
00765 public void actionPerformed(ActionEvent e) {
00766 project.doManualRotate(180);
00767 }
00768 });
00769
00770 rotate270.addActionListener(new ActionListener() {
00771 public void actionPerformed(ActionEvent e) {
00772 project.doManualRotate(270);
00773 }
00774 });
00775
00776
00777
00778
00779
00780 measureAllButton.addActionListener(new ActionListener() {
00781 public void actionPerformed(ActionEvent e) {
00782 if (!project.doManualMeasure()) measureAllButtonFlasher.flash();
00783 }
00784 });
00785
00786
00787
00788
00789
00790 resetAllButton.addActionListener(new ActionListener() {
00791 public void actionPerformed(ActionEvent e) {
00792 if (!project.doManualReset()) resetAllButtonFlasher.flash();
00793 }
00794 });
00795
00796
00797
00798
00799 nextLineButton.addActionListener(new ActionListener() {
00800 public void actionPerformed(ActionEvent e) {
00801 if (!project.doManualStepDone()) nextLineButtonFlasher.flash();
00802 }
00803 });
00804
00805
00806
00807
00808
00809 demagButton.addActionListener(new ActionListener() {
00810 public void actionPerformed(ActionEvent e) {
00811 double amplitude = getDemagAmplitude();
00812 if (amplitude < 0) {
00813 demagAmplitudeFieldError();
00814 } else if (demagButtonIsY) {
00815 if (!project.doManualDemagY(amplitude)) demagButtonFlasher.flash();
00816 } else {
00817 if (!project.doManualDemagZ(amplitude)) demagButtonFlasher.flash();
00818 }
00819 }
00820 });
00821
00822
00823
00824
00825
00826 demagZButton.addActionListener(new ActionListener() {
00827 public void actionPerformed(ActionEvent e) {
00828 double amplitude = getDemagAmplitude();
00829 if (amplitude < 0) {
00830 demagAmplitudeFieldError();
00831 } else if (!project.doManualDemagZ(amplitude)) demagZButtonFlasher.flash();
00832 }
00833 });
00834
00835
00836
00837
00838
00839 demagYButton.addActionListener(new ActionListener() {
00840 public void actionPerformed(ActionEvent e) {
00841 double amplitude = getDemagAmplitude();
00842 if (amplitude < 0) {
00843 demagAmplitudeFieldError();
00844 } else if (!project.doManualDemagY(amplitude)) demagYButtonFlasher.flash();
00845 }
00846 });
00847 }
00848
00854 private double getDemagAmplitude() {
00855 double amplitude;
00856 try {
00857 amplitude = Double.valueOf(demagAmplitudeField.getText());
00858 } catch (NumberFormatException ex) {
00859 amplitude = -1;
00860 }
00861
00862 return amplitude;
00863 }
00864
00868 private void demagAmplitudeFieldError() {
00869
00870 demagAmplitudeField.requestFocusInWindow();
00871 demagAmplitudeFieldFlasher.flash();
00872 }
00873
00880 public void setEnabled(boolean enabled) {
00881 super.setEnabled(enabled);
00882 if (squid == null) enabled = false;
00883 for (Component component : components) component.setEnabled(enabled);
00884
00885
00886
00887
00888 int currentPosition = 0;
00889 if (squid != null) {
00890 currentPosition = squid.getHandler().getPosition();
00891 }
00892 if (currentPosition == Integer.MIN_VALUE) {
00893 moveLeft.setSelected(true);
00894 } else if (currentPosition == Integer.MAX_VALUE) {
00895 moveRight.setSelected(true);
00896 } else {
00897 JComponent c = moveButtons.get(new Integer(currentPosition));
00898 if (c != null && c instanceof JRadioButton) {
00899 ((JRadioButton) c).setSelected(true);
00900 }
00901 }
00902
00903
00904 switch (rotation) {
00905 case 0:
00906 rotate0.setSelected(true);
00907 break;
00908 case 90:
00909 rotate90.setSelected(true);
00910 break;
00911 case 180:
00912 rotate180.setSelected(true);
00913 break;
00914 case 270:
00915 rotate270.setSelected(true);
00916 break;
00917 }
00918
00919
00920
00921
00922 if (position == posMeasure) {
00923 measureAllButton.setText(measureAllButtonBaseText + "XYZ");
00924 } else {
00925 measureAllButton.setText(measureAllButtonBaseText + "BG ");
00926 }
00927
00928
00929 demagButton.setEnabled(enabled && project != null && project.isDegaussingEnabled());
00930 if (position == posDemagZ) {
00931 demagButtonIsY = false;
00932 demagButton.setText(demagButtonBaseText + "Z");
00933 } else if (position == posDemagY) {
00934 demagButtonIsY = true;
00935 switch (rotation) {
00936 case 0:
00937 case 180:
00938 demagButton.setText(demagButtonBaseText + "Y");
00939 break;
00940 case 90:
00941 case 270:
00942 demagButton.setText(demagButtonBaseText + "X");
00943 break;
00944 }
00945 } else {
00946 demagButton.setText(demagButtonBaseText);
00947 demagButton.setEnabled(false);
00948 }
00949 }
00950
00954 public void setEnabled() {
00955 setProject(this.project);
00956 }
00957
00963 public void setProject(Project project) {
00964 this.project = project;
00965
00966 if (this.project == null) {
00967 setEnabled(false);
00968 } else {
00969 setEnabled(project.isManualControlEnabled());
00970 }
00971 }
00972 }
00973 }