📄 formpanel.java
字号:
/* CRMS, customer relationship management system Copyright (C) 2003 Service To Youth Council 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. 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. 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 For further information contact the SYC ICT department on GPL@syc.net.au 98 Kermode Street North Adelaide South Australia SA 5006 +61 (0)8 8367 0755 *//* * FormPanel.java * * Created on 11 April 2003, 08:17 */package crms.form;import java.awt.event.*;import java.awt.*;import java.text.*;import javax.swing.*;import java.util.*;import mseries.Calendar.*;import mseries.ui.*;/** * * @author dmurphy */public class FormPanel extends JPanel { private Form form = null; private HashMap widgets = new HashMap(); private FormSubmission result = new FormSubmission(); private ArrayList formSubmitListeners = new ArrayList(); private ArrayList formCancelListeners = new ArrayList(); private ArrayList formResetListeners = new ArrayList(); /** Creates a new instance of FormPanel */ public FormPanel() { } public void setForm(Form form) { this.form = form; } public Form getForm() { return form; } public void submitButtonClicked(ActionEvent ev) { processFormSubmit(); for (int i=0; i < formSubmitListeners.size(); i++) { FormSubmitListener l = (FormSubmitListener) formSubmitListeners.get(i); l.formSubmitted(getResult()); } } public void resetButtonClicked(ActionEvent ev) { for (int i=0; i < formResetListeners.size(); i++) { ActionListener listener = (ActionListener) formResetListeners.get(i); listener.actionPerformed(ev); } } public void cancelButtonClicked(ActionEvent ev) { for (int i=0; i < formCancelListeners.size(); i++) { ActionListener listener = (ActionListener) formCancelListeners.get(i); listener.actionPerformed(ev); } } public void addWidget(String fieldName, Component comp) { widgets.put(fieldName, comp); } public void addFormSubmitListener(FormSubmitListener listener) { formSubmitListeners.add(listener); } public void addFormResetListener(ActionListener listener) { formResetListeners.add(listener); } public void addFormCancelListener(ActionListener listener) { formCancelListeners.add(listener); } public void processFormSubmit() { result.setFormName(form.getName()); for (int i=0; i < form.getFieldCount(); i++) { FormField field = form.getField(i); Component widget = (Component) widgets.get(field.getName()); String value = null; if (widget instanceof JTextField) { JTextField textField = (JTextField) widget; result.setFieldValue(field.getName(), textField.getText()); } else if (widget instanceof JTextArea) { JTextArea textField = (JTextArea) widget; result.setFieldValue(field.getName(), textField.getText()); } else if (widget instanceof JComboBox) { JComboBox comboBox = (JComboBox) widget; FieldOption option = (FieldOption) comboBox.getSelectedItem(); result.setFieldValue(field.getName(), option.getCode()); } else if (widget instanceof JCheckBox) { // Value of checkbox should be changed as it is clicked // through the use of the checkbox's item listener which // was added when it was initialised. } else if (widget instanceof MDateEntryField) { MDateEntryField dateField = (MDateEntryField) widget; try { Date date = dateField.getValue(); result.setFieldValue(field.getName(), FormSubmission.df.format(date)); } catch (ParseException ex) { throw new RuntimeException(ex); } } else if (widget instanceof MDateSpinner) { MDateSpinner timeField = (MDateSpinner) widget; try { Date date = timeField.getValue(); result.setFieldValue(field.getName(), FormSubmission.tf.format(date)); } catch (ParseException ex) { throw new RuntimeException(ex); } } } } public FormSubmission getResult() { return result; } public interface FormSubmitListener { public void formSubmitted(FormSubmission result); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -