List of usage examples for java.awt.geom Rectangle2D getX
public abstract double getX();
From source file:com.igormaznitsa.sciareto.ui.editors.MMDEditor.java
public void topicToCentre(@Nullable final Topic topic) { if (topic != null) { SwingUtilities.invokeLater(new Runnable() { @Override//from ww w.ja v a 2s .com public void run() { final AbstractElement element = (AbstractElement) Assertions.assertNotNull(topic).getPayload(); if (element != null) { final Rectangle2D bounds = element.getBounds(); final Dimension viewPortSize = getViewport().getExtentSize(); final int x = Math.max(0, (int) Math .round(bounds.getX() - (viewPortSize.getWidth() - bounds.getWidth()) / 2)); final int y = Math.max(0, (int) Math .round(bounds.getY() - (viewPortSize.getHeight() - bounds.getHeight()) / 2)); getViewport().setViewPosition(new Point(x, y)); } } }); } }
From source file:ucar.unidata.idv.control.chart.RangeFilter.java
/** * Draws the annotation.// w w w .j a va 2s .co m * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info an optional info object that will be populated with * entity information. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { super.setGraphicsState(g2); if (!getPlotWrapper().okToDraw(this)) { return; } g2.setStroke(new BasicStroke()); boolean selected = getSelected(); if (attached != null) { selected |= attached.getSelected(); } if (selected) { g2.setColor(COLOR_SELECTED); } else { g2.setColor(getColor()); } y = (int) rangeAxis.valueToJava2D(rangeValue, dataArea, RectangleEdge.LEFT); int width = (int) ANNOTATION_WIDTH; int width2 = (int) (ANNOTATION_WIDTH / 2); x = (int) dataArea.getX(); // System.err.println("x/y:" + x +"/" +y); int[] xs; int[] ys; if (type == TYPE_LESSTHAN) { xs = new int[] { x, x + width, x + width2, x }; ys = new int[] { y, y, y + width, y }; } else { xs = new int[] { x, x + width, x + width2, x }; ys = new int[] { y, y, y - width, y }; } g2.fillPolygon(xs, ys, xs.length); g2.setColor(Color.gray); g2.drawLine(x + width, y, (int) (dataArea.getX() + dataArea.getWidth()), y); if ((attached != null) && (type == TYPE_LESSTHAN)) { int otherY = (int) rangeAxis.valueToJava2D(attached.rangeValue, dataArea, RectangleEdge.LEFT); g2.drawLine(x + width2, y + width, x + width2, otherY - width); } }
From source file:at.tuwien.ifs.somtoolbox.visualization.thematicmap.SOMRegion.java
public void calcGrids() { Rectangle2D rect = getBounds2D(); double w = rect.getWidth(); double h = rect.getHeight(); if (h > 150 || w > 150) { Logger.getLogger("at.tuwien.ifs.somtoolbox").fine("Error: " + this); return;//www . j a v a2 s . c om } int x = (int) rect.getX(); int y = (int) rect.getY(); int xSteps = (int) (w / (int) Grid.SIZE); int ySteps = (int) (h / (int) Grid.SIZE); for (int i = 0; i < xSteps; i++) { for (int j = 0; j < ySteps; j++) { Polygon p = new Polygon(); p.addPoint((int) (x + i * Grid.SIZE), (int) (y + j * Grid.SIZE)); p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE), (int) (y + j * Grid.SIZE)); p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE), (int) (y + Grid.SIZE + j * Grid.SIZE)); p.addPoint((int) (x + i * Grid.SIZE), (int) (y + Grid.SIZE + j * Grid.SIZE)); if (this.contains(p.getBounds().x + Grid.SIZE / 2, p.getBounds().y + Grid.SIZE / 2)) { Pnt topLeft = new Pnt(x + i * Grid.SIZE, y + j * Grid.SIZE); Pnt bottomRight = new Pnt(x + i * Grid.SIZE + Grid.SIZE, y + Grid.SIZE + j * Grid.SIZE); Grid grid = new Grid(topLeft, bottomRight); grids.add(grid); } } } }
From source file:at.tuwien.ifs.somtoolbox.visualization.thematicmap.SOMRegion.java
public void fillRegion(Graphics2D g, boolean chessboard) { if (!resolved) { fillcolor = getColor(mainClass.classIndex); Color c = repairColor(fillcolor); g.setColor(c);// w w w . j ava 2s. c om if (segments.isEmpty()) { return; } g.fillPolygon(this); } else { if (chessboard) { if (polygons == null) { // calculate polygons polygons = new ArrayList<Polygon>(); Rectangle2D rect = getBounds2D(); double w = rect.getWidth(); double h = rect.getHeight(); if (h > 200 || w > 200) { Logger.getLogger("at.tuwien.ifs.somtoolbox").info("ERROR: h>200 || w>200"); return; } int x = (int) rect.getX(); int y = (int) rect.getY(); int xSteps = (int) (w / (int) Grid.SIZE); int ySteps = (int) (h / (int) Grid.SIZE); // int n = classes.size(); for (int i = 0; i < xSteps; i++) { for (int j = 0; j < ySteps; j++) { Polygon p = new Polygon(); p.addPoint((int) (x + i * Grid.SIZE), (int) (y + j * Grid.SIZE)); p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE), (int) (y + j * Grid.SIZE)); p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE), (int) (y + Grid.SIZE + j * Grid.SIZE)); p.addPoint((int) (x + i * Grid.SIZE), (int) (y + Grid.SIZE + j * Grid.SIZE)); if (!this.contains(p.getBounds())) { continue; } SOMClass clss = indexGenerator.getNextIndex(); g.setColor(getColor(clss.classIndex)); g.fillPolygon(p); polygons.add(p); } } } else { // use pre-calculated polygons for (int i = 0; i < polygons.size(); i++) { SOMClass clss = indexGenerator.getNextIndex(); g.setColor(getColor(clss.classIndex)); Polygon p = polygons.get(i); g.fillPolygon(p); } } } else { for (int i = 0; i < grids.size(); i++) { Grid grid = grids.get(i); if (grid.clss == null) { continue; } g.setColor(getColor(grid.clss.classIndex)); g.fillRect((int) grid.topLeft.coord(0), (int) grid.topLeft.coord(1), (int) Grid.SIZE, (int) Grid.SIZE); } } } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.visio.informationflow.VisioInformationFlowExport.java
private void createNamesLegend(Rectangle2D legendsBox) throws MasterNotFoundException { double frameX = legendsBox.getX(); double frameY = legendsBox.getY() - getTargetPage().getHeight() + MARGIN_IN; double frameWidth = legendsBox.getWidth(); double frameHeight = getTargetPage().getHeight() - legendsBox.getHeight() - DISTANCE_TO_MARGIN_INCHES; createNamesLegend(frameX, frameY, frameWidth, frameHeight, informationFlowOptions.isNakedExport(), MessageAccess.getStringOrNull("graphicalExport.informationflow.title", getLocale())); }
From source file:com.newatlanta.bluedragon.CategoryAxis.java
public AxisSpace reserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge, AxisSpace space) {//www .java 2s .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.AbsorbingAreaRenderer.java
public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) { state = STATE_RUNNING;/* w w w . j a v a2 s . com*/ gridWidth = (int) dataArea.getWidth(); gridHeight = (int) dataArea.getHeight(); //imageX,imageY correspond to point(0,0) int imageX = (int) dataArea.getX() + 1; int imageY = (int) dataArea.getY() + 1; DataBufferInt dataBuffer; image = new BufferedImage(gridWidth, gridHeight, BufferedImage.TYPE_INT_RGB); WritableRaster raster = image.getRaster(); grid = ((DataBufferInt) raster.getDataBuffer()).getData(); ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis rangeAxis = plot.getRangeAxis(); xEpsilon = Math.abs((domainAxis.getUpperBound() - domainAxis.getLowerBound()) / (double) gridWidth); yEpsilon = Math.abs((rangeAxis.getUpperBound() - rangeAxis.getLowerBound()) / (double) gridHeight); int numPoints = gridHeight * gridWidth; int index = 0; int rate = numPoints / 100; if (justClearedSet) { if (criticalSetFound) { this.clearDisplay(); g2.drawImage(image, null, imageX, imageY); } justClearedSet = false; return; } if (!notYetRendered) { plotCopiedDisplay(); g2.drawImage(image, null, imageX, imageY); } notYetRendered = false; if (criticalSetFound && !findCriticalSetAgain) { if (this.chooseSegmentsSet) chooseSegments(g2, image, imageX, imageY); if (this.plotAttractorSet) plotAttractor(g2, image, imageX, imageY); if (this.iterateChosenSegmentsSet) iterateChosenSegments(g2, image, imageX, imageY); if (this.hideAttractorSet) hideAttractor(g2, image, imageX, imageY); } else { this.disableAllActionsExceptStop(); det = new AbsorbingAreaRenderer.ImplicitDeterminant(gridWidth, gridHeight, epsilon, g2, image, imageX, imageY); gridBackup = new int[grid.length]; copyDisplay(); criticalSetFound = true; findCriticalSetAgain = false; g2.drawImage(image, null, imageX, imageY); this.enableAllActionsExceptStop(); } }
From source file:org.apache.fop.render.ps.PSRenderer.java
/** * {@inheritDoc}//from ww w. j a v a 2s. c o m */ protected void startVParea(CTM ctm, Rectangle2D clippingRect) { saveGraphicsState(); if (clippingRect != null) { clipRect((float) clippingRect.getX() / 1000f, (float) clippingRect.getY() / 1000f, (float) clippingRect.getWidth() / 1000f, (float) clippingRect.getHeight() / 1000f); } // multiply with current CTM final double[] matrix = ctm.toArray(); matrix[4] /= 1000f; matrix[5] /= 1000f; concatMatrix(matrix); }
From source file:savant.view.tracks.BAMTrackRenderer.java
private void renderSNPMode(Graphics2D g2, GraphPaneAdapter gp, Resolution r) throws RenderingException { Genome genome = GenomeController.getInstance().getGenome(); if (!genome.isSequenceSet()) { throw new RenderingException("No reference sequence loaded\nSwitch to standard display mode", RenderingException.WARNING_PRIORITY); }/*from w w w . j a v a2 s . co m*/ AxisRange axisRange = (AxisRange) instructions.get(DrawingInstruction.AXIS_RANGE); ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME); List<Pileup> pileups = new ArrayList<Pileup>(); // make the pileups int length = axisRange.getXMax() - axisRange.getXMin() + 1; assert Math.abs(axisRange.getXMin()) <= Integer.MAX_VALUE; int startPosition = (int) axisRange.getXMin(); for (int j = 0; j < length; j++) { pileups.add(new Pileup(startPosition + j)); } // Go through the samrecords and edit the pileups for (Record record : data) { SAMRecord samRecord = ((BAMIntervalRecord) record).getSAMRecord(); updatePileupsFromSAMRecord(pileups, samRecord, startPosition); } double maxHeight = 0; for (Pileup p : pileups) { int current = p.getTotalCoverage(null); if (current > maxHeight) { maxHeight = current; } } gp.setXRange(axisRange.getXRange()); gp.setYRange(new Range(0, (int) Math.rint((double) maxHeight / 0.9))); double unitHeight = (Math.rint(gp.transformYPos(0) * 0.9)) / maxHeight; double unitWidth = gp.getUnitWidth(); ColourAccumulator accumulator = new ColourAccumulator(cs); List<Rectangle2D> insertions = new ArrayList<Rectangle2D>(); for (Pileup p : pileups) { int totalCoverage = p.getTotalCoverage(null); if (totalCoverage > 0) { double bottom = gp.transformYPos(0); double x = gp.transformXPos(p.getPosition()); VariantType genomeNuc = VariantType.fromChar((char) refSeq[p.getPosition() - startPosition]); VariantType snpNuc = genomeNuc; // Only record a shape if we have at least some mismatches. if (totalCoverage > p.getCoverage(genomeNuc, null)) { // Reduce height for insertions, since they don't contribute to the height. double h = unitHeight * (totalCoverage - p.getCoverage(VariantType.INSERTION, null)); recordToShapeMap.put(new PileupRecord(p, false), new Rectangle2D.Double(x, bottom - h, unitWidth, h)); } while ((genome.isSequenceSet() && (snpNuc = p.getLargestVariantType(genomeNuc)) != null) || ((snpNuc = p.getLargestVariantType(VariantType.OTHER)) != null)) { double h = unitHeight * p.getCoverage(snpNuc, null); Rectangle2D rect = new Rectangle2D.Double(x, bottom - h, unitWidth, h); accumulator.addShape(getSubPileColour(snpNuc, genomeNuc), rect); if (snpNuc == VariantType.INSERTION) { insertions.add(rect); } else { bottom -= h; } p.clearVariantType(snpNuc); } } } accumulator.fill(g2); for (Rectangle2D ins : insertions) { drawInsertion(g2, ins.getX(), ins.getY(), ins.getWidth(), ins.getHeight()); } }
From source file:savant.view.tracks.BAMTrackRenderer.java
private void renderStrandSNPMode(Graphics2D g2, GraphPaneAdapter gp, Resolution r) throws RenderingException { Genome genome = GenomeController.getInstance().getGenome(); if (!genome.isSequenceSet()) { throw new RenderingException("No reference sequence loaded\nSwitch to standard display mode", RenderingException.WARNING_PRIORITY); }//from w ww . j a v a 2s . co m AxisRange axisRange = (AxisRange) instructions.get(DrawingInstruction.AXIS_RANGE); int xMin = axisRange.getXMin(); int xMax = axisRange.getXMax(); ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME); List<Pileup> pileups = new ArrayList<Pileup>(); // make the pileups for (int j = xMin; j <= xMax; j++) { pileups.add(new Pileup(j)); } // Go through the samrecords and edit the pileups for (Record record : data) { SAMRecord samRecord = ((BAMIntervalRecord) record).getSAMRecord(); updatePileupsFromSAMRecord(pileups, samRecord, xMin); } double maxHeight = 0.0; for (Pileup p : pileups) { int current1 = p.getTotalCoverage(Strand.REVERSE); int current2 = p.getTotalCoverage(Strand.FORWARD); if (current1 > maxHeight) { maxHeight = current1; } if (current2 > maxHeight) { maxHeight = current2; } } int yMax = (int) Math.ceil(maxHeight / 0.9); gp.setYRange(new Range(-yMax, yMax)); instructions.put(DrawingInstruction.AXIS_RANGE, new AxisRange(xMin, xMax, -yMax, yMax)); ColourAccumulator accumulator = new ColourAccumulator(cs); List<Rectangle2D> insertions = new ArrayList<Rectangle2D>(); double unitHeight = gp.getUnitHeight(); double unitWidth = gp.getUnitWidth(); double axis = gp.transformYPos(0.0); for (Pileup p : pileups) { if (p.getTotalCoverage(null) > 0) { VariantType snpNuc = null; double bottom = axis; double top = axis; double x = gp.transformXPos(p.getPosition()); VariantType genomeNuc = null; if (genome.isSequenceSet()) { genomeNuc = VariantType.fromChar((char) refSeq[p.getPosition() - xMin]); snpNuc = genomeNuc; } // Only record a shape if we have at least some mismatches. int totalCoverage = p.getTotalCoverage(null); if (totalCoverage > p.getCoverage(genomeNuc, null)) { double h = unitHeight * (totalCoverage - p.getCoverage(VariantType.INSERTION, null)); recordToShapeMap .put(new PileupRecord(p, true), new Rectangle2D.Double(x, bottom - unitHeight * (p.getTotalCoverage(Strand.FORWARD) - p.getCoverage(VariantType.INSERTION, Strand.FORWARD)), unitWidth, h)); } while ((genome.isSequenceSet() && (snpNuc = p.getLargestVariantType(genomeNuc)) != null) || ((snpNuc = p.getLargestVariantType(null)) != null)) { int forwardCoverage = p.getCoverage(snpNuc, Strand.FORWARD); int reverseCoverage = p.getCoverage(snpNuc, Strand.REVERSE); ColourKey col = getSubPileColour(snpNuc, genomeNuc); if (forwardCoverage > 0) { double h = unitHeight * forwardCoverage; Rectangle2D rect = new Rectangle2D.Double(x, bottom - h, unitWidth, h); accumulator.addShape(col == ColourKey.REVERSE_STRAND ? ColourKey.FORWARD_STRAND : col, rect); if (snpNuc == VariantType.INSERTION) { insertions.add(rect); } else { bottom -= h; } } if (reverseCoverage > 0) { double h = unitHeight * reverseCoverage; Rectangle2D rect = new Rectangle2D.Double(x, top, unitWidth, h); accumulator.addShape(col, rect); if (snpNuc == VariantType.INSERTION) { insertions.add(rect); } else { top += h; } } p.clearVariantType(snpNuc); } } } accumulator.fill(g2); for (Rectangle2D ins : insertions) { drawInsertion(g2, ins.getX(), ins.getY(), ins.getWidth(), ins.getHeight()); } g2.setColor(Color.BLACK); g2.draw(new Line2D.Double(0, axis, gp.getWidth(), axis)); }