Exemplo n.º 1
0
 public void stateChanged(ChangeEvent e) {
   Object obj = e.getSource();
   if (obj instanceof BoundedRangeModel) {
     int id = AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED;
     int type = AdjustmentEvent.TRACK;
     BoundedRangeModel model = (BoundedRangeModel) obj;
     int value = model.getValue();
     boolean isAdjusting = model.getValueIsAdjusting();
     fireAdjustmentValueChanged(id, type, value, isAdjusting);
   }
 }
Exemplo n.º 2
0
  /**
   * Sets the scrollbar's value. This method just forwards the value to the model.
   *
   * @see #getValue
   * @see BoundedRangeModel#setValue
   * @beaninfo preferred: true description: The scrollbar's current value.
   */
  public void setValue(int value) {
    BoundedRangeModel m = getModel();
    int oldValue = m.getValue();
    m.setValue(value);

    if (accessibleContext != null) {
      accessibleContext.firePropertyChange(
          AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
          Integer.valueOf(oldValue),
          Integer.valueOf(m.getValue()));
    }
  }
Exemplo n.º 3
0
  /**
   * Sets the model's valueIsAdjusting property. Scrollbar look and feel implementations should set
   * this property to true when a knob drag begins, and to false when the drag ends. The scrollbar
   * model will not generate ChangeEvents while valueIsAdjusting is true.
   *
   * @see #getValueIsAdjusting
   * @see BoundedRangeModel#setValueIsAdjusting
   * @beaninfo expert: true description: True if the scrollbar thumb is being dragged.
   */
  public void setValueIsAdjusting(boolean b) {
    BoundedRangeModel m = getModel();
    boolean oldValue = m.getValueIsAdjusting();
    m.setValueIsAdjusting(b);

    if ((oldValue != b) && (accessibleContext != null)) {
      accessibleContext.firePropertyChange(
          AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
          ((oldValue) ? AccessibleState.BUSY : null),
          ((b) ? AccessibleState.BUSY : null));
    }
  }
Exemplo n.º 4
0
  /**
   * Sets the four BoundedRangeModel properties after forcing the arguments to obey the usual
   * constraints:
   *
   * <pre>
   * minimum <= value <= value+extent <= maximum
   * </pre>
   *
   * <p>
   *
   * @see BoundedRangeModel#setRangeProperties
   * @see #setValue
   * @see #setVisibleAmount
   * @see #setMinimum
   * @see #setMaximum
   */
  public void setValues(int newValue, int newExtent, int newMin, int newMax) {
    BoundedRangeModel m = getModel();
    int oldValue = m.getValue();
    m.setRangeProperties(newValue, newExtent, newMin, newMax, m.getValueIsAdjusting());

    if (accessibleContext != null) {
      accessibleContext.firePropertyChange(
          AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
          Integer.valueOf(oldValue),
          Integer.valueOf(m.getValue()));
    }
  }
Exemplo n.º 5
0
 private void updateScrolling() {
   if (myScrollingEnabled) {
     myBoundedRangeModel.setRangeProperties(
         0,
         myTermSize.height,
         -myTerminalTextBuffer.getHistoryBuffer().getLineCount(),
         myTermSize.height,
         false);
   } else {
     myBoundedRangeModel.setRangeProperties(0, myTermSize.height, 0, myTermSize.height, false);
   }
 }
Exemplo n.º 6
0
 /**
  * This method sets the value, extent, minimum and maximum.
  *
  * @param newValue The new value.
  * @param newExtent The new extent.
  * @param newMin The new minimum.
  * @param newMax The new maximum.
  */
 public void setValues(int newValue, int newExtent, int newMin, int newMax) {
   if (!isEnabled()) newValue = model.getValue();
   // It seems to be that on any change the value is fired.
   if (newValue != getValue()
       || newExtent != getVisibleAmount()
       || newMin != getMinimum()
       || newMax != getMaximum()) {
     model.setRangeProperties(newValue, newExtent, newMin, newMax, model.getValueIsAdjusting());
     fireAdjustmentValueChanged(
         AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED, AdjustmentEvent.TRACK, newValue);
   }
 }
  /**
   * This determines the amount of the progress bar that should be filled based on the percent done
   * gathered from the model. This is a common operation so it was abstracted out. It assumes that
   * your progress bar is linear. That is, if you are making a circular progress indicator, you will
   * want to override this method.
   */
  protected int getAmountFull(Insets b, int width, int height) {
    int amountFull = 0;
    BoundedRangeModel model = progressBar.getModel();

    if ((model.getMaximum() - model.getMinimum()) != 0) {
      if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
        amountFull = (int) Math.round(width * progressBar.getPercentComplete());
      } else {
        amountFull = (int) Math.round(height * progressBar.getPercentComplete());
      }
    }
    return amountFull;
  }
Exemplo n.º 8
0
 /**
  * This method sets the visible amount (AKA extent).
  *
  * @param extent The visible amount (AKA extent).
  */
 public void setVisibleAmount(int extent) {
   if (extent != getVisibleAmount()) {
     model.setExtent(extent);
     fireAdjustmentValueChanged(
         AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED, AdjustmentEvent.TRACK, extent);
   }
 }
Exemplo n.º 9
0
 /**
  * This method sets the maximum value of the scrollbar.
  *
  * @param maximum The maximum value of the scrollbar.
  */
 public void setMaximum(int maximum) {
   if (maximum != getMaximum()) {
     model.setMaximum(maximum);
     fireAdjustmentValueChanged(
         AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED, AdjustmentEvent.TRACK, maximum);
   }
 }
 public synchronized void setPlayer(Player player) {
   if (this.player != null) {
     this.player.removeChangeListener(this);
     player.removePropertyChangeListener(this);
   }
   this.player = player;
   //        boundedRangeModel = player == null ? null : player.getBoundedRangeModel();
   boundedRangeModel = player == null ? null : player.getTimeModel();
   slider.setModel(boundedRangeModel);
   if (player != null) {
     if (player.getState() >= Player.REALIZED
         && boundedRangeModel != null
         && boundedRangeModel.getMaximum() == 0) {
       setPlayerControlsVisible(false);
     }
     slider.setProgressModel(player.getCachingModel());
     startButton.setSelected(player.isActive());
     player.addChangeListener(this);
     player.addPropertyChangeListener(this);
     audioButton.setVisible(player.isAudioAvailable());
     audioButton.setSelected(player.isAudioEnabled());
     colorCyclingButton.setVisible(
         (player instanceof ColorCyclePlayer)
             ? ((ColorCyclePlayer) player).isColorCyclingAvailable()
             : false);
     colorCyclingButton.setSelected(
         (player instanceof ColorCyclePlayer)
             ? ((ColorCyclePlayer) player).isColorCyclingStarted()
             : false);
     validate();
     repaint();
     BoundedRangeModel cachingControlModel = slider.getProgressModel();
   }
 }
Exemplo n.º 11
0
 /**
  * This method changes the value of the scrollbar.
  *
  * @param value The new value of the scrollbar.
  */
 public void setValue(int value) {
   if (isEnabled() && value != getValue()) {
     model.setValue(value);
     fireAdjustmentValueChanged(
         AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED, AdjustmentEvent.TRACK, value);
   }
 }
    // ChangeListener
    public void stateChanged(ChangeEvent e) {
      BoundedRangeModel model = progressBar.getModel();
      int newRange = model.getMaximum() - model.getMinimum();
      int newPercent;
      int oldPercent = getCachedPercent();

      if (newRange > 0) {
        newPercent = (int) ((100 * (long) model.getValue()) / newRange);
      } else {
        newPercent = 0;
      }

      if (newPercent != oldPercent) {
        setCachedPercent(newPercent);
        progressBar.repaint();
      }
    }
  public void actionPerformed(ActionEvent event) {
    Object source = event.getSource();
    if (boundedRangeModel != null) {
      int value = boundedRangeModel.getValue();
      if (source == forwardButton) {
        boundedRangeModel.setValue(
            value == boundedRangeModel.getMaximum() ? boundedRangeModel.getMinimum() : value + 1);
      } else if (source == rewindButton) {
        boundedRangeModel.setValue(
            value == boundedRangeModel.getMinimum() ? boundedRangeModel.getMaximum() : value - 1);
      } else if (source == startButton) {
        if (startButton.isSelected() != player.isActive()) {
          if (startButton.isSelected()) {
            player.start();
          } else {
            player.stop();
          }
        }
      } else if (source == audioButton) {

        player.setAudioEnabled(audioButton.isSelected());
      } else if (source == colorCyclingButton) {
        if (player instanceof ColorCyclePlayer) {
          ((ColorCyclePlayer) player).setColorCyclingStarted(colorCyclingButton.isSelected());
        }
      }
    }
  }
Exemplo n.º 14
0
 /**
  * Update the visibility model with the associated JTextField (if there is one) to reflect the
  * current visibility as a result of changes to the document model. The bounded range properties
  * are updated. If the view hasn't yet been shown the extent will be zero and we just set it to be
  * full until determined otherwise.
  */
 void updateVisibilityModel() {
   Component c = getContainer();
   if (c instanceof JTextField) {
     JTextField field = (JTextField) c;
     BoundedRangeModel vis = field.getHorizontalVisibility();
     int hspan = (int) getPreferredSpan(X_AXIS);
     int extent = vis.getExtent();
     int maximum = Math.max(hspan, extent);
     extent = (extent == 0) ? maximum : extent;
     int value = maximum - extent;
     int oldValue = vis.getValue();
     if ((oldValue + extent) > maximum) {
       oldValue = maximum - extent;
     }
     value = Math.max(0, Math.min(value, oldValue));
     vis.setRangeProperties(value, extent, 0, maximum, false);
   }
 }
Exemplo n.º 15
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();
 }
Exemplo n.º 16
0
  /**
   * 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()));
    }
  }
Exemplo n.º 17
0
  /**
   * 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);
  }
Exemplo n.º 18
0
  private void clearBuffer() {
    if (!myTerminalTextBuffer.isUsingAlternateBuffer()) {
      myTerminalTextBuffer.clearHistory();

      if (myCoordsAccessor != null && myCoordsAccessor.getY() > 0) {
        TerminalLine line = myTerminalTextBuffer.getLine(myCoordsAccessor.getY() - 1);

        myTerminalTextBuffer.clearAll();

        myCoordsAccessor.setY(0);
        myCursor.setY(1);
        myTerminalTextBuffer.addLine(line);
      }

      updateScrolling();

      myClientScrollOrigin = myBoundedRangeModel.getValue();
    }
  }
Exemplo n.º 19
0
 private void moveScrollBar(int k) {
   myBoundedRangeModel.setValue(myBoundedRangeModel.getValue() + k);
 }
Exemplo n.º 20
0
 private void scrollToBottom() {
   myBoundedRangeModel.setValue(myTermSize.height);
 }
Exemplo n.º 21
0
  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();
  }
Exemplo n.º 22
0
  /**
   * Adjusts the allocation given to the view to be a suitable allocation for a text field. If the
   * view has been allocated more than the preferred span vertically, the allocation is changed to
   * be centered vertically. Horizontally the view is adjusted according to the horizontal alignment
   * property set on the associated JTextField (if that is the type of the hosting component).
   *
   * @param a the allocation given to the view, which may need to be adjusted.
   * @return the allocation that the superclass should use.
   */
  protected Shape adjustAllocation(Shape a) {
    if (a != null) {
      Rectangle bounds = a.getBounds();
      int vspan = (int) getPreferredSpan(Y_AXIS);
      int hspan = (int) getPreferredSpan(X_AXIS);
      if (bounds.height != vspan) {
        int slop = bounds.height - vspan;
        bounds.y += slop / 2;
        bounds.height -= slop;
      }

      // horizontal adjustments
      Component c = getContainer();
      if (c instanceof JTextField) {
        JTextField field = (JTextField) c;
        BoundedRangeModel vis = field.getHorizontalVisibility();
        int max = Math.max(hspan, bounds.width);
        int value = vis.getValue();
        int extent = Math.min(max, bounds.width - 1);
        if ((value + extent) > max) {
          value = max - extent;
        }
        vis.setRangeProperties(value, extent, vis.getMinimum(), max, false);
        if (hspan < bounds.width) {
          // horizontally align the interior
          int slop = bounds.width - 1 - hspan;

          int align = ((JTextField) c).getHorizontalAlignment();
          if (Utilities.isLeftToRight(c)) {
            if (align == LEADING) {
              align = LEFT;
            } else if (align == TRAILING) {
              align = RIGHT;
            }
          } else {
            if (align == LEADING) {
              align = RIGHT;
            } else if (align == TRAILING) {
              align = LEFT;
            }
          }

          switch (align) {
            case SwingConstants.CENTER:
              bounds.x += slop / 2;
              bounds.width -= slop;
              break;
            case SwingConstants.RIGHT:
              bounds.x += slop;
              bounds.width -= slop;
              break;
          }
        } else {
          // adjust the allocation to match the bounded range.
          bounds.width = hspan;
          bounds.x -= vis.getValue();
        }
      }
      return bounds;
    }
    return null;
  }
Exemplo n.º 23
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();
 }
Exemplo n.º 24
0
 /**
  * Sets the current value for the <code>JProgressBar</code>. The value is stored in the
  * component's <code>model</code> (see {@link #getModel()}). If the new value is different to the
  * old value, a {@link ChangeEvent} is sent to the model's registered listeners. In turn, this
  * triggers a call to {@link #fireStateChanged()} which will send a <code>ChangeEvent</code> to
  * this component's registered listeners.
  *
  * <p>If <code>value</code> is outside the range <code>minimum</code> to <code>maximum</code>, it
  * will be set to the nearest of those boundary values.
  *
  * @param value the new value.
  * @see #getValue()
  */
 public void setValue(int value) {
   model.setValue(value);
 }
Exemplo n.º 25
0
 /**
  * Returns the current value for the <code>JProgressBar</code>. This value is fetched from the
  * model.
  *
  * @return The current value.
  * @see #setValue(int)
  */
 public int getValue() {
   return model.getValue();
 }
Exemplo n.º 26
0
 /**
  * Returns the current value expressed as a percentage. This is calculated as <code>
  * (value - min) / (max - min)</code>.
  *
  * @return The percentage (a value in the range 0.0 to 1.0).
  */
 public double getPercentComplete() {
   if (getMaximum() == getMinimum()) return 1.0;
   else
     return (double) (model.getValue() - model.getMinimum())
         / (model.getMaximum() - model.getMinimum());
 }
Exemplo n.º 27
0
 /**
  * Sets the minimum value for the <code>JProgressBar</code>. The value is stored in the
  * component's <code>model</code> (see {@link #getModel()}). If the new value is different to the
  * old value, a {@link ChangeEvent} is sent to the model's registered listeners. In turn, this
  * triggers a call to {@link #fireStateChanged()} which will send a <code>ChangeEvent</code> to
  * this component's registered listeners.
  *
  * @param minimum the minimum value.
  * @see #getMinimum()
  */
 public void setMinimum(int minimum) {
   model.setMinimum(minimum);
 }
Exemplo n.º 28
0
 /**
  * Returns the maximum value for the <code>JProgressBar</code>. This defines the upper bound for
  * the current value, and is stored in the component's <code>model</code>.
  *
  * @return The maximum value.
  * @see #setMaximum(int)
  */
 public int getMaximum() {
   return model.getMaximum();
 }
Exemplo n.º 29
0
 /**
  * Sets the maximum value for the <code>JProgressBar</code>. The value is stored in the
  * component's <code>model</code> (see {@link #getModel()}). If the new value is different to the
  * old value, a {@link ChangeEvent} is sent to the model's registered listeners. In turn, this
  * triggers a call to {@link #fireStateChanged()} which will send a <code>ChangeEvent</code> to
  * this component's registered listeners.
  *
  * @param maximum the maximum value.
  * @see #getMaximum()
  */
 public void setMaximum(int maximum) {
   model.setMaximum(maximum);
 }
Exemplo n.º 30
0
 /**
  * Get the maximum accessible value of this object.
  *
  * @return The maximum value of this object.
  */
 public Number getMaximumAccessibleValue() {
   // TIGER - 4422362
   BoundedRangeModel model = JSlider.this.getModel();
   return Integer.valueOf(model.getMaximum() - model.getExtent());
 }