• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.clients
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Changeset
  • Next Changeset →

Changeset 5526

Show
Ignore:
Timestamp:
07/04/08 11:49:37 (3 months ago)
Author:
will
Message:

Text-changed and focus listeners for text fields, which update the dataField with new values, have been extracted into a new class, AttributeEditorListeners?, used by (eg) AttributeTextEditor? and AttributeTextAreaEditor?

Location:
branches/OmeroEditor/src/ui
Files:
3 added
6 modified

  • components/AttributeEditorListeners.java (added)
  • components/AttributeTextAreaEditor.java (added)
  • components/AttributeTextEditor.java (added)
  • formFields/FormField.java (modified) (7 diffs)
  • formFields/FormFieldCustom.java (modified) (3 diffs)
  • formFields/FormFieldDate.java (modified) (3 diffs)
  • formFields/FormFieldMemo.java (modified) (3 diffs)
  • formFields/FormFieldNumber.java (modified) (4 diffs)
  • formFields/FormFieldText.java (modified) (3 diffs)

Legend:

Unmodified
Added
Removed
  • branches/OmeroEditor/src/ui/formFields/FormField.java

    r5483 r5526  
    6969// Subclasses have eg TextFields etc 
    7070 
    71 public abstract class FormField extends JPanel implements DataFieldObserver{ 
     71public abstract class FormField  
     72        extends JPanel  
     73        implements DataFieldObserver{ 
    7274         
    7375        IDataFieldObservable dataFieldObs; 
    … …  
    8486        public static final String HAS_FOCUS = "hasFocus"; 
    8587         
    86         boolean textChanged = false; 
    87         TextChangedListener textChangedListener = new TextChangedListener(); 
    88         FocusListener focusChangedListener = new FocusChangedListener(); 
     88        /** 
     89         * Add this listener to various buttons etc, so that if they are clicked. 
     90         * this field will become selected. 
     91         */ 
    8992        FocusListener componentFocusListener = new FormFieldComponentFocusListener(); 
    9093         
    … …  
    128131        Icon spacerIcon;                // A blank icon to replace collapsedIcon if there are no children. 
    129132         
    130         // used in Diff (comparing two trees), to get a ref to all components, to colour red if different! 
    131         ArrayList<JComponent> visibleAttributes = new ArrayList<JComponent>(); 
    132133                 
    133134        boolean showDescription = false;        // not saved, just used to toggle 
    … …  
    205206                descriptionLabel = new JLabel(); 
    206207                descriptionLabel.setBackground(null); 
    207                 visibleAttributes.add(descriptionLabel); 
     208                 
    208209                infoIcon = ImageFactory.getInstance().getIcon(ImageFactory.INFO_ICON); 
    209210                descriptionButton = new JButton(infoIcon); 
    … …  
    559560                        if(evt.getPropertyName().equals(FormField.HAS_FOCUS)) { 
    560561                                panelClicked(true); 
     562                                System.out.println("FormField. FocusGainedPropertyChangedListener"); 
    561563                        } 
    562564                } 
    … …  
    761763        } 
    762764 
    763         public ArrayList<JComponent> getVisibleAttributes() { 
    764                 return visibleAttributes; 
    765         } 
    766765         
    767766        private String addHtmlTagsForNameLabel(String text) { 
    … …  
    770769        } 
    771770         
    772          
    773         public class TextChangedListener implements KeyListener { 
    774                  
    775                 public void keyTyped(KeyEvent event) { 
    776                         textChanged = true;             // some character was typed, so set this flag 
    777                 } 
    778                 public void keyPressed(KeyEvent event) {} 
    779                 public void keyReleased(KeyEvent event) {} 
    780          
    781         } 
    782          
    783         public class FocusChangedListener implements FocusListener { 
    784                  
    785                 public void focusLost(FocusEvent event) { 
    786                         if (textChanged) { 
    787                                 JTextComponent source = (JTextComponent)event.getSource(); 
    788                                  
    789                                 setDataFieldAttribute(source.getName(), source.getText(), true); 
    790                                  
    791                                 textChanged = false; 
    792                         } 
    793                 } 
    794                 public void focusGained(FocusEvent event) {} 
    795         } 
    796          
    797  
    798771        // called to update dataField with attribute 
    799772        protected void setDataFieldAttribute(String attributeName, String value, boolean notifyUndoRedo) { 
  • branches/OmeroEditor/src/ui/formFields/FormFieldCustom.java

    r5344 r5526  
    3434import tree.IDataFieldObservable; 
    3535import ui.XMLView; 
     36import ui.components.AttributeTextEditor; 
    3637import ui.components.AttributesDialog; 
    3738import util.ImageFactory; 
    … …  
    5758                } 
    5859                 
    59                 textInput = new JTextField(); 
     60                textInput = new AttributeTextEditor(dataField,  
     61                                DataFieldConstants.TEXT_NODE_VALUE); 
    6062                textInput.addMouseListener(new FormPanelMouseListener()); 
    61                 textInput.setName(DataFieldConstants.TEXT_NODE_VALUE); 
    62                 textInput.addFocusListener(focusChangedListener); 
    63                 textInput.addKeyListener(textChangedListener); 
     63                 
     64                textInput.setVisible(false);    // not visible unless text node 
     65                 
     66                horizontalBox.add(textInput); 
     67                 
    6468                checkForTextNodeValue(); 
    6569                 
    … …  
    6872        public void checkForTextNodeValue() { 
    6973                String textNodeValue = dataField.getAttribute(DataFieldConstants.TEXT_NODE_VALUE); 
    70                 //System.out.println("FormFieldCustom constructor: textNodeValue = " + textNodeValue); 
    71                 if (textNodeValue != null) { 
    72                         textInput.setText(textNodeValue); 
    73                         horizontalBox.add(textInput); 
    74                 } 
     74                 
     75                textInput.setVisible(textNodeValue != null); 
     76                 
    7577        } 
    7678         
  • branches/OmeroEditor/src/ui/formFields/FormFieldDate.java

    r5355 r5526  
    2929import tree.DataFieldConstants; 
    3030import tree.IDataFieldObservable; 
     31import ui.components.AttributeTextEditor; 
    3132 
    3233public class FormFieldDate extends FormField { 
    … …  
    4041                String date = dataField.getAttribute(DataFieldConstants.VALUE); 
    4142                 
    42                 textInput = new JTextField(date); 
    43                 visibleAttributes.add(textInput); 
     43                textInput = new AttributeTextEditor(dataField,  
     44                                DataFieldConstants.VALUE); 
     45                 
    4446                textInput.addFocusListener(componentFocusListener); 
    45                 textInput.setName(DataFieldConstants.VALUE); 
    46                 textInput.addFocusListener(focusChangedListener); 
    47                 textInput.addKeyListener(textChangedListener); 
     47 
    4848                horizontalBox.add(textInput); 
    4949                 
    … …  
    9191        } 
    9292         
    93         // overridden by subclasses if they have other attributes to retrieve from dataField 
    94         public void dataFieldUpdated() { 
    95                 super.dataFieldUpdated(); 
    96                 textInput.setText(dataField.getAttribute(DataFieldConstants.VALUE)); 
    97         } 
    98          
    9993         
    10094        public void setHighlighted(boolean highlight) { 
  • branches/OmeroEditor/src/ui/formFields/FormFieldMemo.java

    r5355 r5526  
    2929import tree.DataFieldConstants; 
    3030import tree.IDataFieldObservable; 
     31import ui.components.AttributeTextAreaEditor; 
    3132 
    3233public class FormFieldMemo extends FormField { 
    … …  
    3940                super(dataFieldObs); 
    4041                 
    41                 /* 
    42                 inputEditor = new AttributeMemoFormatEditor(dataField,  
    43                                 "", DataFieldConstants.VALUE, dataField.getAttribute(DataFieldConstants.VALUE)); 
    44                 inputEditor.getTextArea().addFocusListener(componentFocusListener); 
    45                 horizontalBox.add(inputEditor); 
    46                 */ 
     42                textInput = new AttributeTextAreaEditor(dataField,  
     43                                DataFieldConstants.VALUE); 
    4744                 
     45                textInput.addMouseListener(new FormPanelMouseListener()); 
    4846                 
    49                 String value = dataField.getAttribute(DataFieldConstants.VALUE); 
    50                  
    51                 textInput = new JTextArea(value); 
    52                 visibleAttributes.add(textInput); 
    53                 textInput.setRows(2); 
    54                 textInput.setLineWrap(true); 
    55                 textInput.setWrapStyleWord(true); 
    56                 //JScrollPane textScroller = new JScrollPane(textInput); 
    57                 Border bevelBorder = BorderFactory.createLoweredBevelBorder(); 
    58                 Border emptyBorder = BorderFactory.createEmptyBorder(3, 3, 3, 3); 
    59                 Border compoundBorder = BorderFactory.createCompoundBorder(bevelBorder, emptyBorder); 
    60                 textInput.setBorder(compoundBorder); 
    61                 //textInput.setMaximumSize(new Dimension(500, 500)); 
    62                 textInput.addMouseListener(new FormPanelMouseListener()); 
    63                 textInput.setName(DataFieldConstants.VALUE); 
    64                 textInput.addFocusListener(focusChangedListener); 
    65                 textInput.addKeyListener(textChangedListener); 
    6647                horizontalBox.add(textInput); 
    6748                 
    … …  
    8465        } 
    8566         
    86          
    87         // overridden by subclasses if they have other attributes to retrieve from dataField 
    88         public void dataFieldUpdated() { 
    89                 super.dataFieldUpdated(); 
    90                 textInput.setText(dataField.getAttribute(DataFieldConstants.VALUE)); 
    91         } 
    9267         
    9368        public void setHighlighted(boolean highlight) { 
  • branches/OmeroEditor/src/ui/formFields/FormFieldNumber.java

    r5355 r5526  
    3434import tree.DataFieldConstants; 
    3535import tree.IDataFieldObservable; 
     36import ui.components.AttributeTextEditor; 
    3637 
    3738public class FormFieldNumber extends FormField { 
    … …  
    4445                super(dataFieldObs); 
    4546                 
    46                 String valueString = dataField.getAttribute(DataFieldConstants.VALUE); 
    4747                 
    4848                String units = dataField.getAttribute(DataFieldConstants.UNITS); 
    4949                 
    50                 numberTextBox = new JTextField(valueString); 
    51                 visibleAttributes.add(numberTextBox); 
     50                numberTextBox = new AttributeTextEditor(dataField,  
     51                                DataFieldConstants.VALUE); 
     52                 
    5253                numberTextBox.addFocusListener(componentFocusListener); 
    5354                numberTextBox.addFocusListener(new NumberCheckerListener()); 
    54                 numberTextBox.setName(DataFieldConstants.VALUE); 
    5555                numberTextBox.setMaximumSize(new Dimension(100, 30)); 
    56                 numberTextBox.addFocusListener(focusChangedListener); 
    57                 numberTextBox.addKeyListener(textChangedListener); 
    5856                numberTextBox.setToolTipText("Must enter a number"); 
    5957                 
    6058                unitsLabel = new JLabel(units); 
    61                 visibleAttributes.add(unitsLabel); 
     59                 
    6260                 
    6361                horizontalBox.add(numberTextBox); 
    … …  
    125123         
    126124        private void checkForNumber() { 
    127                 String number = numberTextBox.getText(); 
     125                String number = dataField.getAttribute(DataFieldConstants.VALUE); 
    128126                float value; 
    129127                try { 
    … …  
    141139        public void dataFieldUpdated() { 
    142140                super.dataFieldUpdated(); 
    143                 numberTextBox.setText(dataField.getAttribute(DataFieldConstants.VALUE)); 
    144141                checkForNumber(); 
    145142                setUnits(dataField.getAttribute(DataFieldConstants.UNITS)); 
  • branches/OmeroEditor/src/ui/formFields/FormFieldText.java

    r5355 r5526  
    2929import tree.DataFieldConstants; 
    3030import tree.IDataFieldObservable; 
     31import ui.components.AttributeTextEditor; 
    3132 
    3233public class FormFieldText extends FormField { 
    … …  
    3940                String value = dataField.getAttribute(DataFieldConstants.VALUE); 
    4041                 
    41                 textInput = new JTextField(value); 
    42                 visibleAttributes.add(textInput); 
     42                textInput = new AttributeTextEditor(dataField,  
     43                                DataFieldConstants.VALUE); 
    4344                textInput.addFocusListener(componentFocusListener);             // to highlight field when textBox gets focus 
    44                 textInput.setName(DataFieldConstants.VALUE); 
    45                 textInput.addFocusListener(focusChangedListener); 
    46                 textInput.addKeyListener(textChangedListener); 
     45 
    4746                horizontalBox.add(textInput); 
    4847                 
    … …  
    8887                return ((value != null) && (value.length() > 0)); 
    8988        } 
    90          
    91         // overridden by subclasses if they have other attributes to retrieve from dataField 
    92         public void dataFieldUpdated() { 
    93                 super.dataFieldUpdated(); 
    94                 textInput.setText(dataField.getAttribute(DataFieldConstants.VALUE)); 
    95         } 
    9689 
    9790         

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/