javax.swing.DefaultBoundedRangeModel Java Examples

The following examples show how to use javax.swing.DefaultBoundedRangeModel. 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: PTextField.java    From PolyGlot with MIT License 6 votes vote down vote up
/**
 * Init for PDialogs
 *
 * @param _core dictionary core
 * @param _overrideFont true overrides ConFont, false sets to default
 * @param _defText default text that will display in grey if otherwise empty
 */
public PTextField(DictCore _core, boolean _overrideFont, String _defText) {
    // remove change listener to add custom one
    DefaultBoundedRangeModel pVis = (DefaultBoundedRangeModel) this.getHorizontalVisibility();
    for (ChangeListener chlist : pVis.getChangeListeners()) {
        pVis.removeChangeListener(chlist);
    }
    pVis.addChangeListener(new PScrollRepainter());

    core = _core;
    defText = _defText;
    overrideFont = _overrideFont;
    setupListeners();
    setForeground(Color.lightGray);
    setupRightClickMenu();
    setText(defText);
    setupLook();
    
    if (overrideFont || !defText.isBlank()) {
        setFont(core.getPropertiesManager().getFontLocal().deriveFont((float) core.getOptionsManager().getMenuFontSize()));
    } else {
        setFont(core.getPropertiesManager().getFontCon());
    }
}
 
Example #2
Source File: LiveEngineTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testIsKnown() {
    class M extends DefaultBoundedRangeModel {

        @Override
        public void setValue(int n) {
            super.setValue(n);
            if (n > 10) {
                super.setValue(10);
                throw new CancelException();
            }
        }

    }
    M model = new M();
    LiveEngine instance = new LiveEngine(model);

    Map<?,?> path = instance.trace(Collections.singleton(last), Collections.<Object>singleton(list));

    assertEquals("Model stops at 10", 10, model.getValue());
    assertEquals("No path found", null, path);
}
 
Example #3
Source File: RangeOptionUI.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new {@code RangeOptionUI} for the given
 * {@code RangeOption}.
 *
 * @param option The {@code RangeOption} to make a user interface for
 * @param editable boolean whether user can modify the setting
 */
public RangeOptionUI(final RangeOption option, boolean editable) {
    super(option, editable);

    JSlider slider = getComponent();

    slider.setModel(new DefaultBoundedRangeModel(option.getValueRank(), 0,
            0, option.getItemValues().size()-1));

    Hashtable<Integer, JComponent> labels
        = new Hashtable<>();
    int index = 0;
    for (String string : option.getItemValues().values()) {
        if (option.localizeLabels()) {
            labels.put(index, Utility.localizedLabel(string));
        } else {
            labels.put(index, new JLabel(string));
        }
        index++;
    }

    slider.setLabelTable(labels);
    slider.setValue(option.getValueRank());
    slider.setMajorTickSpacing(1);
    slider.setSnapToTicks(true);
}
 
Example #4
Source File: PercentageOptionUI.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new {@code PercentageOptionUI} for the given
 * {@code PercentageOption}.
 *
 * @param option The {@code PercentageOption} to make a user
 *     interface for.
 * @param editable boolean whether user can modify the setting
 */
public PercentageOptionUI(final PercentageOption option, boolean editable) {
    super(option, editable);

    JSlider slider = getComponent();

    slider.setModel(new DefaultBoundedRangeModel(option.getValue(), 0, 0, 100));
    Hashtable<Integer, JComponent> labels
        = new Hashtable<>();
    labels.put(0,   new JLabel("0 %"));
    labels.put(25,  new JLabel("25 %"));
    labels.put(50,  new JLabel("50 %"));
    labels.put(75,  new JLabel("75 %"));
    labels.put(100, new JLabel("100 %"));
    slider.setLabelTable(labels);
    slider.setValue(option.getValue());
    slider.setMajorTickSpacing(5);
    slider.setSnapToTicks(false);
}
 
Example #5
Source File: RConsoleView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public void queryFinished(final String result) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                updateUIState();
                progressToolbar.getComponent().setVisible(false);
                graphsToolbar.getComponent().setVisible(rGraphs.isSelected());
                progressBar.setModel(new DefaultBoundedRangeModel(0, 0, 0, 0));
//                objectsView.reloadView();
                
                if (result != null) {
                    htmlView.setText(result);
//                    if (result.length() > 0 && nodeResults.isEmpty()) rHTML.setSelected(true);
                }
            }
        });
    }
 
Example #6
Source File: OQLConsoleView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private void queryFinished(final boolean hasObjectsResults, final boolean hasHTMLResults, final String errorMessage) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            updateUIState();
            progressToolbar.getComponent().setVisible(false);
            resultsToolbar.getComponent().setVisible(true);
            progressBar.setModel(new DefaultBoundedRangeModel(0, 0, 0, 0));
            
            objectsView.reloadView();
            
            String queryHTML = oqlExecutor.getQueryHTML();
            htmlView.setText(errorMessage != null ? errorMessage : queryHTML);
            
            if (errorMessage != null || (!hasObjectsResults && hasHTMLResults)) {
                rHTML.setSelected(true);
            }
        }
    });
}
 
Example #7
Source File: DiscreteProgress.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initComponents() {
        setLayout(new BorderLayout());
        
//        if (UIUtils.isNimbus()) {
            progressDelegateModel = new DefaultBoundedRangeModel(4, 1, 0, 10);
            progressDelegate = new JProgressBar(progressDelegateModel);
            add(progressDelegate, BorderLayout.CENTER);
//        } else {
//            setBorder(new ThinBevelBorder(BevelBorder.LOWERED));
//            setOpaque(false);
//        }
    }
 
Example #8
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 #9
Source File: DiscreteProgress.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void initComponents() {
        setLayout(new BorderLayout());
        
//        if (UIUtils.isNimbus()) {
            progressDelegateModel = new DefaultBoundedRangeModel(4, 1, 0, 10);
            progressDelegate = new JProgressBar(progressDelegateModel);
            add(progressDelegate, BorderLayout.CENTER);
//        } else {
//            setBorder(new ThinBevelBorder(BevelBorder.LOWERED));
//            setOpaque(false);
//        }
    }
 
Example #10
Source File: Main.java    From blog with Apache License 2.0 4 votes vote down vote up
public void createAndShowUI() {
	BoundedRangeModel progressModel = new DefaultBoundedRangeModel();
	BoundedRangeProgress progressAdapter = new BoundedRangeProgress(progressModel);
	Document resultDocument = new PlainDocument();

	ComponentVisibility progressBarVisibility = new ComponentVisibility("enabled", false);
	progressBarVisibility.setInvisibleDelay(1, TimeUnit.SECONDS);

	ProgressCancelAction cancelAction = new ProgressCancelAction();
	cancelAction.putValue(Action.NAME, "Cancel");

	ProgressSimulationAction progressAction = new ProgressSimulationAction();
	progressAction.addProgressAware(progressAdapter);
	progressAction.addProgressAware(cancelAction);
	progressAction.addPropertyChangeListener(progressBarVisibility);
	progressAction.putValue(Action.NAME, "Start");
	progressAction.setResultDocument(resultDocument);

	JFrame mainFrame = new JFrame("Progress Object Pattern with Java Swing");
	mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	mainFrame.setMinimumSize(new Dimension(600, 120));

	JProgressBar progressBar = new JProgressBar(progressModel);
	progressBar.setVisible(false);
	progressBar.setStringPainted(true);
	progressBarVisibility.setComponent(progressBar);

	JButton startProgressButton = new JButton(progressAction);
	JButton cancelButton = new JButton(cancelAction);
	JTextField resultTextField = new JTextField(40);
	resultTextField.setEditable(false);
	resultTextField.setDocument(resultDocument);

	JPanel mainPanel = new JPanel();
	mainPanel.add(startProgressButton);
	mainPanel.add(cancelButton);
	mainPanel.add(resultTextField);

	Container contentPane = mainFrame.getContentPane();
	contentPane.add(mainPanel);
	contentPane.add(progressBar, BorderLayout.SOUTH);

	mainFrame.pack();
	mainFrame.setLocationRelativeTo(null);
	mainFrame.setVisible(true);
}
 
Example #11
Source File: OQLController.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void executeQueryImpl(final String oqlQuery) {
    final BoundedRangeModel progressModel = new DefaultBoundedRangeModel(0, 10, 0, 100);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            BrowserUtils.performTask(new Runnable() {
                public void run() {
                    final AtomicInteger counter = new AtomicInteger(RESULTS_LIMIT);
                    progressModel.setMaximum(100);

                    final StringBuilder sb = new StringBuilder();
                    final boolean[] oddRow = new boolean[1];
                    Color oddRowBackground = UIUtils.getDarker(
                                    UIUtils.getProfilerResultsBackground());
                    final String oddRowBackgroundString =
                            "rgb(" + oddRowBackground.getRed() + "," + //NOI18N
                                     oddRowBackground.getGreen() + "," + //NOI18N
                                     oddRowBackground.getBlue() + ")"; //NOI18N

                    sb.append("<table border='0' width='100%'>"); // NOI18N

                    try {
                        analysisRunning.compareAndSet(false, true);
                        queryController.queryStarted(progressModel);
                        progressUpdater.submit(new ProgressUpdater(progressModel));
                        engine.executeQuery(oqlQuery, new ObjectVisitor() {

                            public boolean visit(Object o) {
                                sb.append(oddRow[0] ?
                                    "<tr><td style='background-color: " + // NOI18N
                                    oddRowBackgroundString + ";'>" : "<tr><td>"); // NOI18N
                                oddRow[0] = !oddRow[0];
                                dump(o, sb);
                                sb.append("</td></tr>"); // NOI18N
                                return counter.decrementAndGet() == 0 || (!analysisRunning.get() && !engine.isCancelled()); // process all hits while the analysis is running
                            }
                        });

                        if (counter.get() == 0) {
                            sb.append("<tr><td><h4>");  // NOI18N
                            sb.append(NbBundle.getMessage(OQLController.class, "OQL_TOO_MANY_RESULTS_MSG"));      // NOI18N
                            sb.append("</h4></td></tr>");   // NOI18N
                        } else if (counter.get() == RESULTS_LIMIT) {
                            sb.append("<tr><td><h4>"); // NOI18N
                            sb.append(NbBundle.getMessage(OQLController.class, "OQL_NO_RESULTS_MSG")); // NOI18N
                            sb.append("</h4></td></tr>" ); // NOI18N
                        }

                        sb.append("</table>"); // NOI18N

                        resultsController.setResult(sb.toString());
                        finalizeQuery();
                    } catch (OQLException oQLException) {
                        StringBuilder errorMessage = new StringBuilder();
                        errorMessage.append("<h2>").append(NbBundle.getMessage(OQLController.class, "OQL_QUERY_ERROR")).append("</h2>"); // NOI18N
                        errorMessage.append(NbBundle.getMessage(OQLController.class, "OQL_QUERY_PLZ_CHECK")); // NOI18N
                        errorMessage.append("<hr>"); // noi18n
                        errorMessage.append(oQLException.getLocalizedMessage().replace("\n", "<br>").replace("\r", "<br>"));
                        resultsController.setResult(errorMessage.toString());
                        finalizeQuery();
                    }
                }

            });
        }
    });
}
 
Example #12
Source File: RConsoleView.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private void executeQueryImpl(final String rQuery) {
        Color b = graphsPanel.getBackground();
        final String rgb = "rgb(" + b.getRed() + ", " + b.getGreen() + ", " + b.getBlue() + ", maxColorValue = 255)";
        
        final BoundedRangeModel progressModel = new DefaultBoundedRangeModel(0, 10, 0, 100);

//        SwingUtilities.invokeLater(new Runnable() {
//            public void run() {
                new RequestProcessor("R Query Processor").post(new Runnable() { // NOI18N
                    public void run() {
                        final AtomicInteger counter = new AtomicInteger(100);
                        progressModel.setMaximum(100);

                        final StringBuilder sb = new StringBuilder();
                        final boolean[] oddRow = new boolean[1];
                        Color oddRowBackground = UIUtils.getDarker(
                                        UIUtils.getProfilerResultsBackground());
                        final String oddRowBackgroundString =
                                "rgb(" + oddRowBackground.getRed() + "," + //NOI18N
                                         oddRowBackground.getGreen() + "," + //NOI18N
                                         oddRowBackground.getBlue() + ")"; //NOI18N

                        sb.append("<table border='0' width='100%'>"); // NOI18N

                        try {
                            analysisRunning.compareAndSet(false, true);
                            queryStarted(progressModel);
                            progressUpdater.submit(new ProgressUpdater(progressModel));
                            
                            Context rContext = engine.getContext();
                            
                            Image rImage = graphsPanel.createPlotImage();
                            Graphics rGraphics = rImage.getGraphics();
                            int rImageW = rImage.getWidth(graphsPanel);
                            int rImageH = rImage.getHeight(graphsPanel);
                            
                            Boolean renderingQuality = graphsPanel.getRenderingQuality();
                            if (renderingQuality != null && rGraphics instanceof Graphics2D) {
                                Graphics2D g2 = (Graphics2D)rGraphics;
                                Object antialiasing = renderingQuality ? RenderingHints.VALUE_ANTIALIAS_ON :
                                                                         RenderingHints.VALUE_ANTIALIAS_OFF;
                                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasing);
                                Object text_antialiasing = renderingQuality ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON :
                                                                              RenderingHints.VALUE_TEXT_ANTIALIAS_OFF;
                                g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, text_antialiasing);
                            }
                            
                            rContext.eval("R", "function(g, w, h) { grDevices:::awt(w, h, g); }").execute(rGraphics, rImageW, rImageH);
                            
                            rContext.eval("R","library(grid); grid.rect(width = 1, height = 1, gp = gpar(col = " + rgb + ", fill = " + rgb + "));");
                            
                            engine.executeQuery(rQuery, new ObjectVisitor() {
                                public boolean visit(Object o) {
                                    sb.append(oddRow[0] ?
                                        "<tr><td style='background-color: " + // NOI18N
                                        oddRowBackgroundString + ";'>" : "<tr><td>"); // NOI18N
                                    oddRow[0] = !oddRow[0];
                                    dump(o, sb);
                                    sb.append("</td></tr>"); // NOI18N
                                    return counter.decrementAndGet() == 0 || (!analysisRunning.get() && !engine.isCancelled()); // process all hits while the analysis is running
                                }
                            });
                            
                            rContext.eval("R","dev.off();");
                            rGraphics.dispose();
                            
                            graphsPanel.repaint();

                            if (counter.get() == 0) {
                                sb.append("<tr><td>");  // NOI18N
                                sb.append("&lt;too many results&gt");      // NOI18N
                                sb.append("</td></tr>");   // NOI18N
                            } else if (counter.get() == 100) {
                                sb.append("<tr><td>"); // NOI18N
                                sb.append("&lt;no results&gt"); // NOI18N
                                sb.append("</td></tr>" ); // NOI18N
                            }

                            sb.append("</table>"); // NOI18N

                            finalizeQuery(sb.toString());
                        } catch (Exception oQLException) {
                            LOGGER.log(Level.INFO, "Error executing R", oQLException);   // NOI18N
                            StringBuilder errorMessage = new StringBuilder();
                            String exceptionMsg = oQLException.getLocalizedMessage();
                            errorMessage.append("<h2>").append("Query error").append("</h2>"); // NOI18N
                            errorMessage.append("Bad R query"); // NOI18N
                            errorMessage.append("<hr>"); // NOI18N
                            if (exceptionMsg != null) {
                                errorMessage.append(exceptionMsg.replace("\n", "<br>").replace("\r", "<br>"));  // NOI18N
                            }
                            finalizeQuery(errorMessage.toString());
                        }
                    }

                });
//            }
//        });
    }
 
Example #13
Source File: HeapProgress.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private ModelInfo() {
    model = new DefaultBoundedRangeModel(0,0,0,PROGRESS_MAX);
}
 
Example #14
Source File: JComponentBuilders.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
protected DefaultBoundedRangeModel createInstanceImpl() {
    return new DefaultBoundedRangeModel(value, extent, min, max);
}
 
Example #15
Source File: JComponentBuilders.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
static DefaultBoundedRangeModelBuilder fromField(Instance instance, String field, Heap heap) {
    Object model = instance.getValueOfField(field);
    if (!(model instanceof Instance)) return null;
    if (!DetailsUtils.isSubclassOf((Instance)model, DefaultBoundedRangeModel.class.getName())) return null;
    return new DefaultBoundedRangeModelBuilder((Instance)model, heap);
}
 
Example #16
Source File: OQLController.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private void executeQueryImpl(final String oqlQuery) {
    final BoundedRangeModel progressModel = new DefaultBoundedRangeModel(0, 10, 0, 100);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            BrowserUtils.performTask(new Runnable() {
                public void run() {
                    final AtomicInteger counter = new AtomicInteger(RESULTS_LIMIT);
                    progressModel.setMaximum(100);

                    final StringBuilder sb = new StringBuilder();
                    final boolean[] oddRow = new boolean[1];
                    Color oddRowBackground = UIUtils.getDarker(
                                    UIUtils.getProfilerResultsBackground());
                    final String oddRowBackgroundString =
                            "rgb(" + oddRowBackground.getRed() + "," + //NOI18N
                                     oddRowBackground.getGreen() + "," + //NOI18N
                                     oddRowBackground.getBlue() + ")"; //NOI18N

                    sb.append("<table border='0' width='100%'>"); // NOI18N

                    try {
                        analysisRunning.compareAndSet(false, true);
                        queryController.queryStarted(progressModel);
                        progressUpdater.submit(new ProgressUpdater(progressModel));
                        engine.executeQuery(oqlQuery, new ObjectVisitor() {

                            public boolean visit(Object o) {
                                sb.append(oddRow[0] ?
                                    "<tr><td style='background-color: " + // NOI18N
                                    oddRowBackgroundString + ";'>" : "<tr><td>"); // NOI18N
                                oddRow[0] = !oddRow[0];
                                dump(o, sb);
                                sb.append("</td></tr>"); // NOI18N
                                return counter.decrementAndGet() == 0 || (!analysisRunning.get() && !engine.isCancelled()); // process all hits while the analysis is running
                            }
                        });

                        if (counter.get() == 0) {
                            sb.append("<tr><td><h4>");  // NOI18N
                            sb.append(NbBundle.getMessage(OQLController.class, "OQL_TOO_MANY_RESULTS_MSG"));      // NOI18N
                            sb.append("</h4></td></tr>");   // NOI18N
                        } else if (counter.get() == RESULTS_LIMIT) {
                            sb.append("<tr><td><h4>"); // NOI18N
                            sb.append(NbBundle.getMessage(OQLController.class, "OQL_NO_RESULTS_MSG")); // NOI18N
                            sb.append("</h4></td></tr>" ); // NOI18N
                        }

                        sb.append("</table>"); // NOI18N

                        resultsController.setResult(sb.toString());
                        finalizeQuery();
                    } catch (OQLException oQLException) {
                        StringBuilder errorMessage = new StringBuilder();
                        errorMessage.append("<h2>").append(NbBundle.getMessage(OQLController.class, "OQL_QUERY_ERROR")).append("</h2>"); // NOI18N
                        errorMessage.append(NbBundle.getMessage(OQLController.class, "OQL_QUERY_PLZ_CHECK")); // NOI18N
                        errorMessage.append("<hr>"); // noi18n
                        errorMessage.append(oQLException.getLocalizedMessage().replace("\n", "<br>").replace("\r", "<br>"));
                        resultsController.setResult(errorMessage.toString());
                        finalizeQuery();
                    }
                }

            });
        }
    });
}
 
Example #17
Source File: PropertySliderValueBinding.java    From pgptool with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void unbind() {
	slider.setModel(new DefaultBoundedRangeModel());
}
 
Example #18
Source File: HeapProgress.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private ModelInfo() {
    model = new DefaultBoundedRangeModel(0,0,0,PROGRESS_MAX);
}
 
Example #19
Source File: JComponentBuilders.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected DefaultBoundedRangeModel createInstanceImpl() {
    return new DefaultBoundedRangeModel(value, extent, min, max);
}
 
Example #20
Source File: JComponentBuilders.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static DefaultBoundedRangeModelBuilder fromField(Instance instance, String field, Heap heap) {
    Object model = instance.getValueOfField(field);
    if (!(model instanceof Instance)) return null;
    if (!DetailsUtils.isSubclassOf((Instance)model, DefaultBoundedRangeModel.class.getName())) return null;
    return new DefaultBoundedRangeModelBuilder((Instance)model, heap);
}