Пример #1
0
    protected void initComponents(
        AirspaceBuilderModel model, final AirspaceBuilderController controller) {
      final JCheckBox resizeNewShapesCheckBox;
      final JCheckBox enableEditCheckBox;

      JPanel newShapePanel = new JPanel();
      {
        JButton newShapeButton = new JButton("New shape");
        newShapeButton.setActionCommand(NEW_AIRSPACE);
        newShapeButton.addActionListener(controller);
        newShapeButton.setToolTipText("Create a new shape centered in the viewport");

        this.factoryComboBox = new JComboBox(defaultAirspaceFactories);
        this.factoryComboBox.setEditable(false);
        this.factoryComboBox.setToolTipText("Choose shape type to create");

        resizeNewShapesCheckBox = new JCheckBox("Fit new shapes to viewport");
        resizeNewShapesCheckBox.setActionCommand(SIZE_NEW_SHAPES_TO_VIEWPORT);
        resizeNewShapesCheckBox.addActionListener(controller);
        resizeNewShapesCheckBox.setSelected(controller.isResizeNewShapesToViewport());
        resizeNewShapesCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT);
        resizeNewShapesCheckBox.setToolTipText(
            "New shapes are sized to fit the geographic viewport");

        enableEditCheckBox = new JCheckBox("Enable shape editing");
        enableEditCheckBox.setActionCommand(ENABLE_EDIT);
        enableEditCheckBox.addActionListener(controller);
        enableEditCheckBox.setSelected(controller.isEnableEdit());
        enableEditCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT);
        enableEditCheckBox.setToolTipText("Allow modifications to shapes");

        Box newShapeBox = Box.createHorizontalBox();
        newShapeBox.add(newShapeButton);
        newShapeBox.add(Box.createHorizontalStrut(5));
        newShapeBox.add(this.factoryComboBox);
        newShapeBox.setAlignmentX(Component.LEFT_ALIGNMENT);

        JPanel gridPanel = new JPanel(new GridLayout(0, 1, 0, 5)); // rows, cols, hgap, vgap
        gridPanel.add(newShapeBox);
        gridPanel.add(resizeNewShapesCheckBox);
        gridPanel.add(enableEditCheckBox);

        newShapePanel.setLayout(new BorderLayout());
        newShapePanel.add(gridPanel, BorderLayout.NORTH);
      }

      JPanel entryPanel = new JPanel();
      {
        this.entryTable = new JTable(model);
        this.entryTable.setColumnSelectionAllowed(false);
        this.entryTable.setRowSelectionAllowed(true);
        this.entryTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        this.entryTable
            .getSelectionModel()
            .addListSelectionListener(
                new ListSelectionListener() {
                  public void valueChanged(ListSelectionEvent e) {
                    if (!ignoreSelectEvents) {
                      controller.actionPerformed(
                          new ActionEvent(e.getSource(), -1, SELECTION_CHANGED));
                    }
                  }
                });
        this.entryTable.setToolTipText("<html>Click to select<br>Double-Click to rename</html>");

        JScrollPane tablePane = new JScrollPane(this.entryTable);
        tablePane.setPreferredSize(new Dimension(200, 100));

        entryPanel.setLayout(new BorderLayout(0, 0)); // hgap, vgap
        entryPanel.add(tablePane, BorderLayout.CENTER);
      }

      JPanel selectionPanel = new JPanel();
      {
        JButton delselectButton = new JButton("Deselect");
        delselectButton.setActionCommand(CLEAR_SELECTION);
        delselectButton.addActionListener(controller);
        delselectButton.setToolTipText("Clear the selection");

        JButton deleteButton = new JButton("Delete Selected");
        deleteButton.setActionCommand(REMOVE_SELECTED);
        deleteButton.addActionListener(controller);
        deleteButton.setToolTipText("Delete selected shapes");

        JPanel gridPanel = new JPanel(new GridLayout(0, 1, 0, 5)); // rows, cols, hgap, vgap
        gridPanel.add(delselectButton);
        gridPanel.add(deleteButton);

        selectionPanel.setLayout(new BorderLayout());
        selectionPanel.add(gridPanel, BorderLayout.NORTH);
      }

      this.setLayout(new BorderLayout(30, 0)); // hgap, vgap
      this.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); // top, left, bottom, right
      this.add(newShapePanel, BorderLayout.WEST);
      this.add(entryPanel, BorderLayout.CENTER);
      this.add(selectionPanel, BorderLayout.EAST);

      controller.addPropertyChangeListener(
          new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent e) {
              if (SIZE_NEW_SHAPES_TO_VIEWPORT.equals(e.getPropertyName())) {
                resizeNewShapesCheckBox.setSelected(controller.isResizeNewShapesToViewport());
              } else if (ENABLE_EDIT.equals(e.getPropertyName())) {
                enableEditCheckBox.setSelected(controller.isEnableEdit());
              }
            }
          });
    }
Пример #2
0
    private void makePanel(Dimension size) {
      JPanel buttonPanel = new JPanel(new GridLayout(1, 2, 5, 5));
      newButton = new JButton("New");
      newButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
              lineBuilder.clear();
              lineBuilder.setArmed(true);
              pauseButton.setText("Pause");
              pauseButton.setEnabled(true);
              endButton.setEnabled(true);
              newButton.setEnabled(false);
              ((Component) wwd).setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
            }
          });
      buttonPanel.add(newButton);
      newButton.setEnabled(true);

      pauseButton = new JButton("Pause");
      pauseButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
              lineBuilder.setArmed(!lineBuilder.isArmed());
              pauseButton.setText(!lineBuilder.isArmed() ? "Resume" : "Pause");
              ((Component) wwd).setCursor(Cursor.getDefaultCursor());
            }
          });
      buttonPanel.add(pauseButton);
      pauseButton.setEnabled(false);

      endButton = new JButton("End");
      endButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
              lineBuilder.setArmed(false);
              newButton.setEnabled(true);
              pauseButton.setEnabled(false);
              pauseButton.setText("Pause");
              endButton.setEnabled(false);
              ((Component) wwd).setCursor(Cursor.getDefaultCursor());
            }
          });
      buttonPanel.add(endButton);
      endButton.setEnabled(false);

      JPanel pointPanel = new JPanel(new GridLayout(0, 1, 0, 10));
      pointPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

      this.pointLabels = new JLabel[20];
      for (int i = 0; i < this.pointLabels.length; i++) {
        this.pointLabels[i] = new JLabel("");
        pointPanel.add(this.pointLabels[i]);
      }

      // Put the point panel in a container to prevent scroll panel from stretching the vertical
      // spacing.
      JPanel dummyPanel = new JPanel(new BorderLayout());
      dummyPanel.add(pointPanel, BorderLayout.NORTH);

      // Put the point panel in a scroll bar.
      JScrollPane scrollPane = new JScrollPane(dummyPanel);
      scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
      if (size != null) scrollPane.setPreferredSize(size);

      // Add the buttons, scroll bar and inner panel to a titled panel that will resize with the
      // main window.
      JPanel outerPanel = new JPanel(new BorderLayout());
      outerPanel.setBorder(
          new CompoundBorder(
              BorderFactory.createEmptyBorder(9, 9, 9, 9), new TitledBorder("Line")));
      outerPanel.setToolTipText("Line control and info");
      outerPanel.add(buttonPanel, BorderLayout.NORTH);
      outerPanel.add(scrollPane, BorderLayout.CENTER);
      this.add(outerPanel, BorderLayout.CENTER);
    }