List of usage examples for java.awt Graphics2D setTransform
public abstract void setTransform(AffineTransform Tx);
From source file:SWT2D.java
private void run() { // Create top level shell final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Java 2D Example"); // GridLayout for canvas and button shell.setLayout(new GridLayout()); // Create container for AWT canvas final Composite canvasComp = new Composite(shell, SWT.EMBEDDED); // Set preferred size GridData data = new GridData(); data.widthHint = 600;/*from ww w. j a va2 s . c o m*/ data.heightHint = 500; canvasComp.setLayoutData(data); // Create AWT Frame for Canvas java.awt.Frame canvasFrame = SWT_AWT.new_Frame(canvasComp); // Create Canvas and add it to the Frame final java.awt.Canvas canvas = new java.awt.Canvas(); canvasFrame.add(canvas); // Get graphical context and cast to Java2D final java.awt.Graphics2D g2d = (java.awt.Graphics2D) canvas.getGraphics(); // Enable antialiasing g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Remember initial transform final java.awt.geom.AffineTransform origTransform = g2d.getTransform(); // Create Clear button and position it Button clearButton = new Button(shell, SWT.PUSH); clearButton.setText("Clear"); data = new GridData(); data.horizontalAlignment = GridData.CENTER; clearButton.setLayoutData(data); // Event processing for Clear button clearButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // Delete word list and redraw canvas wordList.clear(); canvasComp.redraw(); } }); // Process canvas mouse clicks canvas.addMouseListener(new java.awt.event.MouseListener() { public void mouseClicked(java.awt.event.MouseEvent e) { } public void mouseEntered(java.awt.event.MouseEvent e) { } public void mouseExited(java.awt.event.MouseEvent e) { } public void mousePressed(java.awt.event.MouseEvent e) { // Manage pop-up editor display.syncExec(new Runnable() { public void run() { if (eShell == null) { // Create new Shell: non-modal! eShell = new Shell(shell, SWT.NO_TRIM | SWT.MODELESS); eShell.setLayout(new FillLayout()); // Text input field eText = new Text(eShell, SWT.BORDER); eText.setText("Text rotation in the SWT?"); eShell.pack(); // Set position (Display coordinates) java.awt.Rectangle bounds = canvas.getBounds(); org.eclipse.swt.graphics.Point pos = canvasComp.toDisplay(bounds.width / 2, bounds.height / 2); Point size = eShell.getSize(); eShell.setBounds(pos.x, pos.y, size.x, size.y); // Open Shell eShell.open(); } else if (!eShell.isVisible()) { // Editor versteckt, sichtbar machen eShell.setVisible(true); } else { // Editor is visible - get text String t = eText.getText(); // set editor invisible eShell.setVisible(false); // Add text to list and redraw canvas wordList.add(t); canvasComp.redraw(); } } }); } public void mouseReleased(java.awt.event.MouseEvent e) { } }); // Redraw the canvas canvasComp.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { // Pass the redraw task to AWT event queue java.awt.EventQueue.invokeLater(new Runnable() { public void run() { // Compute canvas center java.awt.Rectangle bounds = canvas.getBounds(); int originX = bounds.width / 2; int originY = bounds.height / 2; // Reset canvas g2d.setTransform(origTransform); g2d.setColor(java.awt.Color.WHITE); g2d.fillRect(0, 0, bounds.width, bounds.height); // Set font g2d.setFont(new java.awt.Font("Myriad", java.awt.Font.PLAIN, 32)); double angle = 0d; // Prepare star shape double increment = Math.toRadians(30); Iterator iter = wordList.iterator(); while (iter.hasNext()) { // Determine text colors in RGB color cycle float red = (float) (0.5 + 0.5 * Math.sin(angle)); float green = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(120))); float blue = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(240))); g2d.setColor(new java.awt.Color(red, green, blue)); // Redraw text String text = (String) iter.next(); g2d.drawString(text, originX + 50, originY); // Rotate for next text output g2d.rotate(increment, originX, originY); angle += increment; } } }); } }); // Finish shell and open it shell.pack(); shell.open(); // SWT event processing while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Paints the component by drawing the chart to fill the entire component, but allowing for the * insets (which will be non-zero if a border has been set for this component). To increase * performance (at the expense of memory), an off-screen buffer image can be used. * //from w w w . j a va 2s. com * @param g * the graphics device for drawing on. */ @Override public void paintComponent(Graphics g) { if (this.chart == null) { return; } Graphics2D g2 = (Graphics2D) g.create(); // first determine the size of the chart rendering area... Dimension size = getSize(); Insets insets = getInsets(); Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); this.scaleX = 1.0; this.scaleY = 1.0; if (drawWidth < this.minimumDrawWidth) { this.scaleX = drawWidth / this.minimumDrawWidth; drawWidth = this.minimumDrawWidth; scale = true; } else if (drawWidth > this.maximumDrawWidth) { this.scaleX = drawWidth / this.maximumDrawWidth; drawWidth = this.maximumDrawWidth; scale = true; } if (drawHeight < this.minimumDrawHeight) { this.scaleY = drawHeight / this.minimumDrawHeight; drawHeight = this.minimumDrawHeight; scale = true; } else if (drawHeight > this.maximumDrawHeight) { this.scaleY = drawHeight / this.maximumDrawHeight; drawHeight = this.maximumDrawHeight; scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // redrawing the chart every time... AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); g2.transform(st); } this.chart.draw(g2, chartArea, this.anchor, this.info); g2.setTransform(saved); Iterator<Overlay> iterator = this.overlays.iterator(); while (iterator.hasNext()) { Overlay overlay = iterator.next(); overlay.paintOverlay(g2, this); } // redraw the zoom rectangle (if present) - if useBuffer is false, // we use XOR so we can XOR the rectangle away again without redrawing // the chart drawSelectionRectangle(g2); g2.dispose(); this.anchor = null; this.verticalTraceLine = null; this.horizontalTraceLine = null; }
From source file:ucar.unidata.idv.flythrough.Flythrough.java
/** * _more_// ww w. jav a 2 s . com * * @param g _more_ * @param comp _more_ */ public void paintDashboardAfter(Graphics g, JComponent comp) { Graphics2D g2 = (Graphics2D) g; AffineTransform oldTransform = g2.getTransform(); Rectangle b = dashboardLbl.getBounds(); int w = dashboardImage.getWidth(null); int h = dashboardImage.getHeight(null); Point ul = new Point(b.width / 2 - w / 2, b.height - h); int ptsIdx = 0; try { pipPanel.setPreferredSize(new Dimension(dialPts[ptsIdx][2], dialPts[ptsIdx][3])); pipFrame.setSize(dialPts[ptsIdx][2], dialPts[ptsIdx][3]); pipPanel.doLayout(); pipPanel.validate(); pipFrame.pack(); pipPanel.resetDrawBounds(); pipPanel.redraw(); } catch (Exception ignore) { } JLabel locLbl = null; if (lastLocation != null) { try { locLbl = new JLabel("<html><table width=100%><tr><td align=right> Lat:</td></td>" + getIdv().getDisplayConventions().formatLatLon(getLat(lastLocation)) + "</td></tr>" + "<tr><td align=right> Lon:</td></td>" + getIdv().getDisplayConventions().formatLatLon(getLon(lastLocation)) + "</td></tr>" + "<tr><td align=right> Alt:</td></td>" + getIdv().getDisplayConventions().formatDistance(getAlt(lastLocation)) + "</table>"); } catch (Exception ignore) { } } if (locLbl == null) { locLbl = new JLabel( "<html><table width=100%><tr><td align=right> Lat:</td></td>N/A </td></tr><tr><td align=right> Lon:</td></td>N/A </td></tr><tr><td align=right> Alt:</td></td>N/A </table>"); } locLbl.setOpaque(true); locLbl.setBackground(Color.white); DefaultValueDataset headingDataset = new DefaultValueDataset(new Double(currentHeading)); CompassPlot plot = new CompassPlot(headingDataset); plot.setSeriesNeedle(0); plot.setSeriesPaint(0, Color.red); plot.setSeriesOutlinePaint(0, Color.red); JFreeChart chart = new JFreeChart("", plot); ChartPanel compassPanel = new ChartPanel(chart); plot.setBackgroundPaint(new Color(255, 255, 255, 0)); plot.setBackgroundImageAlpha(0.0f); chart.setBackgroundPaint(new Color(255, 255, 255, 0)); compassPanel.setBackground(new Color(255, 255, 255, 0)); compassPanel.setPreferredSize(dialDimension); // compassPanel.setSize(new Dimension(100,100)); g2.setTransform(oldTransform); pipRect = drawDial(g2, pipPanel, ptsIdx++, ul); JFrame dummyFrame = new JFrame(""); dummyFrame.setContentPane(compassPanel); dummyFrame.pack(); g2.setTransform(oldTransform); drawDial(g2, compassPanel, ptsIdx++, ul); g2.setTransform(oldTransform); dummyFrame.setContentPane(locLbl); dummyFrame.pack(); drawDial(g2, locLbl, ptsIdx++, ul); if (showReadout) { for (JComponent dial : dials) { dummyFrame.setContentPane(dial); dummyFrame.pack(); g2.setTransform(oldTransform); drawDial(g2, dial, ptsIdx++, ul); } } g2.setTransform(oldTransform); }
From source file:org.forester.archaeopteryx.TreePanel.java
final private void paintNodeDataUnrootedCirc(final Graphics2D g, final PhylogenyNode node, final boolean to_pdf, final boolean to_graphics_file, final boolean radial_labels, final double ur_angle, final boolean is_in_found_nodes) { if (isNodeDataInvisibleUnrootedCirc(node) && !to_graphics_file && !to_pdf) { return;//w ww. j a v a 2s.c o m } if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) { g.setColor(Color.BLACK); } else if (is_in_found_nodes) { g.setColor(getTreeColorSet().getFoundColor()); } else if (getControlPanel().isColorAccordingToTaxonomy()) { g.setColor(getTaxonomyBasedColor(node)); } else { g.setColor(getTreeColorSet().getSequenceColor()); } _sb.setLength(0); _sb.append(" "); if (node.getNodeData().isHasTaxonomy() && (getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyNames())) { final Taxonomy taxonomy = node.getNodeData().getTaxonomy(); if (_control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty(taxonomy.getTaxonomyCode())) { _sb.append(taxonomy.getTaxonomyCode()); _sb.append(" "); } if (_control_panel.isShowTaxonomyNames()) { if (!ForesterUtil.isEmpty(taxonomy.getScientificName()) && !ForesterUtil.isEmpty(taxonomy.getCommonName())) { _sb.append(taxonomy.getScientificName()); _sb.append(" ("); _sb.append(taxonomy.getCommonName()); _sb.append(") "); } else if (!ForesterUtil.isEmpty(taxonomy.getScientificName())) { _sb.append(taxonomy.getScientificName()); _sb.append(" "); } else if (!ForesterUtil.isEmpty(taxonomy.getCommonName())) { _sb.append(taxonomy.getCommonName()); _sb.append(" "); } } } if (node.isCollapse() && ((!node.isRoot() && !node.getParent().isCollapse()) || node.isRoot())) { _sb.append(" ["); _sb.append(node.getAllExternalDescendants().size()); _sb.append("]"); } if (getControlPanel().isShowNodeNames() && (node.getNodeName().length() > 0)) { if (_sb.length() > 0) { _sb.append(" "); } _sb.append(node.getNodeName()); } if (node.getNodeData().isHasSequence()) { if (getControlPanel().isShowSequenceAcc() && (node.getNodeData().getSequence().getAccession() != null)) { if (_sb.length() > 0) { _sb.append(" "); } if (!ForesterUtil.isEmpty(node.getNodeData().getSequence().getAccession().getSource())) { _sb.append(node.getNodeData().getSequence().getAccession().getSource()); _sb.append(":"); } _sb.append(node.getNodeData().getSequence().getAccession().getValue()); } if (getControlPanel().isShowGeneNames() && (node.getNodeData().getSequence().getName().length() > 0)) { // if ( _sb.length() > 0 ) { // _sb.append( " " ); // } // _sb.append( node.getNodeData().getSequence().getName() ); PhylogenyNode parent = node.getParent(); double x1 = parent.getXcoord(); double y1 = parent.getYcoord(); double x2 = node.getXcoord(); double y2 = node.getYcoord(); double above_the_line = 1.0; if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) { double center_of_branch_x = Math.abs(x1 + x2) / 2.0; double center_of_branch_y = Math.abs(y1 + y2) / 2.0; TreePanel.drawString(node.getNodeData().getSequence().getName(), center_of_branch_x, center_of_branch_y - above_the_line, g); } } } g.setFont(getTreeFontSet().getLargeFont()); if (is_in_found_nodes) { g.setFont(getTreeFontSet().getLargeFont().deriveFont(Font.BOLD)); } if (_sb.length() > 1) { final String sb_str = _sb.toString(); double m = 0; if (_graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR) { m = _urt_nodeid_angle_map.get(node.getNodeId()) % TWO_PI; } else { m = (float) (ur_angle % TWO_PI); } _at = g.getTransform(); boolean need_to_reset = false; final float x_coord = node.getXcoord(); final float y_coord = node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / 3.0f); if (radial_labels) { need_to_reset = true; boolean left = false; if ((m > HALF_PI) && (m < ONEHALF_PI)) { m -= PI; left = true; } g.rotate(m, x_coord, node.getYcoord()); if (left) { g.translate(-(getTreeFontSet()._fm_large.getStringBounds(sb_str, g).getWidth()), 0); } } else { if ((m > HALF_PI) && (m < ONEHALF_PI)) { need_to_reset = true; g.translate(-getTreeFontSet()._fm_large.getStringBounds(sb_str, g).getWidth(), 0); } } TreePanel.drawString(sb_str, x_coord, y_coord, g); if (need_to_reset) { g.setTransform(_at); } } }
From source file:org.forester.archaeopteryx.TreePanel.java
final void paintPhylogeny(final Graphics2D g, final boolean to_pdf, final boolean to_graphics_file, final int graphics_file_width, final int graphics_file_height, final int graphics_file_x, final int graphics_file_y) { /* GUILHEM_BEG */ _query_sequence = _control_panel.getSelectedQuerySequence(); /* GUILHEM_END */ // Color the background if (!to_pdf) { final Rectangle r = getVisibleRect(); if (!getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite()) { g.setColor(getTreeColorSet().getBackgroundColor()); if (!to_graphics_file) { g.fill(r);/* w w w . j a va 2 s. c o m*/ } else { if (getOptions().isPrintBlackAndWhite()) { g.setColor(Color.WHITE); } g.fillRect(graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height); } } else { if (!to_graphics_file) { g.setPaint(new GradientPaint(r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y + r.height, getTreeColorSet().getBackgroundColorGradientBottom())); g.fill(r); } else { g.setPaint(new GradientPaint(graphics_file_x, graphics_file_y, getTreeColorSet().getBackgroundColor(), graphics_file_x, graphics_file_y + graphics_file_height, getTreeColorSet().getBackgroundColorGradientBottom())); g.fillRect(graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height); } } g.setStroke(new BasicStroke(1)); } else { g.setStroke(new BasicStroke(getOptions().getPrintLineWidth())); } if ((getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED) && (getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR)) { _external_node_index = 0; // Position starting X of tree if (!_phylogeny.isRooted()) { _phylogeny.getRoot().setXcoord(TreePanel.MOVE); } else if ((_phylogeny.getRoot().getDistanceToParent() > 0.0) && getControlPanel().isDrawPhylogram()) { _phylogeny.getRoot().setXcoord((float) (TreePanel.MOVE + (_phylogeny.getRoot().getDistanceToParent() * getXcorrectionFactor()))); } else { _phylogeny.getRoot().setXcoord(TreePanel.MOVE + getXdistance()); } // Position starting Y of tree _phylogeny.getRoot().setYcoord( (getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes()) + (TreePanel.MOVE / 2.0f)); final int dynamic_hiding_factor = (int) (getTreeFontSet()._fm_large.getHeight() / (1.5 * getYdistance())); if (getControlPanel().isDynamicallyHideData()) { if (dynamic_hiding_factor > 1) { getControlPanel().setDynamicHidingIsOn(true); } else { getControlPanel().setDynamicHidingIsOn(false); } } final PhylogenyNodeIterator it; for (it = _phylogeny.iteratorPreorder(); it.hasNext();) { paintNodeRectangular(g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData() && (dynamic_hiding_factor > 1), dynamic_hiding_factor, to_graphics_file); } if (getOptions().isShowScale()) { if (!(to_graphics_file || to_pdf)) { paintScale(g, getVisibleRect().x, getVisibleRect().y + getVisibleRect().height, to_pdf, to_graphics_file); } else { paintScale(g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file); } } if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) { paintPhylogenyLite(g); } } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) { if (getControlPanel().getDynamicallyHideData() != null) { getControlPanel().setDynamicHidingIsOn(false); } final double angle = getStartingAngle(); final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL; _dynamic_hiding_factor = 0; if (getControlPanel().isDynamicallyHideData()) { _dynamic_hiding_factor = (int) ((getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny().getNumberOfExternalNodes()) / (TWO_PI * 10)); } if (getControlPanel().getDynamicallyHideData() != null) { if (_dynamic_hiding_factor > 1) { getControlPanel().setDynamicHidingIsOn(true); } else { getControlPanel().setDynamicHidingIsOn(false); } } paintUnrooted(_phylogeny.getRoot(), angle, (float) (angle + 2 * Math.PI), radial_labels, g, to_pdf, to_graphics_file); if (getOptions().isShowScale()) { if (!(to_graphics_file || to_pdf)) { paintScale(g, getVisibleRect().x, getVisibleRect().y + getVisibleRect().height, to_pdf, to_graphics_file); } else { paintScale(g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file); } } if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) { g.setColor(getTreeColorSet().getOvColor()); paintUnrootedLite(_phylogeny.getRoot(), angle, angle + 2 * Math.PI, g, (getUrtFactorOv() / (getVisibleRect().width / getOvMaxWidth()))); paintOvRectangle(g); } } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR) { final int radius = (int) ((Math.min(getPreferredSize().getWidth(), getPreferredSize().getHeight()) / 2) - (MOVE + getLongestExtNodeInfo())); final int d = radius + MOVE + getLongestExtNodeInfo(); _dynamic_hiding_factor = 0; if (getControlPanel().isDynamicallyHideData() && (radius > 0)) { _dynamic_hiding_factor = (int) ((getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny().getNumberOfExternalNodes()) / (TWO_PI * radius)); } if (getControlPanel().getDynamicallyHideData() != null) { if (_dynamic_hiding_factor > 1) { getControlPanel().setDynamicHidingIsOn(true); } else { getControlPanel().setDynamicHidingIsOn(false); } } paintCircular(_phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file); if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) { final int radius_ov = (int) (getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2 : getOvMaxWidth() / 2); double x_scale = 1.0; double y_scale = 1.0; int x_pos = getVisibleRect().x + getOvXPosition(); int y_pos = getVisibleRect().y + getOvYPosition(); if (getWidth() > getHeight()) { x_scale = (double) getHeight() / getWidth(); x_pos = ForesterUtil.roundToInt(x_pos / x_scale); } else { y_scale = (double) getWidth() / getHeight(); y_pos = ForesterUtil.roundToInt(y_pos / y_scale); } _at = g.getTransform(); g.scale(x_scale, y_scale); paintCircularLite(_phylogeny, getStartingAngle(), x_pos + radius_ov, y_pos + radius_ov, (int) (radius_ov - (getLongestExtNodeInfo() / (getVisibleRect().width / getOvRectangle().getWidth()))), g); g.setTransform(_at); paintOvRectangle(g); } } }
From source file:org.esa.nest.dat.layers.maptools.components.CompassComponent.java
public void render(final Graphics2D graphics, final ScreenPixelConverter screenPixel) { if (Double.isNaN(angle)) return;//www .j a va 2 s. com final AffineTransform transformSave = graphics.getTransform(); try { final AffineTransform transform = screenPixel.getImageTransform(transformSave); final double scale = (marginPct * 2 * rasterWidth) / (double) image.getWidth(); transform.translate(point1.x, point1.y); transform.scale(scale, scale); transform.rotate(angle); graphics.drawRenderedImage(image, transform); } finally { graphics.setTransform(transformSave); } }
From source file:org.evors.rs.ui.sandpit.TrialViewer.java
@Override public void draw() { if (buffer == null) { return;/*from ww w .j a va 2s . c om*/ } Graphics2D g2 = (Graphics2D) buffer.getDrawGraphics(); camera.setWindowSize(new Vector2D(this.getWidth(), this.getHeight())); g2.setColor(Color.WHITE); g2.fillRect(0, 0, getWidth(), getHeight()); AffineTransform prevTrans = g2.getTransform(); g2.setTransform(camera.getTransform()); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); grid.draw(g2); if (world != null) { SandpitRenderer.drawWorld(g2, world); } if (path != null) { path.draw(g2); } if (robot != null) { SandpitRenderer.drawRobot(g2, robot); } g2.setTransform(prevTrans); drawText(g2, String.format("Time: %.2f\nRobot position: {%.2f,%.2f}\nRobot heading: %.2f\nInputs:%s\nNeurons:%s", time, robot.getPosition().getX(), robot.getPosition().getY(), robot.getHeading(), Arrays.toString(robot.getInput()), Arrays.toString(((CTRNN) controller.getController()).getNeurons()))); }
From source file:org.evors.rs.ui.sandpit.WorldViewer.java
@Override public void draw() { Graphics2D g2 = (Graphics2D) getGraphics(); camera.setWindowSize(new Vector2D(this.getWidth(), this.getHeight())); g2.setColor(Color.WHITE);//ww w . java 2 s .c o m g2.fillRect(0, 0, getWidth(), getHeight()); AffineTransform prevTrans = g2.getTransform(); g2.setTransform(camera.getTransform()); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); grid.draw(g2); if (world != null) { SandpitRenderer.drawWorld(g2, world); } g2.setTransform(prevTrans); }
From source file:org.jcurl.core.swing.RockLocationDisplayBase.java
public void paintComponent(final Graphics g) { super.paintComponent(g); if (log.isDebugEnabled()) log.debug("[" + this.getX() + ", " + this.getY() + ", " + this.getWidth() + ", " + this.getHeight() + "]"); final Graphics2D g2 = (Graphics2D) g; final AffineTransform dc_mat = g2.getTransform(); g2.setRenderingHints(hints);/*w ww . ja v a 2 s . c om*/ final int w = this.getWidth(); final int h = this.getHeight(); // paint WC stuff (ice and rocks) if (zoom.hasChanged() || oldWid != w || oldHei != h) { // either the wc viewport, fixpoint or dc viewport has changed: // re-compute the transformation wc_mat.setToIdentity(); zoom.computeWctoDcTrafo(this.getBounds(), orient, true, wc_mat); oldWid = w; oldHei = h; // re-build the background image img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); final Graphics2D gi = (Graphics2D) img.getGraphics(); gi.setRenderingHints(hints); paintIceDC(gi); } g2.drawImage(img, null, 0, 0); paintRocksDC(g2); g2.setTransform(dc_mat); }
From source file:org.jcurl.core.swing.RockLocationDisplayBase.java
/** * Draw one rock at it's wc position. Builds the coordinate transform and * calls {@link #paintRockRC(Graphics2D, boolean, int)}. * //from ww w.ja v a 2s . co m * @param g * @param rock * @param isDark * @param idx * @see RockPainter#paintRockRC(Graphics2D, boolean, int) */ protected void paintRockWC(final Graphics2D g, final Rock rock, final boolean isDark, final int idx) { final AffineTransform t = g.getTransform(); g.translate(JCurlDisplay.SCALE * rock.getX(), JCurlDisplay.SCALE * rock.getY()); g.rotate(Math.PI + rock.getZ()); // make the right-handed coordinate system left handed again (for // un-flipped text display) g.scale(-1, 1); paintRockRC(g, isDark, idx); g.setTransform(t); }