コード例 #1
0
 /**
  * Creates a new <code>JProgressBar</code> with the specified range and orientation. The following
  * defaults are used:
  *
  * <p>
  *
  * <ul>
  *   <li><code>value</code>: <code>minimum</code>;
  * </ul>
  *
  * @param minimum the lower bound of the value range.
  * @param maximum the upper bound of the value range.
  * @param orientation the orientation ({@link #HORIZONTAL} or {@link #VERTICAL}).
  * @throws IllegalArgumentException if <code>orientation</code> is not one of the specified
  *     values.
  */
 public JProgressBar(int orientation, int minimum, int maximum) {
   model = new DefaultBoundedRangeModel(minimum, 0, minimum, maximum);
   if (orientation != HORIZONTAL && orientation != VERTICAL)
     throw new IllegalArgumentException(orientation + " is not a legal orientation");
   this.orientation = orientation;
   changeListener = createChangeListener();
   model.addChangeListener(changeListener);
   updateUI();
 }
コード例 #2
0
ファイル: JScrollBar.java プロジェクト: GregBowyer/Hotspot
  /**
   * Sets the model that handles the scrollbar's four fundamental properties: minimum, maximum,
   * value, extent.
   *
   * @see #getModel
   * @beaninfo bound: true expert: true description: The scrollbar's BoundedRangeModel.
   */
  public void setModel(BoundedRangeModel newModel) {
    Integer oldValue = null;
    BoundedRangeModel oldModel = model;
    if (model != null) {
      model.removeChangeListener(fwdAdjustmentEvents);
      oldValue = Integer.valueOf(model.getValue());
    }
    model = newModel;
    if (model != null) {
      model.addChangeListener(fwdAdjustmentEvents);
    }

    firePropertyChange("model", oldModel, model);

    if (accessibleContext != null) {
      accessibleContext.firePropertyChange(
          AccessibleContext.ACCESSIBLE_VALUE_PROPERTY, oldValue, new Integer(model.getValue()));
    }
  }
コード例 #3
0
ファイル: JSlider.java プロジェクト: CodeingBoy/Java8CN
  /**
   * Sets the {@code BoundedRangeModel} that handles the slider's three fundamental properties:
   * minimum, maximum, value.
   *
   * <p>Attempts to pass a {@code null} model to this method result in undefined behavior, and, most
   * likely, exceptions.
   *
   * @param newModel the new, {@code non-null} <code>BoundedRangeModel</code> to use
   * @see #getModel
   * @see BoundedRangeModel
   * @beaninfo bound: true description: The sliders BoundedRangeModel.
   */
  public void setModel(BoundedRangeModel newModel) {
    BoundedRangeModel oldModel = getModel();

    if (oldModel != null) {
      oldModel.removeChangeListener(changeListener);
    }

    sliderModel = newModel;

    if (newModel != null) {
      newModel.addChangeListener(changeListener);
    }

    if (accessibleContext != null) {
      accessibleContext.firePropertyChange(
          AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
          (oldModel == null ? null : Integer.valueOf(oldModel.getValue())),
          (newModel == null ? null : Integer.valueOf(newModel.getValue())));
    }

    firePropertyChange("model", oldModel, sliderModel);
  }
コード例 #4
0
ファイル: TerminalPanel.java プロジェクト: bitekas/jediterm
  public void init() {
    initFont();

    setUpClipboard();

    setPreferredSize(new Dimension(getPixelWidth(), getPixelHeight()));

    setFocusable(true);
    enableInputMethods(true);
    setDoubleBuffered(true);

    setFocusTraversalKeysEnabled(false);

    addMouseMotionListener(
        new MouseMotionAdapter() {
          @Override
          public void mouseDragged(final MouseEvent e) {
            if (!isLocalMouseAction(e)) {
              return;
            }

            final Point charCoords = panelToCharCoords(e.getPoint());

            if (mySelection == null) {
              // prevent unlikely case where drag started outside terminal panel
              if (mySelectionStartPoint == null) {
                mySelectionStartPoint = charCoords;
              }
              mySelection = new TerminalSelection(new Point(mySelectionStartPoint));
            }
            repaint();
            mySelection.updateEnd(charCoords);
            if (mySettingsProvider.copyOnSelect()) {
              handleCopy(false);
            }

            if (e.getPoint().y < 0) {
              moveScrollBar((int) ((e.getPoint().y) * SCROLL_SPEED));
            }
            if (e.getPoint().y > getPixelHeight()) {
              moveScrollBar((int) ((e.getPoint().y - getPixelHeight()) * SCROLL_SPEED));
            }
          }
        });

    addMouseWheelListener(
        new MouseWheelListener() {
          @Override
          public void mouseWheelMoved(MouseWheelEvent e) {
            if (isLocalMouseAction(e)) {
              int notches = e.getWheelRotation();
              moveScrollBar(notches);
            }
          }
        });

    addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(final MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
              if (e.getClickCount() == 1) {
                mySelectionStartPoint = panelToCharCoords(e.getPoint());
                mySelection = null;
                repaint();
              }
            }
          }

          @Override
          public void mouseReleased(final MouseEvent e) {
            requestFocusInWindow();
            repaint();
          }

          @Override
          public void mouseClicked(final MouseEvent e) {
            requestFocusInWindow();
            if (e.getButton() == MouseEvent.BUTTON1 && isLocalMouseAction(e)) {
              int count = e.getClickCount();
              if (count == 1) {
                // do nothing
              } else if (count == 2) {
                // select word
                final Point charCoords = panelToCharCoords(e.getPoint());
                Point start = SelectionUtil.getPreviousSeparator(charCoords, myTerminalTextBuffer);
                Point stop = SelectionUtil.getNextSeparator(charCoords, myTerminalTextBuffer);
                mySelection = new TerminalSelection(start);
                mySelection.updateEnd(stop);

                if (mySettingsProvider.copyOnSelect()) {
                  handleCopy(false);
                }
              } else if (count == 3) {
                // select line
                final Point charCoords = panelToCharCoords(e.getPoint());
                int startLine = charCoords.y;
                while (startLine > -getScrollBuffer().getLineCount()
                    && myTerminalTextBuffer.getLine(startLine - 1).isWrapped()) {
                  startLine--;
                }
                int endLine = charCoords.y;
                while (endLine < myTerminalTextBuffer.getHeight()
                    && myTerminalTextBuffer.getLine(endLine).isWrapped()) {
                  endLine++;
                }
                mySelection = new TerminalSelection(new Point(0, startLine));
                mySelection.updateEnd(new Point(myTermSize.width, endLine));

                if (mySettingsProvider.copyOnSelect()) {
                  handleCopy(false);
                }
              }
            } else if (e.getButton() == MouseEvent.BUTTON2
                && mySettingsProvider.pasteOnMiddleMouseClick()
                && isLocalMouseAction(e)) {
              handlePaste();
            } else if (e.getButton() == MouseEvent.BUTTON3) {
              JPopupMenu popup = createPopupMenu();
              popup.show(e.getComponent(), e.getX(), e.getY());
            }
            repaint();
          }
        });

    addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentResized(final ComponentEvent e) {
            sizeTerminalFromComponent();
          }
        });

    addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(FocusEvent e) {
            myCursor.cursorChanged();
          }

          @Override
          public void focusLost(FocusEvent e) {
            myCursor.cursorChanged();
          }
        });

    myBoundedRangeModel.addChangeListener(
        new ChangeListener() {
          public void stateChanged(final ChangeEvent e) {
            myClientScrollOrigin = myBoundedRangeModel.getValue();
            repaint();
          }
        });

    createRepaintTimer();
  }
コード例 #5
0
 /**
  * Creates a new <code>JProgressBar</code> with the specified model. The following defaults are
  * used:
  *
  * <p>
  *
  * <ul>
  *   <li><code>orientation</code>: {@link SwingConstants#HORIZONTAL}.
  * </ul>
  *
  * @param model the model (<code>null</code> not permitted).
  */
 public JProgressBar(BoundedRangeModel model) {
   this.model = model;
   changeListener = createChangeListener();
   if (model != null) model.addChangeListener(changeListener);
   updateUI();
 }