public class TApplication
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Class and Description |
---|---|
static class |
TApplication.BackendType
Two backend types are available.
|
Constructor and Description |
---|
TApplication(Backend backend)
Public constructor.
|
TApplication(java.io.InputStream input,
java.io.OutputStream output)
Public constructor.
|
TApplication(java.io.InputStream input,
java.io.Reader reader,
java.io.PrintWriter writer)
Public constructor.
|
TApplication(java.io.InputStream input,
java.io.Reader reader,
java.io.PrintWriter writer,
boolean setRawMode)
Public constructor.
|
TApplication(TApplication.BackendType backendType)
Public constructor.
|
TApplication(TApplication.BackendType backendType,
int windowWidth,
int windowHeight,
int fontSize)
Public constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
activateWindow(TWindow window)
Activate a window: bring it to the top and have it receive events.
|
TMenu |
addEditMenu()
Convenience function to add a default "Edit" menu.
|
TMenu |
addFileMenu()
Convenience function to add a default "File" menu.
|
TMenu |
addHelpMenu()
Convenience function to add a default "Help" menu.
|
TMenu |
addMenu(java.lang.String title)
Convenience function to add a top-level menu.
|
void |
addMenu(TMenu menu)
Add a top-level menu to the list.
|
void |
addMenuItem(TMenuItem item)
Add a menu item to the global list.
|
void |
addSubMenu(TMenu menu)
Add a sub-menu to the list of open sub-menus.
|
TMenu |
addTableMenu()
Convenience function to add a default "Table" menu.
|
TTimer |
addTimer(long duration,
boolean recurring,
TAction action)
Convenience function to add a timer.
|
TMenu |
addToolMenu()
Convenience function to add a default tools (hamburger) menu.
|
TWindow |
addWindow(java.lang.String title,
int width,
int height)
Convenience function to create a new window and make it active.
|
TWindow |
addWindow(java.lang.String title,
int width,
int height,
int flags)
Convenience function to create a new window and make it active.
|
TWindow |
addWindow(java.lang.String title,
int x,
int y,
int width,
int height)
Convenience function to create a new window and make it active.
|
TWindow |
addWindow(java.lang.String title,
int x,
int y,
int width,
int height,
int flags)
Convenience function to create a new window and make it active.
|
TMenu |
addWindowMenu()
Convenience function to add a default "Window" menu.
|
void |
closeMenu()
Turn off the menu.
|
void |
closeSubMenu()
Turn off a sub-menu.
|
void |
closeWindow(TWindow window)
Close window.
|
void |
disableMenuItem(int id)
Disable one menu item.
|
void |
disableMenuItems(int lower,
int upper)
Disable the range of menu items with ID's between lower and upper,
inclusive.
|
void |
doRepaint()
Repaint the screen on the next update.
|
void |
doSmartPlacement(TWindow window)
Place a window to minimize its overlap with other windows.
|
void |
enableMenuItem(int id)
Enable one menu item.
|
void |
enableMenuItems(int lower,
int upper)
Enable the range of menu items with ID's between lower and upper,
inclusive.
|
void |
enableSecondaryEventReceiver(TWidget widget)
Enable a widget to override the primary event thread.
|
void |
exit()
Force this application to exit.
|
java.lang.String |
fileOpenBox(java.lang.String path)
Convenience function to spawn an file open box.
|
java.lang.String |
fileOpenBox(java.lang.String path,
TFileOpenBox.Type type)
Convenience function to spawn an file open box.
|
java.lang.String |
fileOpenBox(java.lang.String path,
TFileOpenBox.Type type,
java.util.List<java.lang.String> filters)
Convenience function to spawn a file open box.
|
java.lang.String |
fileOpenBox(java.lang.String path,
TFileOpenBox.Type type,
java.lang.String filter)
Convenience function to spawn a file open box.
|
TWindow |
getActiveWindow()
Get the current active window.
|
java.util.List<TMenu> |
getAllMenus()
Get a (shallow) copy of the menu list.
|
java.util.List<TWindow> |
getAllWindows()
Get a (shallow) copy of the window list.
|
Backend |
getBackend()
Get the Backend.
|
TDesktop |
getDesktop()
Get the TDesktop instance.
|
int |
getDesktopBottom()
Get Y coordinate of the bottom edge of the desktop.
|
int |
getDesktopTop()
Get Y coordinate of the top edge of the desktop.
|
boolean |
getFocusFollowsMouse()
Get focusFollowsMouse flag.
|
TMenuItem |
getMenuItem(int id)
Get the menu item associated with this ID.
|
Screen |
getScreen()
Get the Screen.
|
ColorTheme |
getTheme()
Get the color theme.
|
boolean |
hasWindow(TWindow window)
Check if a window instance is in this application's window list.
|
int |
hiddenWindowCount()
Return the number of windows that are hidden.
|
void |
hideWindow(TWindow window)
Hide a window.
|
TInputBox |
inputBox(java.lang.String title,
java.lang.String caption)
Convenience function to spawn an input box.
|
TInputBox |
inputBox(java.lang.String title,
java.lang.String caption,
java.lang.String text)
Convenience function to spawn an input box.
|
TInputBox |
inputBox(java.lang.String title,
java.lang.String caption,
java.lang.String text,
TMessageBox.Type type)
Convenience function to spawn an input box.
|
void |
invokeLater(java.lang.Runnable command)
Place a command on the run queue, and run it before the next round of
checking I/O.
|
boolean |
isRunning()
Check if application is still running.
|
TMessageBox |
messageBox(java.lang.String title,
java.lang.String caption)
Convenience function to spawn a message box.
|
TMessageBox |
messageBox(java.lang.String title,
java.lang.String caption,
TMessageBox.Type type)
Convenience function to spawn a message box.
|
protected boolean |
onCommand(TCommandEvent command)
Method that TApplication subclasses can override to handle menu or
posted command events.
|
void |
onExit()
Subclasses can use this hook to cleanup resources.
|
protected boolean |
onKeypress(TKeypressEvent keypress)
Method that TApplication subclasses can override to handle keystrokes.
|
protected boolean |
onMenu(TMenuEvent menu)
Method that TApplication subclasses can override to handle menu
events.
|
TTerminalWindow |
openTerminal(int x,
int y)
Convenience function to open a terminal window.
|
TTerminalWindow |
openTerminal(int x,
int y,
boolean closeOnExit)
Convenience function to open a terminal window.
|
TTerminalWindow |
openTerminal(int x,
int y,
int flags)
Convenience function to open a terminal window.
|
TTerminalWindow |
openTerminal(int x,
int y,
int flags,
boolean closeOnExit)
Convenience function to open a terminal window.
|
TTerminalWindow |
openTerminal(int x,
int y,
int flags,
java.lang.String commandLine)
Convenience function to open a terminal window and execute a custom
command line inside it.
|
TTerminalWindow |
openTerminal(int x,
int y,
int flags,
java.lang.String[] command)
Convenience function to open a terminal window and execute a custom
command line inside it.
|
TTerminalWindow |
openTerminal(int x,
int y,
int flags,
java.lang.String[] command,
boolean closeOnExit)
Convenience function to open a terminal window and execute a custom
command line inside it.
|
TTerminalWindow |
openTerminal(int x,
int y,
int flags,
java.lang.String commandLine,
boolean closeOnExit)
Convenience function to open a terminal window and execute a custom
command line inside it.
|
TTerminalWindow |
openTerminal(int x,
int y,
java.lang.String commandLine)
Convenience function to open a terminal window and execute a custom
command line inside it.
|
TTerminalWindow |
openTerminal(int x,
int y,
java.lang.String commandLine,
boolean closeOnExit)
Convenience function to open a terminal window and execute a custom
command line inside it.
|
void |
postEvent(TInputEvent event)
Post an event to process.
|
void |
postMenuEvent(TInputEvent event)
Post an event to process and turn off the menu.
|
void |
recomputeMenuX()
Recompute menu x positions based on their title length.
|
void |
removeMenu(TMenu menu)
Remove a top-level menu from the list.
|
void |
removeTimer(TTimer timer)
Convenience function to remove a timer.
|
void |
restoreConsole()
Restore the console to sane defaults.
|
void |
run()
Run this application until it exits.
|
void |
setDesktop(TDesktop desktop)
Set the TDesktop instance.
|
void |
setFocusFollowsMouse(boolean focusFollowsMouse)
Set focusFollowsMouse flag.
|
protected void |
showAboutDialog()
Display the about dialog.
|
int |
shownWindowCount()
Return the number of windows that are showing.
|
void |
showWindow(TWindow window)
Show a window.
|
void |
switchMenu(boolean forward)
Switch to the next menu.
|
void |
switchWindow(boolean forward)
Switch to the next window.
|
int |
windowCount()
Return the total number of windows.
|
void |
yield()
Yield to the secondary thread.
|
public TApplication(TApplication.BackendType backendType, int windowWidth, int windowHeight, int fontSize) throws java.io.UnsupportedEncodingException
backendType
- BackendType.XTERM, BackendType.ECMA48 or
BackendType.SWINGwindowWidth
- the number of text columns to start withwindowHeight
- the number of text rows to start withfontSize
- the size in pointsjava.io.UnsupportedEncodingException
- if an exception is thrown when
creating the InputStreamReaderpublic TApplication(TApplication.BackendType backendType) throws java.io.UnsupportedEncodingException
backendType
- BackendType.XTERM, BackendType.ECMA48 or
BackendType.SWINGjava.io.UnsupportedEncodingException
- if an exception is thrown when
creating the InputStreamReaderpublic TApplication(java.io.InputStream input, java.io.OutputStream output) throws java.io.UnsupportedEncodingException
input
- an InputStream connected to the remote user, or null for
System.in. If System.in is used, then on non-Windows systems it will
be put in raw mode; shutdown() will (blindly!) put System.in in cooked
mode. input is always converted to a Reader with UTF-8 encoding.output
- an OutputStream connected to the remote user, or null
for System.out. output is always converted to a Writer with UTF-8
encoding.java.io.UnsupportedEncodingException
- if an exception is thrown when
creating the InputStreamReaderpublic TApplication(java.io.InputStream input, java.io.Reader reader, java.io.PrintWriter writer, boolean setRawMode)
input
- the InputStream underlying 'reader'. Its available()
method is used to determine if reader.read() will block or not.reader
- a Reader connected to the remote user.writer
- a PrintWriter connected to the remote user.setRawMode
- if true, set System.in into raw mode with stty.
This should in general not be used. It is here solely for Demo3,
which uses System.in.java.lang.IllegalArgumentException
- if input, reader, or writer are null.public TApplication(java.io.InputStream input, java.io.Reader reader, java.io.PrintWriter writer)
input
- the InputStream underlying 'reader'. Its available()
method is used to determine if reader.read() will block or not.reader
- a Reader connected to the remote user.writer
- a PrintWriter connected to the remote user.java.lang.IllegalArgumentException
- if input, reader, or writer are null.public TApplication(Backend backend)
backend
- a Backend that is already ready to go.public void run()
run
in interface java.lang.Runnable
protected boolean onCommand(TCommandEvent command)
command
- command eventprotected boolean onMenu(TMenuEvent menu)
menu
- menu eventprotected boolean onKeypress(TKeypressEvent keypress)
keypress
- keystroke eventpublic final void enableSecondaryEventReceiver(TWidget widget)
widget
- widget that will receive eventspublic final void yield()
public void invokeLater(java.lang.Runnable command)
command
- the command to run laterpublic void restoreConsole()
public final Backend getBackend()
public final Screen getScreen()
public final ColorTheme getTheme()
public void doRepaint()
public final int getDesktopTop()
public final int getDesktopBottom()
public final void setDesktop(TDesktop desktop)
desktop
- a TDesktop instance, or null to remove the one that is
setpublic final TDesktop getDesktop()
public final TWindow getActiveWindow()
public final java.util.List<TWindow> getAllWindows()
public boolean getFocusFollowsMouse()
public void setFocusFollowsMouse(boolean focusFollowsMouse)
focusFollowsMouse
- if true, focus follows mouse: windows
automatically raised if the mouse passes over themprotected void showAboutDialog()
public final boolean isRunning()
public void exit()
public void onExit()
public final int windowCount()
public final int shownWindowCount()
public final int hiddenWindowCount()
public final boolean hasWindow(TWindow window)
window
- window to look forpublic void activateWindow(TWindow window)
window
- the window to become the new active windowpublic void hideWindow(TWindow window)
window
- the window to hidepublic void showWindow(TWindow window)
window
- the window to showpublic final void closeWindow(TWindow window)
window
- the window to removepublic final void switchWindow(boolean forward)
forward
- if true, then switch to the next window in the list,
otherwise switch to the previous window in the listpublic final void doSmartPlacement(TWindow window)
window
- the window to placepublic final void closeMenu()
public final java.util.List<TMenu> getAllMenus()
public final void addMenu(TMenu menu)
menu
- the menu to addjava.lang.IllegalArgumentException
- if the menu is already used in
another TApplicationpublic final void removeMenu(TMenu menu)
menu
- the menu to removejava.lang.IllegalArgumentException
- if the menu is already used in
another TApplicationpublic final void closeSubMenu()
public final void switchMenu(boolean forward)
forward
- if true, then switch to the next menu in the list,
otherwise switch to the previous menu in the listpublic final void addMenuItem(TMenuItem item)
item
- the menu itempublic final void disableMenuItem(int id)
id
- the menu item IDpublic final void disableMenuItems(int lower, int upper)
lower
- the lowest menu item IDupper
- the highest menu item IDpublic final void enableMenuItem(int id)
id
- the menu item IDpublic final void enableMenuItems(int lower, int upper)
lower
- the lowest menu item IDupper
- the highest menu item IDpublic final TMenuItem getMenuItem(int id)
id
- the menu item IDpublic final void recomputeMenuX()
public final void postEvent(TInputEvent event)
event
- new event to add to the queuepublic final void postMenuEvent(TInputEvent event)
event
- new event to add to the queuepublic final void addSubMenu(TMenu menu)
menu
- sub-menupublic final TMenu addMenu(java.lang.String title)
title
- menu titlepublic final TMenu addToolMenu()
public final TMenu addFileMenu()
public final TMenu addEditMenu()
public final TMenu addWindowMenu()
public final TMenu addHelpMenu()
public final TMenu addTableMenu()
public final TTimer addTimer(long duration, boolean recurring, TAction action)
duration
- number of milliseconds to wait between ticksrecurring
- if true, re-schedule this timer after every tickaction
- function to call when button is pressedpublic final void removeTimer(TTimer timer)
timer
- timer to removepublic final TMessageBox messageBox(java.lang.String title, java.lang.String caption)
title
- window title, will be centered along the top bordercaption
- message to display. Use embedded newlines to get a
multi-line box.public final TMessageBox messageBox(java.lang.String title, java.lang.String caption, TMessageBox.Type type)
title
- window title, will be centered along the top bordercaption
- message to display. Use embedded newlines to get a
multi-line box.type
- one of the TMessageBox.Type constants. Default is
Type.OK.public final TInputBox inputBox(java.lang.String title, java.lang.String caption)
title
- window title, will be centered along the top bordercaption
- message to display. Use embedded newlines to get a
multi-line box.public final TInputBox inputBox(java.lang.String title, java.lang.String caption, java.lang.String text)
title
- window title, will be centered along the top bordercaption
- message to display. Use embedded newlines to get a
multi-line box.text
- initial text to seed the field withpublic final TInputBox inputBox(java.lang.String title, java.lang.String caption, java.lang.String text, TMessageBox.Type type)
title
- window title, will be centered along the top bordercaption
- message to display. Use embedded newlines to get a
multi-line box.text
- initial text to seed the field withtype
- one of the Type constants. Default is Type.OK.public final TTerminalWindow openTerminal(int x, int y)
x
- column relative to parenty
- row relative to parentpublic final TTerminalWindow openTerminal(int x, int y, boolean closeOnExit)
x
- column relative to parenty
- row relative to parentcloseOnExit
- if true, close the window when the command exitspublic final TTerminalWindow openTerminal(int x, int y, int flags)
x
- column relative to parenty
- row relative to parentflags
- mask of CENTERED, MODAL, or RESIZABLEpublic final TTerminalWindow openTerminal(int x, int y, int flags, boolean closeOnExit)
x
- column relative to parenty
- row relative to parentflags
- mask of CENTERED, MODAL, or RESIZABLEcloseOnExit
- if true, close the window when the command exitspublic final TTerminalWindow openTerminal(int x, int y, java.lang.String commandLine)
x
- column relative to parenty
- row relative to parentcommandLine
- the command line to executepublic final TTerminalWindow openTerminal(int x, int y, java.lang.String commandLine, boolean closeOnExit)
x
- column relative to parenty
- row relative to parentcommandLine
- the command line to executecloseOnExit
- if true, close the window when the command exitspublic final TTerminalWindow openTerminal(int x, int y, int flags, java.lang.String[] command)
x
- column relative to parenty
- row relative to parentflags
- mask of CENTERED, MODAL, or RESIZABLEcommand
- the command line to executepublic final TTerminalWindow openTerminal(int x, int y, int flags, java.lang.String[] command, boolean closeOnExit)
x
- column relative to parenty
- row relative to parentflags
- mask of CENTERED, MODAL, or RESIZABLEcommand
- the command line to executecloseOnExit
- if true, close the window when the command exitspublic final TTerminalWindow openTerminal(int x, int y, int flags, java.lang.String commandLine)
x
- column relative to parenty
- row relative to parentflags
- mask of CENTERED, MODAL, or RESIZABLEcommandLine
- the command line to executepublic final TTerminalWindow openTerminal(int x, int y, int flags, java.lang.String commandLine, boolean closeOnExit)
x
- column relative to parenty
- row relative to parentflags
- mask of CENTERED, MODAL, or RESIZABLEcommandLine
- the command line to executecloseOnExit
- if true, close the window when the command exitspublic final java.lang.String fileOpenBox(java.lang.String path) throws java.io.IOException
path
- path of selected filejava.io.IOException
- if java.io operation throwspublic final java.lang.String fileOpenBox(java.lang.String path, TFileOpenBox.Type type) throws java.io.IOException
path
- path of selected filetype
- one of the Type constantsjava.io.IOException
- if java.io operation throwspublic final java.lang.String fileOpenBox(java.lang.String path, TFileOpenBox.Type type, java.lang.String filter) throws java.io.IOException
path
- path of selected filetype
- one of the Type constantsfilter
- a string that files must match to be displayedjava.io.IOException
- of a java.io operation throwspublic final java.lang.String fileOpenBox(java.lang.String path, TFileOpenBox.Type type, java.util.List<java.lang.String> filters) throws java.io.IOException
path
- path of selected filetype
- one of the Type constantsfilters
- a list of strings that files must match to be displayedjava.io.IOException
- of a java.io operation throwspublic final TWindow addWindow(java.lang.String title, int width, int height)
title
- window title, will be centered along the top borderwidth
- width of windowheight
- height of windowpublic final TWindow addWindow(java.lang.String title, int width, int height, int flags)
title
- window title, will be centered along the top borderwidth
- width of windowheight
- height of windowflags
- bitmask of RESIZABLE, CENTERED, or MODALpublic final TWindow addWindow(java.lang.String title, int x, int y, int width, int height)
title
- window title, will be centered along the top borderx
- column relative to parenty
- row relative to parentwidth
- width of windowheight
- height of windowpublic final TWindow addWindow(java.lang.String title, int x, int y, int width, int height, int flags)
title
- window title, will be centered along the top borderx
- column relative to parenty
- row relative to parentwidth
- width of windowheight
- height of windowflags
- mask of RESIZABLE, CENTERED, or MODALCopyright © 2019 Kevin Lamonte. Licensed MIT.