Cancel the effects of the zoom on a particular Stroke : Stroke « 2D Graphics GUI « Java

Home
Java
1.2D Graphics GUI
2.2D Graphics GUI1
3.3D
4.Advanced Graphics
5.Ant
6.Apache Common
7.Chart
8.Class
9.Collections Data Structure
10.Data Type
11.Database SQL JDBC
12.Design Pattern
13.Development Class
14.EJB3
15.Email
16.Event
17.File Input Output
18.Game
19.Generics
20.GWT
21.Hibernate
22.I18N
23.J2EE
24.J2ME
25.JDK 6
26.JNDI LDAP
27.JPA
28.JSP
29.JSTL
30.Language Basics
31.Network Protocol
32.PDF RTF
33.Reflection
34.Regular Expressions
35.Scripting
36.Security
37.Servlets
38.Spring
39.Swing Components
40.Swing JFC
41.SWT JFace Eclipse
42.Threads
43.Tiny Application
44.Velocity
45.Web Services SOA
46.XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
SCJP
Java » 2D Graphics GUI » StrokeScreenshots 
Cancel the effects of the zoom on a particular Stroke
     
/*
 * Java2DUtils.java
 
 * Created on Aug 30, 2007, 11:40:18 AM
 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//Revised from jaspersoft ireport designer

import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.util.Stack;

/**
 *
 @author gtoffoli
 */
public class Java2DUtils
{

  /**
   * This function provides a way to cancel the effects of the zoom on a particular Stroke.
   * All the stroke values (as line width, dashes, etc...) are divided by the zoom factor.
   * This allow to have essentially a fixed Stroke independent by the zoom.
   * The returned Stroke is a copy.
   * Remember to restore the right stroke in the graphics when done.
   
   * It works only with instances of BasicStroke
   
   * zoom is the zoom factor.
   */
  public static Stroke getInvertedZoomedStroke(Stroke stroke, double zoom)
  {
            if (stroke == null || !(stroke instanceof BasicStroke )) return stroke;
            
            BasicStroke bs = (BasicStroke)stroke;
            float[] dashArray = bs.getDashArray();
            
            float[] newDashArray = null;
            if (dashArray != null)
            {
                newDashArray = new float[dashArray.length];
                for (int i=0; i<newDashArray.length; ++i)
                {
                    newDashArray[i(float)(dashArray[i/ zoom);
                }
            }
            
            BasicStroke newStroke = new BasicStroke(       
                            (float)(bs.getLineWidth() / zoom),
                            bs.getEndCap(),
                            bs.getLineJoin(),
                            bs.getMiterLimit(),
                            //(float)(bs.getMiterLimit() / zoom),
                            newDashArray,
                            (float)(bs.getDashPhase() / zoom)
                    );
            return newStroke;
  }
}

   
    
    
    
    
  
Related examples in the same category
1.Dashed rectangleDashed rectangle
2.A dashed stroke
3.Stroking or Filling with a Texture
4.Basic strokeBasic stroke
5.Thick stroke demoThick stroke demo
6.Dashed strokeDashed stroke
7.Stroke with iron effectStroke with iron effect
8.Smokey effectSmokey effect
9.Custom StrokesCustom Strokes
10.Changing the Thickness of the Stroking Pen
11.Tries to deduct the stroke-type from the given stroke object.
12.Tries to extract the stroke-width from the given stroke object.
13.A component for choosing a stroke from a list of available strokes.
14.Serialises a Stroke object
15.This program demonstrates different stroke types.This program demonstrates different stroke types.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.