Package mars.venus.editor
Class EditTab
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JTabbedPane
mars.venus.DynamicTabbedPane
mars.venus.editor.EditTab
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
,SwingConstants
The "Edit" tab in the main tabbed pane, which is itself a tabbed pane.
Each of its tabs represents an open file.
- Author:
- Pete Sanderson
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JTabbedPane
JTabbedPane.AccessibleJTabbedPane, JTabbedPane.ModelListener
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 inherited from class javax.swing.JTabbedPane
changeEvent, changeListener, model, SCROLL_TAB_LAYOUT, tabPlacement, WRAP_TAB_LAYOUT
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
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Carries out all necessary operations to implement the Close All operation from the File menu.boolean
Carries out all necessary operations to implement the Close operation from the File menu.boolean
closeFile
(FileEditorTab tab) Carries out all necessary operations to implement the Close operation from the File menu.Get the currently selected editor tab.getCurrentEditorTab
(File file) If the given file is open, make it the current tab.getEditorTab
(File file) Get the editor tab corresponding to the given file, if the file is open.Get the list of currently open editor tabs by iterating through the component list.void
newFile()
Carries out all necessary operations to implement the New operation from the File menu.boolean
Open the specified file in a new editor tab, switching focus to that tab.Launch a file chooser for the user to select one or more files, attempting to open them in new editor tabs afterward.Open the specified files in new editor tabs, switching focus to the first newly opened tab.void
removeTabAt
(int index) Attempts to remove the tab atindex
.boolean
Check whether file has unsaved edits and, if so, check with user about saving them.boolean
Saves all files currently open in the editor.Pops up a dialog box to do the "Save As" operation.boolean
Saves file under existing name.void
Select the specified file editor tab to be the current tab.void
showOpenFileErrorDialog
(List<File> unopenedFiles) Display an error dialog to the user indicating that one or more files could not be opened.void
Update the title on a given tab and possibly the title of the window, as well as the GUI's menu state (i.e. which actions are enabled) if applicable.Methods inherited from class mars.venus.DynamicTabbedPane
hasHorizontalTabPlacement, insertTab, paint, updateUI
Methods inherited from class javax.swing.JTabbedPane
add, add, add, add, add, addChangeListener, addTab, addTab, addTab, createChangeListener, fireStateChanged, getAccessibleContext, getBackgroundAt, getBoundsAt, getChangeListeners, getComponentAt, getDisabledIconAt, getDisplayedMnemonicIndexAt, getForegroundAt, getIconAt, getMnemonicAt, getModel, getSelectedComponent, getSelectedIndex, getTabComponentAt, getTabCount, getTabLayoutPolicy, getTabPlacement, getTabRunCount, getTitleAt, getToolTipText, getToolTipTextAt, getUI, getUIClassID, indexAtLocation, indexOfComponent, indexOfTab, indexOfTab, indexOfTabComponent, isEnabledAt, paramString, remove, remove, removeAll, removeChangeListener, setBackgroundAt, setComponentAt, setDisabledIconAt, setDisplayedMnemonicIndexAt, setEnabledAt, setForegroundAt, setIconAt, setMnemonicAt, setModel, setSelectedComponent, setSelectedIndex, setTabComponentAt, setTabLayoutPolicy, setTabPlacement, setTitleAt, setToolTipTextAt, setUI
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, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, 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, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
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, 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
-
Constructor Details
-
EditTab
Create and initialize the Edit tab with no open files.- Parameters:
gui
- The parent GUI instance.editor
- The editor instance, which will be used to manage the text editors.
-
-
Method Details
-
getCurrentEditorTab
Get the currently selected editor tab.- Returns:
- The current editor tab, or null if no files are open.
-
setCurrentEditorTab
Select the specified file editor tab to be the current tab.- Parameters:
tab
- The tab to become current.
-
getEditorTab
Get the editor tab corresponding to the given file, if the file is open.- Parameters:
file
- File object for the desired tab.- Returns:
- The tab for the given file, or null if no such tab was found.
-
getCurrentEditorTab
If the given file is open, make it the current tab. If not opened, open it in a new tab and make it the current tab. If file is unable to be opened, leave current tab as is.- Parameters:
file
- File object for the desired tab.- Returns:
- The tab for the given file, or null if file is unable to be opened.
-
getEditorTabs
Get the list of currently open editor tabs by iterating through the component list.- Returns:
- The list of editor tabs.
-
newFile
public void newFile()Carries out all necessary operations to implement the New operation from the File menu. -
openFiles
Launch a file chooser for the user to select one or more files, attempting to open them in new editor tabs afterward.- Returns:
- The list of files which could not be opened due to an error. (Can be empty.)
-
openFile
Open the specified file in a new editor tab, switching focus to that tab.- Returns:
- False if the file could not be opened due to an error, true otherwise.
-
openFiles
Open the specified files in new editor tabs, switching focus to the first newly opened tab. If any files cannot be opened, an error dialog will be displayed to the user indicating which files failed to open.- Returns:
- The list of files which could not be opened due to an error. (Can be empty.)
-
showOpenFileErrorDialog
Display an error dialog to the user indicating that one or more files could not be opened.- Parameters:
unopenedFiles
- The list of files which could not be opened. (Should not be empty.) Usually obtained from a call toopenFiles
.
-
removeTabAt
public void removeTabAt(int index) Attempts to remove the tab atindex
. If the tab has unsaved changes, the user will be prompted to save them. If they select cancel, the tab will not be removed. Otherwise, the tab is removed. After a successful removal,VenusUI.saveWorkspaceState()
is invoked.- Overrides:
removeTabAt
in classJTabbedPane
- Parameters:
index
- The index of the tab to be removed.- Throws:
IndexOutOfBoundsException
- Thrown if the index is out of range (index
< 0 orindex
≥JTabbedPane.getTabCount()
).
-
closeCurrentFile
public boolean closeCurrentFile()Carries out all necessary operations to implement the Close operation from the File menu. May return false, for instance when file has unsaved changes and user selects Cancel from the warning dialog.- Returns:
- true if file was closed, false otherwise.
-
closeFile
Carries out all necessary operations to implement the Close operation from the File menu. May return false, for instance when file has unsaved changes and user selects Cancel from the warning dialog.- Parameters:
tab
- The tab for the file to close.- Returns:
- true if file was closed, false otherwise.
-
closeAllFiles
public boolean closeAllFiles()Carries out all necessary operations to implement the Close All operation from the File menu.- Returns:
- true if files closed, false otherwise.
-
saveCurrentFile
public boolean saveCurrentFile()Saves file under existing name. If no name, will invoke Save As.- Returns:
- true if the file was actually saved.
-
saveAsCurrentFile
Pops up a dialog box to do the "Save As" operation. The user will be asked to confirm before any file is overwritten.- Returns:
- The file object if the file was actually saved, null if canceled.
-
saveAllFiles
public boolean saveAllFiles()Saves all files currently open in the editor.- Returns:
- true if operation succeeded, false otherwise.
-
updateTitleAndMenuState
Update the title on a given tab and possibly the title of the window, as well as the GUI's menu state (i.e. which actions are enabled) if applicable. Should be invoked any time the tab's state might change in any way.- Parameters:
tab
- The tab to update, or null if there are no tabs remaining.
-
resolveUnsavedChanges
Check whether file has unsaved edits and, if so, check with user about saving them.- Returns:
- true if no unsaved edits or if user chooses to save them or not; false if there are unsaved edits and user cancels the operation.
-