List of usage examples for java.awt Graphics2D drawLine
public abstract void drawLine(int x1, int y1, int x2, int y2);
(x1, y1)
and (x2, y2)
in this graphics context's coordinate system. From source file:org.gumtree.vis.awt.JChartPanel.java
private void drawTextInputBox(Graphics2D g2) { if (textInputFlag && textInputPoint != null) { // g2.drawChars("Input Text Here".toCharArray(), 1, 60, (int) textInputPoint.getX(), (int) textInputPoint.getY()); Color oldColor = g2.getColor(); g2.setColor(Color.BLACK); String inputText = textInputContent == null ? "" : textInputContent; FontMetrics fm = g2.getFontMetrics(); // int sWidth; // if (textInputCursorIndex == 0 || inputText.length() == 0) { // sWidth = 0; // } else if (textInputCursorIndex < inputText.length()){ // sWidth = fm.stringWidth(inputText.substring(0, textInputCursorIndex)); // } else { // sWidth = fm.stringWidth(inputText); // } String[] lines = inputText.split("\n", 100); int cursorY = 0; int cursorX = 0; int charCount = 0; int maxWidth = 0; int maxHeight = 0; for (int i = 0; i < lines.length; i++) { g2.drawString(lines[i], (int) textInputPoint.getX() + 3, (int) textInputPoint.getY() - 3 + i * 15); // charCount += lines[i].length() + 1; if (textInputCursorIndex > charCount && textInputCursorIndex < charCount + lines[i].length() + 1) { cursorY = i;// w ww . j a va 2 s.c om cursorX = fm.stringWidth(lines[i].substring(0, textInputCursorIndex - charCount)); } else if (textInputCursorIndex == charCount + lines[i].length() + 1) { cursorY = i + 1; cursorX = 0; } charCount += lines[i].length() + 1; int lineWidth = fm.stringWidth(lines[i]); if (lineWidth > maxWidth) { maxWidth = lineWidth; } } maxHeight = 15 * lines.length; // g2.drawString(inputText, (int) textInputPoint.getX() + 3, (int) textInputPoint.getY() - 3); g2.setColor(Color.MAGENTA); // g2.drawString("|", (float) textInputPoint.getX() + 2 + sWidth, (float) textInputPoint.getY() - 3); g2.drawLine((int) textInputPoint.getX() + 3 + cursorX, (int) textInputPoint.getY() + (cursorY - 1) * 15, (int) textInputPoint.getX() + 3 + cursorX, (int) textInputPoint.getY() + cursorY * 15); g2.setColor(Color.BLACK); g2.setColor(oldColor); // int boxWidth = fm.stringWidth(inputText) + 10; if (maxWidth < 100) { maxWidth = 100; } Rectangle2D inputBox = new Rectangle2D.Double(textInputPoint.getX(), textInputPoint.getY() - 15, maxWidth + 8, maxHeight); // ChartMaskingUtilities.drawMaskBoarder(g2, inputBox); Color fillColor = new Color(250, 250, 50, 30); g2.setPaint(fillColor); g2.fill(inputBox); g2.setColor(Color.ORANGE); g2.drawRect((int) textInputPoint.getX(), (int) textInputPoint.getY() - 15, maxWidth + 8, maxHeight); } if (textContentMap.size() > 0) { Color oldColor = g2.getColor(); g2.setColor(Color.BLACK); Rectangle2D imageArea = getScreenDataArea(); for (Entry<Rectangle2D, String> entry : textContentMap.entrySet()) { Rectangle2D rect = entry.getKey(); Point2D screenPoint = ChartMaskingUtilities .translateChartPoint(new Point2D.Double(rect.getX(), rect.getY()), imageArea, getChart()); String text = entry.getValue(); if (text == null) { continue; } String[] lines = text.split("\n"); g2.setColor(Color.BLACK); for (int i = 0; i < lines.length; i++) { g2.drawString(lines[i], (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3 + i * 15); } if (rect == selectedTextWrapper) { FontMetrics fm = g2.getFontMetrics(); int maxWidth = 0; int maxHeight = 0; for (int i = 0; i < lines.length; i++) { int lineWidth = fm.stringWidth(lines[i]); if (lineWidth > maxWidth) { maxWidth = lineWidth; } } maxHeight = 15 * lines.length; if (maxWidth < 100) { maxWidth = 100; } Rectangle2D inputBox = new Rectangle2D.Double(screenPoint.getX(), screenPoint.getY() - 15, maxWidth + 8, maxHeight); Color fillColor = new Color(250, 250, 50, 30); g2.setPaint(fillColor); g2.fill(inputBox); g2.setColor(Color.ORANGE); g2.drawRect((int) screenPoint.getX(), (int) screenPoint.getY() - 15, maxWidth + 8, maxHeight); } // g2.drawString(text == null ? "" : text, (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3); } g2.setColor(oldColor); } }
From source file:org.squidy.designer.zoom.ActionShape.java
@Override protected void paintShapeZoomedIn(PPaintContext paintContext) { Graphics2D g = paintContext.getGraphics(); RectangularShape r = (RectangularShape) getZoomedOutShape(); if (r instanceof RoundRectangle2D) { // int width = (int)(r.getMaxX()-r.getMinX()); // int height = (int)(r.getMaxY()-r.getMinY()); // BufferedImage shadeStarted = new BufferedImage(width, height, // BufferedImage.TYPE_INT_RGB); // BufferedImage shadeStopped = new BufferedImage(width, height, // BufferedImage.TYPE_INT_RGB); // BufferedImage shadeFailure = new BufferedImage(width, height, // BufferedImage.TYPE_INT_RGB); // shadeStarted.getGraphics().setColor(COLOR_STARTED); // shadeStopped.getGraphics().setColor(COLOR_STOPPED); // shadeFailure.getGraphics().setColor(COLOR_FAILURE); // shadeStarted.getGraphics().fillRect(0, 0, width, height); // shadeStopped.getGraphics().fillRect(0, 0, width, height); // shadeFailure.getGraphics().fillRect(0, 0, width, height); // g.setStroke(STROKE_ZOOMED_IN); g.setStroke(StrokeUtils.getBasicStroke(7f)); g.setColor(failure ? COLOR_FAILURE : started ? COLOR_STARTED : COLOR_STOPPED); if (polygonRendering) { if (isRenderPrimitiveRect()) { if (!isHierarchicalZoomInProgress()) { Polygon shadeHorizontal = new Polygon(); Polygon shadeVertical = new Polygon(); double shift = 1; shapeZoomedIn.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); Rectangle bounds = shapeZoomedIn.getBounds(); shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height); shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shift = 5;//from w w w . ja v a 2 s . c om shapeZoomedIn.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); bounds = shapeZoomedIn.getBounds(); shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y); g.fillPolygon(shadeHorizontal); g.fillPolygon(shadeVertical); } } else { g.draw(shapeZoomedIn); } } else { for (double shift = 6.; shift >= 1.; shift -= 1.) { shapeZoomedIn.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); if (isRenderPrimitiveRect()) { if (!isHierarchicalZoomInProgress()) { Rectangle bounds = shapeZoomedIn.getBounds(); // g.drawImage(shadeStarted,null,bounds.x, // bounds.y); // g.fillRect(bounds.x, bounds.y, bounds.width, // bounds.height); g.drawLine(bounds.x + 1, bounds.y + bounds.height, bounds.x + bounds.width - 3, bounds.y + bounds.height); g.drawLine(bounds.x + bounds.width, bounds.y + 1, bounds.x + bounds.width, bounds.y + bounds.height - 3); } } else { g.draw(shapeZoomedIn); } } } } super.paintShapeZoomedIn(paintContext); }
From source file:fr.fg.server.core.TerritoryManager.java
private static BufferedImage createTerritoryMap(int idSector) { List<Area> areas = new ArrayList<Area>(DataAccess.getAreasBySector(idSector)); float[][] points = new float[areas.size()][2]; int[] dominatingAllies = new int[areas.size()]; int i = 0;// w w w .j ava 2s . com for (Area area : areas) { points[i][0] = area.getX() * MAP_SCALE; points[i][1] = area.getY() * MAP_SCALE; dominatingAllies[i] = area.getIdDominatingAlly(); i++; } Hull hull = new Hull(points); MPolygon hullPolygon = hull.getRegion(); float[][] newPoints = new float[points.length + hullPolygon.count()][2]; System.arraycopy(points, 0, newPoints, 0, points.length); float[][] hullCoords = hullPolygon.getCoords(); for (i = 0; i < hullPolygon.count(); i++) { double angle = Math.atan2(hullCoords[i][1], hullCoords[i][0]); double length = Math.sqrt(hullCoords[i][0] * hullCoords[i][0] + hullCoords[i][1] * hullCoords[i][1]); newPoints[i + points.length][0] = (float) (Math.cos(angle) * (length + 8 * MAP_SCALE)); newPoints[i + points.length][1] = (float) (Math.sin(angle) * (length + 8 * MAP_SCALE)); } points = newPoints; Voronoi voronoi = new Voronoi(points); Delaunay delaunay = new Delaunay(points); // Dcoupage en rgions MPolygon[] regions = voronoi.getRegions(); // Calcule le rayon de la galaxie int radius = 0; for (Area area : areas) { radius = Math.max(radius, area.getX() * area.getX() + area.getY() * area.getY()); } radius = (int) Math.floor(Math.sqrt(radius) * MAP_SCALE) + 10 * MAP_SCALE; int diameter = 2 * radius + 1; // Construit l'image avec les quadrants BufferedImage territoriesImage = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) territoriesImage.getGraphics(); // Affecte une couleur chaque alliance HashMap<Integer, Color> alliesColors = new HashMap<Integer, Color>(); for (Area area : areas) { int idDominatingAlly = area.getIdDominatingAlly(); if (idDominatingAlly != 0) alliesColors.put(idDominatingAlly, Ally.TERRITORY_COLORS[DataAccess.getAllyById(idDominatingAlly).getColor()]); } Polygon[] polygons = new Polygon[regions.length]; for (i = 0; i < areas.size(); i++) { if (dominatingAllies[i] != 0) { polygons[i] = createPolygon(regions[i].getCoords(), radius + 1, 3); } } // Dessine tous les secteurs g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); for (i = 0; i < areas.size(); i++) { if (dominatingAllies[i] == 0) continue; Polygon p = polygons[i]; // Dessine le polygone g.setColor(alliesColors.get(dominatingAllies[i])); g.fill(p); // Rempli les espaces entre les polygones adjacents qui // correspondent au territoire d'une mme alliance int[] linkedRegions = delaunay.getLinked(i); for (int j = 0; j < linkedRegions.length; j++) { int linkedRegion = linkedRegions[j]; if (linkedRegion >= areas.size()) continue; if (dominatingAllies[i] == dominatingAllies[linkedRegion]) { if (linkedRegion <= i) continue; float[][] coords1 = regions[i].getCoords(); float[][] coords2 = regions[linkedRegion].getCoords(); int junctionIndex = 0; int[][] junctions = new int[2][2]; search: for (int k = 0; k < coords1.length; k++) { for (int l = 0; l < coords2.length; l++) { if (coords1[k][0] == coords2[l][0] && coords1[k][1] == coords2[l][1]) { junctions[junctionIndex][0] = k; junctions[junctionIndex][1] = l; junctionIndex++; if (junctionIndex == 2) { int[] xpts = new int[] { polygons[i].xpoints[junctions[0][0]], polygons[linkedRegion].xpoints[junctions[0][1]], polygons[linkedRegion].xpoints[junctions[1][1]], polygons[i].xpoints[junctions[1][0]], }; int[] ypts = new int[] { polygons[i].ypoints[junctions[0][0]], polygons[linkedRegion].ypoints[junctions[0][1]], polygons[linkedRegion].ypoints[junctions[1][1]], polygons[i].ypoints[junctions[1][0]], }; Polygon border = new Polygon(xpts, ypts, 4); g.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); g.fill(border); g.draw(border); break search; } break; } } } } } } // Dessine des lignes de contours des territoires g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (i = 0; i < areas.size(); i++) { if (dominatingAllies[i] == 0) continue; g.setStroke(new BasicStroke(1.5f)); g.setColor(alliesColors.get(dominatingAllies[i]).brighter().brighter()); float[][] coords1 = regions[i].getCoords(); lines: for (int j = 0; j < coords1.length; j++) { int[] linkedRegions = delaunay.getLinked(i); for (int k = 0; k < linkedRegions.length; k++) { int linkedRegion = linkedRegions[k]; if (linkedRegion >= areas.size()) continue; if (dominatingAllies[i] == dominatingAllies[linkedRegion]) { float[][] coords2 = regions[linkedRegion].getCoords(); for (int m = 0; m < coords2.length; m++) { if (coords1[j][0] == coords2[m][0] && coords1[j][1] == coords2[m][1] && ((coords1[(j + 1) % coords1.length][0] == coords2[(m + 1) % coords2.length][0] && coords1[(j + 1) % coords1.length][1] == coords2[(m + 1) % coords2.length][1]) || (coords1[(j + 1) % coords1.length][0] == coords2[(m - 1 + coords2.length) % coords2.length][0] && coords1[(j + 1) % coords1.length][1] == coords2[(m - 1 + coords2.length) % coords2.length][1]))) { continue lines; } } } } g.drawLine(Math.round(polygons[i].xpoints[j]), Math.round(polygons[i].ypoints[j]), Math.round(polygons[i].xpoints[(j + 1) % coords1.length]), Math.round(polygons[i].ypoints[(j + 1) % coords1.length])); } for (int j = 0; j < coords1.length; j++) { int neighbours = 0; int lastNeighbourRegion = -1; int neighbourCoordsIndex = -1; int[] linkedRegions = delaunay.getLinked(i); for (int k = 0; k < linkedRegions.length; k++) { int linkedRegion = linkedRegions[k]; if (linkedRegion >= areas.size()) continue; if (dominatingAllies[i] == dominatingAllies[linkedRegion]) { float[][] coords2 = regions[linkedRegion].getCoords(); for (int m = 0; m < coords2.length; m++) { if (coords1[j][0] == coords2[m][0] && coords1[j][1] == coords2[m][1]) { neighbours++; lastNeighbourRegion = linkedRegion; neighbourCoordsIndex = m; break; } } } } if (neighbours == 1) { g.drawLine(Math.round(polygons[i].xpoints[j]), Math.round(polygons[i].ypoints[j]), Math.round(polygons[lastNeighbourRegion].xpoints[neighbourCoordsIndex]), Math.round(polygons[lastNeighbourRegion].ypoints[neighbourCoordsIndex])); } } } BufferedImage finalImage = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB); g = (Graphics2D) finalImage.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, .15f)); g.drawImage(territoriesImage, 0, 0, null); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, .5f)); // Charge la police pour afficher le nom des alliances try { Font textFont = Font.createFont(Font.TRUETYPE_FONT, Action.class.getClassLoader().getResourceAsStream("fr/fg/server/resources/TinDog.ttf")); textFont = textFont.deriveFont(12f).deriveFont(Font.BOLD); g.setFont(textFont); } catch (Exception e) { LoggingSystem.getServerLogger().warn("Could not load quadrant map font.", e); } FontMetrics fm = g.getFontMetrics(); ArrayList<Integer> closedRegions = new ArrayList<Integer>(); for (i = 0; i < areas.size(); i++) { if (dominatingAllies[i] == 0 || closedRegions.contains(i)) continue; ArrayList<Integer> allyRegions = new ArrayList<Integer>(); ArrayList<Integer> openRegions = new ArrayList<Integer>(); openRegions.add(i); while (openRegions.size() > 0) { int currentRegion = openRegions.remove(0); allyRegions.add(currentRegion); closedRegions.add(currentRegion); int[] linkedRegions = delaunay.getLinked(currentRegion); for (int k = 0; k < linkedRegions.length; k++) { int linkedRegion = linkedRegions[k]; if (linkedRegion >= areas.size() || openRegions.contains(linkedRegion) || allyRegions.contains(linkedRegion)) continue; if (dominatingAllies[i] == dominatingAllies[linkedRegion]) openRegions.add(linkedRegion); } } Area area = areas.get(i); long xsum = 0; long ysum = 0; for (int k = 0; k < allyRegions.size(); k++) { int allyRegion = allyRegions.get(k); area = areas.get(allyRegion); xsum += area.getX(); ysum += area.getY(); } int x = (int) (xsum / allyRegions.size()) * MAP_SCALE + radius + 1; int y = (int) (-ysum / allyRegions.size()) * MAP_SCALE + radius + 1; ; Point point = new Point(x, y); boolean validLocation = false; for (int k = 0; k < allyRegions.size(); k++) { int allyRegion = allyRegions.get(k); if (polygons[allyRegion].contains(point)) { validLocation = true; break; } } if (validLocation) { if (allyRegions.size() == 1) y -= 14; } else { int xmid = (int) (xsum / allyRegions.size()); int ymid = (int) (ysum / allyRegions.size()); area = areas.get(i); int dx = area.getX() - xmid; int dy = area.getY() - ymid; int distance = dx * dx + dy * dy; int nearestAreaIndex = i; int nearestDistance = distance; for (int k = 0; k < allyRegions.size(); k++) { int allyRegion = allyRegions.get(k); area = areas.get(allyRegion); dx = area.getX() - xmid; dy = area.getY() - ymid; distance = dx * dx + dy * dy; if (distance < nearestDistance) { nearestAreaIndex = allyRegion; nearestDistance = distance; } } area = areas.get(nearestAreaIndex); x = area.getX() * MAP_SCALE + radius + 1; y = -area.getY() * MAP_SCALE + radius - 13; } // Dessine le tag de l'alliance String allyTag = "[ " + DataAccess.getAllyById(dominatingAllies[i]).getTag() + " ]"; g.setColor(Color.BLACK); g.drawString(allyTag, x - fm.stringWidth(allyTag) / 2 + 1, y); g.setColor(alliesColors.get(dominatingAllies[i])); g.drawString(allyTag, x - fm.stringWidth(allyTag) / 2, y); } return finalImage; }
From source file:be.fedict.eidviewer.gui.printing.IDPrintout.java
public int print(Graphics graphics, PageFormat pageFormat, int pageNumber) throws PrinterException { // we only support printing all in one single page if (pageNumber > 0) return Printable.NO_SUCH_PAGE; logger.finest(new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) .append("width", pageFormat.getWidth()).append("height", pageFormat.getHeight()) .append("imageableWidth", pageFormat.getImageableWidth()) .append("imageableHeight", pageFormat.getImageableHeight()) .append("imageableX", pageFormat.getImageableX()).append("imageableY", pageFormat.getImageableY()) .append("orientation", pageFormat.getOrientation()) .append("paper.width", pageFormat.getPaper().getWidth()) .append("paper.height", pageFormat.getPaper().getHeight()) .append("paper.imageableWidth", pageFormat.getPaper().getImageableWidth()) .append("paper.imageableHeight", pageFormat.getPaper().getImageableHeight()) .append("paper.imageableX", pageFormat.getPaper().getImageableX()) .append("paper.imageableY", pageFormat.getPaper().getImageableY()).toString()); logger.finest(new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) .append("clip.width", graphics.getClipBounds().width) .append("clip.height", graphics.getClipBounds().height).append("clip.x", graphics.getClipBounds().x) .append("clip.y", graphics.getClipBounds().y).toString()); // translate graphics2D with origin at top left first imageable location Graphics2D graphics2D = (Graphics2D) graphics; graphics2D.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); // keep imageable width and height as variables for clarity (we use them often) float imageableWidth = (float) pageFormat.getImageableWidth(); float imageableHeight = (float) pageFormat.getImageableHeight(); // Coat of Arms images are stored at approx 36 DPI, scale 1/2 to get to Java default of 72DPI AffineTransform coatOfArmsTransform = new AffineTransform(); coatOfArmsTransform.scale(0.5, 0.5); // photo images are stored at approx 36 DPI, scale 1/2 to get to Java default of 72DPI AffineTransform photoTransform = new AffineTransform(); photoTransform.scale(0.5, 0.5);//from www. j a v a 2s . c o m photoTransform.translate((imageableWidth * 2) - (photo.getWidth(this)), 0); // make sure foreground is black, and draw coat of Arms and photo at the top of the page // using the transforms to scale them to 72DPI. graphics2D.setColor(Color.BLACK); graphics2D.drawImage(coatOfArms, coatOfArmsTransform, null); graphics2D.drawImage(photo, photoTransform, null); // calculate some sizes that need to take into account the scaling of the graphics, to avoid dragging // those non-intuitive "/2" further along in the code. float headerHeight = (float) (coatOfArms.getHeight(this)) / 2; float coatOfArmsWidth = (float) (coatOfArms.getWidth(this)) / 2; float photoWidth = (float) (photo.getWidth(this)) / 2; float headerSpaceBetweenImages = imageableWidth - (coatOfArmsWidth + photoWidth + (SPACE_BETWEEN_ITEMS * 2)); logger.finest(new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("headerHeight", headerHeight) .append("coatOfArmsWidth", coatOfArmsWidth).append("photoWidth", photoWidth) .append("headerSpaceBetweenImages", headerSpaceBetweenImages).toString()); // get localised strings for card type. We'll take a new line every time a ";" is found in the resource String[] cardTypeStr = (bundle.getString("type_" + this.identity.getDocumentType().toString()) .toUpperCase()).split(";"); // if a "mention" is present, append it so it appears below the card type string, between brackets if (identity.getSpecialOrganisation() != SpecialOrganisation.UNSPECIFIED) { String mention = TextFormatHelper.getSpecialOrganisationString(bundle, identity.getSpecialOrganisation()); if (mention != null && !mention.isEmpty()) { String[] cardTypeWithMention = new String[cardTypeStr.length + 1]; System.arraycopy(cardTypeStr, 0, cardTypeWithMention, 0, cardTypeStr.length); cardTypeWithMention[cardTypeStr.length] = "(" + mention + ")"; cardTypeStr = cardTypeWithMention; } } // iterate from MAXIMAL_FONT_SIZE, calculating how much space would be required to fit the card type strings // stop when a font size is found where they all fit the space between the graphics in an orderly manner boolean sizeFound = false; int fontSize; for (fontSize = TITLE_MAXIMAL_FONT_SIZE; (fontSize >= MINIMAL_FONT_SIZE) && (!sizeFound); fontSize--) // count down slowly until we find one that fits nicely { logger.log(Level.FINE, "fontSize=" + fontSize + " sizeFound=" + sizeFound); graphics2D.setFont(new Font(FONT, Font.PLAIN, fontSize)); sizeFound = (ImageUtilities.getTotalStringWidth(graphics2D, cardTypeStr) < headerSpaceBetweenImages) && (ImageUtilities.getTotalStringHeight(graphics2D, cardTypeStr) < headerHeight); } // unless with extremely small papers, a size should always have been found. // draw the card type strings, centered, between the images at the top of the page if (sizeFound) { graphics2D.setFont(new Font(FONT, Font.PLAIN, fontSize + 1)); float cardTypeHeight = cardTypeStr.length * ImageUtilities.getStringHeight(graphics2D); float cardTypeBaseLine = ((headerHeight - cardTypeHeight) / 2) + ImageUtilities.getAscent(graphics2D); float cardTypeLineHeight = ImageUtilities.getStringHeight(graphics2D); logger.finest(new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) .append("cardTypeHeight", cardTypeHeight).append("cardTypeBaseLine", cardTypeBaseLine) .append("cardTypeLineHeight", cardTypeLineHeight).toString()); for (int i = 0; i < cardTypeStr.length; i++) { float left = (coatOfArmsWidth + SPACE_BETWEEN_ITEMS + (headerSpaceBetweenImages - ImageUtilities.getStringWidth(graphics2D, cardTypeStr[i])) / 2); float leading = (float) cardTypeLineHeight * i; graphics2D.drawString(cardTypeStr[i], left, cardTypeBaseLine + leading); } } // populate idAttributes with all the information from identity and address // as well as date printed and some separators List<IdentityAttribute> idAttributes = populateAttributeList(); // draw a horizontal line just below the header (images + card type titles) graphics2D.drawLine(0, (int) headerHeight, (int) imageableWidth, (int) headerHeight); // calculate how much space is left between the header and the bottom of the imageable area headerHeight += 32; // take some distance from header float imageableDataHeight = imageableHeight - headerHeight; float totalDataWidth = 0, totalDataHeight = 0; float labelWidth, widestLabelWidth = 0; float valueWidth, widestValueWidth = 0; // iterate from MAXIMAL_FONT_SIZE, calculating how much space would be required to fit the information in idAttributes into // the space between the header and the bottom of the imageable area // stop when a font size is found where it all fits in an orderly manner sizeFound = false; for (fontSize = MAXIMAL_FONT_SIZE; (fontSize >= MINIMAL_FONT_SIZE) && (!sizeFound); fontSize--) // count down slowly until we find one that fits nicely { logger.log(Level.FINE, "fontSize=" + fontSize + " sizeFound=" + sizeFound); graphics2D.setFont(new Font(FONT, Font.PLAIN, fontSize)); widestLabelWidth = 0; widestValueWidth = 0; for (IdentityAttribute attribute : idAttributes) { if (attribute == SEPARATOR) continue; labelWidth = ImageUtilities.getStringWidth(graphics2D, attribute.getLabel()); valueWidth = ImageUtilities.getStringWidth(graphics2D, attribute.getValue()); if (labelWidth > widestLabelWidth) widestLabelWidth = labelWidth; if (valueWidth > widestValueWidth) widestValueWidth = valueWidth; } totalDataWidth = widestLabelWidth + SPACE_BETWEEN_ITEMS + widestValueWidth; totalDataHeight = ImageUtilities.getStringHeight(graphics2D) + (ImageUtilities.getStringHeight(graphics2D) * idAttributes.size()); if ((totalDataWidth < imageableWidth) && (totalDataHeight < imageableDataHeight)) sizeFound = true; } logger.finest(new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) .append("widestLabelWidth", widestLabelWidth).append("widestValueWidth", widestValueWidth) .append("totalDataWidth", totalDataWidth).append("totalDataHeight", totalDataHeight).toString()); // unless with extremely small papers, a size should always have been found. // draw the identity, addess and date printed information, in 2 columns, centered inside the // space between the header and the bottom of the imageable area if (sizeFound) { graphics2D.setFont(new Font(FONT, Font.PLAIN, fontSize)); float labelsLeft = (imageableWidth - totalDataWidth) / 2; float valuesLeft = labelsLeft + widestLabelWidth + SPACE_BETWEEN_ITEMS; float dataLineHeight = ImageUtilities.getStringHeight(graphics2D); float dataTop = dataLineHeight + headerHeight + ((imageableDataHeight - totalDataHeight) / 2); float lineNumber = 0; logger.finest(new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("labelsLeft", labelsLeft) .append("valuesLeft", valuesLeft).append("dataLineHeight", dataLineHeight) .append("dataTop", dataTop).toString()); for (IdentityAttribute attribute : idAttributes) { if (attribute != SEPARATOR) // data { graphics2D.setColor(attribute.isRelevant() ? Color.BLACK : Color.LIGHT_GRAY); graphics2D.drawString(attribute.getLabel(), labelsLeft, dataTop + (lineNumber * dataLineHeight)); graphics2D.drawString(attribute.getValue(), valuesLeft, dataTop + (lineNumber * dataLineHeight)); } else // separator { int y = (int) (((dataTop + (lineNumber * dataLineHeight) + (dataLineHeight / 2))) - ImageUtilities.getAscent(graphics2D)); graphics2D.setColor(Color.BLACK); graphics2D.drawLine((int) labelsLeft, y, (int) (labelsLeft + totalDataWidth), y); } lineNumber++; } } // tell Java printing that all this makes for a page worth printing :-) return Printable.PAGE_EXISTS; }
From source file:lu.fisch.unimozer.Diagram.java
private void drawExtends(Graphics2D g, Point pFrom, Point pTo) { int ARROW_SIZE = 16; double ARROW_ANGLE = Math.PI / 6; //g.setColor(Color.BLACK); double angle = Math.atan2(-(pFrom.y - pTo.y), pFrom.x - pTo.x); Point pArrow = new Point(pTo.x + (int) ((ARROW_SIZE - 2) * Math.cos(angle)), pTo.y - (int) ((ARROW_SIZE - 2) * Math.sin(angle))); // draw the arrow head int[] xPoints = { pTo.x, pTo.x + (int) ((ARROW_SIZE) * Math.cos(angle + ARROW_ANGLE)), pTo.x + (int) (ARROW_SIZE * Math.cos(angle - ARROW_ANGLE)) }; int[] yPoints = { pTo.y, pTo.y - (int) ((ARROW_SIZE) * Math.sin(angle + ARROW_ANGLE)), pTo.y - (int) (ARROW_SIZE * Math.sin(angle - ARROW_ANGLE)) }; g.drawPolygon(xPoints, yPoints, 3);// w w w .j av a 2 s . com g.drawLine(pFrom.x, pFrom.y, pArrow.x, pArrow.y); }
From source file:ucar.unidata.idv.ui.ImageGenerator.java
/** * Process the lat/lon labels tag//from w w w .ja v a 2s .c o m * * @param child the XML * @param viewManager the associated view manager * @param image the image to draw on * @param imageProps the image properties * * @return a new image * * @throws Exception on badness */ public BufferedImage doLatLonLabels(Element child, ViewManager viewManager, BufferedImage image, Hashtable imageProps) throws Exception { if (viewManager == null) { throw new IllegalArgumentException("Tag " + TAG_LATLONLABELS + " requires a view"); } if (!(viewManager instanceof MapViewManager)) { throw new IllegalArgumentException("Tag " + TAG_LATLONLABELS + " requires a map view"); } MapViewManager mvm = (MapViewManager) viewManager; NavigatedDisplay display = (NavigatedDisplay) viewManager.getMaster(); DecimalFormat format = new DecimalFormat(applyMacros(child, ATTR_FORMAT, "##0.0")); Color color = applyMacros(child, ATTR_COLOR, Color.red); Color lineColor = applyMacros(child, ATTR_LINECOLOR, color); Color bg = applyMacros(child, ATTR_LABELBACKGROUND, (Color) null); double[] latValues = Misc.parseDoubles(applyMacros(child, ATTR_LAT_VALUES, "")); List<String> latLabels = StringUtil.split(applyMacros(child, ATTR_LAT_LABELS, ""), ",", true, true); double[] lonValues = Misc.parseDoubles(applyMacros(child, ATTR_LON_VALUES, "")); List<String> lonLabels = StringUtil.split(applyMacros(child, ATTR_LON_LABELS, ""), ",", true, true); boolean drawLonLines = applyMacros(child, ATTR_DRAWLONLINES, false); boolean drawLatLines = applyMacros(child, ATTR_DRAWLATLINES, false); boolean showTop = applyMacros(child, ATTR_SHOWTOP, false); boolean showBottom = applyMacros(child, ATTR_SHOWBOTTOM, true); boolean showLeft = applyMacros(child, ATTR_SHOWLEFT, true); boolean showRight = applyMacros(child, ATTR_SHOWRIGHT, false); int width = image.getWidth(null); int height = image.getHeight(null); int centerX = width / 2; int centerY = height / 2; EarthLocation nw, ne, se, sw; //don: this what I added Double north = (Double) imageProps.get(ATTR_NORTH); Double south = (Double) imageProps.get(ATTR_SOUTH); Double east = (Double) imageProps.get(ATTR_EAST); Double west = (Double) imageProps.get(ATTR_WEST); //Assume if we have one we have them all if (north != null) { nw = DisplayControlImpl.makeEarthLocation(north.doubleValue(), west.doubleValue(), 0); ne = DisplayControlImpl.makeEarthLocation(north.doubleValue(), east.doubleValue(), 0); sw = DisplayControlImpl.makeEarthLocation(south.doubleValue(), west.doubleValue(), 0); se = DisplayControlImpl.makeEarthLocation(south.doubleValue(), east.doubleValue(), 0); } else { nw = display.screenToEarthLocation(0, 0); ne = display.screenToEarthLocation(width, 0); se = display.screenToEarthLocation(0, height); sw = display.screenToEarthLocation(width, height); } double widthDegrees = ne.getLongitude().getValue() - nw.getLongitude().getValue(); double heightDegrees = ne.getLatitude().getValue() - se.getLatitude().getValue(); Insets insets = getInsets(child, 0); int delta = 2; int bgPad = 1; image = doMatte(image, child, 0); Graphics2D g = (Graphics2D) image.getGraphics(); g.setFont(getFont(child)); FontMetrics fm = g.getFontMetrics(); int lineOffsetRight = applyMacros(child, ATTR_LINEOFFSET_RIGHT, 0); int lineOffsetLeft = applyMacros(child, ATTR_LINEOFFSET_LEFT, 0); int lineOffsetTop = applyMacros(child, ATTR_LINEOFFSET_TOP, 0); int lineOffsetBottom = applyMacros(child, ATTR_LINEOFFSET_BOTTOM, 0); Stroke lineStroke; if (XmlUtil.hasAttribute(child, ATTR_DASHES)) { lineStroke = new BasicStroke((float) applyMacros(child, ATTR_LINEWIDTH, 1.0), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f, Misc.parseFloats(applyMacros(child, ATTR_DASHES, "8")), 0.0f); } else { lineStroke = new BasicStroke((float) applyMacros(child, ATTR_LINEWIDTH, 1.0)); } g.setStroke(lineStroke); double leftLon = nw.getLongitude().getValue(CommonUnit.degree); double rightLon = ne.getLongitude().getValue(CommonUnit.degree); Range lonRange = new Range(leftLon, rightLon); for (int i = 0; i < lonValues.length; i++) { double lon = GeoUtils.normalizeLongitude(lonRange, lonValues[i]); double percent = (lon - nw.getLongitude().getValue()) / widthDegrees; // if(percent<0 || percent>1) continue; String label; if (i < lonLabels.size()) { label = lonLabels.get(i); } else { label = format.format(lonValues[i]); } Rectangle2D rect = fm.getStringBounds(label, g); int baseX = insets.left + (int) (percent * width); int x = baseX - (int) rect.getWidth() / 2; int topY; if (insets.top == 0) { topY = (int) rect.getHeight() + delta; } else { topY = insets.top - delta; } if (drawLonLines) { g.setColor(lineColor); g.drawLine(baseX, insets.top + lineOffsetTop, baseX, insets.top + height - lineOffsetBottom); } if (showTop) { if (bg != null) { g.setColor(bg); g.fillRect(x - bgPad, topY - (int) rect.getHeight() - bgPad, (int) rect.getWidth() + bgPad * 2, (int) rect.getHeight() + bgPad * 2); } g.setColor(color); g.drawString(label, x, topY); } int bottomY; if (insets.bottom == 0) { bottomY = insets.top + height - delta; } else { bottomY = insets.top + height + (int) rect.getHeight() + delta; } if (showBottom) { if (bg != null) { g.setColor(bg); g.fillRect(x - bgPad, bottomY - (int) rect.getHeight() - bgPad, (int) rect.getWidth() + bgPad * 2, (int) rect.getHeight() + bgPad * 2); } g.setColor(color); g.drawString(label, x, bottomY); } } for (int i = 0; i < latValues.length; i++) { double lat = latValues[i]; double percent = 1.0 - (lat - se.getLatitude().getValue()) / heightDegrees; int baseY = insets.top + (int) (percent * height); // if(percent<0 || percent>1) continue; String label; if (i < latLabels.size()) { label = latLabels.get(i); } else { label = format.format(lat); } Rectangle2D rect = fm.getStringBounds(label, g); int y = baseY + (int) rect.getHeight() / 2; int leftX; if (insets.left == 0) { leftX = 0 + delta; } else { leftX = insets.left - (int) rect.getWidth() - delta; } if (drawLonLines) { g.setColor(lineColor); g.drawLine(insets.left + lineOffsetRight, baseY, insets.left + width - lineOffsetRight, baseY); } if (showLeft) { if (bg != null) { g.setColor(bg); g.fillRect(leftX - bgPad, y - (int) rect.getHeight() - bgPad, (int) rect.getWidth() + bgPad * 2, (int) rect.getHeight() + bgPad * 2); } g.setColor(color); g.drawString(label, leftX, y); } if (insets.right == 0) { leftX = insets.left + width - (int) rect.getWidth() - delta; } else { leftX = insets.left + width + delta; } if (showRight) { if (bg != null) { g.setColor(bg); g.fillRect(leftX - bgPad, y - (int) rect.getHeight() - bgPad, (int) rect.getWidth() + bgPad * 2, (int) rect.getHeight() + bgPad * 2); } g.setColor(color); g.drawString(label, leftX, y); } } return image; }
From source file:org.simmi.GeneSetHead.java
License:asdf
public void repaintGCSkew(List<Sequence> selclist, Graphics2D g2, int size, GeneGroup gg, String selspec) { g2.setColor(Color.white);/* w ww. j a va2s . c om*/ g2.fillRect(0, 0, 1024, 1024); g2.setFont(g2.getFont().deriveFont(10.0f)); int total = 0; int g = 0; int c = 0; double gcstotal = 0.0; for (Sequence ctg : selclist) { //Sequence ctg = clist.get( u ); if (gg != null) { for (Tegeval tv : gg.getTegevals()) { if (tv.getContshort() == ctg) { int i = tv.start; int x1 = (int) (512.0 + (384.0 - 100.0) * Math.cos((i + total) * 2.0 * Math.PI / size)); int y1 = (int) (512.0 + (384.0 - 100.0) * Math.sin((i + total) * 2.0 * Math.PI / size)); int x2 = (int) (512.0 + (384.0 + 100.0) * Math.cos((i + total) * 2.0 * Math.PI / size)); int y2 = (int) (512.0 + (384.0 + 100.0) * Math.sin((i + total) * 2.0 * Math.PI / size)); g2.setColor(Color.green); g2.drawLine(x1, y1, x2, y2); } } } double horn = total * 2.0 * Math.PI / size; double horn2 = (total + ctg.length()) * 2.0 * Math.PI / size; int x1 = (int) (512.0 + (384.0 - 100.0) * Math.cos(horn)); int y1 = (int) (512.0 + (384.0 - 100.0) * Math.sin(horn)); int x2 = (int) (512.0 + (384.0 + 100.0) * Math.cos(horn)); int y2 = (int) (512.0 + (384.0 + 100.0) * Math.sin(horn)); g2.setColor(Color.black); g2.drawLine(x1, y1, x2, y2); int xoff = (int) (512.0 + (384.0 + 100.0) * Math.cos(horn2)); int yoff = (int) (512.0 + (384.0 + 100.0) * Math.sin(horn2)); if (horn < Math.PI) { g2.translate(x2, y2); g2.rotate(horn + Math.PI / 2.0); g2.drawString(ctg.getName(), 0, 0); g2.rotate(-horn - Math.PI / 2.0); g2.translate(-x2, -y2); } else { g2.translate(xoff, yoff); g2.rotate(horn2 + Math.PI / 2.0); g2.drawString(ctg.getName(), -g2.getFontMetrics().stringWidth(ctg.getName()), 0); g2.rotate(-horn2 - Math.PI / 2.0); g2.translate(-xoff, -yoff); } for (int i = 0; i < ctg.length(); i += 500) { for (int k = i; k < Math.min(ctg.length(), i + 500); k++) { char chr = ctg.charAt(k); if (chr == 'g' || chr == 'G') { g++; } else if (chr == 'c' || chr == 'C') { c++; } } int gcount = 0; int ccount = 0; int acount = 0; int tcount = 0; for (int k = i; k < Math.min(ctg.length(), i + 10000); k++) { char chr = k - 5000 < 0 ? ctg.charAt(ctg.length() + (k - 5000)) : ctg.charAt(k - 5000); if (chr == 'g' || chr == 'G') { gcount++; } else if (chr == 'c' || chr == 'C') { ccount++; } else if (chr == 'a' || chr == 'A') acount++; else if (chr == 't' || chr == 'T') tcount++; } if (gcount > 0 || ccount > 0) { double gcskew = (gcount - ccount) / (double) (gcount + ccount); gcstotal += gcskew; x1 = (int) (512.0 + (384.0) * Math.cos((i + total) * 2.0 * Math.PI / size)); y1 = (int) (512.0 + (384.0) * Math.sin((i + total) * 2.0 * Math.PI / size)); x2 = (int) (512.0 + (384.0 + gcskew * 100.0) * Math.cos((i + total) * 2.0 * Math.PI / size)); y2 = (int) (512.0 + (384.0 + gcskew * 100.0) * Math.sin((i + total) * 2.0 * Math.PI / size)); if (gcskew >= 0) g2.setColor(Color.blue); else g2.setColor(Color.red); g2.drawLine(x1, y1, x2, y2); } if (acount > 0 || tcount > 0) { double atskew = (acount - tcount) / (double) (acount + tcount); x1 = (int) (512.0 + (300.0) * Math.cos((i + total) * 2.0 * Math.PI / size)); y1 = (int) (512.0 + (300.0) * Math.sin((i + total) * 2.0 * Math.PI / size)); x2 = (int) (512.0 + (300.0 + atskew * 100.0) * Math.cos((i + total) * 2.0 * Math.PI / size)); y2 = (int) (512.0 + (300.0 + atskew * 100.0) * Math.sin((i + total) * 2.0 * Math.PI / size)); if (atskew >= 0) g2.setColor(Color.blue); else g2.setColor(Color.red); g2.drawLine(x1, y1, x2, y2); } } total += ctg.length(); } g2.setColor(Color.black); g2.setFont(g2.getFont().deriveFont(java.awt.Font.ITALIC).deriveFont(32.0f)); String[] specsplit; // = selspec.split("_"); if (selspec.contains("hermus")) specsplit = selspec.split("_"); else { Matcher m = Pattern.compile("\\d").matcher(selspec); int firstDigitLocation = m.find() ? m.start() : 0; if (firstDigitLocation == 0) specsplit = new String[] { "Thermus", selspec }; else specsplit = new String[] { "Thermus", selspec.substring(0, firstDigitLocation), selspec.substring(firstDigitLocation) }; } int k = 0; for (String spec : specsplit) { int strw = g2.getFontMetrics().stringWidth(spec); g2.drawString(spec, (1024 - strw) / 2, 1024 / 2 - specsplit.length * 32 / 2 + 32 + k * 32); k++; } /*double gcs = gcstotal/total; //(g-c)/(g+c); String gcstr = Double.toString( Math.round( gcs*1000000.0 ) ); g2.drawString( gcstr+"ppm", 768, 512 );*/ }
From source file:org.forester.archaeopteryx.TreePanel.java
final private void paintNodeData(final Graphics2D g, final PhylogenyNode node, final boolean to_graphics_file, final boolean to_pdf, final boolean is_in_found_nodes) { if (isNodeDataInvisible(node) && !to_graphics_file && !to_pdf) { return;//from w ww.j a va 2 s. com } if (getOptions().isShowBranchLengthValues() && ((getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR) || (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED) || (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE)) && (!node.isRoot()) && (node.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT)) { paintBranchLength(g, node, to_pdf, to_graphics_file); } if (!getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse()) { return; } int x = 0; if (node.getNodeData().isHasTaxonomy() && (getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyNames())) { x = paintTaxonomy(g, node, is_in_found_nodes, to_pdf, to_graphics_file); } if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) { g.setColor(Color.BLACK); } else if (is_in_found_nodes) { g.setColor(getTreeColorSet().getFoundColor()); } else if (getControlPanel().isColorAccordingToTaxonomy()) { g.setColor(getTaxonomyBasedColor(node)); } else { g.setColor(getTreeColorSet().getSequenceColor()); } _sb.setLength(0); if (node.isCollapse() && ((!node.isRoot() && !node.getParent().isCollapse()) || node.isRoot())) { _sb.append(" ["); _sb.append(node.getAllExternalDescendants().size()); _sb.append("]"); } if (getControlPanel().isShowNodeNames() && (node.getNodeName().length() > 0)) { if (_sb.length() > 0) { _sb.append(" "); } _sb.append(node.getNodeName()); } if (node.getNodeData().isHasSequence()) { if (getControlPanel().isShowGeneSymbols() && (node.getNodeData().getSequence().getSymbol().length() > 0)) { if (_sb.length() > 0) { _sb.append(" "); } _sb.append(node.getNodeData().getSequence().getSymbol()); } if (getControlPanel().isShowGeneNames() && (node.getNodeData().getSequence().getName().length() > 0)) { // if ( _sb.length() > 0 ) { // _sb.append( " " ); // } // _sb.append( node.getNodeData().getSequence().getName() ); PhylogenyNode parent = node.getParent(); double x1 = parent.getXcoord(); double y1 = parent.getYcoord(); double x2 = node.getXcoord(); double y2 = node.getYcoord(); double above_the_line = 1.0; if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR) { double center_of_branch_x = Math.abs(x1 + x2) / 2.0; double center_of_branch_y = Math.abs(y1 + y2) / 2.0; TreePanel.drawString(node.getNodeData().getSequence().getName(), center_of_branch_x, center_of_branch_y - above_the_line, g); } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR) { double center_of_branch_x = Math.abs(x1 + x2) / 2.0; double center_of_branch_y = y2; TreePanel.drawString(node.getNodeData().getSequence().getName(), center_of_branch_x, center_of_branch_y - above_the_line, g); } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED) { double center_of_branch_x = Math.abs(x1 + x2) / 2.0; double center_of_branch_y = y2; TreePanel.drawString(node.getNodeData().getSequence().getName(), center_of_branch_x, center_of_branch_y - above_the_line, g); } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE) { double center_of_branch_x = Math.abs(x1 + x2) / 2.0 + EURO_D; double center_of_branch_y = y2; TreePanel.drawString(node.getNodeData().getSequence().getName(), center_of_branch_x, center_of_branch_y - above_the_line, g); } } if (getControlPanel().isShowSequenceAcc() && (node.getNodeData().getSequence().getAccession() != null)) { if (_sb.length() > 0) { _sb.append(" "); } if (!ForesterUtil.isEmpty(node.getNodeData().getSequence().getAccession().getSource())) { _sb.append(node.getNodeData().getSequence().getAccession().getSource()); _sb.append(":"); } _sb.append(node.getNodeData().getSequence().getAccession().getValue()); } } g.setFont(getTreeFontSet().getLargeFont()); if (is_in_found_nodes) { g.setFont(getTreeFontSet().getLargeFont().deriveFont(Font.BOLD)); } double down_shift_factor = 3.0; if (!node.isExternal() && (node.getNumberOfDescendants() == 1)) { down_shift_factor = 1; } // GUILHEM_BEG ______________ final double posX = node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE; final double posY = (node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / down_shift_factor)); final int CONFIDENCE_LEFT_MARGIN = 4; final String sNodeText = _sb.toString(); if (_control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence() && (_query_sequence != null)) { int nodeTextBoundsWidth = 0; if (sNodeText.length() > 0) { final Rectangle2D node_text_bounds = new TextLayout(sNodeText, g.getFont(), _frc).getBounds(); //would like to remove this 'new', but how... nodeTextBoundsWidth = (int) node_text_bounds.getWidth(); } if (node.getNodeData().getSequence().equals(_query_sequence)) { if (nodeTextBoundsWidth > 0) { // invert font color and background color to show that this is the query sequence g.fillRect((int) posX - 1, (int) posY - 8, nodeTextBoundsWidth + 5, 11); g.setColor(getTreeColorSet().getBackgroundColor()); } } else { final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations(); for (final SequenceRelation seqRelation : seqRelations) { final boolean fGotRelationWithQuery = (seqRelation.getRef0().isEqual(_query_sequence) || seqRelation.getRef1().isEqual(_query_sequence)) && seqRelation.getType() .equals(getControlPanel().getSequenceRelationTypeBox().getSelectedItem()); if (fGotRelationWithQuery) { // we will underline the text to show that this sequence is ortholog to the query final double linePosX = node.getXcoord() + 2 + TreePanel.HALF_BOX_SIZE; final String sConfidence = (!getControlPanel().isShowSequenceRelationConfidence() || (seqRelation.getConfidence() == null)) ? null : " (" + seqRelation.getConfidence().getValue() + ")"; if (sConfidence != null) { double confidenceX = posX; if (sNodeText.length() > 0) { confidenceX += new TextLayout(sNodeText, g.getFont(), _frc).getBounds().getWidth() + CONFIDENCE_LEFT_MARGIN; } if (confidenceX > linePosX) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code final int confidenceWidth = (int) new TextLayout(sConfidence, g.getFont(), _frc) .getBounds().getWidth(); TreePanel.drawString(sConfidence, confidenceX, posY, g); x += CONFIDENCE_LEFT_MARGIN + confidenceWidth; } } if (x + nodeTextBoundsWidth > 0) /* we only underline if there is something displayed */ { if (nodeTextBoundsWidth == 0) { nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */ } else { nodeTextBoundsWidth += 2; } g.drawLine((int) linePosX + 1, 3 + (int) posY, (int) linePosX + x + nodeTextBoundsWidth, 3 + (int) posY); break; } } } } } if (sNodeText.length() > 0) { TreePanel.drawString(sNodeText, posX, posY, g); } // GUILHEM_END _____________ // COMMENTED_OUT_BY_GUILHEM_BEG _______________ // TODO FIXME need to check this one! //if ( _sb.length() > 0 ) { // TreePanel.drawString( _sb.toString(), node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord() // + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g ); //} // COMMENTED_OUT_BY_GUILHEM_END ________________ if (getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence() && (node.getNodeData().getSequence().getAnnotations() != null) && (!node.getNodeData().getSequence().getAnnotations().isEmpty())) { if (_sb.length() > 0) { x += getTreeFontSet()._fm_large.stringWidth(_sb.toString()) + 5; } final Annotation ann = (Annotation) node.getNodeData().getSequence().getAnnotations().get(0); if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) { g.setColor(Color.BLACK); } else { g.setColor(calculateColorForAnnotation(ann)); } final String ann_str = ann.asSimpleText().toString(); TreePanel.drawString(ann_str, node.getXcoord() + x + 3 + TreePanel.HALF_BOX_SIZE, node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / down_shift_factor), g); _sb.setLength(0); _sb.append(ann_str); } if ((getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR) || (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE) || (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED)) { if ((getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts()) && node.getNodeData().isHasBinaryCharacters()) { if (_sb.length() > 0) { x += getTreeFontSet()._fm_large.stringWidth(_sb.toString()) + 5; } if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) { g.setColor(Color.BLACK); } else { g.setColor(getTreeColorSet().getBinaryDomainCombinationsColor()); } if (getControlPanel().isShowBinaryCharacters()) { TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer() .toString(), node.getXcoord() + x + 1 + TreePanel.HALF_BOX_SIZE, node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / down_shift_factor), g); paintGainedAndLostCharacters(g, node, node.getNodeData().getBinaryCharacters().getGainedCharactersAsStringBuffer().toString(), node.getNodeData().getBinaryCharacters().getLostCharactersAsStringBuffer().toString()); } else { if (DRAW_MEAN_COUNTS && node.isInternal()) { final List<PhylogenyNode> ec = node.getAllExternalDescendants(); double sum = 0; int count = 0; for (final PhylogenyNode phylogenyNode : ec) { count++; if (phylogenyNode.getNodeData().getBinaryCharacters() != null) { sum += phylogenyNode.getNodeData().getBinaryCharacters().getPresentCount(); } } final double mean = ForesterUtil.round(sum / count, 1); TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCount() + " [" + mean + "]", node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / down_shift_factor), g); } else { TreePanel.drawString(node.getNodeData().getBinaryCharacters().getPresentCount(), node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / down_shift_factor), g); } paintGainedAndLostCharacters(g, node, "+" + node.getNodeData().getBinaryCharacters().getGainedCount(), "-" + node.getNodeData().getBinaryCharacters().getLostCount()); } } } }