KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
22
23 import javax.swing.*;
24
25 import org.lucane.client.Client;
26 import org.lucane.client.widgets.ManagedWindow;
27
28 public class UIFactory
29 {
30     private Color workedColor;
31     private Color unworkedColor;
32     private int initialWorkStart;
33     private int initialWorkEnd;
34     private int initalFirstDayOfWeek;
35         
36     private JButton worked;
37     private JButton unworked;
38     private JSlider workStart;
39     private JSlider workEnd;
40     private JComboBox firstDayOfWeek;
41     
42     
43     public ManagedWindow createMainFrame(CalendarPrefs plugin)
44     {
45         ManagedWindow window = new ManagedWindow(plugin, plugin.getTitle());
46         window.getContentPane().setLayout(new BorderLayout());
47
48         JPanel content = new JPanel(new GridLayout(5, 2));
49         
50         // hours
51
workStart = new JSlider(0, 24, initialWorkStart);
52         workStart.setPaintLabels(true);
53         workStart.setPaintTicks(true);
54         workStart.setMajorTickSpacing(8);
55         workStart.setMinorTickSpacing(1);
56         workStart.setSnapToTicks(true);
57         workEnd = new JSlider(0, 24, initialWorkEnd);
58         workEnd.setPaintLabels(true);
59         workEnd.setPaintTicks(true);
60         workEnd.setMajorTickSpacing(8);
61         workEnd.setMinorTickSpacing(1);
62         workEnd.setSnapToTicks(true);
63         
64         content.add(new JLabel(plugin.tr("lbl.workStart")));
65         content.add(workStart);
66         content.add(new JLabel(plugin.tr("lbl.workEnd")));
67         content.add(workEnd);
68                 
69         
70         // colors
71
worked = new JButton("");
72         worked.setBackground(workedColor);
73         worked.setName("worked");
74         worked.addActionListener(plugin);
75         unworked = new JButton("");
76         unworked.setBackground(unworkedColor);
77         unworked.setName("unworked");
78         unworked.addActionListener(plugin);
79                 
80         content.add(new JLabel(plugin.tr("lbl.workedColor")));
81         content.add(worked);
82         content.add(new JLabel(plugin.tr("lbl.unworkedColor")));
83         content.add(unworked);
84         
85         // first day of week
86
firstDayOfWeek = new JComboBox(new Object JavaDoc[]{
87                 plugin.tr("monday"),
88                 plugin.tr("sunday"),
89         });
90         firstDayOfWeek.setSelectedIndex(initalFirstDayOfWeek);
91         content.add(new JLabel(plugin.tr("lbl.firstDayOfWeek")));
92         content.add(firstDayOfWeek);
93         
94         // buttons
95
JButton ok = new JButton(plugin.tr("btn.ok"), Client.getImageIcon("ok.png"));
96         JButton cancel = new JButton(plugin.tr("btn.cancel"), Client.getImageIcon("cancel.png"));
97         ok.setName("ok");
98         cancel.setName("cancel");
99         ok.addActionListener(plugin);
100         cancel.addActionListener(plugin);
101                 
102         JPanel buttonContainer = new JPanel(new BorderLayout());
103         JPanel buttons = new JPanel(new GridLayout(1, 2));
104         buttons.add(ok);
105         buttons.add(cancel);
106         buttonContainer.add(buttons, BorderLayout.EAST);
107         buttonContainer.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
108         
109         // frame
110
window.getContentPane().add(content, BorderLayout.CENTER);
111         window.getContentPane().add(buttonContainer, BorderLayout.SOUTH);
112         
113         return window;
114     }
115     
116     public void setFirstDayOfWeek(int day)
117     {
118         this.initalFirstDayOfWeek = day;
119     }
120     
121     public int getFirstDayOfWeek()
122     {
123         return this.firstDayOfWeek.getSelectedIndex();
124     }
125     
126     public void setWorkedColor(Color color)
127     {
128         if(color == null)
129             return;
130             
131         workedColor = color;
132         if(worked != null)
133             worked.setBackground(color);
134     }
135     
136     public void setUnworkedColor(Color color)
137     {
138         if(color == null)
139             return;
140             
141         unworkedColor = color;
142         if(unworked != null)
143             unworked.setBackground(color);
144     }
145     
146     public Color getWorkedColor()
147     {
148         return workedColor;
149     }
150     
151     public Color getUnworkedColor()
152     {
153         return unworkedColor;
154     }
155     
156     public void setWorkStart(int i)
157     {
158         this.initialWorkStart = i;
159     }
160     
161     public void setWorkEnd(int i)
162     {
163         this.initialWorkEnd = i;
164     }
165     
166     public int getWorkStart()
167     {
168         return workStart.getValue();
169     }
170     
171     public int getWorkEnd()
172     {
173         return workEnd.getValue();
174     }
175 }
Popular Tags