pianola-0.1.1: Remotely controlling Java Swing applications

Safe HaskellNone

Pianola.Model.Swing

Synopsis

Documentation

type GUI m = [Window m]Source

A client-side representation of the state of a remote Swing GUI. Interaction with the GUI is through actions in the monad m.

data WindowInfo m Source

Constructors

WindowInfo 

Fields

_windowTitle :: Text
 
_windowDim :: (Int, Int)

Width, height.

_menu :: [Component m]

List of components in the menu bar. See selectInMenuBar.

_popupLayer :: [Component m]

List of components in the popup layer.

_contentPane :: Component m

The contents pane. All non-popup components of the window are descendants of the contents pane. See contentPane and descendants.

_capture :: Nullipotent m Image

Action which returns a screenshot capture of the window. See logcapture.

_escape :: Sealed m

See escape.

_enter :: Sealed m

See enter.

_close :: Sealed m

See close.

_toFront :: Sealed m

See toFront.

class Windowed w => WindowLike w whereSource

Typeclass which provides convenience functions to supplement the bare fields of a WindowInfo record.

Methods

wInfo :: w m -> WindowInfo mSource

title :: (Monad m, Monad n) => w m -> n TextSource

hasTitle :: MonadPlus n => (Text -> Bool) -> w m -> n (w m)Source

If the window has a title that satisfies the predicate, returns the window, otherwise mzero.

popupLayer :: Monad m => Glance m l (w m) (Component m)Source

Convenience function to access the components in the popup layer. Most of the time, clients should use popupItem instead of this function.

logcapture :: Monad m => Pianola m LogEntry (w m) ()Source

Convenience function to log an screenshot of a window.

contentPane :: Monad m => Glance m l (w m) (ComponentW m)Source

Convenience function which returns the content pane component augmented with a reference to the containing window.

toFront :: Monad m => Glance m l (w m) (Sealed m)Source

Brings the window to the front of the screen.

escape :: Monad m => Glance m l (w m) (Sealed m)Source

Sends an escape keypress to the window.

enter :: Monad m => Glance m l (w m) (Sealed m)Source

Sends an enter keypress to the window.

close :: Monad m => Glance m l (w m) (Sealed m)Source

Instances

class Windowed w whereSource

Typeclass instantiated by windows and components aware of belonging to a window.

Methods

window :: Monad n => w m -> n (Window m)Source

newtype ComponentW m Source

A component which carries a reference to the window to which it belongs. See Windowed.

Constructors

ComponentW 

data ComponentInfo m Source

Constructors

ComponentInfo 

Fields

_pos :: (Int, Int)

The position of the component within the containing window.

_dim :: (Int, Int)

Width and height.

_name :: Maybe Text
 
_tooltip :: Maybe Text
 
_text :: Maybe Text

The textual value of the component.

_enabled :: Bool
 
_componentType :: ComponentType m
 
_click :: Sealed m
 
_doubleClick :: Sealed m
 
_rightClick :: Sealed m
 

data ComponentType m Source

Represents data specific to each subclass of Swing components.

Constructors

Panel 
Toggleable Bool (Bool -> Sealed m)

A check box, either in a window or in a popup menu. The bool value is the current selection state.

Button (Sealed m)

A button with its selection action. Menu items in popup menus are also treated as buttons.

TextField (Maybe (Text -> Sealed m))

Nothing when the textfield is not editable.

Label 
ComboBox (Maybe (Component m)) (Sealed m)

A combo box which may already have a selection, and which offers a click action which shows the drop-down list. See selectInComboBox.

List [Cell m]

See listCellByText.

Table [[Cell m]]

Tables are represented as lists of columns. See tableCellByText.

Treegui (Forest (Cell m))

A list of trees of Cell. It is a list of trees instead of a single tree so that JTrees which do not show the root can be represented. See treeCellByText.

PopupMenu

In Swing, popup menus reside in the popup layer of a window or, if the popup extends beyond the window, in the contents pane of a child window created to hold the popup. See popupItem.

TabbedPane [Tab m]

See selectTabByText.

Other Text

The text value holds the name of the class.

class ComponentLike c whereSource

Typeclass which provides convenience functions to supplement the bare fields of a ComponentInfo record.

Methods

cInfo :: c m -> ComponentInfo mSource

cType :: c m -> ComponentType mSource

text :: MonadPlus n => c m -> n TextSource

Returns the component's textual content or mzero if it doesn't have any.

hasText :: MonadPlus n => (Text -> Bool) -> c m -> n (c m)Source

If the component has some kind of textual content and the text satisfies the predicate, returns the component, otherwise mzero.

tooltip :: MonadPlus n => c m -> n TextSource

Returns the component's tooltip or mzero if it doesn't have any.

hasToolTip :: MonadPlus n => (Text -> Bool) -> c m -> n (c m)Source

If the component has a tooltip and the tooltip satisfies the predicate, returns the component, otherwise mzero.

hasName :: MonadPlus n => (Text -> Bool) -> c m -> n (c m)Source

If the component has a name and the name satisfies the predicate, returns the component, otherwise mzero.

toggle :: MonadPlus n => Bool -> c m -> n (Sealed m)Source

Toggles the component to the desired state if the component is toggleable, mzero otherwise.

click :: Monad n => c m -> n (Sealed m)Source

Returns the click action of a component.

doubleClick :: Monad n => c m -> n (Sealed m)Source

rightClick :: Monad n => c m -> n (Sealed m)Source

clickButton :: MonadPlus n => c m -> n (Sealed m)Source

If the component is a button returns its click action, otherwise mzero.

clickCombo :: MonadPlus n => c m -> n (Sealed m)Source

If the component is a combo box returns its click action, otherwise mzero.

listCellByText :: MonadPlus n => (Text -> Bool) -> c m -> n (Cell m)Source

If the component is a list and has a cell whose renderer's text satisfies the predicate, returns the cell, otherwise mzero.

tableCellByText :: MonadPlus n => Int -> (Text -> Bool) -> c m -> n (Cell m, [Cell m])Source

If the component is a table and has a cell at the specified column whose renderer's text satisfies the predicate, returns a pair of the cell and the row to which it belongs, otherwise mzero.

treeCellByText :: MonadPlus n => Int -> (Text -> Bool) -> c m -> n (Tree (Cell m))Source

If the component is a tree and has a cell at the specified depth (starting at 0 for the root) whose renderer's text satisfies the predicate, returns the subtree which has the cell as a root, otherwise mzero.

tab :: MonadPlus n => c m -> n (Tab m)Source

Returns the tabs of a component if the component is a tabbed pane, mzero otherwise.

setText :: MonadPlus n => Text -> c m -> n (Sealed m)Source

If the component is a text field and is editable, set the text of the text field. Otherwise mzero.

data Cell m Source

Complex gui components like lists, tables and trees are represented as list of cells, list of lists (list of columns) of cells, and trees of cells, respectively.

Bear in mind that in Swing the renderer sub-components of a complex component do not count as children of the component. However, editor components do count as children of the component.

A common case is to double click on a table cell to activate the cell's editor, and then having to look for that editor among the descendants of the table.

Constructors

Cell 

Fields

_renderer :: Component m

The rendering component. Clients should not try to invoke actions on rendering components, as they are inert and only used for display purposes.

_clickCell :: Sealed m
 
_doubleClickCell :: Sealed m
 
_rightClickCell :: Sealed m
 
_expand :: Maybe (Bool -> Sealed m)

Always Nothing for cells not belonging to trees.

Instances

data Tab m Source

Constructors

Tab 

Instances

mainWindow :: Glance m l (GUI m) (Window m)Source

Returns the main window of the application. Only works properly when there is only one top-level window.

childWindow :: Glance m l (Window m) (Window m)Source

Returns the children of a window.

windowTitled :: (Text -> Bool) -> Glance m l (GUI m) (Window m)Source

Returns all visible windows whose title satisfies the predicate.

clickButtonByText :: (Monad m, ComponentLike c, Treeish (c m)) => (Text -> Bool) -> Glance m l (c m) (Sealed m)Source

If the component or *any of its descendants* is a button whose text satisfies the predicate, returns the click action. Otherwise mzero.

clickButtonByToolTip :: (Monad m, ComponentLike c, Treeish (c m)) => (Text -> Bool) -> Glance m l (c m) (Sealed m)Source

Similar to clickButtonByText.

rightClickByText :: (Monad m, ComponentLike c, Treeish (c m)) => (Text -> Bool) -> Glance m l (c m) (Sealed m)Source

Similar to clickButtonByText.

popupItem :: Monad m => Glance m l (Window m) (Component m)Source

Returns all the visible popup items belonging to a window (that is, not only the popup components themselves, but all their clickable children). Clients should use this function instead of trying to access the popup layer directly.

selectInMenuBar :: Monad m => [Text -> Bool] -> Pianola m l (Window m) ()Source

Performs a sequence of selections in a window menu, based to the text of the options. Pass it something like

 map (==) ["menuitem1","menuitem2',...]

To match the exact names of the options.

toggleInMenuBar :: Monad m => Bool -> [Text -> Bool] -> Pianola m l (Window m) ()Source

Like selectInMenuBar, but for when the last item is a toggleable component. The boolean paramenter is the desired selection state.

selectInComboBox :: (Monad m, ComponentLike c, Windowed c) => (Text -> Bool) -> Pianola m l (c m) ()Source

If the component is a combo box, clicks on it and selects an option by its text. Otherwise fails.

selectTabByText :: (Monad m, ComponentLike c) => (Text -> Bool) -> Glance m l (c m) (Sealed m)Source

If the component is a tabbed pane returns the select action of a tab whose text matches the predicate. Returns mzero if the component is not a tabbed pane.

selectTabByToolTip :: (Monad m, ComponentLike c) => (Text -> Bool) -> Glance m l (c m) (Sealed m)Source

Similar to selecTabByText.

expand :: Monad m => Bool -> Glance m l (Tree (Cell m)) (Sealed m)Source

Returns the expand/collapse action of the root node of a tree of cells, depending on a boolean parameter. Useful with gui trees.

labeledBy :: (Monad m, ComponentLike c, Treeish (c m)) => (Text -> Bool) -> Glance m l (c m) (c m)Source

Takes a component, searches its descendants to find a label whose text matches the predicate, finds the component to which the label applies, and returns it.

Useful for targeting text fields in form-like dialogs.