Java Code Examples for org.jfree.ui.RectangleEdge#TOP
The following examples show how to use
org.jfree.ui.RectangleEdge#TOP .
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: CategoryAxis.java From opensim-gui with Apache License 2.0 | 6 votes |
/** * Returns the starting coordinate for the specified category. * * @param category the category. * @param categoryCount the number of categories. * @param area the data area. * @param edge the axis location. * * @return The coordinate. */ public double getCategoryStart(int category, int categoryCount, Rectangle2D area, RectangleEdge edge) { double result = 0.0; if ((edge == RectangleEdge.TOP) || (edge == RectangleEdge.BOTTOM)) { result = area.getX() + area.getWidth() * getLowerMargin(); } else if ((edge == RectangleEdge.LEFT) || (edge == RectangleEdge.RIGHT)) { result = area.getMinY() + area.getHeight() * getLowerMargin(); } double categorySize = calculateCategorySize(categoryCount, area, edge); double categoryGapWidth = calculateCategoryGapSize( categoryCount, area, edge ); result = result + category * (categorySize + categoryGapWidth); return result; }
Example 2
Source File: ValueAxis.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * 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 3
Source File: CategoryAxis.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Calculates the size (width or height, depending on the location of the * axis) of a category. * * @param categoryCount the number of categories. * @param area the area within which the categories will be drawn. * @param edge the axis location. * * @return The category size. */ protected double calculateCategorySize(int categoryCount, Rectangle2D area, RectangleEdge edge) { double result; double available = 0.0; if ((edge == RectangleEdge.TOP) || (edge == RectangleEdge.BOTTOM)) { available = area.getWidth(); } else if ((edge == RectangleEdge.LEFT) || (edge == RectangleEdge.RIGHT)) { available = area.getHeight(); } if (categoryCount > 1) { result = available * (1 - getLowerMargin() - getUpperMargin() - getCategoryMargin()); result = result / categoryCount; } else { result = available * (1 - getLowerMargin() - getUpperMargin()); } return result; }
Example 4
Source File: BorderArrangement.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Adds a block to the arrangement manager at the specified edge. * If the key is not an instance of {@link RectangleEdge} the block will * be added in the center. * * @param block the block (<code>null</code> permitted). * @param key the edge (an instance of {@link RectangleEdge}) or * <code>null</code> for the center block. */ @Override public void add(Block block, Object key) { if (!(key instanceof RectangleEdge)) { // catches null also this.centerBlock = block; } else { RectangleEdge edge = (RectangleEdge) key; if (edge == RectangleEdge.TOP) { this.topBlock = block; } else if (edge == RectangleEdge.BOTTOM) { this.bottomBlock = block; } else if (edge == RectangleEdge.LEFT) { this.leftBlock = block; } else if (edge == RectangleEdge.RIGHT) { this.rightBlock = block; } } }
Example 5
Source File: AxisSpace.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Calculates the reserved area. * * @param area the area. * @param edge the edge. * * @return The reserved area. */ public Rectangle2D reserved(Rectangle2D area, RectangleEdge edge) { Rectangle2D result = null; if (edge == RectangleEdge.TOP) { result = new Rectangle2D.Double( area.getX(), area.getY(), area.getWidth(), this.top ); } else if (edge == RectangleEdge.BOTTOM) { result = new Rectangle2D.Double( area.getX(), area.getMaxY() - this.top, area.getWidth(), this.bottom ); } else if (edge == RectangleEdge.LEFT) { result = new Rectangle2D.Double( area.getX(), area.getY(), this.left, area.getHeight() ); } else if (edge == RectangleEdge.RIGHT) { result = new Rectangle2D.Double( area.getMaxX() - this.right, area.getY(), this.right, area.getHeight() ); } return result; }
Example 6
Source File: CyclicNumberAxis.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Draws the axis. * * @param g2 the graphics device (<code>null</code> not permitted). * @param cursor the cursor position. * @param plotArea the plot area (<code>null</code> not permitted). * @param dataArea the data area (<code>null</code> not permitted). * @param edge the edge (<code>null</code> not permitted). * @param plotState collects information about the plot * (<code>null</code> permitted). * * @return The axis state (never <code>null</code>). */ @Override public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState) { AxisState ret = super.draw(g2, cursor, plotArea, dataArea, edge, plotState); if (isAdvanceLineVisible()) { double xx = valueToJava2D(getRange().getUpperBound(), dataArea, edge); Line2D mark = null; g2.setStroke(getAdvanceLineStroke()); g2.setPaint(getAdvanceLinePaint()); if (edge == RectangleEdge.LEFT) { mark = new Line2D.Double(cursor, xx, cursor + dataArea.getWidth(), xx); } else if (edge == RectangleEdge.RIGHT) { mark = new Line2D.Double(cursor - dataArea.getWidth(), xx, cursor, xx); } else if (edge == RectangleEdge.TOP) { mark = new Line2D.Double(xx, cursor + dataArea.getHeight(), xx, cursor); } else if (edge == RectangleEdge.BOTTOM) { mark = new Line2D.Double(xx, cursor, xx, cursor - dataArea.getHeight()); } g2.draw(mark); } return ret; }
Example 7
Source File: ImageTitle.java From ECG-Viewer with GNU General Public License v2.0 | 4 votes |
/** * Draws the title on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param chartArea the area within which the title (and plot) should be * drawn. * * @return The size of the area used by the title. */ protected Size2D drawHorizontal(Graphics2D g2, Rectangle2D chartArea) { double startY; double topSpace; double bottomSpace; double leftSpace; double rightSpace; double w = getWidth(); double h = getHeight(); RectangleInsets padding = getPadding(); topSpace = padding.calculateTopOutset(h); bottomSpace = padding.calculateBottomOutset(h); leftSpace = padding.calculateLeftOutset(w); rightSpace = padding.calculateRightOutset(w); if (getPosition() == RectangleEdge.TOP) { startY = chartArea.getY() + topSpace; } else { startY = chartArea.getY() + chartArea.getHeight() - bottomSpace - h; } // what is our alignment? HorizontalAlignment horizontalAlignment = getHorizontalAlignment(); double startX = 0.0; if (horizontalAlignment == HorizontalAlignment.CENTER) { startX = chartArea.getX() + leftSpace + chartArea.getWidth() / 2.0 - w / 2.0; } else if (horizontalAlignment == HorizontalAlignment.LEFT) { startX = chartArea.getX() + leftSpace; } else if (horizontalAlignment == HorizontalAlignment.RIGHT) { startX = chartArea.getX() + chartArea.getWidth() - rightSpace - w; } g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h, null); return new Size2D(chartArea.getWidth() + leftSpace + rightSpace, h + topSpace + bottomSpace); }
Example 8
Source File: CyclicNumberAxis.java From SIMVA-SoS with Apache License 2.0 | 4 votes |
/** * Draws the tick marks and labels. * * @param g2 the graphics device. * @param cursor the cursor. * @param plotArea the plot area. * @param dataArea the area inside the axes. * @param edge the side on which the axis is displayed. * * @return The axis state. */ @Override protected AxisState drawTickMarksAndLabels(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge) { this.internalMarkerWhenTicksOverlap = false; AxisState ret = super.drawTickMarksAndLabels(g2, cursor, plotArea, dataArea, edge); // continue and separate the labels only if necessary if (!this.internalMarkerWhenTicksOverlap) { return ret; } double ol; FontMetrics fm = g2.getFontMetrics(getTickLabelFont()); if (isVerticalTickLabels()) { ol = fm.getMaxAdvance(); } else { ol = fm.getHeight(); } double il = 0; if (isTickMarksVisible()) { float xx = (float) valueToJava2D(getRange().getUpperBound(), dataArea, edge); Line2D mark = null; g2.setStroke(getTickMarkStroke()); g2.setPaint(getTickMarkPaint()); if (edge == RectangleEdge.LEFT) { mark = new Line2D.Double(cursor - ol, xx, cursor + il, xx); } else if (edge == RectangleEdge.RIGHT) { mark = new Line2D.Double(cursor + ol, xx, cursor - il, xx); } else if (edge == RectangleEdge.TOP) { mark = new Line2D.Double(xx, cursor - ol, xx, cursor + il); } else if (edge == RectangleEdge.BOTTOM) { mark = new Line2D.Double(xx, cursor + ol, xx, cursor - il); } g2.draw(mark); } return ret; }
Example 9
Source File: CategoryAxis.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * Estimates the space required for the axis, given a specific drawing area. * * @param g2 the graphics device (used to obtain font information). * @param plot the plot that the axis belongs to. * @param plotArea the area within which the axis should be drawn. * @param edge the axis location (top or bottom). * @param space the space already reserved. * * @return The space required to draw the axis. */ @Override public AxisSpace reserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge, AxisSpace space) { // 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 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, labelWidth; if (RectangleEdge.isTopOrBottom(edge)) { labelHeight = labelEnclosure.getHeight(); space.add(labelHeight + tickLabelHeight + this.categoryLabelPositionOffset, edge); } else if (RectangleEdge.isLeftOrRight(edge)) { labelWidth = labelEnclosure.getWidth(); space.add(labelWidth + tickLabelWidth + this.categoryLabelPositionOffset, edge); } return space; }
Example 10
Source File: ImageTitle.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Draws the title on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param chartArea the area within which the title (and plot) should be * drawn. * * @return The size of the area used by the title. */ protected Size2D drawHorizontal(Graphics2D g2, Rectangle2D chartArea) { double startY; double topSpace; double bottomSpace; double leftSpace; double rightSpace; double w = getWidth(); double h = getHeight(); RectangleInsets padding = getPadding(); topSpace = padding.calculateTopOutset(h); bottomSpace = padding.calculateBottomOutset(h); leftSpace = padding.calculateLeftOutset(w); rightSpace = padding.calculateRightOutset(w); if (getPosition() == RectangleEdge.TOP) { startY = chartArea.getY() + topSpace; } else { startY = chartArea.getY() + chartArea.getHeight() - bottomSpace - h; } // what is our alignment? HorizontalAlignment horizontalAlignment = getHorizontalAlignment(); double startX = 0.0; if (horizontalAlignment == HorizontalAlignment.CENTER) { startX = chartArea.getX() + leftSpace + chartArea.getWidth() / 2.0 - w / 2.0; } else if (horizontalAlignment == HorizontalAlignment.LEFT) { startX = chartArea.getX() + leftSpace; } else if (horizontalAlignment == HorizontalAlignment.RIGHT) { startX = chartArea.getX() + chartArea.getWidth() - rightSpace - w; } g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h, null); return new Size2D(chartArea.getWidth() + leftSpace + rightSpace, h + topSpace + bottomSpace); }
Example 11
Source File: LineChart.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
public JFreeChart createChart(){ logger.debug("IN"); CategoryPlot plot = new CategoryPlot(); NumberAxis rangeAxis = new NumberAxis("Kpi Values"); rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12 )); Color colorLabel= Color.decode("#000000"); rangeAxis.setLabelPaint(colorLabel); rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10 )); rangeAxis.setTickLabelPaint(colorLabel); plot.setRangeAxis(rangeAxis); CategoryAxis domainAxis = new CategoryAxis(); domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10 )); domainAxis.setLabelPaint(colorLabel); domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10 )); domainAxis.setTickLabelPaint(colorLabel); plot.setDomainAxis(domainAxis); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); //I create a line renderer MyStandardCategoryItemLabelGenerator generator=null; LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(); lineRenderer.setShapesFilled(true); lineRenderer.setBaseItemLabelGenerator(generator); lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12 )); lineRenderer.setBaseItemLabelPaint(colorLabel); lineRenderer.setBaseItemLabelsVisible(true); DefaultCategoryDataset datasetLine=(DefaultCategoryDataset)datasetMap.getDatasets().get("line"); for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) { String serName = (String) iterator.next(); String labelName = ""; int index=-1; index=datasetLine.getRowIndex(serName); Color color=Color.decode("#990200"); lineRenderer.setSeriesPaint(index, color); } plot.setDataset(0,datasetLine); plot.setRenderer(0,lineRenderer); plot.getDomainAxis().setCategoryLabelPositions( CategoryLabelPositions.UP_45); JFreeChart chart = new JFreeChart(plot); logger.debug("Chart created"); TextTitle title=new TextTitle(name,new Font("Arial", Font.BOLD, 16 ),Color.decode("#990200"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.setTitle(title); TextTitle subTitle =new TextTitle(subName,new Font("Arial", Font.PLAIN, 12 ),Color.decode("#000000"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle); TextTitle subTitle2 =new TextTitle(subName,new Font("Arial", Font.PLAIN, 8 ),Color.decode("#FFFFFF"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle2); chart.removeLegend(); chart.setBackgroundPaint(Color.white); logger.debug("OUT"); return chart; }
Example 12
Source File: StandardXYBarPainter.java From ECG-Viewer with GNU General Public License v2.0 | 4 votes |
/** * Creates a shadow for the bar. * * @param bar the bar shape. * @param xOffset the x-offset for the shadow. * @param yOffset the y-offset for the shadow. * @param base the edge that is the base of the bar. * @param pegShadow peg the shadow to the base? * * @return A rectangle for the shadow. */ private Rectangle2D createShadow(RectangularShape bar, double xOffset, double yOffset, RectangleEdge base, boolean pegShadow) { double x0 = bar.getMinX(); double x1 = bar.getMaxX(); double y0 = bar.getMinY(); double y1 = bar.getMaxY(); if (base == RectangleEdge.TOP) { x0 += xOffset; x1 += xOffset; if (!pegShadow) { y0 += yOffset; } y1 += yOffset; } else if (base == RectangleEdge.BOTTOM) { x0 += xOffset; x1 += xOffset; y0 += yOffset; if (!pegShadow) { y1 += yOffset; } } else if (base == RectangleEdge.LEFT) { if (!pegShadow) { x0 += xOffset; } x1 += xOffset; y0 += yOffset; y1 += yOffset; } else if (base == RectangleEdge.RIGHT) { x0 += xOffset; if (!pegShadow) { x1 += xOffset; } y0 += yOffset; y1 += yOffset; } return new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0)); }
Example 13
Source File: CategoryAxis.java From opensim-gui with Apache License 2.0 | 4 votes |
/** * Creates a temporary list of ticks that can be used when drawing the axis. * * @param g2 the graphics device (used to get font measurements). * @param state the axis state. * @param dataArea the area inside the axes. * @param edge the location of the axis. * * @return A list of ticks. */ 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.categoryLabelPositions.getLabelPosition(edge); float r = this.maximumCategoryLabelWidthRatio; 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(); 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; }
Example 14
Source File: LogAxis.java From SIMVA-SoS with Apache License 2.0 | 4 votes |
/** * Returns a list of ticks for an axis at the top or bottom of the chart. * * @param g2 the graphics device ({@code null} not permitted). * @param dataArea the data area ({@code null} not permitted). * @param edge the edge ({@code null} not permitted). * * @return A list of ticks. */ protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { Range range = getRange(); List ticks = new ArrayList(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); TextAnchor textAnchor; if (edge == RectangleEdge.TOP) { textAnchor = TextAnchor.BOTTOM_CENTER; } else { textAnchor = TextAnchor.TOP_CENTER; } if (isAutoTickUnitSelection()) { selectAutoTickUnit(g2, dataArea, edge); } int minorTickCount = this.tickUnit.getMinorTickCount(); double unit = getTickUnit().getSize(); double index = Math.ceil(calculateLog(getRange().getLowerBound()) / unit); double start = index * unit; double end = calculateLog(getUpperBound()); double current = start; boolean hasTicks = (this.tickUnit.getSize() > 0.0) && !Double.isInfinite(start); while (hasTicks && current <= end) { double v = calculateValueNoINF(current); if (range.contains(v)) { ticks.add(new LogTick(TickType.MAJOR, v, createTickLabel(v), textAnchor)); } // add minor ticks (for gridlines) double next = Math.pow(this.base, current + this.tickUnit.getSize()); for (int i = 1; i < minorTickCount; i++) { double minorV = v + i * ((next - v) / minorTickCount); if (range.contains(minorV)) { ticks.add(new LogTick(TickType.MINOR, minorV, null, textAnchor)); } } current = current + this.tickUnit.getSize(); } return ticks; }
Example 15
Source File: ColorBar.java From opensim-gui with Apache License 2.0 | 4 votes |
/** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param cursor the cursor. * @param plotArea the area within which the chart should be drawn. * @param dataArea the area within which the plot should be drawn (a * subset of the drawArea). * @param reservedArea the reserved area. * @param edge the color bar location. * * @return The new cursor location. */ public double draw(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, Rectangle2D reservedArea, RectangleEdge edge) { Rectangle2D colorBarArea = null; double thickness = calculateBarThickness(dataArea, edge); if (this.colorBarThickness > 0) { thickness = this.colorBarThickness; // allow fixed thickness } double length = 0.0; if (RectangleEdge.isLeftOrRight(edge)) { length = dataArea.getHeight(); } else { length = dataArea.getWidth(); } if (this.colorBarLength > 0) { length = this.colorBarLength; } if (edge == RectangleEdge.BOTTOM) { colorBarArea = new Rectangle2D.Double( dataArea.getX(), plotArea.getMaxY() + this.outerGap, length, thickness ); } else if (edge == RectangleEdge.TOP) { colorBarArea = new Rectangle2D.Double( dataArea.getX(), reservedArea.getMinY() + this.outerGap, length, thickness ); } else if (edge == RectangleEdge.LEFT) { colorBarArea = new Rectangle2D.Double( plotArea.getX() - thickness - this.outerGap , dataArea.getMinY(), thickness, length ); } else if (edge == RectangleEdge.RIGHT) { colorBarArea = new Rectangle2D.Double( plotArea.getMaxX() + this.outerGap, dataArea.getMinY(), thickness, length ); } // update, but dont draw tick marks (needed for stepped colors) this.axis.refreshTicks( g2, new AxisState(), colorBarArea, edge ); drawColorBar(g2, colorBarArea, edge); AxisState state = null; if (edge == RectangleEdge.TOP) { cursor = colorBarArea.getMinY(); state = this.axis.draw( g2, cursor, reservedArea, colorBarArea, RectangleEdge.TOP, null ); } else if (edge == RectangleEdge.BOTTOM) { cursor = colorBarArea.getMaxY(); state = this.axis.draw( g2, cursor, reservedArea, colorBarArea, RectangleEdge.BOTTOM, null ); } else if (edge == RectangleEdge.LEFT) { cursor = colorBarArea.getMinX(); state = this.axis.draw( g2, cursor, reservedArea, colorBarArea, RectangleEdge.LEFT, null ); } else if (edge == RectangleEdge.RIGHT) { cursor = colorBarArea.getMaxX(); state = this.axis.draw( g2, cursor, reservedArea, colorBarArea, RectangleEdge.RIGHT, null ); } return state.getCursor(); }
Example 16
Source File: LogAxis.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Returns a list of ticks for an axis at the top or bottom of the chart. * * @param g2 the graphics device ({@code null} not permitted). * @param dataArea the data area ({@code null} not permitted). * @param edge the edge ({@code null} not permitted). * * @return A list of ticks. */ protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { Range range = getRange(); List ticks = new ArrayList(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); TextAnchor textAnchor; if (edge == RectangleEdge.TOP) { textAnchor = TextAnchor.BOTTOM_CENTER; } else { textAnchor = TextAnchor.TOP_CENTER; } if (isAutoTickUnitSelection()) { selectAutoTickUnit(g2, dataArea, edge); } int minorTickCount = this.tickUnit.getMinorTickCount(); double unit = getTickUnit().getSize(); double index = Math.ceil(calculateLog(getRange().getLowerBound()) / unit); double start = index * unit; double end = calculateLog(getUpperBound()); double current = start; boolean hasTicks = (this.tickUnit.getSize() > 0.0) && !Double.isInfinite(start); while (hasTicks && current <= end) { double v = calculateValueNoINF(current); if (range.contains(v)) { ticks.add(new LogTick(TickType.MAJOR, v, createTickLabel(v), textAnchor)); } // add minor ticks (for gridlines) double next = Math.pow(this.base, current + this.tickUnit.getSize()); for (int i = 1; i < minorTickCount; i++) { double minorV = v + i * ((next - v) / minorTickCount); if (range.contains(minorV)) { ticks.add(new LogTick(TickType.MINOR, minorV, null, textAnchor)); } } current = current + this.tickUnit.getSize(); } return ticks; }
Example 17
Source File: GradientBarPainter.java From SIMVA-SoS with Apache License 2.0 | 4 votes |
/** * Creates a shadow for the bar. * * @param bar the bar shape. * @param xOffset the x-offset for the shadow. * @param yOffset the y-offset for the shadow. * @param base the edge that is the base of the bar. * @param pegShadow peg the shadow to the base? * * @return A rectangle for the shadow. */ private Rectangle2D createShadow(RectangularShape bar, double xOffset, double yOffset, RectangleEdge base, boolean pegShadow) { double x0 = bar.getMinX(); double x1 = bar.getMaxX(); double y0 = bar.getMinY(); double y1 = bar.getMaxY(); if (base == RectangleEdge.TOP) { x0 += xOffset; x1 += xOffset; if (!pegShadow) { y0 += yOffset; } y1 += yOffset; } else if (base == RectangleEdge.BOTTOM) { x0 += xOffset; x1 += xOffset; y0 += yOffset; if (!pegShadow) { y1 += yOffset; } } else if (base == RectangleEdge.LEFT) { if (!pegShadow) { x0 += xOffset; } x1 += xOffset; y0 += yOffset; y1 += yOffset; } else if (base == RectangleEdge.RIGHT) { x0 += xOffset; if (!pegShadow) { x1 += xOffset; } y0 += yOffset; y1 += yOffset; } return new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0)); }
Example 18
Source File: CyclicNumberAxis.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Draws the tick marks and labels. * * @param g2 the graphics device. * @param cursor the cursor. * @param plotArea the plot area. * @param dataArea the area inside the axes. * @param edge the side on which the axis is displayed. * * @return The axis state. */ @Override protected AxisState drawTickMarksAndLabels(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge) { this.internalMarkerWhenTicksOverlap = false; AxisState ret = super.drawTickMarksAndLabels(g2, cursor, plotArea, dataArea, edge); // continue and separate the labels only if necessary if (!this.internalMarkerWhenTicksOverlap) { return ret; } double ol; FontMetrics fm = g2.getFontMetrics(getTickLabelFont()); if (isVerticalTickLabels()) { ol = fm.getMaxAdvance(); } else { ol = fm.getHeight(); } double il = 0; if (isTickMarksVisible()) { float xx = (float) valueToJava2D(getRange().getUpperBound(), dataArea, edge); Line2D mark = null; g2.setStroke(getTickMarkStroke()); g2.setPaint(getTickMarkPaint()); if (edge == RectangleEdge.LEFT) { mark = new Line2D.Double(cursor - ol, xx, cursor + il, xx); } else if (edge == RectangleEdge.RIGHT) { mark = new Line2D.Double(cursor + ol, xx, cursor - il, xx); } else if (edge == RectangleEdge.TOP) { mark = new Line2D.Double(xx, cursor - ol, xx, cursor + il); } else if (edge == RectangleEdge.BOTTOM) { mark = new Line2D.Double(xx, cursor + ol, xx, cursor - il); } g2.draw(mark); } return ret; }
Example 19
Source File: LogAxis.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * Returns a list of ticks for an axis at the top or bottom of the chart. * * @param g2 the graphics device ({@code null} not permitted). * @param dataArea the data area ({@code null} not permitted). * @param edge the edge ({@code null} not permitted). * * @return A list of ticks. */ protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { Range range = getRange(); List ticks = new ArrayList(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); TextAnchor textAnchor; if (edge == RectangleEdge.TOP) { textAnchor = TextAnchor.BOTTOM_CENTER; } else { textAnchor = TextAnchor.TOP_CENTER; } if (isAutoTickUnitSelection()) { selectAutoTickUnit(g2, dataArea, edge); } int minorTickCount = this.tickUnit.getMinorTickCount(); double unit = getTickUnit().getSize(); double index = Math.ceil(calculateLog(getRange().getLowerBound()) / unit); double start = index * unit; double end = calculateLog(getUpperBound()); double current = start; boolean hasTicks = (this.tickUnit.getSize() > 0.0) && !Double.isInfinite(start); while (hasTicks && current <= end) { double v = calculateValueNoINF(current); if (range.contains(v)) { ticks.add(new LogTick(TickType.MAJOR, v, createTickLabel(v), textAnchor)); } // add minor ticks (for gridlines) double next = Math.pow(this.base, current + this.tickUnit.getSize()); for (int i = 1; i < minorTickCount; i++) { double minorV = v + i * ((next - v) / minorTickCount); if (range.contains(minorV)) { ticks.add(new LogTick(TickType.MINOR, minorV, null, textAnchor)); } } current = current + this.tickUnit.getSize(); } return ticks; }
Example 20
Source File: ImageTitle.java From openstock with GNU General Public License v3.0 | 4 votes |
/** * Draws the title on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param chartArea the area within which the title (and plot) should be * drawn. * * @return The size of the area used by the title. */ protected Size2D drawHorizontal(Graphics2D g2, Rectangle2D chartArea) { double startY; double topSpace; double bottomSpace; double leftSpace; double rightSpace; double w = getWidth(); double h = getHeight(); RectangleInsets padding = getPadding(); topSpace = padding.calculateTopOutset(h); bottomSpace = padding.calculateBottomOutset(h); leftSpace = padding.calculateLeftOutset(w); rightSpace = padding.calculateRightOutset(w); if (getPosition() == RectangleEdge.TOP) { startY = chartArea.getY() + topSpace; } else { startY = chartArea.getY() + chartArea.getHeight() - bottomSpace - h; } // what is our alignment? HorizontalAlignment horizontalAlignment = getHorizontalAlignment(); double startX = 0.0; if (horizontalAlignment == HorizontalAlignment.CENTER) { startX = chartArea.getX() + leftSpace + chartArea.getWidth() / 2.0 - w / 2.0; } else if (horizontalAlignment == HorizontalAlignment.LEFT) { startX = chartArea.getX() + leftSpace; } else if (horizontalAlignment == HorizontalAlignment.RIGHT) { startX = chartArea.getX() + chartArea.getWidth() - rightSpace - w; } g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h, null); return new Size2D(chartArea.getWidth() + leftSpace + rightSpace, h + topSpace + bottomSpace); }