Revision: 13679
          http://gate.svn.sourceforge.net/gate/?rev=13679&view=rev
Author:   valyt
Date:     2011-04-15 13:18:56 +0000 (Fri, 15 Apr 2011)

Log Message:
-----------
- removed some spurious code;
- added a few more comments.

Modified Paths:
--------------
    gate/trunk/src/gate/gui/annedit/JNullableTextField.java

Modified: gate/trunk/src/gate/gui/annedit/JNullableTextField.java
===================================================================
--- gate/trunk/src/gate/gui/annedit/JNullableTextField.java     2011-04-15 
13:05:29 UTC (rev 13678)
+++ gate/trunk/src/gate/gui/annedit/JNullableTextField.java     2011-04-15 
13:18:56 UTC (rev 13679)
@@ -15,9 +15,7 @@
 
 import gate.gui.MainFrame;
 
-import java.awt.BorderLayout;
 import java.awt.Color;
-import java.awt.Insets;
 import java.awt.event.ActionEvent;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
@@ -29,11 +27,8 @@
 import javax.swing.Box;
 import javax.swing.BoxLayout;
 import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JTextField;
-import javax.swing.border.Border;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 
@@ -56,18 +51,33 @@
     public void actionPerformed(ActionEvent e) {
       textField.setText(null);
       text = null;
-      fireInsertUpdate(null);
+      fireRemoveUpdate(null);
     }
   }
   
+  /**
+   * The button used to clear (nullify) the textual value.
+   */
   protected JButton nullifyButton;
   
+  /**
+   * The text field used for editing the textual value.
+   */
   protected JTextField textField;
   
+  /**
+   * The normal background colour for the text field.
+   */
   protected Color normalBgColor;
   
+  /**
+   * The colour used for the text field's background when the value is null.
+   */
   protected Color nullBgColor = new Color(200, 250, 255);
-  
+
+  /**
+   * My document listeners.
+   */
   protected Set<DocumentListener> documentListeners;
   
   /**
@@ -75,21 +85,41 @@
    */
   protected String text = null;
   
+  /**
+   * Creates a new {@link JNullableTextField} widget.
+   */
   public JNullableTextField() {
     initGui();
     initListeners();
   }
 
+  /**
+   * Sets the value edited by this component. Will cause an insertUpdate
+   * notification to all {@link DocumentListener}s associated with this
+   * component (see {@link #addDocumentListener(DocumentListener)}.
+   * @param text
+   */
   public void setText(String text) {
     textField.setText(text);
     this.text = text;
     fireInsertUpdate(null);
   }
   
+  /**
+   * Gets the value currently being edited. Unlike {@link JTextField}, this 
+   * value may be null (if {@link #setText(String)} was called previously with 
+   * a <code>null</code> value, of the delete button was pressed by the user). 
+   * @return
+   */
   public String getText() {
     return text;
   }
 
+  /**
+   * Sets the number of columns for the included {@link JTextField}, see 
+   * {@link JTextField#setColumns(int)}. 
+   * @param cols
+   */
   public void setColumns(int cols) {
     textField.setColumns(cols);
   }
@@ -101,18 +131,9 @@
     add(textField);
     add(Box.createHorizontalStrut(2));
     nullifyButton = new JButton(new NullifyTextAction());
-//    nullifyButton.setBorderPainted(true);
-//    nullifyButton.setContentAreaFilled(false);
-//    nullifyButton.setOpaque(false);
-//    nullifyButton.setMargin(new Insets(2, 2, 2, 2));
     add(nullifyButton);
 
     normalBgColor = textField.getBackground();
-    // borrow the LnF from the text field
-//    setBackground(textField.getBackground());
-//    Border border = textField.getBorder();
-//    textField.setBorder(null);
-//    setBorder(border);
   }
   
   protected void initListeners() {
@@ -143,7 +164,7 @@
       }
     });
     
-    // listen to our own events, and display null value
+    // listen to our own events, and highlight null value
     addDocumentListener(new DocumentListener() {
       public void removeUpdate(DocumentEvent e) {
         valueChanged();
@@ -165,14 +186,27 @@
     
   }
 
+  /**
+   * Registers a new {@link DocumentListener} with this component. The provided
+   * listener will be forwarded all the events generated by the encapsulated 
+   * {@link JTextField}. An event will also be generated when the user presses 
+   * the delete button, causing the text value to be nullified.  
+   * @param listener
+   */
   public void addDocumentListener(DocumentListener listener) {
     documentListeners.add(listener);
   }
 
+  /**
+   * Removes a previously registered listener (see 
+   * {@link #addDocumentListener(DocumentListener)}).
+   * @param listener
+   */
   public void removeDocumentListener(DocumentListener listener) {
     documentListeners.remove(listener);
   }
   
+  
   protected void fireChangedUpdate(DocumentEvent e) {
     for(DocumentListener aListener : documentListeners) 
       aListener.changedUpdate(e);
@@ -187,35 +221,4 @@
     for(DocumentListener aListener : documentListeners) 
       aListener.removeUpdate(e);
   }
-  
-  public static void main(String[] args) {
-    
-    JFrame frame = new JFrame(JNullableTextField.class.getName());
-    
-    JPanel mainPanel = new JPanel(new BorderLayout());
-    
-    final JNullableTextField textField = new JNullableTextField();
-    textField.setText("Test text");
-    mainPanel.add(textField, BorderLayout.CENTER);
-
-    final JLabel textLabel = new JLabel();
-    JButton getTextButton = new JButton(new AbstractAction("Copy text") {
-      public void actionPerformed(ActionEvent e) {
-        String text = textField.getText();
-        textLabel.setText(text == null ? "<null>" : text);
-      }
-    });
-    
-    Box box = new Box(BoxLayout.X_AXIS);
-    box.add(getTextButton);
-    box.add(textLabel);
-    mainPanel.add(box, BorderLayout.SOUTH);
-    
-    frame.add(mainPanel);
-    frame.setSize(400, 400);
-    frame.pack();
-    frame.setVisible(true);
-    
-    
-  }
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload 
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve 
application availability and disaster protection. Learn more about boosting 
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to