public abstract class TICComponent extends java.lang.Object
SwingComponentFactory
and SWTComponentFactory
from the respective TIC modules
can be used.
To create a concrete TIC component either the paint(TICPaintEvent)
method must be overwritten
with code painting the component or toolkit specific classes for Swing and SWT that do not need
a toolkit-independent paint method must be provided by overwriting getSwingComponentClassName(Object...)
and getSWTComponentClassName(Object...)()
.
getSize()
should be overwritten if a component requires a certain (minimal) size.
Note that depending on your GUI design assignSize()
might not have the desired effect if
#assignSizeToSWTLayoutData(org.eclipse.swt.graphics.Point, Composite)
is not overwritten with an
respective implementation.
TIC components support adding TIC event listeners for mouse and keyboard events. Due to the implementation of this
behavior the toolkit specific components always have mouse and key listeners attached, no matter if a TIC listener
was attached to the owning TIC component. In the case of Swing components events will not be forwarded to parent
components anymore, even if no listener in this component consumed the event. Therefore TIC components automatically
forward events to parent Swing components, if no TIC listener for the according event type consumed that event.
TIC listener indicate whether they consumed an event by the return value of their handler methods (e.g.
TICMouseWheelListener.mouseWheelMoved(info.bioinfweb.tic.input.TICMouseWheelEvent)
).
If more than one listener for the same event type is attached to a TIC component, all listeners will be informed on events, no matter if a previous listener in the list already consumed the event. (Only forwarding to parent events is influenced by the return value of TIC event listeners.)
ScrollingTICComponent
,
ToolkitComponent
Modifier and Type | Field and Description |
---|---|
protected static java.util.Map<java.lang.Integer,info.bioinfweb.tic.TICComponent.EventDispatcher> |
DISPATCHER_MAP |
protected boolean |
repaintRequested |
Constructor and Description |
---|
TICComponent()
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
void |
addKeyListener(TICKeyListener listener)
Adds a key listener to this component (and automatically to the underlying toolkit specific component).
|
void |
addMouseListener(TICMouseListener listener)
Adds a mouse listener to this component (and automatically to the underlying toolkit specific component).
|
void |
addMouseWheelListener(TICMouseWheelListener listener)
Adds a mouse wheel listener to this component (and automatically to the underlying toolkit specific component).
|
void |
assignSize()
Adopts the current component size to the underlying GUI toolkit, if a toolkit specific component
has already been created.
|
boolean |
dispatchEvent(TICInputEvent event) |
TargetToolkit |
getCurrentToolkit()
Returns the toolkit the associated toolkit class belongs to.
|
protected TICListenerSet<TICKeyListener> |
getKeyListenersSet() |
protected TICListenerSet<TICMouseListener> |
getMouseListenersSet() |
protected TICListenerSet<TICMouseWheelListener> |
getMouseWheelListenersSet() |
java.awt.Dimension |
getSize()
Returns the size this object needs to be painted completely.
|
protected java.lang.String |
getSwingComponentClassName(java.lang.Object... parameters)
Method used by
SwingComponentFactory in the Swing module to create the concrete GUI
object for Swing. |
protected java.lang.Object[] |
getSwingComponentConstructorParameters(java.lang.Object... parameters)
Inherited classes can overwrite this method if their Swing component needs constructor parameters
in addition to the owning
TICComponent . |
protected java.lang.String |
getSWTComponentClassName(java.lang.Object... parameters)
Method used by
SWTComponentFactory in the SWT module to create the concrete GUI
object for SWT. |
protected java.lang.Object[] |
getSWTComponentConstructorParameters(java.lang.Object... parameters)
Inherited classes can overwrite this method if their SWT component needs constructor parameters
in addition to the owning
TICComponent , the parent composite and the SWT style. |
ToolkitComponent |
getToolkitComponent()
Returns a toolkit specific component used to display the contents of this class.
|
boolean |
hasDefinedSize()
Determines whether this component specifies a defined size.
|
boolean |
hasToolkitComponent()
Checks if an associated toolkit specific component has already been assigned to this instance.
|
boolean |
isUpdateOngoing()
Determines whether the contents displayed by this component are currently ongoing.
|
void |
paint(TICPaintEvent event)
Painting operations of the implementing class should be performed here, if a toolkit independent
painting method is provided.
|
boolean |
removeKeyListener(TICKeyListener listener)
Removes the specified key listener from this component (and from the underlying toolkit specific component).
|
boolean |
removeMouseListener(TICMouseListener listener)
Removes the specified mouse listener from this component (and from the underlying toolkit specific component).
|
boolean |
removeWheelMouseListener(TICMouseWheelListener listener)
Removes the specified mouse wheel listener from this component (and from the underlying toolkit specific component).
|
void |
repaint()
Forces the underlying toolkit component to be repainted.
|
protected void |
setToolkitComponent(ToolkitComponent toolkitComponent) |
void |
setUpdateOngoing(boolean updateOngoing)
Allows to specify whether the contents displayed by this component are currently ongoing.
|
protected static final java.util.Map<java.lang.Integer,info.bioinfweb.tic.TICComponent.EventDispatcher> DISPATCHER_MAP
protected boolean repaintRequested
public TICComponent()
public TargetToolkit getCurrentToolkit()
TargetToolkit.UNDEFINED
if no toolkit specific
implementation has yet been assignedpublic void paint(TICPaintEvent event)
If implementing classes provide custom toolkit specific components by overwriting
getSwingComponentClassName(Object...)
and getSwingComponentClassName(Object...)
the implementation of this method may remain empty.
This default implementation is empty. Inherited classes must either overwrite it or overwrite
getSwingComponentClassName(Object...)
and getSWTComponentClassName(Object...)
to provide toolkit components that do not need an implementation of this method.
event
- the paint event providing the graphics context and information on which part of the
component should be repaintedpublic java.awt.Dimension getSize()
Components may specify their minimal size or the only acceptable fixed size here. The respective
toolkit components should be implemented respectively. Returning null
if the component
does not prefer any size is also valid.
Note that this size may differ from the actual size of the toolkit component, e.g. if it specifies a preferred size.
This default implementation always returns null
.
null
ToolkitComponent.getToolkitSize()
public boolean hasDefinedSize()
getSize()
for details.public boolean isUpdateOngoing()
repaint()
makes use of this property to avoid unnecessary repaint operations.
true
if an update is currently ongoing, false
otherwisepublic void setUpdateOngoing(boolean updateOngoing)
repaint()
makes use of this property to avoid unnecessary repaint operations. If
this property is changed from true
to false
, the component will be repainted
directly, if that was previously requested.
updateOngoing
- true
if an update is currently ongoing, false
otherwisepublic void repaint()
hasToolkitComponent()
return
true
).
If isUpdateOngoing()
is set to true
, calls of this method will not cause a direct
repaint. The request for repainting is stored internally by this instance and it will be repainted
when setUpdateOngoing(boolean)
is set to false
the next time. (If this method was
called multiple times before that, still only one repaint operation will be performed.)
public void assignSize()
This methods delegates to ToolkitComponent.assignSize()
, if an underlying toolkit-specific
component was already created.
public ToolkitComponent getToolkitComponent()
null
if neither a Swing nor a SWT component has yet been createdprotected void setToolkitComponent(ToolkitComponent toolkitComponent)
public boolean hasToolkitComponent()
true
if a component has been assigned, false
otherwiseprotected java.lang.String getSwingComponentClassName(java.lang.Object... parameters)
SwingComponentFactory
in the Swing module to create the concrete GUI
object for Swing. Inherited classes providing custom Swing specific implementations should
overwrite this method.
Note that custom implementations need to provide constructors as defined in the documentation
of ToolkitComponent
.
parameters
- an optional list of parameters that were passed to the getSwingComponent()
method of SwingComponentFactory
protected java.lang.Object[] getSwingComponentConstructorParameters(java.lang.Object... parameters)
TICComponent
.
The default implementation of this method returns an empty array an can be left unchanged for all Swing components that do not need additional constructor parameters.
parameters
- an optional list of parameters that were passed to the getSwingComponent()
method of SwingComponentFactory
getSwingComponentClassName(Object...)
protected java.lang.String getSWTComponentClassName(java.lang.Object... parameters)
SWTComponentFactory
in the SWT module to create the concrete GUI
object for SWT. Inherited classes providing custom SWT specific implementations should
overwrite this method.
Note that custom implementations need to provide constructors as defined in the documentation
of ToolkitComponent
.
parameters
- an optional list of parameters that were passed to the getSWTComponent()
method of SWTComponentFactory
protected java.lang.Object[] getSWTComponentConstructorParameters(java.lang.Object... parameters)
TICComponent
, the parent composite and the SWT style.
The default implementation of this method returns an empty array an can be left unchanged for all SWT components that do not need additional constructor parameters.
parameters
- an optional list of parameters that were passed to the getSWTComponent()
method of SWTComponentFactory
getSwingComponentClassName(Object...)
protected TICListenerSet<TICKeyListener> getKeyListenersSet()
protected TICListenerSet<TICMouseListener> getMouseListenersSet()
protected TICListenerSet<TICMouseWheelListener> getMouseWheelListenersSet()
public void addKeyListener(TICKeyListener listener)
listener
- the object to listen to key eventspublic boolean removeKeyListener(TICKeyListener listener)
listener
- the listener to be removedtrue
if the specified lister was contained in the list, false
otherwisepublic void addMouseListener(TICMouseListener listener)
listener
- the object to listen to mouse eventsaddMouseWheelListener(TICMouseWheelListener)
public boolean removeMouseListener(TICMouseListener listener)
listener
- the listener to be removedtrue
if the specified lister was contained in the list, false
otherwisepublic void addMouseWheelListener(TICMouseWheelListener listener)
listener
- the object to listen to mouse wheel eventsaddMouseListener(TICMouseListener)
public boolean removeWheelMouseListener(TICMouseWheelListener listener)
listener
- the listener to be removedtrue
if the specified lister was contained in the list, false
otherwisepublic boolean dispatchEvent(TICInputEvent event)