public Rectangle2D getBounds2D() { StringTokenizer tokens = new StringTokenizer(getRenderString(), "\n"); int noLines = tokens.countTokens(); double height = (theFont.getSize2D() * noLines) + 5; double width = 0; while (tokens.hasMoreTokens()) { double l = theFont.getSize2D() * tokens.nextToken().length() * (5.0 / 8.0); if (l > width) width = l; } double parX; double parY; if (parent instanceof State) { parX = ((State) parent).getX(); parY = ((State) parent).getY(); } else if (parent instanceof Transition) { parX = ((Transition) parent).getMiddle().getX(); // dummy parY = ((Transition) parent).getMiddle().getY(); // dummy } else { parX = 0; parY = 0; } double mx = parX + offsetX; double my = parY + offsetY - 10; double tx = parX + width + offsetX; double ty = parY + height + offsetY - 10; return new Rectangle2D.Double(mx, my, tx - mx, ty - my); }
public void workOutMinsAndMaxs() { StringTokenizer tokens = new StringTokenizer(getRenderString(), "\n"); int noLines = tokens.countTokens(); double height = (theFont.getSize2D() * noLines) + 5; double width = 0; while (tokens.hasMoreTokens()) { double l = theFont.getSize2D() * tokens.nextToken().length() * (5.0 / 8.0); if (l > width) width = l; } double parX; double parY; if (parent instanceof State) { parX = ((State) parent).getX(); parY = ((State) parent).getY(); } else if (parent instanceof Transition) { parX = ((Transition) parent).getMiddle().getX(); // dummy parY = ((Transition) parent).getMiddle().getY(); // dummy } else { parX = 0; parY = 0; } minX = parX + offsetX - 5; minY = parY + offsetY - 25; maxX = parX + width + offsetX + 5; maxY = parY + height + offsetY - 5; }
/* * (non-Javadoc) * * @see org.math.plot.render.AbstractDrawer#drawStringRatio(java.lang.String, * double[], double, double, double) */ public void drawTextBase(String label, double... rC) { int[] sC = projection.screenProjectionBase(rC); // Corner offset adjustment : Text Offset is used Here FontRenderContext frc = comp2D.getFontRenderContext(); Font font1 = comp2D.getFont(); int x = sC[0]; int y = sC[1]; double w = font1.getStringBounds(label, frc).getWidth(); double h = font1.getSize2D(); x -= (int) (w * text_Eastoffset); y += (int) (h * text_Northoffset); int wc = (int) (w * FastMath.cos(text_angle) + h * FastMath.sin(text_angle)); int hc = (int) (h * FastMath.cos(text_angle) + w * FastMath.sin(text_angle)); if (!comp2D.hitClip(x, y, wc, hc)) { return; } if (text_angle != 0) { comp2D.rotate(text_angle, x + w / 2, y - h / 2); } String[] lines = label.split("\n"); for (int i = 0; i < lines.length; i++) { comp2D.drawString(lines[i], x, y); y += h; } // comp2D.drawString(label, x, y); if (text_angle != 0) { comp2D.rotate(-text_angle, x + w / 2, y - h / 2); } }
/** * This method calculates whether a given "Hot area" rectangle intersects with this label and * returns the result. The aim of this method is that it can be used to detect whether the * position of the mouse is colliding with the label. * * @param rect A "Hot area" which we are looking for the collision to lie in. * @return the result of the collision. */ public boolean intersects(Rectangle2D rect) { intersects = new ArrayList(); if (!getString().equals("")) { double parX; double parY; if (parent instanceof State) { parX = ((State) parent).getX(); parY = ((State) parent).getY(); } else if (parent instanceof Transition) { parX = ((Transition) parent).getMiddle().getX(); // dummy parY = ((Transition) parent).getMiddle().getY(); // dummy } else { parX = 0; parY = 0; } double x = parX + offsetX; double y = parY + offsetY - 5; StringTokenizer tokens; String pre = ""; if (lineLabels) { pre = getName() + ": "; } tokens = new StringTokenizer(pre + getRenderString(), "\n"); int i = 0; boolean collides = false; while (tokens.hasMoreTokens() && !collides) { String str = tokens.nextToken().trim(); // System.out.println("str = \""+str+"\""); double height = theFont.getSize2D(); double width = theFont.getSize2D() * str.length() * (5.0 / 8.0); intersects.add(new Rectangle2D.Double(x, y + (i * (height + 1.75) - 2), width, height)); collides = (new Rectangle2D.Double(x, y + (i * (height + 1.75) - 2), width, height)) .intersects(rect); i++; } return collides; } else return false; }
public void drawShadowedText(String label, float alpha, double... pC) { int[] sC = projection.screenProjection(pC); // Corner offset adjustment : Text Offset is used Here FontRenderContext frc = comp2D.getFontRenderContext(); Font font1 = comp2D.getFont(); int x = sC[0]; int y = sC[1]; double w = font1.getStringBounds(label, frc).getWidth(); double h = font1.getSize2D(); x -= (int) (w * text_Eastoffset); y += (int) (h * text_Northoffset); int wc = (int) (w * FastMath.cos(text_angle) + h * FastMath.sin(text_angle)); int hc = (int) (h * FastMath.cos(text_angle) + w * FastMath.sin(text_angle)); if (!comp2D.hitClip(x, y, wc, hc)) { return; } if (text_angle != 0) { comp2D.rotate(text_angle, x + w / 2, y - h / 2); } Composite cs = comp2D.getComposite(); Color c = comp2D.getColor(); String[] lines = label.split("\n"); for (int i = 0; i < lines.length; i++) { comp2D.setColor(Color.white); comp2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); comp2D.fillRect(x, y - (int) h, (int) w, (int) h); comp2D.setComposite(cs); comp2D.setColor(c); comp2D.drawString(lines[i], x, y); y += h; } if (text_angle != 0) { comp2D.rotate(-text_angle, x + w / 2, y - h / 2); } }
/** Set the day-of-week labels' font. */ protected void setupDayOfWeekFonts() { Font font; if (dayOfWeekLabels == null) return; // If not null, use what the user gave us font = dayOfWeekFont; // Otherwise, use 9/11 of the L&F default for a label if (font == null) { font = UIManager.getFont("Label.font"); font = font.deriveFont((float) (font.getSize2D() * 9.0 / 11.0)); } // Set the day of week labels' font for (int day = 0; day < 7; day++) { dayOfWeekLabels[day].setFont(font); } }
/** Set the day labels' font. */ protected void setupDayFonts() { Font font; if (dayButtons == null) return; // If null, use what the user gave us font = dayFont; // Otherwise, use 9/11 of the L&F default for a button if (font == null) { font = UIManager.getFont("Button.font"); font = font.deriveFont((float) (font.getSize2D() * 9.0 / 11.0)); } // Set the day labels' font for (int row = 0; row < 6; row++) { for (int day = 0; day < 7; day++) { dayButtons[row][day].setFont(font); } } }