/** * Reset the base coordinates on Java2D screen. */ public void reset() { initBaseCoordsProjection(); }
/** * Reset projection object when the PlotCanvas size changed. */ void resetProjection() { projection.reset(); }
/** * Fill the specified rectangle. */ public void fillRect(double[] topLeft, double[] rightBottom) { if (!(projection instanceof Projection2D)) { throw new UnsupportedOperationException("Only 2D graphics supports drawing rectangles."); } int[] sc = projection.screenProjection(topLeft); int[] sc2 = projection.screenProjection(rightBottom); g2d.fillRect(sc[0], sc[1], sc2[0] - sc[0], sc2[1] - sc[1]); }
/** * Draw the outline of the specified rectangle. The logical coordinates * are proportional to the base coordinates. */ public void drawRectBaseRatio(double[] topLeft, double[] rightBottom) { if (!(projection instanceof Projection2D)) { throw new UnsupportedOperationException("Only 2D graphics supports drawing rectangles."); } int[] sc = projection.screenProjectionBaseRatio(topLeft); int[] sc2 = projection.screenProjectionBaseRatio(rightBottom); g2d.drawRect(sc[0], sc[1], sc2[0] - sc[0], sc2[1] - sc[1]); }
/** * Initialize base coordinates on Java2D screen. */ private void initBaseCoordsProjection() { baseScreenCoords = new int[canvas.base.baseCoords.length][2]; for (int i = 0; i < canvas.base.dimension + 1; i++) { double[] ratio = baseCoordsScreenProjectionRatio(canvas.base.baseCoords[i]); baseScreenCoords[i][0] = (int) (canvas.getWidth() * (canvas.margin + (1 - 2 * canvas.margin) * ratio[0])); baseScreenCoords[i][1] = (int) (canvas.getHeight() - canvas.getHeight() * (canvas.margin + (1 - 2 * canvas.margin) * ratio[1])); } }
/** * Fill the specified rectangle. The logical coordinates are proportional * to the base coordinates. */ public void fillRectBaseRatio(double[] topLeft, double[] rightBottom) { if (!(projection instanceof Projection2D)) { throw new UnsupportedOperationException("Only 2D graphics supports drawing rectangles."); } int[] sc = projection.screenProjectionBaseRatio(topLeft); int[] sc2 = projection.screenProjectionBaseRatio(rightBottom); g2d.fillRect(sc[0], sc[1], sc2[0] - sc[0], sc2[1] - sc[1]); }
@Override public void actionPerformed(ActionEvent e) { if (margin < 0.3) { margin += 0.05; graphics.projection.reset(); repaint(); } if (margin >= 0.3) { setEnabled(false); } if (!enlargePlotAreaAction.isEnabled()) { enlargePlotAreaAction.setEnabled(true); } } }
/** * Draw the outline of the specified rectangle. */ public void drawRect(double[] topLeft, double[] rightBottom) { if (!(projection instanceof Projection2D)) { throw new UnsupportedOperationException("Only 2D graphics supports drawing rectangles."); } int[] sc = projection.screenProjection(topLeft); int[] sc2 = projection.screenProjection(rightBottom); g2d.drawRect(sc[0], sc[1], sc2[0] - sc[0], sc2[1] - sc[1]); }
/** * Draw poly line. The logical coordinates are proportional to the base * coordinates. */ public void drawLineBaseRatio(double[]... coord) { int[][] sc = new int[coord.length][]; for (int i = 0; i < sc.length; i++) { sc[i] = projection.screenProjectionBaseRatio(coord[i]); } drawLine(sc); }
/** * Constructor. */ public Projection(PlotCanvas canvas) { this.canvas = canvas; initBaseCoordsProjection(); }
@Override public void actionPerformed(ActionEvent e) { if (margin > 0.05) { margin -= 0.05; graphics.projection.reset(); repaint(); } if (margin <= 0.05) { setEnabled(false); } if (!shrinkPlotAreaAction.isEnabled()) { shrinkPlotAreaAction.setEnabled(true); } } }
/** * Draw poly line. The coordinates are in logical coordinates. */ public void drawLine(double[]... coord) { int[][] sc = new int[coord.length][]; for (int i = 0; i < sc.length; i++) { sc[i] = projection.screenProjection(coord[i]); } drawLine(sc); }
/** * Draw a string with given reference point and rotation angle. (0.5, 0.5) * is center, (0, 0) is lower left, (1, 0) is upper left, etc. * The angle of rotation is in radians. The logical are proportional to * the base coordinates. */ public void drawTextBaseRatio(String label, double horizontalReference, double verticalReference, double rotation, double[] coord) { int[] sc = projection.screenProjectionBaseRatio(coord); int x = sc[0]; int y = sc[1]; AffineTransform transform = g2d.getTransform(); // Corner offset adjustment : Text Offset is used Here FontRenderContext frc = g2d.getFontRenderContext(); Font font = g2d.getFont(); double w = font.getStringBounds(label, frc).getWidth(); double h = font.getSize2D(); if (rotation != 0) { g2d.rotate(rotation, x, y); } x -= (int) (w * horizontalReference); y += (int) (h * verticalReference); g2d.drawString(label, x, y); g2d.setTransform(transform); }
@Override public void componentResized(ComponentEvent e) { if (graphics != null) { base.initBaseCoord(); graphics.projection.reset(); baseGrid.setBase(base); } repaint(); }
/** * Draw polygon. The coordinates are in logical coordinates. */ public void drawPolygon(double[]... coord) { int[][] c = new int[coord.length][2]; for (int i = 0; i < coord.length; i++) { c[i] = projection.screenProjection(coord[i]); } int[] x = new int[c.length]; for (int i = 0; i < c.length; i++) { x[i] = c[i][0]; } int[] y = new int[c.length]; for (int i = 0; i < c.length; i++) { y[i] = c[i][1]; } g2d.drawPolygon(x, y, c.length); }
/** * Resets the plot. */ public void reset() { base.reset(); graphics.projection.reset(); baseGrid.setBase(base); if (graphics.projection instanceof Projection3D) { ((Projection3D) graphics.projection).setDefaultView(); } canvas.repaint(); }
/** * Fill polygon. The coordinates are in logical coordinates. */ public void fillPolygon(double[]... coord) { int[][] c = new int[coord.length][2]; for (int i = 0; i < coord.length; i++) { c[i] = projection.screenProjection(coord[i]); } int[] x = new int[c.length]; for (int i = 0; i < c.length; i++) { x[i] = c[i][0]; } int[] y = new int[c.length]; for (int i = 0; i < c.length; i++) { y[i] = c[i][1]; } g2d.fillPolygon(x, y, c.length); }
@Override public void mouseWheelMoved(MouseWheelEvent e) { if (e.getWheelRotation() == 0) { return; } for (int i = 0; i < base.dimension; i++) { int s = baseGrid.getAxis(i).getLinearSlices(); double r = e.getWheelRotation() > 0 ? 1.0 / s : -1.0 / s; if (r > -0.5) { double d = (base.upperBound[i] - base.lowerBound[i]) * r; base.lowerBound[i] -= d; base.upperBound[i] += d; } } for (int i = 0; i < base.dimension; i++) { base.setPrecisionUnit(i); } base.initBaseCoord(); graphics.projection.reset(); baseGrid.setBase(base); repaint(); e.consume(); }
/** * Fill polygon. The coordinates are in logical coordinates. This also supports * basic alpha compositing rules for combining source and destination * colors to achieve blending and transparency effects with graphics and images. * * @param alpha the constant alpha to be multiplied with the alpha of the * source. alpha must be a floating point number in the inclusive range * [0.0, 1.0]. */ public void fillPolygon(float alpha, double[]... coord) { int[][] c = new int[coord.length][2]; for (int i = 0; i < coord.length; i++) { c[i] = projection.screenProjection(coord[i]); } int[] x = new int[c.length]; for (int i = 0; i < c.length; i++) { x[i] = c[i][0]; } int[] y = new int[c.length]; for (int i = 0; i < c.length; i++) { y[i] = c[i][1]; } Composite cs = g2d.getComposite(); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2d.fillPolygon(x, y, c.length); g2d.setComposite(cs); }
graphics.projection.reset(); baseGrid.setBase(base);