-
Notifications
You must be signed in to change notification settings - Fork 0
AWT Peer Implementation
JNode implements AWT peers using Swing components as a lightweight simulation of a desktop operating system, bypassing the need for a host OS windowing system.
Unlike traditional JVMs that delegate UI rendering to the host OS (X11, Windows), JNode implements the entire peer layer from scratch. The peer implementation uses Swing components as an internal rendering backend, creating a simulated desktop environment that draws directly to the framebuffer.
| Class | Location | Purpose |
|---|---|---|
JNodeToolkit |
gui/src/awt/org/jnode/awt/JNodeToolkit.java |
Base toolkit, bridges AWT to framebuffer |
SwingToolkit |
gui/src/awt/org/jnode/awt/swingpeers/SwingToolkit.java |
Creates all peer instances using Swing |
JNodeGraphicsEnvironment |
gui/src/awt/org/jnode/awt/JNodeGraphicsEnvironment.java |
Manages screen devices and fonts |
AWTPlugin |
gui/src/awt/org/jnode/awt/AWTPlugin.java |
Plugin lifecycle management |
DesktopFrame |
gui/src/awt/org/jnode/awt/swingpeers/DesktopFrame.java |
Root window (the desktop) |
DesktopFramePeer |
gui/src/awt/org/jnode/awt/swingpeers/DesktopFramePeer.java |
Peer for desktop |
JNodeEventQueue |
gui/src/awt/org/jnode/awt/JNodeEventQueue.java |
Event dispatch |
KeyboardHandler |
gui/src/awt/org/jnode/awt/KeyboardHandler.java |
Raw keyboard to AWT events |
MouseHandler |
gui/src/awt/org/jnode/awt/MouseHandler.java |
Mouse input handling |
Boot → AWTPlugin.startPlugin()
→ VMImageUtils.setAPI(new VMImageAPIImpl())
→ Application calls Toolkit.getDefaultToolkit()
→ JNodeToolkit.incRefCount() initializes graphics mode
→ JNodeToolkit.onInitialize() (abstract, implemented by SwingToolkit)
→ SwingToolkit creates DesktopFrame
java.awt.Toolkit
└── gnu.java.awt.ClasspathToolkit (GNU Classpath)
└── org.jnode.awt.JNodeToolkit (abstract base)
└── org.jnode.awt.swingpeers.SwingToolkit
When an AWT component is created, the toolkit creates a peer:
// Example from SwingToolkit.java
protected ButtonPeer createButton(Button target) {
return new SwingButtonPeer(this, target);
}Each peer wraps a Swing component that handles rendering. The peer maps between AWT and Swing coordinate systems and event models.
JNode connects to video hardware through the Video-Driver-Architecture:
-
JNodeToolkitqueriesDeviceManagerforFrameBufferAPIimplementations - Requests ownership of the framebuffer via
api.requestOwnership(this) - Opens a
Surfacefor drawing:api.open(config.getConfig()) - All painting operations write directly to video memory
The DesktopFrame is the root of the component hierarchy:
// From SwingToolkit.onInitialize()
desktopFrame = new DesktopFrame(getScreenSize());
desktopFrame.show();
desktopFrame.getContentPane().repaint();All other AWT Frames are rendered as JInternalFrames inside this desktop's JDesktopPane.
Input Hardware → KeyboardHandler/MouseHandler
→ JNodeEventQueue
→ EventQueue.dispatchEvent()
→ AWT Component event listeners
The KeyboardHandler and MouseHandler convert hardware interrupts into AWT events:
- Keyboard scancodes →
KeyEvent(KEY_PRESSED, KEY_RELEASED, KEY_TYPED) - Mouse movement/clicks →
MouseEvent(MOUSE_MOVED, MOUSE_DRAGGED, MOUSE_CLICKED, etc.)
Swing peers implement standard AWT peer interfaces:
| Peer Interface | Implementation |
|---|---|
ButtonPeer |
SwingButtonPeer |
LabelPeer |
SwingLabelPeer |
FramePeer |
SwingFramePeer / DesktopFramePeer
|
WindowPeer |
SwingWindowPeer |
ContainerPeer |
SwingContainerPeer |
LightweightPeer |
SwingLightweightPeer |
| ... | ... |
Each implementation wraps the corresponding JComponent and delegates painting, event handling, and layout.
JNode includes a TrueType font subsystem:
-
TTFFontPeer— wraps a TrueType font file -
FontManager— service managing available fonts -
TextRenderer— renders glyphs to graphics context
Font rendering flows through the graphics pipeline to the framebuffer.
The SwingFramePeer (lines 54-167 in SwingFramePeer.java) implements FramePeer and ISwingContainerPeer. It wraps a SwingFrame (an internal JInternalFrame subclass) and manages:
- Window state (iconified, maximized, normal)
- Menu bar integration via
setMenuBar() - Addition to the desktop via
addToDesktop()
The DesktopFrame (lines 45-165 in DesktopFrame.java) extends JFrame and implements JNodeAwtContext. It serves as:
- The root window containing all other AWT windows
- A
JDesktopPanethat manages internal frames - Background color persistence via
Preferences - Size adjustment through
adjustDesktopSize()
The peer implementation uses SwingToolkit.invokeNowOrLater() to ensure thread-safe operations:
// From SwingFramePeer.java
public void setMenuBar(final MenuBar mb) {
SwingToolkit.invokeNowOrLater(new Runnable() {
public void run() { /* ... */ }
});
}This ensures AWT operations execute on the Event Dispatch Thread (EDT) while handling cases where peers may be created from different AppContext instances.
- No native windowing: AWT windows are simulated internally; they don't correspond to OS-level windows
-
Reference counting: GUI mode uses
incRefCount()/decRefCount()to track active users; when count reaches zero, graphics are released -
AppContext isolation: Peers must be created in the same
AppContextas the desktop frame to ensure event dispatch works correctly -
Look and feel:
SwingToolkitsetsMetalLookAndFeelwithOceanThemeas default -
Desktop ownership: The first
Framecreated becomes the desktop; subsequent frames become internal frames
- GUI-AWT — High-level GUI and AWT overview
- Font-Rendering — TrueType and BDF font rendering system.
- Video-Driver-Architecture — Framebuffer and Surface abstraction
- JNode-Graphics2D — Graphics2D implementations (JNodeSurfaceGraphics2D, JNodeGraphics2D)
- Driver-Framework — How drivers are registered and loaded
- Plugin-System — How the AWT plugin is loaded at boot
- Architecture — Overall system structure