diff options
Diffstat (limited to 'client')
| -rw-r--r-- | client/AboutWindow.java | 49 | ||||
| -rw-r--r-- | client/CalendarTableCellRenderer.java | 135 | ||||
| -rw-r--r-- | client/CalendarTableModel.java | 434 | ||||
| -rw-r--r-- | client/InfoWindow.java | 57 | ||||
| -rw-r--r-- | client/LicenseWindow.java | 33 | ||||
| -rw-r--r-- | client/NetCalendarClient.java | 731 | ||||
| -rw-r--r-- | client/ServerRequester.java | 82 | ||||
| -rw-r--r-- | client/SplashScreen.java | 42 | ||||
| -rw-r--r-- | client/SubWindow.java | 101 | ||||
| -rw-r--r-- | client/helper/DateSpinner.java | 57 | ||||
| -rw-r--r-- | client/helper/GUIHelper.java | 189 | ||||
| -rw-r--r-- | client/inputforms/AdvancedSearching.java | 140 | ||||
| -rw-r--r-- | client/inputforms/CreateNewEvent.java | 122 | ||||
| -rw-r--r-- | client/inputforms/EditExistingEvent.java | 156 | ||||
| -rw-r--r-- | client/inputforms/InputForm.java | 93 | ||||
| -rw-r--r-- | client/inputforms/Preferences.java | 99 | ||||
| -rw-r--r-- | client/inputforms/RenameCategory.java | 123 |
17 files changed, 2643 insertions, 0 deletions
diff --git a/client/AboutWindow.java b/client/AboutWindow.java new file mode 100644 index 0000000..d3e8008 --- /dev/null +++ b/client/AboutWindow.java @@ -0,0 +1,49 @@ +package client; + +import shared.*; + +/** + * This window simply shows an about message about the + * netcalendar. + * @author paul.buetow + * + */ +public class AboutWindow extends InfoWindow { + final static long serialVersionUID = 1L; + /** + * Creates the window and shows it. + * @param sTitleText Specifies the title text of this JFrame. + * @param netCalendarClient Specifies the calendar client session object to use. + */ + public AboutWindow(NetCalendarClient netCalendarClient) { + super(netCalendarClient, "About", + Config.VERSION + "\n" + + "Copyright (C) 2006, 2009 by Paul C. Buetow; " + + "Web: netcalendar.buetow.org; E-Mail: " + getEmailAddr() + "\n\n" + + "NetCalendar is a network capable and mostly UNIX /usr/bin/calendar database compatible Calendar application " + + "programmed in Java. Its initial motivation was a programming project at the Aachen " + + "University of Applied Sciences (www.fh-aachen.de) for the object oriented " + + "programming class. But it became much more than just that!\n\n" + + "Credits:\n\n" + + "Bernhard Schertl " + + "for testing and suggestions for improvements; Web: www.b78.org\n\n" + + "Prof. Dr. rer. nat. H. Fassbender " + + "for supervision of expert opinion; Web: www.fassbender.fh-aachen.de\n\n" + + "Florian P. Buetow " + + "for ideas concerning the splash image; Web: www.florianbuetow.com" + ); + } + + /** + * This method simply returns a string containing the contact email address. + * This method is needed to protect this sourcecode + the email address for + * internet spam because some spambots try to fetch this address from the + * cvsweb interface. + * @return Returns a string containing the contact email address. + */ + private static String getEmailAddr() { + String sEmail = "netcalendar at dev dot buetow dot org"; + sEmail = sEmail.replaceAll(" at ", "@"); + return sEmail.replaceAll(" dot ", "."); + } +} diff --git a/client/CalendarTableCellRenderer.java b/client/CalendarTableCellRenderer.java new file mode 100644 index 0000000..11d2a1c --- /dev/null +++ b/client/CalendarTableCellRenderer.java @@ -0,0 +1,135 @@ +package client; + +import java.awt.*; + +import javax.swing.*; +import javax.swing.table.*; +import java.util.*; + +import shared.*; + +/** + * This class is responsible for the rendering of the JTable of the client gui which contains + * all the events. + * @author buetow + */ +public class CalendarTableCellRenderer extends DefaultTableCellRenderer { + private static final long serialVersionUID = 1L; + private CalendarTableModel tableModel; + // private NetCalendarClient netCalendarClient; + + private static final Color SELECTED_BACKGROUND_COLOR; + private static final Color SELECTED_FOREGROUND_COLOR; + private static final Color ALREADY_OVER_BACKGROUND_COLOR; + private static final Color ALREADY_OVER_FOREGROUND_COLOR; + private static final Color STANDARD_FOREGROUND_COLOR; + private static final Color BACKGROUND_COLOR_1_DAY; + private static final Color BACKGROUND_COLOR_7_DAYS; + private static final Color BACKGROUND_COLOR_28_DAYS; + private static final Color BACKGROUND_COLOR_168_DAYS; + private static final Color BACKGROUND_COLOR_365_DAYS; + private static final Color BACKGROUND_COLOR_MT_365_DAYS; + private static final Color YEARLY_BACKGROUND_COLOR; + private static final Color NOT_YEARLY_BACKGROUND_COLOR; + + + private static final long NANOSECONDS_1_DAY; + private static final long NANOSECONDS_7_DAYS; + private static final long NANOSECONDS_28_DAYS; + private static final long NANOSECONDS_168_DAYS; + private static final long NANOSECONDS_365_DAYS; + + // Initialize once, use often! + static { + SELECTED_BACKGROUND_COLOR = new Color(0, 0, 0); + SELECTED_FOREGROUND_COLOR = new Color(255, 255, 255); + STANDARD_FOREGROUND_COLOR = new Color(0, 0, 0); + ALREADY_OVER_FOREGROUND_COLOR = SELECTED_BACKGROUND_COLOR; + ALREADY_OVER_BACKGROUND_COLOR = SELECTED_FOREGROUND_COLOR; + BACKGROUND_COLOR_1_DAY = new Color(0xff, 0x00, 0x00); + BACKGROUND_COLOR_7_DAYS = new Color(0xff, 0x6c, 0x00); + BACKGROUND_COLOR_28_DAYS = new Color(0xff, 0xa5, 0x00); + BACKGROUND_COLOR_168_DAYS = new Color(0xe7, 0xa5, 0x5e); + BACKGROUND_COLOR_365_DAYS = new Color(230, 218, 161); + BACKGROUND_COLOR_MT_365_DAYS = new Color(0xa2, 0x9c, 0x90); // For more than 365 days + + YEARLY_BACKGROUND_COLOR = new Color(0x65, 0xa9, 0xe3); + NOT_YEARLY_BACKGROUND_COLOR = new Color(0x88, 0xe0, 0x90); + + + NANOSECONDS_1_DAY = 3600 * 24 * 1000; + NANOSECONDS_7_DAYS = NANOSECONDS_1_DAY * 7; + NANOSECONDS_28_DAYS = NANOSECONDS_7_DAYS * 4; + NANOSECONDS_168_DAYS = NANOSECONDS_28_DAYS * 6; + NANOSECONDS_365_DAYS = NANOSECONDS_1_DAY * 365; + } + + /** + * This method creates a custom table cell renderer for the calendar client. + * Its coloring the different cells and sets other special display attributes. + * @param tableModel Specifies the DefaultTableModel object used by the JTable. This is needed to make decisions about displaying a specific cell. + */ + public CalendarTableCellRenderer(CalendarTableModel tableModel) { + // this.netCalendarClient = netCalendarClient; + this.tableModel = tableModel; + } + + /** + * This method returns the Component object of a specific table cell. + * @param jTable Specifies the table object of the calendar client frame. + * @param object Specifies the object which is inside of the specific table cell. + * @param isSelected Specifies if the current cell is selected or not. + * @param hasFocus Specifies if the current cell is focused or not. + * @param iRow Specifies thr row number of the current cell. + * @param iCol specifies the column number of the current cell. + * @return Returns the Component object of a specific table cell. + */ + public Component getTableCellRendererComponent(JTable jTable, Object object, + boolean isSelected, boolean hasFocus, int iRow, int iCol){ + JLabel jLable =(JLabel) super.getTableCellRendererComponent(jTable, object, isSelected, hasFocus, iRow, iCol); + + //MyVector vecSelected = netCalendarClient.getSelectedIndexes(); + + //if (vecSelected.hasLike(new Integer(iRow))) { + if (isSelected) { + jLable.setBackground(SELECTED_BACKGROUND_COLOR); + jLable.setForeground(SELECTED_FOREGROUND_COLOR); + return jLable; + } + + CalendarEvent calendarEvent = tableModel.getEvent(iRow); + jLable.setForeground(STANDARD_FOREGROUND_COLOR); + + if (iCol <= 1) { + if (!calendarEvent.isYearly()) + jLable.setBackground(NOT_YEARLY_BACKGROUND_COLOR); + else + jLable.setBackground(YEARLY_BACKGROUND_COLOR); + + return jLable; + } + + long lCurrentTime = new Date().getTime(); + long lEventTime = calendarEvent.getDate().getTime(); + + if (lCurrentTime + NANOSECONDS_1_DAY > lEventTime) + jLable.setBackground(BACKGROUND_COLOR_1_DAY); + + else if (lCurrentTime + NANOSECONDS_7_DAYS > lEventTime) + jLable.setBackground(BACKGROUND_COLOR_7_DAYS); + + else if (lCurrentTime + NANOSECONDS_28_DAYS > lEventTime) + jLable.setBackground(BACKGROUND_COLOR_28_DAYS); + + else if (lCurrentTime + NANOSECONDS_168_DAYS > lEventTime) + jLable.setBackground(BACKGROUND_COLOR_168_DAYS); + + else if (lCurrentTime + NANOSECONDS_365_DAYS > lEventTime) + jLable.setBackground(BACKGROUND_COLOR_365_DAYS); + + else + jLable.setBackground(BACKGROUND_COLOR_MT_365_DAYS); + + return jLable; + } +} diff --git a/client/CalendarTableModel.java b/client/CalendarTableModel.java new file mode 100644 index 0000000..146c20b --- /dev/null +++ b/client/CalendarTableModel.java @@ -0,0 +1,434 @@ +package client; + +import javax.swing.table.*; +import javax.swing.*; +import java.util.*; +import shared.*; +import shared.remotecall.*; + +/** + * This class defined the table model of the JTable of the main calendar client window. All table + * data and most of the table actions, like sorting or updating the content, go trough this class. + * @author buetow + * + */ +public final class CalendarTableModel extends AbstractTableModel { + public static final String NUM_HEADER = "#"; + public static final String DATE_HEADER = "Date"; + public static final String CATEGORY_HEADER = "Category"; + public static final String DESCRIPTION_HEADER = "Description"; + public static final String PLACE_HEADER = "Place"; + + private static final int iEnumLength = Config.getStringValue("client_max_events").length(); + private static final long serialVersionUID = 1L; + private static final int iCols = 5; // Num of columns never changes! + private int iRows = 0; + private Vector vecEvents; + private Comparator lastSortComparator = null; + private JTable jTable; + + /** + * Simple constructor, creates a calendar table model to be used with the JTable of the netcalendar client main window. + * @param jTable Specifies the JTable object of this table model. + */ + public CalendarTableModel(JTable jTable) { + this.jTable = jTable; + } + + /** + * This method returns the number of columns of the JTable. + * @return Returns the number of columns of the JTable. + */ + public int getColumnCount() { + return iCols; + } + + /** + * This method retuns the number of rows of the JTable. + * @return Returns the number of rows of the JTable. + */ + public int getRowCount() { + return iRows; + } + + /** + * This method sets the number of rows of the JTable. + * @param iRows Specifies the number of rows of the JTable. + */ + public void setRowCount(int iRows) { + this.iRows = iRows; + } + + /** + * This method checks if a cell is editable or not. + * @param iRow Specifies the tables row. + * @param iCol Specifies the tables column. + * @return Returns true if the cell is editable. Else, false will be returned. + */ + public boolean isCellEditable(int iRow, int iCol) { + if (iCol > 1) + return true; + + return false; + } + + /** + * Gets a specific table value + * @param iRow Specifies the tables row + * @param iCol Specifies the tables column + * @return Returns the object at (row,column) + */ + public Object getValueAt(int iRow, int iCol) { + CalendarEvent calendarEvent = (CalendarEvent) vecEvents.get(iRow); + + switch (iCol) { + case 0: String sEnum = "" + (iRow + 1); + while (sEnum.length() < iEnumLength) + sEnum = "0" + sEnum; + return sEnum; + case 1: return calendarEvent.getDate(); + case 2: return calendarEvent.getDescription(); + case 3: return calendarEvent.getCategoryName(); + case 4: return calendarEvent.getPlace(); + } + + return "N/A"; + } + + /** + * This function updates the data of the JTable. + * @param object Specifies the new value. + * @param iRow Specifies the row of the cell to be updated. + * @param iCol Specifies the column of the cell to be updated. + */ + public void setValueAt(Object object, int iRow, int iCol) { + CalendarEvent calendarEvent = (CalendarEvent) vecEvents.get(iRow); + + switch (iCol) { + case 2: calendarEvent.setDescription((String) object); + break; + case 3: calendarEvent.setCategoryName((String) object); + break; + case 4: calendarEvent.setPlace((String) object); + break; + default: return; + } + + runLastSorter(); + jTable.updateUI(); + + ClientRequest clientRequest = new ClientRequest(ClientRequest.MODIFY_EVENT); + clientRequest.setEvent(calendarEvent); + ServerRequester.sendClientRequest(clientRequest); + } + + /** + * This method returns the class types of a specific table column. + * @param iCol Specifies the column index to get the class type for. + * @return Returns the class type of the specified column. + */ + public Class getColumnClass(int iCol) { + switch (iCol) { + case 0: return String.class; + case 1: return MyDate.class; + case 2: return String.class; + case 3: return String.class; + case 4: return String.class; + } + + return String.class; + } + + /** + * This method returns the column header of a specific table column. + * @param iCol Specifies the column index to get the column header for. + * @return Returns the header string of the specified column. + */ + public String getColumnName(int iCol) { + switch (iCol) { + case 0: return NUM_HEADER; + case 1: return DATE_HEADER; + case 2: return DESCRIPTION_HEADER; + case 3: return CATEGORY_HEADER; + case 4: return PLACE_HEADER; + } + + return "N/A"; + } + + /** + * This method returns the calendar event which belongs to a specific table row + * @param iRow Specifies the table row index + * @return Returns the calendar event + */ + public CalendarEvent getEvent(int iRow) { + return (CalendarEvent) vecEvents.get(iRow); + } + + /** + * This method updates all the value objects (calendar events) of the table. + * @param vecEvents Specifies the vector of the events to be used. + */ + public void setEvents(Vector vecEvents) { + if (vecEvents == null) + return; + + this.vecEvents = vecEvents; + setRowCount(vecEvents.size()); + + runLastSorter(); + } + + /** + * This method sorts the data again using the last sorting method being used. + */ + private void runLastSorter() { + if (lastSortComparator == null) { + sortByDate(); + + } else { + Collections.sort(vecEvents, lastSortComparator); + jTable.updateUI(); + } + } + + /** + * Sorts the table content by a specified table column. + * @param iCol Specifies the table column to sort against. + */ + public void sortByCol(int iCol) { + switch (iCol) { + case 0: + case 1: sortByDate(); + break; + case 2: sortByDescription(); + break; + case 3: sortByCategory(); + break; + case 4: sortByPlace(); + break; + } + } + + /** + * Reverse sorts the table content by a specified table column. + * @param iCol Specifies the table column to reverse sort against. + */ + public void reverseSortByCol(int iCol) { + switch (iCol) { + case 0: + case 1: reverseSortByDate(); + break; + case 2: reverseSortByDescription(); + break; + case 3: reverseSortByCategory(); + break; + case 4: reverseSortByPlace(); + break; + } + } + + /** + * Sorts the table content by their IDs. + */ + public void sortByID() { + Main.statusMessage("Sorting by ID..."); + + lastSortComparator = new Comparator() { + public int compare(Object objectA, Object objectB) { + int i = ((CalendarEvent) objectA).getID(); + int j = ((CalendarEvent) objectB).getID(); + if (i == j) + return 0; + else if (i < j) + return -1; + else + return 1; + } + public boolean equals(Object object) { return false; } + }; + Collections.sort(vecEvents, lastSortComparator); + jTable.updateUI(); + + Main.statusMessage("Sorting by date done"); + } + + /** + * Sorts the table content by their dates. + */ + public void sortByDate() { + Main.statusMessage("Sorting by date..."); + + lastSortComparator = new Comparator() { + public int compare(Object objectA, Object objectB) { + long l = ((CalendarEvent) objectA).getDate().getTime(); + long m = ((CalendarEvent) objectB).getDate().getTime(); + if (l == m) + return 0; + else if (l < m) + return -1; + else + return 1; + } + public boolean equals(Object object) { return false; } + }; + Collections.sort(vecEvents, lastSortComparator); + jTable.updateUI(); + + Main.statusMessage("Sorting by date done"); + } + + /** + * Sorts the table content by their category names. + */ + public void sortByCategory() { + Main.statusMessage("Sorting by category..."); + lastSortComparator = new Comparator() { + public int compare(Object objectA, Object objectB) { + CalendarEvent eventA = (CalendarEvent) objectA; + CalendarEvent eventB = (CalendarEvent) objectB; + return eventA.getCategoryName().compareTo(eventB.getCategoryName()); + } + public boolean equals(Object object) { return false; } + }; + Collections.sort(vecEvents, lastSortComparator); + jTable.updateUI(); + Main.statusMessage("Sorting by category done"); + } + + /** + * Sorts the table content by their description texts. + */ + public void sortByDescription() { + Main.statusMessage("Sorting by description..."); + lastSortComparator = new Comparator() { + public int compare(Object objectA, Object objectB) { + CalendarEvent eventA = (CalendarEvent) objectA; + CalendarEvent eventB = (CalendarEvent) objectB; + return eventA.getDescription().compareTo(eventB.getDescription()); + } + public boolean equals(Object object) { return false; } + }; + Collections.sort(vecEvents, lastSortComparator); + jTable.updateUI(); + Main.statusMessage("Sorting by description done"); + } + + /** + * Sorts the table content by their places. + */ + public void sortByPlace() { + Main.statusMessage("Sorting by place..."); + lastSortComparator = new Comparator() { + public int compare(Object objectA, Object objectB) { + CalendarEvent eventA = (CalendarEvent) objectA; + CalendarEvent eventB = (CalendarEvent) objectB; + return eventA.getPlace().compareTo(eventB.getPlace()); + } + public boolean equals(Object object) { return false; } + }; + Collections.sort(vecEvents, lastSortComparator); + jTable.updateUI(); + Main.statusMessage("Sorting by place done"); + } + + /** + * Reverse sorts the table content by their IDs. + */ + public void reverseSortByID() { + Main.statusMessage("Reverse sorting by date..."); + lastSortComparator = new Comparator() { + public int compare(Object objectA, Object objectB) { + long i = ((CalendarEvent) objectA).getID(); + long j = ((CalendarEvent) objectB).getID(); + if (i == j) + return 0; + else if (i > j) + return -1; + else + return 1; + } + public boolean equals(Object object) { return false; } + }; + Collections.sort(vecEvents, lastSortComparator); + jTable.updateUI(); + Main.statusMessage("Reverse sorting by date done"); + } + + /** + * Reverse sorts the table content by their dates. + */ + public void reverseSortByDate() { + Main.statusMessage("Reverse sorting by date..."); + lastSortComparator = new Comparator() { + public int compare(Object objectA, Object objectB) { + long l = ((CalendarEvent) objectA).getDate().getTime(); + long m = ((CalendarEvent) objectB).getDate().getTime(); + if (l == m) + return 0; + else if (l > m) + return -1; + else + return 1; + } + public boolean equals(Object object) { return false; } + }; + Collections.sort(vecEvents, lastSortComparator); + jTable.updateUI(); + Main.statusMessage("Reverse sorting by date done"); + } + + /** + * Reverse sorts the table content by their category names. + */ + public void reverseSortByCategory() { + Main.statusMessage("Reverse sorting by category..."); + lastSortComparator = new Comparator() { + public int compare(Object objectA, Object objectB) { + CalendarEvent eventA = (CalendarEvent) objectA; + CalendarEvent eventB = (CalendarEvent) objectB; + return eventB.getCategoryName().compareTo(eventA.getCategoryName()); + } + public boolean equals(Object object) { return false; } + }; + Collections.sort(vecEvents, lastSortComparator); + jTable.updateUI(); + Main.statusMessage("Reverse sorting by category done"); + } + + /** + * Reverse sorts the table content by their description texts. + */ + public void reverseSortByDescription() { + Main.statusMessage("Reverse sorting by description..."); + lastSortComparator = new Comparator() { + public int compare(Object objectA, Object objectB) { + CalendarEvent eventA = (CalendarEvent) objectA; + CalendarEvent eventB = (CalendarEvent) objectB; + return eventB.getDescription().compareTo(eventA.getDescription()); + } + public boolean equals(Object object) { return false; } + }; + Collections.sort(vecEvents, lastSortComparator); + jTable.updateUI(); + Main.statusMessage("Reverse sorting by description done!"); + } + + /** + * Reverse sorts the table content by their places. + */ + public void reverseSortByPlace() { + Main.statusMessage("Reverse sorting by place..."); + lastSortComparator = new Comparator() { + public int compare(Object objectA, Object objectB) { + CalendarEvent eventA = (CalendarEvent) objectA; + CalendarEvent eventB = (CalendarEvent) objectB; + return eventB.getPlace().compareTo(eventA.getPlace()); + } + public boolean equals(Object object) { return false; } + }; + Collections.sort(vecEvents, lastSortComparator); + jTable.updateUI(); + Main.statusMessage("Reverse sorting by place done"); + } +} diff --git a/client/InfoWindow.java b/client/InfoWindow.java new file mode 100644 index 0000000..6b8c32b --- /dev/null +++ b/client/InfoWindow.java @@ -0,0 +1,57 @@ +package client; + +import java.awt.*; +import javax.swing.*; + +/** + * This window simply shows an about message about the + * netcalendar. + * @author paul.buetow + * + */ +public class InfoWindow extends SubWindow { + final static long serialVersionUID = 1L; + private String sText; + + /** + * Creates the window and shows it. + * @param netCalendarClient Specifies the calendar client session object to use. + * @param jTitle Speicifies the title text to be displayd in the title bar. + * @param jText Specifies the text to be displayed at the text area. + */ + public InfoWindow(NetCalendarClient netCalendarClient, String jTitle, String sText) { + super(jTitle, netCalendarClient); + this.sText = sText; + initComponents(); + setResizable(false); + pack(); + setVisible(true); + } + + /** + * This method initializes all the GUI components. + */ + protected void initComponents() { + setSize(306,400); + JPanel contentPane = (JPanel) getContentPane(); + contentPane.setBackground(Color.BLACK); + + // Build the splash screen + JLabel jLabel = new JLabel(new ImageIcon("images/netcal.png")); + contentPane.add(jLabel, BorderLayout.CENTER); + + JTextArea jTextArea = new JTextArea(); + jTextArea.setEditable(false); + jTextArea.setBackground(Color.BLACK); + jTextArea.setForeground(Color.WHITE); + jTextArea.setLineWrap(true); + jTextArea.setWrapStyleWord(true); + jTextArea.setMargin(new Insets(10, 10, 10, 10)); + jTextArea.setText(sText); + jTextArea.setFocusable(false); + jTextArea.setEnabled(false); + JScrollPane jScrollPane = new JScrollPane(jTextArea); + jScrollPane.setPreferredSize(new Dimension(306, 400-261)); + contentPane.add(jScrollPane, BorderLayout.SOUTH); + } +} diff --git a/client/LicenseWindow.java b/client/LicenseWindow.java new file mode 100644 index 0000000..0f683ed --- /dev/null +++ b/client/LicenseWindow.java @@ -0,0 +1,33 @@ +package client; + +import shared.*; + +/** + * This window simply shows an license message. + * @author buetow + * + */ +public class LicenseWindow extends InfoWindow { + final static long serialVersionUID = 1L; + /** + * Creates the window and shows it. + * @param netCalendarClient Specifies the calendar client session object to use. + */ + public LicenseWindow(NetCalendarClient netCalendarClient) { + super(netCalendarClient, "License", + Config.VERSION + "\n" + + "Copyright (C) 2006, 2009 by Paul C. Buetow\n\n" + + "This program is free software; you can redistribute it and/or " + + "modify it under the terms of the GNU General Public License " + + "as published by the Free Software Foundation; either version 2 " + + "of the License, or (at your option) any later version.\n\n" + + "This program is distributed in the hope that it will be useful, " + + "but WITHOUT ANY WARRANTY; without even the implied warranty of " + + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " + + "GNU General Public License for more details.\n\n" + + "You should have received a copy of the GNU General Public License " + + "along with this program; if not, write to the Free Software " + + "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA." + ); + } +} diff --git a/client/NetCalendarClient.java b/client/NetCalendarClient.java new file mode 100644 index 0000000..ac5fcda --- /dev/null +++ b/client/NetCalendarClient.java @@ -0,0 +1,731 @@ +/** + */ + +package client; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.table.*; +import java.util.*; + +import shared.*; +import shared.remotecall.*; +import client.inputforms.*; + +/** + * This is the main class of the client part of the netcalendar suite. It contains the main GUI. + * All subguis are created within this class. + * @author buetow + */ +public class NetCalendarClient extends JFrame { + private static final long serialVersionUID = 1L; + private static int iNextSession = 1; + private static int iNumCurrentSessions = 0; + private int iCurrentSession; + private NetCalendarClient netCalendarClient; + private Vector vecFrames = new Vector(); + + // Diverse components + private ClientRequest lastClientRequest = null; + protected int iCurrentMouseSelectedRow = 0; + protected int iCurrentMouseSelectedCol = 0; + + // GUI components + private JMenuBar jMenuBar; + private JPopupMenu jPopupMenu; + private CalendarTableModel tableModel; + private JTable jTable; + + private JTextField jTextFieldRegexp; + private JTextField jTextFieldStatusMessages; + + // Some callback objects + private DoCallback doCallbackEditEvent; + private DoCallback doCallbackDeleteEvent; + private DoCallback doCallbackCopyEvent; + private DoCallback doCallbackDeleteCategory; + private DoCallback doCallbackRenameCategory; + + // Static GUI strings which needs to be specified at least twice + private final static String DELETE_EVENT = "Delete event(s)"; + private final static String EDIT_EVENT = "Edit event(s)"; + private final static String COPY_EVENT = "Copy event(s)"; + private final static String CREATE_EVENT = "Create new event"; + private final static String DELETE_CATEGORY = "Delete whole category(s)"; + private final static String RENAME_CATEGORY = "Rename whole category(s)"; + private final static String ADVANCED_SEARCH = "Advanced searching"; + private final static String SORT_BY_COL = "Sort by this row"; + private final static String REVERSE_SORT_BY_COL = "Reverse sort by this row"; + private final static String ENTER_REGEXP_HERE ="Enter some regexp search string here..."; + + /** + * Standard constructor, creates the client GUI. + */ + public NetCalendarClient() { + super(getSessionString(iNextSession) + Config.VERSION); + this.iCurrentSession = iNextSession++; + + // Save a reference of this to allow to access this object through + // inner-classes + // (See the "Advanced searching" action listener object for example!) + this.netCalendarClient = this; + iNumCurrentSessions++; + + initComponents(); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setLocationRelativeTo(null); + pack(); + setVisible(true); + + // Start a default request to the netcalendar server + update(new ClientRequest(ClientRequest.REQUEST_ALL_EVENTS)); + } + + /** + * Initializes all the GUI components. + */ + private void initComponents() { + this.addWindowListener(new WindowListener() { + public void windowActivated(WindowEvent e) { } + public void windowClosing(WindowEvent e) {} + public void windowDeactivated(WindowEvent e) {} + public void windowDeiconified(WindowEvent e) {} + public void windowIconified(WindowEvent e) { } + public void windowOpened(WindowEvent e) {} + public void windowClosed(WindowEvent e) { + if (--iNumCurrentSessions == 0) + Main.exit(0); + + Main.infoMessage("Closing a session window"); + } + }); + + Container container = getContentPane(); + + jMenuBar = new JMenuBar(); + setJMenuBar(jMenuBar); + + JMenu jMenuSession = new JMenu("Session"); + jMenuBar.add(jMenuSession); + + JMenuItem jMenuItemNewWindow = new JMenuItem("New window"); + jMenuSession.add(jMenuItemNewWindow); + jMenuItemNewWindow.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + new NetCalendarClient(); + } + }); + + JMenuItem jMenuItemCloseWindow = new JMenuItem("Close window"); + jMenuSession.add(jMenuItemCloseWindow); + jMenuItemCloseWindow.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + dispose(); + } + }); + + jMenuSession.add(new JSeparator()); + + JMenuItem jMenuItemPreferences = new JMenuItem("Preferences"); + jMenuSession.add(jMenuItemPreferences); + jMenuItemPreferences.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + new Preferences(netCalendarClient); + } + }); + + jMenuSession.add(new JSeparator()); + + JMenuItem jMenuItemQuit = new JMenuItem("Quit"); + jMenuSession.add(jMenuItemQuit); + jMenuItemQuit.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + System.exit(0); + } + }); + + JMenu jMenuEdit = new JMenu("Edit"); + jMenuBar.add(jMenuEdit); + + JMenuItem jMenuItemCreate = new JMenuItem(CREATE_EVENT); + jMenuEdit.add(jMenuItemCreate); + jMenuItemCreate.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + new CreateNewEvent(netCalendarClient); + } + }); + + JMenuItem jMenuItemEdit = new JMenuItem(EDIT_EVENT); + jMenuEdit.add(jMenuItemEdit); + doCallbackEditEvent = new DoCallback() { + public void callback(Object obj) { + new EditExistingEvent(netCalendarClient, (CalendarEvent) obj); + } + }; + jMenuItemEdit.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + foreachSelectedEvent(doCallbackEditEvent); + } + }); + + JMenuItem jMenuItemCopy = new JMenuItem(COPY_EVENT); + jMenuEdit.add(jMenuItemCopy); + doCallbackCopyEvent = new DoCallback() { + public void callback(Object obj) { + CalendarEvent calendarEvent = (CalendarEvent) obj; + ClientRequest clientRequest = new ClientRequest(ClientRequest.ADD_EVENT); + clientRequest.setEvent(calendarEvent); + ServerRequester.sendClientRequest(clientRequest); + netCalendarClient.updateLast(); + } + }; + jMenuItemCopy.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + foreachSelectedEvent(doCallbackCopyEvent); + } + }); + + JMenuItem jMenuItemDelete = new JMenuItem(DELETE_EVENT); + jMenuEdit.add(jMenuItemDelete); + doCallbackDeleteEvent = new DoCallback() { + public void callback(Object obj) { + deleteEvent((CalendarEvent)obj); + jTable.getSelectionModel().clearSelection(); + } + }; + jMenuItemDelete.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + foreachSelectedEvent(doCallbackDeleteEvent); + } + }); + + jMenuEdit.add(new JSeparator()); + + JMenuItem jMenuItemRenameCategory = new JMenuItem(RENAME_CATEGORY); + jMenuEdit.add(jMenuItemRenameCategory); + doCallbackRenameCategory = new DoCallback() { + public void callback(Object obj) { + new RenameCategory(netCalendarClient, (CalendarEvent) obj); + jTable.getSelectionModel().clearSelection(); + } + }; + jMenuItemRenameCategory.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + foreachSelectedEvent(doCallbackRenameCategory); + } + }); + + JMenuItem jMenuItemDeleteCategory = new JMenuItem(DELETE_CATEGORY); + jMenuEdit.add(jMenuItemDeleteCategory); + doCallbackDeleteCategory = new DoCallback() { + public void callback(Object obj) { + deleteCategory((CalendarEvent)obj); + jTable.getSelectionModel().clearSelection(); + } + }; + jMenuItemDeleteCategory.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + foreachSelectedEvent(doCallbackDeleteCategory); + } + }); + + + JMenu jMenuSorting = new JMenu("Sorting"); + jMenuBar.add(jMenuSorting); + |
