Java Code Examples for java.awt.Graphics2D.setFont()

The following are Jave code examples for showing how to use setFont() of the java.awt.Graphics2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: QN-ACTR-Release   File: StatiDrawer.java   View Source Code Vote up 6 votes
private Rectangle2D drawCenteredText(String s, Color c, double centerX, double centerY, Graphics2D g2d, boolean drawBorder) {
	double x, y;
	g2d.setFont(f);
	txtBounds = f.getStringBounds(s, g2d.getFontRenderContext());
	x = centerX - txtBounds.getWidth() / 2.0;
	y = centerY - txtBounds.getY() - txtBounds.getHeight() / 2;
	txtBounds.setRect(x - ELEMS_GAP, y - txtBounds.getHeight() / 2.0 - ELEMS_GAP, txtBounds.getWidth() + 2 * ELEMS_GAP, txtBounds.getHeight() + 2
			* ELEMS_GAP);
	if (drawBorder) {
		g2d.setColor(invertedColor(c));
		g2d.fill(txtBounds);
		g2d.setColor(c);
		g2d.draw(txtBounds);
	}
	Color ctmp = g2d.getColor();
	g2d.setColor(c);
	g2d.drawString(s, (float) x, (float) y);
	g2d.setColor(ctmp);
	return txtBounds;
}
 
Example 2
Project: jmt   File: Convex3DGraph.java   View Source Code Vote up 6 votes
/**
 * Prints useful internal data, such as rotation angles and transform
 * matrices.
 * 
 * @param g
 *            Graphics context.
 */
protected void printViewState(Graphics2D g) {
	int y = 16;
	g.setColor(Color.LIGHT_GRAY);
	g.setFont(FONT);
	// FontMetrics fm = g.getFontMetrics();
	g.drawString("rotY = " + floatString(rotY, 6) + " rad", 16, y);
	g.drawString("= " + floatString((float) (rotY * 180 / Math.PI), 6)
			+ "°", 110, y);
	y += 10;
	g.drawString("rotX = " + floatString(rotX, 6) + " rad", 16, y);
	g.drawString("= " + floatString((float) (rotX * 180 / Math.PI), 6)
			+ "°", 110, y);
	y += 16;

	y = printMatrix4(g, prj.getModelView(), 16, y + 16, "viewMatrix");
	y = printMatrix4(g, prj.getProjection(), 16, y + 16, "projMatrix");
	y = printMatrix4(g, eyeRT, 16, y + 16, "eyeRT");
}
 
Example 3
Project: openjdk-jdk10   File: AquaTabbedPaneContrastUI.java   View Source Code Vote up 6 votes
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        v.paint(g2d, textRect);
        return;
    }

    if (title == null) return;

    final Color color = tabPane.getForegroundAt(tabIndex);
    if (color instanceof UIResource) {
        g2d.setColor(getNonSelectedTabTitleColor());
        if (tabPane.getSelectedIndex() == tabIndex) {
            boolean pressed = isPressedAt(tabIndex);
            boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
            Color textColor = getSelectedTabTitleColor(enabled, pressed);
            Color shadowColor = getSelectedTabTitleShadowColor(enabled);
            AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
            return;
        }
    } else {
        g2d.setColor(color);
    }
    g2d.setFont(font);
    SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
 
Example 4
Project: hearthstone   File: Custo.java   View Source Code Vote up 6 votes
@Override
protected void paintComponent(Graphics g) {
    atualizar();
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setFont(FONT);
    FontRenderContext frc = g2.getFontRenderContext();
    TextLayout textLayout = new TextLayout(Integer.toString(value), FONT, frc);
    g2.setPaint(textColor);
    AffineTransform at = AffineTransform.getTranslateInstance(20, 30);
    Shape outline = textLayout.getOutline(at);
    g2.fill(outline);
    g2.setPaint(BLACK);
    g2.draw(outline);
}
 
Example 5
Project: KeysPerSecond   File: BasePanel.java   View Source Code Vote up 5 votes
@Override
public void paintComponent(Graphics g1) {
	Graphics2D g = (Graphics2D) g1;

	g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, Main.config.getBackgroundOpacity()));
	g.setColor(Main.config.getBackgroundColor());
	g.fillRect(0, 0, this.getWidth(), this.getHeight());
	g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Main.config.getForegroundOpacity()));
	g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

	BufferedImage colorImage = isActive() ? ColorManager.pressed : ColorManager.unpressed;
	g.drawImage(colorImage, 2, 2, this.getWidth() - 2, this.getHeight() - 2, 0, 0, colorImage.getWidth(), colorImage.getHeight(), this);

	g.setColor(isActive() ? Main.config.getBackgroundColor() : Main.config.getForegroundColor());

	String titleString = getTitle();
	Font titleFont = Main.config.mode.getTitleFont(titleString);
	Point namePos = Main.config.mode.getTitleDrawPosition(g, this, titleString, titleFont);
	g.setFont(titleFont);
	g.drawString(titleString, namePos.x, namePos.y);

	String valueString = getValue();
	Font valueFont = Main.config.mode.getValueFont(valueString);
	Point keyCountPos = Main.config.mode.getValueDrawPosition(g, this, valueString, valueFont);
	g.setFont(valueFont);
	g.drawString(valueString, keyCountPos.x, keyCountPos.y);
}
 
Example 6
Project: What-Happened-to-Station-7   File: TStack.java   View Source Code Vote up 5 votes
public void apply(Graphics2D g)
{
	g.setTransform(transform);
	g.setPaint(paint);
	g.setStroke(stroke);
	g.setFont(font);
	g.setComposite(composite);
	g.setBackground(bgrnd);
	g.setClip(shape);
	g.setRenderingHints(hints);
}
 
Example 7
Project: parabuild-ci   File: AbstractCategoryItemRenderer.java   View Source Code Vote up 5 votes
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param row  the row.
 * @param column  the column.
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 * @param negative  indicates a negative value (which affects the item
 *                  label position).
 */
protected void drawItemLabel(Graphics2D g2,
                             PlotOrientation orientation,
                             CategoryDataset dataset,
                             int row, int column,
                             double x, double y,
                             boolean negative) {

    CategoryItemLabelGenerator generator
        = getItemLabelGenerator(row, column);
    if (generator != null) {
        Font labelFont = getItemLabelFont(row, column);
        Paint paint = getItemLabelPaint(row, column);
        g2.setFont(labelFont);
        g2.setPaint(paint);
        String label = generator.generateLabel(dataset, row, column);
        ItemLabelPosition position = null;
        if (!negative) {
            position = getPositiveItemLabelPosition(row, column);
        }
        else {
            position = getNegativeItemLabelPosition(row, column);
        }
        Point2D anchorPoint = calculateLabelAnchorPoint(
                position.getItemLabelAnchor(), x, y, orientation);
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(),
                position.getAngle(), position.getRotationAnchor());
    }

}
 
Example 8
Project: ramus   File: MovingText.java   View Source Code Vote up 5 votes
protected void paintText(final Graphics2D g) {
    if (!transparent && !movingArea.isPrinting() || isNegative()) {
        final Rectangle2D rec = movingArea.getBounds(getBounds());
        g.setColor(fiterColor(movingArea.getBackground()));
        g.fill(rec);
    }
    g.setFont(getFont());
    g.setColor(fiterColor(getColor()));

    movingArea.paintText(g, getXText(), getTextBounds(), getAlign(), 1, true);
}
 
Example 9
Project: litiengine   File: EditorScreen.java   View Source Code Vote up 4 votes
@Override
public void render(final Graphics2D g) {
  Game.getCamera().updateFocus();
  if (Game.getEnvironment() != null) {
    Game.getEnvironment().render(g);
  }

  if (ImageCache.IMAGES.size() > 200) {
    ImageCache.IMAGES.clear();
    log.log(Level.INFO, "cache cleared!");
  }

  if (this.currentResourceFile != null) {
    Game.getScreenManager().setTitle(Game.getInfo().getName() + " " + Game.getInfo().getVersion() + " - " + this.currentResourceFile);
    String mapName = Game.getEnvironment() != null && Game.getEnvironment().getMap() != null ? "\nMap: " + Game.getEnvironment().getMap().getName() : "";
    Program.trayIcon.setToolTip(Game.getInfo().getName() + " " + Game.getInfo().getVersion() + "\n" + this.currentResourceFile + mapName);
  } else if (this.getProjectPath() != null) {
    Game.getScreenManager().setTitle(Game.getInfo().toString() + " - " + NEW_GAME_STRING);
    Program.trayIcon.setToolTip(Game.getInfo().toString() + "\n" + NEW_GAME_STRING);
  } else {
    Game.getScreenManager().setTitle(Game.getInfo().toString());
  }

  super.render(g);

  // render mouse/zoom and fps

  g.setFont(g.getFont().deriveFont(11f));
  g.setColor(Color.WHITE);
  Point tile = Input.mouse().getTile();
  RenderEngine.drawText(g, "x: " + (int) Input.mouse().getMapLocation().getX() + " y: " + (int) Input.mouse().getMapLocation().getY()
      + " tile: [" + tile.x + ", " + tile.y + "]"
      + " zoom: " + (int) (Game.getCamera().getRenderScale() * 100) + " %", 10, Game.getScreenManager().getResolution().getHeight() - 40);
  RenderEngine.drawText(g, Game.getMetrics().getFramesPerSecond() + " FPS", 10, Game.getScreenManager().getResolution().getHeight() - 20);

  // render status
  if (this.currentStatus != null && !this.currentStatus.isEmpty()) {
    long deltaTime = Game.getLoop().getDeltaTime(this.statusTick);
    if (deltaTime > STATUS_DURATION) {
      this.currentStatus = null;
    }

    // fade out status color
    final double fadeOutTime = 0.75 * STATUS_DURATION;
    if (deltaTime > fadeOutTime) {
      double fade = deltaTime - fadeOutTime;
      int alpha = (int) (255 - (fade / (STATUS_DURATION - fadeOutTime)) * 255);
      g.setColor(new Color(255, 255, 255, MathUtilities.clamp(alpha, 0, 255)));
    }

    Font old = g.getFont();
    g.setFont(g.getFont().deriveFont(20.0f));
    RenderEngine.drawText(g, this.currentStatus, 10, Game.getScreenManager().getResolution().getHeight() - 60);
    g.setFont(old);
  }
}
 
Example 10
Project: litiengine   File: SpeechBubble.java   View Source Code Vote up 4 votes
private void createBubbleImage() {

    final BufferedImage img = ImageProcessing.getCompatibleImage(500, 500);
    final Graphics2D g = img.createGraphics();
    g.setFont(this.font);
    final int stringWidth = g.getFontMetrics().stringWidth(this.currentText);
    if (stringWidth < this.textBoxWidth) {
      this.textBoxWidth = stringWidth;
    }

    final FontRenderContext frc = g.getFontRenderContext();
    final AttributedString styledText = new AttributedString(this.currentText);
    styledText.addAttribute(TextAttribute.FONT, this.font);
    final AttributedCharacterIterator iterator = styledText.getIterator();
    final LineBreakMeasurer measurer = new LineBreakMeasurer(iterator, frc);
    measurer.setPosition(0);
    float y = 0;
    while (measurer.getPosition() < this.currentText.length()) {
      final TextLayout layout = measurer.nextLayout(this.textBoxWidth);
      y += layout.getAscent() + layout.getLeading() + 0.2;
    }

    final RoundRectangle2D bounds = new RoundRectangle2D.Double(0, 0, this.textBoxWidth + 2 * PADDING, y + 2 * PADDING, PADDING, PADDING);

    // Build a path
    final GeneralPath path = new GeneralPath();
    path.moveTo(bounds.getWidth() / 2.0 - TRIANGLE_SIZE / 2.0, bounds.getHeight());
    path.lineTo(bounds.getWidth() / 2.0, bounds.getHeight() + TRIANGLE_SIZE);
    path.lineTo(bounds.getWidth() / 2.0 + TRIANGLE_SIZE / 2.0, bounds.getHeight());
    path.closePath();

    final Area ar = new Area(bounds);
    ar.add(new Area(path));

    int width = ar.getBounds().width;
    this.height = ar.getBounds().height;
    g.setColor(SPEAK_BACKGROUNDCOLOR);
    g.fill(ar);

    g.setColor(SPEAK_BORDERCOLOR);
    g.draw(ar);
    g.dispose();

    this.bubble = ImageProcessing.crop(img, ImageProcessing.CROP_ALIGN_LEFT, ImageProcessing.CROP_VALIGN_TOP, width + 1, this.height + 1);
  }
 
Example 11
Project: parabuild-ci   File: DialValueIndicator.java   View Source Code Vote up 4 votes
/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been 
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted). 
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, 
            this.radius);
    Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();
    
    // calculate the bounds of the template value
    FontMetrics fm = g2.getFontMetrics(this.font);
    String s = this.formatter.format(this.templateValue);
    Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);

    // align this rectangle to the frameAnchor
    Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(
            tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(), 
            this.frameAnchor);
    
    // add the insets
    Rectangle2D fb = this.insets.createOutsetRectangle(bounds);

    // draw the background
    g2.setPaint(this.backgroundPaint);
    g2.fill(fb);

    // draw the border
    g2.setStroke(this.outlineStroke);
    g2.setPaint(this.outlinePaint);
    g2.draw(fb);
    
    
    // now find the text anchor point
    double value = plot.getValue(this.datasetIndex);
    String valueStr = this.formatter.format(value);
    Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor);
    g2.setPaint(this.paint);
    g2.setFont(this.font);
    TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), 
            (float) pt2.getY(), this.textAnchor);
    
}
 
Example 12
Project: parabuild-ci   File: TextTitle.java   View Source Code Vote up 4 votes
/**
 * Draws a the title horizontally within the specified area.  This method will be called
 * from the {@link #draw(Graphics2D, Rectangle2D) draw} method.
 * 
 * @param g2  the graphics device.
 * @param area  the area for the title.
 */
protected void drawHorizontal(Graphics2D g2, Rectangle2D area) {
    Rectangle2D titleArea = (Rectangle2D) area.clone();
    getSpacer().trim(titleArea);
    g2.setFont(this.font);
    g2.setPaint(this.paint);
    TextBlock title = TextUtilities.createTextBlock(
        this.text, this.font, this.paint, (float) titleArea.getWidth(), new G2TextMeasurer(g2)
    );
    TextBlockAnchor anchor = null;
    float x = 0.0f;
    HorizontalAlignment horizontalAlignment = getHorizontalAlignment();
    if (horizontalAlignment == HorizontalAlignment.LEFT) {
        x = (float) titleArea.getX();
        anchor = TextBlockAnchor.TOP_LEFT;
    }
    else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
        x = (float) titleArea.getMaxX();
        anchor = TextBlockAnchor.TOP_RIGHT;
    }
    else if (horizontalAlignment == HorizontalAlignment.CENTER) {
        x = (float) titleArea.getCenterX();
        anchor = TextBlockAnchor.TOP_CENTER;
    }
    float y = 0.0f;
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.TOP) {
        y = (float) titleArea.getY();
    }
    else if (position == RectangleEdge.BOTTOM) {
        y = (float) titleArea.getMaxY();
        if (horizontalAlignment == HorizontalAlignment.LEFT) {
            anchor = TextBlockAnchor.BOTTOM_LEFT;
        }
        else if (horizontalAlignment == HorizontalAlignment.CENTER) {
            anchor = TextBlockAnchor.BOTTOM_CENTER;
        }
        else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
            anchor = TextBlockAnchor.BOTTOM_RIGHT;
        }
    }
    title.draw(g2, x, y, anchor);
}
 
Example 13
Project: QN-ACTR-Release   File: PainterConvex2D.java   View Source Code Vote up 4 votes
/**
 * When is select a Dominat point is draw an arrow from the dominant
 * @param g The graphic object
 * @param dominant The vector with the dominant points
 * @param dominates The vector with the dominates points
 */
public void drawDominantArrow(Graphics2D g, Vector<Point2D> dominant, Vector<Point2D> dominates) {
	DPoint p;
	DPoint p2;
	boolean first = true;

	for (int i = 0; i < dominates.size(); i++) {
		p = (DPoint) dominates.get(i);
		if (p.isSelect()) {
			for (int k = dominant.size() - 1; k >= 0; k--) {
				p2 = (DPoint) dominant.get(k);
				if (p2.isSelect()) {

					g.setColor(Color.magenta);
					//Draw Arrow

					//The angle is calculete throw the rotator point
					DPoint rotator = new DPoint(p2.getX() - p.getX(), p2.getY() - p.getY());
					double angle = rotator.polarAngle();
					//The thestination point in not into the point but near the point
					int xPoint = (int) (p.getX() * scale) + tran_x + (int) (pointSize * Math.cos(angle));
					int yPoint = tran_y - (int) (p.getY() * scale) - (int) (pointSize * Math.sin(angle));

					g.drawLine(xPoint, yPoint, (int) (p2.getX() * scale) + tran_x, tran_y - (int) (p2.getY() * scale));
					//The rotation turn the arrow in the right position
					g.rotate(-angle, xPoint, yPoint);

					g.drawLine(xPoint, yPoint, xPoint + 4 + pointSize, yPoint - pointSize);
					g.drawLine(xPoint, yPoint, xPoint + 4 + pointSize, yPoint + pointSize);

					g.rotate((2 * Math.PI) + angle, xPoint, yPoint);

					//Draw Label on the first arrow (only)
					if (first) {
						first = false;

						g.setColor(new Color(152, 61, 168));
						int fontSize = 7 + pointSize;
						Font f = new Font("Arial", Font.PLAIN, fontSize);
						g.setFont(f);

						double x = (p.getX() + p2.getX()) / 2;
						double y = (p.getY() + p2.getY()) / 2;

						g.drawString("Dominating", (int) (x * scale) + tran_x + 7, tran_y - 3 - (int) (y * scale));
					}
				}
			}
		}
	}
}
 
Example 14
Project: QN-ACTR-Release   File: PainterConvex2D.java   View Source Code Vote up 4 votes
/**
 * It draws the axis of the graph
 * @param g The graphic object
 * @param className The name of the classes
 */
public void axis(Graphics2D g, String[] className) {
	g.setColor(Color.black);
	//Axis
	g.drawLine(tran_x, tran_y, tran_x, fromBorderY);
	g.drawLine(tran_x, tran_y, width - fromBorderX, tran_y);
	//Arrows Y
	g.drawLine(tran_x - 4, fromBorderY + 8, tran_x, fromBorderY);
	g.drawLine(tran_x + 4, fromBorderY + 8, tran_x, fromBorderY);
	//Arrows X
	g.drawLine(width - fromBorderX - 8, tran_y - 4, width - fromBorderX, tran_y);
	g.drawLine(width - fromBorderX - 8, tran_y + 4, width - fromBorderX, tran_y);

	Font label = new Font("Arial", Font.PLAIN, 9 + pointSize);
	g.setFont(label);
	//Label Y
	g.drawString(className[0], tran_x - 15, fromBorderY - 8);
	//Label X 
	g.drawString(className[1], width - Math.max(fromBorderX, (int) (className[1].length() * (9 + pointSize) * 0.58)), height - (pointSize));

	//Insert the line on the axis
	for (int i = 1; i < 11; i++) {
		g.drawLine(tran_x + (int) (((maxValue / 10) * i) * scale), tran_y, tran_x + (int) (((maxValue / 10) * i) * scale), tran_y + 2);
		g.drawLine(tran_x, tran_y - (int) (((maxValue / 10) * i) * scale), tran_x - 2, tran_y - (int) (((maxValue / 10) * i) * scale));
	}

	//Setting the Font
	int fontSize = 8 + pointSize;
	Font f = new Font("Arial", Font.PLAIN, fontSize);
	g.setFont(f);

	//Insert the number on the axis X
	for (int i = 1; i < 11; i++) {
		g.drawString("" + (int) (((maxValue / 10) * i)), tran_x + (int) (((maxValue / 10) * i) * scale) - 7, tran_y + 3 + fontSize);
	}

	for (int i = 1; i < 11; i++) {
		int translationt = ((("" + maxValue).length()) - ((("" + ((int) (((maxValue / 10) * i)))).length()))) - 1;
		g.drawString("" + (int) (((maxValue / 10) * i)), (translationt * (fontSize / 2)) - 3, tran_y + 3 - (int) (((maxValue / 10) * i) * scale));
	}

	//Insert 0
	g.drawString("0", tran_x - pointSize - 5, tran_y + pointSize + 5);
}
 
Example 15
Project: open-rmbt   File: ImageExport.java   View Source Code Vote up 4 votes
@Override
public BufferedImage generateImage(String lang, double upload, double download, double ping, String isp, String typ, String signal, String os) throws IOException {
    String unknownString = (lang.equals("de")) ? "unbekannt" : "unknown";
    BufferedImage img = new BufferedImage(390, 130, BufferedImage.TYPE_INT_ARGB);  
    img.createGraphics();  
    Graphics2D g = (Graphics2D)img.getGraphics(); 
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    BufferedImage img2 = ImageIO.read(getClass().getResourceAsStream("forumsmall_" + lang + ".png"));
    g.drawImage(img2, null, 0, 0);
    
    //Speeds
    g.setColor(Color.black);
    g.setFont(new Font("Droid Sans", Font.BOLD, 40));
    drawCenteredString(formatNumber(download, lang), 0, 20,130,65,g);
    drawCenteredString(formatNumber(upload, lang), 130, 20,130,65,g);
    drawCenteredString(formatNumber(ping, lang), 260, 20,130,65,g);


    //ISP and other information
    g.setColor(Color.WHITE);
    g.setFont(new Font("Verdana", Font.BOLD,10));

    //de
    if (lang.equals("de")) {
        //left
        g.drawString((typ == null)?unknownString:typ, 73, 109);
        g.drawString((isp == null)?unknownString:isp, 73, 124);

        //right
        g.drawString((signal==null)?"":signal + " dBm", 270, 109);
        g.drawString((os==null)?unknownString:os, 270, 124);
        
        //hide signal caption if signal is null
        if (signal==null) {
        	g.setColor(new Color(89,178,0));
        	g.fillRect(195, 98, 71, 13);
        	
        }
        
    } 
    else { //en
        //left
        g.drawString((typ == null)?unknownString:typ, 83, 109);
        g.drawString((isp == null)?unknownString:isp, 60, 124);

        //right
        g.drawString((signal==null)?"":signal + " dBm", 290, 109);
        g.drawString((os==null)?unknownString:os, 290, 124);
        
        //hide signal caption if signal is null
        if (signal==null) {
        	g.setColor(new Color(89,178,0));
        	g.fillRect(195, 98, 90, 13);
        	
        }
    }
    
    g.dispose();
    
    return img;
}
 
Example 16
Project: spacesettlers   File: BaseGraphics.java   View Source Code Vote up 4 votes
@Override
public void draw(Graphics2D graphics) {
	float radius = Base.BASE_RADIUS;
	float diameter = Base.BASE_RADIUS * 2;

	// change the base's transparency based upon the energy level
	int alpha =  (int) (((float) base.getEnergy() / base.getMaxEnergy()) * 255.0);
	Color energyColor = new Color(teamColor.getRed(), teamColor.getGreen(), teamColor.getBlue(), alpha);
	graphics.setColor(energyColor);
	
	graphics.fillOval((int)(drawLocation.getX() - radius), (int)(drawLocation.getY() - radius), 
				(int)diameter, (int)diameter);
	
	// draw an outline around the base (in case its healing energy goes to 0)
       final Ellipse2D.Double shape = new Ellipse2D.Double(drawLocation.getX() - radius,
       		drawLocation.getY() - radius, diameter, diameter);
       graphics.setStroke(JSpaceSettlersComponent.STROKE);
	Color outlineColor = new Color(teamColor.getRed(), teamColor.getGreen(), teamColor.getBlue());
   	graphics.setColor(outlineColor);
       graphics.draw(shape);

	// if the base is shielded, put a white circle around the outside
       if (base.isShielded()) {
        double shieldRadius = radius + 8;
        final Ellipse2D.Double shieldShape = new Ellipse2D.Double(drawLocation.getX() - shieldRadius,
        		drawLocation.getY() - shieldRadius, 2 * shieldRadius, 2 * shieldRadius);
        graphics.setStroke(JSpaceSettlersComponent.THIN_STROKE);
    	graphics.setColor(BASE_SHIELD_COLOR);
        graphics.draw(shieldShape);
       }
       
	// show the healing energy level of the base
	final Font font = new Font("Arial", Font.BOLD, 12);
	graphics.setFont(font);

	String number = Integer.toString(base.getHealingEnergy());
	graphics.setPaint(JSpaceSettlersComponent.TEXT_COLOR);
	graphics.drawString(number, (int) drawLocation.getX() + 12, (int) drawLocation.getY() + 12);
	
	// show the resourcesAvailable collected by the team at this base
	//number = Integer.toString(base.getMoney());
	//graphics.setPaint(JSpaceSettlersComponent.TEXT_COLOR);
	//graphics.drawString(number, (int) drawLocation.getX() + 12, (int) drawLocation.getY() - 12);
	
	// if it is a home base, put a H inside it
	if (base.isHomeBase()) {
		graphics.setPaint(Color.BLACK);
		graphics.drawString("H", (int) drawLocation.getX()-4, (int) drawLocation.getY() + 4);
	}
	
	
}
 
Example 17
Project: parabuild-ci   File: StandardLegend.java   View Source Code Vote up 4 votes
/**
 * Draws the series elements.
 * 
 * @param g2  the graphics device.
 * @param items  the items.
 * @param translation  the translation point.
 * @param info  optional carrier for rendering info.
 */
private void drawSeriesElements(Graphics2D g2, List items, Point2D translation, 
                                ChartRenderingInfo info) {
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getEntityCollection();
    }
    // Draw individual series elements
    for (int i = 0; i < items.size(); i++) {
        DrawableLegendItem item = (DrawableLegendItem) items.get(i);
        g2.setPaint(item.getItem().getPaint());
        Shape keyBox = item.getMarker();
        if (this.displaySeriesLines) {
            g2.setStroke(item.getLineStroke());
            g2.draw(item.getLine());

            if (this.displaySeriesShapes) {
                if (item.isMarkerFilled()) {
                    g2.fill(keyBox);
                }
                else {
                    g2.draw(keyBox);
                }
            }
        } 
        else {
            if (item.isMarkerFilled()) {
                g2.fill(keyBox);
            }
            else {
                g2.draw(keyBox);
            }
        }
        if (getOutlineShapes()) {
            g2.setPaint(this.shapeOutlinePaint);
            g2.setStroke(this.shapeOutlineStroke);
            g2.draw(keyBox);
        }
        g2.setPaint(this.itemPaint);
        g2.setFont(this.itemFont);
        TextUtilities.drawAlignedString(
            item.getItem().getLabel(), g2,
            (float) item.getLabelPosition().getX(), (float) item.getLabelPosition().getY(),
            TextAnchor.CENTER_LEFT
        );
        LOGGER.debug("Item x = " + item.getLabelPosition().getX());
        LOGGER.debug("Item y = " + item.getLabelPosition().getY());

        if (entities != null) {
            Rectangle2D area = new Rectangle2D.Double(
                translation.getX() + item.getX(),
                translation.getY() + item.getY(),
                item.getWidth(), item.getHeight()
            );
            LegendItemEntity entity = new LegendItemEntity(area);
            entity.setSeriesIndex(i);
            entities.addEntity(entity);
        }
    }
}
 
Example 18
Project: incubator-netbeans   File: CoverageBar.java   View Source Code Vote up 4 votes
@Override
protected void paintComponent(Graphics g) {

    if (!(g instanceof Graphics2D)) {
        return;
    }

    int width = getWidth();
    int barRectWidth = width;
    int height = getHeight();
    int barRectHeight = height;

    if (barRectWidth <= 0 || barRectHeight <= 0) {
        return;
    }

    int amountFull = (int) (barRectWidth * coveragePercentage / 100.0f);

    Graphics2D g2 = (Graphics2D) g;

    g2.setColor(getBackground());

    Color notCoveredLight = NOT_COVERED_LIGHT;
    Color notCoveredDark = NOT_COVERED_DARK;
    Color coveredLight = COVERED_LIGHT;
    Color coveredDark = COVERED_DARK;
    if (emphasize) {
        coveredDark = coveredDark.darker();
    } else if (selected) {
        coveredLight = coveredLight.brighter();
        coveredDark = coveredDark.darker();
    }
    if (emphasize) {
        notCoveredDark = notCoveredDark.darker();
    } else if (selected) {
        notCoveredLight = notCoveredLight.brighter();
        notCoveredDark = notCoveredDark.darker();
    }

    g2.setPaint(new GradientPaint(0, 0, notCoveredLight,
            0, height / 2, notCoveredDark));
    g2.fillRect(amountFull, 1, width - 1, height / 2);
    g2.setPaint(new GradientPaint(0, height / 2, notCoveredDark,
            0, 2 * height, notCoveredLight));
    g2.fillRect(amountFull, height / 2, width - 1, height / 2);

    g2.setColor(getForeground());

    g2.setPaint(new GradientPaint(0, 0, coveredLight,
            0, height / 2, coveredDark));
    g2.fillRect(1, 1, amountFull, height / 2);
    g2.setPaint(new GradientPaint(0, height / 2, coveredDark,
            0, 2 * height, coveredLight));
    g2.fillRect(1, height / 2, amountFull, height / 2);

    Rectangle oldClip = g2.getClipBounds();
    if (coveragePercentage > 0.0f) {
        g2.setColor(coveredDark);
        g2.clipRect(0, 0, amountFull + 1, height);
        g2.drawRect(0, 0, width - 1, height - 1);
    }
    if (coveragePercentage < 100.0f) {
        g2.setColor(notCoveredDark);
        g2.setClip(oldClip);
        g2.clipRect(amountFull, 0, width, height);
        g2.drawRect(0, 0, width - 1, height - 1);
    }
    g2.setClip(oldClip);

    g2.setFont(getFont());
    paintDropShadowText(g2, barRectWidth, barRectHeight);
}
 
Example 19
Project: Pogamut3   File: PoshWidget.java   View Source Code Vote up 4 votes
@Override
protected void paintWidget() {
    Graphics2D g = getGraphics();

    // draw rectanlge
    g.setColor(getType().getColor());
    g.fillRect(0, 0, width, height);


    int collapseWidth = 0;
    // draw collapse block
    if (!getChildNodes().isEmpty()) {
        collapseWidth = arrowWidth;
        g.setColor(getType().getColor().darker());

        if (isCollapsed()) {
            g.fillPolygon(
                    new int[]{width - arrowWidth, width, width - arrowWidth},
                    new int[]{0, height / 2, height},
                    3);
        } else {
            g.fillPolygon(
                    new int[]{width, width - arrowWidth, width},
                    new int[]{0, height / 2, height},
                    3);
        }
    }
    g.setColor(Color.BLACK);
    int xofs = 4;

    int maxTextWidth = width - xofs - collapseWidth;
    // draw headline text
    FontMetrics boldMetrics = g.getFontMetrics(boldFont);
    String renderedHeadlineString = getFittingString(getHeadlineText(), boldMetrics, maxTextWidth);

    g.setFont(boldFont);
    g.drawString(renderedHeadlineString, xofs, boldMetrics.getHeight());

    // draw comment string
    FontMetrics italicMetrics = g.getFontMetrics(italicFont);
    String renderCommentString = getFittingString(getCommentText(), italicMetrics, maxTextWidth);

    g.setFont(italicFont);
    g.drawString(renderCommentString, xofs, boldMetrics.getHeight() + italicMetrics.getHeight());
}
 
Example 20
Project: parabuild-ci   File: LabelBlock.java   View Source Code Vote up 3 votes
/**
 * Arranges the contents of the block, within the given constraints, and 
 * returns the block size.
 * 
 * @param g2  the graphics device.
 * @param constraint  the constraint (<code>null</code> not permitted).
 * 
 * @return The block size (in Java2D units, never <code>null</code>).
 */
public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) {
    g2.setFont(this.font);
    Size2D s = this.label.calculateDimensions(g2);
    return new Size2D(calculateTotalWidth(s.getWidth()), 
            calculateTotalHeight(s.getHeight()));
}