Package adams.gui.tools.jep
Class JepConsole
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- adams.gui.core.BasePanel
-
- adams.gui.tools.jep.JepConsole
-
- All Implemented Interfaces:
adams.core.logging.LoggingSupporter
,adams.core.TextSupporter
,adams.flow.sink.TextSupplier
,adams.gui.core.MenuBarProvider
,adams.gui.sendto.SendToActionSupporter
,ImageObserver
,MenuContainer
,Serializable
,Accessible
public class JepConsole extends adams.gui.core.BasePanel implements adams.gui.core.MenuBarProvider, adams.flow.sink.TextSupplier, adams.gui.sendto.SendToActionSupporter, adams.core.logging.LoggingSupporter
Console for editing and running Jep/Python scripts.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- 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 HashSet<ChangeListener>
m_ChangeListeners
the listeners for modification events.protected String
m_CurrentEncoding
the current file encoding.protected File
m_CurrentFile
the current file.protected adams.gui.chooser.TextFileChooser
m_FileChooser
for saving the content.protected boolean
m_IgnoreChanges
whether to ignore changes.protected String
m_LastFind
the last search string used.protected adams.core.logging.Logger
m_Logger
the logger in use.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_MenuItemExecutionRun
the execute 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 boolean
m_Modified
whether the content was modified.protected adams.gui.core.RecentFilesWithEncodingHandler<JMenu>
m_RecentFilesHandler
the recent files handler.protected boolean
m_Running
whether a script is running.protected JepSyntaxEditorPanel
m_TextPanel
the editor for the script.protected adams.gui.core.TitleGenerator
m_TitleGenerator
for generating the title.protected UndoManager
m_Undo
for managing undo/redo.static String
SESSION_FILE
the file to store the recent directories.-
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 JepConsole()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChangeListener(ChangeListener l)
Adds the given change listener to its internal list.protected void
addRecentItem()
Adds the current file/encoding as recent item.boolean
canCopy()
Checks whether text can be copied at the moment.boolean
canCut()
Checks whether text can be cut at the moment.boolean
canPaste()
Checks whether text can be pasted at the moment.boolean
canRedo()
Checks whether a redo action is available.boolean
canUndo()
Checks whether an undo action is available.boolean
checkForModified()
Returns whether we can proceed with the operation or not, depending on whether the user saved the content or discarded the changes.void
clear()
Removes all content.protected void
close()
Closes the dialog, if possible.void
copy()
Copies the currently selected text to the clipboard.void
cut()
Cuts the currently selected text and places it on the clipboard.void
find()
Initiates a search.void
findNext()
Finds the next occurrence.String
getContent()
Returns the content to display.String
getCurrentEncoding()
Returns the current file encoding.File
getCurrentFile()
Returns the currently loaded file.String
getCustomSupplyTextMenuItemCaption()
Returns the text for the menu item.adams.gui.core.ExtensionFileFilter
getCustomTextFileFilter()
Returns a custom file filter for the file chooser.protected adams.gui.chooser.TextFileChooser
getFileChooser()
Returns the file chooser and creates it if necessary.protected adams.gui.core.ExtensionFileFilter
getFileFilter()
Returns the filter for Python files.adams.core.logging.Logger
getLogger()
Returns the logger in use.JMenuBar
getMenuBar()
Creates a menu bar (singleton per panel object).Class[]
getSendToClasses()
Returns the classes that the supporter generates.Object
getSendToItem(Class[] cls)
Returns the object to send.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
isLoggingEnabled()
Returns whether logging is enabled.boolean
isModified()
Returns whether the content has been modified.boolean
isRunning()
Returns whether a script is currently running.protected void
notifyChangeListeners()
Sends an event to all change listeners.boolean
open()
Pops up dialog to open a file.boolean
open(File file)
Opens the specified file and loads/displays the content.boolean
open(File file, String encoding)
Opens the specified file and loads/displays the content.void
paste()
Pastes the text from the clipboard into the document.void
redo()
Performs a redo, if possible.void
removeChangeListener(ChangeListener l)
Removes the given change listener from its internal list.void
runScript()
Executes the current script.void
save()
Pops up dialog to save the content in a file if no filename provided, otherwise saves the .protected void
save(File file, String encoding)
Saves the content under the specified file.void
saveAs()
Pops up dialog to save the content in a file.void
selectAll()
Selects all the text.void
setContent(String value)
Sets the content to display.void
setModified(boolean value)
Sets the modified state.String
supplyText()
Supplies the text.void
undo()
Performs an undo, if possible.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 JepSyntaxEditorPanel m_TextPanel
the editor for the script.
-
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_MenuItemExecutionRun
protected JMenuItem m_MenuItemExecutionRun
the execute menu item.
-
m_TitleGenerator
protected adams.gui.core.TitleGenerator m_TitleGenerator
for generating the title.
-
m_RecentFilesHandler
protected adams.gui.core.RecentFilesWithEncodingHandler<JMenu> m_RecentFilesHandler
the recent files handler.
-
m_CurrentFile
protected File m_CurrentFile
the current file.
-
m_CurrentEncoding
protected String m_CurrentEncoding
the current file encoding.
-
m_Modified
protected boolean m_Modified
whether the content was modified.
-
m_IgnoreChanges
protected boolean m_IgnoreChanges
whether to ignore changes.
-
m_Undo
protected UndoManager m_Undo
for managing undo/redo.
-
m_LastFind
protected String m_LastFind
the last search string used.
-
m_ChangeListeners
protected HashSet<ChangeListener> m_ChangeListeners
the listeners for modification events.
-
m_FileChooser
protected transient adams.gui.chooser.TextFileChooser m_FileChooser
for saving the content.
-
m_Logger
protected adams.core.logging.Logger m_Logger
the logger in use.
-
m_Running
protected boolean m_Running
whether a script is running.
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classadams.gui.core.BasePanel
-
initGUI
protected void initGUI()
For initializing the GUI.- Overrides:
initGUI
in classadams.gui.core.BasePanel
-
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 interfaceadams.gui.core.MenuBarProvider
- 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.
-
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
-
getCurrentFile
public File getCurrentFile()
Returns the currently loaded file.- Returns:
- the current file, null if none loaded
-
getCurrentEncoding
public String getCurrentEncoding()
Returns the current file encoding.- Returns:
- the current encoding, null if no file loaded
-
setModified
public void setModified(boolean value)
Sets the modified state. If false, all edits are discarded and the last search string reset as well.- 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
-
checkForModified
public boolean checkForModified()
Returns whether we can proceed with the operation or not, depending on whether the user saved the content or discarded the changes.- Returns:
- true if safe to proceed
-
open
public boolean open()
Pops up dialog to open a file.- Returns:
- true if successfully opened
-
open
public boolean open(File file)
Opens the specified file and loads/displays the content.- Parameters:
file
- the file to load- Returns:
- true if successfully opened
-
open
public boolean open(File file, String encoding)
Opens the specified file and loads/displays the content.- Parameters:
file
- the file to loadencoding
- the encoding to use, use null or empty string for default UTF-8- Returns:
- true if successfully opened
-
save
public void save()
Pops up dialog to save the content in a file if no filename provided, otherwise saves the .
-
saveAs
public void saveAs()
Pops up dialog to save the content in a file.
-
save
protected void save(File file, String encoding)
Saves the content under the specified file.- Parameters:
file
- the file to save the content inencoding
- the file encoding to use
-
clear
public void clear()
Removes all content. Does not reset the undos.
-
close
protected void close()
Closes the dialog, if possible.
-
canUndo
public boolean canUndo()
Checks whether an undo action is available.- Returns:
- true if an undo action is available
-
undo
public void undo()
Performs an undo, if possible.
-
canRedo
public boolean canRedo()
Checks whether a redo action is available.- Returns:
- true if a redo action is available
-
redo
public void redo()
Performs a redo, if possible.
-
canCut
public boolean canCut()
Checks whether text can be cut at the moment.- Returns:
- true if text is available for cutting
-
cut
public void cut()
Cuts the currently selected text and places it on the clipboard.
-
canCopy
public boolean canCopy()
Checks whether text can be copied at the moment.- Returns:
- true if text is available for copying
-
copy
public void copy()
Copies the currently selected text to the clipboard.
-
canPaste
public boolean canPaste()
Checks whether text can be pasted at the moment.- Returns:
- true if text is available for pasting
-
paste
public void paste()
Pastes the text from the clipboard into the document.
-
selectAll
public void selectAll()
Selects all the text.
-
find
public void find()
Initiates a search.
-
findNext
public void findNext()
Finds the next occurrence.
-
isRunning
public boolean isRunning()
Returns whether a script is currently running.- Returns:
- true if running
-
runScript
public void runScript()
Executes the current script.
-
addChangeListener
public void addChangeListener(ChangeListener l)
Adds the given change listener to its internal list.- Parameters:
l
- the listener to add
-
removeChangeListener
public void removeChangeListener(ChangeListener l)
Removes the given change listener from its internal list.- Parameters:
l
- the listener to remove
-
notifyChangeListeners
protected void notifyChangeListeners()
Sends an event to all change listeners.
-
getCustomSupplyTextMenuItemCaption
public String getCustomSupplyTextMenuItemCaption()
Returns the text for the menu item.- Specified by:
getCustomSupplyTextMenuItemCaption
in interfaceadams.flow.sink.TextSupplier
- Returns:
- the menu item text, null for default
-
getCustomTextFileFilter
public adams.gui.core.ExtensionFileFilter getCustomTextFileFilter()
Returns a custom file filter for the file chooser.- Specified by:
getCustomTextFileFilter
in interfaceadams.flow.sink.TextSupplier
- Returns:
- the file filter, null if to use default one
-
supplyText
public String supplyText()
Supplies the text.- Specified by:
supplyText
in interfaceadams.flow.sink.TextSupplier
- Specified by:
supplyText
in interfaceadams.core.TextSupporter
- Returns:
- the text, null if none available
-
getSendToClasses
public Class[] getSendToClasses()
Returns the classes that the supporter generates.- Specified by:
getSendToClasses
in interfaceadams.gui.sendto.SendToActionSupporter
- Returns:
- the classes
-
hasSendToItem
public boolean hasSendToItem(Class[] cls)
Checks whether something to send is available.- Specified by:
hasSendToItem
in interfaceadams.gui.sendto.SendToActionSupporter
- 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 interfaceadams.gui.sendto.SendToActionSupporter
- Parameters:
cls
- the requested classes- Returns:
- the item to send
-
getFileFilter
protected adams.gui.core.ExtensionFileFilter getFileFilter()
Returns the filter for Python files.- Returns:
- the filter
-
getFileChooser
protected adams.gui.chooser.TextFileChooser getFileChooser()
Returns the file chooser and creates it if necessary.- Returns:
- the file chooser
-
getLogger
public adams.core.logging.Logger getLogger()
Returns the logger in use.- Specified by:
getLogger
in interfaceadams.core.logging.LoggingSupporter
- Returns:
- the logger
-
isLoggingEnabled
public boolean isLoggingEnabled()
Returns whether logging is enabled.- Specified by:
isLoggingEnabled
in interfaceadams.core.logging.LoggingSupporter
- Returns:
- true if at least
Level.INFO
-
-