Example usage for org.jfree.ui RectangleEdge LEFT

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

Introduction

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

Prototype

RectangleEdge LEFT

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

Click Source Link

Document

Left.

Usage

From source file:MouseEventListener.java

@Override
public void chartMouseClicked(ChartMouseEvent arg0) {

    Point point = arg0.getTrigger().getPoint();
    //add a new point to the model editor series 
    int x = point.x;
    int y = point.y;

    Rectangle2D dataArea = chartPanel.getScreenDataArea();
    float x0 = (float) chartPanel.getChart().getXYPlot().getRangeAxis().java2DToValue(y, dataArea,
            RectangleEdge.LEFT);
    float t0 = (float) chartPanel.getChart().getXYPlot().getDomainAxis().java2DToValue(x, dataArea,
            RectangleEdge.BOTTOM);/*from w w  w  .  ja va  2s  . co m*/

    //simuladorGUI.nuevoPuntoInicial(t0, x0);
}

From source file:bigdataproject.CustomFastScatterPlot.java

@Override
public void render(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, CrosshairState crosshairState) {
    if (clusters != null) {
        int colorIndex = 0, points = 0;
        String shape = "";
        for (Integer index : clusters.keySet()) {
            float[][] clusterFloat = clusters.get(index);
            for (float[] clusterFloat1 : clusterFloat) {
                points++;//  w  ww . jav a  2  s.  c o m
                float x = clusterFloat1[0];
                float y = clusterFloat1[1];
                int size = 6;
                int transX = (int) this.getDomainAxis().valueToJava2D(x, dataArea, RectangleEdge.BOTTOM);
                int transY = (int) this.getRangeAxis().valueToJava2D(y, dataArea, RectangleEdge.LEFT);
                g2.setPaint(colors[colorIndex % 11]);
                if (colorIndex % 2 == 0) {
                    g2.fillOval(transX, transY, size, size);
                    shape = "Round";
                } else {
                    g2.fillRect(transX, transY, size, size);
                    shape = "Square";
                }
            }
            System.out.println("Cluster number: " + colorIndex + " Points: " + clusterFloat.length + " Shape: "
                    + shape + " Color: " + colorArray[colorIndex % 11]);
            colorIndex++;
        }
        System.out.println(
                "\nClustering done! Total clusters: " + colorIndex + " Total points: " + points + "\n");
    }
}

From source file:edu.cmu.sv.modelinference.eventtool.charting.DataChart.java

private void createChartPanel(JFreeChart chart) {
    chartPanel = new ChartPanel(chart);

    chartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override/*w ww  .j av a  2 s. co  m*/
        public void chartMouseClicked(ChartMouseEvent arg0) {
            //ignore
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            Rectangle2D dataArea = chartPanel.getScreenDataArea();
            JFreeChart chart = event.getChart();
            XYPlot plot = (XYPlot) chart.getPlot();
            ValueAxis xAxis = plot.getDomainAxis();
            double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM);
            ValueAxis yAxis = plot.getRangeAxis();
            double y = yAxis.java2DToValue(event.getTrigger().getY(), dataArea, RectangleEdge.LEFT);

            //Alternatively, obtain y for one of the subplots, which would be very neat.
            //We should find the "nearest" subplot to the cursor -- this is easy
            //double y = DatasetUtilities.findYValue(plot.getDataset(), 0, x);
            xCrosshair.setValue(x);
            yCrosshair.setValue(y);
        }
    });

    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f));
    xCrosshair.setLabelVisible(true);
    yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f));
    yCrosshair.setLabelVisible(true);
    crosshairOverlay.addDomainCrosshair(xCrosshair);
    crosshairOverlay.addRangeCrosshair(yCrosshair);
    chartPanel.addOverlay(crosshairOverlay);

    chartPanel.setPreferredSize(new java.awt.Dimension(800, 600));
    setContentPane(chartPanel);
}

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.ja  v a2  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:peakml.util.jfreechart.FastSpectrumPlot.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {//from   w  w  w .ja  va2 s.  co  m
    // add the plot area to the info (used amongst other by the axis for zooming)
    if (info != null)
        info.setPlotArea(area);

    // add the insets (if any)
    RectangleInsets insets = getInsets();
    insets.trim(area);

    // draw the axis and add the dataArea to the info (used amongst other by the axis for zooming)
    AxisSpace space = new AxisSpace();
    space = xaxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = yaxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);

    Rectangle2D dataArea = space.shrink(area, null);
    if (info != null)
        info.setDataArea(dataArea);

    // flood fill the whole area with the background color
    drawBackground(g2, dataArea);

    // draw the axis
    xaxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info);
    yaxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info);

    // sanity check
    if (dataseries.size() == 0)
        return;

    // clip the draw area
    Shape originalclip = g2.getClip();
    g2.clip(dataArea);

    // draw all the values
    for (Data data : dataseries) {
        int xpos = (int) xaxis.valueToJava2D(data.mass, dataArea, RectangleEdge.BOTTOM);
        int ypos = (int) yaxis.valueToJava2D(data.intensity, dataArea, RectangleEdge.LEFT);
        g2.drawLine(xpos, (int) yaxis.valueToJava2D(0, dataArea, RectangleEdge.LEFT), xpos, ypos);

        // draw the label
        if (data.description != null && data.description.length() != 0) {
            g2.setColor(Color.RED);
            g2.drawLine(xpos + 2, ypos - 2, xpos + 15, ypos - 15);
            g2.setColor(Color.BLACK);
            g2.drawString(data.description, xpos + 17, ypos - 17);
        }
    }

    // reset
    g2.setClip(originalclip);
}

From source file:it.cnr.istc.utils.gui.ReverseGradientXYBarPainter.java

/**
 * Paints a single bar instance.//from  w  w w .  ja  v a 2 s  . c  om
 *
 * @param g2 the graphics target.
 * @param renderer the renderer.
 * @param row the row index.
 * @param column the column index.
 * @param bar the bar
 * @param base indicates which side of the rectangle is the base of the bar.
 */
@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar,
        RectangleEdge base) {

    Paint itemPaint = renderer.getItemPaint(row, column);

    Color c0, c1;
    if (itemPaint instanceof Color) {
        c0 = (Color) itemPaint;
        c1 = c0.brighter();
    } else if (itemPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) itemPaint;
        c0 = gp.getColor1();
        c1 = gp.getColor2();
    } else {
        c0 = Color.blue;
        c1 = Color.blue.brighter();
    }

    // as a special case, if the bar colour has alpha == 0, we draw
    // nothing.
    if (c0.getAlpha() == 0) {
        return;
    }

    if (base == RectangleEdge.LEFT || base == RectangleEdge.RIGHT) {
        Rectangle2D[] regions = splitVerticalBar(bar, this.g1, this.g2, this.g3);
        GradientPaint gp = new GradientPaint((float) regions[0].getMinX(), 0.0f, c0,
                (float) regions[0].getMaxX(), 0.0f, Color.white);
        g2.setPaint(gp);
        g2.fill(regions[0]);

        gp = new GradientPaint((float) regions[1].getMinX(), 0.0f, Color.white, (float) regions[1].getMaxX(),
                0.0f, c0);
        g2.setPaint(gp);
        g2.fill(regions[1]);

        gp = new GradientPaint((float) regions[2].getMinX(), 0.0f, c0, (float) regions[2].getMaxX(), 0.0f, c1);
        g2.setPaint(gp);
        g2.fill(regions[2]);

        gp = new GradientPaint((float) regions[3].getMinX(), 0.0f, c1, (float) regions[3].getMaxX(), 0.0f, c0);
        g2.setPaint(gp);
        g2.fill(regions[3]);
    } else if (base == RectangleEdge.TOP || base == RectangleEdge.BOTTOM) {
        Rectangle2D[] regions = splitHorizontalBar(bar, this.g1, this.g2, this.g3);
        GradientPaint gp = new GradientPaint(0.0f, (float) regions[0].getMinY(), c0, 0.0f,
                (float) regions[0].getMaxX(), Color.white);
        g2.setPaint(gp);
        g2.fill(regions[0]);

        gp = new GradientPaint(0.0f, (float) regions[1].getMinY(), Color.white, 0.0f,
                (float) regions[1].getMaxY(), c0);
        g2.setPaint(gp);
        g2.fill(regions[1]);

        gp = new GradientPaint(0.0f, (float) regions[2].getMinY(), c0, 0.0f, (float) regions[2].getMaxY(), c1);
        g2.setPaint(gp);
        g2.fill(regions[2]);

        gp = new GradientPaint(0.0f, (float) regions[3].getMinY(), c1, 0.0f, (float) regions[3].getMaxY(), c0);
        g2.setPaint(gp);
        g2.fill(regions[3]);
    }

    // draw the outline...
    if (renderer.isDrawBarOutline()) {
        Stroke stroke = renderer.getItemOutlineStroke(row, column);
        Paint paint = renderer.getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }

}

From source file:com.rapidminer.gui.plotter.charts.WeightBasedSymbolAxis.java

/**
 * Draws the grid bands for the axis when it is at the top or bottom of the plot.
 * //from  w w w  .j  a va2 s .  co  m
 * @param g2
 *            the graphics device.
 * @param drawArea
 *            the area within which the chart should be drawn.
 * @param plotArea
 *            the area within which the plot should be drawn (a subset of the drawArea).
 * @param firstGridBandIsDark
 *            True: the first grid band takes the color of <CODE>gridBandPaint<CODE>.
 *                             False: the second grid band takes the
 *                             color of <CODE>gridBandPaint<CODE>.
 * @param ticks
 *            a list of ticks.
 */
@Override
protected void drawGridBandsVertical(Graphics2D g2, Rectangle2D drawArea, Rectangle2D plotArea,
        boolean firstGridBandIsDark, List ticks) {
    double xx = plotArea.getX();
    double yy1, yy2;

    // gets the outline stroke width of the plot
    double outlineStrokeWidth;
    Stroke outlineStroke = getPlot().getOutlineStroke();
    if (outlineStroke != null && outlineStroke instanceof BasicStroke) {
        outlineStrokeWidth = ((BasicStroke) outlineStroke).getLineWidth();
    } else {
        outlineStrokeWidth = 1d;
    }

    Iterator iterator = ticks.iterator();
    ValueTick tick;
    Rectangle2D band;
    while (iterator.hasNext()) {
        tick = (ValueTick) iterator.next();
        int weightIndex = (int) tick.getValue();
        yy1 = valueToJava2D(tick.getValue() + 0.5d, plotArea, RectangleEdge.LEFT);
        yy2 = valueToJava2D(tick.getValue() - 0.5d, plotArea, RectangleEdge.LEFT);

        g2.setColor(PlotterAdapter.getWeightColor(this.weights[weightIndex], this.maxWeight));

        band = new Rectangle2D.Double(xx + outlineStrokeWidth, yy1,
                plotArea.getMaxX() - xx - outlineStrokeWidth, yy2 - yy1);
        g2.fill(band);
    }
    g2.setPaintMode();
}

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

public AxisSpace reserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge,
        AxisSpace space) {//from  www  .  j a v  a 2  s .  c o m

    // 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.tsho.dmc2.core.chart.CowebRenderer.java

public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) {

    state = STATE_RUNNING;/*from  w ww .java 2  s.  co m*/

    if (plot.isAlpha()) {
        g2.setComposite(AlphaComposite.SrcOver);
    }

    Stepper.Point2D result = stepper.getCurrentPoint2D();

    int transX, transY;

    double start = (int) dataArea.getMinX();
    double end = (int) dataArea.getMaxX();

    double[] value = new double[1];

    int prevY = 0;
    boolean flagOld = false;
    boolean flagNew = false;

    label: for (double i = start; i <= end; i += 1) {
        value[0] = this.domainAxis.java2DToValue(i, dataArea, RectangleEdge.BOTTOM);

        stepper.setInitialValue(value);
        stepper.initialize();

        for (int j = 0; j < power; j++) {
            stepper.step();
        }

        result = stepper.getCurrentPoint2D();

        transX = (int) i;
        transY = (int) rangeAxis.valueToJava2D(result.getX(), dataArea, RectangleEdge.LEFT);
        flagNew = Double.isNaN(result.getX());

        if (bigDots) {
            g2.fillRect(transX - 1, transY - 1, 3, 3);
        } else {
            g2.fillRect(transX, transY, 1, 1);
        }

        if (connectWithLines) {
            if (i > start) {
                if (!flagOld && !flagNew)
                    g2.drawLine(transX, transY, transX - 1, prevY);
            }

            prevY = transY;
            flagOld = flagNew;
        }

        if (stopped) {
            state = STATE_STOPPED;
            return;
        }

    }

    if (animate) {
        animateCowebPlot(g2, dataArea);
    }

    state = STATE_FINISHED;
}

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.j  a  v a 2 s  .c o  m

    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;
}