KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > gui > background > BackgroundProperties


1 package rero.gui.background;
2
3 import java.awt.*;
4 import java.awt.image.*;
5
6 import rero.config.*;
7
8 public class BackgroundProperties implements ClientStateListener
9 {
10    protected String JavaDoc type;
11
12    protected int bgType;
13    protected int bgStyle;
14
15    protected Image image;
16    protected Image transform;
17
18    protected String JavaDoc name;
19
20    protected Color bgColor;
21    protected float bgTint;
22
23    protected boolean isRelative;
24
25    public boolean isRelative()
26    {
27       return isRelative;
28    }
29
30    public int getType()
31    {
32       return bgType;
33    }
34
35    public int getStyle()
36    {
37       return bgStyle;
38    }
39
40    public Color getColor()
41    {
42       return bgColor;
43    }
44
45    public float getTint()
46    {
47       return bgTint;
48    }
49
50    public BackgroundProperties(String JavaDoc type, int defaultType)
51    {
52       this(type, Color.white, defaultType);
53    }
54
55    public BackgroundProperties(String JavaDoc type, Color defaultColor, int defaultType)
56    {
57       this(type, defaultColor, defaultType, BackgroundUtil.STYLE_TILE, .5f);
58    }
59
60    public BackgroundProperties(String JavaDoc _type, Color defaultColor, int defaultType, int defaultStyle, float defaultTint)
61    {
62       type = _type;
63
64       ClientState.getClientState().addClientStateListener(type, this);
65       init(defaultColor, defaultType, defaultStyle, defaultTint);
66    }
67
68    public void propertyChanged(String JavaDoc property, String JavaDoc parms)
69    {
70       init(bgColor, bgType, bgStyle, bgTint);
71    }
72
73    public void init(Color defaultColor, int defaultType, int defaultStyle, float defaultTint)
74    {
75       int _bgType, _bgStyle;
76       Color _bgColor;
77       float _bgTint;
78       boolean _isRelative;
79       String JavaDoc _name;
80
81       _name = ClientState.getClientState().getString(type + ".image", "background.jpg");
82       _bgType = ClientState.getClientState().getInteger(type + ".bgtype" , defaultType);
83       _bgColor = ClientState.getClientState().getColor( type + ".color" , defaultColor);
84       _bgTint = ClientState.getClientState().getFloat( type + ".tint" , defaultTint);
85       _bgStyle = ClientState.getClientState().getInteger(type + ".bgstyle" , defaultStyle);
86       _isRelative = ClientState.getClientState().isOption( type + ".relative", false);
87
88       if (!_name.equals(name) || bgColor == null || bgType != _bgType || !bgColor.equals(_bgColor) || bgTint != _bgTint || bgStyle != _bgStyle || isRelative != _isRelative)
89       {
90          name = _name;
91          bgType = _bgType;
92          bgColor = _bgColor;
93          bgTint = _bgTint;
94          bgStyle = _bgStyle;
95          isRelative = _isRelative;
96          image = null;
97          transform = null;
98       }
99    }
100
101    public Image getImage(Component c)
102    {
103       if (image == null)
104       {
105          String JavaDoc imageName = ClientState.getClientState().getString(type + ".image", "background.jpg");
106          image = BackgroundUtil.getManagedImage(c, imageName, bgTint, bgColor);
107       }
108
109       return image;
110    }
111
112    public Image getTransformedImage()
113    {
114       return transform;
115    }
116
117    public void setTransformedImage(Image i)
118    {
119       transform = i;
120    }
121 }
122
Popular Tags