public class SwingMetawidget extends JComponent
Modifier and Type | Class and Description |
---|---|
protected class |
SwingMetawidget.Pipeline |
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
SwingMetawidget() |
Modifier and Type | Method and Description |
---|---|
protected void |
addImpl(Component component,
Object constraints,
int index) |
void |
addInspectionResultProcessor(InspectionResultProcessor<SwingMetawidget> inspectionResultProcessor) |
void |
addNotify()
Overridden to build widgets just-in-time.
|
void |
addWidgetProcessor(WidgetProcessor<JComponent,SwingMetawidget> widgetProcessor) |
protected void |
buildWidgets() |
protected void |
endBuild() |
List<JComponent> |
fetchExistingUnusedComponents()
Fetch a list of
JComponents that were added manually, and have so far not been
used. |
Rectangle |
getBounds(Rectangle rectangle)
Overridden to build widgets just-in-time.
|
Component |
getComponent(int index)
Overridden to build widgets just-in-time.
|
<T extends Component> |
getComponent(String... names)
Finds the Component with the given name.
|
int |
getComponentCount()
Overridden to build widgets just-in-time.
|
Component[] |
getComponents()
Overridden to build widgets just-in-time.
|
protected String |
getDefaultConfiguration() |
Facet |
getFacet(String name) |
String |
getLabelString(Map<String,String> attributes)
Returns a label for the given set of attributes.
|
LayoutManager |
getLayout()
Overridden to build widgets just-in-time.
|
String |
getLocalizedKey(String key) |
int |
getMaximumInspectionDepth() |
Layout<JComponent,JComponent,SwingMetawidget> |
getMetawidgetLayout() |
String |
getPath() |
Dimension |
getPreferredSize()
Overridden to build widgets just-in-time.
|
<T> T |
getToInspect()
Gets the Object being inspected.
|
<T> T |
getValue(String... names)
Gets the value from the Component with the given name.
|
String |
getValueProperty(Component component)
Returns the property used to get/set the value of the component.
|
WidgetBuilder<JComponent,SwingMetawidget> |
getWidgetBuilder() |
<T> T |
getWidgetProcessor(Class<T> widgetProcessorClass) |
void |
initNestedMetawidget(SwingMetawidget nestedMetawidget,
Map<String,String> attributes)
Useful for WidgetBuilders to setup nested Metawidgets (eg.
|
String |
inspect(Object toInspect,
String type,
String... names)
Useful for WidgetBuilders to perform nested inspections (eg.
|
protected void |
invalidateInspection()
Invalidates the current inspection result (if any) and invalidates the widgets.
|
protected void |
invalidateWidgets()
Invalidates the widgets.
|
boolean |
isReadOnly() |
protected void |
layoutWidget(Component component,
String elementName,
Map<String,String> attributes) |
protected SwingMetawidget.Pipeline |
newPipeline()
Instantiate the Pipeline used by this Metawidget.
|
protected void |
paintComponent(Graphics graphics) |
void |
remove(Component component) |
void |
remove(int index) |
void |
removeAll() |
void |
removeInspectionResultProcessor(InspectionResultProcessor<SwingMetawidget> inspectionResultProcessor) |
void |
removeWidgetProcessor(WidgetProcessor<JComponent,SwingMetawidget> widgetProcessor) |
void |
setBounds(Rectangle rectangle)
Overridden to build widgets just-in-time.
|
void |
setBundle(ResourceBundle bundle) |
void |
setConfig(String config) |
void |
setInspectionResultProcessors(InspectionResultProcessor<SwingMetawidget>... inspectionResultProcessors) |
void |
setInspector(Inspector inspector) |
void |
setMaximumInspectionDepth(int maximumInspectionDepth) |
void |
setMetawidgetLayout(Layout<JComponent,JComponent,SwingMetawidget> layout)
Set the layout for this Metawidget.
|
void |
setPath(String path)
Sets the path to be inspected.
|
void |
setReadOnly(boolean readOnly) |
void |
setToInspect(Object toInspect)
Sets the Object to inspect.
|
void |
setValue(Object value,
String... names)
Sets the Component with the given name to the specified value.
|
void |
setWidgetBuilder(WidgetBuilder<JComponent,SwingMetawidget> widgetBuilder) |
void |
setWidgetProcessors(WidgetProcessor<JComponent,SwingMetawidget>... widgetProcessors) |
protected void |
startBuild() |
void |
updateToInspectWithoutInvalidate(Object toInspect)
Updates the Object to inspect, without invalidating the previous inspection results.
|
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponentAt, getComponentAt, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
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, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public void setToInspect(Object toInspect)
If setPath
has not been set, or points to a previous setToInspect
,
sets it to point to the given Object.
public void updateToInspectWithoutInvalidate(Object toInspect)
This is an internal API exposed for WidgetProcessor rebinding support. Clients should not call it directly.
public <T> T getToInspect()
Exposed for binding implementations.
Person p = getToInspect()
)public void setPath(String path)
Note setPath
is quite different to java.awt.Component.setName
.
setPath
is always in relation to setToInspect
, so must include the
type name and any subsequent sub-names (eg. type/name/name). Conversely, setName
is a single name relative to our immediate parent.
public String getPath()
public void setConfig(String config)
public void setInspector(Inspector inspector)
public String inspect(Object toInspect, String type, String... names)
public void addInspectionResultProcessor(InspectionResultProcessor<SwingMetawidget> inspectionResultProcessor)
public void removeInspectionResultProcessor(InspectionResultProcessor<SwingMetawidget> inspectionResultProcessor)
public void setInspectionResultProcessors(InspectionResultProcessor<SwingMetawidget>... inspectionResultProcessors)
public void setWidgetBuilder(WidgetBuilder<JComponent,SwingMetawidget> widgetBuilder)
public WidgetBuilder<JComponent,SwingMetawidget> getWidgetBuilder()
public void addWidgetProcessor(WidgetProcessor<JComponent,SwingMetawidget> widgetProcessor)
public void removeWidgetProcessor(WidgetProcessor<JComponent,SwingMetawidget> widgetProcessor)
public void setWidgetProcessors(WidgetProcessor<JComponent,SwingMetawidget>... widgetProcessors)
public <T> T getWidgetProcessor(Class<T> widgetProcessorClass)
public void setMetawidgetLayout(Layout<JComponent,JComponent,SwingMetawidget> layout)
Named setMetawidgetLayout
, rather than the usual setLayout
, because
Swing already defines a setLayout
. Overloading Swing's setLayout
was considered cute, but ultimately confusing and dangerous. For example, what should
setLayout( null )
do?
public Layout<JComponent,JComponent,SwingMetawidget> getMetawidgetLayout()
public void setBundle(ResourceBundle bundle)
public String getLabelString(Map<String,String> attributes)
The label is determined using the following algorithm:
public String getLocalizedKey(String key)
public boolean isReadOnly()
public void setReadOnly(boolean readOnly)
public int getMaximumInspectionDepth()
public void setMaximumInspectionDepth(int maximumInspectionDepth)
public List<JComponent> fetchExistingUnusedComponents()
JComponents
that were added manually, and have so far not been
used.
This is an internal API exposed for OverriddenWidgetBuilder. Clients should not call it directly.
public Dimension getPreferredSize()
This is the first method a JFrame.pack calls.
getPreferredSize
in class JComponent
public void setBounds(Rectangle rectangle)
This is the first method a JTable.editCellAt calls.
public Rectangle getBounds(Rectangle rectangle)
This is the first method a JComponent.paintChildren calls (this includes JDialog)
getBounds
in class JComponent
public Component getComponent(int index)
This method may be called by developers who wish to modify the created Components before they are displayed. For example, they may wish to call .setBorder( null ) if the component is to be used as a JTable CellEditor.
getComponent
in class Container
public Component[] getComponents()
This method may be called by developers who wish to modify the created Components before they are displayed. For example, they may wish to call .setBorder( null ) if the component is to be used as a JTable CellEditor.
getComponents
in class Container
public int getComponentCount()
This method may be called by developers who wish to modify the created Components before they are displayed.
getComponentCount
in class Container
public LayoutManager getLayout()
This method may be called by developers who wish to test the SwingMetawidget's active LayoutManager.
public void addNotify()
When adding a Stub that immediately stubs out a widget and therefore disappears from the
component list, we must override addNotify
to build widgets or else Swing gets
confused trying to addNotify a component that isn't there.
See SwingTutorialTest.testAddNotify
.
addNotify
in class JComponent
public <T> T getValue(String... names)
The value is returned as it was stored in the Component (eg. String for JTextField) so may need some conversion before being reapplied to the object being inspected. This obviously requires knowledge of which Component SwingMetawidget created, which is not ideal, so clients may prefer to use a binding WidgetProcessor instead.
String s = getValue(names)
)public void setValue(Object value, String... names)
Clients must ensure the value is of the correct type to suit the Component (eg. String for JTextField). This obviously requires knowledge of which Component SwingMetawidget created, which is not ideal, so clients may prefer to use a binding WidgetProcessor instead.
public String getValueProperty(Component component)
If the component is not known, returns null
. Does not throw an Exception, as we
want to fail gracefully if, say, someone tries to bind to a JPanel.
public <T extends Component> T getComponent(String... names)
public void initNestedMetawidget(SwingMetawidget nestedMetawidget, Map<String,String> attributes)
protected SwingMetawidget.Pipeline newPipeline()
Subclasses wishing to use their own Pipeline should override this method to instantiate their version.
protected String getDefaultConfiguration()
protected void paintComponent(Graphics graphics)
paintComponent
in class JComponent
protected void invalidateInspection()
As an optimisation we only invalidate the widgets, not the entire inspection result, for some operations (such as adding/removing stubs, changing read-only etc.)
protected void invalidateWidgets()
protected void buildWidgets()
protected void startBuild()
protected void layoutWidget(Component component, String elementName, Map<String,String> attributes)
elementName
- XML node name of the business field. Typically 'entity', 'property' or 'action'.
Never nullprotected void endBuild()
Copyright © 2015. All Rights Reserved.