void drawRoiLabel(Graphics g, int index, Roi roi) { Rectangle r = roi.getBounds(); int x = screenX(r.x); int y = screenY(r.y); double mag = getMagnification(); int width = (int) (r.width * mag); int height = (int) (r.height * mag); int size = width > 40 && height > 40 ? 12 : 9; if (font != null) { g.setFont(font); size = font.getSize(); } else if (size == 12) g.setFont(largeFont); else g.setFont(smallFont); boolean drawingList = index >= LIST_OFFSET; if (drawingList) index -= LIST_OFFSET; String label = "" + (index + 1); if (drawNames && roi.getName() != null) label = roi.getName(); FontMetrics metrics = g.getFontMetrics(); int w = metrics.stringWidth(label); x = x + width / 2 - w / 2; y = y + height / 2 + Math.max(size / 2, 6); int h = metrics.getAscent() + metrics.getDescent(); if (bgColor != null) { g.setColor(bgColor); g.fillRoundRect(x - 1, y - h + 2, w + 1, h - 3, 5, 5); } if (!drawingList && labelRects != null && index < labelRects.length) labelRects[index] = new Rectangle(x - 1, y - h + 2, w + 1, h); g.setColor(labelColor); g.drawString(label, x, y - 2); g.setColor(defaultColor); }
/** * A rendering method to draw this label to the given Graphics2D object, with the additional * option of allowing the "long" lines to be drawn. Due to the fact that the relative drawing * point of a state is its x and y co-ordinates and for a Transition there is a workOutMiddle() * method, the relative x and y values must be supplied to this method. Usually this method will * be called from inside a Transition render method or a State render method. * * @param g2 the Graphics2D component upon which to draw this label. * @param x the x position upon which to make relative co-ordinates exact. * @param y the y position upon which to make relative co-ordinates exact. * @param longLines flag to determine whether the long version of this label should be drawn. */ public void render(Graphics2D g2, double x, double y, boolean longLines) { intersects(new Rectangle2D.Double(0, 0, 1, 1)); StringTokenizer tokens = new StringTokenizer(getRenderString(), "\n"); if (selected) { g2.setColor(Color.green); } else { g2.setColor(theColour); } g2.setFont(theFont); int i = 0; boolean doneLong = false; while (tokens.hasMoreTokens()) { if (doneLong) g2.drawString( tokens.nextToken(), (float) (x + offsetX), (float) (y + offsetY + ((i * (theFont.getSize() + 2))))); else { if (!longLines) g2.drawString( tokens.nextToken().trim(), (float) (x + offsetX), (float) (y + offsetY + ((i * (theFont.getSize()))) + 2)); else g2.drawString( getName() + ": " + tokens.nextToken().trim(), (float) (x + offsetX), (float) (y + offsetY + ((i * (theFont.getSize()))) + 2)); } i++; doneLong = true; } /*if(intersects != null) { g2.setColor(Color.magenta); for(int j = 0; j < intersects.size(); j++) { Rectangle2D rect = (Rectangle2D)intersects.get(j); g2.draw(rect); } }*/ }
/** * Set current font. Default to Plain Courier 11 if null. * * @param font new font. */ public void setFont(Font font) { if (font != null) { m_localGraphicsState.setFont(font); if (font.getName().equals(m_psGraphicsState.getFont().getName()) && (m_psGraphicsState.getFont().getStyle() == font.getStyle()) && (m_psGraphicsState.getFont().getSize() == yScale(font.getSize()))) return; m_psGraphicsState.setFont( new Font(font.getName(), font.getStyle(), yScale(getFont().getSize()))); } else { m_localGraphicsState.setFont(new Font("Courier", Font.PLAIN, 11)); m_psGraphicsState.setFont(getFont()); } m_printstream.println("/(" + replacePSFont(getFont().getPSName()) + ")" + " findfont"); m_printstream.println(yScale(getFont().getSize()) + " scalefont setfont"); }