Package javax.swing

Examples of javax.swing.BoundedRangeModel


     */
    @Override
    void scrollRectToVisible(Rectangle r) {
        final int x = r.x;
        final Insets insets = getTextFieldKit().getInsets();
        final BoundedRangeModel brm = getTextFieldKit().getHorizontalVisibility();
        final int oldValue = brm.getValue();
        final int width = getModelRect().width;
        if (x > width - insets.right) {
            final int newVal = oldValue + (x - width + insets.right) + 2;
            brm.setValue(newVal);
            repaint();
        }
        if (x < insets.left) {
            brm.setValue(oldValue - (insets.left - x) - 2);
            repaint();
        }
    }
View Full Code Here


                job.setState(State.WORKING);
            }
            try {
                Source src = job.getSource();
                Destination dst = job.getDestination();
                BoundedRangeModel progress = job.getProgress();

                if(dst.exists()) {
                    progress.setMaximum(1);
                    progress.setValue(1);
                } else {
                    progress.setMaximum(src.length());
                    InputStream is = new BufferedInputStream(src.open());
                    try {
                        OutputStream os = new BufferedOutputStream(dst.open());
                        try {
                            byte[] buf = new byte[8 * 1024];
                            int total = 0;
                            for(int len; (len = is.read(buf)) != -1;) {
                                if(job.getState() == State.ABORTED) {
                                    throw new IOException("Job was aborted");
                                }
                                progress.setValue(total += len);
                                os.write(buf, 0, len);
                            }
                        } catch(IOException ex) {
                            try {
                                dst.delete();
View Full Code Here

     */
    @Override
    void scrollRectToVisible(Rectangle r) {
        int x = r.x;
        Insets insets = getTextFieldKit().getInsets();
        BoundedRangeModel brm = getTextFieldKit().getHorizontalVisibility();
        int oldValue = brm.getValue();
        int width = getModelRect().width;
        if (x > width - insets.right) {
            int newVal = oldValue + (x - width + insets.right) + 2;
            brm.setValue(newVal);
            repaint();
        }
        if (x < insets.left) {
            brm.setValue(oldValue - (insets.left - x) - 2);
            repaint();
        }
    }
View Full Code Here

    private class HSBPropertyChangeHandler implements PropertyChangeListener {
        public void propertyChange(final PropertyChangeEvent e) {
            String propertyName = e.getPropertyName();
            if (StringConstants.MODEL_PROPERTY_CHANGED.equals(propertyName)) {
                BoundedRangeModel oldValue = (BoundedRangeModel)e.getOldValue();
                if (oldValue != null) {
                    oldValue.removeChangeListener(hsbChangeListener);
                }

                BoundedRangeModel newValue = (BoundedRangeModel)e.getNewValue();
                if (newValue != null) {
                    newValue.addChangeListener(hsbChangeListener);
                }
            } else if (StringConstants.COMPONENT_ORIENTATION.equals(propertyName)) {
                hsbChangeListener.stateChanged(new ChangeEvent(e.getSource()));
            }
        }
View Full Code Here

    private class VSBPropertyChangeHandler implements PropertyChangeListener {
        public void propertyChange(final PropertyChangeEvent e) {
            String propertyName = e.getPropertyName();
            if (StringConstants.MODEL_PROPERTY_CHANGED.equals(propertyName)) {
                BoundedRangeModel oldValue = (BoundedRangeModel)e.getOldValue();
                if (oldValue != null) {
                    oldValue.removeChangeListener(vsbChangeListener);
                }

                BoundedRangeModel newValue = (BoundedRangeModel)e.getNewValue();
                if (newValue != null) {
                    newValue.addChangeListener(vsbChangeListener);
                }
            }
        }
View Full Code Here

        uninstallKeyboardActions();
    }

    public void layoutContainer(final Container c) {
        JScrollBar bar = ((JScrollBar)c);
        BoundedRangeModel model = bar.getModel();
        orientationStrategy.layoutScrollBar(bar);
        orientationStrategy.calculateTrackBounds(model);
        orientationStrategy.calculateThumbBounds(model);
    }
View Full Code Here

            String propertyName = e.getPropertyName();
            if (StringConstants.COMPONENT_ORIENTATION.equals(propertyName)) {
                uninstallKeyboardActions();
                installKeyboardActions();
            } else if (StringConstants.MODEL_PROPERTY_CHANGED.equals(propertyName)) {
                BoundedRangeModel oldValue = (BoundedRangeModel)e.getOldValue();
                if (oldValue != null) {
                    oldValue.removeChangeListener(modelListener);
                }

                BoundedRangeModel newValue = (BoundedRangeModel)e.getNewValue();
                if (newValue != null) {
                    newValue.addChangeListener(modelListener);
                }
            }

      if (scrollbar != null) { 
                scrollbar.revalidate();
View Full Code Here

                trackListener.offset = offset;
            }
        }

        void setValueOnDragging(final MouseEvent e, final int currentMouseX, final int currentMouseY, final int initialModelValue) {
            BoundedRangeModel model = scrollbar.getModel();
            int extent = model.getExtent();
            int viewSize = model.getMaximum() - model.getMinimum();
            int availableScrollingSize = viewSize - extent;
            int thumbSize = getThumbSize(Math.round(getTrackSize() * extent / viewSize));
            int availableTrackSize = getTrackSize() - thumbSize;
            int offset = getOffset(e, currentMouseX, currentMouseY);
            int modelIncrement = availableTrackSize != 0 ? offset * availableScrollingSize / availableTrackSize : 0;
            model.setValue(initialModelValue + modelIncrement);
        }
View Full Code Here

     * @param e
     *            Mouse event.
     */
    private void setValueFrom(MouseEvent e) {
      boolean active = SubstanceScrollBarUI.this.isThumbRollover();
      BoundedRangeModel model = SubstanceScrollBarUI.this.scrollbar
          .getModel();
      Rectangle thumbR = SubstanceScrollBarUI.this.getThumbBounds();
      int thumbMin = 0, thumbMax = 0, thumbPos;

      ScrollPaneButtonPolicyKind buttonPolicy = SubstanceCoreUtilities
          .getScrollPaneButtonsPolicyKind(SubstanceScrollBarUI.this.scrollbar);

      if (SubstanceScrollBarUI.this.scrollbar.getOrientation() == JScrollBar.VERTICAL) {
        switch (buttonPolicy) {
        case OPPOSITE:
          thumbMin = SubstanceScrollBarUI.this.decrButton.getY()
              + SubstanceScrollBarUI.this.decrButton.getHeight();
          thumbMax = SubstanceScrollBarUI.this.incrButton.getY()
              - thumbR.height;
          break;
        case ADJACENT:
          thumbMin = 0;
          thumbMax = SubstanceScrollBarUI.this.mySecondDecreaseButton
              .getY()
              - thumbR.height;
          break;
        case NONE:
          thumbMin = 0;
          thumbMax = SubstanceScrollBarUI.this.scrollbar.getSize().height
              - SubstanceScrollBarUI.this.scrollbar.getInsets().bottom
              - thumbR.height;
          break;
        case MULTIPLE:
          thumbMin = SubstanceScrollBarUI.this.decrButton.getY()
              + SubstanceScrollBarUI.this.decrButton.getHeight();
          thumbMax = SubstanceScrollBarUI.this.mySecondDecreaseButton
              .getY()
              - thumbR.height;
          break;
        case MULTIPLE_BOTH:
          thumbMin = SubstanceScrollBarUI.this.mySecondIncreaseButton
              .getY()
              + SubstanceScrollBarUI.this.mySecondIncreaseButton
                  .getHeight();
          thumbMax = SubstanceScrollBarUI.this.mySecondDecreaseButton
              .getY()
              - thumbR.height;
          break;
        }

        thumbPos = Math.min(thumbMax, Math.max(thumbMin,
            (e.getY() - this.offset)));
        SubstanceScrollBarUI.this.setThumbBounds(thumbR.x, thumbPos,
            thumbR.width, thumbR.height);
      } else {
        if (SubstanceScrollBarUI.this.scrollbar
            .getComponentOrientation().isLeftToRight()) {
          switch (buttonPolicy) {
          case OPPOSITE:
            thumbMin = SubstanceScrollBarUI.this.decrButton.getX()
                + SubstanceScrollBarUI.this.decrButton
                    .getWidth();
            thumbMax = SubstanceScrollBarUI.this.incrButton.getX()
                - thumbR.width;
            break;
          case ADJACENT:
            thumbMin = 0;
            thumbMax = SubstanceScrollBarUI.this.mySecondDecreaseButton
                .getX()
                - thumbR.width;
            break;
          case MULTIPLE:
            thumbMin = SubstanceScrollBarUI.this.decrButton.getX()
                + SubstanceScrollBarUI.this.decrButton
                    .getWidth();
            thumbMax = SubstanceScrollBarUI.this.mySecondDecreaseButton
                .getX()
                - thumbR.width;
            break;
          case MULTIPLE_BOTH:
            thumbMin = SubstanceScrollBarUI.this.mySecondIncreaseButton
                .getX()
                + SubstanceScrollBarUI.this.mySecondIncreaseButton
                    .getWidth();
            thumbMax = SubstanceScrollBarUI.this.mySecondDecreaseButton
                .getX()
                - thumbR.width;
            break;
          case NONE:
            thumbMin = 0;
            thumbMax = SubstanceScrollBarUI.this.scrollbar
                .getSize().width
                - SubstanceScrollBarUI.this.scrollbar
                    .getInsets().right - thumbR.width;
            break;
          }
        } else {
          switch (buttonPolicy) {
          case OPPOSITE:
            thumbMin = SubstanceScrollBarUI.this.incrButton.getX()
                + SubstanceScrollBarUI.this.incrButton
                    .getWidth();
            thumbMax = SubstanceScrollBarUI.this.decrButton.getX()
                - thumbR.width;
            break;
          case ADJACENT:
            thumbMin = SubstanceScrollBarUI.this.mySecondDecreaseButton
                .getX()
                + SubstanceScrollBarUI.this.mySecondDecreaseButton
                    .getWidth();
            thumbMax = SubstanceScrollBarUI.this.scrollbar
                .getSize().width
                - SubstanceScrollBarUI.this.scrollbar
                    .getInsets().right - thumbR.width;
            break;
          case MULTIPLE:
            thumbMin = SubstanceScrollBarUI.this.mySecondDecreaseButton
                .getX()
                + SubstanceScrollBarUI.this.mySecondDecreaseButton
                    .getWidth();
            thumbMax = SubstanceScrollBarUI.this.decrButton.getX()
                - thumbR.width;
            break;
          case MULTIPLE_BOTH:
            thumbMin = SubstanceScrollBarUI.this.mySecondDecreaseButton
                .getX()
                + SubstanceScrollBarUI.this.mySecondDecreaseButton
                    .getWidth();
            thumbMax = SubstanceScrollBarUI.this.mySecondIncreaseButton
                .getX()
                - thumbR.width;
            break;
          case NONE:
            thumbMin = 0;
            thumbMax = SubstanceScrollBarUI.this.scrollbar
                .getSize().width
                - SubstanceScrollBarUI.this.scrollbar
                    .getInsets().right - thumbR.width;
            break;
          }
        }
        // System.out.println(thumbMin + " : " + thumbMax + " : "
        // + (e.getX() - offset));
        thumbPos = Math.min(thumbMax, Math.max(thumbMin,
            (e.getX() - this.offset)));
        SubstanceScrollBarUI.this.setThumbBounds(thumbPos, thumbR.y,
            thumbR.width, thumbR.height);
      }

      /*
       * Set the scrollbars value. If the thumb has reached the end of the
       * scrollbar, then just set the value to its maximum. Otherwise
       * compute the value as accurately as possible.
       */
      if (thumbPos == thumbMax) {
        if (SubstanceScrollBarUI.this.scrollbar.getOrientation() == JScrollBar.VERTICAL
            || SubstanceScrollBarUI.this.scrollbar
                .getComponentOrientation().isLeftToRight()) {
          SubstanceScrollBarUI.this.scrollbar.setValue(model
              .getMaximum()
              - model.getExtent());
        } else {
          SubstanceScrollBarUI.this.scrollbar.setValue(model
              .getMinimum());
        }
      } else {
        float valueMax = model.getMaximum() - model.getExtent();
        float valueRange = valueMax - model.getMinimum();
        float thumbValue = thumbPos - thumbMin;
        float thumbRange = thumbMax - thumbMin;
        int value;
        if (SubstanceScrollBarUI.this.scrollbar.getOrientation() == JScrollBar.VERTICAL
            || SubstanceScrollBarUI.this.scrollbar
                .getComponentOrientation().isLeftToRight()) {
          value = (int) (0.5 + ((thumbValue / thumbRange) * valueRange));
        } else {
          value = (int) (0.5 + (((thumbMax - thumbPos) / thumbRange) * valueRange));
        }

        SubstanceScrollBarUI.this.scrollbar.setValue(value
            + model.getMinimum());
      }
      SubstanceScrollBarUI.this.setThumbRollover(active);
    }
View Full Code Here

    private HeapProgress() {

    }

    public static BoundedRangeModel getProgress() {
        BoundedRangeModel model = (BoundedRangeModel) progressThreadLocal.get();

        if (model == null) {
            model = new DefaultBoundedRangeModel(0,0,0,PROGRESS_MAX);
            progressThreadLocal.set(model);
        }
View Full Code Here

TOP

Related Classes of javax.swing.BoundedRangeModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.