Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.scopemvc.view.swing
Class SComboBox  view SComboBox download SComboBox.java

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JComboBox
                  extended byorg.scopemvc.view.swing.SComboBox
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.ItemSelectable, javax.swing.event.ListDataListener, java.awt.MenuContainer, Refreshable, java.io.Serializable, org.scopemvc.core.View

public class SComboBox
extends javax.swing.JComboBox
implements org.scopemvc.core.View, Refreshable

A JComboBox that uses a SComboBoxModel to bind to model properties for the list of items and to bind the selected item to a property. Uses a SListCellRenderer to draw items in the list. Uses a SComboBoxEditor if editable.

SComboBox can issue Controls on selection changes.

SList doesn't itself bind to a model: it delegates all binding to its SComboBoxModel.

Examples for SComboBox use can be found in samples.swing.combodemo package, and see SComboBoxModel and SAbstractListModel.

Elements (rows) in the data model can be arbitrary class (e.g. Person, Employee etc.). Scope's combobox renderer can have set Selector for desired element attribute (e.g. "name"). If selector is ommited, then toString() value is drawn. If elements are of types for which exist StringConvertor, the combo box can be editable (exactly not the elements, but selected item property, however it has make sense to have elements and selected item of the same type.)

Data model will be typically array (Object[]) or list derived from java.util.List. For this case there is no need to set size model. For example:

     class SelectedPerson {
         ...
         public void setSelectedPerson(Person p) {...}
         public Person getSelectedPerson() {...}
     }
     ...
     List persons = getSomePersons();
     combo.setDataModel(persons);
     combo.setSelectionSelectorString("selectedPerson");	// a property of the bound view model
 

Some times data elements of combobox changes during combobox life cycle. For this case is better to use single model for both selection and element list. The list is treated as model property and can be changed:

     class PersonSelection extends BasicModel {
         public final static Selector PERSONS = Selector.fromString("persons");
         ...
         public void setSelectedPerson(Person p) {...}
         public Person getSelectedPerson() {...}
         public List getPersons() {...}

         ...
             // in some method
             persons = fetchOtherPersons();
             super.fireModelChange(ModelChangeEvent.VALUE_CHANGED, PERSONS);
             // now are data in combobox refreshed
         ...
     }
     ...
     SComboBox combo = new SComboBox();
     combo.setSelector(PERSONS);
     combo.setSelectionSelectorString("selectedPerson");
     ...
 
Note that since persons attribute is of type java.util.List, there is again no need to set size selector.

In the last variation of the example is shown, where the size model and selector is need. Java Beans specifiaction says, that indexed properties can be exposed as a single array value. However, this is not requirement. Let's see example:

     class Persons  {
         ...
         public Person getPerson(int i) {...}
         public void setPerson(int i, Person p) {...}

         public int getPersonsNumber() {...}
     }
     ...
     SComboBox combo = new SComboBox();
     combo.setSelectorString("person");
     combo.setSizeSelectorString("personsNumber");
     ...
 

Version:
$Revision: 1.8 $ $Date: 2002/01/26 09:46:20 $

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComboBox
javax.swing.JComboBox.AccessibleJComboBox, javax.swing.JComboBox.KeySelectionManager
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private static org.apache.commons.logging.Log LOG
           
private  java.lang.String selectionControlID
           
private  ValidationHelper validationHelper
          Helper to manage validation state.
 
Fields inherited from class javax.swing.JComboBox
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SComboBox()
           
 
Method Summary
 javax.swing.JToolTip createToolTip()
          Return the toolTip property of this component, creating it and setting it if it is currently null.
 java.lang.Object getBoundModel()
           
 org.scopemvc.core.Controller getController()
          Don't assign a direct Controller to ComboBox, instead delegate to the containing SwingView that has a parent Controller.
 void issueChangeSelectionControl()
           
 void issueControl(org.scopemvc.core.Control inControl)
          Don't assign a direct Controller to ComboBox, instead delegate to the containing SwingView that has a parent Controller.
 void refresh()
          Update the widget with the current state of the bound model.
 void setBoundModel(java.lang.Object inModel)
           
 void setChangeSelectionControlID(java.lang.String inControlID)
          Set the Control ID for the Control that will be issued when the selection is changed.
 void setController(org.scopemvc.core.Controller inController)
          Don't assign a direct Controller to ComboBox, instead delegate to the containing SwingView that has a parent Controller.
 void setListModel(java.lang.Object inModel)
          Can use this to specify a static list model for the contents of the list rather than binding to a dynamic property of some view model.
 void setModel(javax.swing.ComboBoxModel m)
          This method is overriden to fix JDK 1.2.x,1.3.x bug: after setting model combobox sets element 0 as selected.
 void setRendererIconSelector(org.scopemvc.core.Selector inSelector)
          Set the Selector for the list cell renderer to get an Icon: this is the property that will be shown as an Icon in a list cell.
 void setRendererIconSelectorString(java.lang.String inSelectorString)
          Set the Selector for the list cell renderer to get an Icon: this is the property that will be shown as an Icon in a list cell.
 void setRendererSelector(org.scopemvc.core.Selector inSelector)
          Set the Selector for the list cell renderer: this is the property that will be shown in a list cell (converted to a String).
 void setRendererSelectorString(java.lang.String inSelectorString)
          Set the Selector for the list cell renderer: this is the property that will be shown in a list cell (converted to a String).
 void setSelectionSelector(org.scopemvc.core.Selector inSelector)
          Set the Selector for the list selection: this property will be bound to the list's single selection.
 void setSelectionSelectorString(java.lang.String inSelectorString)
          Set the Selector for the list selection: this property will be bound to the list's single selection.
 void setSelector(org.scopemvc.core.Selector inSelector)
          Set the Selector for the list data.
 void setSelectorString(java.lang.String inSelectorString)
          Set the Selector for the list data.
 void setSizeSelector(org.scopemvc.core.Selector inSelector)
          Optional: set the Selector for the property that is the size of the items list.
 void setSizeSelectorString(java.lang.String inSelectorString)
          Optional: set the Selector for the property that is the size of the items list.
 void setStringConvertor(org.scopemvc.util.convertor.StringConvertor inConvertor)
          Force use of this StringConvertor instead of automatically finding one to match the datatype being edited.
 void validationFailed(java.lang.Exception inException)
           
 void validationSuccess()
           
 
Methods inherited from class javax.swing.JComboBox
actionPerformed, addActionListener, addItem, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditable, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setPopupVisible, setPrototypeDisplayValue, setRenderer, setSelectedIndex, setSelectedItem, setUI, showPopup, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

private static final org.apache.commons.logging.Log LOG

selectionControlID

private java.lang.String selectionControlID

validationHelper

private ValidationHelper validationHelper
Helper to manage validation state.

Constructor Detail

SComboBox

public SComboBox()
Method Detail

setStringConvertor

public void setStringConvertor(org.scopemvc.util.convertor.StringConvertor inConvertor)
Force use of this StringConvertor instead of automatically finding one to match the datatype being edited.


setModel

public void setModel(javax.swing.ComboBoxModel m)
This method is overriden to fix JDK 1.2.x,1.3.x bug: after setting model combobox sets element 0 as selected. This is violation of MVC paradigm - model describes some state and should not be modified by view. JDK 1.4 beta has this bug fixed.

Model should be instance of SComboBoxModel to fix take effect

.


getBoundModel

public final java.lang.Object getBoundModel()
Specified by:
getBoundModel in interface org.scopemvc.core.View

setBoundModel

public final void setBoundModel(java.lang.Object inModel)
Specified by:
setBoundModel in interface org.scopemvc.core.View

setListModel

public void setListModel(java.lang.Object inModel)
Can use this to specify a static list model for the contents of the list rather than binding to a dynamic property of some view model.


setSelector

public final void setSelector(org.scopemvc.core.Selector inSelector)
Set the Selector for the list data. Should be a java.util.List or an Object[] or have a "size" property and properties accessible by an IntIndexedSelector.


setSelectorString

public final void setSelectorString(java.lang.String inSelectorString)
Set the Selector for the list data. Should be a java.util.List or an Object[] or have a "size" property and properties accessible by an IntIndexedSelector.


setSelectionSelector

public final void setSelectionSelector(org.scopemvc.core.Selector inSelector)
Set the Selector for the list selection: this property will be bound to the list's single selection.


setSelectionSelectorString

public final void setSelectionSelectorString(java.lang.String inSelectorString)
Set the Selector for the list selection: this property will be bound to the list's single selection.


setRendererSelector

public final void setRendererSelector(org.scopemvc.core.Selector inSelector)
Set the Selector for the list cell renderer: this is the property that will be shown in a list cell (converted to a String).


setRendererIconSelector

public final void setRendererIconSelector(org.scopemvc.core.Selector inSelector)
Set the Selector for the list cell renderer to get an Icon: this is the property that will be shown as an Icon in a list cell.


setRendererSelectorString

public final void setRendererSelectorString(java.lang.String inSelectorString)
Set the Selector for the list cell renderer: this is the property that will be shown in a list cell (converted to a String).


setRendererIconSelectorString

public final void setRendererIconSelectorString(java.lang.String inSelectorString)
Set the Selector for the list cell renderer to get an Icon: this is the property that will be shown as an Icon in a list cell.


setSizeSelector

public final void setSizeSelector(org.scopemvc.core.Selector inSelector)
Optional: set the Selector for the property that is the size of the items list. Not needed for lists that are of type Object[] or java.util.List.


setSizeSelectorString

public final void setSizeSelectorString(java.lang.String inSelectorString)
Optional: set the Selector for the property that is the size of the items list. Not needed for lists that are of type Object[] or java.util.List.


issueChangeSelectionControl

public void issueChangeSelectionControl()

setChangeSelectionControlID

public final void setChangeSelectionControlID(java.lang.String inControlID)
Set the Control ID for the Control that will be issued when the selection is changed. If null no Control will be issued.


setController

public void setController(org.scopemvc.core.Controller inController)
Don't assign a direct Controller to ComboBox, instead delegate to the containing SwingView that has a parent Controller.

Specified by:
setController in interface org.scopemvc.core.View

getController

public org.scopemvc.core.Controller getController()
Don't assign a direct Controller to ComboBox, instead delegate to the containing SwingView that has a parent Controller.

Specified by:
getController in interface org.scopemvc.core.View

issueControl

public void issueControl(org.scopemvc.core.Control inControl)
Don't assign a direct Controller to ComboBox, instead delegate to the containing SwingView that has a parent Controller.

Specified by:
issueControl in interface org.scopemvc.core.View

refresh

public void refresh()
Description copied from interface: Refreshable
Update the widget with the current state of the bound model. Probably something like this:
     Object propertyValue = boundModel.getPropertyValue();
     boolean propertyReadOnly = boundModel.getPropertyReadOnly();
     updateFromProperty(propertyValue, propertyReadOnly);
 

Specified by:
refresh in interface Refreshable

validationFailed

public void validationFailed(java.lang.Exception inException)

validationSuccess

public void validationSuccess()

createToolTip

public javax.swing.JToolTip createToolTip()
Description copied from class: javax.swing.JComponent
Return the toolTip property of this component, creating it and setting it if it is currently null. This method can be overridden in subclasses which wish to control the exact form of tooltip created.