List of usage examples for java.awt Graphics2D drawString
public abstract void drawString(AttributedCharacterIterator iterator, float x, float y);
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
protected void paintAnnotations(Graphics2D g2d) { DecimalFormat mz_df = new DecimalFormat("0.0"); // set font//w ww . j ava2 s . co m Font old_font = g2d.getFont(); Font new_font = new Font(theOptions.ANNOTATION_MZ_FONT, Font.PLAIN, theOptions.ANNOTATION_MZ_SIZE); // compute bboxes PositionManager pman = new PositionManager(); BBoxManager bbman = new BBoxManager(); computeRectangles(pman, bbman); // compute connections computeConnections(); // paint connections for (AnnotationObject a : theDocument.getAnnotations()) { boolean selected = !is_printing && selections.contains(a); // paint arrow Polygon connection = connections.get(a); if (connection != null) { g2d.setColor(theOptions.CONNECTION_LINES_COLOR); g2d.setStroke((selected) ? new BasicStroke((float) (1. + theOptions.ANNOTATION_LINE_WIDTH)) : new BasicStroke((float) theOptions.ANNOTATION_LINE_WIDTH)); g2d.draw(connection); g2d.setStroke(new BasicStroke(1)); } // paint control point if (selected) { g2d.setColor(Color.black); Point2D cp = connections_cp.get(a); if (cp != null) { int s = (int) (2 + theOptions.ANNOTATION_LINE_WIDTH); g2d.fill(new Rectangle((int) cp.getX() - s, (int) cp.getY() - s, 2 * s, 2 * s)); } } } // paint glycans for (AnnotationObject a : theDocument.getAnnotations()) { boolean highlighted = a.isHighlighted(); boolean selected = !is_printing && selections.contains(a); // set scale theGlycanRenderer.getGraphicOptions().setScale(theOptions.SCALE_GLYCANS * theDocument.getScale(a)); // paint highlighted region if (highlighted) { Rectangle c_bbox = rectangles_complete.get(a); g2d.setColor(theOptions.HIGHLIGHTED_COLOR); g2d.setXORMode(Color.white); g2d.fill(c_bbox); g2d.setPaintMode(); g2d.setColor(Color.black); g2d.draw(c_bbox); } // paint glycan for (Glycan s : a.getStructures()) theGlycanRenderer.paint(g2d, s, null, null, false, false, pman, bbman); // paint MZ text g2d.setFont(new_font); g2d.setColor(theOptions.MASS_TEXT_COLOR); String mz_text = mz_df.format(a.getPeakPoint().getX()); Rectangle mz_bbox = rectangles_text.get(a); g2d.drawString(mz_text, mz_bbox.x, mz_bbox.y + mz_bbox.height); // paint selection if (selected) { // paint rectangle Rectangle c_bbox = rectangles_complete.get(a); g2d.setStroke(new BasicStroke(highlighted ? 2 : 1)); g2d.setColor(Color.black); g2d.draw(c_bbox); g2d.setStroke(new BasicStroke(1)); // paint resize points Polygon p1 = new Polygon(); int cx1 = right(c_bbox); int cy1 = top(c_bbox); p1.addPoint(cx1, cy1); p1.addPoint(cx1 - 2 * theOptions.ANNOTATION_MARGIN / 3, cy1); p1.addPoint(cx1, cy1 + 2 * theOptions.ANNOTATION_MARGIN / 3); g2d.fill(p1); Polygon p2 = new Polygon(); int cx2 = left(c_bbox); int cy2 = top(c_bbox); p2.addPoint(cx2, cy2); p2.addPoint(cx2 + 2 * theOptions.ANNOTATION_MARGIN / 3, cy2); p2.addPoint(cx2, cy2 + 2 * theOptions.ANNOTATION_MARGIN / 3); g2d.fill(p2); } } g2d.setFont(old_font); }
From source file:spinworld.gui.RadarPlot.java
private void drawTickLabel(Graphics2D g2, Rectangle2D radarArea, Point2D middlePoint, double _axisAngle, int cat, double tick) { double axisAngle = normalize(_axisAngle); double _origin = getOrigin(cat).doubleValue(); double max = getMaxValue(cat).doubleValue(); double tickValue = ((max - _origin) * tick) + _origin; String label = "" + Math.round(tickValue * 1000) / 1000d; FontRenderContext frc = g2.getFontRenderContext(); Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc); int labelW = (int) labelBounds.getWidth(); int labelH = (int) labelBounds.getHeight(); double centerX = radarArea.getCenterX(); double centerY = radarArea.getCenterY(); double adj = middlePoint.distance(centerX, centerY); double opp = TICK_MARK_LENGTH / 2 + 4; double hyp = Math.sqrt(Math.pow(opp, 2) + Math.pow(adj, 2)); double angle = Math.toDegrees(Math.atan(opp / adj)); int charHeight = g2.getFontMetrics().getHeight(); int charWidth = g2.getFontMetrics().charWidth('M'); double alphaRad = Math.toRadians(axisAngle - angle); double labelX = centerX + (hyp * Math.cos(alphaRad)); double labelY = centerY - (hyp * Math.sin(alphaRad)) + labelH; // g2.draw(new Line2D.Double(centerX, centerY, labelX, labelY - labelH)); // test line double sinGap = Math.pow(Math.sin(Math.toRadians(axisAngle)), 2); if (axisAngle > 90 && axisAngle < 270) { labelY -= labelH;/* w ww . j av a 2 s . co m*/ labelY += (charHeight * sinGap / 2); } else { labelY -= (charHeight * sinGap / 2); } double cosGap = Math.pow(Math.cos(Math.toRadians(axisAngle)), 2); if (axisAngle > 180) { labelX -= labelW; labelX += (charWidth * cosGap / 2); } else { labelX -= (charWidth * cosGap / 2); } // g2.drawRect((int) labelX, (int) labelY - labelH, labelW, labelH); // test rectangle g2.setPaint(getLabelPaint()); g2.setFont(getLabelFont()); g2.drawString(label, (float) labelX, (float) labelY); }
From source file:org.ietr.preesm.mapper.ui.MyGanttRenderer.java
/** * Draws the tasks/subtasks for one item. * /* w w w . j ava 2s.co m*/ * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the data plot area. * @param plot * the plot. * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param dataset * the data. * @param row * the row index (zero-based). * @param column * the column index (zero-based). */ @Override protected void drawTasks(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, GanttCategoryDataset dataset, int row, int column) { int count = dataset.getSubIntervalCount(row, column); if (count == 0) { drawTask(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column); } for (int subinterval = 0; subinterval < count; subinterval++) { RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); // value 0 Number value0 = dataset.getStartValue(row, column, subinterval); if (value0 == null) { return; } double translatedValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation); // value 1 Number value1 = dataset.getEndValue(row, column, subinterval); if (value1 == null) { return; } double translatedValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation); if (translatedValue1 < translatedValue0) { double temp = translatedValue1; translatedValue1 = translatedValue0; translatedValue0 = temp; } double rectStart = calculateBarW0(plot, plot.getOrientation(), dataArea, domainAxis, state, row, column); double rectLength = Math.abs(translatedValue1 - translatedValue0); double rectBreadth = state.getBarWidth(); // DRAW THE BARS... RoundRectangle2D bar = null; bar = new RoundRectangle2D.Double(translatedValue0, rectStart, rectLength, rectBreadth, 10.0, 10.0); /* Paint seriesPaint = */getItemPaint(row, column); if (((TaskSeriesCollection) dataset).getSeriesCount() > 0) if (((TaskSeriesCollection) dataset).getSeries(0).getItemCount() > column) if (((TaskSeriesCollection) dataset).getSeries(0).get(column).getSubtaskCount() > subinterval) { g2.setPaint(getRandomBrightColor(((TaskSeriesCollection) dataset).getSeries(0).get(column) .getSubtask(subinterval).getDescription())); } g2.fill(bar); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); } // Displaying the tooltip inside the bar if enough space is // available if (getToolTipGenerator(row, column) != null) { // Getting the string to display String tip = getToolTipGenerator(row, column).generateToolTip(dataset, subinterval, column); // Truncting the string if it is too long String subtip = ""; if (rectLength > 0) { double percent = (g2.getFontMetrics().getStringBounds(tip, g2).getWidth() + 10) / rectLength; if (percent > 1.0) { subtip = tip.substring(0, (int) (tip.length() / percent)); } else if (percent > 0) { subtip = tip; } // Setting font and color Font font = new Font("Garamond", Font.BOLD, 12); g2.setFont(font); g2.setColor(Color.WHITE); // Testing width and displaying if (!subtip.isEmpty()) { g2.drawString(subtip, (int) translatedValue0 + 5, (int) rectStart + g2.getFontMetrics().getHeight()); } } } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; if (getToolTipGenerator(row, column) != null) { tip = getToolTipGenerator(row, column).generateToolTip(dataset, subinterval, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } } }
From source file:com.aerohive.nms.web.config.lbs.services.HmFolderServiceImpl.java
private BufferedImage createFloorImage(HmFolder floor, double scale, int floorWidth, int floorHeight, Map<Long, Integer> channelMap, Map<Long, Integer> colorMap, int borderX, int borderY, double gridSize) throws Exception { BufferedImage image = new BufferedImage(floorWidth + borderX + 1, floorHeight + borderY + 1, BufferedImage.TYPE_INT_ARGB); if (floor == null) { return image; }//w w w . j ava2 s. c om double metricWidth = 0.0, metricHeight = 0.0, offsetX = 0.0, offsetY = 0.0; int imageWidth = 0; LengthUnit lengthUnit = LengthUnit.METERS; if (null != floor.getMetricWidth()) { metricWidth = floor.getMetricWidth().doubleValue(); } if (null != floor.getMetricHeight()) { metricHeight = floor.getMetricHeight().doubleValue(); } if (null != floor.getImageWidth()) { imageWidth = floor.getImageWidth().intValue(); } if (null != floor.getOffsetX()) { offsetX = floor.getOffsetX().doubleValue(); } if (null != floor.getOffsetY()) { offsetY = floor.getOffsetY().doubleValue(); } if (null != floor.getLengthUnit()) { lengthUnit = floor.getLengthUnit(); } Graphics2D g2 = image.createGraphics(); g2.setStroke(new BasicStroke(1)); if (getDistanceMetric(metricWidth, lengthUnit) == 0) { g2.setColor(new Color(255, 255, 255)); g2.fillRect(borderX, 0, floorWidth + 1, borderY); g2.fillRect(0, 0, borderX, borderY + floorHeight + 1); g2.setColor(new Color(120, 120, 120)); g2.drawLine(0, borderY, floorWidth + borderX, borderY); g2.drawLine(borderX, 0, borderX, floorHeight + borderY); g2.setColor(new Color(255, 255, 204)); g2.fillRect(borderX + 2, borderY + 2, 162, 25); g2.setColor(new Color(0, 51, 102)); g2.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 12)); g2.drawString("Please size this floor plan.", borderX + 8, borderY + 19); return image; } double screenWidth = scale * getDistanceMetric(metricWidth, lengthUnit); double imageScale = screenWidth / imageWidth; int originX = (int) (getDistanceMetric(offsetX, lengthUnit) * scale); int originY = (int) (getDistanceMetric(offsetY, lengthUnit) * scale); g2.setColor(new Color(255, 255, 255)); if (floor.getBackground() != null && floor.getBackground().length() > 0) { LinkedMultiValueMap<String, String> metadata = new LinkedMultiValueMap<>(); String url = getImageBaseUrl(floor.getOwnerId()) + floor.getBackground(); try { BufferedImage map = ImageIO.read(clientFileService.getFile(url, "AFS_TOKEN", metadata)); AffineTransform transform = new AffineTransform(); transform.scale(imageScale, imageScale); g2.drawImage(map, new AffineTransformOp(transform, null), getFloorX(0, borderX, originX), getFloorY(0, borderY, originY)); } catch (Exception e) { logger.error(String.format("image file not found with url: %s", url)); double screenHeight = scale * getDistanceMetric(metricHeight, lengthUnit); g2.fillRect(getFloorX(0, borderX, originX), getFloorY(0, borderY, originY), (int) screenWidth, (int) screenHeight); } } else { double screenHeight = scale * getDistanceMetric(metricHeight, lengthUnit); g2.fillRect(getFloorX(0, borderX, originX), getFloorY(0, borderY, originY), (int) screenWidth, (int) screenHeight); } g2.setColor(new Color(204, 204, 204)); // Right edge border g2.drawLine(borderX + floorWidth, borderY + 1, borderX + floorWidth, borderY + floorHeight); // Left edge border (right of tick marks) g2.drawLine(borderX + 1, borderY + floorHeight, borderX + floorWidth, borderY + floorHeight); g2.setColor(new Color(255, 255, 255)); g2.fillRect(borderX, 0, floorWidth + 1, borderY); g2.fillRect(0, 0, borderX, borderY + floorHeight + 1); g2.setColor(new Color(120, 120, 120)); g2.drawLine(0, borderY, floorWidth + borderX, borderY); g2.drawLine(borderX, 0, borderX, floorHeight + borderY); Font font = new Font(Font.SANS_SERIF, Font.BOLD, 12); double actualWidth = floorWidth / scale; double actualHeight = floorHeight / scale; String firstLabel; double unitScale = scale; if (LengthUnit.FEET == lengthUnit) { firstLabel = "0 feet"; actualWidth /= HmFolder.FEET_TO_METERS; actualHeight /= HmFolder.FEET_TO_METERS; unitScale *= HmFolder.FEET_TO_METERS; } else { firstLabel = "0 meters"; } g2.drawString(firstLabel, borderX + 4, 12); double gridX = gridSize; while (gridX < actualWidth) { int x = (int) (gridX * unitScale) + borderX; g2.drawLine(x, 0, x, borderY); boolean label = true; if (gridX + gridSize >= actualWidth) { // Last mark if (x + getNumberPixelWidth(gridX) + 2 > floorWidth) { label = false; } } if (label) { g2.drawString("" + (int) gridX, x + 4, 12); } gridX += gridSize; } double gridY = 0; while (gridY < actualHeight) { int y = (int) (gridY * unitScale) + borderY; g2.drawLine(0, y, borderX, y); double lx = gridY; int dx = 1; for (int bx = borderX; bx >= 16; bx -= 7) { if (lx < 10) { dx += 7; } else { lx /= 10; } } boolean label = true; if (gridY + gridSize >= actualHeight) { // Last mark if (y - borderY + 13 > floorHeight) { label = false; } } if (label) { g2.drawString("" + (int) gridY, dx, y + 13); } gridY += gridSize; } double mapToImage = getMapToMetric(metricWidth, imageWidth, lengthUnit) * scale; if (floor.getPerimeter().size() > 0) { g2.setStroke(new BasicStroke(2)); g2.setColor(new Color(2, 159, 245)); int[] xPoints = new int[floor.getPerimeter().size()]; int[] yPoints = new int[floor.getPerimeter().size()]; int nPoints = 0; int perimId = floor.getPerimeter().get(0).getId(); for (int i = 0; i < floor.getPerimeter().size(); i++) { HmVertex vertex = floor.getPerimeter().get(i); if (vertex.getId() != perimId) { g2.drawPolygon(xPoints, yPoints, nPoints); nPoints = 0; perimId = vertex.getId(); } xPoints[nPoints] = getFloorX((int) (vertex.getX() * mapToImage), borderX, originX); yPoints[nPoints++] = getFloorY((int) (vertex.getY() * mapToImage), borderY, originY); } g2.drawPolygon(xPoints, yPoints, nPoints); } g2.setStroke(new BasicStroke(1)); g2.setColor(new Color(0, 170, 0)); g2.setFont(font.deriveFont(Font.BOLD, 11)); List<HmDeviceLocationEx> devices = deviceLocationExRep.findAllHmDevices(floor.getId()); if (null != devices && !devices.isEmpty()) { for (HmDeviceLocationEx device : devices) { double x = device.getX() * mapToImage; double y = device.getY() * mapToImage; createNodeImage(device.getId(), channelMap, colorMap, getFloorX((int) x, borderX, originX), getFloorY((int) y, borderY, originY), g2); } } else { List<HmDevicePlanningEx> plannedDevices = devicePlanningExRep.findAllPlannedDevices(floor.getId()); for (HmDevicePlanningEx plannedDevice : plannedDevices) { double x = plannedDevice.getX() * mapToImage; double y = plannedDevice.getY() * mapToImage; createNodeImage(plannedDevice.getId(), channelMap, colorMap, getFloorX((int) x, borderX, originX), getFloorY((int) y, borderY, originY), g2); } } return image; }
From source file:com.aerohive.nms.web.config.lbs.services.HmFolderServiceImpl.java
private void createNodeImage(long id, Map<Long, Integer> channelMap, Map<Long, Integer> colorMap, int x, int y, Graphics2D g2) { Integer channel = channelMap.get(id); Integer colorIndex = colorMap.get(id); int radius = 11; if (channel == null || channel == 0 || colorIndex == null || colorIndex > startChannelColors.length - 1) { g2.setColor(new Color(180, 180, 180)); g2.fillOval(x - radius, y - radius, 2 * radius, 2 * radius); return;//from w ww . j a v a2 s. co m } g2.setColor(startChannelColors[colorIndex]); g2.fillOval(x - radius, y - radius, 2 * radius, 2 * radius); int dy = 6, w = 21; g2.fillRect(x, y - dy, w, dy + dy); dy = 5; g2.setColor(new Color(255, 255, 255)); g2.fillRect(x + 1, y - dy, w - 2, dy + dy); g2.setColor(new Color(0, 51, 102)); int chx = x + 2; if (channel < 100) { chx += 3; } if (channel < 10) { chx += 3; } g2.drawString("" + channel, chx, y + 4); }
From source file:net.geoprism.dashboard.DashboardMap.java
private BufferedImage getLegendTitleImage(DashboardLayer layer) { FontMetrics fm;/* w ww .j a v a 2 s . c o m*/ int textWidth; int textHeight; int textBoxHorizontalPadding = 4; int textBoxVerticalPadding = 4; int borderWidth = 2; int paddedTitleHeight; int paddedTitleWidth; int titleLeftPadding = textBoxHorizontalPadding; BufferedImage newLegendTitleBase; Graphics2D newLegendTitleBaseGraphic = null; try { // Build the Font object Font titleFont = new Font(layer.getName(), Font.BOLD, 14); // Build variables for base legend graphic construction try { newLegendTitleBase = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); newLegendTitleBaseGraphic = newLegendTitleBase.createGraphics(); newLegendTitleBaseGraphic.setFont(titleFont); fm = newLegendTitleBaseGraphic.getFontMetrics(); textHeight = fm.getHeight(); textWidth = fm.stringWidth(layer.getName()); paddedTitleWidth = textWidth + (textBoxHorizontalPadding * 2) + (borderWidth * 2); paddedTitleHeight = textHeight + (textBoxVerticalPadding * 2) + (borderWidth * 2); } finally { // dispose of temporary graphics context if (newLegendTitleBaseGraphic != null) { newLegendTitleBaseGraphic.dispose(); } } titleLeftPadding = ((paddedTitleWidth / 2) - ((textWidth + (textBoxHorizontalPadding * 2) + (borderWidth * 2)) / 2)) + textBoxHorizontalPadding; newLegendTitleBase = new BufferedImage(paddedTitleWidth, paddedTitleHeight, BufferedImage.TYPE_INT_ARGB); newLegendTitleBaseGraphic = newLegendTitleBase.createGraphics(); newLegendTitleBaseGraphic.drawImage(newLegendTitleBase, 0, 0, null); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); newLegendTitleBaseGraphic.setFont(titleFont); // draw title text fm = newLegendTitleBaseGraphic.getFontMetrics(); newLegendTitleBaseGraphic.setColor(Color.WHITE); newLegendTitleBaseGraphic.drawString(layer.getName(), titleLeftPadding, fm.getAscent() + textBoxVerticalPadding); newLegendTitleBaseGraphic.drawImage(newLegendTitleBase, 0, 0, null); } finally { if (newLegendTitleBaseGraphic != null) { newLegendTitleBaseGraphic.dispose(); } } return newLegendTitleBase; }
From source file:net.sf.firemox.clickable.target.card.VirtualCard.java
@SuppressWarnings("null") @Override//from www. j av a 2 s . c o m public void paintComponent(Graphics g) { final Graphics2D g2D = (Graphics2D) g; // Renderer g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // Optimization card painting final MZone container = card.getContainer(); final boolean shortPaint = container == null || !container.isMustBePainted(card); // tap/reverse operation : PI/2, PI, -PI/2 rotation if (!shortPaint) { if (container.isMustBePaintedReversed(card)) { if (card.tapped) { g2D.translate(rotateTransformY, CardFactory.cardWidth + rotateTransformX); g2D.rotate(angle - Math.PI / 2); } else { g2D.translate(CardFactory.cardWidth + rotateTransformX, CardFactory.cardHeight + rotateTransformY); g2D.rotate(Math.PI - angle); } } else { if (card.tapped) { g2D.translate(CardFactory.cardHeight + rotateTransformY, rotateTransformX); g2D.rotate(Math.PI / 2 + angle); } else { g2D.translate(rotateTransformX, rotateTransformY); g2D.rotate(angle); } } } if (container != null) { if (container.isVisibleForOpponent() && !card.isVisibleForOpponent() && card.isVisibleForYou()) { /* * This card is visible for you but not for opponent in despite of the * fact the container is public. */ g2D.drawImage(card.scaledImage(), null, null); g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); g2D.drawImage(DatabaseFactory.scaledBackImage, null, null); } else if (!card.isVisibleForYou()) { g2D.drawImage(DatabaseFactory.scaledBackImage, null, null); } else { g2D.drawImage(card.scaledImage(), null, null); } } if (shortPaint) return; /* * The card picture is displayed as a rounded rectangle with 0,90,180 or * 270 */ if (card.isHighLighted && (card.isVisibleForYou() || StackManager.idHandedPlayer == 0)) { // Draw the rounded colored rectangle g2D.setColor(card.highLightColor); g2D.draw3DRect(0, 0, CardFactory.cardWidth - 2, CardFactory.cardHeight - 2, false); } // Draw the eventual progress bar card.database.updatePaintNotification(card, g); // Cursor for our pretty pictures int px = 3; int py = 3; int maxX = CardFactory.cardWidth - 2; // for in-play, visible cards if (card.isVisibleForYou() || (container != null && container.isVisibleForYou())) { // draw registers above the card's picture if (refreshToolTipFilter().powerANDtoughness) { // power / toughness final String powerANDtoughness = String.valueOf(card.getValue(IdTokens.POWER)) + "/" + card.getValue(IdTokens.TOUGHNESS); g2D.setFont(g2D.getFont().deriveFont(Font.BOLD, 13)); final Rectangle2D stringDim = g2D.getFontMetrics().getStringBounds(powerANDtoughness, g2D); g2D.setColor(CardFactory.powerToughnessColor); g2D.drawString(powerANDtoughness, (int) (CardFactory.cardWidth - stringDim.getWidth() - 3), CardFactory.cardHeight - 5); g2D.setColor(Color.BLUE); g2D.drawString(powerANDtoughness, (int) (CardFactory.cardWidth - stringDim.getWidth() - 3), CardFactory.cardHeight - 6); } /* * START drawing additional pictures */ // draw state pictures for (StatePicture statePicture : CardFactory.statePictures) { if (px + 13 > maxX) { px = 3; py += 13; } if (statePicture.paint(card, g2D, px, py)) { px += 13; } } // draw properties if (card.cachedProperties != null) { for (Integer property : card.cachedProperties) { if (Configuration.getBoolean("card.property.picture", true) && CardFactory.propertyPictures.get(property) != null) { // There is an associated picture to this property if (px + 13 > maxX) { px = 3; py += 13; } g2D.drawImage(CardFactory.propertyPictures.get(property), px, py, 12, 12, null); px += 13; } } } } // draw attached objects int startX = 3; int startY = CardFactory.cardHeight - 18; if (card.registerModifiers != null) { for (int i = card.registerModifiers.length; i-- > 0;) { if (card.registerModifiers[i] != null) { startX = card.registerModifiers[i].paintObject(g, startX, startY); } } } if (card.propertyModifier != null) { startX = card.propertyModifier.paintObject(g, startX, startY); } if (card.idCardModifier != null) { card.idCardModifier.paintObject(g, startX, startY); /* * END drawing additional pictures */ } // Draw the target Id if helper said it final String id = TargetHelper.getInstance().getMyId(card); if (id != null) { if (px + 13 > maxX) { px = 3; py += 13; } if (id == TargetHelper.STR_CONTEXT1) { // TODO I am in the context 1, draw a picture g2D.setColor(Color.BLUE); g2D.setFont(g2D.getFont().deriveFont(Font.BOLD, 60 / id.length())); g2D.drawString(id, 5, CardFactory.cardHeight - 15); } else if (id == TargetHelper.STR_CONTEXT2) { // TODO I am in the context 2, draw a picture g2D.setColor(Color.BLUE); g2D.setFont(g2D.getFont().deriveFont(Font.BOLD, 60 / id.length())); g2D.drawString(id, 5, CardFactory.cardHeight - 15); } else if (id != TargetHelper.STR_SOURCE) { // } else if (id == TargetHelper.STR_SOURCE) { // TODO I am the source, draw a picture // } else { // I am a target g2D.drawImage(TargetHelper.getInstance().getTargetPictureSml(), px, py, null); py += 12; } } g2D.dispose(); }
From source file:org.earthtime.UPb_Redux.dateInterpretation.WeightedMeanGraphPanel.java
private void drawAxesAndTicks(Graphics2D g2d, double rangeX, double rangeY) { // oct 2014 new tic logic // reset the clip bounds to paint axis and numbers g2d.setClip(0, 0, getWidth(), getHeight()); g2d.setFont(new Font("Monospaced", Font.BOLD, 14)); g2d.setPaint(Color.BLACK);/*from ww w. ja v a 2s .c om*/ g2d.setStroke(new BasicStroke(2.0f)); // determine the axis ticks BigDecimal[] tics = TicGeneratorForAxes.generateTics(getMinY_Display(), getMaxY_Display(), 12); // trap for bad plot if (tics.length <= 1) { tics = new BigDecimal[0]; } double minXDisplay = 0.0; int yAxisTicWidth = 8; int yTicLabelFrequency = 2; int labeledTicCountYAxis = 0; g2d.setPaint(Color.black); for (int i = 0; i < tics.length; i++) { double y = tics[i].doubleValue(); if ((y > getMinY_Display()) // dont print across mappedX axis && (y < getMaxY_Display())) // dont print across top border { try { Shape ticMark = new Line2D.Double( // mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth), mapY(y, getMaxY_Display(), rangeY, graphHeight), mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) + 7, mapY(y, getMaxY_Display(), rangeY, graphHeight)); g2d.draw(ticMark); String intString = "00000" + tics[i].toPlainString().replace(".", ""); int lastPlace = Integer.parseInt(intString.substring(intString.length() - 4)); if (lastPlace % yTicLabelFrequency == 0) { if (labeledTicCountYAxis % yTicLabelFrequency == 0) { TextLayout mLayout = // new TextLayout(tics[i].toPlainString(), g2d.getFont(), g2d.getFontRenderContext()); Rectangle2D bounds = mLayout.getBounds(); //if (isyAxisHorizontalTicLabels()) { // g2d.drawString(tics[i].toPlainString(),// // (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, // (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f); // } else { float yLabelCenterOffset = (float) mLayout.getBounds().getWidth() / 2f; g2d.rotate(-Math.PI / 2.0, (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + yLabelCenterOffset); g2d.drawString(tics[i].toPlainString(), (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + yLabelCenterOffset); g2d.rotate(Math.PI / 2.0, (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + yLabelCenterOffset); } labeledTicCountYAxis++; } else { if (labeledTicCountYAxis > 0) { labeledTicCountYAxis++; } } } catch (Exception e) { } } } //// // reset the clip bounds to paint axis and numbers //// g2d.setClip(0, 0, getWidth(), getHeight()); //// //// g2d.setFont(new Font("Monospaced", Font.BOLD, 14)); //// g2d.setPaint(Color.BLACK); //// g2d.setStroke(new BasicStroke(2.0f)); //// //// // determine the axis ticks //// double minYtick = Math.ceil(getMinY_Display() * 100) / 100; //// double maxYtick = Math.floor(getMaxY_Display() * 100) / 100; //// //// int count = 0; //// double deltay = Math.rint((maxYtick - minYtick) * 10 + 0.5); //// double stepYtick = deltay / 100; //// //// for (double y = minYtick; y //// < maxYtick; y //// += stepYtick) { //// Line2D line = new Line2D.Double( //// mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth), //// mapY(y, getMaxY_Display(), rangeY, graphHeight), //// mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) + 7, //// mapY(y, getMaxY_Display(), rangeY, graphHeight)); //// g2d.draw(line); //// //// if ((count % 2) == 1) { //// NumberFormat yFormat = null; //// String temp = null; //// //// yFormat //// = new DecimalFormat("0.00"); //// temp //// = yFormat.format(y); //// //// g2d.setPaint(Color.black); //// g2d.rotate( //// -Math.PI / 2.0, //// (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, //// (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f); //// g2d.drawString( //// temp, //// (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, //// (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f); //// g2d.rotate( //// Math.PI / 2.0, //// (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, //// (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f); //// //// } //// //// count++; //// //// } // draw and label axes g2d.setFont(new Font("Monospaced", Font.BOLD, 20)); g2d.drawRect(getLeftMargin(), getTopMargin(), getGraphWidth() - 1, getGraphHeight() - 1); }
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 av a 2 s. co 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:org.forester.archaeopteryx.TreePanel.java
final private void paintScale(final Graphics2D g, int x1, int y1, final boolean to_pdf, final boolean to_graphics_file) { if (!getControlPanel().isDrawPhylogram() || (getScaleDistance() <= 0.0)) { return;// w w w . j ava2s .co m } x1 += MOVE; final double x2 = x1 + (getScaleDistance() * getXcorrectionFactor()); y1 -= 12; final int y2 = y1 - 8; final int y3 = y1 - 4; g.setFont(getTreeFontSet().getSmallFont()); if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) { g.setColor(Color.BLACK); } else { g.setColor(getTreeColorSet().getBranchLengthColor()); } drawLine(x1, y1, x1, y2, g); drawLine(x2, y1, x2, y2, g); drawLine(x1, y3, x2, y3, g); if (getScaleLabel() != null) { g.drawString(getScaleLabel(), (x1 + 2), y3 - 2); } }