JDance is built around a small set of concepts that are used consistently throughout an application.
The four most important parts are:
- Layout
- Panel
- Styling
- Actions
Layouts describe structure.
Panels add behavior around content.
Styling controls appearance, size and responsive behavior.
Actions connect the user interface to application behavior.
Together they form the basis of most JDance applications.
Layouts define how components are arranged.
A layout does not normally represent a feature by itself. Its responsibility is structure.
For example:
This can be represented as nested layouts:
The body can itself be another layout:
This is an important part of JDance architecture.
Large interfaces are not built as one large page definition. They are composed from smaller layouts containing other layouts and components.
BasicLayout is the main general-purpose layout.
It can arrange its children vertically:
or horizontally:
BasicLayout also controls properties such as sizing, padding, gap and alignment.
JDance also provides layouts for common structures.
These exist so common structures do not need to be recreated manually.
The important concept is still the same: a layout controls composition and position.
When a component is added to a layout, the returned cell can control how that component behaves inside the layout.
For example:
The component describes what is rendered.
The layout cell describes how that component participates in the surrounding layout.
This keeps layout decisions outside the component itself when appropriate.
Panels wrap content and give it additional behavior.
A useful distinction is:
A panel normally contains another component.
The content itself does not need to implement the behavior provided by the panel.
LinkPanel makes content interactive.
The content inside the panel can remain a normal component while the panel handles the interaction around it.
This is useful because visual structure and interaction behavior do not have to be implemented in the same class.
FormPanel represents form behavior.
Fields and buttons can be composed normally using layouts and then placed inside a FormPanel.
The layout still controls structure.
The FormPanel provides the form behavior.
FixedPanel and StickyPanel change how content behaves relative to the browser viewport.
They can contain normal layouts and components.
This means viewport behavior can be added without changing the internal structure of the content.
WindowPanel represents the outer browser window.
Most applications do not need to create a WindowPanel in every page.
Instead it is normally placed in a shared outer component such as MainFrame.
This gives the application one common outer structure.
Styling in JDance is part of the Java API.
Appearance, size, spacing, alignment and responsive behavior can all be configured directly on components and layouts.
There is normally no need for application code to manually construct CSS for common styling.
Visual properties are represented by Java objects.
For example:
Common styling objects include:
Components and layout cells can use fixed or relative dimensions.
Sizing therefore becomes part of the component tree rather than a separate page definition.
Padding and gaps are handled directly by layouts.
Padding controls the inside of a layout.
Gap controls the distance between its cells.
Layout cells control alignment.
Horizontal and vertical alignment can be configured independently.
JDance supports media-dependent properties.
A Media object describes a viewport range:
Properties can then change for that media range.
The component tree remains the same.
Only the relevant properties change.
This means desktop and mobile versions normally do not require separate pages.
Larger applications commonly keep shared styling configuration in a Skin class.
A Skin can contain things such as:
This keeps common visual decisions centralized.
For example, documentation headings, text and code blocks can all use the same shared configuration instead of defining their appearance separately on every page.
Actions connect the interface to behavior.
Layouts and panels describe the interface.
Styling controls how that interface looks.
Actions describe what happens when the application is used.
The main action types are:
HttpAction handles normal HTTP requests.
It is the most commonly used action type.
A typical view action remains very small:
The action receives the request and decides what should be returned.
It should normally not contain the complete GUI itself.
Actions that display pages normally use the naming convention:
A class called ViewAccount therefore immediately communicates its responsibility.
It handles the request for viewing the account page.
AjaxAction handles interaction with a page that is already open.
Typical uses include:
- Updating part of a page.
- Saving a field.
- Opening or closing interface elements.
- Refreshing content.
- Performing an operation without normal page navigation.
The interaction remains server-side while the existing browser interface can be updated.
ServerAction is used when the server needs to initiate an action toward an already connected browser.
This is commonly associated with WebSocket communication.
HttpAction, AjaxAction and ServerAction therefore represent different forms of communication while using the same general action model.
Controllers connect incoming communication to actions.
The main controller types are:
An application normally extends these with a small control class.
A typical HTTP controller looks like this:
HttpControl owns the HTTP action mapper for that web context.
The controller handles routing.
The individual HttpAction classes handle the requests.
AjaxControl performs the same role for Ajax actions.
It extends JDance AjaxController and provides the action mapping used by Ajax actions.
WebsocketControl handles WebSocket communication.
It extends JDance WebsocketController and provides the connection used for server-side communication with the browser.
Actions receive a context representing the current communication.
The main context types correspond to the controller and action types:
For example:
The context provides the action with the JDance environment for the current request or connection.
This keeps the action API consistent without requiring application classes to manage the lower-level communication directly.
Pages are normally implemented as GuiComponent classes.
A page describes the larger GUI structure for one view.
For example:
The page combines existing GUI parts.
It does not need to recreate every part of the application shell.
Repeated pieces of interface are normally implemented as GuiComponent classes.
Examples include:
A reusable GUI class can internally use layouts, panels and ordinary components.
It can then be used like any other component:
This keeps pages focused on composition rather than implementation details.
MainFrame is normally the common outer structure of the web interface.
A typical MainFrame may contain:
Individual pages provide the content.
MainFrame provides the common application frame.
This avoids repeating WindowPanel setup, navigation and common layout configuration in every page.
A normal HTTP page request can be viewed like this:
Each layer has a different responsibility.
The result is still one Java component tree rendered by JDance.
A JDance application's web package is normally divided into contexts.
A common structure is:
adm/ contains administration functionality.
pub/ contains public functionality.
usr/ contains functionality for logged-in users.
The top-level comps/ package contains GUI classes that are shared between contexts.
Each context normally contains:
pages/ contains the larger page components.
comps/ contains reusable GUI used inside that context.
actions/ contains the interaction layer.
Actions are normally divided by communication type:
The controller for each type sits beside its actions.
The control class extends the corresponding JDance controller.
The other classes extend the corresponding JDance action type.
The page structure might look like this:
Pages describe complete views.
Components contain reusable parts used by those pages.
Components shared by several contexts are commonly placed directly under web/comps/.
These classes define the common outer structure and appearance of the application.
A larger application may therefore look like this:
The package structure mirrors the JDance architecture.
Controllers route.
Actions handle interaction.
Pages compose the interface.
Layouts structure it.
Panels add behavior.
Styling controls its presentation.
Shared GUI classes remove repetition.