sventon subversion web client - http://www.sventon.org
[show recent changes]
 
  Go to revisionGo to path
HEAD Help
Rev: 657 - svn://greenwoodma.servehttp.com/open-source / SVGRoundTrip / trunk / src / englishcoffeedrinker / svg / in / templates / scalable
Diff View - scalable
Next diff       /SVGRoundTrip/trunk/src/englishcoffeedrinker/svg/in/templates/scalable @ revision 656
        /SVGRoundTrip/trunk/src/englishcoffeedrinker/svg/in/templates/scalable @ revision 657
1 1   TOKEN_PACKAGE
2 2    
3 3   import java.awt.*;
4 4   import java.awt.geom.*;
5 5   import java.awt.image.*;
6 6    
7 7   import java.awt.image.BufferedImage;
8 8   import java.io.IOException;
9 9   import javax.imageio.ImageIO;
10 10    
11 11   /**
12 12    * This class has been automatically generated using <a
13 13    * href="http://englishjavadrinker.blogspot.com/search/label/SVGRoundTrip">SVGRoundTrip</a>.
14 14    */
15 15   @SuppressWarnings("unused")
16 16   public class TOKEN_CLASSNAME implements
17 17     javax.swing.Icon {
Next diff 18 +  
Next diff 19 +  private static Color getColor(int red, int green, int blue, int alpha, boolean disabled) {
Next diff 20 +  
Next diff 21 +   if (!disabled) return new Color(red, green, blue, alpha);
Next diff 22 +  
Next diff 23 +   int gray = (int)(((0.30f * red) + (0.59f * green) + (0.11f * blue))/3f);
Next diff 24 +  
Next diff 25 +   gray = Math.min(255, Math.max(0, gray));
Next diff 26 +  
Next diff 27 +   //This brightens the image the same as GrayFilter
Next diff 28 +   int percent = 50;
Next diff 29 +   gray = (255 - ((255 - gray) * (100 - percent) / 100));
Next diff 30 +  
Next diff 31 +   return new Color(gray, gray, gray, alpha);
Next diff 32 +  }
Next diff 33 +  
18 34    /**
19 35     * Paints the transcoded SVG image on the specified graphics context. You
20 36     * can install a custom transformation on the graphics context to scale the
21 37     * image.
22 38     *
23 39     * @param g
24 40     * Graphics context.
25 41     */
Next diff 26 -  public static void paint(Graphics2D g) {
Next diff 42 +  public static void paint(Graphics2D g, boolean disabled) {
27 43           Shape shape = null;
28 44           Paint paint = null;
29 45           Stroke stroke = null;
30 46           Area clip = null;
31 47    
32 48           float origAlpha = 1.0f;
33 49           Composite origComposite = g.getComposite();
34 50           if (origComposite instanceof AlphaComposite) {
35 51               AlphaComposite origAlphaComposite =
36 52                   (AlphaComposite)origComposite;
37 53               if (origAlphaComposite.getRule() == AlphaComposite.SRC_OVER) {
38 54                   origAlpha = origAlphaComposite.getAlpha();
39 55               }
40 56           }
41 57    
42 58        TOKEN_PAINTING_CODE
43 59    }
44 60    
45 61    public Image getImage() {
46 62     BufferedImage image =
47 63               new BufferedImage(getIconWidth(), getIconHeight(),
48 64                       BufferedImage.TYPE_INT_ARGB);
49 65        Graphics2D g = image.createGraphics();
50 66        paintIcon(null, g, 0, 0);
51 67        g.dispose();
52 68        return image;
53 69    }
54 70    
55 71       /**
56 72        * Returns the X of the bounding box of the original SVG image.
57 73        *
58 74        * @return The X of the bounding box of the original SVG image.
59 75        */
60 76       public static int getOrigX() {
61 77           return TOKEN_ORIG_X;
62 78       }
63 79    
64 80       /**
65 81        * Returns the Y of the bounding box of the original SVG image.
66 82        *
67 83        * @return The Y of the bounding box of the original SVG image.
68 84        */
69 85       public static int getOrigY() {
70 86           return TOKEN_ORIG_Y;
71 87       }
72 88    
73 89    /**
74 90     * Returns the width of the bounding box of the original SVG image.
75 91     *
76 92     * @return The width of the bounding box of the original SVG image.
77 93     */
78 94    public static int getOrigWidth() {
79 95     return TOKEN_ORIG_WIDTH;
80 96    }
81 97    
82 98    /**
83 99     * Returns the height of the bounding box of the original SVG image.
84 100     *
85 101     * @return The height of the bounding box of the original SVG image.
86 102     */
87 103    public static int getOrigHeight() {
88 104     return TOKEN_ORIG_HEIGHT;
89 105    }
90 106    
91 107    /**
92 108     * The current width of this resizable icon.
93 109     */
94 110    int width;
95 111    
96 112    /**
97 113     * The current height of this resizable icon.
98 114     */
99 115    int height;
Next diff 116 +  
Next diff 117 +  /**
Next diff 118 +   * Should this icon be drawn in a disabled state
Next diff 119 +   */
Next diff 120 +  boolean disabled = false;
100 121    
101 122    /**
102 123     * Creates a new transcoded SVG image.
103 124     */
104 125    public TOKEN_CLASSNAME() {
Next diff 105 -         this.width = getOrigWidth();
Next diff 106 -         this.height = getOrigHeight();
Next diff 126 +         this(getOrigWidth(),getOrigHeight(),false);
Next diff 127 +  }
Next diff 128 +  
Next diff 129 +  public TOKEN_CLASSNAME(boolean disabled) {
Next diff 130 +         this(getOrigWidth(),getOrigHeight(),disabled);
107 131    }
108 132    
109 133    /**
110 134     * Creates a new transcoded SVG image with the given dimensions.
111 135     *
112 136     * @param size the dimensions of the icon
113 137     */
114 138    public TOKEN_CLASSNAME(Dimension size) {
Next diff 115 -  this.width = size.width;
Next diff 116 -  this.height = size.width;
Next diff 139 +   this(size.width, size.height, false);
Next diff 140 +  }
Next diff 141 +  
Next diff 142 +  public TOKEN_CLASSNAME(Dimension size, boolean disabled) {
Next diff 143 +   this(size.width, size.height, disabled);
117 144    }
118 145    
119 146    public TOKEN_CLASSNAME(int width, int height) {
Next diff 120 -  this.width = width;
Next diff 121 -  this.height = height;
Next diff 147 +   this(width, height, false);
Next diff 148 +  }
Next diff 149 +  
Next diff 150 +  public TOKEN_CLASSNAME(int width, int height, boolean disabled) {
Next diff 151 +   this.width = width;
Next diff 152 +   this.height = height;
Next diff 153 +   this.disabled = disabled;
122 154    }
123 155    
124 156    /*
125 157     * (non-Javadoc)
126 158     *
127 159     * @see javax.swing.Icon#getIconHeight()
128 160     */
129 161       @Override
130 162    public int getIconHeight() {
131 163     return height;
132 164    }
133 165    
134 166    /*
135 167     * (non-Javadoc)
136 168     *
137 169     * @see javax.swing.Icon#getIconWidth()
138 170     */
139 171       @Override
140 172    public int getIconWidth() {
141 173     return width;
142 174    }
143 175    
144 176    public void setDimension(Dimension newDimension) {
145 177     this.width = newDimension.width;
146 178     this.height = newDimension.height;
147 179    }
148 180    
149 181    /*
150 182     * (non-Javadoc)
151 183     *
152 184     * @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics,
153 185     * int, int)
154 186     */
155 187       @Override
156 188    public void paintIcon(Component c, Graphics g, int x, int y) {
157 189     Graphics2D g2d = (Graphics2D) g.create();
158 190     g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
159 191       RenderingHints.VALUE_ANTIALIAS_ON);
160 192     g2d.translate(x, y);
161 193    
162 194     Area clip = new Area(new Rectangle(0, 0, this.width, this.height));
163 195     if (g2d.getClip() != null) clip.intersect(new Area(g2d.getClip()));
164 196     g2d.setClip(clip);
165 197    
166 198     double coef1 = (double) this.width / (double) getOrigWidth();
167 199     double coef2 = (double) this.height / (double) getOrigHeight();
168 200     double coef = Math.min(coef1, coef2);
169 201     g2d.scale(coef, coef);
Next diff 170 -   paint(g2d);
Next diff 202 +   paint(g2d, disabled);
171 203     g2d.dispose();
172 204    }
173 205   }

feed icon

sventon 2.1.4