001: /*
002: * Copyright (c) 2000, Jacob Smullyan.
003: *
004: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
005: * for the latest version.
006: *
007: * SkunkDAV is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License as published
009: * by the Free Software Foundation; either version 2, or (at your option)
010: * any later version.
011: *
012: * SkunkDAV is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with SkunkDAV; see the file COPYING. If not, write to the Free
019: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021: */
022:
023: package org.skunk.dav.client.gui;
024:
025: import java.awt.event.ActionEvent;
026: import java.awt.event.ActionListener;
027: import java.util.ArrayList;
028: import java.util.Collections;
029: import java.util.Iterator;
030: import java.util.List;
031: import javax.swing.Box;
032: import javax.swing.BoxLayout;
033: import javax.swing.JLabel;
034: import javax.swing.JPanel;
035: import javax.swing.JTextField;
036: import org.skunk.swing.text.EntryDocument;
037: import org.skunk.swing.text.EntryFilter;
038:
039: public class StatusInputPanel extends JPanel {
040: private JLabel labelComponent;
041: private JTextField textFieldComponent;
042: private String labelString;
043: private int textFieldLength;
044: private ArrayList listeners;
045:
046: public StatusInputPanel(String labelString, int textFieldLength) {
047: super ();
048: this .labelString = labelString;
049: this .textFieldLength = textFieldLength;
050: this .listeners = new ArrayList();
051: initComponents();
052: }
053:
054: public StatusInputPanel(String labelString, int textFieldLength,
055: EntryFilter entryFilter) {
056: this (labelString, textFieldLength);
057: setEntryFilter(entryFilter);
058: }
059:
060: private void initComponents() {
061: labelComponent = new JLabel(labelString);
062: textFieldComponent = new JTextField(textFieldLength);
063: textFieldComponent.setMaximumSize(textFieldComponent
064: .getPreferredSize());
065: textFieldComponent.addActionListener(new ActionListener() {
066: public void actionPerformed(ActionEvent ae) {
067: fireActionEvent();
068: }
069: });
070: setLayout(new BoxLayout(this , BoxLayout.X_AXIS));
071: this .add(labelComponent);
072: this .add(Box.createHorizontalStrut(2));
073: this .add(textFieldComponent);
074: this .add(Box.createHorizontalGlue());
075: }
076:
077: public void focus() {
078: textFieldComponent.requestFocus();
079: }
080:
081: public void setEntryFilter(EntryFilter entryFilter) {
082: textFieldComponent.setDocument(new EntryDocument(entryFilter));
083: }
084:
085: public String getInputText() {
086: return textFieldComponent.getText();
087: }
088:
089: public void setInputText(String inputText) {
090: textFieldComponent.setText(inputText);
091: }
092:
093: public void addActionListener(ActionListener listener) {
094: listeners.add(listener);
095: }
096:
097: public void removeActionListener(ActionListener listener) {
098: listeners.remove(listener);
099: }
100:
101: private void fireActionEvent() {
102: ActionEvent ae = new ActionEvent(this ,
103: ActionEvent.ACTION_PERFORMED, null);
104: //this is to prevent concurrent modifications, should an action listener call removeActionListener
105: Object[] listenersArray = listeners.toArray();
106: for (int i = 0; i < listenersArray.length; i++) {
107: ((ActionListener) listenersArray[i]).actionPerformed(ae);
108: }
109: }
110: }
|