/** * Instantiates a new AffineTransformOp with the specified AffineTransform and a specified * interpolation type from the list of predefined interpolation types. * * @param xform the AffineTransform. * @param interp the one of predefined interpolation types: TYPE_NEAREST_NEIGHBOR, TYPE_BILINEAR, * or TYPE_BICUBIC. */ public AffineTransformOp(AffineTransform xform, int interp) { if (Math.abs(xform.getDeterminant()) <= Double.MIN_VALUE) { // awt.24F=Unable to invert transform {0} throw new ImagingOpException(Messages.getString("awt.24F", xform)); // $NON-NLS-1$ } this.at = (AffineTransform) xform.clone(); if (interp != TYPE_NEAREST_NEIGHBOR && interp != TYPE_BILINEAR && interp != TYPE_BICUBIC) { // awt.250=Unknown interpolation type: {0} throw new IllegalArgumentException(Messages.getString("awt.250", interp)); // $NON-NLS-1$ } this.iType = interp; }
public void mouseWheelMoved(MouseWheelEvent event) { JGVTComponent component = (JGVTComponent) event.getSource(); double scale = 1 - 0.2 * event.getWheelRotation(); int x = event.getX(); int y = event.getY(); AffineTransform at = AffineTransform.getTranslateInstance(x, y); at.scale(scale, scale); at.translate(-x, -y); AffineTransform rt = (AffineTransform) component.getRenderingTransform().clone(); rt.preConcatenate(at); if (rt.getDeterminant() < MAX_ZOOM_DETERMINANT) { return; } component.setRenderingTransform(rt); calculator.reset(); }
private Stroke transformStroke(Stroke stroke) { if (!(stroke instanceof BasicStroke)) return stroke; BasicStroke st = (BasicStroke) stroke; float scale = (float) Math.sqrt(Math.abs(transform.getDeterminant())); float dash[] = st.getDashArray(); if (dash != null) { for (int k = 0; k < dash.length; ++k) dash[k] *= scale; } return new BasicStroke( st.getLineWidth() * scale, st.getEndCap(), st.getLineJoin(), st.getMiterLimit(), dash, st.getDashPhase() * scale); }
public void paint(Graphics g) { // repaint the whole transformer in case the view component was repainted Rectangle clipBounds = g.getClipBounds(); if (clipBounds != null && !clipBounds.equals(visibleRect)) { repaint(); } // clear the background g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); if (view != null && at.getDeterminant() != 0) { Graphics2D g2 = (Graphics2D) g.create(); Insets insets = getInsets(); Rectangle bounds = getBounds(); // don't forget about insets bounds.x += insets.left; bounds.y += insets.top; bounds.width -= insets.left + insets.right; bounds.height -= insets.top + insets.bottom; double centerX1 = bounds.getCenterX(); double centerY1 = bounds.getCenterY(); Rectangle tb = getTransformedSize(); double centerX2 = tb.getCenterX(); double centerY2 = tb.getCenterY(); // set antialiasing by default g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (renderingHints != null) { g2.addRenderingHints(renderingHints); } // translate it to the center of the view component again double tx = centerX1 - centerX2 - getX(); double ty = centerY1 - centerY2 - getY(); g2.translate((int) tx, (int) ty); g2.transform(at); view.paint(g2); g2.dispose(); } // paint the border paintBorder(g); }