Package adams.gui.dialog
Class TextPanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- adams.gui.core.BasePanel
-
- adams.gui.dialog.TextPanel
-
- All Implemented Interfaces:
MenuBarProvider
,SendToActionSupporter
,ImageObserver
,MenuContainer
,Serializable
,Accessible
public class TextPanel extends BasePanel implements MenuBarProvider, SendToActionSupporter
A simple text editor panel. By default, files cannot be loaded. This has to be allowed explicitly viasetCanOpenFiles(boolean)
.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
setCanOpenFiles(boolean)
, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
m_CanOpenFiles
whether the editor is allowed to open files as well.protected JLabel
m_LabelInfo
the label with the option info text.protected JMenuBar
m_MenuBar
the menu bar.protected JMenu
m_MenuFileLoadRecent
the "load recent" submenu.protected JMenuItem
m_MenuItemEditCopy
the copy menu item.protected JMenuItem
m_MenuItemEditCut
the cut menu item.protected JMenuItem
m_MenuItemEditFind
the find menu item.protected JMenuItem
m_MenuItemEditFindNext
the find next menu item.protected JMenuItem
m_MenuItemEditPaste
the paste menu item.protected JMenuItem
m_MenuItemEditRedo
the redo menu item.protected JMenuItem
m_MenuItemEditSelectAll
the select all menu item.protected JMenuItem
m_MenuItemEditUndo
the undo menu item.protected JMenuItem
m_MenuItemFileNew
the new menu item.protected JMenuItem
m_MenuItemFileOpen
the open menu item.protected JMenuItem
m_MenuItemFileSave
the save menu item.protected JMenuItem
m_MenuItemFileSaveAs
the save as menu item.protected JMenuItem
m_MenuItemViewFont
the select font menu item.protected JCheckBoxMenuItem
m_MenuItemViewLineWrap
the line wrap menu item.protected JMenuItem
m_MenuItemViewTabSize
the tab size menu item.protected JPanel
m_PanelInfo
the panel with optional info text.protected RecentFilesWithEncodingHandler<JMenu>
m_RecentFilesHandler
the recent files handler.protected TextEditorPanel
m_TextPanel
for displaying the text.protected TitleGenerator
m_TitleGenerator
for generating the title.static String
SESSION_FILE
the file to store the recent directories.-
Fields inherited from class adams.gui.core.BasePanel
m_FileChooser
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
Constructor Summary
Constructors Constructor Description TextPanel()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addRecentItem()
Adds the current file/encoding as recent item.protected void
close()
Closes the dialog, if possible.boolean
getCanOpenFiles()
Returns whether the editor can open files.int
getCaretPosition()
Returns the current position of the cursor.String
getContent()
Returns the content to display.String
getInfoText()
Returns the current info text.boolean
getLineWrap()
Returns whether line wrap is enabled.JMenuBar
getMenuBar()
Creates a menu bar (singleton per panel object).PopupMenuCustomizer<TextEditorPanel>
getPopupMenuCustomizer()
Returns the customizer in use.Class[]
getSendToClasses()
Returns the classes that the supporter generates.Object
getSendToItem(Class[] cls)
Returns the object to send.int
getTabSize()
Returns the tab size, i.e., the number of maximum width characters.Font
getTextFont()
Returns the font currently in use by the text area.String
getTitle()
Returns the base title in use by the title generator.TitleGenerator
getTitleGenerator()
Returns the title generator in use.boolean
getUpdateParentTitle()
Returns whether to update the parent's title.boolean
hasSendToItem(Class[] cls)
Checks whether something to send is available.protected void
initGUI()
For initializing the GUI.protected void
initialize()
Initializes the members.boolean
isEditable()
Returns whether the text area is editable or not.boolean
isModified()
Returns whether the content has been modified.void
open(File file)
Opens the specified file using UTF-8 and loads/displays the content.void
open(File file, String encoding)
Opens the specified file and loads/displays the content.void
printText()
Pops up a print dialog.void
setCanOpenFiles(boolean value)
Sets whether the editor can open files.void
setCaretPosition(int value)
Sets the position of the cursor.void
setContent(String value)
Sets the content to display.void
setEditable(boolean value)
Sets whether the text area is editable or not.void
setInfoText(String value)
Sets the info text to display.void
setLineWrap(boolean value)
Enables/disables line wrap.void
setModified(boolean value)
Sets the modified state.void
setPopupMenuCustomizer(PopupMenuCustomizer<TextEditorPanel> value)
Sets the customizer to use.void
setTabSize(int value)
Sets the tab size, i.e., the number of maximum width characters.void
setTextFont(Font value)
Sets the font of the text area.void
setTitle(String value)
Sets the base title to use for the title generator.void
setUpdateParentTitle(boolean value)
Sets whether to update the parent's title.protected void
update()
Updates title and menu items.protected void
updateMenu()
Updates the state of the menu items.protected void
updateTitle()
Updates the title of the dialog.-
Methods inherited from class adams.gui.core.BasePanel
afterHide, afterShow, beforeHide, beforeShow, closeParent, finishInit, getParentChild, getParentDialog, getParentFrame, getParentInternalFrame, getParentTitle, initFileChooser, main, printErrorMessage, printException, saveComponent, setEnabledCascade, setEnabledCascade, setParentTitle, setVisible
-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, 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, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
SESSION_FILE
public static final String SESSION_FILE
the file to store the recent directories.- See Also:
- Constant Field Values
-
m_MenuBar
protected JMenuBar m_MenuBar
the menu bar.
-
m_TextPanel
protected TextEditorPanel m_TextPanel
for displaying the text.
-
m_PanelInfo
protected JPanel m_PanelInfo
the panel with optional info text.
-
m_LabelInfo
protected JLabel m_LabelInfo
the label with the option info text.
-
m_MenuItemFileNew
protected JMenuItem m_MenuItemFileNew
the new menu item.
-
m_MenuItemFileOpen
protected JMenuItem m_MenuItemFileOpen
the open menu item.
-
m_MenuFileLoadRecent
protected JMenu m_MenuFileLoadRecent
the "load recent" submenu.
-
m_MenuItemFileSave
protected JMenuItem m_MenuItemFileSave
the save menu item.
-
m_MenuItemFileSaveAs
protected JMenuItem m_MenuItemFileSaveAs
the save as menu item.
-
m_MenuItemEditUndo
protected JMenuItem m_MenuItemEditUndo
the undo menu item.
-
m_MenuItemEditRedo
protected JMenuItem m_MenuItemEditRedo
the redo menu item.
-
m_MenuItemEditCut
protected JMenuItem m_MenuItemEditCut
the cut menu item.
-
m_MenuItemEditCopy
protected JMenuItem m_MenuItemEditCopy
the copy menu item.
-
m_MenuItemEditPaste
protected JMenuItem m_MenuItemEditPaste
the paste menu item.
-
m_MenuItemEditSelectAll
protected JMenuItem m_MenuItemEditSelectAll
the select all menu item.
-
m_MenuItemEditFind
protected JMenuItem m_MenuItemEditFind
the find menu item.
-
m_MenuItemEditFindNext
protected JMenuItem m_MenuItemEditFindNext
the find next menu item.
-
m_MenuItemViewTabSize
protected JMenuItem m_MenuItemViewTabSize
the tab size menu item.
-
m_MenuItemViewFont
protected JMenuItem m_MenuItemViewFont
the select font menu item.
-
m_MenuItemViewLineWrap
protected JCheckBoxMenuItem m_MenuItemViewLineWrap
the line wrap menu item.
-
m_RecentFilesHandler
protected RecentFilesWithEncodingHandler<JMenu> m_RecentFilesHandler
the recent files handler.
-
m_CanOpenFiles
protected boolean m_CanOpenFiles
whether the editor is allowed to open files as well.
-
m_TitleGenerator
protected TitleGenerator m_TitleGenerator
for generating the title.
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classBasePanel
-
setCanOpenFiles
public void setCanOpenFiles(boolean value)
Sets whether the editor can open files.- Parameters:
value
- if true then the editor can open files as well
-
getCanOpenFiles
public boolean getCanOpenFiles()
Returns whether the editor can open files.- Returns:
- true if the editor can open files
-
setTitle
public void setTitle(String value)
Sets the base title to use for the title generator.- Parameters:
value
- the title to use- See Also:
m_TitleGenerator
-
getTitle
public String getTitle()
Returns the base title in use by the title generator.- Returns:
- the title in use
- See Also:
m_TitleGenerator
-
getTitleGenerator
public TitleGenerator getTitleGenerator()
Returns the title generator in use.- Returns:
- the generator
-
setPopupMenuCustomizer
public void setPopupMenuCustomizer(PopupMenuCustomizer<TextEditorPanel> value)
Sets the customizer to use.- Parameters:
value
- the customizer, null to unset
-
getPopupMenuCustomizer
public PopupMenuCustomizer<TextEditorPanel> getPopupMenuCustomizer()
Returns the customizer in use.- Returns:
- the customizer, null if none set
-
setModified
public void setModified(boolean value)
Sets the modified state.- Parameters:
value
- if true then the content is flagged as modified
-
isModified
public boolean isModified()
Returns whether the content has been modified.- Returns:
- true if the content was modified
-
setContent
public void setContent(String value)
Sets the content to display. Resets the modified state.- Parameters:
value
- the text
-
getContent
public String getContent()
Returns the content to display.- Returns:
- the text
-
setInfoText
public void setInfoText(String value)
Sets the info text to display.- Parameters:
value
- the text, null or empty string to hide
-
getInfoText
public String getInfoText()
Returns the current info text.- Returns:
- the text
-
setEditable
public void setEditable(boolean value)
Sets whether the text area is editable or not.- Parameters:
value
- if true then the text will be editable
-
isEditable
public boolean isEditable()
Returns whether the text area is editable or not.- Returns:
- true if the text is editable
-
setTextFont
public void setTextFont(Font value)
Sets the font of the text area.- Parameters:
value
- the font to use
-
getTextFont
public Font getTextFont()
Returns the font currently in use by the text area.- Returns:
- the font in use
-
setTabSize
public void setTabSize(int value)
Sets the tab size, i.e., the number of maximum width characters.- Parameters:
value
- the number of maximum width chars
-
getTabSize
public int getTabSize()
Returns the tab size, i.e., the number of maximum width characters.- Returns:
- the number of maximum width chars
-
setLineWrap
public void setLineWrap(boolean value)
Enables/disables line wrap.- Parameters:
value
- if true line wrap gets enabled
-
getLineWrap
public boolean getLineWrap()
Returns whether line wrap is enabled.- Returns:
- true if line wrap enabled
-
setCaretPosition
public void setCaretPosition(int value)
Sets the position of the cursor.- Parameters:
value
- the position
-
getCaretPosition
public int getCaretPosition()
Returns the current position of the cursor.- Returns:
- the cursor position
-
addRecentItem
protected void addRecentItem()
Adds the current file/encoding as recent item.
-
getMenuBar
public JMenuBar getMenuBar()
Creates a menu bar (singleton per panel object). Can be used in frames.- Specified by:
getMenuBar
in interfaceMenuBarProvider
- Returns:
- the menu bar
-
update
protected void update()
Updates title and menu items.
-
updateTitle
protected void updateTitle()
Updates the title of the dialog.
-
updateMenu
protected void updateMenu()
Updates the state of the menu items.
-
close
protected void close()
Closes the dialog, if possible.
-
open
public void open(File file)
Opens the specified file using UTF-8 and loads/displays the content.- Parameters:
file
- the file to load- See Also:
getCanOpenFiles()
-
open
public void open(File file, String encoding)
Opens the specified file and loads/displays the content.- Parameters:
file
- the file to loadencoding
- the encoding to use, null for default UTF-8- See Also:
getCanOpenFiles()
-
getSendToClasses
public Class[] getSendToClasses()
Returns the classes that the supporter generates.- Specified by:
getSendToClasses
in interfaceSendToActionSupporter
- Returns:
- the classes
-
hasSendToItem
public boolean hasSendToItem(Class[] cls)
Checks whether something to send is available.- Specified by:
hasSendToItem
in interfaceSendToActionSupporter
- Parameters:
cls
- the requested classes- Returns:
- true if an object is available for sending
-
getSendToItem
public Object getSendToItem(Class[] cls)
Returns the object to send.- Specified by:
getSendToItem
in interfaceSendToActionSupporter
- Parameters:
cls
- the requested classes- Returns:
- the item to send
-
setUpdateParentTitle
public void setUpdateParentTitle(boolean value)
Sets whether to update the parent's title.- Parameters:
value
- if true the parent's title will get updated
-
getUpdateParentTitle
public boolean getUpdateParentTitle()
Returns whether to update the parent's title.- Returns:
- true if to update the parent's title
-
printText
public void printText()
Pops up a print dialog.
-
-