borland Packages Class Hierarchy dbswing Package
java.lang.Object +----com.borland.dbswing.DBTextDataBinder
Variables Constructors Properties Methods
Implements AccessListener, ColumnAware, DataChangeListener, DataSetAware, Designable, NavigationListener, FocusListener, KeyListener, MouseListener, PropertyChangeListener, Serializable, EventListener, DocumentListener, HyperlinkListener, UndoableEditListener
DBTextDataBinder
maps data from a Swing text component to a DataSet
Column
value. DBTextDataBinder
is used internally to make the JdbTextField
, JdbTextArea
, JdbTextPane
, and JdbEditorPane
components data-aware.
There are two ways to hook up a Swing text component to a
DBTextDataBinder
:
JTextComponent
property to any text component extending
the JTextComponent
class, such as JTextField
, JTextArea
, JTextPane
, or JEditorPane
.
Set DBTextDataBinder's
document
property to the text component's model. Any component using a Document
class as its model can be made data-aware. Note that when using this approach you are responsible for opening the DataSet
before using it.
In either case, you must set DBTextDataBinder's
dataSet
and columnName
properties to indicate the DataSet
and Column
from which the text value is to be read and to which it is to be written. DBTextDataBinder
ensures that the state of the text component is consistent with the current value of the DataSet
Column
to which it is attached.
If you set the JTextComponent
property, DBTextDataBinder
also binds the background
, foreground
, and font
properties from those defined on Column
columnName
(if defined), unless already explicitly set on the JTextComponent
itself.
Data typed into a component made data-aware by DBTextDataBinder
is
not saved immediately to the DataSet
. Rather, certain
conditions/events automatically cause the data to be put into the
DataSet's
column. These two properties affect this behavior:
postOnFocusLost
- If true
, data is saved to the DataSet
whenever the component bound by (or made data-aware by) DBTextDataBinder
loses focus.postOnRowPosted
- If true
, data is saved to the DataSet
whenever the current DataSet
row is posted.
DBTextDataBinder
maps a small number of keys to special editing/DataSet
navigation functions for each bound text component. See the notes in JdbTextField
, JdbTextArea
, JdbTextPane
, and JdbEditorPane
for more details.
DBTextDataBinder
provides each bound component a popup menu for performing simple editing tasks, such as cutting, copying, or pasting clipboard data. The popup menu also appears when the user presses Shift+F10 while the cursor is in the bound component. The menu
commands on the popup menu vary according to the capabilities of the
bound text component. The set of available menu commands can
be customized via the following properties:
enablePopupMenu
- Sets whether or not the popup menu is displayable.enableClearAll
- Sets whether the Clear All popup menu command appears.enableUndoRedo
- Sets whether the Undo and Redo menu commands appear on the popup menu.enableFileLoading
- Sets whether the File Open menu command appears on the popup menu.enableFileSaving
- Sets whether the File Save menu command appears on the popup menu.enableColorChange
- Sets whether the foreground and background color setting menu commands appear on the popup menu.enableFontChange
- Sets whether the font style setting menu commands appear on the popup menu.enableURLLoading
- Sets whether the Open URL menu command appears on the popup menu (JEditorPane
and its subclasses only).
Each text component (subclass of javax.swing.text.JTextComponent
) provides a set of built-in javax.swing.Action
objects (which have names like
'caret-forward', 'page-down', 'paste-from-clipboard', etc.) returned by its getActions()
method. The component's look-and-feel (for example,
javax.swing.plaf.basic.BasicTextUI
) calls the component's getActions()
method to get a list of Actions
provided by the component, and maps the appropriate keystroke to each Action
by name. Thus, for example, in the Windows look and feel class, the right-arrow keystroke is linked to the action 'caret-forward', PgDn to 'page-down', and Ctrl+Ins to 'paste-from-clipboard'.
Nearly all the functionality provided by JdbTextField
, JdbTextArea
, JdbTextPane
, and JdbEditorPane
is available as public Actions
in DBTextDataBinder
. For example, DBTextDataBinder
provides a public Action
named LoadFileAction
that a user can add to a menu, button, or
toolbar to load a file into a JTextArea
as follows:
JButton loadFileButton = new JButton("Load file"); loadFileButton.addActionListener(new DBTextDataBinder.LoadFileAction());
When the button is pressed, the LoadFileAction
is invoked, which brings up a Load File dialog box, allowing the user to select a text file to load into the component. The following table lists the available actions, specifies the components the actions apply to, and describes what the actions do.
DBTextDataBinder
actions
Action Name (Class) | Applies To | Description |
---|---|---|
undo (DBTextDataBinder.UndoAction ) |
any subclass of javax.swing.JTextComponent bound to a DBTextDataBinder |
undoes the most recent change |
redo (DBTextDataBinder.RedoAction ) |
any subclass of javax.swing.JTextComponent bound to a DBTextDataBinder |
re-does the most recent change |
clear-all (DBTextDataBinder.ClearAllAction ) |
any subclass of javax.swing.JTextComponent bound to a DBTextDataBinder |
deletes all text in the component |
select-all (DBTextDataBinder.SelectAllAction ) |
any subclass of javax.swing.JTextComponent |
selects all text in the component |
load-URL (DBTextDataBinder.LoadURLAction ) |
javax.swing.JEditorPane or com.borland.dbswing.JdbEditorPane |
loads an HTML page into a JdbEditorPane via URL |
load-file (DBTextDataBinder.LoadFileAction ) |
any subclass of javax.swing.JTextComponent other than JTextField |
loads data from a file into the component |
save-file (DBTextDataBinder.SaveFileAction ) |
any subclass of javax.swing.JTextComponent other than JTextField |
saves data in a component to a file |
next-row (DBTextDataBinder.NextRowAction ) |
any subclass of javax.swing.JTextComponent bound to a DBTextDataBinder |
navigates to the next DataSet row |
prior-row (DBTextDataBinder.PriorRowAction ) |
any subclass of javax.swing.JTextComponent bound to a DBTextDataBinder |
navigates to the prior DataSet row |
post-data (DBTextDataBinder.PostDataAction ) |
any subclass of javax.swing.JTextComponent bound to a DBTextDataBinder |
posts component data to its corresponding DataSet Column |
cancel-post
( DBTextDataBinder.CancelPostAction ) |
any subclass of javax.swing.JTextComponent bound to a DBTextDataBinder |
reverts component data to its corresponding DataSet Column value |
font-dialog (DBTextDataBinder.FontDialogAction ) |
any subclass of javax.swing.JTextPane |
displays dbSwing's FontChooser dialog to change the text's font |
foreground-color-dialog (DBTextDataBinder.ForegroundColorDialogAction ) |
any subclass of javax.swing.JTextPane |
displays Swing's JColorChooser dialog to change the text's foreground
color |
background-color-dialog (DBTextDataBinder.BackgroundColorDialogAction ) |
any subclass of javax.swing.JTextPane |
displays Swing's JColorChooser dialog to change the text's background
color |
JTextField jTextField = new JTextField(); DBTextDataBinder dbTextDataBinder = new DBTextDataBinder(); // attach the field to DBTextDataBinder dbTextDataBinder.setJTextComponent(jTextField); // set the target DataSet and Column dbTextDataBinder.setDataSet(dataSet); dbTextDataBinder.setColumnName("Name");
public static Action BACKGROUNDCOLOR_ACTIONA reference to an action that displays a color dialog for changing the background color of the component.
public static final String backgroundColorDialogAction = "background-color-dialog"The name of the action that displays a color dialog for changing the background color of the component.
public static final String cancelPostAction = "cancel-post"The name of the action that cancels a posting of the text to the
DataSet
.
public static Action CLEARALL_ACTIONA reference to an action that clears the data displayed in the component.
public static final String clearAllAction = "clear-all"The name of the action that clears the data displayed in the component.
public static Action COPY_ACTIONA reference to an action that copies the data displayed in the component to the system clipboard.
public static Action CUT_ACTIONA reference to an action that removes the data displayed in the component and places it in the system clipboard.
public static final String deleteRowAction = "delete-row"The name of the action that deletes the current row.
public static Action FONTDIALOG_ACTIONA reference to an action that displays a font dialog box so the user can select a font for the component.
public static final String fontDialogAction = "font-dialog"The name of the action that displays a font dialog box so the user can select a font for the component.
public static Action FOREGROUNDCOLOR_ACTIONA reference to an action that displays a color dialog box so the user can select a foreground color for the component.
public static final String foregroundColorDialogAction = "foreground-color-dialog"The name of the action that displays a color dialog box so the user can select a foreground color for the component.
public static final String insertRowAction = "insert-row"The name of the action that inserts a row.
public static Action LOADFILE_ACTIONA reference to an action that loads a file into the component.
public static final String loadFileAction = "load-file"The name of the action that loads a file into the component.
public static Action LOADURL_ACTIONA reference to an action that loads a URL into the component.
public static final String loadURLAction = "load-URL"The name of the action that loads a URL into the component.
public static final String nextRowAction = "next-row"The name of the action that navigates to the next row in the
DataSet
the component is bound to.
public static Action PASTE_ACTIONA reference to an action that pastes text from the system clipboard into the component.
public static final String postDataAction = "post-data"The name of the action that posts text to the
DataSet
.
public static final String priorRowAction = "prior-row"The name of the action that navigates to the previous row in the
DataSet
the component is bound to.
public static Action REDO_ACTIONA reference to an action that redoes the previously undone action.
public static final String redoAction = "redo"The name of the action that redoes the previously undone action.
public static Action SAVEFILE_ACTIONA reference to an action that saves the content of the component to a file.
public static final String saveFileAction = "save-file"The name of the action that saves the content of the component to a file.
public static Action SELECTALL_ACTIONA reference to an action that selects all the text in the component.
public static final String selectAllAction = "select-all"The name of the action that selects all the text in the component.
public static Action UNDO_ACTIONA reference to an action that undoes the previous action.
public static final String undoAction = "undo"The name of an action that undoes the previous action.
public DBTextDataBinder()Constructs a
DBTextDataBinder
. Calls the null
constructor of its superclass.
public DBTextDataBinder(JTextComponent textComponent)Constructs a
DBTextDataBinder
and specifies the JTextComponent
it makes data-aware. Calls the null
constructor of its superclass.
textComponent
DBTextDataBinder
.
public String getColumnName() public void setColumnName(String columnName)Returns and sets the column name of the
DataSet
from which values are read and to which values are written.
dataSet
public String getColumnNameURL() public void setColumnNameURL(String columnNameURL)Returns the column name of the
DataSet
from which URLs are read and sets the column name of the DataSet
to which URLs are written.
dataSet
public DataSet getDataSet() public void setDataSet(DataSet dataSet)Returns the
DataSet
from which values are read and to which values are written.
columName
public Document getDocument() public void setDocument(Document document)Returns and sets the document.
public boolean isEnableClearAll() public void setEnableClearAll(boolean enableClearAll)Returns and sets whether the Clear All popup menu command appears.
enablePopupMenu
public boolean isEnableColorChange() public void setEnableColorChange(boolean enableColorChange)Returns and sets whether the foreground and background color setting menu commands appear on the popup menu. The default value is
true
.
enablePopupMenu
public boolean isEnableFileLoading() public void setEnableFileLoading(boolean enableFileLoading)Returns and sets whether the File Open popup menu command appears.
enablePopupMenu
public boolean isEnableFileSaving() public void setEnableFileSaving(boolean enableFileSaving)Returns and sets whether the File Save popup menu command appears.
enablePopupMenu
public boolean isEnableFontChange() public void setEnableFontChange(boolean enableFontChange)Returns and sets whether the font setting menu command appears on the popup menu. The default value is
true
.
enablePopupMenu
public boolean isEnablePopupMenu() public void setEnablePopupMenu(boolean enablePopup)Returns and sets whether a popup menu is enabled on the component. If
enablePopupMenu
is true
, a menu pops up when the user right-clicks on the component or presses Shift+F10.
public boolean isEnableUndoRedo() public void setEnableUndoRedo(boolean enableUndoRedo)Returns and sets whether the Undo and Redo menu commands appear on the popup menu.
enablePopupMenu
public boolean isEnableURLAutoCache() public void setEnableURLAutoCache(boolean enableURLCache)Returns and sets whether HTML pages fetched using hyperlinks are automatically inserted as new rows if they don't already exist in the
DataSet
(for example, the URL in the columnNameURL
column can't be found). This property is ignored unless the data binder is bound to a component, the columnNameURL
property is set, and the associated DataSet
allows new rows to be inserted. The default value is true
.
enablePopupMenu
public boolean isEnableURLLoading() public void setEnableURLLoading(boolean enableURLLoading)Returns and sets whether the Open URL menu command is available on the popup menu.
enablePopupMenu
public JTextComponent getJTextComponent() public void setJTextComponent(JTextComponent textComponent)Returns and sets the text component that
DBTextDataBinder
makes data-aware. The component must be one that extends JTextComponent
, such as JTextField
, JTextArea
, JTextPane
, or JEditorPane
.
public boolean isNextFocusOnEnter() public void setNextFocusOnEnter(boolean nextFocusOnEnter)Returns and sets whether pressing Enter in a
JTextField
automatically moves the focus to the next focusable field. The default value is true
.
public boolean isPostOnFocusLost() public void setPostOnFocusLost(boolean postOnFocusLost)Returns and sets whether the current text is entered in the
DataSet's
column when focus is lost on the text area. The default value is true
.
public boolean isPostOnRowPosted() public void setPostOnRowPosted(boolean postOnRowPosted)Returns and sets whether the current text should be put in the
DataSet's
column when the current row is posted. This occurs, for example, if the user presses a row navigation key while the text component has current focus. The default value is true
.
public boolean isTextModified() public void setTextModified(boolean textModified)Returns whether or not the text has been modified. Set to
true
on any change to the document model. Set to false
after the value has been saved to a DataSet
or file.
protected JPopupMenu createPopupMenu()Creates the popup menu displayed when the user right-clicks or presses Shift+F10 within the bound text component.
The contents of the menu vary according to the kind of text component and property settings as shown in the following table. Menu items are displayed in the vertical order in which they are listed below.
DBTextDataBinder
popup menus
Menu item | Description | Availability |
---|---|---|
Cut | Removes selected text to clipboard | editable = true |
Copy | Copies selected text to clipboard | always |
Paste | Pastes text from clipboard | editable = true |
ClearAll | Deletes all text | enableClearAll = true |
SelectAll | Selects all text | always |
Font... | Sets font of selected text | JdbTextPane , enableFontChange = true |
Foreground Color... | Sets foreground color of selected text | JdbTextPane , enableColorChange = true |
Background Color... | Sets background color of selected text | JdbTextPane , enableColorChange = true |
Open URL... | Loads HTML content from a URL | JdbEditorPane , enableURLLoading = true |
Open File... | Loads content from a file | JdbTextArea (text files only), JdbTextPane (text or ser file), JdbEditorPane (text, RTF, HTML, ser files), enableFileLoading = true |
Save File... | Saves contents to a file | JdbTextArea (text files only), JdbTextPane (text or ser file), JdbEditorPane (text, RTF, HTML, ser files), enableFileSaving = true |
Undo | Undoes the most recent change | enableUndoRedo = true |
Redo | Redoes the most recent change | enableUndoRedo = true |
Setting the enablePopupMenu
property to false
prevents the entire menu from appearing. To add your own menu items to the menu, override this method in a subclass to return a customized menu.
protected String expandDateYear(DBColumnAwareSupport columnAwareSupport)The
expandDateYear()
method returns a dataset column value with the year always expanded to a 4 digit year (the default is to show only 2 digits), unless an edit mask has been explicitly set on the column.
public void postText()Writes the current field data to the
DataSet
column if the dataSet
and columnName
properties are valid. The postText()
method displays an error dialog if the data is invalid.
public void postText2()Writes the current field data to the
DataSet
column if the dataSet
and columnName
properties are valid. The postText2()
method throws an exception if the data is invalid.
public void updateText()Synchronizes the text with the current
DataSet
value.