public void drawScaledImage(BufferedImage im, int x, int y, int w, int h) { float scaleX = w * 1.0f / im.getWidth(); float scaleY = h * 1.0f / im.getHeight(); AffineTransform tx = new AffineTransform(); tx.scale(scaleX, scaleY); BufferedImageOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); drawImage(im, op, x, y); }
private AffineTransform makeTransform(Object o) { AffineTransform r = (AffineTransform) ((AffineTransform) o).clone(); // System.out.println("r:"+r); if (origTransform != null) { AffineTransform r2 = (AffineTransform) origTransform.clone(); // System.out.println("r2:"+r2); r2.concatenate(r); r = r2; } return r; }
/** * synchronize frame shape and location (TextLayout only) ; this is called by syncShape(), so that * subclasser might override easily when only rectangular shapes are availables. */ protected void syncFrame() { PicText te = (PicText) element; if (!te.isFramed()) { return; } AffineTransform tr = new AffineTransform(); // maps Image coordinates to Model coordinates (see paint) tr.setToIdentity(); // reset PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf); tr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR ! shape = tr.createTransformedShape(te.getShapeOfFrame()); }
/** * This implementation calls <code>super.hitTest</code> and returns the result if non-null (this * should be a HitInfo.Point), then returns a HitInfo.Interior if the mouse-click occured inside * the text bound (as defined by text layout) * * @return a HitInfo corresponding to the given mouse-event */ public HitInfo hitTest(PEMouseEvent e) { // from Bitmap: if (image != null) { if (getBounds().contains(e.getPicPoint())) { return new HitInfo.Interior((PicText) element, e); } return null; } // from TextLayout: if (!getBounds().contains(e.getPicPoint())) return null; PicText te = (PicText) element; // recompute textlayout b-box, but store it in a temporary field ! Rectangle2D tb = textLayout.getBounds(); Shape text_bounds = text2ModelTr.createTransformedShape(tb); if (text_bounds.contains(e.getPicPoint())) { // [SR:pending] for the hitInfo to be reliable, getPicPoint() should first be transformed by // inverse text2ModelTr ! (especially when rotationAngle != 0) TextHitInfo thi = textLayout.hitTestChar( (float) (e.getPicPoint().x - strx), (float) (e.getPicPoint().y - stry)); // guaranteed to return a non-null thi return new HitInfo.Text((PicText) element, thi, e); } // test hit on textlayout's bounding rectangle : // else if (bounds.contains(e.getPicPoint())) return new HitInfo.Interior(element,e); return null; }
public void setFontSize(float size) { // FONT_SIZE.basicSet(this, new Double(size)); Point2D.Double p = new Point2D.Double(0, size); AffineTransform tx = TRANSFORM.get(this); if (tx != null) { try { tx.inverseTransform(p, p); Point2D.Double p0 = new Point2D.Double(0, 0); tx.inverseTransform(p0, p0); p.y -= p0.y; } catch (NoninvertibleTransformException ex) { ex.printStackTrace(); } } FONT_SIZE.set(this, Math.abs(p.y)); }
public float getFontSize() { // return FONT_SIZE.get(this).floatValue(); Point2D.Double p = new Point2D.Double(0, FONT_SIZE.get(this)); AffineTransform tx = TRANSFORM.get(this); if (tx != null) { tx.transform(p, p); Point2D.Double p0 = new Point2D.Double(0, 0); tx.transform(p0, p0); p.y -= p0.y; /* try { tx.inverseTransform(p, p); } catch (NoninvertibleTransformException ex) { ex.printStackTrace(); }*/ } return (float) Math.abs(p.y); }
/** Synchronizes bounding box with the model ; */ protected void syncBounds() { PicText te = (PicText) element; // [pending] Il faut tenir compte de la rotation ! Rectangle2D latexBB = null; // BB relative to latex dimensions (including rotation) (without frame) Rectangle2D textLayoutBB = null; // BB relative to textLayout dimensions (including rotation) (without frame) Rectangle2D textBB = null; // BB of the text (including rotation), without frame if (areDimensionsComputed) { // compute latexBB Rectangle2D nonRotated = new Rectangle2D.Double( te.getLeftX(), te.getBottomY(), te.getWidth(), te.getHeight() + te.getDepth()); AffineTransform tr = new AffineTransform(); // maps Image coordinates to Model coordinates (see paint) tr.setToIdentity(); // reset PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf); tr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR ! latexBB = tr.createTransformedShape(nonRotated).getBounds2D(); } if (image == null) { // compute textLayoutBB Rectangle2D nonRotated = textLayout.getBounds(); textLayoutBB = text2ModelTr.createTransformedShape(nonRotated).getBounds2D(); } // use textLayoutBB or latexBB or their union if (image != null) textBB = latexBB; else { if (!areDimensionsComputed) textBB = textLayoutBB; else { textBB = latexBB.createUnion(textLayoutBB); } } // union with frame BB if (te.isFramed()) { super.syncBounds(); // update bounds of the frame if necessary Rectangle2D.union(super.bounds, textBB, this.bounds); } else this.bounds = textBB; }
/** * Transforms the figure. * * @param tx the transformation. */ public void transform(AffineTransform tx) { if (TRANSFORM.get(this) != null || tx.getType() != (tx.getType() & AffineTransform.TYPE_TRANSLATION)) { if (TRANSFORM.get(this) == null) { TRANSFORM.basicSet(this, (AffineTransform) tx.clone()); } else { AffineTransform t = TRANSFORM.getClone(this); t.preConcatenate(tx); TRANSFORM.basicSet(this, t); } } else { for (int i = 0; i < coordinates.length; i++) { tx.transform(coordinates[i], coordinates[i]); } if (FILL_GRADIENT.get(this) != null && !FILL_GRADIENT.get(this).isRelativeToFigureBounds()) { Gradient g = FILL_GRADIENT.getClone(this); g.transform(tx); FILL_GRADIENT.basicSet(this, g); } if (STROKE_GRADIENT.get(this) != null && !STROKE_GRADIENT.get(this).isRelativeToFigureBounds()) { Gradient g = STROKE_GRADIENT.getClone(this); g.transform(tx); STROKE_GRADIENT.basicSet(this, g); } } invalidate(); }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.translate(x, y); g2.setStroke(new BasicStroke(BORDER_WIDTH)); g2.setPaint(LINE_COLOR); g2.draw(BORDER); g2.setStroke(new BasicStroke(SLIT_WIDTH)); g2.setColor(UIManager.getColor("Panel.background")); int n = SLIT_NUM + 1; int v = ICON_SIZE / n; int m = n * v; for (int i = 1; i < n; i++) { int a = i * v; g2.drawLine(a, 0, a, m); g2.drawLine(0, a, m, a); } // g2.drawLine(1 * v, 0 * v, 1 * v, 4 * v); // g2.drawLine(2 * v, 0 * v, 2 * v, 4 * v); // g2.drawLine(3 * v, 0 * v, 3 * v, 4 * v); // g2.drawLine(0 * v, 1 * v, 4 * v, 1 * v); // g2.drawLine(0 * v, 2 * v, 4 * v, 2 * v); // g2.drawLine(0 * v, 3 * v, 4 * v, 3 * v); g2.setPaint(LINE_COLOR); Rectangle2D b = ARROW.getBounds(); Point2D p = new Point2D.Double(b.getX() + b.getWidth() / 2d, b.getY() + b.getHeight() / 2d); AffineTransform toCenterAT = AffineTransform.getTranslateInstance(ICON_SIZE / 2d - p.getX(), ICON_SIZE / 2d - p.getY()); g2.fill(toCenterAT.createTransformedShape(ARROW)); g2.dispose(); }
public void drawPage(Graphics2D g2, PageFormat pf, int page) { if (message.equals("")) return; page--; // account for cover page drawCropMarks(g2, pf); g2.clip(new Rectangle2D.Double(0, 0, pf.getImageableWidth(), pf.getImageableHeight())); g2.translate(-page * pf.getImageableWidth(), 0); g2.scale(scale, scale); FontRenderContext context = g2.getFontRenderContext(); Font f = new Font("Serif", Font.PLAIN, 72); TextLayout layout = new TextLayout(message, f, context); AffineTransform transform = AffineTransform.getTranslateInstance(0, layout.getAscent()); Shape outline = layout.getOutline(transform); g2.draw(outline); }
/** * Synchronize the textLayout and the shape (=frame box, by calling syncFrame) with the model When * <code>TextLayout</code> is used, this delegates to <code>getRotation()</code> where computing * rotation angle is concerned, and updates the AffineTransform returned by <code> * getTextToModelTransform()</code>. */ protected void syncShape() { PicText te = (PicText) element; // textLayout = new TextLayout(te.getText().length()==0 ? " " : te.getText(), // textFont, // new FontRenderContext(null,false,false)); text2ModelTr.setToIdentity(); // reset PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf); text2ModelTr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR ! // the reference point of an image is the top-left one, but the refpoint of a text layout is on // the baseline if (image != null) { text2ModelTr.translate(te.getLeftX(), te.getTopY()); if (te.getWidth() != 0 && image.getWidth() != 0 && (te.getDepth() + te.getHeight()) != 0 && image.getHeight() != 0) text2ModelTr.scale( te.getWidth() / image.getWidth(), -(te.getHeight() + te.getDepth()) / image.getHeight()); } else { // Hack ? Just cheating a little bit ? Ou juste ruse ? // we want here to use the dimensions of the textLayout instead of latex dimensions if // areDimensionsComputed // sinon on va aligner le textlayout en fonction des parametres latex, et l'Utilisateur (qui // est bien bete) ne va rien comprendre. double latexH = 0; double latexD = 0; double latexW = 0; if (areDimensionsComputed) { // store latex dimensions, and setDimensions to textLayout ones latexH = te.getHeight(); latexD = te.getDepth(); latexW = te.getWidth(); te.setDimensions( textLayout.getBounds().getWidth(), textLayout.getAscent(), textLayout.getDescent()); } text2ModelTr.translate(te.getLeftX(), te.getBaseLineY()); if (areDimensionsComputed) { // restore latex dimensions te.setDimensions(latexW, latexH, latexD); } // Autre possibilite= comprimer le texte pour qu'il rentre dans la boite (evite le hack // ci-dessus): // text2ModelTr.scale(te.getWidth()/textLayout.getWidth(),-(te.getHeight()+te.getDepth())/textLayout.getHeight()); text2ModelTr.scale(1.0, -1.0); } syncFrame(); }
// --------------------------------------------------------- private synchronized AffineTransform bufferTransform() { AffineTransform r = new AffineTransform(); for (int i = 0; i < a1.size(); i++) { int s1 = a1.get(i); Object s2 = a2.get(i); Object s3[] = null; if (s2 instanceof Object[]) s3 = (Object[]) s2; if (s1 == setTransform) { r = makeTransform(s2); } if (s1 == shear) r.shear((Double) s3[0], (Double) s3[1]); if (s1 == rotate1) r.rotate((Double) s2); if (s1 == rotate2) r.rotate((Double) s3[0], (Double) s3[1], (Double) s3[2]); if (s1 == scale1) r.scale((Double) s3[0], (Double) s3[1]); if (s1 == translate1) r.translate((Double) s3[0], (Double) s3[1]); if (s1 == translate2) r.translate((Integer) s3[0], (Integer) s3[1]); } return r; }
private Shape getTextShape() { if (cachedTextShape == null) { String text = getText(); if (text == null || text.length() == 0) { text = " "; } FontRenderContext frc = getFontRenderContext(); HashMap<TextAttribute, Object> textAttributes = new HashMap<TextAttribute, Object>(); textAttributes.put(TextAttribute.FONT, getFont()); if (FONT_UNDERLINE.get(this)) { textAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); } TextLayout textLayout = new TextLayout(text, textAttributes, frc); AffineTransform tx = new AffineTransform(); tx.translate(coordinates[0].x, coordinates[0].y); switch (TEXT_ANCHOR.get(this)) { case END: tx.translate(-textLayout.getAdvance(), 0); break; case MIDDLE: tx.translate(-textLayout.getAdvance() / 2d, 0); break; case START: break; } tx.rotate(rotates[0]); /* if (TRANSFORM.get(this) != null) { tx.preConcatenate(TRANSFORM.get(this)); }*/ cachedTextShape = tx.createTransformedShape(textLayout.getOutline(tx)); cachedTextShape = textLayout.getOutline(tx); } return cachedTextShape; }
public void paintComponent(Graphics g1) { Graphics2D g = (Graphics2D) g1; float width = getWidth(); float height = getHeight(); AffineTransform save = g.getTransform(); AffineTransform save_tmp; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (45.0 <= rotate && rotate < 135.0) { g.translate(width, 0.0); g.rotate(Math.PI * rotate / 180, 0.0, 0.0); g.transform( AffineTransform.getScaleInstance(height / original_width, width / original_height)); } else if (135.0 <= rotate && rotate < 225.0) { g.rotate(Math.PI * rotate / 180, width / 2, height / 2); g.transform( AffineTransform.getScaleInstance(width / original_width, height / original_height)); } else if (225.0 <= rotate && rotate < 315.0) { g.translate(-height, 0.0); g.rotate(Math.PI * rotate / 180, height, 0.0); g.transform( AffineTransform.getScaleInstance(height / original_width, width / original_height)); } else g.transform( AffineTransform.getScaleInstance(width / original_width, height / original_height)); g.setColor( GeColor.getColor( 22, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, fillColor, false)); g.fill(shapes[0]); g.setColor( GeColor.getColor( 20, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, fillColor, false)); g.fill(shapes[1]); g.setColor( GeColor.getColor( 23, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, fillColor, false)); g.fill(shapes[2]); g.setStroke(new BasicStroke(1F)); g.setColor( GeColor.getColor( 0, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, false)); g.draw(shapes[3]); g.setColor(Color.black); g.setFont(annot1Font); save_tmp = g.getTransform(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g.transform( AffineTransform.getScaleInstance(original_width / width * height / original_height, 1)); g.drawString(annot1, 13 * original_height / height * width / original_width, 22F); g.setTransform(save_tmp); g.setTransform(save); }
// SHAPE AND BOUNDS @Override public void transform(AffineTransform tx) { tx.transform(origin, origin); }
public void paintComponent(Graphics g1) { Graphics2D g = (Graphics2D) g1; float width = getWidth(); float height = getHeight(); AffineTransform save = g.getTransform(); AffineTransform save_tmp; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (45.0 <= rotate && rotate < 135.0) { g.translate(width, 0.0); g.rotate(Math.PI * rotate / 180, 0.0, 0.0); g.transform( AffineTransform.getScaleInstance(height / original_width, width / original_height)); } else if (135.0 <= rotate && rotate < 225.0) { g.rotate(Math.PI * rotate / 180, width / 2, height / 2); g.transform( AffineTransform.getScaleInstance(width / original_width, height / original_height)); } else if (225.0 <= rotate && rotate < 315.0) { g.translate(-height, 0.0); g.rotate(Math.PI * rotate / 180, height, 0.0); g.transform( AffineTransform.getScaleInstance(height / original_width, width / original_height)); } else g.transform( AffineTransform.getScaleInstance(width / original_width, height / original_height)); g.setStroke(new BasicStroke(2F)); g.setColor( GeColor.getColor( 30, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, false)); g.draw(shapes[0]); g.setStroke(new BasicStroke(2F)); g.setColor( GeColor.getColor( 32, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, false)); g.draw(shapes[1]); g.setStroke(new BasicStroke(2F)); g.setColor( GeColor.getColor( 32, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, false)); g.draw(shapes[2]); g.setStroke(new BasicStroke(2F)); g.setColor( GeColor.getColor( 33, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, false)); g.draw(shapes[3]); g.setStroke(new BasicStroke(2F)); g.setColor( GeColor.getColor( 33, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, false)); g.draw(shapes[4]); g.setStroke(new BasicStroke(2F)); g.setColor( GeColor.getColor( 32, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, false)); g.draw(shapes[5]); g.setStroke(new BasicStroke(2F)); g.setColor( GeColor.getColor( 30, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, false)); g.draw(shapes[6]); g.setStroke(new BasicStroke(2F)); g.setColor( GeColor.getColor( 33, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, false)); g.draw(shapes[7]); g.setStroke(new BasicStroke(2F)); g.setColor( GeColor.getColor( 32, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, false)); g.draw(shapes[8]); g.setStroke(new BasicStroke(2F)); g.setColor( GeColor.getColor( 30, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, false)); g.draw(shapes[9]); g.setStroke(new BasicStroke(2F)); g.setColor( GeColor.getColor( 32, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, false)); g.draw(shapes[10]); g.setStroke(new BasicStroke(2F)); g.setColor( GeColor.getColor( 32, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, false)); g.draw(shapes[11]); g.setTransform(save); }
public void paintComponent(Graphics g1) { animationCount = 1; if (!visible) return; Graphics2D g = (Graphics2D) g1; float width = getWidth(); float height = getHeight(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (45.0 <= rotate && rotate < 135.0) { g.translate(width, 0.0); g.rotate(Math.PI * rotate / 180, 0.0, 0.0); g.transform( AffineTransform.getScaleInstance(height / original_width, width / original_height)); } else if (135.0 <= rotate && rotate < 225.0) { g.rotate(Math.PI * rotate / 180, width / 2, height / 2); g.transform( AffineTransform.getScaleInstance(width / original_width, height / original_height)); } else if (225.0 <= rotate && rotate < 315.0) { g.translate(-height, 0.0); g.rotate(Math.PI * rotate / 180, height, 0.0); g.transform( AffineTransform.getScaleInstance(height / original_width, width / original_height)); } else g.transform( AffineTransform.getScaleInstance(width / original_width, height / original_height)); if ((dd.dynType & GeDyn.mDynType_Rotate) != 0 && dd.rotate != 0) { g.rotate( Math.PI * dd.rotate / 180, (dd.x0 - getX()) * original_width / width, (dd.y0 - getY()) * original_height / height); } AffineTransform save = g.getTransform(); AffineTransform save_tmp; int rounds = 1; if (fillLevel != 1F) rounds = 2; int oldColor = 0; for (int i = 0; i < rounds; i++) { if (rounds == 2) { switch (i) { case 0: if (levelColorTone != GeColor.COLOR_TONE_NO) { oldColor = colorTone; colorTone = levelColorTone; } else if (levelFillColor != GeColor.COLOR_NO) { oldColor = fillColor; fillColor = levelFillColor; } break; case 1: if (levelColorTone != GeColor.COLOR_TONE_NO) colorTone = oldColor; else if (levelFillColor != GeColor.COLOR_NO) fillColor = oldColor; break; } switch (levelDirection) { case Ge.DIRECTION_UP: if (i == 0) g.setClip( new Rectangle2D.Float( 0F, fillLevel * original_height + Ge.cJBean_Offset, original_width, original_height)); else g.setClip( new Rectangle2D.Float( 0F, 0F, original_width, fillLevel * original_height + Ge.cJBean_Offset)); break; case Ge.DIRECTION_DOWN: if (i == 0) g.setClip( new Rectangle2D.Float( 0F, 0F, original_width, (1 - fillLevel) * original_height + Ge.cJBean_Offset)); else g.setClip( new Rectangle2D.Float( 0F, (1 - fillLevel) * original_height + Ge.cJBean_Offset, original_width, original_height)); break; case Ge.DIRECTION_RIGHT: if (i == 0) g.setClip( new Rectangle2D.Float( fillLevel * original_width + Ge.cJBean_Offset, 0F, original_width, original_height)); else g.setClip( new Rectangle2D.Float(0F, 0F, fillLevel * width + Ge.cJBean_Offset, height)); break; case Ge.DIRECTION_LEFT: if (i == 0) g.setClip( new Rectangle2D.Float( 0F, 0F, (1 - fillLevel) * original_width + Ge.cJBean_Offset, original_height)); else g.setClip( new Rectangle2D.Float( (1 - fillLevel) * original_width + Ge.cJBean_Offset, 0F, original_width, original_height)); break; } } { int fcolor = GeColor.getDrawtype( 293, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, fillColor, dimmed); if (gradient == GeGradient.eGradient_No) { g.setColor(GeColor.getColor(fcolor)); g.fill(shapes[0]); } else { GeGradient.paint( g, gradient, 2, -2, 2F, 2F, 13.6808F, 14.8208F, false, 293, colorTone, colorShift, colorIntensity, colorInverse, fillColor, dimmed); g.fill(shapes[0]); } if (shadow != 0) { g.setColor(GeColor.shiftColor(fcolor, -2, colorInverse)); g.fill(shapes[1]); g.setColor(GeColor.shiftColor(fcolor, 2, colorInverse)); g.fill(shapes[2]); } g.setStroke(new BasicStroke(1F)); g.setColor( GeColor.getColor( 0, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, dimmed)); g.draw(shapes[0]); } } if (rounds == 2) g.setClip(null); g.setTransform(save); }
public void paintComponent(Graphics g1) { Graphics2D g = (Graphics2D) g1; float width = getWidth(); float height = getHeight(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); double scaleWidth = (1.0 * width / original_width); double scaleHeight = (1.0 * height / original_height); AffineTransform save = g.getTransform(); g.setColor(getBackground()); g.fill(new Rectangle(0, 0, getWidth(), getHeight())); g.transform(AffineTransform.getScaleInstance(scaleWidth, scaleHeight)); // scaletest AffineTransform save_tmp; g.setColor( GeColor.getColor( 0, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, textColor, dimmed)); g.setFont(new Font("Helvetica", Font.BOLD, 12)); g.drawString(JopLang.transl("Status"), 13, 91); g.setColor( GeColor.getColor( 0, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, textColor, dimmed)); g.setFont(new Font("Helvetica", Font.BOLD, 12)); g.drawString(JopLang.transl("LogMessage"), 13, 114); g.setColor( GeColor.getColor( 0, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, textColor, dimmed)); g.setFont(new Font("Helvetica", Font.BOLD, 12)); g.drawString(JopLang.transl("EventListSize"), 13, 23); g.setColor( GeColor.getColor( 0, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, textColor, dimmed)); g.setFont(new Font("Helvetica", Font.BOLD, 12)); g.drawString(JopLang.transl("EventLogSize"), 13, 44); g.setColor( GeColor.getColor( 0, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, textColor, dimmed)); g.setFont(new Font("Helvetica", Font.BOLD, 12)); g.drawString(JopLang.transl("MaxApplAlarms"), 13, 67); g.setTransform(save); }
public AffineTransform getAffineTransform( int width, int height, double[] _xyzSW, double[] _xyzSE, double[] _xyzNW) { int[] cornerNW = projection.screenProjection(_xyzNW); int[] cornerSE = projection.screenProjection(_xyzSE); int[] cornerSW = projection.screenProjection(_xyzSW); double[] vectWE = { (double) cornerSE[0] - (double) cornerSW[0], (double) cornerSE[1] - (double) cornerSW[1] }; double normvectWE = sqrt(sqr(vectWE[0]) + sqr(vectWE[1])); double[] vectSN = { (double) cornerNW[0] - (double) cornerSW[0], (double) cornerNW[1] - (double) cornerSW[1] }; double normvectSN = sqrt(sqr(vectSN[0]) + sqr(vectSN[1])); double angleSW = acos((vectWE[0] * vectSN[0] + vectWE[1] * vectSN[1]) / (normvectWE * normvectSN)); if (angleSW == 0.0) { return null; } AffineTransform t = new AffineTransform(); t.translate(cornerNW[0], cornerNW[1]); t.scale(sign(vectWE[0]), -sign(vectSN[1])); t.rotate(-atan(vectSN[0] / vectSN[1])); t.shear(0, 1 / tan(PI - angleSW)); t.scale(normvectWE * cos(angleSW - PI / 2) / (double) width, normvectSN / (double) height); double[] _cornerSE_tr = new double[2]; double[] _cornerSE = {width, height}; t.transform(_cornerSE, 0, _cornerSE_tr, 0, 1); if (isDiff(_cornerSE_tr, cornerSE)) { double[] vectSE_NW_1 = { (double) cornerNW[0] - (double) cornerSE[0], (double) cornerNW[1] - (double) cornerSE[1] }; double[] vectSE_NW_2 = { (double) cornerNW[0] - (double) _cornerSE_tr[0], (double) cornerNW[1] - (double) _cornerSE_tr[1] }; double normvect_1 = sqrt(sqr(vectSE_NW_1[0]) + sqr(vectSE_NW_1[1])); double normvect_2 = sqrt(sqr(vectSE_NW_1[0]) + sqr(vectSE_NW_1[1])); double cos_angle = (((vectSE_NW_1[0] * vectSE_NW_2[0] + vectSE_NW_1[1] * vectSE_NW_2[1]) / (normvect_1 * normvect_2))); double vect = (vectSE_NW_1[0] * vectSE_NW_2[1] - vectSE_NW_1[1] * vectSE_NW_2[0]); AffineTransform t2 = new AffineTransform(); if (vect < 0) { t2.rotate(acos(cos_angle), cornerNW[0], cornerNW[1]); } else { t2.rotate(-acos(cos_angle), cornerNW[0], cornerNW[1]); } t.preConcatenate(t2); } // TODO patch for many cases... /*double[] _cornerSW_tr = new double[2]; double[] _cornerSW = { 0, img.getHeight(canvas) }; t.transform(_cornerSW, 0, _cornerSW_tr, 0, 1); if (isDiff(_cornerSW_tr, cornerSW)) { double[] vectSW_NW_1 = { (double) cornerNW[0] - (double) cornerSW[0], (double) cornerNW[1] - (double) cornerSW[1] }; double[] vectSW_NW_2 = { (double) cornerNW[0] - (double) _cornerSW_tr[0], (double) cornerNW[1] - (double) _cornerSW_tr[1] }; double normvect_1 = sqrt(sqr(vectSW_NW_1[0]) + sqr(vectSW_NW_1[1])); double normvect_2 = sqrt(sqr(vectSW_NW_1[0]) + sqr(vectSW_NW_1[1])); double cos_angle = (((vectSW_NW_1[0] * vectSW_NW_2[0] + vectSW_NW_1[1] * vectSW_NW_2[1]) / (normvect_1 * normvect_2))); double vect = (vectSW_NW_1[0] * vectSW_NW_2[1] - vectSW_NW_1[1] * vectSW_NW_2[0]); System.out.println(cos_angle + " " + vect + " -> " + toDegrees(acos(cos_angle))); //System.out.println(" "+vectSE_NW_1[0]+","+vectSE_NW_1[1]+" "+vectSE_NW_2[0]+","+vectSE_NW_2[1]); AffineTransform t2 = new AffineTransform(); if (vect > 0) t2.rotate(acos(cos_angle), cornerNW[0], cornerNW[1]); else t2.rotate(-acos(cos_angle), cornerNW[0], cornerNW[1]); t.preConcatenate(t2); }*/ return t; }
public void drawScaledImage(BufferedImage im, int x, int y, float scale) { AffineTransform tx = new AffineTransform(); tx.scale(scale, scale); BufferedImageOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); drawImage(im, op, x, y); }
// Thread's run method aimed at creating a bitmap asynchronously public void run() { Drawing drawing = new Drawing(); PicText rawPicText = new PicText(); String s = ((PicText) element).getText(); rawPicText.setText(s); drawing.add( rawPicText); // bug fix: we must add a CLONE of the PicText, otherwise it loses it former // parent... (then pb with the view ) drawing.setNotparsedCommands( "\\newlength{\\jpicwidth}\\settowidth{\\jpicwidth}{" + s + "}" + CR_LF + "\\newlength{\\jpicheight}\\settoheight{\\jpicheight}{" + s + "}" + CR_LF + "\\newlength{\\jpicdepth}\\settodepth{\\jpicdepth}{" + s + "}" + CR_LF + "\\typeout{JPICEDT INFO: \\the\\jpicwidth, \\the\\jpicheight, \\the\\jpicdepth }" + CR_LF); RunExternalCommand.Command commandToRun = RunExternalCommand.Command.BITMAP_CREATION; // RunExternalCommand command = new RunExternalCommand(drawing, contentType,commandToRun); boolean isWriteTmpTeXfile = true; String bitmapExt = "png"; // [pending] preferences String cmdLine = "{i}/unix/tetex/create_bitmap.sh {p} {f} " + bitmapExt + " " + fileDPI; // [pending] preferences ContentType contentType = getContainer().getContentType(); RunExternalCommand.isGUI = false; // System.out, no dialog box // [pending] debug RunExternalCommand command = new RunExternalCommand(drawing, contentType, cmdLine, isWriteTmpTeXfile); command .run(); // synchronous in an async. thread => it's ok (anyway, we must way until the LaTeX // process has completed) if (wantToComputeLatexDimensions) { // load size of text: try { File logFile = new File(command.getTmpPath(), command.getTmpFilePrefix() + ".log"); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(logFile)); } catch (FileNotFoundException fnfe) { System.out.println("Cannot find log file! " + fnfe.getMessage()); System.out.println(logFile); } catch (IOException ioex) { System.out.println("Log file IO exception"); ioex.printStackTrace(); } // utile ? System.out.println("Log file created! file=" + logFile); getDimensionsFromLogFile(reader, (PicText) element); syncStringLocation(); // update dimensions syncBounds(); syncFrame(); SwingUtilities.invokeLater( new Thread() { public void run() { repaint(null); } }); // repaint(null); // now that dimensions are available, we force a repaint() [pending] // smart-repaint ? } catch (Exception e) { e.printStackTrace(); } } if (wantToGetBitMap) { // load image: try { File bitmapFile = new File(command.getTmpPath(), command.getTmpFilePrefix() + "." + bitmapExt); this.image = ImageIO.read(bitmapFile); System.out.println( "Bitmap created! file=" + bitmapFile + ", width=" + image.getWidth() + "pixels, height=" + image.getHeight() + "pixels"); if (image == null) return; syncStringLocation(); // sets strx, stry, and dimensions of text syncBounds(); // update the AffineTransform that will be applied to the bitmap before displaying on screen PicText te = (PicText) element; text2ModelTr.setToIdentity(); // reset PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf); text2ModelTr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR ! text2ModelTr.translate(te.getLeftX(), te.getTopY()); text2ModelTr.scale( te.getWidth() / image.getWidth(), -(te.getHeight() + te.getDepth()) / image.getHeight()); // [pending] should do something special to avoid dividing by 0 or setting a rescaling // factor to 0 [non invertible matrix] (java will throw an exception) syncFrame(); SwingUtilities.invokeLater( new Thread() { public void run() { repaint(null); } }); // repaint(null); // now that bitmap is available, we force a repaint() [pending] // smart-repaint ? } catch (Exception e) { e.printStackTrace(); } } }