summaryrefslogtreecommitdiff
path: root/client/NetCalendarClient.java
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2009-02-08 01:37:25 +0000
committerPaul Buetow <paul@buetow.org>2009-02-08 01:37:25 +0000
commit69f0e6b0bf0dc0a6c6fe8ccf17c74960697ca10c (patch)
tree4b99d266e90f2ac93e46b499b6e02c6dd4bcae18 /client/NetCalendarClient.java
1.0 releasedv0.1
Diffstat (limited to 'client/NetCalendarClient.java')
-rw-r--r--client/NetCalendarClient.java731
1 files changed, 731 insertions, 0 deletions
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);
+
+ JMenuItem jMenuItemSortByDate = new JMenuItem("Sort by date");
+ jMenuSorting.add(jMenuItemSortByDate);
+ jMenuItemSortByDate.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ tableModel.sortByDate();
+ }
+ });
+ JMenuItem jMenuItemSortByCategory = new JMenuItem("Sort by category");
+ jMenuSorting.add(jMenuItemSortByCategory);
+ jMenuItemSortByCategory.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ tableModel.sortByCategory();
+ }
+ });
+ JMenuItem jMenuItemSortByDescr = new JMenuItem("Sort by description");
+ jMenuSorting.add(jMenuItemSortByDescr);
+ jMenuItemSortByDescr.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ tableModel.sortByDescription();
+ }
+ });
+ JMenuItem jMenuItemSortByPlace = new JMenuItem("Sort by place");
+ jMenuSorting.add(jMenuItemSortByPlace);
+ jMenuItemSortByPlace.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ tableModel.sortByPlace();
+ }
+ });
+ JMenuItem jMenuItemSortByEventIDs = new JMenuItem("Sort by event IDs");
+ jMenuSorting.add(jMenuItemSortByEventIDs);
+ jMenuItemSortByEventIDs.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ tableModel.sortByID();
+ }
+ });
+
+ jMenuSorting.add(new JSeparator());
+
+ JMenuItem jMenuItemReverseSortByDate = new JMenuItem(
+ "Reverse sort by date");
+ jMenuSorting.add(jMenuItemReverseSortByDate);
+ jMenuItemReverseSortByDate.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ tableModel.reverseSortByDate();
+ }
+ });
+ JMenuItem jMenuItemReverseSortByCategory = new JMenuItem(
+ "Reverse sort by category");
+ jMenuSorting.add(jMenuItemReverseSortByCategory);
+ jMenuItemReverseSortByCategory.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ tableModel.reverseSortByCategory();
+ }
+ });
+ JMenuItem jMenuItemReverseSortByDescr = new JMenuItem(
+ "Reverse sort by description");
+ jMenuSorting.add(jMenuItemReverseSortByDescr);
+ jMenuItemReverseSortByDescr.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ tableModel.reverseSortByDescription();
+ }
+ });
+ JMenuItem jMenuItemReverseSortByPlace = new JMenuItem(
+ "Reverse sort by place");
+ jMenuSorting.add(jMenuItemReverseSortByPlace);
+ jMenuItemReverseSortByPlace.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ tableModel.reverseSortByPlace();
+ }
+ });
+ JMenuItem jMenuItemReverseSortByIDs = new JMenuItem(
+ "Reverse sort by event IDs");
+ jMenuSorting.add(jMenuItemReverseSortByIDs);
+ jMenuItemReverseSortByIDs.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ tableModel.reverseSortByID();
+ }
+ });
+
+ JMenu jMenuServer = new JMenu("Server");
+ jMenuBar.add(jMenuServer);
+
+ JMenuItem jMenuItemUpdate = new JMenuItem("Update events from server");
+ jMenuServer.add(jMenuItemUpdate);
+ jMenuItemUpdate.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ update(lastClientRequest);
+ }
+ });
+
+ JMenuItem jMenuItemGetAll = new JMenuItem("Get all events from server");
+ jMenuServer.add(jMenuItemGetAll);
+ ActionListener actionListenerGetAll = new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ update(new ClientRequest(ClientRequest.REQUEST_ALL_EVENTS));
+ }
+ };
+ jMenuItemGetAll.addActionListener(actionListenerGetAll);
+
+ JMenuItem jMenuItemAdvancedSearch = new JMenuItem(
+ "Advanced searching for events");
+ jMenuServer.add(jMenuItemAdvancedSearch);
+ jMenuItemAdvancedSearch.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ new AdvancedSearching(netCalendarClient);
+ }
+ });
+
+ jMenuServer.add(new JSeparator());
+
+ JMenuItem jMenuItemReloadDatabase = new JMenuItem("Reload database");
+ jMenuServer.add(jMenuItemReloadDatabase);
+ jMenuItemReloadDatabase.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ ServerRequester.sendClientRequest(new ClientRequest(
+ ClientRequest.RELOAD_DATABASE));
+ updateLast();
+ }
+ });
+ JMenuItem jMenuItemFlushDatabase = new JMenuItem("Flush database");
+ jMenuServer.add(jMenuItemFlushDatabase);
+ jMenuItemFlushDatabase.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ ServerRequester.sendClientRequest(new ClientRequest(
+ ClientRequest.FLUSH_DATABASE));
+ }
+ });
+
+ jMenuServer.add(new JSeparator());
+
+ JMenuItem jMenuItemShutdownServer = new JMenuItem("Shutdown server");
+ jMenuServer.add(jMenuItemShutdownServer);
+ jMenuItemShutdownServer.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ ServerRequester.sendClientRequest(new ClientRequest(
+ ClientRequest.SHUTDOWN_SERVER));
+ }
+ });
+
+ JMenu jMenuAbout = new JMenu("About");
+ jMenuBar.add(jMenuAbout);
+
+ JMenuItem jMenuItemAbout = new JMenuItem("About");
+ jMenuAbout.add(jMenuItemAbout);
+ jMenuItemAbout.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ new AboutWindow(netCalendarClient);
+ }
+ });
+ JMenuItem jMenuItemLicense = new JMenuItem("License");
+ jMenuAbout.add(jMenuItemLicense);
+ jMenuItemLicense.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ new LicenseWindow(netCalendarClient);
+ }
+ });
+
+ jPopupMenu = new JPopupMenu();
+ ActionListener jPopupMenuActionListener = new ActionListener() {
+ public void actionPerformed(ActionEvent actionEvent) {
+ String sActionCommand = actionEvent.getActionCommand();
+ if (sActionCommand.equals(DELETE_EVENT)) {
+ foreachSelectedEvent(doCallbackDeleteEvent);
+
+ } else if (sActionCommand.equals(CREATE_EVENT)) {
+ new CreateNewEvent(netCalendarClient);
+
+ } else if (sActionCommand.equals(EDIT_EVENT)) {
+ foreachSelectedEvent(doCallbackEditEvent);
+
+ } else if (sActionCommand.equals(COPY_EVENT)) {
+ foreachSelectedEvent(doCallbackCopyEvent);
+
+ } else if (sActionCommand.equals(RENAME_CATEGORY)) {
+ foreachSelectedEvent(doCallbackRenameCategory);
+
+ } else if (sActionCommand.equals(DELETE_CATEGORY)) {
+ foreachSelectedEvent(doCallbackDeleteCategory);
+
+ } else if (sActionCommand.equals(ADVANCED_SEARCH)) {
+ new AdvancedSearching(netCalendarClient);
+
+ } else if (sActionCommand.equals(SORT_BY_COL)) {
+ tableModel.sortByCol(iCurrentMouseSelectedCol);
+
+ } else if (sActionCommand.equals(REVERSE_SORT_BY_COL)) {
+ tableModel.reverseSortByCol(iCurrentMouseSelectedCol);
+ }
+ }
+ };
+
+ JMenuItem jMenuItemPopupCreate = new JMenuItem(CREATE_EVENT);
+ jMenuItemPopupCreate.addActionListener(jPopupMenuActionListener);
+ jPopupMenu.add(jMenuItemPopupCreate);
+ JMenuItem jMenuItemPopupEdit = new JMenuItem(EDIT_EVENT);
+ jMenuItemPopupEdit.addActionListener(jPopupMenuActionListener);
+ jPopupMenu.add(jMenuItemPopupEdit);
+ JMenuItem jMenuItemPopupCopy = new JMenuItem(COPY_EVENT);
+ jMenuItemPopupCopy.addActionListener(jPopupMenuActionListener);
+ jPopupMenu.add(jMenuItemPopupCopy);
+ JMenuItem jMenuItemPopupDelete = new JMenuItem(DELETE_EVENT);
+ jMenuItemPopupDelete.addActionListener(jPopupMenuActionListener);
+ jPopupMenu.add(jMenuItemPopupDelete);
+ jPopupMenu.add(new JSeparator());
+
+ JMenuItem jMenuItemPopupRenameCategory = new JMenuItem(RENAME_CATEGORY);
+ jMenuItemPopupRenameCategory.addActionListener(jPopupMenuActionListener);
+ jPopupMenu.add(jMenuItemPopupRenameCategory);
+ JMenuItem jMenuItemPopupDeleteCategory = new JMenuItem(DELETE_CATEGORY);
+ jMenuItemPopupDeleteCategory.addActionListener(jPopupMenuActionListener);
+ jPopupMenu.add(jMenuItemPopupDeleteCategory);
+ jPopupMenu.add(new JSeparator());
+
+ JMenuItem jMenuItemPopupSort = new JMenuItem(SORT_BY_COL);
+ jMenuItemPopupSort.addActionListener(jPopupMenuActionListener);
+ jPopupMenu.add(jMenuItemPopupSort);
+ JMenuItem jMenuItemPopupReverseSort = new JMenuItem(REVERSE_SORT_BY_COL);
+ jMenuItemPopupReverseSort.addActionListener(jPopupMenuActionListener);
+ jPopupMenu.add(jMenuItemPopupReverseSort);
+ jPopupMenu.add(new JSeparator());
+
+ JMenuItem jMenuItemPopupAdvancedSearch = new JMenuItem(ADVANCED_SEARCH);
+ jMenuItemPopupAdvancedSearch
+ .addActionListener(jPopupMenuActionListener);
+ jPopupMenu.add(jMenuItemPopupAdvancedSearch);
+
+ jTable = new JTable();
+ jTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+
+ jTable.setColumnModel(new DefaultTableColumnModel() {
+ private static final long serialVersionUID = 1L;
+ // Dont allow column moving!
+ public void moveColumn(int iColumnIndex, int iNewColumnIndex) { }
+ });
+
+ tableModel = new CalendarTableModel(jTable);
+ jTable.setModel(tableModel);
+ jTable.addMouseListener(new MouseListener() {
+ public void mouseClicked(MouseEvent mouseEvent) {
+ iCurrentMouseSelectedRow = jTable.rowAtPoint(mouseEvent.getPoint());
+ iCurrentMouseSelectedCol = jTable.columnAtPoint(mouseEvent.getPoint());
+
+ if (mouseEvent.getButton() != MouseEvent.BUTTON1)
+ jPopupMenu.show(jTable, mouseEvent.getX(), mouseEvent.getY());
+ }
+
+ public void mouseEntered(MouseEvent event) { }
+ public void mouseExited(MouseEvent event) {}
+ public void mousePressed(MouseEvent event) { }
+ public void mouseReleased(MouseEvent event) {
+ }
+ });
+
+ CalendarTableCellRenderer cellRenderer = new CalendarTableCellRenderer(tableModel);
+
+ TableColumn column = jTable.getColumn(CalendarTableModel.NUM_HEADER);
+ column.setMaxWidth(Config.getStringValue("client_max_events").length() * 10);
+ column.setResizable(false);
+ column.setCellRenderer(cellRenderer);
+
+ column = jTable.getColumn(CalendarTableModel.CATEGORY_HEADER);
+ column.setPreferredWidth(10);
+ column.setCellRenderer(cellRenderer);
+
+ column = jTable.getColumn(CalendarTableModel.PLACE_HEADER);
+ column.setPreferredWidth(10);
+ column.setCellRenderer(cellRenderer);
+
+ jTable.getColumn(CalendarTableModel.DATE_HEADER).setCellRenderer(cellRenderer);
+ jTable.getColumn(CalendarTableModel.DESCRIPTION_HEADER).setCellRenderer(cellRenderer);
+
+ jTextFieldRegexp = new JTextField();
+ jTextFieldRegexp.setText(ENTER_REGEXP_HERE);
+ jTextFieldRegexp.setEnabled(false);
+
+ ActionListener actionListenerSearchRegexp = new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ ClientRequest clientRequest = new ClientRequest();
+ clientRequest.setRegexpAll(jTextFieldRegexp.getText());
+ clientRequest.setMainRegexp(true);
+ jTextFieldRegexp.setText("");
+ update(ServerRequester.sendClientRequest(clientRequest));
+ lastClientRequest = clientRequest;
+ }
+ };
+ MouseListener mouseListenerSearchRegexp = new MouseListener() {
+ public void mouseClicked(MouseEvent mouseEvent) {}
+ public void mousePressed(MouseEvent mouseEvent) {}
+ public void mouseReleased(MouseEvent mouseEvent) {}
+ public void mouseExited(MouseEvent mouseEvent) {
+ if (jTextFieldRegexp.getText().equals("")) {
+ jTextFieldRegexp.setText(ENTER_REGEXP_HERE);
+ jTextFieldRegexp.setEnabled(false);
+ }
+ }
+ public void mouseEntered(MouseEvent mouseEvent) {
+ if (!jTextFieldRegexp.isEnabled()) {
+ jTextFieldRegexp.setText("");
+ jTextFieldRegexp.setEnabled(true);
+ }
+ }
+ };
+
+ jTextFieldRegexp.addActionListener(actionListenerSearchRegexp);
+ jTextFieldRegexp.addMouseListener(mouseListenerSearchRegexp);
+
+ JButton jButtonSearch = new JButton("Search");
+ jButtonSearch.addActionListener(actionListenerSearchRegexp);
+ jButtonSearch.addMouseListener(mouseListenerSearchRegexp);
+
+ JButton jButtonGetAll = new JButton("Get all");
+ jButtonGetAll.addActionListener(actionListenerGetAll);
+
+ // Init split panes
+ JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+ jSplitPane.setResizeWeight(1);
+ jSplitPane.setDividerSize(0);
+
+ JSplitPane jSplitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+ jSplitPane2.setResizeWeight(1);
+ jSplitPane2.setDividerSize(0);
+
+ JSplitPane jSplitPane3 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
+ jSplitPane3.setResizeWeight(1);
+ jSplitPane3.setDividerSize(0);
+
+ JSplitPane jSplitPane4 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
+ jSplitPane4.setDividerSize(0);
+
+ // Init components
+ JScrollPane jScrollPaneTable = new JScrollPane(jTable);
+
+ jTextFieldStatusMessages = new JTextField("Welcome to "
+ + Config.VERSION);
+ jTextFieldStatusMessages.setEditable(false);
+
+ // Set split pane components
+ jSplitPane.setTopComponent(jScrollPaneTable);
+ jSplitPane.setBottomComponent(jSplitPane2);
+
+ jSplitPane2.setTopComponent(jSplitPane3);
+ jSplitPane2.setBottomComponent(jTextFieldStatusMessages);
+
+ JPanel jPanelButtons = new JPanel();
+ jPanelButtons.add(jButtonSearch);
+ jPanelButtons.add(jButtonGetAll);
+
+ jSplitPane3.setLeftComponent(jTextFieldRegexp);
+ jSplitPane3.setRightComponent(jPanelButtons);
+
+ container.add(jSplitPane);
+ }
+
+ /**
+ * This method sends a client request object to the server and used the server response object
+ * to update the JTable ith its new values using the table model.
+ * @param clientRequest Specifies the client request object to use for the updating.
+ */
+ public void update(ClientRequest clientRequest) {
+ if (clientRequest == null)
+ return;
+
+ update(ServerRequester.sendClientRequest(clientRequest));
+ lastClientRequest = clientRequest;
+ }
+
+ /**
+ * This method sends the last client request object being used to the server again. If
+ * If there is no last client request, nothing will be done.
+ */
+ public void updateLast() {
+ if (lastClientRequest != null)
+ update(ServerRequester.sendClientRequest(lastClientRequest));
+ }
+
+ /**
+ * This method updates the GUI unsing a given server response object.
+ * @param serverResponse Specifies the server response to use for the updating.
+ */
+ public void update(ServerResponse serverResponse) {
+ if (serverResponse == null)
+ return;
+
+ tableModel.setEvents(serverResponse.getEvents());
+ }
+
+ /**
+ * This method tells the calendar server to delete a given calendar event.
+ * @param deleteEvent Specifies the calendar event to delete.
+ */
+ public void deleteEvent(CalendarEvent deleteEvent) {
+ ClientRequest deleteRequest = new ClientRequest(
+ ClientRequest.DELETE_EVENT);
+ deleteRequest.setEvent(deleteEvent);
+ ServerRequester.sendClientRequest(deleteRequest);
+ updateLast();
+ }
+
+ /**
+ * This method tells the calendar server to delete a given calendar category.
+ * @param deleteEventsCategory Specifies the calendar event to delete its category!
+ */
+ public void deleteCategory(CalendarEvent deleteEventsCategory) {
+ ClientRequest deleteRequest = new ClientRequest(
+ ClientRequest.DELETE_CATEGORY);
+ deleteRequest.setEvent(deleteEventsCategory);
+ ServerRequester.sendClientRequest(deleteRequest);
+ updateLast();
+ }
+
+ /**
+ * If the client has several main windows open, then it will display a
+ * session indicator so that the user knows which window belongs to which
+ * session window!
+ * @param iSession Specifies the session number of the current client window.
+ * @return Returns the session indicator of the current client session.
+ */
+ private static String getSessionString(int iSession) {
+ return iSession > 1 ? "[" + iSession + "] " : "";
+ }
+
+ /**
+ * If the client has several main windows open, then it will display a
+ * session indicator so that the user knows which window belongs to which
+ * session window.
+ * @return Returns the session indicator of the current client session.
+ */
+ public String getSessionString() {
+ return iCurrentSession > 1 ? "[" + iCurrentSession + "] " : "";
+ }
+
+ /**
+ * Runs a callback function on each selected event of the table.
+ * @param doCallback Specifies the callback object to be used.
+ */
+ public void foreachSelectedEvent(DoCallback doCallback) {
+ ListSelectionModel listSelectionModel = jTable.getSelectionModel();
+
+ int iMinIndex = listSelectionModel.getMinSelectionIndex();
+ int iMaxIndex = listSelectionModel.getMaxSelectionIndex();
+
+ Vector vecEvents = new Vector();
+
+ for (int i = iMinIndex; i <= iMaxIndex; ++i)
+ if (listSelectionModel.isSelectedIndex(i))
+ vecEvents.add(tableModel.getEvent(i));
+
+ Enumeration enumEvents = vecEvents.elements();
+ while (enumEvents.hasMoreElements())
+ doCallback.callback(enumEvents.nextElement());
+ }
+
+ /**
+ * This method is for various status messages. All messages will show up in the
+ * status bar of the current client session window.
+ * @param sMessage Specifies the message to be displayed in the status bar.
+ */
+ public void statusMessage(String sMessage) {
+ jTextFieldStatusMessages.setText(sMessage);
+ jTextFieldStatusMessages.updateUI();
+ }
+
+ /**
+ * This method disposes this JFrame window including all the JFrame windows which
+ * belong to this session.
+ */
+ public void dispose() {
+ Enumeration enumFrames = vecFrames.elements();
+
+ while (enumFrames.hasMoreElements())
+ ((JFrame) enumFrames.nextElement()).dispose();
+
+ super.dispose();
+ }
+
+ /**
+ * This method tells the main netcalendar client JFrame which sub JFrames are opened.
+ * So that all the sub JFrames will be disposed as well if the main JFrame gets disposed.
+ * A sub JFrame is for example a input form for advanced searching or the preferences dialog.
+ * @param jFrame Specifies the frame object to add. .
+ */
+ public void addFrame(JFrame jFrame) {
+ vecFrames.add(jFrame);
+ }
+
+ /**
+ * This method tells the main netcalendar client JFrame which sub JFrames are opened.
+ * So that all the sub JFrames will be disposed as well if the main JFrame gets disposed.
+ * A sub JFrame is for example a input form for advanced searching or the preferences dialog.
+ * @param jFrame Specifies the frame object to remove.
+ */
+ public void removeFrame(JFrame jFrame) {
+ vecFrames.remove(jFrame);
+ }
+}