Example usage for org.jfree.data.gantt SlidingGanttCategoryDataset SlidingGanttCategoryDataset

List of usage examples for org.jfree.data.gantt SlidingGanttCategoryDataset SlidingGanttCategoryDataset

Introduction

In this page you can find the example usage for org.jfree.data.gantt SlidingGanttCategoryDataset SlidingGanttCategoryDataset.

Prototype

public SlidingGanttCategoryDataset(GanttCategoryDataset underlying, int firstColumn, int maxColumns) 

Source Link

Document

Creates a new instance.

Usage

From source file:org.jfree.data.gantt.SlidingGanttCategoryDatasetTest.java

/**
 * Some checks for the equals() method.//from w ww.  ja v  a  2  s.  c o  m
 */
@Test
public void testEquals() {
    TaskSeries s1 = new TaskSeries("Series");
    s1.add(new Task("Task 1", new Date(0L), new Date(1L)));
    s1.add(new Task("Task 2", new Date(10L), new Date(11L)));
    s1.add(new Task("Task 3", new Date(20L), new Date(21L)));
    TaskSeriesCollection u1 = new TaskSeriesCollection();
    u1.add(s1);
    SlidingGanttCategoryDataset d1 = new SlidingGanttCategoryDataset(u1, 0, 5);
    TaskSeries s2 = new TaskSeries("Series");
    s2.add(new Task("Task 1", new Date(0L), new Date(1L)));
    s2.add(new Task("Task 2", new Date(10L), new Date(11L)));
    s2.add(new Task("Task 3", new Date(20L), new Date(21L)));
    TaskSeriesCollection u2 = new TaskSeriesCollection();
    u2.add(s2);
    SlidingGanttCategoryDataset d2 = new SlidingGanttCategoryDataset(u2, 0, 5);
    assertTrue(d1.equals(d2));

    d1.setFirstCategoryIndex(1);
    assertFalse(d1.equals(d2));
    d2.setFirstCategoryIndex(1);
    assertTrue(d1.equals(d2));

    d1.setMaximumCategoryCount(99);
    assertFalse(d1.equals(d2));
    d2.setMaximumCategoryCount(99);
    assertTrue(d1.equals(d2));

    s1.add(new Task("Task 2", new Date(10L), new Date(11L)));
    assertFalse(d1.equals(d2));
    s2.add(new Task("Task 2", new Date(10L), new Date(11L)));
    assertTrue(d1.equals(d2));
}

From source file:org.jfree.data.gantt.SlidingGanttCategoryDatasetTest.java

/**
 * Confirm that cloning works.//from   w ww. j  a  v  a  2s. c om
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    TaskSeries s1 = new TaskSeries("Series");
    s1.add(new Task("Task 1", new Date(0L), new Date(1L)));
    TaskSeriesCollection u1 = new TaskSeriesCollection();
    u1.add(s1);
    SlidingGanttCategoryDataset d1 = new SlidingGanttCategoryDataset(u1, 0, 5);
    SlidingGanttCategoryDataset d2 = (SlidingGanttCategoryDataset) d1.clone();
    assertTrue(d1 != d2);
    assertTrue(d1.getClass() == d2.getClass());
    assertTrue(d1.equals(d2));

    // basic check for independence
    s1.add(new Task("Task 2", new Date(10L), new Date(11L)));
    assertFalse(d1.equals(d2));
    TaskSeriesCollection u2 = (TaskSeriesCollection) d2.getUnderlyingDataset();
    TaskSeries s2 = u2.getSeries("Series");
    s2.add(new Task("Task 2", new Date(10L), new Date(11L)));
    assertTrue(d1.equals(d2));
}

From source file:org.jfree.data.gantt.SlidingGanttCategoryDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *//*from   w  w w  .  ja v a 2  s.c  o  m*/
@Test
public void testSerialization() {
    TaskSeries s1 = new TaskSeries("Series");
    s1.add(new Task("Task 1", new Date(0L), new Date(1L)));
    TaskSeriesCollection u1 = new TaskSeriesCollection();
    u1.add(s1);
    SlidingGanttCategoryDataset d1 = new SlidingGanttCategoryDataset(u1, 0, 5);
    SlidingGanttCategoryDataset d2 = (SlidingGanttCategoryDataset) TestUtilities.serialised(d1);
    assertEquals(d1, d2);

    // basic check for independence
    s1.add(new Task("Task 2", new Date(10L), new Date(11L)));
    assertFalse(d1.equals(d2));
    TaskSeriesCollection u2 = (TaskSeriesCollection) d2.getUnderlyingDataset();
    TaskSeries s2 = u2.getSeries("Series");
    s2.add(new Task("Task 2", new Date(10L), new Date(11L)));
    assertTrue(d1.equals(d2));
}

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  .  j  a  va2  s . co  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 ww.  ja  va 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;
}