KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > config > CfgColors


1 /*
2  * Authors:
3  * Stefanovic Nenad chupo@iis.ns.ac.yu
4  * Bojanic Sasa sasaboy@neobee.net
5  *
6  */

7
8 package org.enhydra.jawe.config;
9
10
11 import java.awt.*;
12 import java.awt.event.*;
13 import javax.swing.*;
14
15
16 import org.enhydra.jawe.*;
17
18 public class CfgColors extends BaseConfigPane{
19
20    private JTextField BackgroundColor, HighlightColor, HandleColor,
21       MarqueeColor, GridColor, ProcessColor, TransitionColor,
22       OtherwiseTransitionColor,ExceptionTransitionColor,DefaultExceptionTransitionColor,
23       ParticipantTextColor, ParticipantBorderColor, ResourceSetParticipantColor,
24       ResourceParticipantColor, RoleParticipantColor,
25       OrganizationalUnitParticipantColor, HumanParticipantColor,
26       SystemParticipantColor, FreeTextExpressionParticipantColor,
27       SelectedActivityColor, StartColor, EndColor, StartEndColor, GenericActivityColor,
28       RouteActivityColor, SubFlowActivityColor, BlockActivityColor;
29       //ActivityPreconditionColor, ActivityPostconditionColor;
30

31    public CfgColors(String JavaDoc name){
32       super(name);
33
34       BackgroundColor = new JTextField();
35       addComponent("Config.Color.BackgroundColor.Label",drawPanel(BackgroundColor));
36       HighlightColor = new JTextField();
37       addComponent("Config.Color.HighlightColor.Label",drawPanel(HighlightColor) );
38       HandleColor = new JTextField();
39       addComponent("Config.Color.HandleColor.Label",drawPanel(HandleColor) );
40       MarqueeColor = new JTextField();
41       addComponent("Config.Color.MarqueeColor.Label",drawPanel(MarqueeColor) );
42       GridColor = new JTextField();
43       addComponent("Config.Color.GridColor.Label",drawPanel(GridColor));
44       ProcessColor = new JTextField();
45       addComponent("Config.Color.ProcessColor.Label",drawPanel(ProcessColor) );
46       TransitionColor = new JTextField();
47       addComponent("Config.Color.TransitionColor.Label",drawPanel(TransitionColor) );
48       OtherwiseTransitionColor = new JTextField();
49       addComponent("Config.Color.OtherwiseTransitionColor.Label",drawPanel(OtherwiseTransitionColor) );
50       ExceptionTransitionColor = new JTextField();
51       addComponent("Config.Color.ExceptionTransitionColor.Label",drawPanel(ExceptionTransitionColor) );
52       DefaultExceptionTransitionColor = new JTextField();
53       addComponent("Config.Color.DefaultExceptionTransitionColor.Label",drawPanel(DefaultExceptionTransitionColor) );
54       ParticipantTextColor = new JTextField();
55       addComponent("Config.Color.ParticipantTextColor.Label",drawPanel(ParticipantTextColor) );
56       ParticipantBorderColor = new JTextField();
57       addComponent("Config.Color.ParticipantBorderColor.Label",drawPanel(ParticipantBorderColor) );
58       ResourceSetParticipantColor = new JTextField();
59       addComponent("Config.Color.ResourceSetParticipantColor.Label",drawPanel(ResourceSetParticipantColor) );
60       ResourceParticipantColor = new JTextField();
61       addComponent("Config.Color.ResourceParticipantColor.Label",drawPanel(ResourceParticipantColor) );
62       RoleParticipantColor = new JTextField();
63       addComponent("Config.Color.RoleParticipantColor.Label",drawPanel(RoleParticipantColor) );
64       OrganizationalUnitParticipantColor = new JTextField();
65       addComponent("Config.Color.OrganizationalUnitParticipantColor.Label",drawPanel(OrganizationalUnitParticipantColor) );
66       HumanParticipantColor = new JTextField();
67       addComponent("Config.Color.HumanParticipantColor.Label",drawPanel(HumanParticipantColor) );
68       SystemParticipantColor = new JTextField();
69       addComponent("Config.Color.SystemParticipantColor.Label",drawPanel(SystemParticipantColor) );
70       FreeTextExpressionParticipantColor = new JTextField();
71       addComponent("Config.Color.FreeTextExpressionParticipantColor.Label",drawPanel(FreeTextExpressionParticipantColor) );
72       SelectedActivityColor = new JTextField();
73       addComponent("Config.Color.SelectedActivityColor.Label",drawPanel(SelectedActivityColor) );
74       StartColor = new JTextField();
75       addComponent("Config.Color.StartColor.Label",drawPanel(StartColor) );
76       EndColor = new JTextField();
77       addComponent("Config.Color.EndColor.Label",drawPanel(EndColor) );
78       StartEndColor = new JTextField();
79       addComponent("Config.Color.StartEndColor.Label",drawPanel(StartEndColor) );
80       GenericActivityColor = new JTextField();
81       addComponent("Config.Color.GenericActivityColor.Label",drawPanel(GenericActivityColor) );
82       RouteActivityColor = new JTextField();
83       addComponent("Config.Color.RouteActivityColor.Label",drawPanel(RouteActivityColor) );
84       SubFlowActivityColor = new JTextField();
85       addComponent("Config.Color.SubFlowActivityColor.Label",drawPanel(SubFlowActivityColor) );
86       BlockActivityColor = new JTextField();
87       addComponent("Config.Color.BlockActivityColor.Label",drawPanel(BlockActivityColor) );
88       /*ActivityPreconditionColor = new JTextField();
89       addComponent("Config.Color.ActivityPreconditionColor.Label",drawPanel(ActivityPreconditionColor) );
90       ActivityPostconditionColor = new JTextField();
91        addComponent("Config.Color.ActivityPostconditionColor.Label",drawPanel(ActivityPostconditionColor) );*/

92       readConf();
93    }
94
95    public void readConf(){
96       String JavaDoc col=JaWEConfig.getInstance().getBackgroundColor();
97       setColorField(BackgroundColor,col);
98
99       col=JaWEConfig.getInstance().getHighlightColor();
100       setColorField(HighlightColor,col);
101
102       col=JaWEConfig.getInstance().getHandleColor();
103       setColorField(HandleColor,col);
104
105       col=JaWEConfig.getInstance().getMarqueeColor();
106       setColorField(MarqueeColor,col);
107
108       col=JaWEConfig.getInstance().getGridColor();
109       setColorField(GridColor,col);
110
111       col=JaWEConfig.getInstance().getProcessColor();
112       setColorField(ProcessColor,col);
113
114       col=JaWEConfig.getInstance().getTransitionColor();
115       setColorField(TransitionColor,col);
116
117       col=JaWEConfig.getInstance().getOtherwiseTransitionColor();
118       setColorField(OtherwiseTransitionColor,col);
119
120       col=JaWEConfig.getInstance().getExceptionTransitionColor();
121       setColorField(ExceptionTransitionColor,col);
122
123       col=JaWEConfig.getInstance().getDefaultExceptionTransitionColor();
124       setColorField(DefaultExceptionTransitionColor,col);
125
126       col=JaWEConfig.getInstance().getParticipantTextColor();
127       setColorField(ParticipantTextColor,col);
128
129       col=JaWEConfig.getInstance().getParticipantBorderColor();
130       setColorField(ParticipantBorderColor,col);
131
132       col=JaWEConfig.getInstance().getResourceSetParticipantColor();
133       setColorField(ResourceSetParticipantColor,col);
134
135       col=JaWEConfig.getInstance().getResourceParticipantColor();
136       setColorField(ResourceParticipantColor,col);
137
138       col=JaWEConfig.getInstance().getRoleParticipantColor();
139       setColorField(RoleParticipantColor,col);
140
141       col=JaWEConfig.getInstance().getOrganizationalUnitParticipantColor();
142       setColorField(OrganizationalUnitParticipantColor,col);
143
144       col=JaWEConfig.getInstance().getHumanParticipantColor();
145       setColorField(HumanParticipantColor,col);
146
147       col=JaWEConfig.getInstance().getSystemParticipantColor();
148       setColorField(SystemParticipantColor,col);
149
150       col=JaWEConfig.getInstance().getFreeTextExpressionParticipantColor();
151       setColorField(FreeTextExpressionParticipantColor,col);
152
153       col=JaWEConfig.getInstance().getSelectedActivityColor();
154       setColorField(SelectedActivityColor,col);
155
156       col=JaWEConfig.getInstance().getStartColor();
157       setColorField(StartColor,col);
158
159       col=JaWEConfig.getInstance().getEndColor();
160       setColorField(EndColor,col);
161
162       col=JaWEConfig.getInstance().getStartEndColor();
163       setColorField(StartEndColor,col);
164
165       col=JaWEConfig.getInstance().getGenericActivityColor();
166       setColorField(GenericActivityColor,col);
167
168       col=JaWEConfig.getInstance().getRouteActivityColor();
169       setColorField(RouteActivityColor,col);
170
171       col=JaWEConfig.getInstance().getSubFlowActivityColor();
172       setColorField(SubFlowActivityColor,col);
173
174       col=JaWEConfig.getInstance().getBlockActivityColor();
175       setColorField(BlockActivityColor,col);
176
177       /*col=JaWEConfig.getInstance().getActivityPreconditionColor();
178       setColorField(ActivityPreconditionColor,col);
179
180       col=JaWEConfig.getInstance().getActivityPostconditionColor();
181        setColorField(ActivityPostconditionColor,col);*/

182
183    }
184
185    public void save(){
186       //System.out.println("Snimam Colors");
187
JaWEConfig.getInstance().setBackgroundColor(BackgroundColor.getText());
188       JaWEConfig.getInstance().setHighlightColor(HighlightColor.getText());
189       JaWEConfig.getInstance().setHandleColor(HandleColor.getText());
190       JaWEConfig.getInstance().setMarqueeColor(MarqueeColor.getText());
191       JaWEConfig.getInstance().setGridColor(GridColor.getText());
192       JaWEConfig.getInstance().setProcessColor(ProcessColor.getText());
193       JaWEConfig.getInstance().setTransitionColor(TransitionColor.getText());
194       JaWEConfig.getInstance().setOtherwiseTransitionColor(OtherwiseTransitionColor.getText());
195       JaWEConfig.getInstance().setExceptionTransitionColor(ExceptionTransitionColor.getText());
196       JaWEConfig.getInstance().setDefaultExceptionTransitionColor(DefaultExceptionTransitionColor.getText());
197       JaWEConfig.getInstance().setParticipantTextColor(ParticipantTextColor.getText());
198       JaWEConfig.getInstance().setParticipantBorderColor(ParticipantBorderColor.getText());
199       JaWEConfig.getInstance().setResourceSetParticipantColor(ResourceSetParticipantColor.getText());
200       JaWEConfig.getInstance().setResourceParticipantColor(ResourceParticipantColor.getText());
201       JaWEConfig.getInstance().setRoleParticipantColor(RoleParticipantColor.getText());
202       JaWEConfig.getInstance().setOrganizationalUnitParticipantColor(OrganizationalUnitParticipantColor.getText());
203       JaWEConfig.getInstance().setHumanParticipantColor(HumanParticipantColor.getText());
204       JaWEConfig.getInstance().setSystemParticipantColor(SystemParticipantColor.getText());
205       JaWEConfig.getInstance().setFreeTextExpressionParticipantColor(FreeTextExpressionParticipantColor.getText());
206       JaWEConfig.getInstance().setSelectedActivityColor(SelectedActivityColor.getText());
207       JaWEConfig.getInstance().setStartColor(StartColor.getText());
208       JaWEConfig.getInstance().setEndColor(EndColor.getText());
209       JaWEConfig.getInstance().setStartEndColor(StartEndColor.getText());
210       JaWEConfig.getInstance().setGenericActivityColor(GenericActivityColor.getText());
211       JaWEConfig.getInstance().setRouteActivityColor(RouteActivityColor.getText());
212       JaWEConfig.getInstance().setSubFlowActivityColor(SubFlowActivityColor.getText());
213       JaWEConfig.getInstance().setBlockActivityColor(BlockActivityColor.getText());
214       //JaWEConfig.getInstance().setActivityPreconditionColor(ActivityPreconditionColor.getText());
215
//JaWEConfig.getInstance().setActivityPostconditionColor(ActivityPostconditionColor.getText());
216
}
217
218    private String JavaDoc getColorString(Color c){
219       String JavaDoc color ="R=" + Integer.toString(c.getRed());
220       color += ",G="+Integer.toString(c.getGreen());
221       color += ",B="+Integer.toString(c.getBlue());
222       return color;
223    }
224
225    private JPanel drawPanel(final JTextField field){
226       JPanel panelColor = new JPanel(new BorderLayout());
227       JButton buttColor = new JButton(
228          new ImageIcon(ResourceManager.getResource("ColorImage")));
229       buttColor.addActionListener(new ActionListener() {
230          public void actionPerformed (ActionEvent ae) {
231             Color newColor = JColorChooser.showDialog(
232                   CfgColors.this,"Choose Color",Utils.getColor(field.getText()));
233             if (newColor != null) {
234                setColorField(field,getColorString(newColor));
235             }
236
237          }
238       });
239       panelColor.add(field,BorderLayout.CENTER);
240       panelColor.add(buttColor,BorderLayout.EAST);
241       return panelColor;
242    }
243
244    private void setColorField (JTextField cf,String JavaDoc col) {
245       cf.setText(col);
246       cf.setBackground(Utils.getColor(col));
247       cf.setToolTipText(col);
248    }
249
250    public Component getComponent(){
251       return this;
252    }
253
254 }
255
256
Popular Tags