public Controls(EPGSwingEngine swingEngine) {
    _playButton = (JToggleButton) swingEngine.find("PLAY_BUTTON");
    _playButton.addActionListener(this);

    _allNotesOffButton = (JButton) swingEngine.find("ALL_NOTES_OFF_BUTTON");
    _allNotesOffButton.addActionListener(this);

    _tempoSlider = (JSlider) swingEngine.find("TEMPO_SLIDER");
    _tempoSlider.addChangeListener(this);

    _tempoInput = (JFormattedTextField) swingEngine.find("TEMPO_INPUT");
    _tempoInput.setPreferredSize(new Dimension(60, _tempoInput.getPreferredSize().height));
    _tempoInput.addActionListener(this);

    _midiOutBox = (JComboBox) swingEngine.find("MIDI_OUT_BOX");
    _midiOutBox.addActionListener(this);

    _midiCheckBox = (JCheckBox) swingEngine.find("MIDI_CHECKBOX");
    _midiCheckBox.addActionListener(this);

    _oscTextField = (JTextField) swingEngine.find("OSC_TEXTFIELD");
    _oscTextField.addActionListener(this);

    _oscCheckBox = (JCheckBox) swingEngine.find("OSC_CHECKBOX");
    _oscCheckBox.addActionListener(this);
  }
Esempio n. 2
0
  private void createZoomTextField() {
    mZoomTextField = new JFormattedTextField(new DecimalFormat("##0.00%"));
    mZoomTextField.setFocusLostBehavior(JFormattedTextField.REVERT);
    mZoomTextField.setHorizontalAlignment(SwingConstants.CENTER);
    mZoomTextField.setColumns(6);
    mZoomTextField.setMinimumSize(mZoomTextField.getPreferredSize());

    mZoomTextField.addActionListener(
        (x) -> mImagePresentationModel.setZoom(((Number) mZoomTextField.getValue()).doubleValue()));

    mImagePresentationModel.addListener(
        new ImagePresentationModel.Listener() {
          @Override
          public void onVisibleImageContentUpdate() {
            mZoomTextField.setValue(mImagePresentationModel.getZoom());
          }

          @Override
          public void onImageChange() {
            onVisibleImageContentUpdate();
          }
        });
  }
Esempio n. 3
0
  /** make the view for this face */
  protected Component makeView() {
    final Box mainBox = new Box(BoxLayout.Y_AXIS);

    final JTable bpmTable = new JTable(BPM_TABLE_MODEL);

    final JSplitPane mainSplitPane =
        new JSplitPane(
            JSplitPane.VERTICAL_SPLIT, new JScrollPane(bpmTable), TARGET_PLOT.getPlotPanel());
    final Box mainSplitBox = new Box(BoxLayout.X_AXIS);
    mainSplitBox.add(mainSplitPane);
    mainBox.add(mainSplitBox);
    mainSplitPane.setOneTouchExpandable(true);
    mainSplitPane.addAncestorListener(
        new AncestorListener() {
          public void ancestorAdded(final AncestorEvent event) {
            // only set the divider location the first time it becomes visible
            if (mainSplitPane.getClientProperty("initialized") == null) {
              mainSplitPane.setDividerLocation(0.4);
              mainSplitPane.putClientProperty("initialized", true);
            }
          }

          public void ancestorRemoved(final AncestorEvent event) {}

          public void ancestorMoved(final AncestorEvent event) {}
        });

    final Box targetBox = new Box(BoxLayout.X_AXIS);
    mainBox.add(targetBox);
    targetBox.setBorder(BorderFactory.createTitledBorder("Target Beam Position"));

    final java.text.NumberFormat TARGET_NUMBER_FORMAT = new DecimalFormat("#,##0.0");
    final int NUMBER_WIDTH = 6;

    targetBox.add(new JLabel("X (mm):"));
    final JFormattedTextField xTargetField = new JFormattedTextField(TARGET_NUMBER_FORMAT);
    xTargetField.setToolTipText("Matching Target horizontal beam position");
    xTargetField.setEditable(false);
    xTargetField.setHorizontalAlignment(JTextField.RIGHT);
    xTargetField.setColumns(NUMBER_WIDTH);
    xTargetField.setMaximumSize(xTargetField.getPreferredSize());
    targetBox.add(xTargetField);

    targetBox.add(new JLabel("+/-"));
    final JFormattedTextField xTargetErrorField = new JFormattedTextField(TARGET_NUMBER_FORMAT);
    xTargetErrorField.setToolTipText("Estimated horizontal target beam position error.");
    xTargetErrorField.setEditable(false);
    xTargetErrorField.setHorizontalAlignment(JTextField.RIGHT);
    xTargetErrorField.setColumns(NUMBER_WIDTH);
    xTargetErrorField.setMaximumSize(xTargetErrorField.getPreferredSize());
    targetBox.add(xTargetErrorField);
    targetBox.add(Box.createHorizontalGlue());

    targetBox.add(new JLabel("Y (mm):"));
    final JFormattedTextField yTargetField = new JFormattedTextField(TARGET_NUMBER_FORMAT);
    yTargetField.setToolTipText("Matching Target vertical beam position");
    yTargetField.setEditable(false);
    yTargetField.setHorizontalAlignment(JTextField.RIGHT);
    yTargetField.setColumns(NUMBER_WIDTH);
    yTargetField.setMaximumSize(yTargetField.getPreferredSize());
    targetBox.add(yTargetField);

    targetBox.add(new JLabel("+/-"));
    final JFormattedTextField yTargetErrorField = new JFormattedTextField(TARGET_NUMBER_FORMAT);
    yTargetErrorField.setToolTipText("Estimated vertical target beam position error.");
    yTargetErrorField.setEditable(false);
    yTargetErrorField.setHorizontalAlignment(JTextField.RIGHT);
    yTargetErrorField.setColumns(NUMBER_WIDTH);
    yTargetErrorField.setMaximumSize(yTargetErrorField.getPreferredSize());
    targetBox.add(yTargetErrorField);
    targetBox.add(Box.createHorizontalGlue());

    final JButton clearButton = new JButton("Clear");
    clearButton.setToolTipText("Clear results and running average BPM statistics.");
    targetBox.add(clearButton);
    clearButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent event) {
            TARGET_PLOT.clear();
            clearBeamPositionRunningAverage();
            xTargetField.setValue(null);
            xTargetErrorField.setValue(null);
            yTargetField.setValue(null);
            yTargetErrorField.setValue(null);
          }
        });

    final JButton startButton = new JButton("Start");
    startButton.setToolTipText("Start Beam Position Running Average after clearing it.");
    targetBox.add(startButton);
    startButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent event) {
            for (final BpmAgent bpmAgent : BPM_AGENTS) {
              bpmAgent.startAveraging(); // automatically clears the running average each time
            }
          }
        });

    final JButton stopButton = new JButton("Stop");
    stopButton.setToolTipText("Stop Beam Position Running Average.");
    targetBox.add(stopButton);
    stopButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent event) {
            stopRunningAverage();
          }
        });

    final JButton targetMatchButton = new JButton("Match");
    targetMatchButton.setToolTipText(
        "<html><body>Stop averaging the BPM beam position.<br>Match the target position to the BPM beam position data.</body></html>");
    targetBox.add(targetMatchButton);
    targetMatchButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent event) {
            try {
              stopButton.doClick();

              final List<BpmAgent> enabledBpmAgents = BPM_TABLE_MODEL.getEnabledBpmAgents();
              final List<BpmAgent> xBpmAgents = new ArrayList<BpmAgent>(enabledBpmAgents.size());
              final List<BpmAgent> yBpmAgents = new ArrayList<BpmAgent>(enabledBpmAgents.size());
              final StringBuffer warningsBuffer = new StringBuffer("");

              if (enabledBpmAgents.size() < 2) {
                warningsBuffer.append(
                    "Only " + enabledBpmAgents.size() + " are enabled for matching.\n");
              }

              // only include BPM agents with running average samples for at least one valid channel
              for (final BpmAgent bpmAgent : enabledBpmAgents) {
                if (bpmAgent.hasRunningAverageSamplesInValidPlanes()) {
                  if (bpmAgent.isXAvgChannelValid()) {
                    xBpmAgents.add(bpmAgent);
                  } else {
                    warningsBuffer.append(
                        "Warning: Enabled BPM, "
                            + bpmAgent.name()
                            + " has an invalid X Avg channel, "
                            + bpmAgent.getXAvgChannel().channelName()
                            + " which will be exluded from analysis.\n");
                  }

                  if (bpmAgent.isYAvgChannelValid()) {
                    yBpmAgents.add(bpmAgent);
                  } else {
                    warningsBuffer.append(
                        "Warning: Enabled BPM, "
                            + bpmAgent.name()
                            + " has an invalid Y Avg channel, "
                            + bpmAgent.getYAvgChannel().channelName()
                            + " which will be exluded from analysis.\n");
                  }
                } else if (!bpmAgent.hasValidPlane()) {
                  warningsBuffer.append(
                      "Warning: Ignoring BPM, "
                          + bpmAgent.name()
                          + " because it has no valid X or Y channel.\n");
                } else {
                  warningsBuffer.append(
                      "Warning: Ignoring BPM, "
                          + bpmAgent.name()
                          + " because it has no samples in a valid channel.\n");
                }
              }

              // always post warnings to the console
              final String warningsMessage = warningsBuffer.toString();
              if (warningsMessage != null && warningsMessage.length() > 0) {
                System.out.print(warningsBuffer.toString());
              }

              // to match both X and Y, at least two BPMs must be valid for each of X and Y channels
              if (xBpmAgents.size() < 2 || yBpmAgents.size() < 2) {
                DOCUMENT.displayError(
                    "Matching Error",
                    "You must choose at least 2 BPMs that have valid channels for each plane.\n"
                        + warningsBuffer.toString());
                return;
              }

              if (_beamPositionMatcher == null) {
                _beamPositionMatcher = new TargetBeamPositionMatcher(RTBT_SEQUENCE);
              }
              final BeamPosition targetBeamPosition =
                  _beamPositionMatcher.getMatchingTargetBeamPosition(xBpmAgents, yBpmAgents);
              xTargetField.setValue(targetBeamPosition.X);
              xTargetErrorField.setValue(targetBeamPosition.X_RMS_ERROR);
              yTargetField.setValue(targetBeamPosition.Y);
              yTargetErrorField.setValue(targetBeamPosition.Y_RMS_ERROR);

              // update the main document so the values can be shared elsewhere
              DOCUMENT.xpos = targetBeamPosition.X;
              DOCUMENT.ypos = targetBeamPosition.Y;

              TARGET_PLOT.displayBeamPosition(
                  targetBeamPosition.X,
                  targetBeamPosition.Y,
                  targetBeamPosition.X_RMS_ERROR,
                  targetBeamPosition.Y_RMS_ERROR);
            } catch (Exception exception) {
              exception.printStackTrace();
              JOptionPane.showMessageDialog(
                  FACE_VIEW,
                  exception.getMessage(),
                  "Error matching target beam position.",
                  JOptionPane.ERROR_MESSAGE);
            }
          }
        });

    final JButton copyReportButton = new JButton("Report");
    copyReportButton.setToolTipText("Copy a report to the clipboard.");
    targetBox.add(copyReportButton);
    copyReportButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent event) {
            final StringBuffer reportBuffer = new StringBuffer("Target Beam Position Report\n");
            reportBuffer.append(
                "Date:\t" + new SimpleDateFormat("MMM dd, yyyy HH:mm:ss").format(new Date()));
            reportBuffer.append("\n");
            reportBuffer.append("BPM Data:\n");
            BPM_TABLE_MODEL.appendReport(reportBuffer);
            reportBuffer.append(
                "Matching Target X (mm):\t"
                    + xTargetField.getText()
                    + "\t+/-\t"
                    + xTargetErrorField.getText()
                    + "\n");
            reportBuffer.append(
                "Matching Target Y (mm):\t"
                    + yTargetField.getText()
                    + "\t+/-\t"
                    + yTargetErrorField.getText()
                    + "\n");

            final String report = reportBuffer.toString();
            final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            final StringSelection contents = new StringSelection(report);
            clipboard.setContents(contents, contents);
          }
        });

    return mainBox;
  }