Java Code Examples for javax.swing.BoundedRangeModel

The following examples show how to use javax.swing.BoundedRangeModel. These examples are extracted from open source projects. 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 Project: blog-codes   Source File: mxGraphComponent.java    License: 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 2
Source Project: netbeans   Source File: ReferencesBrowserController.java    License: 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 3
Source Project: netbeans   Source File: OQLControllerUI.java    License: 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
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 Project: triplea   Source File: ChatMessagePanel.java    License: 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 6
Source Project: triplea   Source File: CommentPanel.java    License: 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 Project: swift-k   Source File: GanttChart.java    License: 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 8
Source Project: blog-codes   Source File: mxGraphComponent.java    License: 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 9
Source Project: netbeans   Source File: Populate.java    License: Apache License 2.0 5 votes vote down vote up
private static void create(File root, int val, final BoundedRangeModel progress) throws IOException {
    for (int i = 0; i < val; i++) {
        final int progval = i;
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                progress.setValue(progval);
            }
        });
        boolean xml = i % 5 > 2;
        String fname = "file" + i + (xml ? ".xml" : ".txt");
        int bit = 0;
        int x = i;
        while (x > 0) {
            if (x % 3 == 0) {
                fname = "dir" + bit + File.separatorChar + fname;
            }
            bit++;
            x /= 3;
        }
        File tomake = new File(root, "test" + File.separatorChar + fname);
        tomake.getParentFile().mkdirs();
        if (tomake.createNewFile()) {
            OutputStream os = new FileOutputStream(tomake);
            try {
                if (xml) {
                    Document doc = createXML(i);
                    XMLUtil.write(doc, os, "UTF-8");
                } else {
                    PrintStream ps = new PrintStream(os);
                    ps.println("Sample data for file #" + i);
                    ps.close();
                }
            } finally {
                os.close();
            }
        }
    }
}
 
Example 10
Source Project: netbeans   Source File: MemoryLint.java    License: Apache License 2.0 5 votes vote down vote up
BoundedRangeModel getNextDelegate() {
    step++;
    delegate.setRangeProperties(0, 0, 0, 1, false);
    updateValue();

    return delegate;
}
 
Example 11
Source Project: netbeans   Source File: InstanceNode.java    License: 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 12
Source Project: netbeans   Source File: AnalysisController.java    License: 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 13
Source Project: netbeans   Source File: HeapWalker.java    License: 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 14
Source Project: netbeans   Source File: HeapProgress.java    License: Apache License 2.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 15
Source Project: netbeans   Source File: HeapProgress.java    License: Apache License 2.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 16
/**
 * Maps {@code JProgressBar.getModel()} through queue
 */
public BoundedRangeModel getModel() {
    return (runMapping(new MapAction<BoundedRangeModel>("getModel") {
        @Override
        public BoundedRangeModel map() {
            return ((JProgressBar) getSource()).getModel();
        }
    }));
}
 
Example 17
/**
 * Maps {@code JProgressBar.setModel(BoundedRangeModel)} through queue
 */
public void setModel(final BoundedRangeModel boundedRangeModel) {
    runMapping(new MapVoidAction("setModel") {
        @Override
        public void map() {
            ((JProgressBar) getSource()).setModel(boundedRangeModel);
        }
    });
}
 
Example 18
Source Project: openjdk-jdk9   Source File: JSliderOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JSlider.getModel()} through queue
 */
public BoundedRangeModel getModel() {
    return (runMapping(new MapAction<BoundedRangeModel>("getModel") {
        @Override
        public BoundedRangeModel map() {
            return ((JSlider) getSource()).getModel();
        }
    }));
}
 
Example 19
Source Project: openjdk-jdk9   Source File: JSliderOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JSlider.setModel(BoundedRangeModel)} through queue
 */
public void setModel(final BoundedRangeModel boundedRangeModel) {
    runMapping(new MapVoidAction("setModel") {
        @Override
        public void map() {
            ((JSlider) getSource()).setModel(boundedRangeModel);
        }
    });
}
 
Example 20
Source Project: Spark   Source File: JavaMixer.java    License: Apache License 2.0 5 votes vote down vote up
private JComponent createControlComponent(FloatControl control) {
    int orientation = isBalanceOrPan(control) ? JSlider.HORIZONTAL : JSlider.VERTICAL;
    BoundedRangeModel model = new JavaMixer.FloatControlBoundedRangeModel(control);
    JSlider slider = new JSlider(model);
    slider.setOrientation(orientation);
    slider.setPaintLabels(true);
    slider.setPaintTicks(true);
    slider.setSize(10, 50);
    return slider;
}
 
Example 21
/**
 * Maps {@code JScrollBar.getModel()} through queue
 */
public BoundedRangeModel getModel() {
    return (runMapping(new MapAction<BoundedRangeModel>("getModel") {
        @Override
        public BoundedRangeModel map() {
            return ((JScrollBar) getSource()).getModel();
        }
    }));
}
 
Example 22
/**
 * 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 23
private void apply (BoundedRangeModel src,
                    BoundedRangeModel tgt)
{
    tgt.setRangeProperties(
            src.getValue(),
            src.getExtent(),
            src.getMinimum(),
            src.getMaximum(),
            false);
}
 
Example 24
private DefaultBoundedRangeModel copy (BoundedRangeModel m)
{
    return new DefaultBoundedRangeModel(
            m.getValue(),
            m.getExtent(),
            m.getMinimum(),
            m.getMaximum());
}
 
Example 25
Source Project: visualvm   Source File: HeapFragment.java    License: 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 26
Source Project: visualvm   Source File: OQLConsoleView.java    License: 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 27
Source Project: visualvm   Source File: MemoryLint.java    License: 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 28
Source Project: visualvm   Source File: InstanceNode.java    License: 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 29
Source Project: visualvm   Source File: AnalysisController.java    License: 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 30
Source Project: pdfxtk   Source File: JNumberField.java    License: 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();    
 }