Example usage for org.jfree.ui RectangleEdge TOP

List of usage examples for org.jfree.ui RectangleEdge TOP

Introduction

In this page you can find the example usage for org.jfree.ui RectangleEdge TOP.

Prototype

RectangleEdge TOP

To view the source code for org.jfree.ui RectangleEdge TOP.

Click Source Link

Document

Top.

Usage

From source file:org.jfree.chart.demo.LegendWrapperDemo1.java

private static JFreeChart createChart(PieDataset piedataset) {
    JFreeChart jfreechart = ChartFactory.createPieChart("Legend Wrapper Demo 1", piedataset, false, true,
            false);/*from  w  ww.  jav  a2s. c  o m*/
    PiePlot pieplot = (PiePlot) jfreechart.getPlot();
    pieplot.setLabelFont(new Font("SansSerif", 0, 12));
    pieplot.setNoDataMessage("No data available");
    pieplot.setCircular(true);
    pieplot.setLabelGap(0.02D);
    LegendTitle legendtitle = new LegendTitle(jfreechart.getPlot());
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.setFrame(new BlockBorder(1.0D, 1.0D, 1.0D, 1.0D));
    LabelBlock labelblock = new LabelBlock("Legend Items:", new Font("SansSerif", 1, 12));
    labelblock.setPadding(5D, 5D, 5D, 5D);
    blockcontainer.add(labelblock, RectangleEdge.TOP);
    LabelBlock labelblock1 = new LabelBlock("Source: http://www.jfree.org");
    labelblock1.setPadding(8D, 20D, 2D, 5D);
    blockcontainer.add(labelblock1, RectangleEdge.BOTTOM);
    BlockContainer blockcontainer1 = legendtitle.getItemContainer();
    blockcontainer1.setPadding(2D, 10D, 5D, 2D);
    blockcontainer.add(blockcontainer1);
    legendtitle.setWrapper(blockcontainer);
    legendtitle.setPosition(RectangleEdge.RIGHT);
    legendtitle.setHorizontalAlignment(HorizontalAlignment.LEFT);
    jfreechart.addSubtitle(legendtitle);
    return jfreechart;
}

From source file:no.imr.sea2data.guibase.chart.XYBarChart.java

public XYBarChart() {
    dataset = new XYSeriesCollection(new XYSeries("Series 1"));
    JFreeChart chart = ChartFactory.createXYBarChart("", "X axis", false, "Y axis", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    chart.setBackgroundPaint(Color.white);
    chart.getTitle().setPaint(Color.black);
    chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN, 12));
    chart.addSubtitle(trendLegend);//from w  w w  . j ava 2  s .c  o  m
    chart.addSubtitle(trendLegend2);
    trendLegend.setPosition(RectangleEdge.TOP);
    trendLegend2.setPosition(RectangleEdge.TOP);
    plot = (XYPlot) chart.getPlot();
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setShadowVisible(false);
    chartPanel = new ChartPanel(chart);
    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
}

From source file:org.jfree.chart.demo.AreaChartDemo1.java

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createAreaChart("Area Chart", "Category", "Value", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    TextTitle texttitle = new TextTitle(
            "An area chart demonstration.  We use this subtitle as an example of what happens when you get a really long title or subtitle.");
    texttitle.setFont(new Font("SansSerif", 0, 12));
    texttitle.setPosition(RectangleEdge.TOP);
    texttitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.050000000000000003D, 0.050000000000000003D,
            0.050000000000000003D, 0.050000000000000003D));
    texttitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
    jfreechart.addSubtitle(texttitle);// w  ww  .j a v  a 2 s. c  om
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setForegroundAlpha(0.5F);
    categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinesVisible(true);
    categoryplot.setRangeGridlinePaint(Color.white);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    categoryaxis.setLowerMargin(0.0D);
    categoryaxis.setUpperMargin(0.0D);
    categoryaxis.addCategoryLabelToolTip("Type 1", "The first type.");
    categoryaxis.addCategoryLabelToolTip("Type 2", "The second type.");
    categoryaxis.addCategoryLabelToolTip("Type 3", "The third type.");
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setLabelAngle(0.0D);
    return jfreechart;
}

From source file:net.nosleep.superanalyzer.panels.HomePanel.java

public static TextTitle createSubtitle(String s) {
    TextTitle subtitle = new TextTitle(s);
    subtitle.setPosition(RectangleEdge.TOP);
    subtitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.05, 0.05, 0.05, 0.05));
    subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
    return subtitle;
}

From source file:chartsPK.LineChart.java

private JPanel createChartPanel(String color1, String color2) {

    XYDataset dataset = createDataset();

    boolean showLegend = false;
    boolean createURL = false;
    boolean createTooltip = false;

    JFreeChart chart = ChartFactory.createXYLineChart(getMyTitle(), getAxis().getXLabel(),
            getAxis().getYLabel(), dataset, PlotOrientation.VERTICAL, true, true, true);

    Color color;/*  w w  w  . j a va 2 s .c om*/

    XYPlot plot = (XYPlot) chart.getPlot();

    try {
        Field field = Class.forName("java.awt.Color").getField(color1);
        color = (Color) field.get(null);
    } catch (Exception e) {
        color = null; // Not defined
    }
    plot.setBackgroundPaint(color);

    try {
        Field field = Class.forName("java.awt.Color").getField(color2);
        color = (Color) field.get(null);

    } catch (Exception e) {
        color = null; // Not defined
    }

    chart.setBackgroundPaint(color);

    for (int i = 0; i < dataSeries.size(); i++) {

        try {
            Field field = Class.forName("java.awt.Color").getField(dataSeries.get(i).getColor());
            color = (Color) field.get(null);
        } catch (Exception e) {
            color = null; // Not defined
        }

        plot.getRenderer().setSeriesPaint(i, color);

    }

    RectangleEdge p = RectangleEdge.BOTTOM;
    LegendTitle legend = chart.getLegend();
    switch (getLegend().getPosition().toLowerCase()) {
    case "top":
        p = RectangleEdge.TOP;
        break;
    case "bottom":
        p = RectangleEdge.BOTTOM;
        break;
    case "left":
        p = RectangleEdge.LEFT;
        break;
    case "right":
        p = RectangleEdge.RIGHT;
        break;
    }

    legend.setPosition(p);

    try {
        Field field = Class.forName("java.awt.Color").getField(getLegend().getColor());
        color = (Color) field.get(null);
    } catch (Exception e) {
        color = null; // Not defined
    }
    legend.setBackgroundPaint(color);

    return new ChartPanel(chart);
}

From source file:hudson.util.NoOverlapCategoryAxis.java

@Override
protected AxisState drawCategoryLabels(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea,
        RectangleEdge edge, AxisState state, PlotRenderingInfo plotState) {

    if (state == null) {
        throw new IllegalArgumentException("Null 'state' argument.");
    }//from ww  w.ja  v  a 2s  .c om

    if (isTickLabelsVisible()) {
        java.util.List ticks = refreshTicks(g2, state, plotArea, edge);
        state.setTicks(ticks);

        // remember the last drawn label so that we can avoid drawing overlapping labels.
        Rectangle2D r = null;

        int categoryIndex = 0;
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {

            CategoryTick tick = (CategoryTick) iterator.next();
            g2.setFont(getTickLabelFont(tick.getCategory()));
            g2.setPaint(getTickLabelPaint(tick.getCategory()));

            CategoryLabelPosition position = this.getCategoryLabelPositions().getLabelPosition(edge);
            double x0 = 0.0;
            double x1 = 0.0;
            double y0 = 0.0;
            double y1 = 0.0;
            if (edge == RectangleEdge.TOP) {
                x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                y1 = state.getCursor() - this.getCategoryLabelPositionOffset();
                y0 = y1 - state.getMax();
            } else if (edge == RectangleEdge.BOTTOM) {
                x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                y0 = state.getCursor() + this.getCategoryLabelPositionOffset();
                y1 = y0 + state.getMax();
            } else if (edge == RectangleEdge.LEFT) {
                y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                x1 = state.getCursor() - this.getCategoryLabelPositionOffset();
                x0 = x1 - state.getMax();
            } else if (edge == RectangleEdge.RIGHT) {
                y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                x0 = state.getCursor() + this.getCategoryLabelPositionOffset();
                x1 = x0 - state.getMax();
            }
            Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0));
            if (r == null || !r.intersects(area)) {
                Point2D anchorPoint = RectangleAnchor.coordinates(area, position.getCategoryAnchor());
                TextBlock block = tick.getLabel();
                block.draw(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getAngle());
                Shape bounds = block.calculateBounds(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getAngle());
                if (plotState != null && plotState.getOwner() != null) {
                    EntityCollection entities = plotState.getOwner().getEntityCollection();
                    if (entities != null) {
                        String tooltip = getCategoryLabelToolTip(tick.getCategory());
                        entities.add(new CategoryLabelEntity(tick.getCategory(), bounds, tooltip, null));
                    }
                }
                r = bounds.getBounds2D();
            }

            categoryIndex++;
        }

        if (edge.equals(RectangleEdge.TOP)) {
            double h = state.getMax();
            state.cursorUp(h);
        } else if (edge.equals(RectangleEdge.BOTTOM)) {
            double h = state.getMax();
            state.cursorDown(h);
        } else if (edge == RectangleEdge.LEFT) {
            double w = state.getMax();
            state.cursorLeft(w);
        } else if (edge == RectangleEdge.RIGHT) {
            double w = state.getMax();
            state.cursorRight(w);
        }
    }
    return state;
}

From source file:edu.jhuapl.graphs.jfreechart.utils.SparselyLabeledCategoryAxis.java

@SuppressWarnings("unchecked")
@Override/*  w  w  w .j av  a  2s  .  c  o m*/
public void drawTickMarks(Graphics2D g2, double cursor, Rectangle2D dataArea, RectangleEdge edge,
        AxisState state) {
    Plot p = getPlot();

    if (p == null) {
        return;
    }

    CategoryPlot plot = (CategoryPlot) p;
    double il = getTickMarkInsideLength();
    double ol = getTickMarkOutsideLength();
    Line2D line = new Line2D.Double();
    List categories = plot.getCategoriesForAxis(this);
    int tickEvery = categories.size() / (maxLabeledTicks == 0 ? 1 : maxLabeledTicks);

    if (tickEvery < 1) {
        tickEvery = 1;
    }

    if (edge.equals(RectangleEdge.TOP)) {
        Iterator iterator = categories.iterator();
        int i = 0;

        while (iterator.hasNext()) {
            Comparable key = (Comparable) iterator.next();

            if (i % tickEvery == 0) {
                double x = getCategoryMiddle(key, categories, dataArea, edge);
                g2.setPaint(getTickMarkPaint());
                g2.setStroke(getTickMarkStroke());
                line.setLine(x, cursor, x, cursor + il);
                g2.draw(line);
                line.setLine(x, cursor, x, cursor - ol);
                g2.draw(line);

                if (domainGridlinePaint != null) {
                    drawDomainGridline(g2, plot, dataArea, x);
                }
            }

            i++;
        }

        state.cursorUp(ol);
    } else if (edge.equals(RectangleEdge.BOTTOM)) {
        Iterator iterator = categories.iterator();
        int i = 0;

        while (iterator.hasNext()) {
            Comparable key = (Comparable) iterator.next();

            if (i % tickEvery == 0) {
                double x = getCategoryMiddle(key, categories, dataArea, edge);
                g2.setPaint(getTickMarkPaint());
                g2.setStroke(getTickMarkStroke());
                line.setLine(x, cursor, x, cursor - il);
                g2.draw(line);
                line.setLine(x, cursor, x, cursor + ol);
                g2.draw(line);

                if (domainGridlinePaint != null) {
                    drawDomainGridline(g2, plot, dataArea, x);
                }
            }

            i++;
        }

        state.cursorDown(ol);
    } else if (edge.equals(RectangleEdge.LEFT)) {
        Iterator iterator = categories.iterator();
        int i = 0;

        while (iterator.hasNext()) {
            Comparable key = (Comparable) iterator.next();

            if (i % tickEvery == 0) {
                double y = getCategoryMiddle(key, categories, dataArea, edge);
                g2.setPaint(getTickMarkPaint());
                g2.setStroke(getTickMarkStroke());
                line.setLine(cursor, y, cursor + il, y);
                g2.draw(line);
                line.setLine(cursor, y, cursor - ol, y);
                g2.draw(line);

                if (domainGridlinePaint != null) {
                    drawDomainGridline(g2, plot, dataArea, y);
                }
            }

            i++;
        }

        state.cursorLeft(ol);
    } else if (edge.equals(RectangleEdge.RIGHT)) {
        Iterator iterator = categories.iterator();
        int i = 0;

        while (iterator.hasNext()) {
            Comparable key = (Comparable) iterator.next();

            if (i % tickEvery == 0) {
                double y = getCategoryMiddle(key, categories, dataArea, edge);
                g2.setPaint(getTickMarkPaint());
                g2.setStroke(getTickMarkStroke());
                line.setLine(cursor, y, cursor - il, y);
                g2.draw(line);
                line.setLine(cursor, y, cursor + ol, y);
                g2.draw(line);

                if (domainGridlinePaint != null) {
                    drawDomainGridline(g2, plot, dataArea, y);
                }
            }

            i++;
        }

        state.cursorRight(ol);
    }
}

From source file:org.jstockchart.axis.TimeseriesNumberAxis.java

public List<Tick> refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    TextAnchor anchor = null;//ww  w .  j a v  a2s  .co m
    TextAnchor rotationAnchor = null;
    double angle = 0.0;
    if (isVerticalTickLabels()) {
        anchor = TextAnchor.CENTER_RIGHT;
        rotationAnchor = TextAnchor.CENTER_RIGHT;
        if (edge == RectangleEdge.TOP) {
            angle = Math.PI / 2.0;
        } else {
            angle = -Math.PI / 2.0;
        }
    } else {
        if (edge == RectangleEdge.TOP) {
            anchor = TextAnchor.BOTTOM_CENTER;
            rotationAnchor = TextAnchor.BOTTOM_CENTER;
        } else {
            anchor = TextAnchor.TOP_CENTER;
            rotationAnchor = TextAnchor.TOP_CENTER;
        }
    }
    return createTicks(logicTicks, anchor, rotationAnchor, angle);
}

From source file:com.newatlanta.bluedragon.CategoryAxis.java

public AxisSpace reserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge,
        AxisSpace space) {/*from w w w.j  a v a 2  s . com*/

    // create a new space object if one wasn't supplied...
    if (space == null) {
        space = new AxisSpace();
    }

    // if the axis is not visible, no additional space is required...
    if (!isVisible()) {
        return space;
    }

    // calculate the max size of the tick labels (if visible)...
    double tickLabelHeight = 0.0;
    double tickLabelWidth = 0.0;
    if (isTickLabelsVisible()) {
        g2.setFont(getTickLabelFont());
        AxisState state = new AxisState();
        // we call refresh ticks just to get the maximum width or height
        if (RectangleEdge.isTopOrBottom(edge)) {
            // BEGIN fix for category labels that wrap
            // If space has been reserved to the left and right then we need to
            // reduce the plot area
            // by this amount so that the space needed by category labels that wrap
            // on to multiple lines
            // will be calculated properly.
            Rectangle2D newPlotArea = new Rectangle2D.Double(plotArea.getX(), plotArea.getY(),
                    plotArea.getWidth() - space.getLeft() - space.getRight(), plotArea.getHeight());
            refreshTicks(g2, state, newPlotArea, edge);
            // END fix for category labels that wrap
        } else {
            refreshTicks(g2, state, plotArea, edge);
        }
        if (edge == RectangleEdge.TOP) {
            tickLabelHeight = state.getMax();
        } else if (edge == RectangleEdge.BOTTOM) {
            tickLabelHeight = state.getMax();
        } else if (edge == RectangleEdge.LEFT) {
            tickLabelWidth = state.getMax();
        } else if (edge == RectangleEdge.RIGHT) {
            tickLabelWidth = state.getMax();
        }
    }

    // get the axis label size and update the space object...
    Rectangle2D labelEnclosure = getLabelEnclosure(g2, edge);
    double labelHeight = 0.0;
    double labelWidth = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        labelHeight = labelEnclosure.getHeight();
        space.add(labelHeight + tickLabelHeight + this.getCategoryLabelPositionOffset(), edge);
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        labelWidth = labelEnclosure.getWidth();
        space.add(labelWidth + tickLabelWidth + this.getCategoryLabelPositionOffset(), edge);
    }
    return space;

}

From source file:org.fhaes.fhrecorder.util.NumericCategoryAxis.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override//from   w  w w .j  ava  2 s .c  o  m
public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {

    List ticks = new java.util.ArrayList();

    // sanity check for data area...
    if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) {
        return ticks;
    }

    CategoryPlot plot = (CategoryPlot) getPlot();
    List categories = plot.getCategoriesForAxis(this);
    double max = 0.0;

    if (categories != null) {
        CategoryLabelPosition position = this.getCategoryLabelPositions().getLabelPosition(edge);
        float r = this.getMaximumCategoryLabelWidthRatio();
        if (r <= 0.0) {
            r = position.getWidthRatio();
        }

        float l = 0.0f;
        if (position.getWidthType() == CategoryLabelWidthType.CATEGORY) {
            l = (float) calculateCategorySize(categories.size(), dataArea, edge);
        } else {
            if (RectangleEdge.isLeftOrRight(edge)) {
                l = (float) dataArea.getWidth();
            } else {
                l = (float) dataArea.getHeight();
            }
        }
        int categoryIndex = 0;
        Iterator iterator = categories.iterator();
        while (iterator.hasNext()) {
            Comparable category = (Comparable) iterator.next();

            try {
                Integer intcategory = Integer.valueOf(category.toString());

                int modulus = intcategory % labelEveryXCategories;

                if (modulus != 0)
                    category = " ";

            } catch (NumberFormatException e) {

            }

            TextBlock label = createLabel(category, l * r, edge, g2);
            if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) {
                max = Math.max(max, calculateTextBlockHeight(label, position, g2));
            } else if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
                max = Math.max(max, calculateTextBlockWidth(label, position, g2));
            }
            Tick tick = new CategoryTick(category, label, position.getLabelAnchor(),
                    position.getRotationAnchor(), position.getAngle());
            ticks.add(tick);
            categoryIndex = categoryIndex + 1;
        }
    }
    state.setMax(max);
    return ticks;
}