public MainCitiesCriteriaPanel() {
    super(new BorderLayout());

    CountryController countryc = Application.getCountryController();
    CitiesController citiesc = Application.getCitiesController();
    countryName = Application.getCountryName();

    label = new JLabel();
    labelPanel = new JPanel();
    labelPanel.add(label);

    label.setText("Criteria to select main cities for " + countryName.replaceAll("_", " "));

    listModel = new DefaultListModel();

    Iterator<HashMap<String, String>> iter = citiesc.getToponymTypesIterator();
    while (iter.hasNext()) {
      String topTypeName = iter.next().get("code");
      listModel.addElement(topTypeName);
    }
    list = new JList(listModel);
    list.addListSelectionListener(this);
    listPanel = new JScrollPane(list);

    NumberFormat nCitiesFormat = NumberFormat.getInstance();
    nCitiesFormat.setMaximumFractionDigits(0);
    nCitiesFormat.setMaximumIntegerDigits(4);

    NumberFormat distFormat = NumberFormat.getInstance();
    distFormat.setMaximumFractionDigits(0);
    distFormat.setMaximumIntegerDigits(3);

    nCitiesField = new JFormattedTextField(nCitiesFormat);
    distField = new JFormattedTextField(distFormat);

    nCitiesField.setMaximumSize(new Dimension(50, 1));
    distField.setMaximumSize(new Dimension(50, 1));

    rb1 = new JRadioButton("Filter by type", true);
    rb2 = new JRadioButton("Filter by number", false);
    rb3 = new JRadioButton("Filter by distance to the borders (km)", false);

    ButtonGroup bgroup = new ButtonGroup();

    bgroup.add(rb1);
    bgroup.add(rb2);
    bgroup.add(rb3);

    JPanel radioPanel = new JPanel();

    radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.Y_AXIS));
    radioPanel.add(rb1);
    radioPanel.add(listPanel);
    radioPanel.add(rb2);
    radioPanel.add(nCitiesField);
    radioPanel.add(rb3);
    radioPanel.add(distField);

    submit = new JButton();
    back = new JButton();

    submit.setText("OK");
    back.setText("GO BACK");
    submit.addActionListener(this);
    back.addActionListener(this);

    buttonPanel = new JPanel();
    buttonPanel.add(back);
    buttonPanel.add(submit);

    add(labelPanel, BorderLayout.NORTH);
    add(radioPanel, BorderLayout.CENTER);
    add(buttonPanel, BorderLayout.SOUTH);
  }
コード例 #2
0
  private void addInformationPanel() {
    // Create UI elements for connection information.
    JPanel informationPanel = new JPanel();
    informationPanel.setLayout(new BorderLayout());

    // Add the Host information
    JPanel connPanel = new JPanel();
    connPanel.setLayout(new GridBagLayout());
    connPanel.setBorder(BorderFactory.createTitledBorder("Connection information"));

    JLabel label = new JLabel("Host: ");
    label.setMinimumSize(new java.awt.Dimension(150, 14));
    label.setMaximumSize(new java.awt.Dimension(150, 14));
    connPanel.add(
        label, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
    JFormattedTextField field = new JFormattedTextField(connection.getServiceName());
    field.setMinimumSize(new java.awt.Dimension(150, 20));
    field.setMaximumSize(new java.awt.Dimension(150, 20));
    field.setEditable(false);
    field.setBorder(null);
    connPanel.add(
        field, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));

    // Add the Port information
    label = new JLabel("Port: ");
    label.setMinimumSize(new java.awt.Dimension(150, 14));
    label.setMaximumSize(new java.awt.Dimension(150, 14));
    connPanel.add(
        label, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
    field = new JFormattedTextField(connection.getPort());
    field.setMinimumSize(new java.awt.Dimension(150, 20));
    field.setMaximumSize(new java.awt.Dimension(150, 20));
    field.setEditable(false);
    field.setBorder(null);
    connPanel.add(
        field, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));

    // Add the connection's User information
    label = new JLabel("User: "******"Creation time: ");
    label.setMinimumSize(new java.awt.Dimension(150, 14));
    label.setMaximumSize(new java.awt.Dimension(150, 14));
    connPanel.add(
        label, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
    field = new JFormattedTextField(new SimpleDateFormat("yyyy.MM.dd hh:mm:ss:SS aaa"));
    field.setMinimumSize(new java.awt.Dimension(150, 20));
    field.setMaximumSize(new java.awt.Dimension(150, 20));
    field.setValue(creationTime);
    field.setEditable(false);
    field.setBorder(null);
    connPanel.add(
        field, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));

    // Add the connection's creationTime information
    label = new JLabel("Status: ");
    label.setMinimumSize(new java.awt.Dimension(150, 14));
    label.setMaximumSize(new java.awt.Dimension(150, 14));
    connPanel.add(
        label, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
    statusField = new JFormattedTextField();
    statusField.setMinimumSize(new java.awt.Dimension(150, 20));
    statusField.setMaximumSize(new java.awt.Dimension(150, 20));
    statusField.setValue("Active");
    statusField.setEditable(false);
    statusField.setBorder(null);
    connPanel.add(
        statusField,
        new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
    // Add the connection panel to the information panel
    informationPanel.add(connPanel, BorderLayout.NORTH);

    // Add the Number of sent packets information
    JPanel packetsPanel = new JPanel();
    packetsPanel.setLayout(new GridLayout(1, 1));
    packetsPanel.setBorder(BorderFactory.createTitledBorder("Transmitted Packets"));

    statisticsTable =
        new DefaultTableModel(
            new Object[][] {
              {"IQ", 0, 0}, {"Message", 0, 0}, {"Presence", 0, 0}, {"Other", 0, 0}, {"Total", 0, 0}
            },
            new Object[] {"Type", "Received", "Sent"}) {
          private static final long serialVersionUID = -6793886085109589269L;

          public boolean isCellEditable(int rowIndex, int mColIndex) {
            return false;
          }
        };
    JTable table = new JTable(statisticsTable);
    // Allow only single a selection
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    packetsPanel.add(new JScrollPane(table));

    // Add the packets panel to the information panel
    informationPanel.add(packetsPanel, BorderLayout.CENTER);

    tabbedPane.add("Information", new JScrollPane(informationPanel));
    tabbedPane.setToolTipTextAt(4, "Information and statistics about the debugged connection");
  }
コード例 #3
0
ファイル: BeamOrbitFace.java プロジェクト: kritha/MyOpenXal
  /** 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;
  }