summaryrefslogtreecommitdiff
path: root/sources/client/inputforms
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2009-02-18 17:33:22 +0000
committerPaul Buetow <paul@buetow.org>2009-02-18 17:33:22 +0000
commit4722100cba287b164957c658c2e035783e20c963 (patch)
tree35733fd3e50aeeb493e38ceaea83521a4710f0ac /sources/client/inputforms
parent61f7175cc3e51c0afaf63e380d03824a77464ba8 (diff)
moved sources
Diffstat (limited to 'sources/client/inputforms')
-rw-r--r--sources/client/inputforms/AdvancedSearching.java141
-rw-r--r--sources/client/inputforms/CreateNewEvent.java122
-rw-r--r--sources/client/inputforms/EditExistingEvent.java156
-rw-r--r--sources/client/inputforms/InputForm.java93
-rw-r--r--sources/client/inputforms/Preferences.java99
-rw-r--r--sources/client/inputforms/RenameCategory.java123
6 files changed, 734 insertions, 0 deletions
diff --git a/sources/client/inputforms/AdvancedSearching.java b/sources/client/inputforms/AdvancedSearching.java
new file mode 100644
index 0000000..1b39320
--- /dev/null
+++ b/sources/client/inputforms/AdvancedSearching.java
@@ -0,0 +1,141 @@
+/*
+ * A 1.4 application that uses SpringLayout to create a forms-type layout.
+ * Other files required: SpringUtilities.java.
+ */
+
+package client.inputforms;
+
+import java.awt.event.*;
+import java.util.*;
+import javax.swing.*;
+
+import client.NetCalendarClient;
+import client.helper.DateSpinner;
+import client.helper.GUIHelper;
+
+
+import shared.remotecall.*;
+
+/**
+ * This class contains all the GUI components of the advanced searching dialog.
+ * Its used for using the andvanced searching options of the client such as using
+ * Java regular expressions on specific elements of the calendar database instead and
+ * date ranges.
+ * @author buetow
+ *
+ */
+public class AdvancedSearching extends InputForm {
+ private final static long serialVersionUID = 1L;
+
+ // Static elements which are the same on all AdvancedSearching objects!
+ private final static String BUTTON_GET_ALL = "Get all";
+ private final static String[] labels = {"Date string: ", "Description: ", "Category: ", "Place: ",
+ "Use date ranging: ", "Date range from: ", "Date range to: "
+ };
+ private final static int iNumPairs = labels.length;
+ private final static int iTextFields = labels.length - 3;
+ private final static int iCheckBoxes = labels.length - 2;
+
+ /**
+ * Create the input form window and show it.
+ * @param netCalendarClient Specifies the current calendar client session window.
+ */
+ public AdvancedSearching(NetCalendarClient netCalendarClient) {
+ super("Advanced searching", netCalendarClient);
+ initComponents();
+ pack();
+ setVisible(true);
+ }
+
+ /**
+ * Initializes all the GUI components.
+ */
+ protected void initComponents() {
+ super.initComponents();
+ //Create and populate the panel.
+ JPanel jPanel = new JPanel(new SpringLayout());
+
+ ActionListener actionListenerFields = new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ submit();
+ }
+ };
+
+ vecFields = new Vector();
+ for (int i = 0; i < iNumPairs; ++i) {
+ JLabel jLable = new JLabel(labels[i], JLabel.TRAILING);
+ jPanel.add(jLable);
+ JComponent jComponent = null;
+
+ if (i < iTextFields) {
+ JTextField jTextField = new JTextField(InputForm.TEXTFIELD_LENGTH);
+ jTextField.addActionListener(actionListenerFields);
+ jComponent = jTextField;
+
+ } else if (i < iCheckBoxes) {
+ jComponent = new JCheckBox();
+
+ } else {
+ jComponent = new DateSpinner();
+ }
+
+ jLable.setLabelFor(jComponent);
+ jPanel.add(jComponent);
+
+ vecFields.add(jComponent);
+ }
+
+ //Lay out the panel.
+ GUIHelper.makeCompactGrid(jPanel,
+ iNumPairs, 2, // iRows, iCols
+ 6, 6, // iInitX, iInitY
+ 6, 6); // iXPad, iYPad
+
+ JButton jButtonGetAll = new JButton(BUTTON_GET_ALL);
+
+ ActionListener actionListenerButtons = new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ if (event.getActionCommand().equals(BUTTON_CLEAR))
+ for (int i = 0; i < iTextFields; ++i)
+ ((JTextField) vecFields.get(i)).setText("");
+
+ else if (event.getActionCommand().equals(BUTTON_GET_ALL))
+ netCalendarClient.update(new ClientRequest(ClientRequest.REQUEST_ALL_EVENTS));
+
+ }
+ };
+
+ jButtonClear.addActionListener(actionListenerButtons);
+ jButtonGetAll.addActionListener(actionListenerButtons);
+ jPanelButtons.add(jButtonGetAll);
+
+ JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+ jSplitPane.setTopComponent(jPanel);
+ jSplitPane.setBottomComponent(jPanelButtons);
+ jSplitPane.setDividerSize(0);
+
+ setContentPane(jSplitPane);
+ }
+
+ /**
+ * This method is invoked if the enter key is pressed or if the submit button
+ * has been pressed. It starts a client request relating to the user's input of
+ * the text fields.
+ */
+ protected void submit() {
+ ClientRequest clientRequest = new ClientRequest();
+ clientRequest.setRegexpDate(((JTextField) vecFields.get(0)).getText());
+ clientRequest.setRegexpDescription(((JTextField) vecFields.get(1)).getText());
+ clientRequest.setRegexpCategory(((JTextField) vecFields.get(2)).getText());
+ clientRequest.setRegexpPlace(((JTextField) vecFields.get(3)).getText());
+
+ JCheckBox jCheckBox = (JCheckBox) vecFields.get(4);
+ if (jCheckBox.isSelected()) {
+ Date dateRangeFrom = ((DateSpinner) vecFields.get(5)).getDate();
+ Date dateRangeTo = ((DateSpinner) vecFields.get(6)).getDate();
+ clientRequest.setDateRange(dateRangeFrom, dateRangeTo);
+ }
+
+ netCalendarClient.update(clientRequest);
+ }
+}
diff --git a/sources/client/inputforms/CreateNewEvent.java b/sources/client/inputforms/CreateNewEvent.java
new file mode 100644
index 0000000..430f982
--- /dev/null
+++ b/sources/client/inputforms/CreateNewEvent.java
@@ -0,0 +1,122 @@
+package client.inputforms;
+
+import java.awt.event.*;
+import java.util.*;
+
+import javax.swing.*;
+
+import client.NetCalendarClient;
+import client.ServerRequester;
+import client.helper.DateSpinner;
+import client.helper.GUIHelper;
+
+
+import shared.*;
+import shared.remotecall.*;
+
+/**
+ * This class contains all the GUI components of the create new event dialog.
+ * Its used for adding new calendar events to the database.
+ * @author buetow
+ *
+ */
+public class CreateNewEvent extends InputForm {
+ private final static long serialVersionUID = 1L;
+
+ // Static elements which are the same on all AdvancedSearching objects!
+ private final static String[] labels =
+ { "Description: ", "Category: ", "Place: ", "Yearly: ", "Date: "};
+ private final static int iNumPairs = labels.length;
+ private final static int iTextFields = iNumPairs - 2;
+ private final static int iCheckBoxes = iNumPairs - 1;
+
+ /**
+ * Create the input form window and show it.
+ * @param netCalendarClient Specifies the current calendar client session window. *
+ */
+ public CreateNewEvent(NetCalendarClient netCalendarClient) {
+ super("Create new event", netCalendarClient);
+ initComponents();
+ pack();
+ setVisible(true);
+ }
+
+ /**
+ * Initializes all the GUI components.
+ */
+ protected void initComponents() {
+ super.initComponents();
+ JPanel jPanel = new JPanel(new SpringLayout());
+
+ ActionListener actionListenerTextFields = new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ submit();
+ }
+ };
+
+ vecFields = new Vector();
+ for (int i = 0; i < iNumPairs; ++i) {
+ JLabel jLable = new JLabel(labels[i], JLabel.TRAILING);
+ jPanel.add(jLable);
+ JComponent jComponent = null;
+ if ( i < iTextFields) {
+ JTextField textField = new JTextField(InputForm.TEXTFIELD_LENGTH);
+ textField.addActionListener(actionListenerTextFields);
+ jComponent = textField;
+
+ } else if (i < iCheckBoxes) {
+ jComponent = new JCheckBox();
+
+ } else {
+ jComponent = new DateSpinner();
+ }
+
+ jLable.setLabelFor(jComponent);
+ jPanel.add(jComponent);
+ vecFields.add(jComponent);
+ }
+
+ //Lay out the panel.
+ GUIHelper.makeCompactGrid(jPanel,
+ iNumPairs, 2, // iRows, iCols
+ 6, 6, // iInitX, iInitY
+ 6, 6); // iXPad, iYPad
+
+ ActionListener actionListenerButtons = new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ if (event.getActionCommand().equals(BUTTON_CLEAR))
+ for (int i = 0; i < iNumPairs -2; ++i)
+ ((JTextField) vecFields.get(i)).setText("");
+ }
+ };
+
+ jButtonClear.addActionListener(actionListenerButtons);
+
+ JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+ jSplitPane.setTopComponent(jPanel);
+ jSplitPane.setBottomComponent(jPanelButtons);
+ jSplitPane.setDividerSize(0);
+
+ setContentPane(jSplitPane);
+ }
+
+ /**
+ * This method is invoked if the enter key is pressed or if the submit button
+ * has been pressed. It starts a client request relating to the user's input of
+ * the text fields.
+ */
+ protected void submit() {
+ String sCategoryName = ((JTextField) vecFields.get(1)).getText();
+ CalendarEvent calendarEvent = new CalendarEvent(sCategoryName);
+ calendarEvent.setDescription(((JTextField) vecFields.get(0)).getText());
+ calendarEvent.setPlace(((JTextField) vecFields.get(2)).getText());
+ calendarEvent.setYearly(((JCheckBox) vecFields.get(3)).isSelected());
+ calendarEvent.setDate(((DateSpinner) vecFields.get(4)).getDate());
+
+ ClientRequest clientRequest = new ClientRequest(ClientRequest.ADD_EVENT);
+ clientRequest.setEvent(calendarEvent);
+
+ ServerRequester.sendClientRequest(clientRequest);
+ netCalendarClient.updateLast();
+ }
+}
diff --git a/sources/client/inputforms/EditExistingEvent.java b/sources/client/inputforms/EditExistingEvent.java
new file mode 100644
index 0000000..6c65aeb
--- /dev/null
+++ b/sources/client/inputforms/EditExistingEvent.java
@@ -0,0 +1,156 @@
+package client.inputforms;
+
+import java.awt.event.*;
+import java.util.*;
+
+import javax.swing.*;
+
+import client.NetCalendarClient;
+import client.ServerRequester;
+import client.helper.DateSpinner;
+import client.helper.GUIHelper;
+
+
+import shared.*;
+import shared.remotecall.*;
+
+/**
+ * This class contains all the GUI components of the edit event dialog.
+ * Its used for editing existing events of the calendar database.
+ * @author buetow
+ *
+ */
+public class EditExistingEvent extends InputForm {
+ private final static long serialVersionUID = 1L;
+
+ // Static elements which are the same on all AdvancedSearching objects!
+ private final static String BUTTON_DELETE = "Delete";
+ private final static String[] labels =
+ { "Event ID: ", "Description: ", "Category: ", "Place: ", "Yearly: ", "Date: "};
+ private final static int iNumPairs = labels.length;
+ private final static int iTextFields = iNumPairs - 2;
+ private final static int iCheckBoxes = iNumPairs - 1;
+
+ private CalendarEvent originalCalendarEvent;
+ private Date date;
+
+ /**
+ * Create the input form window and show it.
+ * @param netCalendarClient Specifies the current calendar client session window.
+ * @param originalCalendarEvent Specifies the calendar event to modify.
+ */
+ public EditExistingEvent(NetCalendarClient netCalendarClient, CalendarEvent originalCalendarEvent) {
+ super("Edit event", netCalendarClient);
+ this.originalCalendarEvent = originalCalendarEvent;
+ this.date = originalCalendarEvent.getDate();
+ initComponents();
+ setFieldValues();
+ pack();
+ setVisible(true);
+ }
+
+ /**
+ * Initializes all the GUI components.
+ */
+ protected void initComponents() {
+ super.initComponents();
+
+ JPanel jPanel = new JPanel(new SpringLayout());
+
+ ActionListener actionListenerTextFields = new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ submit();
+ }
+ };
+
+ vecFields = new Vector();
+ for (int i = 0; i < iNumPairs; ++i) {
+ JLabel jLable = new JLabel(labels[i], JLabel.TRAILING);
+ jPanel.add(jLable);
+ JComponent jComponent = null;
+ if ( i < iTextFields) {
+ JTextField textField = new JTextField(InputForm.TEXTFIELD_LENGTH);
+ textField.addActionListener(actionListenerTextFields);
+ jComponent = textField;
+
+ } else if (i < iCheckBoxes) {
+ jComponent = new JCheckBox();
+
+ } else {
+ jComponent = new DateSpinner(date);
+ }
+
+ jLable.setLabelFor(jComponent);
+ jPanel.add(jComponent);
+ vecFields.add(jComponent);
+ }
+
+ //Lay out the panel.
+ GUIHelper.makeCompactGrid(jPanel,
+ iNumPairs, 2, // iRows, iCols
+ 6, 6, // iInitX, iInitY
+ 6, 6); // iXPad, iYPad
+
+ JButton jButtonDelete = new JButton(BUTTON_DELETE);
+
+ ActionListener actionListenerButtons = new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ if (event.getActionCommand().equals(BUTTON_CLEAR)) {
+ for (int i = 1; i < iNumPairs -2; ++i)
+ ((JTextField) vecFields.get(i)).setText("");
+
+ } else if (event.getActionCommand().equals(BUTTON_DELETE)) {
+ netCalendarClient.deleteEvent(originalCalendarEvent);
+ dispose();
+ }
+ }
+ };
+
+ jButtonDelete.addActionListener(actionListenerButtons);
+ jButtonClear.addActionListener(actionListenerButtons);
+ jPanelButtons.add(jButtonDelete);
+
+ JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+ jSplitPane.setTopComponent(jPanel);
+ jSplitPane.setBottomComponent(jPanelButtons);
+ jSplitPane.setDividerSize(0);
+
+ setContentPane(jSplitPane);
+ }
+
+ /**
+ * This method sets the fields of the edit frame according to the originalCalendarEvent object.
+ * The date is not set by this method. Its done by the initComponents method.
+ */
+ private void setFieldValues() {
+ JTextField jTextFieldEventID = (JTextField) vecFields.get(0);
+ jTextFieldEventID.setText(""+originalCalendarEvent.getEventID());
+ jTextFieldEventID.setEditable(false);
+
+ ((JTextField) vecFields.get(1)).setText(originalCalendarEvent.getDescription());
+ ((JTextField) vecFields.get(2)).setText(originalCalendarEvent.getCategoryName());
+ ((JTextField) vecFields.get(3)).setText(originalCalendarEvent.getPlace());
+ ((JCheckBox) vecFields.get(4)).setSelected(originalCalendarEvent.isYearly());
+ }
+
+ /**
+ * This method is invoked if the enter key is pressed or if the submit button
+ * has been pressed. It starts a client request relating to the user's input of
+ * the text fields.
+ */
+ protected void submit() {
+ String sCategoryName = ((JTextField) vecFields.get(2)).getText();
+ CalendarEvent calendarEvent = new CalendarEvent(sCategoryName);
+ calendarEvent.setDescription(((JTextField) vecFields.get(1)).getText());
+ calendarEvent.setPlace(((JTextField) vecFields.get(3)).getText());
+ calendarEvent.setYearly(((JCheckBox) vecFields.get(4)).isSelected());
+ calendarEvent.setDate(((DateSpinner) vecFields.get(5)).getDate());
+ calendarEvent.setEventID(originalCalendarEvent.getEventID());
+
+ ClientRequest clientRequest = new ClientRequest(ClientRequest.MODIFY_EVENT);
+ clientRequest.setEvent(calendarEvent);
+
+ ServerRequester.sendClientRequest(clientRequest);
+ netCalendarClient.updateLast();
+ }
+}
diff --git a/sources/client/inputforms/InputForm.java b/sources/client/inputforms/InputForm.java
new file mode 100644
index 0000000..41004fa
--- /dev/null
+++ b/sources/client/inputforms/InputForm.java
@@ -0,0 +1,93 @@
+package client.inputforms;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.*;
+import javax.swing.*;
+
+import client.*;
+
+/**
+ * This abstract class is the base class of all other classes of the same package.
+ * It contains some common members using by all other (specialized) input form classes.
+ * @author buetow
+ *
+ */
+public abstract class InputForm extends SubWindow {
+ protected final static long serialVersionUID = 1L;
+ protected Vector vecFields;
+ protected JPanel jPanelButtons;
+ protected JButton jButtonClear;
+ protected JButton jButtonApply;
+ protected JButton jButtonCancel;
+ protected JButton jButtonOK;
+ private boolean bApplyHasBeenPressed = false;
+
+ protected final static String BUTTON_CANCEL = "Cancel";
+ protected final static String BUTTON_CLEAR = "Clear";
+ protected final static String BUTTON_APPLY = "Apply";
+ protected final static String BUTTON_OK = "OK";
+
+ protected final static int TEXTFIELD_LENGTH = 20;
+
+ /**
+ * Creates the input form window and show it.
+ * @param sTitleText Specifies the title text of this JFrame.
+ * @param netCalendarClient Specifies the calendar client session object to use.
+ */
+ public InputForm(String sTitleText, NetCalendarClient netCalendarClient) {
+ super(sTitleText, netCalendarClient);
+ }
+
+ /**
+ * Initializes the input form
+ * @param sTitleText Specifies the title text of this JFrame.
+ * @param netCalendarClient Specifies the calendar client session object to use.
+ */
+ public void init(String sTitleText, NetCalendarClient netCalendarClient) {
+ super.init(sTitleText, netCalendarClient);
+ }
+
+ /**
+ * Initializes all the GUI components of the implementating class.
+ */
+ protected void initComponents() {
+ jButtonClear = new JButton(BUTTON_CLEAR);
+ jButtonApply = new JButton(BUTTON_APPLY);
+ jButtonCancel = new JButton(BUTTON_CANCEL);
+ jButtonOK = new JButton(BUTTON_OK);
+
+ ActionListener actionListenerButtons = new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ if (event.getActionCommand().equals(BUTTON_CANCEL)) {
+ dispose();
+
+ } else if (event.getActionCommand().equals(BUTTON_APPLY)) {
+ bApplyHasBeenPressed = true;
+ submit();
+
+ } else if (event.getActionCommand().equals(BUTTON_OK)) {
+ if (!bApplyHasBeenPressed)
+ submit();
+ dispose();
+ }
+ }
+ };
+
+ jButtonCancel.addActionListener(actionListenerButtons);
+ jButtonClear.addActionListener(actionListenerButtons);
+ jButtonApply.addActionListener(actionListenerButtons);
+ jButtonOK.addActionListener(actionListenerButtons);
+
+ jPanelButtons = new JPanel();
+ jPanelButtons.add(jButtonOK);
+ jPanelButtons.add(jButtonCancel);
+ jPanelButtons.add(jButtonApply);
+ jPanelButtons.add(jButtonClear);
+ }
+
+ /**
+ * Submits the input form of the implementating class.
+ */
+ protected abstract void submit();
+}
diff --git a/sources/client/inputforms/Preferences.java b/sources/client/inputforms/Preferences.java
new file mode 100644
index 0000000..cefc192
--- /dev/null
+++ b/sources/client/inputforms/Preferences.java
@@ -0,0 +1,99 @@
+package client.inputforms;
+
+import java.awt.event.*;
+import java.util.*;
+
+import javax.swing.*;
+
+import client.NetCalendarClient;
+import client.helper.GUIHelper;
+
+
+import shared.*;
+/**
+ * This class contains all the GUI components of the preferences/options/config dialog.
+ * Its used for editing the current config values of the config.txt file.
+ * @author buetow
+ *
+ */
+public class Preferences extends InputForm {
+ private final static long serialVersionUID = 1L;
+
+ private String[] labels = null;
+ private int iNumPairs = -1;
+
+ /**
+ * Create the input form window and show it.
+ * @param netCalendarClient Specifies the current calendar client session window.
+ */
+ public Preferences(NetCalendarClient netCalendarClient) {
+ super("Preferences", netCalendarClient);
+ initComponents();
+ setFieldValues();
+ pack();
+ setVisible(true);
+ }
+
+ /**
+ * Initializes all the GUI components.
+ */
+ protected void initComponents() {
+ super.initComponents();
+ setFieldValues();
+ JPanel jPanel = new JPanel(new SpringLayout());
+
+ labels = Config.getSortedKeyArray();
+ iNumPairs = labels.length;
+
+ ActionListener actionListenerTextFields = new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ submit();
+ }
+ };
+
+ vecFields = new Vector();
+ for (int i = 0; i < iNumPairs; ++i) {
+ JLabel jLable = new JLabel(labels[i], JLabel.TRAILING);
+ jPanel.add(jLable);
+ JTextField textField = new JTextField(InputForm.TEXTFIELD_LENGTH);
+ textField.addActionListener(actionListenerTextFields);
+ jLable.setLabelFor(textField);
+ jPanel.add(textField);
+ vecFields.add(textField);
+ }
+
+ //Lay out the panel.
+ GUIHelper.makeCompactGrid(jPanel,
+ iNumPairs, 2, // iRows, iCols
+ 6, 6, // iInitX, iInitY
+ 6, 6); // iXPad, iYPad
+
+ jPanelButtons.remove(jButtonClear);
+ JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+ jSplitPane.setTopComponent(jPanel);
+ jSplitPane.setBottomComponent(jPanelButtons);
+ jSplitPane.setDividerSize(0);
+
+ setContentPane(jSplitPane);
+ }
+
+ /**
+ * This method sets the fields of the edit frame according to the current configuration options.
+ */
+ private void setFieldValues() {
+ for (int i = 0; i < iNumPairs; ++i)
+ ((JTextField) vecFields.get(i)).setText(Config.getStringValue(labels[i]));
+ }
+
+ /**
+ * This method is invoked if the enter key is pressed or if the submit button
+ * has been pressed. It starts a client request relating to the user's input of
+ * the text fields. It will write all changes to the config.txt file.
+ */
+ protected void submit() {
+ for (int i = 0; i < iNumPairs; ++i)
+ Config.setValue(labels[i], ((JTextField) vecFields.get(i)).getText());
+
+ Config.writeConfigToFile();
+ }
+}
diff --git a/sources/client/inputforms/RenameCategory.java b/sources/client/inputforms/RenameCategory.java
new file mode 100644
index 0000000..90c6750
--- /dev/null
+++ b/sources/client/inputforms/RenameCategory.java
@@ -0,0 +1,123 @@
+package client.inputforms;
+
+import java.awt.event.*;
+import java.util.*;
+
+import javax.swing.*;
+
+import client.NetCalendarClient;
+import client.ServerRequester;
+import client.helper.DateSpinner;
+import client.helper.GUIHelper;
+
+
+import shared.*;
+import shared.remotecall.*;
+
+/**
+ * This class contains all the GUI components of the edit event dialog.
+ * Its used for editing existing events of the calendar database.
+ * @author buetow
+ *
+ */
+public class RenameCategory extends InputForm {
+ private final static long serialVersionUID = 1L;
+
+ // Static elements which are the same on all AdvancedSearching objects!
+ private final static String[] labels = { "Category name: " };
+ private final static int iNumPairs = labels.length;
+
+ private CalendarEvent calendarEvent;
+
+ /**
+ * Create the input form window and show it.
+ * @param netCalendarClient Specifies the current calendar client session window.
+ * @param originalCalendarEvent Specifies the calendar event to modify.
+ */
+ public RenameCategory(NetCalendarClient netCalendarClient, CalendarEvent calendarEvent) {
+ super("Rename whole category", netCalendarClient);
+ this.calendarEvent = calendarEvent;
+ initComponents();
+ setFieldValues();
+ pack();
+ setVisible(true);
+ }
+
+ /**
+ * Initializes all the GUI components.
+ */
+ protected void initComponents() {
+ super.initComponents();
+
+ JPanel jPanel = new JPanel(new SpringLayout());
+
+ ActionListener actionListenerTextFields = new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ submit();
+ }
+ };
+
+ vecFields = new Vector();
+
+ for (int i = 0; i < iNumPairs; ++i) {
+ JLabel jLable = new JLabel(labels[i], JLabel.TRAILING);
+ jPanel.add(jLable);
+ JComponent jComponent = null;
+ JTextField textField = new JTextField(InputForm.TEXTFIELD_LENGTH);
+ textField.addActionListener(actionListenerTextFields);
+ jComponent = textField;
+ jLable.setLabelFor(jComponent);
+ jPanel.add(jComponent);
+ vecFields.add(jComponent);
+ }
+
+ //Lay out the panel.
+ GUIHelper.makeCompactGrid(jPanel,
+ iNumPairs, 2, // iRows, iCols
+ 6, 6, // iInitX, iInitY
+ 6, 6); // iXPad, iYPad
+
+ ActionListener actionListenerButtons = new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ if (event.getActionCommand().equals(BUTTON_CLEAR)) {
+ for (int i = 1; i < iNumPairs; ++i)
+ ((JTextField) vecFields.get(i)).setText("");
+ }
+ }
+ };
+
+ jButtonClear.addActionListener(actionListenerButtons);
+ jPanelButtons.remove(jButtonClear);
+
+ JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+ jSplitPane.setTopComponent(jPanel);
+ jSplitPane.setBottomComponent(jPanelButtons);
+ jSplitPane.setDividerSize(0);
+
+ setContentPane(jSplitPane);
+ }
+
+ /**
+ * This method sets the fields of the edit frame according to the originalCalendarEvent object.
+ * The date is not set by this method. Its done by the initComponents method.
+ */
+ private void setFieldValues() {
+ ((JTextField) vecFields.get(0)).setText(calendarEvent.getCategoryName());
+ }
+
+ /**
+ * This method is invoked if the enter key is pressed or if the submit button
+ * has been pressed. It starts a client request relating to the user's input of
+ * the text fields.
+ */
+ protected void submit() {
+ String sNewCategoryName = ((JTextField) vecFields.get(0)).getText();
+
+ ClientRequest clientRequest = new ClientRequest(ClientRequest.RENAME_CATEGORY);
+ clientRequest.setEvent(calendarEvent);
+ clientRequest.setString(sNewCategoryName);
+ ServerRequester.sendClientRequest(clientRequest);
+ netCalendarClient.updateLast();
+ calendarEvent.setCategoryName(sNewCategoryName);
+ }
+}