javax.swing.BoundedRangeModel Java Examples

The following examples show how to use javax.swing.BoundedRangeModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GanttChart.java    From swift-k with Apache License 2.0 6 votes vote down vote up
public void stateChanged(ChangeEvent e) {
    if (e.getSource() == scalesp) {
        scale = ((Number) scalesp.getValue()).doubleValue() * INITIAL_SCALE;
        repaint();
    }
    else if (e.getSource() == hsb.getModel()) {
        BoundedRangeModel m = hsb.getModel();
        if (offset != m.getValue()) {
   	        offset = m.getValue();
   	        repaint();
        }
    }
    else if (e.getSource() == csp.getVerticalScrollBar().getModel()) {
        if (scrollVerticallyOnNextUpdate) {
            scrollVerticallyOnNextUpdate = false;
            csp.getVerticalScrollBar().getModel().setValue(Integer.MAX_VALUE);
        }
    }
}
 
Example #2
Source File: mxGraphComponent.java    From blog-codes with Apache License 2.0 6 votes vote down vote up
/**
 *
 */
protected void maintainScrollBar(boolean horizontal, double factor,
		boolean center)
{
	JScrollBar scrollBar = (horizontal) ? getHorizontalScrollBar()
			: getVerticalScrollBar();

	if (scrollBar != null)
	{
		BoundedRangeModel model = scrollBar.getModel();
		int newValue = (int) Math.round(model.getValue() * factor)
				+ (int) Math.round((center) ? (model.getExtent()
						* (factor - 1) / 2) : 0);
		model.setValue(newValue);
	}
}
 
Example #3
Source File: OQLControllerUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void queryStarted(final BoundedRangeModel model) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            updateUIState();
            progressLabel.setText(Bundle.OQLControllerUI_ExecutingQueryMsg());
            progressBar.setModel(model);
            progressBar.setMaximumSize(new Dimension(progressBar.getMaximumSize().width,
                                                     progressBar.getPreferredSize().height));
            contentsPanel.remove(controlPanel);
            contentsPanel.add(progressPanel, BorderLayout.SOUTH);
            progressPanel.invalidate();
            contentsPanel.revalidate();
            contentsPanel.repaint();
        }
    });
}
 
Example #4
Source File: ReferencesBrowserController.java    From netbeans with Apache License 2.0 6 votes vote down vote up
Dialog createProgressPanel(final String message, BoundedRangeModel model) {
    Dialog dialog;
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout(10, 10));
    panel.setBorder(new EmptyBorder(15, 15, 15, 15));
    panel.add(new JLabel(message), BorderLayout.NORTH);

    final Dimension ps = panel.getPreferredSize();
    ps.setSize(Math.max(ps.getWidth(), DEFAULT_WIDTH), Math.max(ps.getHeight(), DEFAULT_HEIGHT));
    panel.setPreferredSize(ps);

    final JProgressBar progress = new JProgressBar();
    if (model == null) {
        progress.setIndeterminate(true);
    } else {
        progress.setStringPainted(true);
        progress.setModel(model);
    }
    panel.add(progress, BorderLayout.SOUTH);
    dialog = DialogDisplayer.getDefault().createDialog(new DialogDescriptor(panel, Bundle.ReferencesBrowserController_ProgressDialogCaption(), true, new Object[] {  },
                                                       DialogDescriptor.CANCEL_OPTION, DialogDescriptor.RIGHT_ALIGN,
                                                       null, null));

    return dialog;
}
 
Example #5
Source File: ReferencesBrowserController.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
Dialog createProgressPanel(final String message, BoundedRangeModel model) {
    Dialog dialog;
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout(10, 10));
    panel.setBorder(new EmptyBorder(15, 15, 15, 15));
    panel.add(new JLabel(message), BorderLayout.NORTH);

    final Dimension ps = panel.getPreferredSize();
    ps.setSize(Math.max(ps.getWidth(), DEFAULT_WIDTH), Math.max(ps.getHeight(), DEFAULT_HEIGHT));
    panel.setPreferredSize(ps);

    final JProgressBar progress = new JProgressBar();
    if (model == null) {
        progress.setIndeterminate(true);
    } else {
        progress.setStringPainted(true);
        progress.setModel(model);
    }
    panel.add(progress, BorderLayout.SOUTH);
    dialog = DialogDisplayer.getDefault().createDialog(new DialogDescriptor(panel, Bundle.ReferencesBrowserController_ProgressDialogCaption(), true, new Object[] {  },
                                                       DialogDescriptor.CANCEL_OPTION, DialogDescriptor.RIGHT_ALIGN,
                                                       null, null));

    return dialog;
}
 
Example #6
Source File: CommentPanel.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
/** thread safe. */
void addMessage(final String message) {
  SwingAction.invokeNowOrLater(
      () -> {
        try {
          final Document doc = text.getDocument();
          // save history entry
          final IEditDelegate delegate = frame.getEditDelegate();
          final String error;
          if (delegate == null) {
            error = "You can only add comments during your turn";
          } else {
            error = delegate.addComment(message);
          }
          if (error != null) {
            doc.insertString(doc.getLength(), error + "\n", italic);
          }
        } catch (final BadLocationException e) {
          log.log(Level.SEVERE, "Failed to add comment", e);
        }
        final BoundedRangeModel scrollModel = scrollPane.getVerticalScrollBar().getModel();
        scrollModel.setValue(scrollModel.getMaximum());
      });
}
 
Example #7
Source File: ChatMessagePanel.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
private void addMessageWithSound(final String message, final UserName from, final String sound) {
  SwingAction.invokeNowOrLater(
      () -> {
        if (from == null || chat == null) {
          // someone likely disconnected from the game.
          return;
        }
        if (!floodControl.allow(from, System.currentTimeMillis())) {
          if (from.equals(chat.getLocalUserName())) {
            addChatMessage(
                "MESSAGE LIMIT EXCEEDED, TRY AGAIN LATER", UserName.of("ADMIN_FLOOD_CONTROL"));
          }
          return;
        }
        addChatMessage(message, from);
        SwingUtilities.invokeLater(
            () -> {
              final BoundedRangeModel scrollModel = scrollPane.getVerticalScrollBar().getModel();
              scrollModel.setValue(scrollModel.getMaximum());
            });
        ClipPlayer.play(sound);
      });
}
 
Example #8
Source File: SeaGlassScrollPaneUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
private void hsbStateChanged(JViewport viewport, ChangeEvent e) {
    BoundedRangeModel model = (BoundedRangeModel) (e.getSource());
    Point p = viewport.getViewPosition();
    int value = model.getValue();
    if (scrollpane.getComponentOrientation().isLeftToRight()) {
        p.x = value;
    } else {
        int max = viewport.getViewSize().width;
        int extent = viewport.getExtentSize().width;
        int oldX = p.x;

        /*
         * Set new X coordinate based on "value".
         */
        p.x = max - extent - value;

        /*
         * If setValue() was called before "extent" was fixed, turn
         * setValueCalled flag on.
         */
        if ((extent == 0) && (value != 0) && (oldX == max)) {
            setValueCalled = true;
        } else {
            /*
             * When a pane without a horizontal scroll bar was reduced
             * and the bar appeared, the viewport should show the right
             * side of the view.
             */
            if ((extent != 0) && (oldX < 0) && (p.x == 0)) {
                p.x += value;
            }
        }
    }
    viewport.setViewPosition(p);
}
 
Example #9
Source File: HeapFragment.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public static void setProgress(final ProgressHandle pHandle, final int offset) {
    final BoundedRangeModel progress = HeapProgress.getProgress();
    progress.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            pHandle.progress(progress.getValue() + offset);
        }
    });
}
 
Example #10
Source File: SheetAssembly.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
private DefaultBoundedRangeModel copy (BoundedRangeModel m)
{
    return new DefaultBoundedRangeModel(
            m.getValue(),
            m.getExtent(),
            m.getMinimum(),
            m.getMaximum());
}
 
Example #11
Source File: SheetAssembly.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
private void apply (BoundedRangeModel src,
                    BoundedRangeModel tgt)
{
    tgt.setRangeProperties(
            src.getValue(),
            src.getExtent(),
            src.getMinimum(),
            src.getMaximum(),
            false);
}
 
Example #12
Source File: PenWidth.java    From zxpoly with GNU General Public License v3.0 5 votes vote down vote up
protected void updateLookForCurrentModel() {
  final BoundedRangeModel model = this.currentModel.get();
  if (model == null) {
    this.showLabel.setEnabled(false);
    this.widthSlider.setEnabled(false);
    drawImageForValue(-1);
  } else {
    this.showLabel.setEnabled(true);
    this.widthSlider.setEnabled(true);
    drawImageForValue(model.getValue());
  }
}
 
Example #13
Source File: SeaGlassScrollPaneUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
private void sbPropertyChange(PropertyChangeEvent e) {
    String propertyName = e.getPropertyName();
    Object source = e.getSource();

    if ("model" == propertyName) {
        JScrollBar sb = scrollpane.getVerticalScrollBar();
        BoundedRangeModel oldModel = (BoundedRangeModel) e.getOldValue();
        ChangeListener cl = null;

        if (source == sb) {
            cl = vsbChangeListener;
        } else if (source == scrollpane.getHorizontalScrollBar()) {
            sb = scrollpane.getHorizontalScrollBar();
            cl = hsbChangeListener;
        }
        if (cl != null) {
            if (oldModel != null) {
                oldModel.removeChangeListener(cl);
            }
            if (sb.getModel() != null) {
                sb.getModel().addChangeListener(cl);
            }
        }
    } else if ("componentOrientation" == propertyName) {
        if (source == scrollpane.getHorizontalScrollBar()) {
            JScrollBar hsb = scrollpane.getHorizontalScrollBar();
            JViewport viewport = scrollpane.getViewport();
            Point p = viewport.getViewPosition();
            if (scrollpane.getComponentOrientation().isLeftToRight()) {
                p.x = hsb.getValue();
            } else {
                p.x = viewport.getViewSize().width - viewport.getExtentSize().width - hsb.getValue();
            }
            viewport.setViewPosition(p);
        }
    }
}
 
Example #14
Source File: JScrollBarOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JScrollBar.setModel(BoundedRangeModel)} through queue
 */
public void setModel(final BoundedRangeModel boundedRangeModel) {
    runMapping(new MapVoidAction("setModel") {
        @Override
        public void map() {
            ((JScrollBar) getSource()).setModel(boundedRangeModel);
        }
    });
}
 
Example #15
Source File: JScrollBarOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JScrollBar.getModel()} through queue
 */
public BoundedRangeModel getModel() {
    return (runMapping(new MapAction<BoundedRangeModel>("getModel") {
        @Override
        public BoundedRangeModel map() {
            return ((JScrollBar) getSource()).getModel();
        }
    }));
}
 
Example #16
Source File: HeapWalker.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void setProgress(final ProgressHandle pHandle, final int offset) {
    final BoundedRangeModel progress = HeapProgress.getProgress();
    progress.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            pHandle.progress(progress.getValue()+offset);
        }
    });
}
 
Example #17
Source File: InstanceNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ChangeListener setProgress(final ProgressHandle pHandle) {
    final BoundedRangeModel progress = HeapProgress.getProgress();
    ChangeListener cl = new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            pHandle.progress(progress.getValue());
        }
    };
    progress.addChangeListener(cl);
    return cl;
}
 
Example #18
Source File: AnalysisController.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BoundedRangeModel performAnalysis(boolean[] rulesSelection) {
    final List<Rule> selectedRules = new ArrayList<Rule>();
    final List<Rule> allRules = getRules();

    for (int i = 0; i < rulesSelection.length; i++) {
        if (rulesSelection[i]) {
            selectedRules.add(allRules.get(i));
        }
    }

    if (selectedRules.size() > 0) {
        analysisRunning = true;

        final MemoryLint ml = new MemoryLint(heapFragmentWalker.getHeapFragment());
        runningMemoryLint = ml;
        BrowserUtils.performTask(new Runnable() {
                public void run() {
                    try {
                        ml.process(selectedRules);
                    } catch (Exception e) {
                        ErrorManager.getDefault().log(ErrorManager.ERROR, e.getMessage());
                    }
                    rules = null;
                    analysisRunning = false;
                    runningMemoryLint = null;

                    AnalysisControllerUI ui = (AnalysisControllerUI)getPanel();
                    ui.displayNewRules();
                    if (!ml.isInterruped()) ui.setResult(ml.getResults());
                }
            });

        return ml.getGlobalProgress();
    } else {
        return null;
    }
}
 
Example #19
Source File: OQLConsoleView.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void queryStarted(final BoundedRangeModel model) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            updateUIState();
            resultsToolbar.getComponent().setVisible(false);
            progressToolbar.getComponent().setVisible(true);
            progressBar.setModel(model);
            
            objectsView.reloadView();
            htmlView.setText(oqlExecutor.getQueryHTML());
        }
    });
}
 
Example #20
Source File: PenWidth.java    From zxpoly with GNU General Public License v3.0 5 votes vote down vote up
public void setModel(final BoundedRangeModel model) {
  final BoundedRangeModel prev = this.currentModel.getAndSet(model);
  if (prev != null) {
    prev.removeChangeListener(this.changeListener);
  }
  if (model == null) {
    this.widthSlider.setPaintTicks(false);
  } else {
    this.widthSlider.setModel(model);
    this.widthSlider.setPaintTicks(true);
    model.addChangeListener(this.changeListener);
  }
  updateLookForCurrentModel();
}
 
Example #21
Source File: MemoryLint.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
BoundedRangeModel getNextDelegate() {
    step++;
    delegate.setRangeProperties(0, 0, 0, 1, false);
    updateValue();

    return delegate;
}
 
Example #22
Source File: mxGraphComponent.java    From blog-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 
 */
public void scrollToCenter(boolean horizontal)
{
	JScrollBar scrollBar = (horizontal) ? getHorizontalScrollBar()
			: getVerticalScrollBar();

	if (scrollBar != null)
	{
		final BoundedRangeModel model = scrollBar.getModel();
		final int newValue = ((model.getMaximum()) / 2) - model.getExtent()
				/ 2;
		model.setValue(newValue);
	}
}
 
Example #23
Source File: PenWidth.java    From zxpoly with GNU General Public License v3.0 5 votes vote down vote up
public PenWidth() {
  super();
  this.changeListener =
      (ChangeEvent e) -> drawImageForValue(((BoundedRangeModel) e.getSource()).getValue());
  setOpaque(false);
  setLayout(new BorderLayout(0, 0));

  this.showImage = new BufferedImage(ICON_WIDTH, ICON_HEIGHT, BufferedImage.TYPE_INT_RGB);

  this.widthSlider = new JSlider();
  this.widthSlider.setMajorTickSpacing(10);
  this.widthSlider.setMinorTickSpacing(5);
  this.widthSlider.setSnapToTicks(false);

  this.showLabel = new JLabel(new ImageIcon(showImage));

  add(this.showLabel, BorderLayout.CENTER);
  add(this.widthSlider, BorderLayout.SOUTH);

  this.widthSlider.setSize(ICON_WIDTH << 1, 10);
  this.widthSlider.setFocusable(false);

  setBorder(this.titledBorder);

  setSize(getPreferredSize());

  updateLookForCurrentModel();
}
 
Example #24
Source File: InstanceNode.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private static ChangeListener setProgress(final ProgressHandle pHandle) {
    final BoundedRangeModel progress = HeapProgress.getProgress();
    ChangeListener cl = new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            pHandle.progress(progress.getValue());
        }
    };
    progress.addChangeListener(cl);
    return cl;
}
 
Example #25
Source File: AnalysisController.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public BoundedRangeModel performAnalysis(boolean[] rulesSelection) {
    final List<Rule> selectedRules = new ArrayList();
    final List<Rule> allRules = getRules();

    for (int i = 0; i < rulesSelection.length; i++) {
        if (rulesSelection[i]) {
            selectedRules.add(allRules.get(i));
        }
    }

    if (selectedRules.size() > 0) {
        analysisRunning = true;

        final MemoryLint ml = new MemoryLint(heapFragmentWalker.getHeapFragment());
        runningMemoryLint = ml;
        BrowserUtils.performTask(new Runnable() {
                public void run() {
                    try {
                        ml.process(selectedRules);
                    } catch (Exception e) {
                        ErrorManager.getDefault().log(ErrorManager.ERROR, e.getMessage());
                    }
                    rules = null;
                    analysisRunning = false;
                    runningMemoryLint = null;

                    AnalysisControllerUI ui = (AnalysisControllerUI)getPanel();
                    ui.displayNewRules();
                    if (!ml.isInterruped()) ui.setResult(ml.getResults());
                }
            });

        return ml.getGlobalProgress();
    } else {
        return null;
    }
}
 
Example #26
Source File: JNumberField.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
public JNumberField(int columns, BoundedRangeModel model_, int property_) {
   super(columns);
   model = model_;
   model.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {initFromModel();}
     });
   property = property_;
   integer  = true;
   initFromModel();
   init();    
 }
 
Example #27
Source File: HeapWalker.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private static void setProgress(final ProgressHandle pHandle, final int offset) {
    final BoundedRangeModel progress = HeapProgress.getProgress();
    progress.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            pHandle.progress(progress.getValue()+offset);
        }
    });
}
 
Example #28
Source File: HeapProgress.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public static BoundedRangeModel getProgress() {
    ModelInfo info = (ModelInfo) progressThreadLocal.get();
    
    if (info == null) {
        info = new ModelInfo();
        progressThreadLocal.set(info);
    }
    return info.model;
}
 
Example #29
Source File: HeapProgress.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private static void setValue(final BoundedRangeModel model, final int val) {
    if (SwingUtilities.isEventDispatchThread()) {
        model.setValue(val);
    } else {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() { model.setValue(val); }
        });
    }
}
 
Example #30
Source File: RConsoleView.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void queryStarted(final BoundedRangeModel model) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            updateUIState();
            graphsToolbar.getComponent().setVisible(false);
            progressToolbar.getComponent().setVisible(true);
            progressBar.setModel(model);
        }
    });
}