Package org.basex.gui.text
Class TextPanel
-
- All Implemented Interfaces:
ComponentListener
,KeyListener
,MouseListener
,MouseMotionListener
,MouseWheelListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
- Direct Known Subclasses:
EditorArea
public class TextPanel extends BaseXPanel
Renders and provides edit capabilities for text.- Author:
- BaseX Team 2005-24, BSD License, Christian Gruen
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TextPanel.Action
Editor action.-
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 TextEditor
editor
Text editor.History
hist
Undo history.protected SearchBar
search
Search bar.-
Fields inherited from class org.basex.gui.layout.BaseXPanel
gui
-
Fields inherited from class org.basex.gui.layout.BaseXBack
SEPARATOR_SIZE
-
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(BaseXWindow win, boolean editable)
Default constructor.TextPanel(BaseXWindow win, String text, boolean editable)
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bracket()
Jumps to a matching bracket.int[]
caretPos()
Returns the line and column of the current caret position.void
comment()
Adds or removes a comment.void
componentResized(ComponentEvent e)
void
error(int pos)
Sets the error marker.void
format()
Formats the selected text.SearchBar
getSearch()
Returns the search bar.byte[]
getText()
Returns the output text.boolean
isEditable()
Returns the editable flag.protected void
jump(SearchBar.SearchDir dir, boolean select)
Jumps to the current, next or previous search string.void
keyPressed(KeyEvent e)
void
keyTyped(KeyEvent e)
void
mouseDragged(MouseEvent e)
void
mouseEntered(MouseEvent e)
void
mouseExited(MouseEvent e)
void
mouseMoved(MouseEvent e)
void
mousePressed(MouseEvent e)
void
mouseReleased(MouseEvent e)
void
mouseWheelMoved(MouseWheelEvent e)
void
refreshLayout(Font f)
Refreshes the layout.protected void
release(TextPanel.Action action)
Releases a key or mouse.void
resetError()
Removes the error marker.String
searchString()
Returns a currently marked string if it does not extend over more than one line.boolean
selected()
Tests if text has been selected.void
setCaret(int pos)
Sets the caret to the specified position.void
setEnabled(boolean enabled)
void
setFont(Font f)
void
setLinkListener(LinkListener ll)
Installs a link listener.void
setSyntax(org.basex.gui.text.Syntax syntax)
Sets a syntax highlighter.protected void
setSyntax(IO file, boolean opened)
Sets a syntax highlighter, based on the file format.void
setText(byte[] t)
Sets the output text.void
setText(byte[] text, int size)
Sets the output text.void
setText(String t)
Sets the output text.void
sort()
Sorts text.void
toCase(TextEditor.Case cs)
Case conversion.-
Methods inherited from class org.basex.gui.layout.BaseXPanel
componentHidden, componentMoved, componentShown, keyReleased, mouseClicked
-
Methods inherited from class org.basex.gui.layout.BaseXBack
border, border, layout, paintComponent
-
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, 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, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, 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
-
editor
public final TextEditor editor
Text editor.
-
hist
public final History hist
Undo history.
-
search
protected SearchBar search
Search bar.
-
-
Constructor Detail
-
TextPanel
public TextPanel(BaseXWindow win, boolean editable)
Default constructor.- Parameters:
win
- parent windoweditable
- editable flag
-
TextPanel
public TextPanel(BaseXWindow win, String text, boolean editable)
Default constructor.- Parameters:
win
- parent windowtext
- initial texteditable
- editable flag
-
-
Method Detail
-
setText
public void setText(String t)
Sets the output text.- Parameters:
t
- output text
-
setText
public void setText(byte[] t)
Sets the output text.- Parameters:
t
- output text
-
searchString
public final String searchString()
Returns a currently marked string if it does not extend over more than one line.- Returns:
- search string
-
caretPos
public final int[] caretPos()
Returns the line and column of the current caret position.- Returns:
- line/column
-
setText
public final void setText(byte[] text, int size)
Sets the output text.- Parameters:
text
- output textsize
- text size
-
setSyntax
protected final void setSyntax(IO file, boolean opened)
Sets a syntax highlighter, based on the file format.- Parameters:
file
- file referenceopened
- indicates if file was opened from disk
-
isEditable
public final boolean isEditable()
Returns the editable flag.- Returns:
- boolean result
-
setSyntax
public final void setSyntax(org.basex.gui.text.Syntax syntax)
Sets a syntax highlighter.- Parameters:
syntax
- syntax reference
-
setCaret
public final void setCaret(int pos)
Sets the caret to the specified position. A text selection will be removed.- Parameters:
pos
- caret position
-
getText
public final byte[] getText()
Returns the output text.- Returns:
- output text
-
selected
public final boolean selected()
Tests if text has been selected.- Returns:
- result of check
-
setFont
public final void setFont(Font f)
- Overrides:
setFont
in classJComponent
-
resetError
public final void resetError()
Removes the error marker.
-
error
public final void error(int pos)
Sets the error marker.- Parameters:
pos
- start of optional error mark
-
comment
public final void comment()
Adds or removes a comment.
-
toCase
public final void toCase(TextEditor.Case cs)
Case conversion.- Parameters:
cs
- case type
-
bracket
public final void bracket()
Jumps to a matching bracket.
-
sort
public final void sort()
Sorts text.
-
format
public final void format()
Formats the selected text.
-
setEnabled
public final void setEnabled(boolean enabled)
- Overrides:
setEnabled
in classJComponent
-
setLinkListener
public final void setLinkListener(LinkListener ll)
Installs a link listener.- Parameters:
ll
- link listener
-
getSearch
public final SearchBar getSearch()
Returns the search bar.- Returns:
- search bar
-
jump
protected final void jump(SearchBar.SearchDir dir, boolean select)
Jumps to the current, next or previous search string.- Parameters:
dir
- search directionselect
- select hit
-
mouseEntered
public final void mouseEntered(MouseEvent e)
- Specified by:
mouseEntered
in interfaceMouseListener
- Overrides:
mouseEntered
in classBaseXPanel
-
mouseExited
public final void mouseExited(MouseEvent e)
- Specified by:
mouseExited
in interfaceMouseListener
- Overrides:
mouseExited
in classBaseXPanel
-
mouseMoved
public final void mouseMoved(MouseEvent e)
- Specified by:
mouseMoved
in interfaceMouseMotionListener
- Overrides:
mouseMoved
in classBaseXPanel
-
mouseReleased
public void mouseReleased(MouseEvent e)
- Specified by:
mouseReleased
in interfaceMouseListener
- Overrides:
mouseReleased
in classBaseXPanel
-
mouseDragged
public final void mouseDragged(MouseEvent e)
- Specified by:
mouseDragged
in interfaceMouseMotionListener
- Overrides:
mouseDragged
in classBaseXPanel
-
mousePressed
public final void mousePressed(MouseEvent e)
- Specified by:
mousePressed
in interfaceMouseListener
- Overrides:
mousePressed
in classBaseXPanel
-
keyPressed
public void keyPressed(KeyEvent e)
- Specified by:
keyPressed
in interfaceKeyListener
- Overrides:
keyPressed
in classBaseXPanel
-
keyTyped
public void keyTyped(KeyEvent e)
- Specified by:
keyTyped
in interfaceKeyListener
- Overrides:
keyTyped
in classBaseXPanel
-
release
protected void release(TextPanel.Action action)
Releases a key or mouse. Can be overwritten to react on events.- Parameters:
action
- action
-
refreshLayout
public final void refreshLayout(Font f)
Refreshes the layout.- Parameters:
f
- used font
-
mouseWheelMoved
public final void mouseWheelMoved(MouseWheelEvent e)
- Specified by:
mouseWheelMoved
in interfaceMouseWheelListener
- Overrides:
mouseWheelMoved
in classBaseXPanel
-
componentResized
public final void componentResized(ComponentEvent e)
- Specified by:
componentResized
in interfaceComponentListener
- Overrides:
componentResized
in classBaseXPanel
-
-