Example usage for javax.swing JScrollBar setMaximum

List of usage examples for javax.swing JScrollBar setMaximum

Introduction

In this page you can find the example usage for javax.swing JScrollBar setMaximum.

Prototype

@BeanProperty(bound = false, preferred = true, description = "The scrollbar's maximum value.")
public void setMaximum(int maximum) 

Source Link

Document

Sets the model's maximum property.

Usage

From source file:org.datacleaner.widgets.result.DateGapAnalyzerResultSwingRenderer.java

@Override
public JComponent render(DateGapAnalyzerResult result) {

    final TaskSeriesCollection dataset = new TaskSeriesCollection();
    final Set<String> groupNames = result.getGroupNames();
    final TaskSeries completeDurationTaskSeries = new TaskSeries(LABEL_COMPLETE_DURATION);
    final TaskSeries gapsTaskSeries = new TaskSeries(LABEL_GAPS);
    final TaskSeries overlapsTaskSeries = new TaskSeries(LABEL_OVERLAPS);
    for (final String groupName : groupNames) {
        final String groupDisplayName;

        if (groupName == null) {
            if (groupNames.size() == 1) {
                groupDisplayName = "All";
            } else {
                groupDisplayName = LabelUtils.NULL_LABEL;
            }//from w ww  . ja  v a  2 s.  c o  m
        } else {
            groupDisplayName = groupName;
        }

        final TimeInterval completeDuration = result.getCompleteDuration(groupName);
        final Task completeDurationTask = new Task(groupDisplayName,
                createTimePeriod(completeDuration.getFrom(), completeDuration.getTo()));
        completeDurationTaskSeries.add(completeDurationTask);

        // plot gaps
        {
            final SortedSet<TimeInterval> gaps = result.getGaps(groupName);

            int i = 1;
            Task rootTask = null;
            for (TimeInterval interval : gaps) {
                final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo());

                if (rootTask == null) {
                    rootTask = new Task(groupDisplayName, timePeriod);
                    gapsTaskSeries.add(rootTask);
                } else {
                    Task task = new Task(groupDisplayName + " gap" + i, timePeriod);
                    rootTask.addSubtask(task);
                }

                i++;
            }
        }

        // plot overlaps
        {
            final SortedSet<TimeInterval> overlaps = result.getOverlaps(groupName);

            int i = 1;
            Task rootTask = null;
            for (TimeInterval interval : overlaps) {
                final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo());

                if (rootTask == null) {
                    rootTask = new Task(groupDisplayName, timePeriod);
                    overlapsTaskSeries.add(rootTask);
                } else {
                    Task task = new Task(groupDisplayName + " overlap" + i, timePeriod);
                    rootTask.addSubtask(task);
                }

                i++;
            }
        }
    }
    dataset.add(overlapsTaskSeries);
    dataset.add(gapsTaskSeries);
    dataset.add(completeDurationTaskSeries);

    final SlidingGanttCategoryDataset slidingDataset = new SlidingGanttCategoryDataset(dataset, 0,
            GROUPS_VISIBLE);

    final JFreeChart chart = ChartFactory.createGanttChart(
            "Date gaps and overlaps in " + result.getFromColumnName() + " / " + result.getToColumnName(),
            result.getGroupColumnName(), "Time", slidingDataset, true, true, false);
    ChartUtils.applyStyles(chart);

    // make sure the 3 timeline types have correct coloring
    {
        final CategoryPlot plot = (CategoryPlot) chart.getPlot();

        plot.setDrawingSupplier(new DCDrawingSupplier(WidgetUtils.ADDITIONAL_COLOR_GREEN_BRIGHT,
                WidgetUtils.ADDITIONAL_COLOR_RED_BRIGHT, WidgetUtils.BG_COLOR_BLUE_BRIGHT));
    }

    final int visibleLines = Math.min(GROUPS_VISIBLE, groupNames.size());
    final ChartPanel chartPanel = ChartUtils.createPanel(chart, ChartUtils.WIDTH_WIDE, visibleLines * 50 + 200);

    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
            ChartEntity entity = event.getEntity();
            if (entity instanceof PlotEntity) {
                cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
            }
            chartPanel.setCursor(cursor);
        }

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            // do nothing
        }
    });

    final JComponent decoratedChartPanel;

    final StringBuilder chartDescription = new StringBuilder("<html>");
    chartDescription.append("<p>The chart displays the recorded timeline based on FROM and TO dates.</p>");
    chartDescription.append(
            "<p>The <b>red items</b> represent gaps in the timeline and the <b>green items</b> represent points in the timeline where more than one record show activity.</p>");
    chartDescription.append(
            "<p>You can <b>zoom in</b> by clicking and dragging the area that you want to examine in further detail.</p>");

    if (groupNames.size() > GROUPS_VISIBLE) {
        final JScrollBar scroll = new JScrollBar(JScrollBar.VERTICAL);
        scroll.setMinimum(0);
        scroll.setMaximum(groupNames.size());
        scroll.addAdjustmentListener(new AdjustmentListener() {

            @Override
            public void adjustmentValueChanged(AdjustmentEvent e) {
                int value = e.getAdjustable().getValue();
                slidingDataset.setFirstCategoryIndex(value);
            }
        });

        chartPanel.addMouseWheelListener(new MouseWheelListener() {

            @Override
            public void mouseWheelMoved(MouseWheelEvent e) {
                int scrollType = e.getScrollType();
                if (scrollType == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
                    int wheelRotation = e.getWheelRotation();
                    scroll.setValue(scroll.getValue() + wheelRotation);
                }
            }
        });

        final DCPanel outerPanel = new DCPanel();
        outerPanel.setLayout(new BorderLayout());
        outerPanel.add(chartPanel, BorderLayout.CENTER);
        outerPanel.add(scroll, BorderLayout.EAST);
        chartDescription.append("<p>Use the right <b>scrollbar</b> to scroll up and down on the chart.</p>");
        decoratedChartPanel = outerPanel;
    } else {
        decoratedChartPanel = chartPanel;
    }

    chartDescription.append("</html>");

    final JLabel chartDescriptionLabel = new JLabel(chartDescription.toString());

    final DCPanel panel = new DCPanel();
    panel.setLayout(new VerticalLayout());
    panel.add(chartDescriptionLabel);
    panel.add(decoratedChartPanel);

    return panel;
}

From source file:org.eobjects.datacleaner.widgets.result.DateGapAnalyzerResultSwingRenderer.java

@Override
public JComponent render(DateGapAnalyzerResult result) {

    final TaskSeriesCollection dataset = new TaskSeriesCollection();
    final Set<String> groupNames = result.getGroupNames();
    final TaskSeries completeDurationTaskSeries = new TaskSeries(LABEL_COMPLETE_DURATION);
    final TaskSeries gapsTaskSeries = new TaskSeries(LABEL_GAPS);
    final TaskSeries overlapsTaskSeries = new TaskSeries(LABEL_OVERLAPS);
    for (final String groupName : groupNames) {
        final String groupDisplayName;

        if (groupName == null) {
            if (groupNames.size() == 1) {
                groupDisplayName = "All";
            } else {
                groupDisplayName = LabelUtils.NULL_LABEL;
            }//from  ww  w. j  ava  2  s .c o m
        } else {
            groupDisplayName = groupName;
        }

        final TimeInterval completeDuration = result.getCompleteDuration(groupName);
        final Task completeDurationTask = new Task(groupDisplayName,
                createTimePeriod(completeDuration.getFrom(), completeDuration.getTo()));
        completeDurationTaskSeries.add(completeDurationTask);

        // plot gaps
        {
            final SortedSet<TimeInterval> gaps = result.getGaps(groupName);

            int i = 1;
            Task rootTask = null;
            for (TimeInterval interval : gaps) {
                final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo());

                if (rootTask == null) {
                    rootTask = new Task(groupDisplayName, timePeriod);
                    gapsTaskSeries.add(rootTask);
                } else {
                    Task task = new Task(groupDisplayName + " gap" + i, timePeriod);
                    rootTask.addSubtask(task);
                }

                i++;
            }
        }

        // plot overlaps
        {
            final SortedSet<TimeInterval> overlaps = result.getOverlaps(groupName);

            int i = 1;
            Task rootTask = null;
            for (TimeInterval interval : overlaps) {
                final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo());

                if (rootTask == null) {
                    rootTask = new Task(groupDisplayName, timePeriod);
                    overlapsTaskSeries.add(rootTask);
                } else {
                    Task task = new Task(groupDisplayName + " overlap" + i, timePeriod);
                    rootTask.addSubtask(task);
                }

                i++;
            }
        }
    }
    dataset.add(overlapsTaskSeries);
    dataset.add(gapsTaskSeries);
    dataset.add(completeDurationTaskSeries);

    final SlidingGanttCategoryDataset slidingDataset = new SlidingGanttCategoryDataset(dataset, 0,
            GROUPS_VISIBLE);

    final JFreeChart chart = ChartFactory.createGanttChart(
            "Date gaps and overlaps in " + result.getFromColumnName() + " / " + result.getToColumnName(),
            result.getGroupColumnName(), "Time", slidingDataset, true, true, false);
    ChartUtils.applyStyles(chart);

    // make sure the 3 timeline types have correct coloring
    {
        final CategoryPlot plot = (CategoryPlot) chart.getPlot();

        plot.setDrawingSupplier(new DCDrawingSupplier(WidgetUtils.ADDITIONAL_COLOR_GREEN_BRIGHT,
                WidgetUtils.ADDITIONAL_COLOR_RED_BRIGHT, WidgetUtils.BG_COLOR_BLUE_BRIGHT));
    }

    final ChartPanel chartPanel = new ChartPanel(chart);

    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
            ChartEntity entity = event.getEntity();
            if (entity instanceof PlotEntity) {
                cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
            }
            chartPanel.setCursor(cursor);
        }

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            // do nothing
        }
    });

    final int visibleLines = Math.min(GROUPS_VISIBLE, groupNames.size());

    chartPanel.setPreferredSize(new Dimension(0, visibleLines * 50 + 200));

    final JComponent decoratedChartPanel;

    StringBuilder chartDescription = new StringBuilder();
    chartDescription
            .append("<html><p>The chart displays the recorded timeline based on FROM and TO dates.<br/><br/>");
    chartDescription.append(
            "The <b>red items</b> represent gaps in the timeline and the <b>green items</b> represent points in the timeline where more than one record show activity.<br/><br/>");
    chartDescription.append(
            "You can <b>zoom in</b> by clicking and dragging the area that you want to examine in further detail.");

    if (groupNames.size() > GROUPS_VISIBLE) {
        final JScrollBar scroll = new JScrollBar(JScrollBar.VERTICAL);
        scroll.setMinimum(0);
        scroll.setMaximum(groupNames.size());
        scroll.addAdjustmentListener(new AdjustmentListener() {

            @Override
            public void adjustmentValueChanged(AdjustmentEvent e) {
                int value = e.getAdjustable().getValue();
                slidingDataset.setFirstCategoryIndex(value);
            }
        });

        chartPanel.addMouseWheelListener(new MouseWheelListener() {

            @Override
            public void mouseWheelMoved(MouseWheelEvent e) {
                int scrollType = e.getScrollType();
                if (scrollType == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
                    int wheelRotation = e.getWheelRotation();
                    scroll.setValue(scroll.getValue() + wheelRotation);
                }
            }
        });

        final DCPanel outerPanel = new DCPanel();
        outerPanel.setLayout(new BorderLayout());
        outerPanel.add(chartPanel, BorderLayout.CENTER);
        outerPanel.add(scroll, BorderLayout.EAST);
        chartDescription.append("<br/><br/>Use the right <b>scrollbar</b> to scroll up and down on the chart.");
        decoratedChartPanel = outerPanel;

    } else {
        decoratedChartPanel = chartPanel;
    }

    chartDescription.append("</p></html>");

    final JLabel chartDescriptionLabel = new JLabel(chartDescription.toString());

    chartDescriptionLabel.setBorder(new EmptyBorder(4, 10, 4, 10));

    final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.add(decoratedChartPanel);
    split.add(chartDescriptionLabel);
    split.setDividerLocation(550);

    return split;
}

From source file:com.att.aro.ui.view.waterfalltab.WaterfallPanel.java

/**
 * Refreshes the waterfall display with the specified analysis data
 * @param Analyzed data from aro core.//from w ww.j a v a 2  s .  co  m
 */
public void refresh(AROTraceData aModel) {

    this.popup.refresh(null, 0);
    this.popup.setVisible(false);

    double range = DEFAULT_TIMELINE;

    // Create sorted list of request/response pairs
    List<WaterfallCategory> categoryList = new ArrayList<WaterfallCategory>();

    if (aModel != null && aModel.getAnalyzerResult() != null) {
        this.traceDuration = aModel.getAnalyzerResult().getTraceresult().getTraceDuration();

        // add 20% to make sure labels close to the right edge of the screen are visible
        this.traceDuration *= 1.2;
        range = Math.min(this.traceDuration, DEFAULT_TIMELINE);

        for (Session tcpSession : aModel.getAnalyzerResult().getSessionlist()) {
            Session thisSession = tcpSession;
            if (!tcpSession.isUDP()) {
                for (HttpRequestResponseInfo reqResInfo : tcpSession.getRequestResponseInfo()) {
                    if (reqResInfo.getDirection() == HttpDirection.REQUEST
                            && reqResInfo.getWaterfallInfos() != null) {
                        categoryList.add(new WaterfallCategory(reqResInfo, thisSession));
                    }
                }

            }

        }

        // Sort and set index
        Collections.sort(categoryList);
        int index = 0;
        for (WaterfallCategory wCategory : categoryList) {
            wCategory.setIndex(++index);
        }

    }

    // Horizontal scroll bar used to scroll through trace duration
    JScrollBar hScrollBar = getHorizontalScroll();
    hScrollBar.setMaximum((int) Math.ceil(this.traceDuration));

    // Set the visible time range
    setTimeRange(0, range);

    CategoryAxis cAxis = getCategoryAxis();
    cAxis.clearCategoryLabelToolTips();

    // Build the dataset
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    for (WaterfallCategory wfc : categoryList) {
        RequestResponseTimeline rrTimeLine = wfc.getReqResp().getWaterfallInfos();

        underlying.addValue(rrTimeLine.getStartTime(), Waterfall.BEFORE, wfc);
        underlying.addValue(rrTimeLine.getDnsLookupDuration(), Waterfall.DNS_LOOKUP, wfc);
        underlying.addValue(rrTimeLine.getInitialConnDuration(), Waterfall.INITIAL_CONNECTION, wfc);
        underlying.addValue(rrTimeLine.getSslNegotiationDuration(), Waterfall.SSL_NEGOTIATION, wfc);
        underlying.addValue(rrTimeLine.getRequestDuration(), Waterfall.REQUEST_TIME, wfc);
        underlying.addValue(rrTimeLine.getTimeToFirstByte(), Waterfall.TIME_TO_FIRST_BYTE, wfc);
        underlying.addValue(rrTimeLine.getContentDownloadDuration(), Waterfall.CONTENT_DOWNLOAD, wfc);
        underlying.addValue(null, Waterfall.HTTP_3XX_REDIRECTION, wfc);
        underlying.addValue(null, Waterfall.HTTP_4XX_CLIENTERROR, wfc);

        int code = wfc.getReqResp().getAssocReqResp().getStatusCode();
        double endTime = this.traceDuration - rrTimeLine.getStartTime() - rrTimeLine.getTotalTime();
        if (code >= 300 && code < 400) {
            underlying.addValue(endTime, Waterfall.AFTER_3XX, wfc);
        } else if (code >= 400) {
            underlying.addValue(endTime, Waterfall.AFTER_4XX, wfc);
        } else {
            underlying.addValue(endTime, Waterfall.AFTER, wfc);
        }

        cAxis.addCategoryLabelToolTip(wfc, wfc.getTooltip());
    }

    // Vertical scroll bar is used to scroll through data
    JScrollBar vScrollBar = getVerticalScroll();
    int count = underlying.getColumnCount();
    vScrollBar.setValue(0);
    vScrollBar.setMaximum(count);
    vScrollBar.setVisibleAmount(count > 0 ? this.dataset.getMaximumCategoryCount() - 1 / count : 1);

    // Add the dataset to the plot
    CategoryPlot plot = getChartPanel().getChart().getCategoryPlot();
    this.dataset = new SlidingCategoryDataset(underlying, 0, CATEGORY_MAX_COUNT);
    plot.setDataset(this.dataset);

    // Place proper colors on renderer for waterfall states
    final CategoryItemRenderer renderer = plot.getRenderer();
    for (Object obj : underlying.getRowKeys()) {
        Waterfall wFall = (Waterfall) obj;
        int index = underlying.getRowIndex(wFall);

        Color paint;
        switch (wFall) {
        case DNS_LOOKUP:
            paint = dnsLoolupColor;
            break;
        case INITIAL_CONNECTION:
            paint = initiaConnColor;
            break;
        case SSL_NEGOTIATION:
            paint = sslNegColor;
            break;
        case REQUEST_TIME:
            paint = requestTimeColor;
            break;
        case TIME_TO_FIRST_BYTE:
            paint = firstByteTimeColor;
            break;
        case CONTENT_DOWNLOAD:
            paint = contentDownloadColor;
            break;
        case AFTER_3XX:
            paint = noneColor;
            renderer.setSeriesItemLabelPaint(index, threexColor);
            renderer.setSeriesVisibleInLegend(index, false);
            break;
        case AFTER_4XX:
            paint = noneColor;
            renderer.setSeriesItemLabelPaint(index, fourxColor);
            renderer.setSeriesVisibleInLegend(index, false);
            break;
        case HTTP_3XX_REDIRECTION:
            paint = threexColor;
            break;
        case HTTP_4XX_CLIENTERROR:
            paint = fourxColor;
            break;
        default:
            renderer.setSeriesItemLabelPaint(index, Color.black);
            renderer.setSeriesVisibleInLegend(index, false);
            paint = noneColor;
        }
        renderer.setSeriesPaint(index, paint);
    }

    // Adding the label at the end of bars
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public String generateLabel(CategoryDataset dataset, int row, int column) {
            if (Waterfall.AFTER == dataset.getRowKey(row) || Waterfall.AFTER_3XX == dataset.getRowKey(row)
                    || Waterfall.AFTER_4XX == dataset.getRowKey(row)) {
                WaterfallCategory waterfallItem = (WaterfallCategory) dataset.getColumnKey(column);

                RequestResponseTimeline waterfallInfos = waterfallItem.getReqResp().getWaterfallInfos();
                DecimalFormat formatter = new DecimalFormat("#.##");
                int code = waterfallItem.getReqResp().getAssocReqResp().getStatusCode();
                return MessageFormat.format(ResourceBundleHelper.getMessageString("waterfall.totalTime"),
                        formatter.format(waterfallInfos.getTotalTime()),
                        code > 0 ? waterfallItem.getReqResp().getScheme() + " " + code
                                : ResourceBundleHelper.getMessageString("waterfall.unknownCode"));
            }

            return null;
        }
    });

}

From source file:savant.view.variation.swing.VariationModule.java

public void visibleRangeChanged(String ref, Range r) {
    if (r.getLength() > ResolutionSettings.getVariantLowToHighThreshold()) {
        showMessage(ZOOM_MESSAGE);/* w  w w .  j a  v  a  2s  . co  m*/
    } else {
        try {
            // Detach the adjustment listeners so that setting the maximum doesn't fire an event.
            for (JScrollBar sb : scrollers) {
                sb.removeAdjustmentListener(scrollerListener);
            }

            for (JScrollBar sb : scrollers) {
                sb.setMaximum(LocationController.getInstance().getMaxRangeEnd());
                sb.setValue(r.getFrom());
                sb.setVisibleAmount(r.getLength());
                sb.setBlockIncrement(r.getLength());
                sb.repaint();
            }
        } finally {
            // Reattach the adjustment listeners.
            for (JScrollBar sb : scrollers) {
                sb.addAdjustmentListener(scrollerListener);
            }
        }
    }
    rangeField.setText(String.format("%s:%d-%d", ref, r.getFrom(), r.getTo()));
}