Example usage for java.awt.event AdjustmentEvent getAdjustable

List of usage examples for java.awt.event AdjustmentEvent getAdjustable

Introduction

In this page you can find the example usage for java.awt.event AdjustmentEvent getAdjustable.

Prototype

public Adjustable getAdjustable() 

Source Link

Document

Returns the Adjustable object where this event originated.

Usage

From source file:Main.java

private static void dumpInfo(AdjustmentEvent e) {
    System.out.println("getAdjustable: " + e.getAdjustable());
}

From source file:Main.java

public void adjustmentValueChanged(AdjustmentEvent evt) {
    Adjustable source = evt.getAdjustable();
    if (evt.getValueIsAdjusting()) {
        return;/*from   ww  w. ja va  2  s .c  o m*/
    }
    int orient = source.getOrientation();
    if (orient == Adjustable.HORIZONTAL) {
        System.out.println("from horizontal scrollbar");
    } else {
        System.out.println("from vertical scrollbar");
    }
    int type = evt.getAdjustmentType();
    switch (type) {
    case AdjustmentEvent.UNIT_INCREMENT:
        System.out.println("Scrollbar was increased by one unit");
        break;
    case AdjustmentEvent.UNIT_DECREMENT:
        System.out.println("Scrollbar was decreased by one unit");
        break;
    case AdjustmentEvent.BLOCK_INCREMENT:
        System.out.println("Scrollbar was increased by one block");
        break;
    case AdjustmentEvent.BLOCK_DECREMENT:
        System.out.println("Scrollbar was decreased by one block");
        break;
    case AdjustmentEvent.TRACK:
        System.out.println("The knob on the scrollbar was dragged");
        break;
    }
    int value = evt.getValue();
}

From source file:tw.edu.sju.ee.eea.module.iepe.file.IepeVoltageElement.java

public IepeVoltageElement(Lookup lkp) {
    info = lkp.lookup(IepeDataInfo.class);
    assert info != null;

    index = 0;//from   w w w.  j a  va 2 s  . c o m
    length = 10000;

    cursor = new ValueMarker(0);
    cursor.setPaint(Color.black);
    initComponents();
    scrollBar.setMaximum(total);
    scrollLength();
    ((ChartPanel) chartPanel).addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            chartMouseClicked = true;
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        }
    });
    scrollBar.addAdjustmentListener(new AdjustmentListener() {

        @Override
        public void adjustmentValueChanged(AdjustmentEvent e) {
            if (chartScroll) {
                index = e.getAdjustable().getValue();
                length = e.getAdjustable().getVisibleAmount();
                repaintChart();
            }
        }
    });
    info.getCursor().addIepeCursorListener(new IepeCursorListener() {

        @Override
        public void cursorMoved(IepeCursorEvent e) {
            cursor.setValue(e.getTime());
            double tmp = cursor.getValue() - index;
            if (tmp < 0 || tmp > length) {
                index = (int) (cursor.getValue() - (length * 0.05));
                scrollIndex();
            }
        }
    });
}

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 a2s .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 w w w .  ja  va  2  s .  c om*/
        } 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:brainleg.app.intellij.ui.EForm.java

private void configureHtmlPane() {
    if (htmlPane == null) {
        htmlPane = new JEditorPane();

        htmlPane.setEditable(false);//from   w ww. java2s.  c  o m

        HTMLEditorKit kit = new HTMLEditorKit();
        htmlPane.setEditorKit(kit);

        JScrollPane scrollPane = new JBScrollPane(htmlPane);

        scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
            public void adjustmentValueChanged(AdjustmentEvent e) {
                Adjustable source = e.getAdjustable();

                // check if user is currently dragging the scrollbar's knob
                if (e.getValueIsAdjusting()) {
                    return;
                }

                int orient = source.getOrientation();
                if (orient == Adjustable.HORIZONTAL) {
                    return; //we are not interested in horizontal scroll
                }

                // get the type of adjustment which caused the value changed event
                int type = e.getAdjustmentType();
                switch (type) {
                case AdjustmentEvent.UNIT_INCREMENT:
                    //                            System.out.println("increased by one unit");
                    break;

                case AdjustmentEvent.UNIT_DECREMENT:
                    //                            System.out.println("decreased by one unit");
                    break;

                case AdjustmentEvent.BLOCK_INCREMENT:
                    //                            System.out.println("increased by one block");
                    break;

                case AdjustmentEvent.BLOCK_DECREMENT:
                    //                            System.out.println("decreased by one block");
                    break;

                case AdjustmentEvent.TRACK:
                    //                            System.out.println("knob on the scrollbar was dragged");
                    break;

                }

                // get the current value in the adjustment event
                int value = e.getValue();
                //                    System.out.println("Current Value: " + value);
                if (value > 200) {
                    //this is about click middle mouse flip - i.e. about 15% of vertical space (approx)
                    markExceptionAsDontShowNotificationFor();
                }
            }
        });

        StyleSheet styleSheet = kit.getStyleSheet();
        CssUtil.addStyles(styleSheet);

        configureNewHtmlDocument();

        htmlPane.addHyperlinkListener(new HyperlinkListener() {
            public void hyperlinkUpdate(HyperlinkEvent e) {
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    try {
                        URL url = e.getURL();
                        if (url != null) {
                            BrowserUtil.launchBrowser(url.toString());
                        }
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            }
        });
        solutionPanel.add(scrollPane);
    }
}

From source file:br.com.bgslibrary.gui.MainFrame.java

private void autoscroll() {
    if (autoscrollCheckBox.isSelected()) {
        adjustmentListener = new AdjustmentListener() {
            @Override/*from  w ww  .j a  v a2  s . c o m*/
            public void adjustmentValueChanged(AdjustmentEvent e) {
                e.getAdjustable().setValue(e.getAdjustable().getMaximum());
            }
        };

        logTextScrollPane.getVerticalScrollBar().addAdjustmentListener(adjustmentListener);
    } else
        logTextScrollPane.getVerticalScrollBar().removeAdjustmentListener(adjustmentListener);
}