borland Packages  Class Hierarchy  dbswing Package 

DBTextDataBinder component

java.lang.Object
   +----com.borland.dbswing.DBTextDataBinder

About the DBTextDataBinder component

Variables  Constructors  Properties  Methods  

Implements AccessListener, ColumnAware, DataChangeListener, DataSetAware, Designable, NavigationListener, FocusListener, KeyListener, MouseListener, PropertyChangeListener, Serializable, EventListener, DocumentListener, HyperlinkListener, UndoableEditListener

Note: This is a feature of JBuilder Professional and Enterprise.

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:

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:

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:

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

Example:

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");

DBTextDataBinder variables

Variables implemented in this class

DBTextDataBinder constructors

DBTextDataBinder properties

*Read-only properties **Write-only properties

Properties implemented in this class

Properties implemented in java.lang.Object

DBTextDataBinder methods

Methods implemented in this class

Methods implemented in java.lang.Object


DBTextDataBinder variables

BACKGROUNDCOLOR_ACTION

  public static Action BACKGROUNDCOLOR_ACTION
A reference to an action that displays a color dialog for changing the background color of the component.

backgroundColorDialogAction

  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.

cancelPostAction

  public static final String cancelPostAction = "cancel-post"
The name of the action that cancels a posting of the text to the DataSet.

CLEARALL_ACTION

  public static Action CLEARALL_ACTION
A reference to an action that clears the data displayed in the component.

clearAllAction

  public static final String clearAllAction = "clear-all"
The name of the action that clears the data displayed in the component.

COPY_ACTION

  public static Action COPY_ACTION
A reference to an action that copies the data displayed in the component to the system clipboard.

CUT_ACTION

  public static Action CUT_ACTION
A reference to an action that removes the data displayed in the component and places it in the system clipboard.

deleteRowAction

  public static final String deleteRowAction = "delete-row"
The name of the action that deletes the current row.

FONTDIALOG_ACTION

  public static Action FONTDIALOG_ACTION
A reference to an action that displays a font dialog box so the user can select a font for the component.

fontDialogAction

  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.

FOREGROUNDCOLOR_ACTION

  public static Action FOREGROUNDCOLOR_ACTION
A reference to an action that displays a color dialog box so the user can select a foreground color for the component.

foregroundColorDialogAction

  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.

insertRowAction

  public static final String insertRowAction = "insert-row"
The name of the action that inserts a row.

LOADFILE_ACTION

  public static Action LOADFILE_ACTION
A reference to an action that loads a file into the component.

loadFileAction

  public static final String loadFileAction = "load-file"
The name of the action that loads a file into the component.

LOADURL_ACTION

  public static Action LOADURL_ACTION
A reference to an action that loads a URL into the component.

loadURLAction

  public static final String loadURLAction = "load-URL"
The name of the action that loads a URL into the component.

nextRowAction

  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.

PASTE_ACTION

  public static Action PASTE_ACTION
A reference to an action that pastes text from the system clipboard into the component.

postDataAction

  public static final String postDataAction = "post-data"
The name of the action that posts text to the DataSet.

priorRowAction

  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.

REDO_ACTION

  public static Action REDO_ACTION
A reference to an action that redoes the previously undone action.

redoAction

  public static final String redoAction = "redo"
The name of the action that redoes the previously undone action.

SAVEFILE_ACTION

  public static Action SAVEFILE_ACTION
A reference to an action that saves the content of the component to a file.

saveFileAction

  public static final String saveFileAction = "save-file"
The name of the action that saves the content of the component to a file.

SELECTALL_ACTION

  public static Action SELECTALL_ACTION
A reference to an action that selects all the text in the component.

selectAllAction

  public static final String selectAllAction = "select-all"
The name of the action that selects all the text in the component.

UNDO_ACTION

  public static Action UNDO_ACTION
A reference to an action that undoes the previous action.

undoAction

  public static final String undoAction = "undo"
The name of an action that undoes the previous action.

DBTextDataBinder constructors

DBTextDataBinder()

  public DBTextDataBinder()
Constructs a DBTextDataBinder. Calls the null constructor of its superclass.

DBTextDataBinder(javax.swing.text.JTextComponent)

  public DBTextDataBinder(JTextComponent textComponent)
Constructs a DBTextDataBinder and specifies the JTextComponent it makes data-aware. Calls the null constructor of its superclass.

Parameters:

textComponent
The component you are making data-aware with DBTextDataBinder.

DBTextDataBinder properties

columnName

 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.

See also: dataSet

columnNameURL

 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.

See also: dataSet

dataSet

 public DataSet getDataSet()
 public void setDataSet(DataSet dataSet)
Returns the DataSet from which values are read and to which values are written.

See also: columName

document

 public Document getDocument()
 public void setDocument(Document document)
Returns and sets the document.

enableClearAll

 public boolean isEnableClearAll()
 public void setEnableClearAll(boolean enableClearAll)
Returns and sets whether the Clear All popup menu command appears.

See also: enablePopupMenu

enableColorChange

 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.

See also: enablePopupMenu

enableFileLoading

 public boolean isEnableFileLoading()
 public void setEnableFileLoading(boolean enableFileLoading)
Returns and sets whether the File Open popup menu command appears.

See also: enablePopupMenu

enableFileSaving

 public boolean isEnableFileSaving()
 public void setEnableFileSaving(boolean enableFileSaving)
Returns and sets whether the File Save popup menu command appears.

See also: enablePopupMenu

enableFontChange

 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.

See also: enablePopupMenu

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.

enableUndoRedo

 public boolean isEnableUndoRedo()
 public void setEnableUndoRedo(boolean enableUndoRedo)
Returns and sets whether the Undo and Redo menu commands appear on the popup menu.

See also: enablePopupMenu

enableURLAutoCache

 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.

See also: enablePopupMenu

enableURLLoading

 public boolean isEnableURLLoading()
 public void setEnableURLLoading(boolean enableURLLoading)
Returns and sets whether the Open URL menu command is available on the popup menu.

See also: enablePopupMenu

JTextComponent

 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.

nextFocusOnEnter

 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.

postOnFocusLost

 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.

postOnRowPosted

 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.

textModified

 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.

DBTextDataBinder methods

createPopupMenu()

  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 textJdbTextPane, enableColorChange = true
Background Color...Sets background color of selected textJdbTextPane, 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.

expandDateYear(com.borland.dbswing.DBColumnAwareSupport)

  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.

postText()

  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.

postText2()

  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.

updateText()

  public void updateText()
Synchronizes the text with the current DataSet value.