/** * Draws as much as possible of a given string into a 2d square region in a graphical space. * * @param g component onto which to draw * @param f font to use in drawing the string * @param s string to be drawn * @param xPos * @param yPos * @param width * @param height */ public static void drawStringMultiline( Graphics2D g, Font f, String s, double xPos, double yPos, double width, double height) { FontMetrics fm = g.getFontMetrics(f); int w = fm.stringWidth(s); int h = fm.getAscent(); // g.setColor(Color.LIGHT_GRAY); g.setColor(Color.BLACK); g.setFont(f); Scanner lineSplitter = new Scanner(s); // draw as much as can fit in each item // read all content from scanner, storing in string lists (where each string == 1 line), each // string should be as long as possible without overflowing the space int maxRows = (int) height / h; List<String> textRows = new ArrayList<>(); while (lineSplitter.hasNextLine() && textRows.size() < maxRows) { String line = lineSplitter.nextLine(); // if line is blank, insert to maintain paragraph seps if (line.trim().equals("")) { textRows.add(""); } // else, pass to inner loop StringBuilder currentBuilder = new StringBuilder(); int currentStrWidth = 0; Scanner splitter = new Scanner(line); while (splitter.hasNext() && textRows.size() < maxRows) { String token = splitter.next() + " "; // TODO incorporate weight detection, formatting for token? currentStrWidth += fm.stringWidth(token); if (currentStrWidth >= width) { // if string length >= glyph width, build row textRows.add(currentBuilder.toString()); currentBuilder = new StringBuilder(); currentBuilder.append(token); currentStrWidth = fm.stringWidth(token); } else { // if not yet at end of row, append to builder currentBuilder.append(token); } } // if we've still space and still have things to write, add them here if (textRows.size() < maxRows) { textRows.add(currentBuilder.toString()); currentBuilder = new StringBuilder(); currentStrWidth = 0; } } // write each line to object for (int t = 0; t < textRows.size(); t++) { String line = textRows.get(t); if (fm.stringWidth(line) <= width) { // ensure that string doesn't overflow the box // g.drawString(line, (float) (xPos-(width/2.)), (float) (yPos-(height/2.) + // h * (t+1))); g.drawString(line, (float) xPos, (float) (yPos + h * (t + 1))); } } }
public void paint(Graphics g) { gRef = (Graphics2D) g; // change size of font gRef.setFont(gRef.getFont().deriveFont(9.0f)); fmRef = g.getFontMetrics(); // Clear background if (Preferences.monochrome) { gRef.setColor(Preferences.whiteColor); } else { gRef.setColor(Preferences.backgroundColor); } gRef.fillRect(0, 0, getWidth(), getHeight()); // set colour to correct drawing colour if (Preferences.monochrome) { gRef.setColor(Preferences.blackColor); } else { gRef.setColor(Preferences.penColor); } gRef.translate(0, margin); // Call c code to draw tree gRef.scale(scale, scale); nativeDrawTree(); }
public void paint(java.awt.Graphics g) { if (element != null) { Rectangle bounds = element.jGetBounds(); Graphics2D g2 = (Graphics2D) g; g2.setFont(font); int mitteX = bounds.x + (bounds.width) / 2; int mitteY = bounds.y + (bounds.height) / 2; int distanceY = 10; g2.setColor(new Color(204, 204, 255)); g2.fillRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY); g2.setColor(Color.BLACK); g2.drawRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY); String caption = "dec(" + variable.getValue() + ")"; FontMetrics fm = g2.getFontMetrics(); Rectangle2D r = fm.getStringBounds(caption, g2); g2.setColor(Color.BLACK); g.drawString( caption, mitteX - (int) (r.getWidth() / 2), (int) (mitteY + fm.getHeight() / 2) - 3); } super.paint(g); }
/** [Internal] */ private void paintBackground(Graphics2D g2, Color theBackground) { Color color1 = g2.getColor(); if (theBackground == null) theBackground = Color.white; g2.setColor(theBackground); g2.fillRect(0, 0, 30000, 30000); g2.setColor(color1); }
public void drawCluster(Cluster cluster) { int index = clusters.indexOf(cluster); if (index != -1) { cluster.y = maxY; cluster.x = minX + index * factor; if (cluster.size() > 1) g.setColor(Color.RED); else g.setColor(Color.BLACK); g.drawRect(cluster.x - 1, cluster.y - cluster.size(), 2, 1 + cluster.size()); } else { Cluster left = cluster.getLeft(); Cluster right = cluster.getRight(); drawCluster(left); drawCluster(right); int yBar = minY + (int) ((maxY - minY) * (cluster.getSimilarity() / threshold)); g.setColor(Color.DARK_GRAY); if (left.y > yBar) { g.drawLine(left.x, left.y - 1, left.x, yBar); writeMap(left, yBar); } if (right.y > yBar) { g.drawLine(right.x, right.y - 1, right.x, yBar); writeMap(right, yBar); } g.setColor(Color.BLACK); g.drawLine(left.x, yBar, right.x, yBar); cluster.x = (right.x + left.x) / 2; cluster.y = yBar; } }
/** Erase the whole canvas. (Does not repaint.) */ private void erase() { Color original = graphic.getColor(); graphic.setColor(backgroundColor); Dimension size = canvas.getSize(); graphic.fill(new Rectangle(0, 0, size.width, size.height)); graphic.setColor(original); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D gfx = (Graphics2D) g; gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Clear screen gfx.setColor(Constants.BACKGROUND_COLOR); gfx.fillRect(0, 0, getWidth(), getHeight()); // Render next frame grid.draw(gfx); // Trace path line if (tracing) { gfx.setColor(Constants.PATH_COLOR); gfx.setStroke(new BasicStroke(2)); for (int i = 1; i < pathLine.size(); i++) { Coordinate p = pathLine.get(i - 1); Coordinate n = pathLine.get(i); gfx.drawLine( (Constants.TILESIZE + Constants.MARGIN) * p.x + (Constants.TILESIZE / 2) + Constants.MARGIN, (Constants.TILESIZE + Constants.MARGIN) * p.y + (Constants.TILESIZE / 2) + Constants.MARGIN, (Constants.TILESIZE + Constants.MARGIN) * n.x + (Constants.TILESIZE / 2) + Constants.MARGIN, (Constants.TILESIZE + Constants.MARGIN) * n.y + (Constants.TILESIZE / 2) + Constants.MARGIN); } } }
/** PaintComponent to draw everything. */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); setBackground(Color.WHITE); // If using images, use cool dragon background if (useImages) g.drawImage(background, 0, 0, 310, 300, null); // Use light gray to not overpower the background image g.setColor(Color.LIGHT_GRAY); for (int y = 1; y < ROWS; ++y) g.fillRoundRect(0, cellSize * y - 4, (cellSize * COLS) - 1, 8, 8, 8); for (int x = 1; x < COLS; ++x) g.fillRoundRect(cellSize * x - 4, 0, 8, (cellSize * ROWS) - 1, 8, 8); // Use graphics2d for when not using the images Graphics2D g2d = (Graphics2D) g; g2d.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); for (int y = 0; y < ROWS; ++y) { for (int x = 0; x < COLS; ++x) { int x1 = x * cellSize + 16; int y1 = y * cellSize + 16; if (board[y][x] == Symbol.X) { // use image if set to true, otherwise use g2d // for thicker, better looking X's and O's if (useImages) g.drawImage(imageX, x1, y1, 75, 75, null); else { g2d.setColor(PURPLE); int x2 = (x + 1) * cellSize - 16; int y2 = (y + 1) * cellSize - 16; g2d.drawLine(x1, y1, x2, y2); g2d.drawLine(x2, y1, x1, y2); } } else if (board[y][x] == Symbol.O) { if (useImages) g.drawImage(imageO, x1, y1, 75, 75, null); else { g2d.setColor(Color.BLUE); g2d.drawOval(x1, y1, 70, 70); } } } // end for } // Set status bar based on gamestate. If CONTINUE, show whose turn it is if (gameStatus == GameStatus.CONTINUE) { statusBar.setForeground(Color.BLACK); if (currentPlayer == Symbol.X) statusBar.setText("X's Turn"); else statusBar.setText("O's Turn"); } else if (gameStatus == GameStatus.DRAW) { statusBar.setForeground(Color.RED); statusBar.setText("Draw! Click to play again!"); } else if (gameStatus == GameStatus.X_WIN) { statusBar.setForeground(Color.RED); statusBar.setText("X has won! Click to play again!"); } else if (gameStatus == GameStatus.O_WIN) { statusBar.setForeground(Color.RED); statusBar.setText("O has won! Click to play again!"); } }
// initialize default image private BufferedImage getDefaultImage(int w, int h) { BufferedImage defaultImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = defaultImage.createGraphics(); graphics2D.setColor(new Color(200, 200, 200)); graphics2D.fillRect(0, 0, w, h); graphics2D.setColor(new Color(130, 130, 130)); graphics2D.drawRect(0, 0, w - 1, h - 1); return defaultImage; }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; int i, j, k; System.out.println("Starting painting"); // draw sets if (firstTimeAround) { drawSet(g2); render(); viewer.save("final_product_full.png"); firstTimeAround = false; } // render(); /* for(i=0;i<viewer.getWidth();i++){ for(j=0;j<viewer.getHeight();j++){ viewer.setPixel(i,j,Color3.BLACK); } } */ g2.setBackground(Color.BLACK); // if(newRender){ for (i = minX; i < maxX; i++) { // System.out.println("line "+i); for (j = minY; j < maxY; j++) { g2.setColor( new Color( (float) viewer.getPixel(i, j).getR(), (float) viewer.getPixel(i, j).getG(), (float) viewer.getPixel(i, j).getB())); // g2.drawLine(i,j,1,1); Ellipse2D.Double node_circ = new Ellipse2D.Double(i, j, 1, 1); g2.fill(node_circ); g2.setColor(Color.BLACK); // if(j*scale<viewer.getHeight()){ // j=0;//viewer.getHeight(); // } } // if(i*scale<viewer.getWidth()){ // i=0;//viewer.getWidth(); // } } // g2.drawImage(viewer.1) newRender = false; // } System.out.println("end painting"); }
/** * Draws the edge. * * @param graphics the graphics context */ public void draw(Graphics2D graphics) { updateContactPoints(); Color oldColor = graphics.getColor(); Stroke oldStroke = graphics.getStroke(); graphics.setColor(getBorderColor()); graphics.setStroke(getLineStyle()); graphics.draw(getPath()); graphics.setStroke(oldStroke); graphics.setColor(oldColor); }
public void setPenColour(int colour) { if (Preferences.monochrome) { gRef.setColor(Preferences.blackColor); } else { if (colour == 0) { gRef.setColor(Preferences.penColor); } if (colour == 1) { gRef.setColor(Preferences.highlightColor); } } }
/** * Set the canvas visibility and brings canvas to the front of screen when made visible. This * method can also be used to bring an already visible canvas to the front of other windows. * * @param visible boolean value representing the desired visibility of the canvas (true or false) */ public void setVisible(boolean visible) { if (graphic == null) { // first time: instantiate the offscreen image and fill it with // the background color Dimension size = canvas.getSize(); canvasImage = canvas.createImage(size.width, size.height); graphic = (Graphics2D) canvasImage.getGraphics(); graphic.setColor(backgroundColor); graphic.fillRect(0, 0, size.width, size.height); graphic.setColor(Color.black); } frame.setVisible(visible); }
void draw(Graphics2D g) { // toX/toY is tip of arrow and fx/fy is a point on the line - // fx/fy is used to determine direction & angle AffineTransform at = AffineTransform.getTranslateInstance(toX, toY); int b = 9; double theta = Math.toRadians(20); // The idea of using a GeneralPath is so we can // create the (three lines that make up the) arrow // (only) one time and then use AffineTransform to // place it anywhere we want. GeneralPath path = new GeneralPath(); // distance between line and the arrow mark <** not ** // Start a new line segment from the position of (0,0). path.moveTo(0, 0); // Create one of the two arrow head lines. int x = (int) (-b * Math.cos(theta)); int y = (int) (b * Math.sin(theta)); path.lineTo(x, y); // distance between line and the arrow mark <** not ** // Make the other arrow head line. int x2 = (int) (-b * Math.cos(-theta)); int y2 = (int) (b * Math.sin(-theta)); // path.moveTo(0,0); path.lineTo(x2, y2); path.closePath(); // theta is in radians double s, t; s = toY - fy; // calculate slopes. t = toX - fx; if (t != 0) { s = s / t; theta = Math.atan(s); if (t < 0) theta += Math.PI; } else if (s < 0) theta = -(Math.PI / 2); else theta = Math.PI / 2; at.rotate(theta); // at.rotate(theta,toX,toY); Shape shape = at.createTransformedShape(path); if (checkStatus == Status.UNCHECKED) g.setColor(Color.BLACK); else if (checkStatus == Status.COMPATIBLE) g.setColor(FOREST_GREEN); else g.setColor(ORANGE_RED); g.fill(shape); g.draw(shape); }
public void draw(Graphics2D g) { g.setColor(Color.BLACK); g.fillRect(xPos, yPos, width, length); if (onPlate == true) { g.setColor(Color.white); g.fillOval(600, 20, 15, 15); g.setColor(Color.black); g.fillOval(602, 22, 10, 10); } if (isCooking == true) { g.setColor(Color.black); g.fillOval(700, 20, 10, 10); } }
void renderer(Graphics2D g2d) { height = window.getHeight() - 20; width = window.getWidth(); lastTime = curTime; curTime = System.currentTimeMillis(); totalTime += curTime - lastTime; if (totalTime > 1000) { totalTime -= 1000; fps = frames; frames = 0; } ++frames; delta = 16.0 / (curTime - lastTime); if (delta < 0) delta = 0; g2d.setColor(Color.white); if (removeMode) g2d.fill(new Rectangle(0, 0, width, height)); if (eventHandeler(g2d)) { renderBackground(g2d); return; } Graphics2D map = (Graphics2D) g2d.create(); playerHandeler(); xOffset = -player.body.getCenterX() + width / 2; yOffset = -player.body.getCenterY() + height / 2; if (-xOffset < bounds.getBounds2D().getX()) xOffset = -bounds.getBounds2D().getX(); else if (-xOffset > bounds.getBounds2D().getMaxX() - width) xOffset = -bounds.getBounds2D().getMaxX() + width; if (-yOffset < bounds.getBounds2D().getY()) yOffset = -bounds.getBounds2D().getY(); else if (-yOffset > bounds.getBounds2D().getMaxY() - height + 3) yOffset = -bounds.getBounds2D().getMaxY() + height - 3; map.translate(xOffset, yOffset); renderBackground(map); itemHandeler(map); enemieHandeler(); characterHandeler(map); map.setColor(Color.black); map.draw(bounds); renderUI(g2d); }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.white); g2.fillRect(0, 0, getWidth(), getHeight()); AffineTransform at = new AffineTransform(0.5, 0, 0, -0.5, 30, getHeight() * 3 / 4); g2.transform(at); g2.setColor(Color.black); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // System.out.println("Showing="+showing); if (showing != null) { showing.draw(g2); } }
/** Draws the game */ @Override protected void paintComponent(Graphics g) { super.paintComponent(g); final Graphics2D g2 = (Graphics2D) g; /** Draw all the non-falling blocks on the board. Non-OUTSIDE blocks have rounded corners. */ for (int row = 0; row < board.getHeight(); row++) { for (int column = 0; column < board.getWidth(); column++) { if (board.getSquareType(row, column) != SquareType.OUTSIDE) { Shape tetrominoBlock = new RoundRectangle2D.Double( column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT, 5, 5); g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column))); g2.fill(tetrominoBlock); g2.draw(tetrominoBlock); } else { Shape tetrominoBlock = new Rectangle2D.Double( column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT); g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column))); g2.fill(tetrominoBlock); g2.draw(tetrominoBlock); } } } Poly tempPoly = board.getFalling(); if (tempPoly != null) { for (int row = 0; row < tempPoly.getSize(); row++) { for (int column = 0; column < tempPoly.getSize(); column++) { if (tempPoly.getSquareType(row, column) != SquareType.EMPTY) { Shape tetrominoBlock = new RoundRectangle2D.Double( (column + board.getFallingPosX()) * SQUARE_WIDTH, (row + board.getFallingPosY()) * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT, 5, 5); g2.setColor(SQUARE_COLOR.get(tempPoly.getSquareType(row, column))); g2.fill(tetrominoBlock); g2.draw(tetrominoBlock); } } } } }
private BufferedImage createThumbNailImage(Dimension imgSize, ProgressMonitor pm) { Assert.notNull(pm, "pm"); String thumbNailBandName = getThumbnailBandName(); Band thumbNailBand = product.getBand(thumbNailBandName); Debug.trace( "ProductSubsetDialog: Reading thumbnail data for band '" + thumbNailBandName + "'..."); pm.beginTask("Creating thumbnail image", 5); BufferedImage image = null; try { MultiLevelSource multiLevelSource = BandImageMultiLevelSource.create(thumbNailBand, SubProgressMonitor.create(pm, 1)); final ImageLayer imageLayer = new ImageLayer(multiLevelSource); final int imageWidth = imgSize.width; final int imageHeight = imgSize.height; final int imageType = BufferedImage.TYPE_3BYTE_BGR; image = new BufferedImage(imageWidth, imageHeight, imageType); Viewport snapshotVp = new DefaultViewport(isModelYAxisDown(imageLayer)); final BufferedImageRendering imageRendering = new BufferedImageRendering(image, snapshotVp); final Graphics2D graphics = imageRendering.getGraphics(); graphics.setColor(getBackground()); graphics.fillRect(0, 0, imageWidth, imageHeight); snapshotVp.zoom(imageLayer.getModelBounds()); snapshotVp.moveViewDelta(snapshotVp.getViewBounds().x, snapshotVp.getViewBounds().y); imageLayer.render(imageRendering); pm.worked(4); } finally { pm.done(); } return image; }
@Override public void paint(Graphics2D g2, State s, float cWidth, float cHeight) { float domainXScale = this.dwidth; float domainYScale = this.dheight; // determine then normalized width float width = (1.0f / domainXScale) * cWidth; float height = (1.0f / domainYScale) * cHeight; // pass through each cell of the map and if it is a wall, draw it for (int i = 0; i < this.dwidth; i++) { for (int j = 0; j < this.dheight; j++) { if (this.map[i][j] > 0) { float rx = i * width; float ry = cHeight - height - j * height; // draw the walls; make them black g2.setColor(this.cols[this.map[i][j] - 1]); g2.fill(new Rectangle2D.Float(rx, ry, width, height)); } } } }
private void paintToImage( final BufferedImage img, final int x, final int y, final int width, final int height) { // clear the prior image Graphics2D imgG = (Graphics2D) img.getGraphics(); imgG.setComposite(AlphaComposite.Clear); imgG.setColor(Color.black); imgG.fillRect(0, 0, width + blur * 2, height + blur * 2); final int adjX = (int) (x + blur + offsetX + (insets.left * distance)); final int adjY = (int) (y + blur + offsetY + (insets.top * distance)); final int adjW = (int) (width - (insets.left + insets.right) * distance); final int adjH = (int) (height - (insets.top + insets.bottom) * distance); // let the delegate paint whatever they want to be blurred imgG.setComposite(AlphaComposite.DstAtop); if (prePainter != null) prePainter.paint(imgG, adjX, adjY, adjW, adjH); imgG.dispose(); // blur the prior image back into the same pixels imgG = (Graphics2D) img.getGraphics(); imgG.setComposite(AlphaComposite.DstAtop); imgG.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); imgG.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); imgG.drawImage(img, blurOp, 0, 0); if (postPainter != null) postPainter.paint(imgG, adjX, adjY, adjW, adjH); imgG.dispose(); }
/** * Paint a background for all groups and a round blue border and background when a cell is * selected. * * @param g2 the <tt>Graphics2D</tt> object through which we paint */ private void internalPaintComponent(Graphics2D g2) { Color borderColor = Color.GRAY; if (isSelected) { g2.setPaint( new GradientPaint( 0, 0, Constants.SELECTED_COLOR, 0, getHeight(), Constants.SELECTED_GRADIENT_COLOR)); borderColor = Constants.SELECTED_COLOR; } else if (treeNode instanceof GroupNode) { g2.setPaint( new GradientPaint( 0, 0, Constants.CONTACT_LIST_GROUP_BG_GRADIENT_COLOR, 0, getHeight(), Constants.CONTACT_LIST_GROUP_BG_COLOR)); borderColor = Constants.CONTACT_LIST_GROUP_BG_COLOR; } g2.fillRect(0, 0, getWidth(), getHeight()); g2.setColor(borderColor); g2.drawLine(0, 0, getWidth(), 0); g2.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1); }
/** * Draws this without refreshing steps. * * @param panel the drawing panel requesting the drawing * @param _g the graphics context on which to draw */ public void drawMe(DrawingPanel panel, Graphics _g) { // position and show inspector if requested during loading if (inspectorX != Integer.MIN_VALUE && trackerPanel != null && trackerPanel.getTFrame() != null) { positionInspector(); Runnable runner = new Runnable() { public void run() { showInspector = false; inspector.setVisible(true); } }; if (showInspector) SwingUtilities.invokeLater(runner); } if (isVisible() && isTraceVisible()) { // draw trace only if fixed coords & (non-worldview or no ref frame) TrackerPanel tPanel = (TrackerPanel) panel; ImageCoordSystem coords = tPanel.getCoords(); // get active coords boolean isRefFrame = coords instanceof ReferenceFrame; if (isRefFrame) { coords = ((ReferenceFrame) coords).getCoords(); } boolean fixed = coords.isFixedAngle() && coords.isFixedOrigin() && coords.isFixedScale(); if (fixed && (!(tPanel instanceof WorldTView) || !isRefFrame)) { trace.reset(); for (int i = 0; i < traceX.length; i++) { if (Double.isNaN(traceX[i])) continue; tracePt.setLocation(traceX[i], traceY[i]); java.awt.Point p = tracePt.getScreenPosition(tPanel); if (trace.getCurrentPoint() == null) trace.moveTo((float) p.getX(), (float) p.getY()); else trace.lineTo((float) p.getX(), (float) p.getY()); } Graphics2D g2 = (Graphics2D) _g; Color color = g2.getColor(); Stroke stroke = g2.getStroke(); g2.setColor(getFootprint().getColor()); g2.setStroke(traceStroke); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2.draw(trace); // restore original color and stroke g2.setColor(color); g2.setStroke(stroke); } } super.draw(panel, _g); }
/** * paintComponent schreibt alle Laendernamen an die entsprechende Stelle der Landkarte * (Hintergrundgrafik) und zeichnet die Laendergrenzen auf der Landkarte nach. * * @param g Zeichenflaeche der Landkarte */ public void paintComponent(Graphics g) { Shape shape; Graphics2D g2d = (Graphics2D) g; g2d.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this); Font myFont = new Font("Times New Roman", Font.BOLD, 12); g2d.setFont(myFont); g2d.setStroke(new BasicStroke(2.0f)); Territory territory; Color color; ListIterator territories = worldMap.getTerritories().listIterator(); while (territories.hasNext()) { territory = (Territory) territories.next(); if (territory.getOwner() != null) { color = territory.getOwner().getPlayerColor(); } else { color = Color.WHITE; } g2d.setColor(color); g2d.drawString( territory.getName(), (int) territory.getMidpoint().getX() - 15, (int) territory.getMidpoint().getY() - 10); g2d.drawString( new Integer(territory.getArmySize()).toString(), (int) territory.getMidpoint().getX(), (int) territory.getMidpoint().getY()); } if (territoryBattle.size() != 0) { for (int j = 0; j < territoryBattle.size(); j++) { g2d.setColor(territoryBattle.get(j).getOwner().getPlayerColor()); // g2d.fillPolygon(territoryTmp.getFrontiers()); Sieht bei unseren Grenzen nicht huebsch // aus g2d.drawPolygon(territoryBattle.get(j).getFrontiers()); } } repaint(); }
public BufferedImage filter(BufferedImage src, BufferedImage dst) { if (dst == null) dst = createCompatibleDestImage(src, null); int width = src.getWidth(); int height = src.getHeight(); int numScratches = (int) (density * width * height / 100); ArrayList<Line2D> lines = new ArrayList<Line2D>(); { float l = length * width; Random random = new Random(seed); Graphics2D g = dst.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(new Color(color)); g.setStroke(new BasicStroke(this.width)); for (int i = 0; i < numScratches; i++) { float x = width * random.nextFloat(); float y = height * random.nextFloat(); float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f)); float s = (float) Math.sin(a) * l; float c = (float) Math.cos(a) * l; float x1 = x - c; float y1 = y - s; float x2 = x + c; float y2 = y + s; g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); lines.add(new Line2D.Float(x1, y1, x2, y2)); } g.dispose(); } if (false) { // int[] inPixels = getRGB( src, 0, 0, width, height, null ); int[] inPixels = new int[width * height]; int index = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float sx = x, sy = y; for (int i = 0; i < numScratches; i++) { Line2D.Float l = (Line2D.Float) lines.get(i); float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1); if (dot > 0) inPixels[index] |= (1 << i); } index++; } } Colormap colormap = new LinearColormap(); index = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff; inPixels[index] = colormap.getColor(f); index++; } } setRGB(dst, 0, 0, width, height, inPixels); } return dst; }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; if (!text.equals("")) { g2.translate(0, getSize().getHeight()); g2.rotate(-Math.PI / 2); g2.setColor(Color.red); g2.fillRect(0, 0, sizeText_y, sizeText_x); g2.setColor(Color.white); g2.drawString(text, 20, 14); g2.translate(0, -getSize().getHeight()); g2.transform(AffineTransform.getQuadrantRotateInstance(1)); } }
/** * Set the foreground colour of the Canvas. * * @param newColour the new colour for the foreground of the Canvas */ public void setForegroundColor(String colorString) { if (colorString.equals("red")) graphic.setColor(Color.red); else if (colorString.equals("black")) graphic.setColor(Color.black); else if (colorString.equals("blue")) graphic.setColor(Color.blue); else if (colorString.equals("yellow")) graphic.setColor(Color.yellow); else if (colorString.equals("green")) graphic.setColor(Color.green); else if (colorString.equals("magenta")) graphic.setColor(Color.magenta); else if (colorString.equals("white")) graphic.setColor(Color.white); else graphic.setColor(Color.black); }
/** @see prefuse.render.Renderer#render(java.awt.Graphics2D, prefuse.visual.VisualItem) */ @Override public void render(Graphics2D g, VisualItem item) { Shape s = getShape(item); GraphicsLib.paint(g, item, m_line, getStroke(item), getRenderType(item)); // check if we have a text label, if so, render it String str; if (item.canGetString(VisualItem.LABEL)) { str = (String) item.getString(VisualItem.LABEL); if (str != null && !str.equals("")) { float x = (float) m_box.getMinX(); float y = (float) m_box.getMinY() + m_ascent; // draw label background GraphicsLib.paint(g, item, s, null, RENDER_TYPE_FILL); AffineTransform origTransform = g.getTransform(); AffineTransform transform = this.getTransform(item); if (transform != null) { g.setTransform(transform); } g.setFont(item.getFont()); g.setColor(ColorLib.getColor(item.getTextColor())); if (!(str.length() > 5 && str.substring(str.length() - 5, str.length()).equals("_last"))) { g.setColor(Color.WHITE); // TODO properly hunt down source of null str! for now, triage if (str != null) { // bump y down by appropriate amount FontMetrics fm = g.getFontMetrics(item.getFont()); int strHeight = fm.getAscent(); // g.drawString(str, x, y); g.drawString(str, x, y + strHeight); } if (transform != null) { g.setTransform(origTransform); } } } } }
public void paintItem(Graphics2D g, int x1, int y1, int x2, int y2) { if (!canPaint()) { return; } Iterator<ScoredRegion> regions = model.getResults(); while (regions.hasNext()) { ScoredRegion r = regions.next(); int minx = getXPos(r.getStart(), getRegion().getStart(), getRegion().getEnd(), x1, x2); int maxx = getXPos(r.getEnd(), getRegion().getStart(), getRegion().getEnd(), x1, x2); float percent = (float) (1.0 - r.getScore() / maxScore); g.setColor(new Color(percent, percent, percent, (float) 1.0)); g.fillRect(minx, y1, maxx - minx, (y2 - y1)); } if (props.DrawTrackLabel) { g.setColor(new Color((float) 0.0, (float) 0.0, (float) 0.0, (float) 0.5)); g.drawString(getLabel(), x1, y2); } }
public void paint(Graphics screen) { Graphics2D screen2D = (Graphics2D) screen; Font type = new Font("Monospaced", Font.BOLD, 20); screen2D.setFont(type); GregorianCalendar day = new GregorianCalendar(); String time = day.getTime().toString(); screen2D.setColor(back); screen2D.drawString(lastTime, 5, 25); screen2D.setColor(butterscotch); screen2D.drawString(time, 5, 25); try { Thread.sleep(1000); } catch (InterruptedException e) { // do nothing } lastTime = time; repaint(); }