Source Code Cross Referenced for JMonthChooser.java in  » Project-Management » lgantt » com » toedter » calendar » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Project Management » lgantt » com.toedter.calendar 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  06/27/2002 - 20:54:54
003:         *
004:         *  JMonthChooser.java  - A bean for choosing a month
005:         *  Copyright (C) 2002 Kai Toedter
006:         *  kai@toedter.com
007:         *  www.toedter.com
008:         *
009:         *  This program is free software; you can redistribute it and/or
010:         *  modify it under the terms of the GNU Lesser General Public License
011:         *  as published by the Free Software Foundation; either version 2
012:         *  of the License, or (at your option) any later version.
013:         *
014:         *  This program is distributed in the hope that it will be useful,
015:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017:         *  GNU Lesser General Public License for more details.
018:         *
019:         *  You should have received a copy of the GNU Lesser General Public License
020:         *  along with this program; if not, write to the Free Software
021:         *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
022:         */
023:        package com.toedter.calendar;
024:
025:        import java.awt.Adjustable;
026:        import java.awt.BorderLayout;
027:        import java.awt.Dimension;
028:        import java.awt.event.AdjustmentEvent;
029:        import java.awt.event.AdjustmentListener;
030:        import java.awt.event.ItemEvent;
031:        import java.awt.event.ItemListener;
032:        import java.text.DateFormatSymbols;
033:        import java.util.Calendar;
034:        import java.util.Locale;
035:
036:        import javax.swing.JComboBox;
037:        import javax.swing.JFrame;
038:        import javax.swing.JPanel;
039:        import javax.swing.JScrollBar;
040:
041:        /**
042:         *  JMonthChooser is a bean for choosing a month.
043:         *
044:         *@author     Kai Toedter
045:         *@version    1.1.3 07/16/02
046:         */
047:        public class JMonthChooser extends JPanel implements  ItemListener,
048:                AdjustmentListener {
049:
050:            /**
051:             * 
052:             */
053:            private static final long serialVersionUID = 4121138021874874419L;
054:            /**
055:             *  Displays a JSpinField on the right
056:             */
057:            public final static int RIGHT_SPINNER = 0;
058:            /**
059:             *  Displays a JSpinField on the left
060:             */
061:            public final static int LEFT_SPINNER = 1;
062:            /**
063:             *  Displays no JSpinField
064:             */
065:            public final static int NO_SPINNER = 2;
066:
067:            /**
068:             *  Default JMonthChooser constructor.
069:             */
070:            public JMonthChooser() {
071:                this (RIGHT_SPINNER);
072:            }
073:
074:            /**
075:             *  JMonthChooser constructor with month spinner parameter.
076:             *
077:             *@param  spinner  Possible values are RIGHT_SPINNER, LEFT_SPINNER, NO_SPINNER
078:             */
079:            public JMonthChooser(int spinner) {
080:                super ();
081:
082:                setLayout(new BorderLayout());
083:
084:                comboBox = new JComboBox();
085:                comboBox.addItemListener(this );
086:                dayChooser = null;
087:                locale = Locale.getDefault();
088:                initNames();
089:                add(comboBox, BorderLayout.CENTER);
090:
091:                if (spinner != NO_SPINNER) {
092:                    // 10000 possible clicks in both directions should be enough :)
093:                    scrollBar = new JScrollBar(Adjustable.VERTICAL, 0, 0,
094:                            -10000, 10000);
095:                    scrollBar.setPreferredSize(new Dimension(scrollBar
096:                            .getPreferredSize().width,
097:                            this .getPreferredSize().height));
098:                    scrollBar.setVisibleAmount(0);
099:                    scrollBar.addAdjustmentListener(this );
100:
101:                    if (spinner == RIGHT_SPINNER) {
102:                        add(scrollBar, BorderLayout.EAST);
103:                    } else {
104:                        add(scrollBar, BorderLayout.WEST);
105:                    }
106:                }
107:
108:                initialized = true;
109:                setMonth(Calendar.getInstance().get(Calendar.MONTH));
110:            }
111:
112:            /**
113:             *  Initializes the locale specific month names.
114:             */
115:            public void initNames() {
116:                localInitialize = true;
117:
118:                DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(
119:                        locale);
120:                String[] monthNames = dateFormatSymbols.getMonths();
121:
122:                if (comboBox.getItemCount() == 12) {
123:                    comboBox.removeAllItems();
124:                }
125:                for (int i = 0; i < 12; i++) {
126:                    comboBox.addItem(monthNames[i]);
127:                }
128:
129:                localInitialize = false;
130:                comboBox.setSelectedIndex(month);
131:            }
132:
133:            /**
134:             *  The ItemListener for the months.
135:             *
136:             *@param  iEvt  Description of the Parameter
137:             */
138:            public void itemStateChanged(ItemEvent iEvt) {
139:                int index = comboBox.getSelectedIndex();
140:                if (index >= 0) {
141:                    setMonth(index, false);
142:                }
143:            }
144:
145:            /**
146:             *  The 2 buttons are implemented with a JScrollBar.
147:             *
148:             *@param  e  Description of the Parameter
149:             */
150:            public void adjustmentValueChanged(AdjustmentEvent e) {
151:                boolean increase = true;
152:                int newScrollBarValue = e.getValue();
153:                if (newScrollBarValue > oldScrollBarValue) {
154:                    increase = false;
155:                }
156:                oldScrollBarValue = newScrollBarValue;
157:                int month = getMonth();
158:                if (increase) {
159:                    month += 1;
160:                    if (month == 12) {
161:                        month = 0;
162:                        if (yearChooser != null) {
163:                            int year = yearChooser.getYear();
164:                            year += 1;
165:                            yearChooser.setYear(year);
166:                        }
167:                    }
168:                } else {
169:                    month -= 1;
170:                    if (month == -1) {
171:                        month = 11;
172:                        if (yearChooser != null) {
173:                            int year = yearChooser.getYear();
174:                            year -= 1;
175:                            yearChooser.setYear(year);
176:                        }
177:                    }
178:                }
179:                setMonth(month);
180:            }
181:
182:            /**
183:             *  Sets the month attribute of the JMonthChooser object
184:             *
185:             *@param  newMonth  The new month value
186:             *@param  select    The new month value
187:             */
188:            private void setMonth(int newMonth, boolean select) {
189:                if (!initialized || localInitialize) {
190:                    return;
191:                }
192:
193:                int oldMonth = month;
194:                month = newMonth;
195:                if (select) {
196:                    comboBox.setSelectedIndex(month);
197:                }
198:                if (dayChooser != null) {
199:                    dayChooser.setMonth(month);
200:                }
201:                firePropertyChange("month", oldMonth, month);
202:            }
203:
204:            /**
205:             *  Sets the month. This is a bound property.
206:             *
207:             *@param  newMonth  The new month value
208:             *@see              #getMonth
209:             */
210:            public void setMonth(int newMonth) {
211:                setMonth(newMonth, true);
212:            }
213:
214:            /**
215:             *  Returns the month.
216:             *
217:             *@return    The month value
218:             *@see       #setMonth
219:             */
220:            public int getMonth() {
221:                return month;
222:            }
223:
224:            /**
225:             *  Convenience method set a day chooser.
226:             *
227:             *@param  dayChooser  the day chooser
228:             */
229:            public void setDayChooser(JDayChooser dayChooser) {
230:                this .dayChooser = dayChooser;
231:            }
232:
233:            /**
234:             *  Convenience method set a year chooser. If set, the spin buttons will spin
235:             *  the year as well
236:             *
237:             *@param  yearChooser  The new yearChooser value
238:             */
239:            public void setYearChooser(JYearChooser yearChooser) {
240:                this .yearChooser = yearChooser;
241:            }
242:
243:            /**
244:             *  Returns the locale.
245:             *
246:             *@return    The locale value
247:             *@see       #setLocale
248:             */
249:            public Locale getLocale() {
250:                return locale;
251:            }
252:
253:            /**
254:             *  Set the locale and initializes the new month names.
255:             *
256:             *@param  l  The new locale value
257:             *@see       #getLocale
258:             */
259:            public void setLocale(Locale l) {
260:                if (!initialized) {
261:                    super .setLocale(l);
262:                } else {
263:                    locale = l;
264:                    initNames();
265:                }
266:            }
267:
268:            /**
269:             *  Enable or disable the JMonthChooser.
270:             *
271:             *@param  enabled  The new enabled value
272:             */
273:            public void setEnabled(boolean enabled) {
274:                super .setEnabled(enabled);
275:                comboBox.setEnabled(enabled);
276:                if (scrollBar != null) {
277:                    scrollBar.setEnabled(enabled);
278:                }
279:            }
280:
281:            /**
282:             *  Creates a JFrame with a JMonthChooser inside and can be used for testing.
283:             *
284:             *@param  s  The command line arguments
285:             */
286:            public static void main(String[] s) {
287:                JFrame frame = new JFrame("MonthChooser");
288:                frame.getContentPane().add(new JMonthChooser());
289:                frame.pack();
290:                frame.setVisible(true);
291:            }
292:
293:            private Locale locale;
294:            private int month;
295:            private int oldScrollBarValue = 0;
296:            // needed for comparison
297:            private JDayChooser dayChooser = null;
298:            private JYearChooser yearChooser = null;
299:            private JComboBox comboBox;
300:            private JScrollBar scrollBar;
301:            private boolean initialized = false;
302:            private boolean localInitialize = false;
303:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.