Example usage for org.jfree.chart ChartPanel setCursor

List of usage examples for org.jfree.chart ChartPanel setCursor

Introduction

In this page you can find the example usage for org.jfree.chart ChartPanel setCursor.

Prototype

public void setCursor(Cursor cursor) 

Source Link

Document

Sets the cursor image to the specified cursor.

Usage

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. j a  v  a  2s  . 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: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;
            }/*  w  w w  .  ja  va  2s  .  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:jgnash.ui.report.compiled.IncomeExpensePieChart.java

private void setChartCursor(final ChartPanel chartPanel, final ChartEntity e, final Point point) {
    lastPoint = point;//  w  w w.j a  va  2s  . com

    EventQueue.invokeLater(new Runnable() {

        ChartEntity entity = e;

        @Override
        public void run() {
            if (entity == null && point != null) {
                entity = chartPanel.getEntityForPoint(lastPoint.x, lastPoint.y);
            }
            Account parent = currentAccount;
            if (entity instanceof PieSectionEntity) {
                // change cursor if section is interesting
                Account a = (Account) ((PieSectionEntity) entity).getSectionKey();
                if (a.getChildCount() > 0 && a != parent) {
                    chartPanel.setCursor(ZOOM_IN);
                } else {
                    chartPanel.setCursor(Cursor.getDefaultCursor());
                }
                return;
            } else if (entity == null && parent != null) {
                parent = parent.getParent();
                if (parent != null && !(parent instanceof RootAccount)) {
                    chartPanel.setCursor(ZOOM_OUT);
                    return;
                }
            }
            chartPanel.setCursor(Cursor.getDefaultCursor());
        }
    });
}

From source file:uk.ac.lkl.cram.ui.ModuleFrame.java

private JXTaskPane createLearnerFeedbackChartPane() {
    JXTaskPane feedbackChartPane = new JXTaskPane();
    feedbackChartPane.setScrollOnExpand(true);
    feedbackChartPane.setTitle("Learner Feedback");
    FeedbackChartMaker maker = new FeedbackChartMaker(module);
    final ChartPanel chartPanel = maker.getChartPanel();
    //Add a mouselistener, listening for a double click on a bar of the stacked bar
    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override//from www  . j  a v  a  2  s.c o  m
        public void chartMouseClicked(ChartMouseEvent cme) {
            //Get the mouse event
            MouseEvent trigger = cme.getTrigger();
            //Test if the mouse event is a left-button
            if (trigger.getButton() == MouseEvent.BUTTON1 && trigger.getClickCount() == 2) {

                //Create a pop up dialog containing that the tlalineitems
                FeedbackPopupDialog popup = new FeedbackPopupDialog(
                        (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, module.getTLALineItems());
                //Set the title of the popup 
                popup.setTitle("All Activities");
                //Centre the popup at the location of the mouse click
                Point location = trigger.getLocationOnScreen();
                int w = popup.getWidth();
                int h = popup.getHeight();
                popup.setLocation(location.x - w / 2, location.y - h / 2);
                popup.setVisible(true);
                int returnStatus = popup.getReturnStatus();
                if (returnStatus == LearningTypePopupDialog.RET_OK) {
                    modifyTLALineItem(popup.getSelectedTLALineItem(), 1);
                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent cme) {
            //Set the cursor shape according to the location of the cursor
            if (cme.getEntity() instanceof CategoryItemEntity) {
                chartPanel.setCursor(HAND);
            } else {
                chartPanel.setCursor(Cursor.getDefaultCursor());
            }
        }
    });
    chartPanel.setPreferredSize(new Dimension(150, 200));
    feedbackChartPane.add(chartPanel);
    return feedbackChartPane;
}

From source file:uk.ac.lkl.cram.ui.ModuleFrame.java

private JXTaskPane createLearningExperienceChartPane() {
    JXTaskPane experienceChartPane = new JXTaskPane();
    experienceChartPane.setScrollOnExpand(true);
    experienceChartPane.setTitle("Learning Experiences");
    final LearningExperienceChartMaker maker = new LearningExperienceChartMaker(module);
    final ChartPanel chartPanel = maker.getChartPanel();
    //Add a mouselistener, listening for a double click on a bar of the stacked bar
    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override/* ww  w. j ava 2  s. c o m*/
        public void chartMouseClicked(ChartMouseEvent cme) {
            //Get the mouse event
            MouseEvent trigger = cme.getTrigger();
            //Test if the mouse event is a left-button
            if (trigger.getButton() == MouseEvent.BUTTON1 && trigger.getClickCount() == 2) {
                //Get the selected segment of the pie
                CategoryItemEntity bar = (CategoryItemEntity) cme.getEntity();
                //Get the row key that corresponds to that segment--this is a learning experience
                String key = bar.getRowKey().toString();
                //Get the set of tlalineitems whose activity contains that learning type
                Set<TLALineItem> relevantTLAs = maker.getLearningExperienceMap().get(key);
                //Create a pop up dialog containing that set of tlalineitems
                LearningExperiencePopupDialog popup = new LearningExperiencePopupDialog(
                        (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, relevantTLAs);
                //Set the title of the popup to indicate which learning type was selected
                popup.setTitle("Activities with \'" + key + "\'");
                //Centre the popup at the location of the mouse click
                Point location = trigger.getLocationOnScreen();
                int w = popup.getWidth();
                int h = popup.getHeight();
                popup.setLocation(location.x - w / 2, location.y - h / 2);
                popup.setVisible(true);
                int returnStatus = popup.getReturnStatus();
                if (returnStatus == LearningTypePopupDialog.RET_OK) {
                    modifyTLALineItem(popup.getSelectedTLALineItem(), 0);
                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent cme) {
            //Set the cursor shape according to the location of the cursor
            if (cme.getEntity() instanceof CategoryItemEntity) {
                chartPanel.setCursor(HAND);
            } else {
                chartPanel.setCursor(Cursor.getDefaultCursor());
            }
        }
    });
    chartPanel.setPreferredSize(new Dimension(125, 75));
    chartPanel.setMinimumDrawHeight(75);
    experienceChartPane.add(chartPanel);
    return experienceChartPane;
}

From source file:uk.ac.lkl.cram.ui.ModuleFrame.java

private JXTaskPane createLearningTypeChartPane() {
    JXTaskPane typeChartPane = new JXTaskPane();
    typeChartPane.setTitle("Learning Types");
    typeChartPane.setScrollOnExpand(true);
    final LearningTypeChartMaker maker = new LearningTypeChartMaker(module);
    final ChartPanel chartPanel = maker.getChartPanel();
    //Add a mouse listener to the chart
    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override/*from  w w  w  . j  a v  a  2s  . c  om*/
        public void chartMouseClicked(ChartMouseEvent cme) {
            //Get the mouse event
            MouseEvent trigger = cme.getTrigger();
            //Test if the mouse event is a left-button
            if (trigger.getButton() == MouseEvent.BUTTON1 && trigger.getClickCount() == 2) {
                //Check that the mouse click is on a segment of the pie
                if (cme.getEntity() instanceof PieSectionEntity) {
                    //Get the selected segment of the pie
                    PieSectionEntity pieSection = (PieSectionEntity) cme.getEntity();
                    //Get the key that corresponds to that segment--this is a learning type
                    String key = pieSection.getSectionKey().toString();
                    //Get the set of tlalineitems whose activity contains that learning type
                    Set<TLALineItem> relevantTLAs = maker.getLearningTypeMap().get(key);
                    //Create a pop up dialog containing that set of tlalineitems
                    LearningTypePopupDialog popup = new LearningTypePopupDialog(
                            (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, relevantTLAs, key);
                    //Set the title of the popup to indicate which learning type was selected
                    popup.setTitle("Activities with \'" + key + "\'");
                    //Centre the popup at the location of the mouse click
                    Point location = trigger.getLocationOnScreen();
                    int w = popup.getWidth();
                    int h = popup.getHeight();
                    popup.setLocation(location.x - w / 2, location.y - h / 2);
                    popup.setVisible(true);
                    int returnStatus = popup.getReturnStatus();
                    if (returnStatus == LearningTypePopupDialog.RET_OK) {
                        modifyTLALineItem(popup.getSelectedTLALineItem(), 0);
                    }
                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent cme) {
            //Set the cursor shape according to the location of the cursor
            if (cme.getEntity() instanceof PieSectionEntity) {
                chartPanel.setCursor(HAND);
            } else {
                chartPanel.setCursor(Cursor.getDefaultCursor());
            }
        }
    });
    chartPanel.setPreferredSize(new Dimension(150, 200));
    typeChartPane.add(chartPanel);
    return typeChartPane;
}