Exemplo n.º 1
0
  public HelpPanel(final Module module) {
    this.module = module;

    miniHelpBtn = new JButton(showHelpStr);
    megaHelpBtn = new JButton(megaHelpStr);

    SwingUtils.fixButtonOpacity(miniHelpBtn);
    SwingUtils.fixButtonOpacity(megaHelpBtn);

    // Hook up listeners to the buttons that will tell the
    // module what help to show, if any
    miniHelpBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            miniHelpShowing = !miniHelpShowing;

            // If there is no megahelp, don't show the megahelp button
            if (miniHelpShowing) {
              setTwoButtonMode();
            } else {
              setOneButtonMode();
            }
            module.setHelpEnabled(miniHelpShowing);
            // Synchronize the Help menu item.
            PhetApplication.getInstance()
                .getPhetFrame()
                .getHelpMenu()
                .setHelpSelected(miniHelpShowing);
          }
        });
    megaHelpBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            module.showMegaHelp();
          }
        });

    add(miniHelpBtn);
    add(megaHelpBtn);
    layoutPanel();
    setOneButtonMode();
  }
Exemplo n.º 2
0
  /**
   * @param min
   * @param max
   * @param textFieldFormat
   * @param units
   * @param initialValue
   * @param title
   */
  private void init(
      final double min,
      final double max,
      NumberFormat textFieldFormat,
      NumberFormat sliderLabelFormat,
      String units,
      double initialValue,
      String title) {

    // In case this has been called in response to a change in some characteristic, remove all the
    // items in the
    // control
    while (getComponentCount() > 0) {
      this.remove(getComponent(0));
    }

    this.title = title;
    this.min = min;
    this.max = max;
    this.textFieldFormat = textFieldFormat;
    this.sliderLabelFormat = sliderLabelFormat;
    this.units = units;
    this.modelViewTransform = new ModelViewTransform1D(min, max, SLIDER_MIN, SLIDER_MAX);
    this.initialValue = initialValue;
    numMajorTicks = 5;
    int numMinorsPerMajor = 2;
    numMinorTicks = (numMajorTicks - 1) * numMinorsPerMajor + 1;

    setLayout(new GridBagLayout());
    setBorder(BorderFactory.createEtchedBorder());
    createTextField();
    textField.setHorizontalAlignment(JTextField.RIGHT);

    createSlider();

    titleLabel =
        new JLabel(title) {
          protected void paintComponent(Graphics g) {
            // added antialias for the ModelSlider title
            ((Graphics2D) g)
                .setRenderingHint(
                    RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            super.paintComponent(g);
          }
        };
    titleLabel.setFont(titleFont);

    unitsReadout = new JTextField(" " + this.units);
    unitsReadout.setFocusable(false);
    unitsReadout.setEditable(false);
    unitsReadout.setBorder(null);

    textPanel = new JPanel();
    textPanel.setLayout(new BorderLayout());
    textPanel.add(textField, BorderLayout.WEST);
    textPanel.add(unitsReadout, BorderLayout.EAST);
    try {
      SwingUtils.addGridBagComponent(
          this, titleLabel, 0, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER);
      SwingUtils.addGridBagComponent(
          this, slider, 0, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER);
      SwingUtils.addGridBagComponent(
          this, textPanel, 0, 2, 2, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER);
    } catch (AWTException e) {
      throw new RuntimeException(e);
    }
    setValue(initialValue);
  }