Example #1
0
  /**
   * Sets the slider's current value to {@code n}. This method forwards the new value to the model.
   *
   * <p>The data model (an instance of {@code BoundedRangeModel}) handles any mathematical issues
   * arising from assigning faulty values. See the {@code BoundedRangeModel} documentation for
   * details.
   *
   * <p>If the new value is different from the previous value, all change listeners are notified.
   *
   * @param n the new value
   * @see #getValue
   * @see #addChangeListener
   * @see BoundedRangeModel#setValue
   * @beaninfo preferred: true description: The sliders current value.
   */
  public void setValue(int n) {
    BoundedRangeModel m = getModel();
    int oldValue = m.getValue();
    if (oldValue == n) {
      return;
    }
    m.setValue(n);

    if (accessibleContext != null) {
      accessibleContext.firePropertyChange(
          AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
          Integer.valueOf(oldValue),
          Integer.valueOf(m.getValue()));
    }
  }
  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());
        }
      }
    }
  }
Example #3
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);
  }
    // 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();
      }
    }
Example #5
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);
   }
 }
Example #6
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();
    }
  }
Example #7
0
 private void moveScrollBar(int k) {
   myBoundedRangeModel.setValue(myBoundedRangeModel.getValue() + k);
 }
Example #8
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;
  }