public abstract class View extends BaseComponent
AlgorithmPlugin
.
GuiJob
and GuiRequest
. If your method does not have a return type
you should use a GuiJob
to shift the action to the EDT otherwise you should use a GuiRequest
.String text; ... // possibility 1: public String getText() { return EDT.execute(new GuiRequest<String>() { protected String execute() throws Throwable { return text; } }); } public void setText(final String newText) { EDT.execute(new GuiJob() { protected void execute() throws Throwable { text = newText; } }); } // possibility 2: to avoid creating a GUI action if the current thread is the EDT you can take a little more effort public String getText() { if(EDT.isExecutedInEDT()) return text; else return EDT.execute(new GuiRequest<String>() { protected String execute() throws Throwable { return text; } }); } public void setText(final String newText) { if(EDT.isExecutedInEDT()) text = newText; else EDT.execute(new GuiJob() { protected void execute() throws Throwable { text = newText; } }); } ...Language dependent labels, tooltips and messages:
View(String, boolean, LanguageFile, String)
to specify a language file from which
labels, tooltips and messages are read by the given language id. The following language labels are available:
Resources.LANGUAGE_FILE
.
content
. The header bar consists of a title (the name of the view)
and a close button to close a view manually by the user. To set a tooltip for the close button use setCloseButtonToolTip(String)
.
content
is the area in which the view is expandable. This is a JPanel
where you can add view specific components.
Use the Container.setLayout(java.awt.LayoutManager)
method to set a layout for the content area and use the Container.add(java.awt.Component)
method to add your own components to the view.
ViewGroup
. This is a container to display several views either horizontal or vertical.
Between each views is a divider (a so called sash). The user can use this divider to increase or decrease the sizes of the
views at runtime.
Component.setFocusable(boolean)
and to set the focus manually
call JComponent.requestFocus()
.KeyListener
you have to handle the manual focus.
getAutoRepaint()
and setAutoRepaint(boolean)
and make the methods public to allow that a view respectively
(some) methods of the view can support auto repainting.
addHeaderBarComponent(JComponent)
to add view specific components to the right of the header bar. Furthermore it is possible to
extend ViewHeaderBarExtension
to create a custom headerbar.
loadConfiguration(Configuration, String)
/saveConfiguration(Configuration, String)
.
This enables you the option that a view's state can be stored persistent in case that a concrete view
implements the reading and writing of configuration data.ViewGroup
,
Serialized Formjavax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
protected javax.swing.JPanel |
content
the content that contains the component(s) of the view (add your components here)
|
protected LanguageFile |
langFile
the language file of the view
|
protected java.lang.String |
langID
the language id
|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
View(java.lang.String title)
Creates a new view.
|
View(java.lang.String title,
boolean closable)
Creates a new view.
|
View(java.lang.String title,
boolean closable,
LanguageFile langFile,
java.lang.String langID)
Creates a new view.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addHeaderBarComponent(javax.swing.JComponent component)
Adds a component to the header bar.
|
protected void |
addHeaderBarSeparator()
Adds a separator to the header bar.
|
protected void |
addImpl(java.awt.Component comp,
java.lang.Object constraints,
int index)
Adding external components is locked meaning that no components can be added directly to the view.
|
protected void |
autoRepaint()
Repaints the view but only if auto repainting is allowed.
|
protected void |
beforeRemove()
This method is invoked before the view is removed from its
ViewContainer . |
protected void |
close()
Closes the view meaning that the visibility of the view is set to
false . |
void |
extendTitle(java.lang.String extension)
Extends the title by a string meaning that the extension is appended to the title.
|
protected boolean |
getAutoRepaint()
Indicates whether auto repaint is enabled in the view.
|
javax.swing.JPanel |
getContentPanel()
Gets the content panel of the view.
|
java.lang.String |
getTitle()
Gets the name or title of the view.
|
void |
highlight(boolean enabled)
Highlights the view meaning the view is enclosed by a highlight border.
|
void |
highlight(boolean enabled,
java.awt.Color color)
Highlights the view meaning the view is enclosed by a highlight border.
|
boolean |
isClosable()
Indicates if the view is closable using the "X" in the header bar.
|
boolean |
isVisible()
Indicates whether the view is visible or not.
|
void |
loadConfiguration(Configuration cfg)
Loads the configuration data of the view from the given configuration.
|
void |
loadConfiguration(Configuration cfg,
java.lang.String key)
Loads the configuration data of the view from the given configuration.
|
protected void |
readConfigurationData(Configuration cd)
Reads the configuration data of the view.
|
void |
removeAll()
It is not possible to remove the components of the view meaning this method does nothing!
|
protected void |
removeHeaderBarComponent(javax.swing.JComponent component)
Removes the specified component from the header bar.
|
abstract void |
reset()
Resets the view which means sets the initial state of the view.
|
void |
saveConfiguration(Configuration cfg)
Saves the configuration data of the view to the given configuration.
|
void |
saveConfiguration(Configuration cfg,
java.lang.String key)
Saves the configuration data of the view to the given configuration.
|
protected void |
setAutoRepaint(boolean autoRepaint)
Sets whether the view is allowed to be auto repainted.
|
void |
setBorder(javax.swing.border.Border border)
The border of a view may not be set meaning this method does nothing!
|
protected void |
setCloseButtonToolTip(java.lang.String toolTip)
Sets the tooltip text of the close button in the upper right corner of the view.
|
void |
setLayout(java.awt.LayoutManager mgr)
The layout of a view may not be changed meaning this method does nothing!
|
void |
setVisible(boolean visible)
Sets whether the view should be visible or not.
|
java.lang.String |
toString() |
protected void |
writeConfigurationData(Configuration cd)
Writes the configuration data of the view.
|
isRepaintDisabled, repaint, repaintComponent, setRepaintDisabled
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, 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, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update, updateUI
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
protected final LanguageFile langFile
protected final java.lang.String langID
protected final javax.swing.JPanel content
public View(java.lang.String title) throws java.lang.IllegalArgumentException
title
- the name of the view which is displayed as the title in the header barjava.lang.IllegalArgumentException
- public View(java.lang.String title, boolean closable) throws java.lang.IllegalArgumentException
title
- the name of the view which is displayed as the title in the header barclosable
- true
if the view can be closed by the user using the "X" in the header bar otherwise false
(if a view is not closable he must be set invisible manually using setVisible(boolean)
if required)java.lang.IllegalArgumentException
- public View(java.lang.String title, boolean closable, LanguageFile langFile, java.lang.String langID) throws java.lang.IllegalArgumentException
LanguageFile
and a language id to display language dependent
messages and tooltips in the view. The following language labels are available:
title
- the name of the view which is displayed as the title in the header barclosable
- true
if the view can be closed by the user using the "X" in the header bar otherwise false
(if a view is not closable he must be set invisible manually using setVisible(boolean)
if required)langFile
- the language file or null
if the view should not use language dependent labels, tooltips or messages (in this case the predefined labels, tooltips and messages are shown)langID
- the language idjava.lang.IllegalArgumentException
- public final java.lang.String getTitle()
public final void extendTitle(java.lang.String extension) throws java.lang.IllegalArgumentException
extension
- the extension stringjava.lang.IllegalArgumentException
- public final boolean isClosable()
true
if view is closable otherwise false
public final javax.swing.JPanel getContentPanel()
content
public final void loadConfiguration(Configuration cfg)
"VIEW_" + getTitle()
as the configuration key. If you have changing titles
(for example because of language independent titles) you should create a unique configuration key on your own
by using loadConfiguration(Configuration, String)
.cfg
- the configurationreadConfigurationData(Configuration)
public final void loadConfiguration(Configuration cfg, java.lang.String key)
cfg
- the configurationkey
- the configuration key of the view (must be unique based on the specified configuration otherwise false data could be loaded)readConfigurationData(Configuration)
public final void saveConfiguration(Configuration cfg)
"VIEW_" + getTitle()
as the configuration key. If you have changing titles
(for example because of language independent titles) you should create a unique configuration key on your own
by using saveConfiguration(Configuration, String)
.cfg
- the configuration or null
if the view has no configurationwriteConfigurationData(Configuration)
public final void saveConfiguration(Configuration cfg, java.lang.String key)
cfg
- the configurationkey
- the configuration key of the view (must be unique based on the specified configuration otherwise existing data could be overwritten)writeConfigurationData(Configuration)
public abstract void reset()
public void highlight(boolean enabled)
enabled
- true
if the highlight should be enabled otherwise false
highlight(boolean, Color)
public void highlight(boolean enabled, java.awt.Color color)
enabled
- true
if the highlight should be enabled otherwise false
color
- the color of the highlight borderpublic void setBorder(javax.swing.border.Border border)
highlight(boolean)
.setBorder
in class javax.swing.JComponent
border
- the borderpublic final void setLayout(java.awt.LayoutManager mgr)
setLayout
in class java.awt.Container
mgr
- the layout managerpublic void removeAll()
removeAll
in class java.awt.Container
public boolean isVisible()
isVisible
in class java.awt.Component
true
if the view is not visible meaning the view is closed otherwise false
public void setVisible(boolean visible)
setVisible
in class javax.swing.JComponent
visible
- true
if the view should be visible otherwise false
public java.lang.String toString()
toString
in class java.awt.Component
protected final void addImpl(java.awt.Component comp, java.lang.Object constraints, int index)
content
or getContentPanel()
to add components to the view.addImpl
in class java.awt.Container
comp
- the componentconstraints
- the constraintsindex
- the indexprotected boolean getAutoRepaint()
true
if auto repainting is allowed otherwise false
protected void setAutoRepaint(boolean autoRepaint)
BaseComponent.repaint()
on your own to visualize the changes you made to a component or view.
BaseComponent.repaint()
method of the view is automatically
invoked to make the changes visible. But ensure that this does not overload the EDT (event dispatch thread).n
objects in a loop and you activate the auto repaint option.n
calls to BaseComponent.repaint()
instead of one call at the end of the loop.GuiRequest
) and in consequence of that
the algorithm must wait until the pending event is processed in the EDT.autoRepaint
- true
if auto repainting should be enabled otherwise false
protected void autoRepaint()
protected void readConfigurationData(Configuration cd)
... protected void readConfigurationData(Configuration cd) { super.readConfigurationData(cd); // load custom data like // foreground = cd.getColor("foreground"); // ... } ...
cd
- the configuration dataprotected void writeConfigurationData(Configuration cd)
... protected void writeConfigurationData(Configuration cd) { super.writeConfigurationData(cd); // write custom data like // cd.addColor("foreground", foreground); // ... } ...
cd
- the configuration dataprotected final void addHeaderBarComponent(javax.swing.JComponent component) throws java.lang.IllegalArgumentException
JToolBar.Separator
as the component or call addHeaderBarSeparator()
.component
- the componentjava.lang.IllegalArgumentException
- addHeaderBarSeparator()
protected final void addHeaderBarSeparator()
addHeaderBarComponent(JComponent)
protected final void removeHeaderBarComponent(javax.swing.JComponent component) throws java.lang.IllegalArgumentException
component
- the componentjava.lang.IllegalArgumentException
- protected final void setCloseButtonToolTip(java.lang.String toolTip)
toolTip
- the tooltip textprotected void close()
false
.
protected void beforeRemove()
ViewContainer
.