Package ca.cgjennings.apps.arkham
Interface StrangeEonsEditor
-
- All Superinterfaces:
Commandable
- All Known Implementing Classes:
AbstractGameComponentEditor
,AbstractStrangeEonsEditor
,AbstractSupportEditor
,CardLayoutEditor
,CodeEditor
,DeckEditor
,DIYEditor
,MarkerEditor
,PropertyBundleEditor
public interface StrangeEonsEditor extends Commandable
This interface specifies the base level of functionality provided by every Strange Eons editor. You are not expected to implement this interface directly. Concrete editors are subclasses ofAbstractStrangeEonsEditor
, and in practice all editors are of one of two subclasses of this class: eitherAbstractGameComponentEditor
orAbstractSupportEditor
. Game component editors are used to editGameComponent
s, while support editors are used to edit non-component project files. The purpose of this interface is to describe the basic functionality that is common to both game component editors and support editors without getting distracted by the details of the base class used to provide the UI functionality.The methods and interfaces defined in this interface can be divided into the following categories: interface management (such as setting the title and icon, selecting or closing the window, and so on), the editing framework (which support file and content management and some standard commands like
Commands.SAVE
andCommands.PRINT
), and event services (such as registering listeners for various editor-specific events).- Since:
- 3.0
- Author:
- Chris Jennings
- See Also:
AbstractStrangeEonsEditor
,AbstractGameComponentEditor
,AbstractSupportEditor
,StrangeEonsAppWindow.addEditor(ca.cgjennings.apps.arkham.StrangeEonsEditor)
,StrangeEonsAppWindow.getEditors()
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
StrangeEonsEditor.EditorListener
A listener that is called when an editor becomes active, inactive, or is closed.static interface
StrangeEonsEditor.FieldPopulationListener
A listener to be called by a game component editor when it has updated its edit controls by copying from the current component.static interface
StrangeEonsEditor.HeartbeatListener
A heartbeat listener is notified by an editor once per heartbeat.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addEditorListener(StrangeEonsEditor.EditorListener el)
Adds a newStrangeEonsEditor.EditorListener
to this editor.boolean
canPerformCommand(AbstractCommand command)
Returnstrue
if the commandable wishes to handle the given command.void
clear()
Clears the contents of this component to a blank state, if the user gives permission.boolean
close()
Closes the editor window.void
export()
Exports the editor content as a different file format.java.io.File
getFile()
Returns the file used to save this component, ornull
if it is a new, unsaved file or the editor is not associated with any particular file.java.lang.String
getFileNameExtension()
Returns the standard file extension for the type of content displayed in this editor.java.lang.String
getFileTypeDescription()
Returns a description of the content displayed in this editor.javax.swing.Icon
getFrameIcon()
Returns the editor window icon.GameComponent
getGameComponent()
Returns the edited game component, ornull
if this editor is not editing a game component.javax.swing.JPopupMenu
getTabStripPopupMenu()
Returns a popup menu for this editor when the editor's tab is right clicked in the document tab strip.java.lang.String
getTitle()
Returns the title used to describe this editor.java.lang.String
getToolTipText()
Returns the tool tip text displayed for the editor's tab.boolean
hasUnsavedChanges()
Returnstrue
if this editor is editing a file that has unsaved changes.boolean
isAttached()
Returnstrue
if the editor is attached to the tab strip.boolean
isCommandApplicable(AbstractCommand command)
Returnstrue
if thecommand
can be performed by this commandable in its current state.void
performCommand(AbstractCommand command)
Performs the command.void
print()
Open the print dialog for this editor, allowing the user to print the edited component.void
removeEditorListener(StrangeEonsEditor.EditorListener el)
Removes a newStrangeEonsEditor.EditorListener
from this editor.void
save()
Saves this editor's content to its current save location.void
saveAs()
Saves this editor's content to a file selected by the user.void
select()
Selects this editor, making it the active editor.void
setAttached(boolean attach)
Attaches or detaches an editor from the tab strip.void
setFile(java.io.File newFile)
Sets the preferred file to use when saving the edited component.void
setFrameIcon(javax.swing.Icon icon)
Sets the preferred icon to use for this editor window.void
setTitle(java.lang.String title)
Sets the title of this document.void
setToolTipText(java.lang.String toolTipText)
Sets the tool tip text to display for the editor's tab.StrangeEonsEditor
spinOff()
Creates a duplicate of this editor.
-
-
-
Method Detail
-
setTitle
void setTitle(java.lang.String title)
Sets the title of this document. As it shown in the document's tab, the title text should be kept short. Thetitle
value may benull
, which is equivalent to an empty title.- Parameters:
title
- the text of the title to display
-
getTitle
java.lang.String getTitle()
Returns the title used to describe this editor. The returned value is nevernull
; if anull
title is set withsetTitle(java.lang.String)
then this method returns an empty string.- Returns:
- the current title, which is guaranteed not to be
null
-
setFrameIcon
void setFrameIcon(javax.swing.Icon icon)
Sets the preferred icon to use for this editor window. This icon may be used to represent the window in various parts of the application interface. Possible example uses include the following: the document tab, the editor's item in the Window menu, and the frame icon of the editor's detached window. Note, however, that there is no guarantee that the icon will be used, or how.- Parameters:
icon
- the preferred icon for the editor window- See Also:
getFrameIcon()
-
getFrameIcon
javax.swing.Icon getFrameIcon()
Returns the editor window icon.- Returns:
- the icon for the editor, or
null
if no icon is set - See Also:
#setFrameIcon()
-
setToolTipText
void setToolTipText(java.lang.String toolTipText)
Sets the tool tip text to display for the editor's tab.- Parameters:
toolTipText
- the text to display, ornull
to clear the tool tip
-
getToolTipText
java.lang.String getToolTipText()
Returns the tool tip text displayed for the editor's tab. If no tool tip has been explicitly set andgetFile()
returns a non-null
value, then a default tool tip will be returned.- Returns:
- the tool tip text to display, or
null
to clear the tool tip
-
select
void select()
Selects this editor, making it the active editor.- See Also:
StrangeEonsAppWindow.getActiveEditor()
-
close
boolean close()
Closes the editor window. If there are unsaved changes, the user will be prompted first and may cancel the close attempt.- Returns:
- returns
true
if the editor was actually closed, orfalse
if the user cancelled the attempt or closing was otherwise prevented
-
setAttached
void setAttached(boolean attach)
Attaches or detaches an editor from the tab strip. A detached editor is shown in its own window, independent of the main application window.- Parameters:
attach
- iftrue
, attach a detached editor; otherwise detach the editor from the tab strip
-
isAttached
boolean isAttached()
Returnstrue
if the editor is attached to the tab strip.- Returns:
true
if the editor is attached to the main application window
-
getTabStripPopupMenu
javax.swing.JPopupMenu getTabStripPopupMenu()
Returns a popup menu for this editor when the editor's tab is right clicked in the document tab strip. Because a new menu instance is created each time it is called, subclasses may call a super implementation to obtain a default menu and then modify it.- Returns:
- the popup menu that will be displayed when the user right clicks on the document's tab
-
getGameComponent
GameComponent getGameComponent()
Returns the edited game component, ornull
if this editor is not editing a game component.- Returns:
- the game component currently being edited by this editor, or
null
-
getFileNameExtension
java.lang.String getFileNameExtension()
Returns the standard file extension for the type of content displayed in this editor.- Returns:
- a file extension, such as
"txt"
- See Also:
getFileTypeDescription()
-
getFileTypeDescription
java.lang.String getFileTypeDescription()
Returns a description of the content displayed in this editor. For English descriptions, this should be plural as it is used to describe the file type in save dialogs.- Returns:
- a human-friendly description of the content associated with the editor, such as "Text Files"
- See Also:
getFileNameExtension()
-
setFile
void setFile(java.io.File newFile)
Sets the preferred file to use when saving the edited component.- Parameters:
newFile
- the file to use for Save operations- See Also:
getFile()
-
getFile
java.io.File getFile()
Returns the file used to save this component, ornull
if it is a new, unsaved file or the editor is not associated with any particular file.- Returns:
- the save file
- Since:
- 2.1a5
- See Also:
setFile(java.io.File)
-
hasUnsavedChanges
boolean hasUnsavedChanges()
Returnstrue
if this editor is editing a file that has unsaved changes. If the content cannot be saved or does not use files, then this method should returnfalse
.- Returns:
true
if the editor's content may be different from the saved version
-
canPerformCommand
boolean canPerformCommand(AbstractCommand command)
Returnstrue
if the commandable wishes to handle the given command. This method defines the set of commands that the commandable responds to. The commandable might not be able to act on the command at the current moment. For example, a commandable that responds to "Cut" could return true fromhandlesCommand
, but false fromCommandable.isCommandApplicable(ca.cgjennings.apps.arkham.commands.AbstractCommand)
if there is currently no selection to cut.- Specified by:
canPerformCommand
in interfaceCommandable
- Parameters:
command
- the command to be performed- Returns:
true
if this commandable wishes to handle the command (even if it cannot execute the command currently)
-
isCommandApplicable
boolean isCommandApplicable(AbstractCommand command)
Returnstrue
if thecommand
can be performed by this commandable in its current state. IfCommandable.canPerformCommand(ca.cgjennings.apps.arkham.commands.AbstractCommand)
would return false for this command, then this must also return false.- Specified by:
isCommandApplicable
in interfaceCommandable
- Parameters:
command
- the command to be performed- Returns:
true
if this commandable can currently perform the command
-
performCommand
void performCommand(AbstractCommand command)
Performs the command. IfCommandable.isCommandApplicable(ca.cgjennings.apps.arkham.commands.AbstractCommand)
would returnfalse
for this command, then this should do nothing.- Specified by:
performCommand
in interfaceCommandable
- Parameters:
command
- the command to perform
-
save
void save()
Saves this editor's content to its current save location. If it has not been saved previously, and the command is supported, the user will be prompted to select a file (seesaveAs()
).Note that an editor can support the SAVE_AS command without supporting the SAVE command, but not vice-versa.
- Throws:
java.lang.UnsupportedOperationException
- if the SAVE command is not supported- See Also:
canPerformCommand(ca.cgjennings.apps.arkham.commands.AbstractCommand)
-
saveAs
void saveAs()
Saves this editor's content to a file selected by the user. The user may cancel the operation. If the save is performed, then the selected file will become the new save path for the component.- Throws:
java.lang.UnsupportedOperationException
- if the SAVE_AS command is not supported- See Also:
canPerformCommand(ca.cgjennings.apps.arkham.commands.AbstractCommand)
-
clear
void clear()
Clears the contents of this component to a blank state, if the user gives permission.- Throws:
java.lang.UnsupportedOperationException
- if the CLEAR command is not supported- See Also:
canPerformCommand(ca.cgjennings.apps.arkham.commands.AbstractCommand)
-
export
void export()
Exports the editor content as a different file format. The procedure for exporting and the exact format(s) available will vary with the editor.- Throws:
java.lang.UnsupportedOperationException
- if the EXPORT command is not supported- See Also:
canPerformCommand(ca.cgjennings.apps.arkham.commands.AbstractCommand)
-
print
void print()
Open the print dialog for this editor, allowing the user to print the edited component. If this operation is not supported by this editor, anUnsupportedOperationException
is thrown.- Throws:
java.lang.UnsupportedOperationException
- if the PRINT command is not supported- See Also:
canPerformCommand(ca.cgjennings.apps.arkham.commands.AbstractCommand)
-
spinOff
StrangeEonsEditor spinOff()
Creates a duplicate of this editor. A new editor containing a copy of this editor's content will be created and added to the application. The new component is a deep copy, not a reference (changes to the new component do not affect the original, and vice-versa).- Returns:
- the new, duplicate editor
- Throws:
java.lang.UnsupportedOperationException
- if the SPIN_OFF command is not supported- See Also:
canPerformCommand(ca.cgjennings.apps.arkham.commands.AbstractCommand)
-
addEditorListener
void addEditorListener(StrangeEonsEditor.EditorListener el)
Adds a newStrangeEonsEditor.EditorListener
to this editor. An editor listener can also be added usingStrangeEonsAppWindow.addEditorListener(ca.cgjennings.apps.arkham.StrangeEonsEditor.EditorListener)
interface, in which case it will apply to all editors. If a listener is removed, it must be removed through the same interface as it was added (the application or a specific editor).- Parameters:
el
- the listener to add
-
removeEditorListener
void removeEditorListener(StrangeEonsEditor.EditorListener el)
Removes a newStrangeEonsEditor.EditorListener
from this editor.- Parameters:
el
- the listener to remove
-
-