tomo/application.go

114 lines
3.1 KiB
Go

package tomo
import "image"
// Application represents an application object.
type Application interface {
// Describe returns a description of the application.
Describe () ApplicationDescription
// Init performs the initial setup of the application.
Init ()
}
// ApplicationDescription describes the name and type of an application.
type ApplicationDescription struct {
// The name or ID of the application.
Name string
// Role describes what the application does.
Role ApplicationRole
}
// String satisfies the fmt.Stringer interface.
func (application ApplicationDescription) String () string {
if application.Name == "" {
return application.Role.String()
} else {
return application.Name
}
}
// ApplicationRole describes what an application does.
type ApplicationRole int; const (
RoleUnknown ApplicationRole = iota
RoleWebBrowser
RoleMesssanger
RolePhone
RoleMail
RoleTerminalEmulator
RoleFileBrowser
RoleTextEditor
RoleDocumentViewer
RoleWordProcessor
RoleSpreadsheet
RoleSlideshow
RoleCalculator
RolePreferences
RoleProcessManager
RoleSystemInformation
RoleManual
RoleCamera
RoleImageViewer
RoleMediaPlayer
RoleImageEditor
RoleAudioEditor
RoleVideoEditor
RoleClock
RoleCalendar
RoleChecklist
)
// String satisfies the fmt.Stringer interface.
func (role ApplicationRole) String () string {
switch role {
case RoleWebBrowser: return "Web Browser"
case RoleMesssanger: return "Messsanger"
case RolePhone: return "Phone"
case RoleMail: return "Mail"
case RoleTerminalEmulator: return "Terminal Emulator"
case RoleFileBrowser: return "File Browser"
case RoleTextEditor: return "Text Editor"
case RoleDocumentViewer: return "Document Viewer"
case RoleWordProcessor: return "Word Processor"
case RoleSpreadsheet: return "Spreadsheet"
case RoleSlideshow: return "Slideshow"
case RoleCalculator: return "Calculator"
case RolePreferences: return "Preferences"
case RoleProcessManager: return "Process Manager"
case RoleSystemInformation: return "System Information"
case RoleManual: return "Manual"
case RoleCamera: return "Camera"
case RoleImageViewer: return "Image Viewer"
case RoleMediaPlayer: return "Media Player"
case RoleImageEditor: return "Image Editor"
case RoleAudioEditor: return "Audio Editor"
case RoleVideoEditor: return "Video Editor"
case RoleClock: return "Clock"
case RoleCalendar: return "Calendar"
case RoleChecklist: return "Checklist"
default: return "unknown"
}
}
// RunApplication is like Run, but runs an application.
func RunApplication (application Application) error {
return Run(application.Init)
}
// NewApplicationWindow creates a window for an application. It will
// automatically set window information to signal to the OS that the window is
// owned by the application.
func NewApplicationWindow (application Application, bounds image.Rectangle) (MainWindow, error) {
window, err := NewWindow(bounds)
if err != nil { return nil, err }
window.SetTitle(application.Describe().String())
return window, nil
}