Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
92 changes: 92 additions & 0 deletions sites/labs/public/FlatLaf-Demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>FlatLaf Demo & Theme Editor – CheerpJ + Java 17</title>
<script src="https://cjrtnc.leaningtech.com/4.2/loader.js"></script>
<link rel="stylesheet" href="./style.css" />
</head>

<body>
<main class="page">
<section class="shell">
<header class="shell-header">
<div class="shell-dots">
<span class="shell-dot"></span>
<span class="shell-dot"></span>
<span class="shell-dot"></span>
</div>

<div class="shell-title-block">
<div class="shell-title-row">
<div class="shell-title">FlatLaf – Browser Demo</div>
<div class="shell-pill">Java 17 via CheerpJ</div>
</div>
<div class="shell-subtitle">
Switch between the FlatLaf Demo and Theme Editor, both running
unchanged JARs inside the browser via CheerpJ (Java 17).
</div>
</div>

<div class="shell-spacer"></div>

<div class="switcher" aria-label="Open FlatLaf applications">
<button id="btn-demo" type="button">Demo</button>
<button id="btn-editor" type="button">Theme Editor</button>
</div>
</header>

<div class="shell-body">
<div id="container"></div>

<aside class="side-panel">
<div>
<div class="side-heading">How to use</div>
<ul class="step-list">
<li>
<span class="step-badge">1</span>
<span>
Start with the <strong>Demo</strong> to explore FlatLaf look
&amp; feel options and components.
</span>
</li>
<li>
<span class="step-badge">2</span>
<span>
Switch to the <strong>Theme Editor</strong> to create or
tweak themes. Save them inside the CheerpJ virtual
filesystem.
</span>
</li>
<li>
<span class="step-badge">3</span>
<span>
Go back to the <strong>Demo</strong> and load your custom
theme using the FlatLaf theme selection options.
</span>
</li>
</ul>
</div>

<div class="hint">
This page runs the original FlatLaf JARs:
<br />
<code>flatlaf-demo-3.7.jar</code> and
<code>flatlaf-theme-editor-3.7.jar</code> via
<code>cheerpjRunJar</code> on a Java 17 runtime.
</div>

<div class="status" id="status-bar">
<div class="status-text">
<span class="status-dot"></span>
<span id="status-label">Runtime ready</span>
</div>
</div>
</aside>
</div>
</section>
</main>

<script src="./main.js"></script>
</body>
</html>
134 changes: 134 additions & 0 deletions sites/labs/public/FlatLaf-Demo/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Jar location inside the CheerpJ VFS
const VFS_DIR = "/files/FlatLaf-Demo";
const VFS_JARS = {
demo: `${VFS_DIR}/flatlaf-demo-3.7.jar`,
editor: `${VFS_DIR}/flatlaf-theme-editor-3.7.jar`,
};

// Where the jars live on the website
const WEB_JARS = {
demo: new URL(
"./FlatLaf/flatlaf-demo-3.7.jar",
window.location.href
).toString(),
editor: new URL(
"./FlatLaf/flatlaf-theme-editor-3.7.jar",
window.location.href
).toString(),
};

const btnDemo = document.getElementById("btn-demo");
const btnEditor = document.getElementById("btn-editor");
const statusLabel = document.getElementById("status-label");

// Library-mode to handle filesystem work
let lib = null;

// Status helper (auto-resets after a short delay)
let statusTimer = null;

function setStatus(text, { autoResetMs = 3500 } = {}) {
statusLabel.textContent = text;

if (statusTimer) clearTimeout(statusTimer);
if (autoResetMs > 0) {
statusTimer = setTimeout(() => {
statusLabel.textContent = "Ready — click a button to open a window";
statusTimer = null;
}, autoResetMs);
}
}

(async () => {
setStatus("Starting CheerpJ…", { autoResetMs: 0 });

await cheerpjInit({
version: 17,
});

cheerpjCreateDisplay(-1, -1, document.getElementById("container"));

// Library mode to write files in the VFS
lib = await cheerpjRunLibrary("");

setStatus("Preparing demo files…", { autoResetMs: 0 });

// Ensure jars exist in VFS
await ensureJarInVfs("demo");
await ensureJarInVfs("editor");

// Start the demo automatically
setStatus("Opening Demo…");
runApp("demo");

// Buttons act as launch actions
btnDemo.addEventListener("click", () => runApp("demo"));
btnEditor.addEventListener("click", () => runApp("editor"));

setStatus("Ready — click a button to open a window", { autoResetMs: 0 });
})().catch((err) => {
console.error("Init failed:", err);
setStatus("Failed to start", { autoResetMs: 0 });
});

function labelFor(which) {
return which === "editor" ? "Theme Editor" : "Demo";
}

async function ensureJarInVfs(which) {
const targetPath = VFS_JARS[which];
const sourceUrl = WEB_JARS[which];

const Files = await lib.java.nio.file.Files;
const Paths = await lib.java.nio.file.Paths;

await Files.createDirectories(await Paths.get(VFS_DIR));

const exists = await Files.exists(await Paths.get(targetPath));
if (exists) {
console.log(`[VFS] ${which} jar already present: ${targetPath}`);
return;
}

console.log(`[WEB] Downloading ${which} jar: ${sourceUrl}`);
setStatus(`Downloading ${labelFor(which)} JAR…`, { autoResetMs: 0 });

const resp = await fetch(sourceUrl);
if (!resp.ok) {
throw new Error(
`Failed to fetch ${sourceUrl}: ${resp.status} ${resp.statusText}`
);
}

const buf = await resp.arrayBuffer();
const byteArr = Array.from(new Int8Array(buf));

console.log(
`[VFS] Writing ${which} jar to: ${targetPath} (${byteArr.length} bytes)`
);

const FileOutputStream = await lib.java.io.FileOutputStream;
const fos = await new FileOutputStream(targetPath);
await fos.write(byteArr);
await fos.close();

console.log(`[VFS] Done: ${targetPath}`);
}

function runApp(which) {
const label = labelFor(which);
const jarPath = VFS_JARS[which];

setStatus(`Opening ${label}…`);
console.log(`Starting FlatLaf ${which} from ${jarPath}`);

// Promise resolves only when JVM exits
cheerpjRunJar(jarPath)
.then(() => {
setStatus(`${label} exited`, { autoResetMs: 6000 });
})
.catch((err) => {
console.error(`${which} failed:`, err);
setStatus(`Failed to open ${label}`, { autoResetMs: 6000 });
});
}
Loading
Loading