KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > calendarprefs > CalendarPrefs


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.calendarprefs;
20
21 import java.awt.Color JavaDoc;
22 import java.awt.event.*;
23 import java.io.IOException JavaDoc;
24
25 import javax.swing.*;
26
27 import org.lucane.client.*;
28 import org.lucane.client.widgets.DialogBox;
29 import org.lucane.client.widgets.ManagedWindow;
30 import org.lucane.common.*;
31
32 public class CalendarPrefs
33   extends StandalonePlugin
34   implements ActionListener
35 {
36     private ManagedWindow window;
37     private UIFactory ui;
38     private LocalConfig prefs;
39     
40   public CalendarPrefs()
41   {
42   }
43
44   public Plugin newInstance(ConnectInfo[] friends)
45   {
46     return new CalendarPrefs();
47   }
48
49   public void start()
50   {
51         prefs = new LocalConfig("org.lucane.applications.calendar");
52         
53         Color JavaDoc unworkedColor = getColor("unworked", new Color JavaDoc(160, 155, 150));
54         Color JavaDoc workedColor = getColor("worked", new Color JavaDoc(255, 255, 222));
55         int workStart = prefs.getInt("workStart", 8);
56         int workEnd = prefs.getInt("workEnd", 18);
57         int firstDayOfWeek = prefs.getInt("sundayFirst", 0);
58         
59         ui = new UIFactory();
60         ui.setUnworkedColor(unworkedColor);
61         ui.setWorkedColor(workedColor);
62         ui.setWorkStart(workStart);
63         ui.setWorkEnd(workEnd);
64         ui.setFirstDayOfWeek(firstDayOfWeek);
65         
66         window = ui.createMainFrame(this);
67         window.show();
68   }
69
70   public Color JavaDoc getColor(String JavaDoc name, Color JavaDoc defaultColor)
71   {
72       String JavaDoc r = prefs.get(name + ".r");
73       String JavaDoc g = prefs.get(name + ".g");
74       String JavaDoc b = prefs.get(name + ".b");
75         
76       if(r != null && g != null && b != null)
77           return new Color JavaDoc(Integer.parseInt(r), Integer.parseInt(g), Integer.parseInt(b));
78         
79       return defaultColor;
80   }
81
82   public void actionPerformed(ActionEvent ae)
83   {
84         JButton button = (JButton)ae.getSource();
85         if(button.getName().equals("ok"))
86         {
87             prefs.set("workStart", String.valueOf(ui.getWorkStart()));
88             prefs.set("workEnd", String.valueOf(ui.getWorkEnd()));
89             
90             prefs.set("worked.r", String.valueOf(ui.getWorkedColor().getRed()));
91             prefs.set("worked.g", String.valueOf(ui.getWorkedColor().getGreen()));
92             prefs.set("worked.b", String.valueOf(ui.getWorkedColor().getBlue()));
93         
94             prefs.set("unworked.r", String.valueOf(ui.getUnworkedColor().getRed()));
95             prefs.set("unworked.g", String.valueOf(ui.getUnworkedColor().getGreen()));
96             prefs.set("unworked.b", String.valueOf(ui.getUnworkedColor().getBlue()));
97             
98             prefs.set("sundayFirst", String.valueOf(ui.getFirstDayOfWeek()));
99             
100             try {
101                 prefs.save();
102             } catch (IOException JavaDoc ioe) {
103                 DialogBox.error(tr("err.savePrefs"));
104                 ioe.printStackTrace();
105             }
106             
107             window.dispose();
108         }
109         else if(button.getName().equals("cancel"))
110             window.dispose();
111             
112         else if(button.getName().equals("worked"))
113         {
114             Color JavaDoc color = ui.getWorkedColor();
115             color = JColorChooser.showDialog(null, tr("selectWorkedColor"), color);
116             ui.setWorkedColor(color);
117         }
118         else if(button.getName().equals("unworked"))
119         {
120             Color JavaDoc color = ui.getUnworkedColor();
121             color = JColorChooser.showDialog(null, tr("selectUnworkedColor"), color);
122             ui.setUnworkedColor(color);
123         }
124   }
125 }
126
Popular Tags