List of usage examples for java.awt Graphics2D setColor
public abstract void setColor(Color c);
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
@Override public void renderCellLD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY, int cellWidth, int cellHeight) { if (v == null || v.isNaN()) { //System.out.println(v); _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight); } else {/* w ww . j ava 2s .c o m*/ try { g2D.setColor(UI.colorBlack2); g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight); g2D.setColor(barColorNormal); g2D.setStroke(UI.stroke1_5); //This is the //int height = (int)Math.round(cellHeight * (v - _minValue)/(_maxValue - _minValue)); //g2D.fillRect(Math.round(anchorX), Math.round(anchorY + cellHeight - height), Math.round(cellWidth), Math.round(cellHeight)); if (rowNode.isSingleNode() && columnNode.isSingleNode()) { double value = (v - _minValue) / (_maxValue - _minValue); if (v >= disectBound) { g2D.setColor(barColorNormal); } else { g2D.setColor(barColorBelow); } g2D.drawLine((int) (anchorX + 1), (int) (anchorY + cellHeight - cellHeight * value), (int) (anchorX + cellWidth - 1), (int) (anchorY + cellHeight - cellHeight * value)); } else { // double min = percentile.evaluate(valueArray, 0); // double max = percentile.evaluate(valueArray, 100) double fiveVal[] = boxPlotValues(getCoolMapObject(), rowNode, columnNode); if (fiveVal == null) { g2D.setColor(UI.colorBlack1); g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth), Math.round(cellHeight)); } double range = _maxValue - _minValue; double minP = (fiveVal[0] - _minValue) / range; double maxP = (fiveVal[4] - _minValue) / range; double medianP = (fiveVal[2] - _minValue) / range; double q1P = (fiveVal[1] - _minValue) / range; double q3P = (fiveVal[3] - _minValue) / range; try { // if (cellWidth >= 2 && cellHeight >= 2) { g2D.drawLine((int) (anchorX + cellWidth / 2), (int) (anchorY + cellHeight - cellHeight * maxP), (int) (anchorX + cellWidth / 2), (int) (anchorY + cellHeight - cellHeight * minP)); if (fiveVal[2] >= disectBound) { g2D.setColor(UI.colorLightGreen4); } else { g2D.setColor(UI.colorOrange2); } g2D.fillRect((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth), (int) (cellHeight * (q3P - q1P))); if (fiveVal[2] >= disectBound) { g2D.setColor(barColorNormal); } else { g2D.setColor(barColorBelow); } // g2D.setColor(barColorNormal); //g2D.drawRect((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth), (int) (cellHeight * (q3P - q1P))); g2D.drawLine((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * medianP), (int) (anchorX + cellWidth), (int) (anchorY + cellHeight - cellHeight * medianP)); // } else { // // if (fiveVal[2] >= medianP) { // g2D.setColor(barColorNormal); // } else { // g2D.setColor(barColorBelow); // } // //// System.out.println("painted rect"); //// System.out.println((int) cellWidth + " " + ((int) cellHeight)); // g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight); // } } catch (Exception e) { System.err.println("Boxplot render exception"); } } // if(cellWidth>=4 && cellHeight >=){ // g2D.setColor(UI.colorBlack1); // g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth), Math.round(cellHeight)); // } } catch (Exception e) { } } }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * Paint the given tree layout/*from w w w . j a v a 2 s . c o m*/ * @param graphics * the graphics to paint with * @param treeLayout * the layout to paint */ private void paintPhylogenyTree(Graphics2D graphics, VisualTreeNode treeLayout) { int childNodeCount = treeLayout.getChildNodes().size(); for (int i = 0; i < childNodeCount; i++) { VisualTreeNode visualChild = treeLayout.getChildNodes().get(i); Shape branchShape = new Line2D.Double(treeLayout.getPosition(), visualChild.getPosition()); Shape branchShadowShape = SHADOW_TRANSFORM.createTransformedShape(branchShape); graphics.setColor(SHADOW_COLOR); graphics.draw(branchShadowShape); if (this.paintScale != null) { PhylogenyTreeEdge phylogenyEdge = treeLayout.getPhylogenyTreeNode().getChildEdges().get(i); if (phylogenyEdge instanceof PhylogenyTreeEdgeWithRealValue) { PhylogenyTreeEdgeWithRealValue phylogenyEdgeWithValue = (PhylogenyTreeEdgeWithRealValue) phylogenyEdge; Paint paint = this.paintScale.getPaint(phylogenyEdgeWithValue.getRealValue()); graphics.setPaint(paint); } else { graphics.setColor(FOREGROUND_COLOR); } } else { graphics.setColor(FOREGROUND_COLOR); } graphics.draw(branchShape); // recurse this.paintPhylogenyTree(graphics, visualChild); } if (!treeLayout.getPhylogenyTreeNode().getStrains().isEmpty()) { Shape textShape = this.getLabelShape(treeLayout, graphics.getFontRenderContext()); Shape borderShape = this.getLabelBorder(textShape); graphics.setColor(BACKGROUND_COLOR); graphics.fill(borderShape); graphics.setColor(SHADOW_COLOR); Area borderShadowShape = new Area(SHADOW_TRANSFORM.createTransformedShape(borderShape)); borderShadowShape.subtract(new Area(borderShape)); graphics.draw(borderShadowShape); graphics.setColor(FOREGROUND_COLOR); graphics.draw(borderShape); graphics.fill(textShape); } }
From source file:GifDecoder.java
/** * Creates new frame image from current data (and previous * frames as specified by their disposition codes). */// w ww .ja v a 2 s . c o m protected void setPixels() { // expose destination image's pixels as int array int[] dest = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); // fill in starting image contents based on last image's dispose code if (lastDispose > 0) { if (lastDispose == 3) { // use image before last int n = frameCount - 2; if (n > 0) { lastImage = getFrame(n - 1); } else { lastImage = null; } } if (lastImage != null) { int[] prev = ((DataBufferInt) lastImage.getRaster().getDataBuffer()).getData(); System.arraycopy(prev, 0, dest, 0, width * height); // copy pixels if (lastDispose == 2) { // fill last image rect area with background color Graphics2D g = image.createGraphics(); Color c = null; if (transparency) { c = new Color(0, 0, 0, 0); // assume background is transparent } else { c = new Color(lastBgColor); // use given background color } g.setColor(c); g.setComposite(AlphaComposite.Src); // replace area g.fill(lastRect); g.dispose(); } } } // copy each source line to the appropriate place in the destination int pass = 1; int inc = 8; int iline = 0; for (int i = 0; i < ih; i++) { int line = i; if (interlace) { if (iline >= ih) { pass++; switch (pass) { case 2: iline = 4; break; case 3: iline = 2; inc = 4; break; case 4: iline = 1; inc = 2; } } line = iline; iline += inc; } line += iy; if (line < height) { int k = line * width; int dx = k + ix; // start of line in dest int dlim = dx + iw; // end of dest line if ((k + width) < dlim) { dlim = k + width; // past dest edge } int sx = i * iw; // start of line in source while (dx < dlim) { // map color and insert in destination int index = ((int) pixels[sx++]) & 0xff; int c = act[index]; if (c != 0) { dest[dx] = c; } dx++; } } } }
From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java
private void processTextElement(Graphics2D g2, Element textElement) { int x = Integer.valueOf(textElement.getAttributeValue("X")); int y = Integer.valueOf(textElement.getAttributeValue("Y")); int width = Integer.valueOf(textElement.getAttributeValue("Width")); int height = Integer.valueOf(textElement.getAttributeValue("Height")); String alignment = textElement.getAttributeValue("TextAlignment"); boolean multiline = Boolean.valueOf(textElement.getAttributeValue("Multiline").toLowerCase()); boolean antiAlias = textElement.getAttributeValue("TextQuality").equalsIgnoreCase("antialias"); Font font = parseFont(textElement.getAttributeValue("Font")); logger.info("Using font " + font); // now get the textim4java performance String text = textElement.getAttributeValue("Text"); // if text matches pattern of %VARIABLE%{MODIFIER} logger.info("parsing token {}", text); Matcher matcher = pattern.matcher(text); int start = 0; while (matcher.find(start)) { // apply modification text = text.replace(matcher.group(), applyModifier(matcher.group())); start = matcher.end();/*from ww w . j a v a 2 s. co m*/ } BufferedImage tmpImage; if (width > 0 && height > 0) { // create a transparent tmpImage tmpImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); } else { FontMetrics fm = g2.getFontMetrics(font); Rectangle outlineBounds = fm.getStringBounds(text, g2).getBounds(); // we need to create a transparent image to paint tmpImage = new BufferedImage(outlineBounds.width, outlineBounds.height, BufferedImage.TYPE_INT_ARGB); } Graphics2D g2d = tmpImage.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); // } g2d.setFont(font); Color textColor = new Color(Integer.valueOf(textElement.getAttributeValue("ForeColor"))); g2d.setColor(textColor); Composite comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .8f); g2d.setComposite(comp); drawString(g2d, text, new Rectangle(0, 0, width, height), Align.valueOf(alignment), 0, multiline); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); tmpImage = processActions(textElement, tmpImage); //// Graphics2D g2d = tmpImage.createGraphics(); // // set current font // g2.setFont(font); //// g2d.setComposite(AlphaComposite.Clear); //// g2d.fillRect(0, 0, width, height); //// g2d.setComposite(AlphaComposite.Src); // // TODO: we have to parse it // int strokeWidth = Integer.valueOf(textElement.getAttributeValue("StrokeWidth")); // // the color of the outline // if (strokeWidth > 0) { //// Color strokeColor = new Color(Integer.valueOf(textElement.getAttributeValue("StrokeColor"))); //// AffineTransform affineTransform; //// affineTransform = g2d.getTransform(); //// affineTransform.translate(width / 2 - (outlineBounds.width / 2), height / 2 //// + (outlineBounds.height / 2)); //// g2d.transform(affineTransform); //// // backup stroke width and color //// Stroke originalStroke = g2d.getStroke(); //// Color originalColor = g2d.getColor(); //// g2d.setColor(strokeColor); //// g2d.setStroke(new BasicStroke(strokeWidth)); //// g2d.draw(shape); //// g2d.setClip(shape); //// // restore stroke width and color //// g2d.setStroke(originalStroke); //// g2d.setColor(originalColor); // } //// // get the text color // Color textColor = new Color(Integer.valueOf(textElement.getAttributeValue("ForeColor"))); // g2.setColor(textColor); //// g2d.setBackground(Color.BLACK); //// g2d.setStroke(new BasicStroke(2)); //// g2d.setColor(Color.WHITE); // // draw the text // // drawString(g2, text, new Rectangle(x, y, width, height), Align.valueOf(alignment), 0, multiline); // g2.drawString(text, x, y); // Rectangle rect = new Rectangle(x, y, width, height); // defines the desired size and position // FontMetrics fm = g2.getFontMetrics(); // FontRenderContext frc = g2.getFontRenderContext(); // TextLayout tl = new TextLayout(text, g2.getFont(), frc); // AffineTransform transform = new AffineTransform(); // transform.setToTranslation(rect.getX(), rect.getY()); // if (Boolean.valueOf(textElement.getAttributeValue("AutoSize").toLowerCase())) { // double scaleY // = rect.getHeight() / (double) (tl.getOutline(null).getBounds().getMaxY() // - tl.getOutline(null).getBounds().getMinY()); // transform.scale(rect.getWidth() / (double) fm.stringWidth(text), scaleY); // } // Shape shape = tl.getOutline(transform); // g2.setClip(shape); // g2.fill(shape.getBounds()); // if (antiAlias) { // we need to restore antialias to none // g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); // } // g2.drawString(text, x, y); // alway resize // BicubicScaleFilter scaleFilter = new BicubicScaleFilter(width, height); // tmpImage = scaleFilter.filter(tmpImage, null); // draw the image to the source g2.drawImage(tmpImage, x, y, width, height, null); try { ScreenImage.writeImage(tmpImage, "/tmp/images/" + textElement.getAttributeValue("Name") + ".png"); } catch (IOException ex) { } }
From source file:net.java.sip.communicator.impl.osdependent.jdic.SystrayServiceJdicImpl.java
private BufferedImage createOverlayImage(String text) { int size = 16; BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //background/* ww w . ja v a 2 s .c o m*/ g.setPaint(new Color(0, 0, 0, 102)); g.fillRoundRect(0, 0, size, size, size, size); //filling int mainRadius = 14; g.setPaint(new Color(255, 98, 89)); g.fillRoundRect(size / 2 - mainRadius / 2, size / 2 - mainRadius / 2, mainRadius, mainRadius, size, size); //text Font font = g.getFont(); g.setFont(new Font(font.getName(), Font.BOLD, 9)); FontMetrics fontMetrics = g.getFontMetrics(); int textWidth = fontMetrics.stringWidth(text); g.setColor(Color.white); g.drawString(text, size / 2 - textWidth / 2, size / 2 - fontMetrics.getHeight() / 2 + fontMetrics.getAscent()); return image; }
From source file:de.tor.tribes.ui.views.DSWorkbenchDoItYourselfAttackPlaner.java
@Override public void resetView() { AttackManager.getSingleton().addManagerListener(this); //setup renderer and general view // ((DoItYourselfAttackTableModel) jAttackTable.getModel()).clear(); HighlightPredicate.ColumnHighlightPredicate colu = new HighlightPredicate.ColumnHighlightPredicate(0, 1, 2, 3, 6);/* w ww. ja va 2 s . co m*/ jAttackTable.setRowHeight(24); jAttackTable.getTableHeader().setDefaultRenderer(new DefaultTableHeaderRenderer()); jAttackTable.setHighlighters(new CompoundHighlighter(colu, HighlighterFactory.createAlternateStriping(Constants.DS_ROW_A, Constants.DS_ROW_B))); jAttackTable.setColumnControlVisible(true); jAttackTable.setDefaultEditor(UnitHolder.class, new UnitCellEditor()); jAttackTable.setDefaultEditor(Village.class, new VillageCellEditor()); jAttackTable.setDefaultRenderer(UnitHolder.class, new UnitCellRenderer()); jAttackTable.setDefaultRenderer(Integer.class, new NoteIconCellRenderer(NoteIconCellRenderer.ICON_TYPE.NOTE)); jAttackTable.setDefaultRenderer(Date.class, new ColoredDateCellRenderer()); jAttackTable.setDefaultRenderer(Long.class, new ColoredCoutdownCellRenderer()); jAttackTable.setDefaultEditor(Date.class, new DateSpinEditor()); jAttackTable.setDefaultEditor(Integer.class, new NoteIconCellEditor(NoteIconCellEditor.ICON_TYPE.NOTE)); BufferedImage back = ImageUtils.createCompatibleBufferedImage(5, 5, BufferedImage.BITMASK); Graphics2D g = back.createGraphics(); GeneralPath p = new GeneralPath(); p.moveTo(0, 0); p.lineTo(5, 0); p.lineTo(5, 5); p.closePath(); g.setColor(Color.GREEN.darker()); g.fill(p); g.dispose(); jAttackTable.addHighlighter(new PainterHighlighter(HighlightPredicate.EDITABLE, new ImagePainter(back, HorizontalAlignment.RIGHT, VerticalAlignment.TOP))); DefaultComboBoxModel model = new DefaultComboBoxModel(); DefaultComboBoxModel model2 = new DefaultComboBoxModel(); for (UnitHolder unit : DataHolder.getSingleton().getUnits()) { model.addElement(unit); model2.addElement(unit); } jUnitBox.setModel(model); jUnitComboBox.setModel(model2); jUnitBox.setSelectedItem(DataHolder.getSingleton().getUnitByPlainName("ram")); jUnitComboBox.setSelectedItem(DataHolder.getSingleton().getUnitByPlainName("ram")); jUnitBox.setRenderer(new UnitListCellRenderer()); jAttackTypeComboBox.setRenderer(new StandardAttackListCellRenderer()); DefaultComboBoxModel typeModel = new DefaultComboBoxModel(); for (ManageableType t : StandardAttackManager.getSingleton().getAllElements()) { StandardAttack a = (StandardAttack) t; typeModel.addElement(a); } jAttackTypeComboBox.setModel(typeModel); jUnitComboBox.setRenderer(new UnitListCellRenderer()); jSourceVillage.setValue(new Point(500, 500)); jTargetVillage.setValue(new Point(500, 500)); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jSourceVillage.updateUI(); jTargetVillage.updateUI(); } }); }
From source file:HelloUniverse.java
private void drawZPip(Graphics2D g2, float zAngle) { AffineTransform trans = new AffineTransform(); Color origColor = g2.getColor(); trans.translate(margin, margin);/* w w w. ja v a 2 s.co m*/ trans.rotate(zAngle, diameter / 2, diameter / 2); g2.setXORMode(getBackground()); g2.setTransform(trans); g2.setColor(Color.red); g2.fillPolygon(zPip); // Reset graphics context trans.setToIdentity(); g2.setTransform(trans); g2.setColor(origColor); g2.setPaintMode(); }
From source file:at.tuwien.ifs.somtoolbox.apps.viewer.GeneralUnitPNode.java
/** @see edu.umd.cs.piccolo.PNode#paint(edu.umd.cs.piccolo.util.PPaintContext) */ @Override//from ww w. ja v a2 s . c om protected void paint(PPaintContext paintContext) { Graphics2D g2d = paintContext.getGraphics(); if (state.exactUnitPlacement && getMapPNode().getCurrentVisualization() == null) { // black background for sky // vis border.setRect(X, Y, width, height); g2d.setColor(Color.BLACK); g2d.fill(border); } if (drawBorder) { GridGeometry helper = state.growingSOM.getLayer().getGridGeometry(); Vector3D[] v = helper.shapeLinePoints(X, Y, width, height); g2d.setStroke(borderStroke); g2d.setPaint(Color.CYAN); g2d.setColor(borderColor); g2d.drawLine((int) v[0].getX(), (int) v[0].getY(), (int) v[1].getX(), (int) v[1].getY()); for (int i = 1; i < v.length; i++) { int i_1 = (i + 1) % v.length; g2d.drawLine((int) v[i].getX(), (int) v[i].getY(), (int) v[i_1].getX(), (int) v[i_1].getY()); } border.setRect(helper.getBorder(X, Y, width, height)); } PCamera pCam = paintContext.getCamera(); if (!((PCanvas) pCam.getComponent()).getClass().equals(MapOverviewPane.MapOverviewCanvas.class)) { // only for // main // display currentScale = paintContext.getScale(); if (currentScale != oldScale) { // System.out.println("SCALE: "+currentScale); // double os = t10.getScale(); // t10.setScale(1/currentScale); // if (t10.getGlobalFullBounds().width>this.width) { // t10.setScale(os); // } if (currentScale < state.scaleLimits[1]) { // no information if (currentDetailLevel != DETAIL_LEVEL_NO) { currentDetailLevel = DETAIL_LEVEL_NO; detailChanged(); } } else if (currentScale >= state.scaleLimits[1] && currentScale < state.scaleLimits[2]) { // little // information if (currentDetailLevel != DETAIL_LEVEL_LOW) { currentDetailLevel = DETAIL_LEVEL_LOW; detailChanged(); } } else if (currentScale >= state.scaleLimits[2] && currentScale < state.scaleLimits[3]) { // more labels if (currentDetailLevel != DETAIL_LEVEL_MEDIUM) { currentDetailLevel = DETAIL_LEVEL_MEDIUM; detailChanged(); } } else if (currentScale >= state.scaleLimits[3]) { // detailed information if (currentDetailLevel != DETAIL_LEVEL_HIGH) { currentDetailLevel = DETAIL_LEVEL_HIGH; detailChanged(); } } oldScale = currentScale; } } }
From source file:SimpleBufferedImageDemo.java
public void paint(Graphics g) { Graphics2D g2D = (Graphics2D) g; if (display) { if (buffered) { BufferedImage bi = (BufferedImage) createImage(getWidth(), getHeight()); // Draw into the memory buffer. for (int i = 0; i < getWidth(); i = i + displayImage.getWidth(this)) { for (int j = 0; j < getHeight(); j = j + displayImage.getHeight(this)) { bi.createGraphics().drawImage(displayImage, i, j, this); }/*from w w w. ja va 2 s. c o m*/ } // Draw the buffered Image on to the screen g2D.drawImage(bi, 0, 0, this); } // This block of code draws the texture directly onto the screen. else if (!buffered) { for (int i = 0; i < getWidth(); i = i + displayImage.getWidth(this)) { for (int j = 0; j < getHeight(); j = j + displayImage.getHeight(this)) { g2D.drawImage(displayImage, i, j, this); } } } display = false; } else if (clear) { g2D.setColor(Color.white); g2D.clearRect(0, 0, getWidth(), getHeight()); clear = false; } }
From source file:de.tor.tribes.ui.panels.MinimapPanel.java
protected BufferedImage getImage() { BufferedImage tempImg = ImageUtils.createCompatibleBufferedImage(mapDim.width, mapDim.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = (Graphics2D) tempImg.getGraphics(); g2d.setColor(new Color(35, 125, 0)); g2d.fillRect(0, 0, tempImg.getWidth(null), tempImg.getHeight(null)); g2d.drawImage(mBuffer, 0, 0, null);// w ww .ja v a 2 s .com g2d.dispose(); return tempImg; }