Clover coverage report - clover
Coverage timestamp: Sat Oct 8 2005 22:54:17 EDT
file stats: LOC: 173   Methods: 22
NCLOC: 104   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
XMLEditor.java 0% 9.4% 4.5% 6.7%
coverage coverage
 1   
 package abbot.editor.editors;
 2   
 
 3   
 import java.awt.Component;
 4   
 import java.awt.event.*;
 5   
 import java.util.EventObject;
 6   
 
 7   
 import javax.swing.*;
 8   
 import javax.swing.table.TableCellEditor;
 9   
 import javax.swing.tree.TreeCellEditor;
 10   
 
 11   
 import abbot.script.XMLifiable;
 12   
 
 13   
 /**
 14   
  * An editor for an XMLifiable object. 
 15   
  * It'd be nice to provide a real XML editor here...
 16   
  */
 17   
 
 18   
 public class XMLEditor extends AbstractCellEditor 
 19   
     implements TableCellEditor, TreeCellEditor { 
 20   
 
 21   
     private JTextField textField = new JTextField();
 22   
     protected JComponent editorComponent = textField;
 23   
     protected EditorDelegate delegate;
 24   
     protected int clickCountToStart = 1;
 25   
 
 26   
     /**
 27   
      * Constructs an XMLEditor that uses a text field.
 28   
      */
 29  4
     public XMLEditor() {
 30  4
     this.clickCountToStart = 2;
 31  4
         delegate = new EditorDelegate() {
 32   
             /** Set the contents of the editor based on the original
 33   
                 object. */ 
 34  0
             public void setValue(Object value) {
 35  0
                 if (value instanceof XMLifiable) {
 36  0
                     value = ((XMLifiable)value).toEditableString();
 37   
                 }
 38  0
         textField.setText((value != null) ? value.toString() : "");
 39   
             }
 40   
 
 41  0
         public Object getCellEditorValue() {
 42  0
         return textField.getText();
 43   
         }
 44   
         };
 45  4
     textField.addActionListener(delegate);
 46   
     }
 47   
 
 48   
     /**
 49   
      * Returns the component used to edit this editor's value.
 50   
      *
 51   
      * @return the editor Component
 52   
      */
 53  0
     public Component getComponent() {
 54  0
     return editorComponent;
 55   
     }
 56   
 
 57   
     /**
 58   
      * Specifies the number of clicks needed to start editing.
 59   
      *
 60   
      * @param count  an int specifying the number of clicks needed to start
 61   
      *               editing 
 62   
      * @see #getClickCountToStart
 63   
      */
 64  0
     public void setClickCountToStart(int count) {
 65  0
     clickCountToStart = count;
 66   
     }
 67   
 
 68   
     /**
 69   
      *  ClickCountToStart controls the number of clicks required to start
 70   
      *  editing.
 71   
      */
 72  0
     public int getClickCountToStart() {
 73  0
     return clickCountToStart;
 74   
     }
 75   
 
 76  0
     public Object getCellEditorValue() {
 77  0
         return delegate.getCellEditorValue();
 78   
     }
 79   
 
 80  0
     public boolean isCellEditable(EventObject anEvent) { 
 81  0
     return delegate.isCellEditable(anEvent); 
 82   
     }
 83   
     
 84  0
     public boolean shouldSelectCell(EventObject anEvent) { 
 85  0
     return delegate.shouldSelectCell(anEvent); 
 86   
     }
 87   
 
 88  0
     public boolean stopCellEditing() {
 89  0
     return delegate.stopCellEditing();
 90   
     }
 91   
 
 92  0
     public void cancelCellEditing() {
 93  0
     delegate.cancelCellEditing();
 94   
     }
 95   
 
 96   
     //
 97   
     //  Implementing the TreeCellEditor Interface
 98   
     //
 99   
 
 100  0
     public Component getTreeCellEditorComponent(JTree tree, Object value,
 101   
                         boolean isSelected,
 102   
                         boolean expanded,
 103   
                         boolean leaf, int row) {
 104  0
     String         stringValue = tree.convertValueToText(value, isSelected,
 105   
                         expanded, leaf, row, false);
 106   
 
 107  0
     delegate.setValue(stringValue);
 108  0
     return editorComponent;
 109   
     }
 110   
 
 111   
     //
 112   
     //  Implementing the CellEditor Interface
 113   
     //
 114   
 
 115  0
     public Component getTableCellEditorComponent(JTable table, Object value,
 116   
                          boolean isSelected,
 117   
                          int row, int column) {
 118  0
         delegate.setValue(value);
 119  0
     return editorComponent;
 120   
     }
 121   
 
 122   
 
 123   
     //
 124   
     //  Protected EditorDelegate class
 125   
     //
 126   
 
 127   
     protected class EditorDelegate 
 128   
         implements ActionListener, ItemListener {
 129   
 
 130   
         protected Object value;
 131   
 
 132  0
         public Object getCellEditorValue() {
 133  0
             return value;
 134   
         }
 135   
 
 136  0
         public void setValue(Object value) { 
 137  0
         this.value = value; 
 138   
     }
 139   
 
 140  0
         public boolean isCellEditable(EventObject anEvent) {
 141  0
         if (anEvent instanceof MouseEvent) { 
 142  0
         return ((MouseEvent)anEvent).getClickCount() >= clickCountToStart;
 143   
         }
 144  0
         return true;
 145   
     }
 146   
         
 147  0
         public boolean shouldSelectCell(EventObject anEvent) { 
 148  0
             return true; 
 149   
         }
 150   
 
 151  0
         public boolean startCellEditing(EventObject anEvent) {
 152  0
         return true;
 153   
     }
 154   
 
 155  0
         public boolean stopCellEditing() { 
 156  0
         fireEditingStopped(); 
 157  0
         return true;
 158   
     }
 159   
 
 160  0
        public void cancelCellEditing() { 
 161  0
        fireEditingCanceled(); 
 162   
        }
 163   
 
 164  0
         public void actionPerformed(ActionEvent e) {
 165  0
             XMLEditor.this.stopCellEditing();
 166   
     }
 167   
 
 168  0
         public void itemStateChanged(ItemEvent e) {
 169  0
         XMLEditor.this.stopCellEditing();
 170   
     }
 171   
     }
 172   
 }
 173