org.jfree.ui.RectangleInsets Java Examples

The following examples show how to use org.jfree.ui.RectangleInsets. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CombinedRangeXYPlot.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds a subplot with a particular weight (greater than or equal to one).
 * The weight determines how much space is allocated to the subplot
 * relative to all the other subplots.
 * <br><br>
 * You must ensure that the subplot has a non-null domain axis.  The range
 * axis for the subplot will be set to <code>null</code>.
 *
 * @param subplot  the subplot (<code>null</code> not permitted).
 * @param weight  the weight (must be 1 or greater).
 */
public void add(XYPlot subplot, int weight) {
    ParamChecks.nullNotPermitted(subplot, "subplot");
    if (weight <= 0) {
        String msg = "The 'weight' must be positive.";
        throw new IllegalArgumentException(msg);
    }

    // store the plot and its weight
    subplot.setParent(this);
    subplot.setWeight(weight);
    subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    subplot.setRangeAxis(null);
    subplot.addChangeListener(this);
    this.subplots.add(subplot);
    configureRangeAxes();
    fireChangeEvent();

}
 
Example #2
Source File: AbstractCategoryItemRenderer.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the (x, y) coordinates for drawing the label for a marker on
 * the range axis.
 *
 * @param g2  the graphics device.
 * @param orientation  the plot orientation.
 * @param dataArea  the data area.
 * @param markerArea  the rectangle surrounding the marker.
 * @param markerOffset  the marker offset.
 * @param labelOffsetType  the label offset type.
 * @param anchor  the label anchor.
 *
 * @return The coordinates for drawing the marker label.
 */
protected Point2D calculateDomainMarkerTextAnchorPoint(Graphics2D g2,
        PlotOrientation orientation, Rectangle2D dataArea,
        Rectangle2D markerArea, RectangleInsets markerOffset,
        LengthAdjustmentType labelOffsetType, RectangleAnchor anchor) {

    Rectangle2D anchorRect = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        anchorRect = markerOffset.createAdjustedRectangle(markerArea,
                LengthAdjustmentType.CONTRACT, labelOffsetType);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        anchorRect = markerOffset.createAdjustedRectangle(markerArea,
                labelOffsetType, LengthAdjustmentType.CONTRACT);
    }
    return RectangleAnchor.coordinates(anchorRect, anchor);

}
 
Example #3
Source File: AbstractCategoryItemRenderer.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Calculates the (x, y) coordinates for drawing the label for a marker on
 * the range axis.
 *
 * @param g2  the graphics device.
 * @param orientation  the plot orientation.
 * @param dataArea  the data area.
 * @param markerArea  the rectangle surrounding the marker.
 * @param markerOffset  the marker offset.
 * @param labelOffsetType  the label offset type.
 * @param anchor  the label anchor.
 *
 * @return The coordinates for drawing the marker label.
 */
protected Point2D calculateDomainMarkerTextAnchorPoint(Graphics2D g2,
        PlotOrientation orientation, Rectangle2D dataArea,
        Rectangle2D markerArea, RectangleInsets markerOffset,
        LengthAdjustmentType labelOffsetType, RectangleAnchor anchor) {

    Rectangle2D anchorRect = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        anchorRect = markerOffset.createAdjustedRectangle(markerArea,
                LengthAdjustmentType.CONTRACT, labelOffsetType);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        anchorRect = markerOffset.createAdjustedRectangle(markerArea,
                labelOffsetType, LengthAdjustmentType.CONTRACT);
    }
    return RectangleAnchor.coordinates(anchorRect, anchor);

}
 
Example #4
Source File: ValueAxisTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for bug 3555275 (where the fixed axis space is calculated 
 * incorrectly).
 */
@Test
public void test3555275() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setFixedDimension(100.0);
    BufferedImage image = new BufferedImage(500, 300, 
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    ChartRenderingInfo info = new ChartRenderingInfo();
    chart.draw(g2, new Rectangle2D.Double(0, 0, 500, 300), info);
    g2.dispose();
    Rectangle2D rect = info.getPlotInfo().getDataArea();
    double x = rect.getMinX();
    assertEquals(100.0, x, 1.0);
}
 
Example #5
Source File: ChartFactory.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a 3D pie chart using the specified dataset.  The chart object
 * returned by this method uses a {@link PiePlot3D} instance as the
 * plot.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A pie chart.
 */
public static JFreeChart createPieChart3D(String title, PieDataset dataset,
        boolean legend, boolean tooltips, boolean urls) {

    PiePlot3D plot = new PiePlot3D(dataset);
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    }
    if (urls) {
        plot.setURLGenerator(new StandardPieURLGenerator());
    }
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #6
Source File: DialValueIndicator.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new instance of <code>DialValueIndicator</code>.
 *
 * @param datasetIndex  the dataset index.
 */
public DialValueIndicator(int datasetIndex) {
    this.datasetIndex = datasetIndex;
    this.angle = -90.0;
    this.radius = 0.3;
    this.frameAnchor = RectangleAnchor.CENTER;
    this.templateValue = new Double(100.0);
    this.maxTemplateValue = null;
    this.formatter = new DecimalFormat("0.0");
    this.font = new Font("Dialog", Font.BOLD, 14);
    this.paint = Color.black;
    this.backgroundPaint = Color.white;
    this.outlineStroke = new BasicStroke(1.0f);
    this.outlinePaint = Color.blue;
    this.insets = new RectangleInsets(4, 4, 4, 4);
    this.valueAnchor = RectangleAnchor.RIGHT;
    this.textAnchor = TextAnchor.CENTER_RIGHT;
}
 
Example #7
Source File: AbstractCategoryItemRenderer.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Calculates the (x, y) coordinates for drawing the label for a marker on
 * the range axis.
 *
 * @param g2  the graphics device.
 * @param orientation  the plot orientation.
 * @param dataArea  the data area.
 * @param markerArea  the rectangle surrounding the marker.
 * @param markerOffset  the marker offset.
 * @param labelOffsetType  the label offset type.
 * @param anchor  the label anchor.
 *
 * @return The coordinates for drawing the marker label.
 */
protected Point2D calculateDomainMarkerTextAnchorPoint(Graphics2D g2,
        PlotOrientation orientation, Rectangle2D dataArea,
        Rectangle2D markerArea, RectangleInsets markerOffset,
        LengthAdjustmentType labelOffsetType, RectangleAnchor anchor) {

    Rectangle2D anchorRect = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        anchorRect = markerOffset.createAdjustedRectangle(markerArea,
                LengthAdjustmentType.CONTRACT, labelOffsetType);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        anchorRect = markerOffset.createAdjustedRectangle(markerArea,
                labelOffsetType, LengthAdjustmentType.CONTRACT);
    }
    return RectangleAnchor.coordinates(anchorRect, anchor);

}
 
Example #8
Source File: DialValueIndicator.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new instance of <code>DialValueIndicator</code>.
 *
 * @param datasetIndex  the dataset index.
 */
public DialValueIndicator(int datasetIndex) {
    this.datasetIndex = datasetIndex;
    this.angle = -90.0;
    this.radius = 0.3;
    this.frameAnchor = RectangleAnchor.CENTER;
    this.templateValue = new Double(100.0);
    this.maxTemplateValue = null;
    this.formatter = new DecimalFormat("0.0");
    this.font = new Font("Dialog", Font.BOLD, 14);
    this.paint = Color.black;
    this.backgroundPaint = Color.white;
    this.outlineStroke = new BasicStroke(1.0f);
    this.outlinePaint = Color.blue;
    this.insets = new RectangleInsets(4, 4, 4, 4);
    this.valueAnchor = RectangleAnchor.RIGHT;
    this.textAnchor = TextAnchor.CENTER_RIGHT;
}
 
Example #9
Source File: ChartFactory.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a ring chart with default settings.
 * <P>
 * The chart object returned by this method uses a {@link RingPlot}
 * instance as the plot.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A ring chart.
 */
public static JFreeChart createRingChart(String title, PieDataset dataset,
        boolean legend, boolean tooltips, boolean urls) {

    RingPlot plot = new RingPlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    }
    if (urls) {
        plot.setURLGenerator(new StandardPieURLGenerator());
    }
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #10
Source File: WaferMapPlot.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the wafermap view.
 *
 * @param g2  the graphics device.
 * @param area  the plot area.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param state  the plot state.
 * @param info  the plot rendering info.
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor,
                 PlotState state,
                 PlotRenderingInfo info) {

    // if the plot area is too small, just return...
    boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }

    // record the plot area...
    if (info != null) {
        info.setPlotArea(area);
    }

    // adjust the drawing area for the plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    drawChipGrid(g2, area);
    drawWaferEdge(g2, area);

}
 
Example #11
Source File: ImageTitle.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new image title with the given image scaled to the given
 * width and height in the given location.
 *
 * @param image  the image ({@code null} not permitted).
 * @param height  the height used to draw the image.
 * @param width  the width used to draw the image.
 * @param position  the title position.
 * @param horizontalAlignment  the horizontal alignment.
 * @param verticalAlignment  the vertical alignment.
 * @param padding  the amount of space to leave around the outside of the
 *                 title.
 */
public ImageTitle(Image image, int height, int width,
                  RectangleEdge position,
                  HorizontalAlignment horizontalAlignment,
                  VerticalAlignment verticalAlignment,
                  RectangleInsets padding) {

    super(position, horizontalAlignment, verticalAlignment, padding);
    if (image == null) {
        throw new NullPointerException("Null 'image' argument.");
    }
    this.image = image;
    setHeight(height);
    setWidth(width);

}
 
Example #12
Source File: DialValueIndicator.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new instance of <code>DialValueIndicator</code>.
 *
 * @param datasetIndex  the dataset index.
 */
public DialValueIndicator(int datasetIndex) {
    this.datasetIndex = datasetIndex;
    this.angle = -90.0;
    this.radius = 0.3;
    this.frameAnchor = RectangleAnchor.CENTER;
    this.templateValue = new Double(100.0);
    this.maxTemplateValue = null;
    this.formatter = new DecimalFormat("0.0");
    this.font = new Font("Dialog", Font.BOLD, 14);
    this.paint = Color.black;
    this.backgroundPaint = Color.white;
    this.outlineStroke = new BasicStroke(1.0f);
    this.outlinePaint = Color.blue;
    this.insets = new RectangleInsets(4, 4, 4, 4);
    this.valueAnchor = RectangleAnchor.RIGHT;
    this.textAnchor = TextAnchor.CENTER_RIGHT;
}
 
Example #13
Source File: ValueAxis.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Calculates the anchor point for a tick label.
 *
 * @param tick  the tick.
 * @param cursor  the cursor.
 * @param dataArea  the data area.
 * @param edge  the edge on which the axis is drawn.
 *
 * @return The x and y coordinates of the anchor point.
 */
protected float[] calculateAnchorPoint(ValueTick tick, double cursor,
        Rectangle2D dataArea, RectangleEdge edge) {

    RectangleInsets insets = getTickLabelInsets();
    float[] result = new float[2];
    if (edge == RectangleEdge.TOP) {
        result[0] = (float) valueToJava2D(tick.getValue(), dataArea, edge);
        result[1] = (float) (cursor - insets.getBottom() - 2.0);
    }
    else if (edge == RectangleEdge.BOTTOM) {
        result[0] = (float) valueToJava2D(tick.getValue(), dataArea, edge);
        result[1] = (float) (cursor + insets.getTop() + 2.0);
    }
    else if (edge == RectangleEdge.LEFT) {
        result[0] = (float) (cursor - insets.getLeft() - 2.0);
        result[1] = (float) valueToJava2D(tick.getValue(), dataArea, edge);
    }
    else if (edge == RectangleEdge.RIGHT) {
        result[0] = (float) (cursor + insets.getRight() + 2.0);
        result[1] = (float) valueToJava2D(tick.getValue(), dataArea, edge);
    }
    return result;
}
 
Example #14
Source File: MarkerTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getLabelOffset() and setLabelOffset() methods.
 */
@Test
public void testGetSetLabelOffset() {
    // we use ValueMarker for the tests, because we need a concrete
    // subclass...
    ValueMarker m = new ValueMarker(1.1);
    m.addChangeListener(this);
    this.lastEvent = null;
    assertEquals(new RectangleInsets(3, 3, 3, 3), m.getLabelOffset());
    m.setLabelOffset(new RectangleInsets(1, 2, 3, 4));
    assertEquals(new RectangleInsets(1, 2, 3, 4), m.getLabelOffset());
    assertEquals(m, this.lastEvent.getMarker());

    // check null argument...
    try {
        m.setLabelOffset(null);
        fail("Expected an IllegalArgumentException for null.");
    }
    catch (IllegalArgumentException e) {
        assertTrue(true);
    }
}
 
Example #15
Source File: PeriodAxisLabelInfo.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param periodClass  the subclass of {@link RegularTimePeriod} to use
 *                     (<code>null</code> not permitted).
 * @param dateFormat  the date format (<code>null</code> not permitted).
 * @param padding  controls the space around the band (<code>null</code>
 *                 not permitted).
 * @param labelFont  the label font (<code>null</code> not permitted).
 * @param labelPaint  the label paint (<code>null</code> not permitted).
 * @param drawDividers  a flag that controls whether dividers are drawn.
 * @param dividerStroke  the stroke used to draw the dividers
 *                       (<code>null</code> not permitted).
 * @param dividerPaint  the paint used to draw the dividers
 *                      (<code>null</code> not permitted).
 */
public PeriodAxisLabelInfo(Class periodClass, DateFormat dateFormat,
        RectangleInsets padding, Font labelFont, Paint labelPaint,
        boolean drawDividers, Stroke dividerStroke, Paint dividerPaint) {
    ParamChecks.nullNotPermitted(periodClass, "periodClass");
    ParamChecks.nullNotPermitted(dateFormat, "dateFormat");
    ParamChecks.nullNotPermitted(padding, "padding");
    ParamChecks.nullNotPermitted(labelFont, "labelFont");
    ParamChecks.nullNotPermitted(labelPaint, "labelPaint");
    ParamChecks.nullNotPermitted(dividerStroke, "dividerStroke");
    ParamChecks.nullNotPermitted(dividerPaint, "dividerPaint");
    this.periodClass = periodClass;
    this.dateFormat = (DateFormat) dateFormat.clone();
    this.padding = padding;
    this.labelFont = labelFont;
    this.labelPaint = labelPaint;
    this.drawDividers = drawDividers;
    this.dividerStroke = dividerStroke;
    this.dividerPaint = dividerPaint;
}
 
Example #16
Source File: BlockBorderTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Confirm that the equals() method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    BlockBorder b1 = new BlockBorder(new RectangleInsets(1.0, 2.0, 3.0,
            4.0), Color.red);
    BlockBorder b2 = new BlockBorder(new RectangleInsets(1.0, 2.0, 3.0,
            4.0), Color.red);
    assertTrue(b1.equals(b2));
    assertTrue(b2.equals(b2));

    // insets
    b1 = new BlockBorder(new RectangleInsets(UnitType.RELATIVE, 1.0, 2.0,
            3.0, 4.0), Color.red);
    assertFalse(b1.equals(b2));
    b2 = new BlockBorder(new RectangleInsets(UnitType.RELATIVE, 1.0, 2.0,
            3.0, 4.0), Color.red);
    assertTrue(b1.equals(b2));

    // paint
    b1 = new BlockBorder(new RectangleInsets(1.0, 2.0, 3.0, 4.0),
            Color.blue);
    assertFalse(b1.equals(b2));
    b2 = new BlockBorder(new RectangleInsets(1.0, 2.0, 3.0, 4.0),
            Color.blue);
    assertTrue(b1.equals(b2));
}
 
Example #17
Source File: PeriodAxisLabelInfo.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param periodClass  the subclass of {@link RegularTimePeriod} to use
 *                     (<code>null</code> not permitted).
 * @param dateFormat  the date format (<code>null</code> not permitted).
 * @param padding  controls the space around the band (<code>null</code>
 *                 not permitted).
 * @param labelFont  the label font (<code>null</code> not permitted).
 * @param labelPaint  the label paint (<code>null</code> not permitted).
 * @param drawDividers  a flag that controls whether dividers are drawn.
 * @param dividerStroke  the stroke used to draw the dividers
 *                       (<code>null</code> not permitted).
 * @param dividerPaint  the paint used to draw the dividers
 *                      (<code>null</code> not permitted).
 */
public PeriodAxisLabelInfo(Class periodClass, DateFormat dateFormat,
        RectangleInsets padding, Font labelFont, Paint labelPaint,
        boolean drawDividers, Stroke dividerStroke, Paint dividerPaint) {
    ParamChecks.nullNotPermitted(periodClass, "periodClass");
    ParamChecks.nullNotPermitted(dateFormat, "dateFormat");
    ParamChecks.nullNotPermitted(padding, "padding");
    ParamChecks.nullNotPermitted(labelFont, "labelFont");
    ParamChecks.nullNotPermitted(labelPaint, "labelPaint");
    ParamChecks.nullNotPermitted(dividerStroke, "dividerStroke");
    ParamChecks.nullNotPermitted(dividerPaint, "dividerPaint");
    this.periodClass = periodClass;
    this.dateFormat = (DateFormat) dateFormat.clone();
    this.padding = padding;
    this.labelFont = labelFont;
    this.labelPaint = labelPaint;
    this.drawDividers = drawDividers;
    this.dividerStroke = dividerStroke;
    this.dividerPaint = dividerPaint;
}
 
Example #18
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
protected void configurePlot(Plot plot, JRChartPlot jrPlot)
{
	RectangleInsets padding = getPlotSettings().getPadding();
	if (padding != null) 
		plot.setInsets(padding);

	Boolean plotOutlineVisible = getPlotSettings().getOutlineVisible();
	if (plotOutlineVisible == null || plotOutlineVisible) 
	{
		Paint outlinePaint = getPlotSettings().getOutlinePaint() == null ? null : getPlotSettings().getOutlinePaint().getPaint();
		if (outlinePaint != null)
			plot.setOutlinePaint(outlinePaint);
		
		Stroke plotOutlineStroke = getPlotSettings().getOutlineStroke();
		if (plotOutlineStroke != null)
			plot.setOutlineStroke(plotOutlineStroke);
		
		plot.setOutlineVisible(true);
	}
	else
	{
		plot.setOutlineVisible(false);
	}
	
	setPlotBackground(plot, jrPlot);
	setPlotDrawingDefaults(plot, jrPlot);
	
	if (plot instanceof CategoryPlot)
	{
		handleCategoryPlotSettings((CategoryPlot)plot, jrPlot);
	}

	if (plot instanceof XYPlot)
	{
		handleXYPlotSettings((XYPlot)plot, jrPlot);
	}

}
 
Example #19
Source File: CategoryAxis.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A utility method for determining the width of a text block.
 *
 * @param block  the text block.
 * @param position  the position.
 * @param g2  the graphics device.
 *
 * @return The width.
 */
protected double calculateTextBlockWidth(TextBlock block,
        CategoryLabelPosition position, Graphics2D g2) {
    RectangleInsets insets = getTickLabelInsets();
    Size2D size = block.calculateDimensions(g2);
    Rectangle2D box = new Rectangle2D.Double(0.0, 0.0, size.getWidth(),
            size.getHeight());
    Shape rotatedBox = ShapeUtilities.rotateShape(box, position.getAngle(),
            0.0f, 0.0f);
    double w = rotatedBox.getBounds2D().getWidth() + insets.getLeft()
            + insets.getRight();
    return w;
}
 
Example #20
Source File: ChartFormatter.java    From nmonvisualizer with Apache License 2.0 5 votes vote down vote up
void formatLegend(LegendTitle legend) {
    legend.setItemFont(LEGEND_FONT);
    legend.setItemPaint(textColor);
    legend.setBorder(0, 0, 0, 0);
    legend.setPosition(RectangleEdge.BOTTOM);

    legend.setItemLabelPadding(new RectangleInsets(5, 5, 5, 5));
}
 
Example #21
Source File: ValueAxis.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * A utility method for determining the width of the widest tick label.
 *
 * @param ticks  the ticks.
 * @param g2  the graphics device.
 * @param drawArea  the area within which the plot and axes should be drawn.
 * @param vertical  a flag that indicates whether or not the tick labels 
 *                  are 'vertical'.
 *
 * @return The width of the tallest tick label.
 */
protected double findMaximumTickLabelWidth(List ticks, 
                                           Graphics2D g2, 
                                           Rectangle2D drawArea, 
                                           boolean vertical) {
                                               
    RectangleInsets insets = getTickLabelInsets();
    Font font = getTickLabelFont();
    double maxWidth = 0.0;
    if (!vertical) {
        FontMetrics fm = g2.getFontMetrics(font);
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            Tick tick = (Tick) iterator.next();
            Rectangle2D labelBounds = TextUtilities.getTextBounds(
                    tick.getText(), g2, fm);
            if (labelBounds.getWidth() + insets.getLeft() 
                    + insets.getRight() > maxWidth) {
                maxWidth = labelBounds.getWidth() 
                           + insets.getLeft() + insets.getRight();
            }
        }
    }
    else {
        LineMetrics metrics = font.getLineMetrics("ABCxyz", 
                g2.getFontRenderContext());
        maxWidth = metrics.getHeight() 
                   + insets.getTop() + insets.getBottom();
    }
    return maxWidth;
    
}
 
Example #22
Source File: ValueAxis.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * A utility method for determining the height of the tallest tick label.
 *
 * @param ticks  the ticks.
 * @param g2  the graphics device.
 * @param drawArea  the area within which the plot and axes should be drawn.
 * @param vertical  a flag that indicates whether or not the tick labels
 *                  are 'vertical'.
 *
 * @return The height of the tallest tick label.
 */
protected double findMaximumTickLabelHeight(List ticks, Graphics2D g2,
        Rectangle2D drawArea, boolean vertical) {

    RectangleInsets insets = getTickLabelInsets();
    Font font = getTickLabelFont();
    g2.setFont(font);
    double maxHeight = 0.0;
    if (vertical) {
        FontMetrics fm = g2.getFontMetrics(font);
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            Tick tick = (Tick) iterator.next();
            Rectangle2D labelBounds = null;
            if (tick instanceof LogTick) {
                LogTick lt = (LogTick) tick;
                if (lt.getAttributedLabel() != null) {
                    labelBounds = AttrStringUtils.getTextBounds(
                            lt.getAttributedLabel(), g2);
                }
            } else if (tick.getText() != null) {
                labelBounds = TextUtilities.getTextBounds(
                        tick.getText(), g2, fm);
            }
            if (labelBounds != null && labelBounds.getWidth() 
                    + insets.getTop() + insets.getBottom() > maxHeight) {
                maxHeight = labelBounds.getWidth()
                            + insets.getTop() + insets.getBottom();
            }
        }
    } else {
        LineMetrics metrics = font.getLineMetrics("ABCxyz",
                g2.getFontRenderContext());
        maxHeight = metrics.getHeight()
                    + insets.getTop() + insets.getBottom();
    }
    return maxHeight;

}
 
Example #23
Source File: PiePlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a 
 * printer).
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing 
 *              (<code>null</code> permitted).
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor,
                 PlotState parentState, PlotRenderingInfo info) {

    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    if (info != null) {
        info.setPlotArea(area);
        info.setDataArea(area);
    }

    drawBackground(g2, area);
    drawOutline(g2, area);

    Shape savedClip = g2.getClip();
    g2.clip(area);

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 
            getForegroundAlpha()));

    if (!DatasetUtilities.isEmptyOrNull(this.dataset)) {
        drawPie(g2, area, info);
    }
    else {
        drawNoDataMessage(g2, area);
    }

    g2.setClip(savedClip);
    g2.setComposite(originalComposite);

    drawOutline(g2, area);

}
 
Example #24
Source File: BlockBorder.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new border.
 * 
 * @param insets  the border insets (<code>null</code> not permitted).
 * @param paint  the paint (<code>null</code> not permitted).
 */
public BlockBorder(RectangleInsets insets, Paint paint) {
    if (insets == null) {
        throw new IllegalArgumentException("Null 'insets' argument.");
    }
    if (paint == null) {
        throw new IllegalArgumentException("Null 'paint' argument.");   
    }
    this.insets = insets;
    this.paint = paint;
}
 
Example #25
Source File: DateAxis.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Estimates the maximum width of the tick labels, assuming the specified 
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we
 * just look at two values: the lower bound and the upper bound for the 
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelWidth(Graphics2D g2, 
                                             DateTickUnit unit) {

    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();

    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of 
        // the font)...
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr = null;
        String upperStr = null;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
Example #26
Source File: Marker.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new marker.
 *
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 * @param outlinePaint  the outline paint (<code>null</code> permitted).
 * @param outlineStroke  the outline stroke (<code>null</code> permitted).
 * @param alpha  the alpha transparency (must be in the range 0.0f to 
 *     1.0f).
 *     
 * @throws IllegalArgumentException if <code>paint</code> or 
 *     <code>stroke</code> is <code>null</code>, or <code>alpha</code> is 
 *     not in the specified range.
 */
protected Marker(Paint paint, Stroke stroke, 
                 Paint outlinePaint, Stroke outlineStroke, 
                 float alpha) {

    if (paint == null) {
        throw new IllegalArgumentException("Null 'paint' argument.");
    }
    if (stroke == null) {
        throw new IllegalArgumentException("Null 'stroke' argument.");
    }
    if (alpha < 0.0f || alpha > 1.0f)
        throw new IllegalArgumentException(
                "The 'alpha' value must be in the range 0.0f to 1.0f");
    
    this.paint = paint;
    this.stroke = stroke;
    this.outlinePaint = outlinePaint;
    this.outlineStroke = outlineStroke;
    this.alpha = alpha;
    
    this.labelFont = new Font("SansSerif", Font.PLAIN, 9);
    this.labelPaint = Color.black;
    this.labelAnchor = RectangleAnchor.TOP_LEFT;
    this.labelOffset = new RectangleInsets(3.0, 3.0, 3.0, 3.0);
    this.labelOffsetType = LengthAdjustmentType.CONTRACT;
    this.labelTextAnchor = TextAnchor.CENTER;
    
    this.listenerList = new EventListenerList();
}
 
Example #27
Source File: JFreeChart.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the padding between the chart border and the chart drawing area,
 * and sends a {@link ChartChangeEvent} to all registered listeners.
 * 
 * @param padding  the padding (<code>null</code> not permitted).
 */
public void setPadding(RectangleInsets padding) {
    if (padding == null) {
        throw new IllegalArgumentException("Null 'padding' argument.");   
    }
    this.padding = padding;
    notifyListeners(new ChartChangeEvent(this));
}
 
Example #28
Source File: StandardChartTheme.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new default instance.
 *
 * @param name  the name of the theme (<code>null</code> not permitted).
 * @param shadow  a flag that controls whether a shadow generator is 
 *                included.
 *
 * @since 1.0.14
 */
public StandardChartTheme(String name, boolean shadow) {
    ParamChecks.nullNotPermitted(name, "name");
    this.name = name;
    this.extraLargeFont = new Font("Tahoma", Font.BOLD, 20);
    this.largeFont = new Font("Tahoma", Font.BOLD, 14);
    this.regularFont = new Font("Tahoma", Font.PLAIN, 12);
    this.smallFont = new Font("Tahoma", Font.PLAIN, 10);
    this.titlePaint = Color.black;
    this.subtitlePaint = Color.black;
    this.legendBackgroundPaint = Color.white;
    this.legendItemPaint = Color.darkGray;
    this.chartBackgroundPaint = Color.white;
    this.drawingSupplier = new DefaultDrawingSupplier();
    this.plotBackgroundPaint = Color.lightGray;
    this.plotOutlinePaint = Color.black;
    this.labelLinkPaint = Color.black;
    this.labelLinkStyle = PieLabelLinkStyle.CUBIC_CURVE;
    this.axisOffset = new RectangleInsets(4, 4, 4, 4);
    this.domainGridlinePaint = Color.white;
    this.rangeGridlinePaint = Color.white;
    this.baselinePaint = Color.black;
    this.crosshairPaint = Color.blue;
    this.axisLabelPaint = Color.darkGray;
    this.tickLabelPaint = Color.darkGray;
    this.barPainter = new GradientBarPainter();
    this.xyBarPainter = new GradientXYBarPainter();
    this.shadowVisible = false;
    this.shadowPaint = Color.gray;
    this.itemLabelPaint = Color.black;
    this.thermometerPaint = Color.white;
    this.wallPaint = BarRenderer3D.DEFAULT_WALL_PAINT;
    this.errorIndicatorPaint = Color.black;
    this.shadowGenerator = shadow ? new DefaultShadowGenerator() : null;
}
 
Example #29
Source File: CombinedDomainXYPlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a subplot with the specified weight and sends a 
 * {@link PlotChangeEvent} to all registered listeners.  The weight 
 * determines how much space is allocated to the subplot relative to all 
 * the other subplots.
 * <P>
 * The domain axis for the subplot will be set to <code>null</code>.  You
 * must ensure that the subplot has a non-null range axis.
 *
 * @param subplot  the subplot (<code>null</code> not permitted).
 * @param weight  the weight (must be >= 1).
 */
public void add(XYPlot subplot, int weight) {

    if (subplot == null) {
        throw new IllegalArgumentException("Null 'subplot' argument.");
    }
    if (weight <= 0) {
        throw new IllegalArgumentException("Require weight >= 1.");
    }

    // store the plot and its weight
    subplot.setParent(this);
    subplot.setWeight(weight);
    subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0), false);
    subplot.setDomainAxis(null);
    subplot.addChangeListener(this);
    this.subplots.add(subplot);

    // keep track of total weights
    this.totalWeight += weight;

    ValueAxis axis = getDomainAxis();
    if (axis != null) {
        axis.configure();
    }
    
    notifyListeners(new PlotChangeEvent(this));

}
 
Example #30
Source File: DateAxis.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Estimates the maximum width of the tick labels, assuming the specified
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we
 * just look at two values: the lower bound and the upper bound for the
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelHeight(Graphics2D g2,
        DateTickUnit unit) {

    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();

    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (!isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of
        // the font)...
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr, upperStr;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}