当前位置: 首页>>代码示例>>Java>>正文


Java AffineTransform.getRotateInstance方法代码示例

本文整理汇总了Java中java.awt.geom.AffineTransform.getRotateInstance方法的典型用法代码示例。如果您正苦于以下问题:Java AffineTransform.getRotateInstance方法的具体用法?Java AffineTransform.getRotateInstance怎么用?Java AffineTransform.getRotateInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.geom.AffineTransform的用法示例。


在下文中一共展示了AffineTransform.getRotateInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractRotation

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private static AffineTransform extractRotation(Point2D.Double pt,
    AffineTransform tx, boolean andTranslation) {

    tx.deltaTransform(pt, pt);
    AffineTransform rtx = AffineTransform.getRotateInstance(pt.x, pt.y);

    try {
        AffineTransform rtxi = rtx.createInverse();
        double dx = tx.getTranslateX();
        double dy = tx.getTranslateY();
        tx.preConcatenate(rtxi);
        if (andTranslation) {
            if (dx != 0 || dy != 0) {
                tx.setTransform(tx.getScaleX(), tx.getShearY(),
                                tx.getShearX(), tx.getScaleY(), 0, 0);
                rtx.setTransform(rtx.getScaleX(), rtx.getShearY(),
                                 rtx.getShearX(), rtx.getScaleY(), dx, dy);
            }
        }
    }
    catch (NoninvertibleTransformException e) {
        return null;
    }
    return rtx;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:AttributeValues.java

示例2: getLabelEnclosure

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
 * Returns a rectangle that encloses the axis label.  This is typically 
 * used for layout purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {

    Rectangle2D result = new Rectangle2D.Double();
    String axisLabel = getLabel();
    if (axisLabel != null && !axisLabel.equals("")) {
        FontMetrics fm = g2.getFontMetrics(getLabelFont());
        Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        RectangleInsets insets = getLabelInsets();
        bounds = insets.createOutsetRectangle(bounds);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer 
            = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }

    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:34,代码来源:Axis.java

示例3: medidaV

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private void medidaV(Graphics2D g, int l, int t) {
    FontMetrics fm = g.getFontMetrics();
    String vl = dono.FormateUnidadeMedida(height);
    int traco = width;
    int xIni = l;// + (traco) / 2;
    int xFim = xIni + traco;
    int yIni = t;
    int yFim = t + height;
    int xLin = l + (width / 2);

    g.drawLine(xIni, yIni, xFim, yIni);
    g.drawLine(xIni, yFim, xFim, yFim);
    g.drawLine(xLin, yIni, xLin, yFim);

    int degrees = isInvertido() ? 90 : -90;
    int desse = isInvertido() ? 0 : fm.stringWidth(vl);
    //int centra = fm.getHeight() / 2 - fm.getDescent();
    int centra = fm.getHeight() - fm.getDescent();
    centra = isInvertido() ? -centra : centra;

    AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(degrees));
    Font f = new Font(g.getFont().getName(), Font.BOLD, g.getFont().getSize());
    Font f2 = g.getFont();
    g.setFont(f.deriveFont(at));
    yIni = yIni + (height - fm.stringWidth(vl)) / 2 + desse;
    g.drawString(vl, xLin + centra, yIni);
    g.setFont(f2);
}
 
开发者ID:chcandido,项目名称:brModelo,代码行数:29,代码来源:baseDrawerItem.java

示例4: getGhostPosition

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private Point getGhostPosition() {
  final AffineTransform t =
    AffineTransform.getRotateInstance(-PI_180 * (tempAngle - getAngle()),
                                      pivot.x + centerX(),
                                      pivot.y + centerY());
  final Point2D newPos2D =
    new Point2D.Float(getPosition().x, getPosition().y);
  t.transform(newPos2D, newPos2D);
  return new Point((int) Math.round(newPos2D.getX()),
                   (int) Math.round(newPos2D.getY()));
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:12,代码来源:FreeRotator.java

示例5: pivotPoint

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
 * Pivot the given point around the pivot point from oldAngle to newAngle
 * @param oldAngle
 * @param newAngle
 */
private void pivotPoint(Point p, double oldAngle, double newAngle) {
  Point2D pivot2D = new Point2D.Double(pivotX, pivotY);
  AffineTransform t = AffineTransform.getRotateInstance(oldAngle);
  t.transform(pivot2D, pivot2D);
  t = AffineTransform.getRotateInstance(newAngle - oldAngle, pivot2D.getX(), pivot2D.getY());
  Point2D newPos2D = new Point2D.Float(0, 0);
  t.transform(newPos2D, newPos2D);
  p.x += (int) Math.round(newPos2D.getX());
  p.y += (int) Math.round(newPos2D.getY());
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:16,代码来源:Pivot.java

示例6: makeAT

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public static AffineTransform makeAT(Mode mode, Point2D txpt,
                                     double radians)
{
    AffineTransform at;
    double tx = (txpt == null) ? 0.0 : txpt.getX();
    double ty = (txpt == null) ? 0.0 : txpt.getY();
    switch (mode) {
    case GET:
        if (txpt != null) {
            at = AffineTransform.getRotateInstance(radians, tx, ty);
        } else {
            at = AffineTransform.getRotateInstance(radians);
        }
        break;
    case SET:
        at = makeRandomAT();
        if (txpt != null) {
            at.setToRotation(radians, tx, ty);
        } else {
            at.setToRotation(radians);
        }
        break;
    case MOD:
        at = makeRandomAT();
        at.setToIdentity();
        if (txpt != null) {
            at.rotate(radians, tx, ty);
        } else {
            at.rotate(radians);
        }
        break;
    default:
        throw new InternalError("unrecognized mode: "+mode);
    }

    return at;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:TestRotateMethods.java

示例7: paintString

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
 * Paints the progress string.
 *
 * @param g Graphics used for drawing.
 * @param x x location of bounding box
 * @param y y location of bounding box
 * @param width width of bounding box
 * @param height height of bounding box
 * @param fillStart start location, in x or y depending on orientation,
 *        of the filled portion of the progress bar.
 * @param amountFull size of the fill region, either width or height
 *        depending upon orientation.
 * @param b Insets of the progress bar.
 */
private void paintString(Graphics g, int x, int y, int width, int height,
                         int fillStart, int amountFull, Insets b) {
    if (!(g instanceof Graphics2D)) {
        return;
    }

    Graphics2D g2 = (Graphics2D)g;
    String progressString = progressBar.getString();
    g2.setFont(progressBar.getFont());
    Point renderLocation = getStringPlacement(g2, progressString,
                                              x, y, width, height);
    Rectangle oldClip = g2.getClipBounds();

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
        g2.setColor(getSelectionBackground());
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
        g2.setColor(getSelectionForeground());
        g2.clipRect(fillStart, y, amountFull, height);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
    } else { // VERTICAL
        g2.setColor(getSelectionBackground());
        AffineTransform rotate =
                AffineTransform.getRotateInstance(Math.PI/2);
        g2.setFont(progressBar.getFont().deriveFont(rotate));
        renderLocation = getStringPlacement(g2, progressString,
                                              x, y, width, height);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
        g2.setColor(getSelectionForeground());
        g2.clipRect(x, fillStart, width, amountFull);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
    }
    g2.setClip(oldClip);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:52,代码来源:BasicProgressBarUI.java

示例8: getLabelEnclosure

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
 * Returns a rectangle that encloses the axis label.  This is typically used for layout
 * purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {

    // calculate the width of the axis label...
    Rectangle2D result = new Rectangle2D.Double();
    String axisLabel = getLabel();
    if (axisLabel != null) {
        FontMetrics fm = g2.getFontMetrics(getLabelFont());
        Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        Insets insets = getLabelInsets();
        bounds.setRect(bounds.getX(), bounds.getY(),
                       bounds.getWidth() + insets.left + insets.right,
                       bounds.getHeight() + insets.top + insets.bottom);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }

    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:36,代码来源:Axis.java

示例9: paintText

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
 * Paints the component's text.
 *
 * @param context context for the component being painted
 * @param g {@code Graphics} object used for painting
 * @param title the text to paint
 */
protected void paintText(SynthContext context, Graphics g, String title) {
    if (progressBar.isStringPainted()) {
        SynthStyle style = context.getStyle();
        Font font = style.getFont(context);
        FontMetrics fm = SwingUtilities2.getFontMetrics(
                progressBar, g, font);
        int strLength = style.getGraphicsUtils(context).
            computeStringWidth(context, font, fm, title);
        Rectangle bounds = progressBar.getBounds();

        if (rotateText &&
                progressBar.getOrientation() == JProgressBar.VERTICAL){
            Graphics2D g2 = (Graphics2D)g;
            // Calculate the position for the text.
            Point textPos;
            AffineTransform rotation;
            if (progressBar.getComponentOrientation().isLeftToRight()){
                rotation = AffineTransform.getRotateInstance(-Math.PI/2);
                textPos = new Point(
                    (bounds.width+fm.getAscent()-fm.getDescent())/2,
                       (bounds.height+strLength)/2);
            } else {
                rotation = AffineTransform.getRotateInstance(Math.PI/2);
                textPos = new Point(
                    (bounds.width-fm.getAscent()+fm.getDescent())/2,
                       (bounds.height-strLength)/2);
            }

            // Progress bar isn't wide enough for the font.  Don't paint it.
            if (textPos.x < 0) {
                return;
            }

            // Paint the text.
            font = font.deriveFont(rotation);
            g2.setFont(font);
            g2.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
            style.getGraphicsUtils(context).paintText(context, g, title,
                                                 textPos.x, textPos.y, -1);
        } else {
            // Calculate the bounds for the text.
            Rectangle textRect = new Rectangle(
                (bounds.width / 2) - (strLength / 2),
                (bounds.height -
                    (fm.getAscent() + fm.getDescent())) / 2,
                0, 0);

            // Progress bar isn't tall enough for the font.  Don't paint it.
            if (textRect.y < 0) {
                return;
            }

            // Paint the text.
            g.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
            g.setFont(font);
            style.getGraphicsUtils(context).paintText(context, g, title,
                                                 textRect.x, textRect.y, -1);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:68,代码来源:SynthProgressBarUI.java

示例10: main

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public static void main (String[] args) {
    thresholdOp(low, high);
    int i = 1;
    RescaleOp resop = new RescaleOp(1.0f, 0, null);
    biop[i] = resop;
    rop[i] = resop;
    i++;

    byte invert[] = new byte[256];
    byte ordered[] = new byte[256];
    for (int j = 0; j < 256 ; j++) {
        invert[j] = (byte) (256-j);
        ordered[j] = (byte) j;
    }
    LookupOp lop = new LookupOp(new ByteLookupTable(0,invert), null);
    biop[i] = lop;
    rop[i] = lop;
    i++;

    byte[][] yellowInvert = new byte[][] { invert, invert, ordered };
    lop = new LookupOp(new ByteLookupTable(0,yellowInvert), null);
    biop[i] = lop;
    rop[i] = lop;
    i++;
    int dim[][] = {{3,3}, {3,3}, {3,3}, {5,5}};
    float data[][] = { {0.1f, 0.1f, 0.1f,              // 3x3 blur
                        0.1f, 0.2f, 0.1f,
                        0.1f, 0.1f, 0.1f},
                       {-1.0f, -1.0f, -1.0f,           // 3x3 sharpen
                        -1.0f, 9.0f, -1.0f,
                        -1.0f, -1.0f, -1.0f},
                       { 0.f, -1.f,  0.f,                  // 3x3 edge
                         -1.f,  5.f, -1.f,
                         0.f, -1.f,  0.f},
                       {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f,  // 5x5 edge
                        -1.0f, -1.0f, -1.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f, 24.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f, -1.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}};
    for (int j = 0; j < data.length; j++, i++) {
        ConvolveOp cop = new ConvolveOp(new Kernel(dim[j][0],dim[j][1],data[j]));
        biop[i] = cop;
        rop[i] = cop;
    }

    ColorSpace cs1 = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorSpace cs2 = ColorSpace.getInstance(ColorSpace.CS_PYCC);
    ColorConvertOp ccop = new ColorConvertOp(cs1, cs2, null);
    biop[i] = ccop;
    rop[i] = ccop;
    i++;

    AffineTransform at =
        AffineTransform.getRotateInstance(0.5*Math.PI, SIZE/2, SIZE/2);
    AffineTransformOp atOp =
        new AffineTransformOp(at, null);
    biop[i] = atOp;
    rop[i] = atOp;

    runTest();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:62,代码来源:ImagingOpsNoExceptionsTest.java

示例11: draw

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public void draw(Graphics g, GamePieceImage defn) {

    TextBoxItemInstance tbi = null;
    if (defn != null) {
      tbi = defn.getTextBoxInstance(getConfigureName());
    }
    if (tbi == null) {
      tbi = new TextBoxItemInstance();
    }

    Color fg = tbi.getFgColor().getColor();
    Color bg = tbi.getBgColor().getColor();

    Point origin = layout.getPosition(this);
    Rectangle r = new Rectangle(origin.x, origin.y, getWidth(), getHeight());
    String s = null;
    if (textSource.equals(SRC_FIXED)) {
      s = text;
    }
    else {
      if (defn != null) {
        if (tbi != null) {
          s = tbi.getValue();
        }
      }
    }

    Graphics2D g2d = ((Graphics2D) g);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, isAntialias() ?
      RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);

    AffineTransform saveXForm = null;
    if (getRotation() != 0) {
      saveXForm = g2d.getTransform();
      AffineTransform newXForm =
        AffineTransform.getRotateInstance(Math.toRadians(getRotation()), getLayout().getVisualizerWidth()/2, getLayout().getVisualizerHeight()/2);
      g2d.transform(newXForm);
    }

    if (bg != null) {
      g.setColor(bg);
      g.fillRect(r.x, r.y, r.width, r.height);
    }

    JTextPane l = new JTextPane();
    if (isHTML) l.setContentType("text/html"); //$NON-NLS-1$
    l.setText(s);
    l.setSize(width-2, height-2);
    l.setBackground(bg != null ? bg : new Color(0,true));
    l.setForeground(fg != null ? fg : new Color(0,true));
    FontStyle fs = FontManager.getFontManager().getFontStyle(fontStyleName);
    Font f = fs.getFont();
    l.setFont(f);

    final BufferedImage img = ImageUtils.createCompatibleTranslucentImage(
      Math.max(l.getWidth(), 1),
      Math.max(l.getHeight(), 1)
    );
    final Graphics2D big = img.createGraphics();
    l.paint(big);
    big.dispose();

    g2d.drawImage(img, origin.x+1, origin.y+1, null);

    if (saveXForm != null) {
      g2d.setTransform(saveXForm);
    }
  }
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:69,代码来源:TextBoxItem.java

示例12: draw

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public void draw(Graphics g, GamePieceImage defn) {

    TextItemInstance ti = null;

    FontStyle fs = FontManager.getFontManager().getFontStyle(fontStyleName);
    Font f = fs.getFont();

    if (defn != null) {
      ti = defn.getTextInstance(name);
    }
    else {
      defn = new GamePieceImage(getLayout());
      ti = defn.getTextInstance(name);
    }

    if (ti == null) {
      ti = new TextItemInstance();
    }

    Color fg = ti.getFgColor().getColor();
    Color bg = ti.getBgColor().getColor();
    if (fg == null && bg == null) {
      return;
    }

    boolean outline = ti.isOutline();
    Color ol = ti.getOutlineColor().getColor();

    String compass = GamePieceLayout.getCompassPoint(getLocation());
    int hAlign = AL_CENTER;
    switch (compass.charAt(compass.length()-1)) {
      case 'W':
        hAlign = AL_LEFT;
        break;
        case 'E':
        hAlign = AL_RIGHT;
    }
    int vAlign = AL_CENTER;
    switch (compass.charAt(0)) {
      case 'N':
        vAlign = AL_TOP;
        break;
        case 'S':
        vAlign = AL_BOTTOM;
    }

    Point origin = layout.getPosition(this);
    String s = null;
    if (textSource.equals(SRC_FIXED)) {
      s = text;
    }
    else {
      if (defn != null) {
        if (ti != null) {
          s = ti.getValue();
        }
      }
    }

    Graphics2D g2d = ((Graphics2D) g);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, isAntialias() ?
      RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);

    AffineTransform saveXForm = null;
    if (getRotation() != 0) {
      saveXForm = g2d.getTransform();
      AffineTransform newXForm =
        AffineTransform.getRotateInstance(Math.toRadians(getRotation()), getLayout().getVisualizerWidth()/2, getLayout().getVisualizerHeight()/2);
      g2d.transform(newXForm);
    }

    drawLabel(g, s, origin.x, origin.y, f, hAlign, vAlign, fg, bg, null, outline, ol);
    if (saveXForm != null) {
      g2d.setTransform(saveXForm);
    }
  }
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:77,代码来源:TextItem.java

示例13: bordaLeftRigth

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public void bordaLeftRigth(Graphics2D g, boolean isrigth) {
        FontMetrics fm = g.getFontMetrics();
        String vl = FormateUnidadeMedida(H);
        int pre_x = (isrigth ? getLeftWidth() : getLeft());
        int traco = largTraco < margem ? largTraco : margem;
        traco = (isrigth ? -traco : traco);
        int xIni = pre_x + (isrigth ? -2 : 2);
        int xFim = xIni + 2 * traco;
        int yIni = getTop() + margem;
        int yFim = getTopHeight() - margem;
        int xLin = xIni;
//        int pre_x = (isrigth ? getLeftWidth() - margem : getLeft());
//        int traco = largTraco < margem ? largTraco : margem;
//        int xIni = pre_x + (margem - traco) / 2;
//        int xFim = xIni + traco;
//        int yIni = getTop() + margem;
//        int yFim = getTopHeight() - margem;
//        int xLin = pre_x + margem / 2;

        g.setColor(getCorRegua());
        g.drawLine(xIni, yIni, xFim, yIni);
        g.drawLine(xIni, yFim, xFim, yFim);
        g.drawLine(xLin, yIni, xLin, yFim);

        int blc = calculeSubEspaco(W);
        int sr = yIni;
        xFim -= traco;

        int dv = modInteiro(blc);
        int subblc = 0;
        if (dv > 0) {
            subblc = blc / dv;
        }
        while (sr < yFim) {
            if (dv > 0) {
                int a = blc - subblc;
                while (a > 0) {
                    if (sr + a < yFim) {
                        g.drawLine(xIni, sr + a, xFim - traco / 2, sr + a);
                    }
                    a -= subblc;
                }
            }
            g.drawLine(xIni, sr, xFim, sr);
            sr += blc;
        }

        if (isMostrarTextoRegua()) {
            int degrees = isrigth ? 90 : -90;
            int desse = isrigth ? 0 : fm.stringWidth(vl);
            int centra = fm.getHeight() / 2 - fm.getDescent();
            centra = isrigth ? -centra : centra;

            AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(degrees));
            Font f = new Font(getFont().getName(), Font.BOLD, getFont().getSize());
            g.setFont(f.deriveFont(at));
            g.setColor(getForeColor());
            xLin = pre_x - (isrigth ? margem / 2 : -margem / 2);
            yIni = yIni + (H - fm.stringWidth(vl)) / 2 + desse;
            g.drawString(vl, xLin + centra, yIni);
            g.setFont(getFont());
        }
    }
 
开发者ID:chcandido,项目名称:brModelo,代码行数:64,代码来源:baseDrawer.java

示例14: main

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public static void main(String args[]) {
    String fontName = "Lucida Sans";
    if (args.length > 0) {
        fontName = args[0];
    }
    FontRenderContext frc = new FontRenderContext(null, false, false);
    FontRenderContext frc2 = new FontRenderContext(AffineTransform.getScaleInstance(1.5, 1.5), false, false);

    Font font0 = new Font(fontName, 0, 20);
    HashMap map = new HashMap();
    map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    map.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
    Font font = font0.deriveFont(map);

    System.out.println("Using font: " + font);

    double rot = -Math.PI/4;
    AffineTransform scrtx = AffineTransform.getRotateInstance(rot);
    scrtx.scale(1, 2);

    Font[] fonts = {
        font.deriveFont(1f),
        font.deriveFont(20f),
        font.deriveFont(40f),
        font.deriveFont(80f),
        font.deriveFont(AffineTransform.getRotateInstance(rot)),
        font.deriveFont(AffineTransform.getScaleInstance(1, 2)),
        font.deriveFont(AffineTransform.getScaleInstance(2, 4)),
        font.deriveFont(scrtx),
    };

    LineMetrics[] metrics = new LineMetrics[fonts.length * 2];
    for (int i = 0; i < metrics.length; ++i) {
        Font f = fonts[i % fonts.length];
        FontRenderContext frcx = i < fonts.length ? frc : frc2;
        metrics[i] = f.getLineMetrics("X", frcx);
  //       dumpMetrics("Metrics for " + f.getSize2D() + " pt. font,\n  tx: " +
  //       f.getTransform() + ",\n   frctx: " + frcx.getTransform(), metrics[i]);
    }

    // test for linear scale
    // this seems to work, might need to get fancy to deal with last-significant-bit issues?
    double ds1 = metrics[2].getStrikethroughOffset() - metrics[1].getStrikethroughOffset();
    double du1 = metrics[2].getUnderlineThickness() - metrics[1].getUnderlineThickness();
    double ds2 = metrics[3].getStrikethroughOffset() - metrics[2].getStrikethroughOffset();
    double du2 = metrics[3].getUnderlineThickness() - metrics[2].getUnderlineThickness();
    if (ds2 != ds1 * 2 || du2 != du1 * 2) {
        throw new IllegalStateException("non-linear scale: " + ds1 + " / " + ds2 + ", " +
                                        du1 + " / " + du2);
    }

    JFrame jf = new JFrame("Fonts");
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.add(new JScrollPane(new FontsPanel(fonts)));
    jf.pack();
    jf.setVisible(true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:58,代码来源:UnderlineTest.java

示例15: arcTo

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
 * Adds an elliptical arc, defined by two radii, an angle from the
 * x-axis, a flag to choose the large arc or not, a flag to
 * indicate if we increase or decrease the angles and the final
 * point of the arc.
 *
 * @param rx the x radius of the ellipse
 * @param ry the y radius of the ellipse
 *
 * @param angle the angle from the x-axis of the current
 * coordinate system to the x-axis of the ellipse in degrees.
 *
 * @param largeArcFlag the large arc flag. If true the arc
 * spanning less than or equal to 180 degrees is chosen, otherwise
 * the arc spanning greater than 180 degrees is chosen
 *
 * @param sweepFlag the sweep flag. If true the line joining
 * center to arc sweeps through decreasing angles otherwise it
 * sweeps through increasing angles
 *
 * @param x the absolute x coordinate of the final point of the arc.
 * @param y the absolute y coordinate of the final point of the arc.
 */
public synchronized void arcTo(float rx, float ry, float angle,
		boolean largeArcFlag, boolean sweepFlag, float x, float y)
{

	// Ensure radii are valid
	if (rx == 0 || ry == 0)
	{
		lineTo(x, y);
		return;
	}

	checkMoveTo(); // check if prev command was moveto

	// Get the current (x, y) coordinates of the path
	double x0 = cx;
	double y0 = cy;
	if (x0 == x && y0 == y)
	{
		// If the endpoints (x, y) and (x0, y0) are identical, then this
		// is equivalent to omitting the elliptical arc segment entirely.
		return;
	}

	Arc2D arc = computeArc(x0, y0, rx, ry, angle, largeArcFlag, sweepFlag,
			x, y);
	if (arc == null)
		return;

	AffineTransform t = AffineTransform.getRotateInstance(
			Math.toRadians(angle), arc.getCenterX(), arc.getCenterY());
	Shape s = t.createTransformedShape(arc);
	path.append(s, true);

	makeRoom(7);
	types[numSeg++] = ExtendedPathIterator.SEG_ARCTO;
	values[numVals++] = rx;
	values[numVals++] = ry;
	values[numVals++] = angle;
	values[numVals++] = largeArcFlag ? 1 : 0;
	values[numVals++] = sweepFlag ? 1 : 0;
	cx = values[numVals++] = x;
	cy = values[numVals++] = y;
}
 
开发者ID:GDSRS,项目名称:TrabalhoFinalEDA2,代码行数:67,代码来源:ExtendedGeneralPath.java


注:本文中的java.awt.geom.AffineTransform.getRotateInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。