Source Code Cross Referenced for JNCalendar.java in  » Project-Management » memoranda » net » sf » memoranda » ui » 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 » memoranda » net.sf.memoranda.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JNCalendar.java Created on 13.02.2003, 21:26:38 Alex Package:
003:         * net.sf.memoranda.ui
004:         * 
005:         * @author Alex V. Alishevskikh, alex@openmechanics.net Copyright (c) 2003
006:         *         Memoranda Team. http://memoranda.sf.net
007:         */package net.sf.memoranda.ui;
008:
009:        import java.awt.event.ActionEvent;
010:        import java.awt.event.ActionListener;
011:        import java.util.Calendar;
012:        import java.util.Vector;
013:
014:        import javax.swing.JTable;
015:        import javax.swing.ListSelectionModel;
016:        import javax.swing.event.ListSelectionEvent;
017:        import javax.swing.event.ListSelectionListener;
018:        import javax.swing.table.AbstractTableModel;
019:        import javax.swing.table.TableCellRenderer;
020:
021:        import net.sf.memoranda.date.CalendarDate;
022:        import net.sf.memoranda.date.CurrentDate;
023:        import net.sf.memoranda.util.Local;
024:        import net.sf.memoranda.util.Configuration;
025:
026:        /**
027:         *  
028:         */
029:        /*$Id: JNCalendar.java,v 1.8 2004/11/05 07:38:10 pbielen Exp $*/
030:        public class JNCalendar extends JTable {
031:
032:            private CalendarDate _date = null;
033:            private boolean ignoreChange = false;
034:            private Vector selectionListeners = new Vector();
035:            CalendarDate startPeriod = null;
036:            CalendarDate endPeriod = null;
037:            public JNCalendarCellRenderer renderer = new JNCalendarCellRenderer();
038:
039:            public JNCalendar() {
040:                this (CurrentDate.get());
041:            }
042:
043:            /**
044:             * Constructor for JNCalendar.
045:             */
046:            public JNCalendar(CalendarDate date) {
047:                super ();
048:                /* table properties */
049:                setCellSelectionEnabled(true);
050:                setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
051:                getTableHeader().setReorderingAllowed(false);
052:                getTableHeader().setResizingAllowed(false);
053:                set(date);
054:
055:                /* selection listeners */
056:                final ListSelectionModel rowSM = getSelectionModel();
057:                final ListSelectionModel colSM = getColumnModel()
058:                        .getSelectionModel();
059:                ListSelectionListener lsl = new ListSelectionListener() {
060:                    public void valueChanged(ListSelectionEvent e) {
061:                        //Ignore extra messages.
062:                        if (e.getValueIsAdjusting())
063:                            return;
064:                        if (ignoreChange)
065:                            return;
066:                        int row = getSelRow();
067:                        int col = getSelCol();
068:                        Object val = getModel().getValueAt(row, col);
069:                        if (val != null) {
070:                            if (val.toString().equals(
071:                                    new Integer(_date.getDay()).toString()))
072:                                return;
073:                            _date = new CalendarDate(
074:                                    new Integer(val.toString()).intValue(),
075:                                    _date.getMonth(), _date.getYear());
076:                            notifyListeners();
077:                        } else {
078:                            //getSelectionModel().clearSelection();
079:                            doSelection();
080:                        }
081:                    }
082:
083:                };
084:                rowSM.addListSelectionListener(lsl);
085:                colSM.addListSelectionListener(lsl);
086:            }
087:
088:            int getSelRow() {
089:                return this .getSelectedRow();
090:            }
091:
092:            int getSelCol() {
093:                return this .getSelectedColumn();
094:            }
095:
096:            public JNCalendar(CalendarDate date, CalendarDate sd,
097:                    CalendarDate ed) {
098:                this (date);
099:                setSelectablePeriod(sd, ed);
100:            }
101:
102:            public void set(CalendarDate date) {
103:                _date = date;
104:                setCalendarParameters();
105:                ignoreChange = true;
106:                this .setModel(new JNCalendarModel());
107:                ignoreChange = false;
108:                doSelection();
109:            }
110:
111:            public CalendarDate get() {
112:                return _date;
113:            }
114:
115:            public void addSelectionListener(ActionListener al) {
116:                selectionListeners.add(al);
117:            }
118:
119:            public void setSelectablePeriod(CalendarDate sd, CalendarDate ed) {
120:                startPeriod = sd;
121:                endPeriod = ed;
122:            }
123:
124:            private void notifyListeners() {
125:                for (int i = 0; i < selectionListeners.size(); i++) {
126:                    ((ActionListener) selectionListeners.get(i))
127:                            .actionPerformed(new ActionEvent(this , 0,
128:                                    "Calendar event"));
129:                }
130:            }
131:
132:            public TableCellRenderer getCellRenderer(int row, int column) {
133:                Object d = this .getModel().getValueAt(row, column);
134:                /*
135:                 * if (d != null) return new JNCalendarCellRenderer( new
136:                 * CalendarDate(new Integer(d.toString()).intValue(), _date.getMonth(),
137:                 * _date.getYear()));
138:                 */
139:                if (d != null)
140:                    renderer.setDate(new CalendarDate(new Integer(d.toString())
141:                            .intValue(), _date.getMonth(), _date.getYear()));
142:                else
143:                    renderer.setDate(null);
144:                return renderer;
145:            }
146:
147:            void doSelection() {
148:                ignoreChange = true;
149:                int selRow = getRow(_date.getDay());
150:                int selCol = getCol(_date.getDay());
151:                this .setRowSelectionInterval(selRow, selRow);
152:                this .setColumnSelectionInterval(selCol, selCol);
153:                ignoreChange = false;
154:            }
155:
156:            int getRow(int day) {
157:                return ((day - 1) + firstDay) / 7;
158:            }
159:
160:            int getCol(int day) {
161:                return ((day - 1) + firstDay) % 7;
162:            }
163:
164:            int firstDay;
165:            int daysInMonth;
166:
167:            void setCalendarParameters() {
168:                int d = 1;
169:
170:                Calendar cal = _date.getCalendar();
171:
172:                if (Configuration.get("FIRST_DAY_OF_WEEK").equals("mon")) {
173:                    cal.setFirstDayOfWeek(Calendar.MONDAY);
174:                    d = 2;
175:                } else
176:                    cal.setFirstDayOfWeek(Calendar.SUNDAY);
177:
178:                cal.set(Calendar.DAY_OF_MONTH, 1);
179:                cal.getTime();
180:                firstDay = cal.get(Calendar.DAY_OF_WEEK) - d;
181:                if (firstDay == -1)
182:                    firstDay = 6;
183:                daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
184:            }
185:
186:            /*$Id: JNCalendar.java,v 1.8 2004/11/05 07:38:10 pbielen Exp $*/
187:            public class JNCalendarModel extends AbstractTableModel {
188:
189:                private String[] dayNames = Local.getWeekdayNames();
190:
191:                public JNCalendarModel() {
192:                    super ();
193:                }
194:
195:                public int getColumnCount() {
196:                    return 7;
197:                }
198:
199:                public Object getValueAt(int row, int col) {
200:                    //int pos = (row * 7 + col) - firstDay + 1;
201:                    int pos = (row * 7 + (col + 1)) - firstDay;
202:                    if ((pos > 0) && (pos <= daysInMonth))
203:                        return new Integer(pos);
204:                    else
205:                        return null;
206:
207:                }
208:
209:                public int getRowCount() {
210:                    return 6;
211:                }
212:
213:                public String getColumnName(int col) {
214:                    return dayNames[col];
215:                }
216:
217:            }
218:
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.