Пример #1
0
  protected void attachTo(Component jc) {
    if (extListener != null && extListener.accept(jc)) {
      extListener.startListeningTo(jc, extNotifier);
      listenedTo.add(jc);
      if (wizardPage.getMapKeyFor(jc) != null) {
        wizardPage.maybeUpdateMap(jc);
      }
      return;
    }
    if (isProbablyAContainer(jc)) {
      attachToHierarchyOf((Container) jc);
    } else if (jc instanceof JList) {
      listenedTo.add(jc);
      ((JList) jc).addListSelectionListener(this);
    } else if (jc instanceof JComboBox) {
      ((JComboBox) jc).addActionListener(this);
    } else if (jc instanceof JTree) {
      listenedTo.add(jc);
      ((JTree) jc).getSelectionModel().addTreeSelectionListener(this);
    } else if (jc instanceof JToggleButton) {
      ((AbstractButton) jc).addItemListener(this);
    } else if (jc
        instanceof JFormattedTextField) { // JFormattedTextField must be tested before JTextCompoent
      jc.addPropertyChangeListener("value", this);
    } else if (jc instanceof JTextComponent) {
      listenedTo.add(jc);
      ((JTextComponent) jc).getDocument().addDocumentListener(this);
    } else if (jc instanceof JColorChooser) {
      listenedTo.add(jc);
      ((JColorChooser) jc).getSelectionModel().addChangeListener(this);
    } else if (jc instanceof JSpinner) {
      ((JSpinner) jc).addChangeListener(this);
    } else if (jc instanceof JSlider) {
      ((JSlider) jc).addChangeListener(this);
    } else if (jc instanceof JTable) {
      listenedTo.add(jc);
      ((JTable) jc).getSelectionModel().addListSelectionListener(this);
    } else {
      if (logger.isLoggable(Level.FINE)) {
        logger.fine(
            "Don't know how to listen to a "
                + // NOI18N
                jc.getClass().getName());
      }
    }

    if (accept(jc) && !(jc instanceof JPanel)) {
      jc.addPropertyChangeListener("name", this);
      if (wizardPage.getMapKeyFor(jc) != null) {
        wizardPage.maybeUpdateMap(jc);
      }
    }

    if (logger.isLoggable(Level.FINE) && accept(jc)) {
      logger.fine("Begin listening to " + jc); // NOI18N
    }
  }
Пример #2
0
  /**
   * Initializes the layout of this <code>GroupBox</code>.
   *
   * @param buttons The buttons to be shown at the top-left section of the group box
   * @param panes The panes to be shown as a group where a button is shown as a pane's title
   */
  protected void initializeLayout(AbstractButton[] buttons, JComponent[] panes) {
    checkIntegrity(buttons, panes);

    GridBagConstraints constraints = new GridBagConstraints();

    for (int index = 0; index < buttons.length; index++) {
      boolean paneWasAddedBefore = ((index > 0) && (panes[index - 1] != NO_PANE));

      // First add the button
      AbstractButton button = buttons[index];
      button.setOpaque(false); // Requires to paint the titled border properly
      button.setBorder(
          BorderFactory.createCompoundBorder(
              BorderFactory.createEmptyBorder(0, 5, 0, 0), button.getBorder()));

      if (panes[index] != NO_PANE) {
        button.addItemListener(buildRepainterHandler());
      }

      constraints.gridx = 0;
      constraints.gridy = index;
      constraints.gridwidth = 1;
      constraints.gridheight = 1;
      constraints.weightx = 0;
      constraints.weighty = 0;
      constraints.fill = GridBagConstraints.NONE;
      constraints.anchor = GridBagConstraints.FIRST_LINE_START;
      constraints.insets = new Insets(paneWasAddedBefore ? 5 : 0, 0, 0, 0);

      add(button, constraints);

      // Now add the pane if one is associated with the button
      JComponent pane = panes[index];

      if (pane != NO_PANE) {
        boolean fillVertical = shouldFillVertical(pane);
        int top = button.getPreferredSize().height / 2 - 6;

        pane.setBorder(
            BorderFactory.createCompoundBorder(createPaneBorder(button, pane), pane.getBorder()));

        constraints.gridx = 0;
        constraints.gridy = index;
        constraints.gridwidth = 1;
        constraints.gridheight = 1;
        constraints.weightx = 1;
        constraints.weighty = fillVertical ? 1 : 0;
        constraints.fill = fillVertical ? GridBagConstraints.BOTH : GridBagConstraints.HORIZONTAL;
        constraints.anchor = GridBagConstraints.CENTER;
        constraints.insets = new Insets(paneWasAddedBefore ? top + 5 : top, 0, 0, 0);

        add(pane, constraints);
      }
    }
  }
Пример #3
0
    public ButtonConfigBinding(
        String property, PrefsConfig config, AbstractButton button, boolean defval) {
      _property = property;
      _config = config;
      _button = button;
      _defval = defval;

      // wire ourselves up to the button
      button.addAncestorListener(this);
      button.addItemListener(this);

      // if this is not already a toggle button, we'll need to make
      // it toggle
      if (!(button instanceof JToggleButton)) {
        setToggling(button);
      }
    }
Пример #4
0
  /**
   * Adds the given NamedMediaType.
   *
   * <p>Marks the 'Any Type' as selected.
   */
  private void addMediaType(NamedMediaType type, String toolTip) {
    Icon icon = type.getIcon();
    Icon disabledIcon = null;
    Icon rolloverIcon = null;
    AbstractButton button = new JRadioButton(type.getName());
    button.putClientProperty(MEDIA, type);
    button.putClientProperty(SELECTED, icon);
    if (icon != null) {
      disabledIcon = ImageManipulator.darken(icon);
      rolloverIcon = ImageManipulator.brighten(icon);
    }
    button.putClientProperty(DESELECTED, disabledIcon);
    button.setIcon(disabledIcon);
    button.setRolloverIcon(rolloverIcon);
    button.addItemListener(HIGHLIGHTER);
    button.setBorderPainted(false);
    button.setFocusPainted(false);
    button.setContentAreaFilled(false);
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setOpaque(false);
    button.addMouseListener(CLICK_FORWARDER);
    button.setPreferredSize(new Dimension(100, 22));
    if (toolTip != null) {
      button.setToolTipText(toolTip);
    }
    GROUP.add(button);

    DitherPanel panel = new DitherPanel(DITHERER);
    panel.setDithering(false);
    panel.setLayout(new FlowLayout(FlowLayout.LEFT, 7, 1));
    panel.add(button);
    panel.addMouseListener(CLICK_FORWARDER);
    panel.setBackground(UIManager.getColor("TabbedPane.background"));
    SCHEMAS.add(panel);

    if (type.getMediaType() == MediaType.getAnyTypeMediaType()) button.setSelected(true);
    else button.setSelected(false);
  }
  public HexagonViewerAdvance(String[] args) {
    FormPanel panel = new FormPanel("ise/ct/plugins/HexagonViewerForm.jfrm");
    super.add(panel);

    // add references to configurable components on form
    worldMap = panel.getComponentByName("HexagonViewerImage");

    statusTitle = panel.getComponentByName("StatusTitle");
    fileTitle = panel.getLabel("FileTitle");
    fileProgress = panel.getProgressBar("FileProgress");
    iterationTitle = panel.getLabel("IterationTitle");
    iterationProgress = panel.getProgressBar("IterationProgress");
    cycleTitle = panel.getLabel("CycleTitle");
    cycleProgress = panel.getProgressBar("CycleProgress");

    currentTitle = panel.getComponentByName("CurrentTitle");
    commentTitle = panel.getLabel("CommentTitle");
    commentLabel = panel.getLabel("CommentLabel");
    phaseTitle = panel.getLabel("PhaseTitle");
    phaseLabel = panel.getLabel("PhaseLabel");
    turnTitle = panel.getLabel("TurnTitle");
    turnProgress = panel.getProgressBar("TurnProgress");

    showPaths = panel.getCheckBox("ShowPaths");
    showPaths.setActionCommand("showpaths");
    showPaths.setSelected(true);
    doShowPaths = true;
    showPaths.addItemListener(this);

    playButton = panel.getButton("PlayButton");
    stepButton = panel.getButton("StepButton");
    endButton = panel.getButton("EndButton");
    playButton.setActionCommand("play");
    stepButton.setActionCommand("step");
    endButton.setActionCommand("end");
    playButton.addItemListener(this);
    stepButton.addItemListener(this);
    endButton.addItemListener(this);
    playButton.setEnabled(true);
    stepButton.setEnabled(true);
    endButton.setEnabled(true);

    playButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            JButton s = (JButton) ae.getSource();
            if (s.getText().equalsIgnoreCase("Pause")) {
              s.setText("Play");
              Simulator.controlPanel.paused = true;
              Simulator.controlPanel.step = false;
            } else {
              s.setText("Pause");
              Simulator.controlPanel.paused = false;
              Simulator.controlPanel.step = false;
            }
          }
        });

    stepButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            playButton.setText("Play");
            Simulator.controlPanel.paused = true;
            Simulator.controlPanel.step = true;
          }
        });

    endButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            Simulator.experimentLength = Simulator.cycle;
            Simulator.controlPanel.paused = false;
          }
        });

    cycleTitle = panel.getLabel("CycleTitle");
    phaseTitle = panel.getLabel("PhaseTitle");
    inspectorTitle = panel.getLabel("InspectorTitle");
    cycleProgress = panel.getProgressBar("CycleProgress");

    seperator1 = panel.getComponentByName("Seperator1");
    seperator2 = panel.getComponentByName("Seperator2");
    seperator3 = panel.getComponentByName("Seperator3");
    seperator4 = panel.getComponentByName("Seperator4");

    // inspector JScrollPane and JTree
    inspectorScrollPane = panel.getComponentByName("InspectorScrollPane");
    inspectorTree = new JTree();
    inspectorTree.setRowHeight(iconSize);
    inspectorTree.setCellRenderer(
        new DefaultTreeCellRenderer() {
          private static final long serialVersionUID = 1L;

          public Icon getLeafIcon() {
            Icon icon;
            if (this.getText().equals(AUCTION_NAME)) {
              icon = new ImageIcon(createAuctionIcon(iconSize, iconSize));
            } else {
              icon = new ImageIcon(createAgentIcon(this.getText(), iconSize, iconSize));
            }
            return icon;
          }
        });

    getRootPane().setDefaultButton((JButton) playButton);
    super.addComponentListener(this); // resize events etc.

    // set the parameters this frame
    setSize(600, 500);
    setLocation(200, 100);
    setTitle("Hexagon Viewer Advance");
    setVisible(true);
  }