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.
96 changes: 96 additions & 0 deletions sites/labs/public/FlatLaf-Demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!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="Choose FlatLaf application">
<button id="btn-demo" class="active" 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 class="status-app">
Active app:
<span id="status-app-name">Demo</span>
</div>
</div>
</aside>
</div>
</section>
</main>

<script src="./main.js"></script>
</body>
</html>
125 changes: 125 additions & 0 deletions sites/labs/public/FlatLaf-Demo/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// 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 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");
const statusAppName = document.getElementById("status-app-name");

let currentApp = null;

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

(async () => {
statusLabel.textContent = "Starting CheerpJ";

await cheerpjInit({
version: 17,
});

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

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

statusLabel.textContent = "Preparing demo files";

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

statusLabel.textContent = "Launching Demo";
runApp("demo");

btnDemo.addEventListener("click", () => runApp("demo"));
btnEditor.addEventListener("click", () => runApp("editor"));
})().catch((err) => {
console.error("Init failed:", err);
statusLabel.textContent = "Failed to start";
});

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}`);
statusLabel.textContent = `Downloading ${labelFor(which)} JAR`;

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) {
if (which === currentApp) return;

currentApp = which;

btnDemo.classList.toggle("active", which === "demo");
btnEditor.classList.toggle("active", which === "editor");

const label = labelFor(which);
statusLabel.textContent = `Launching ${label}…`;
statusAppName.textContent = label;

// Run the jar from VFS path
const jarPath = VFS_JARS[which];

console.log(`Starting FlatLaf ${which} from ${jarPath}`);

cheerpjRunJar(jarPath)
.then((code) => console.log(`${which} exited with code`, code))
.catch((err) => {
console.error(`${which} failed:`, err);
statusLabel.textContent = `Error starting ${label}`;
});
}
Loading
Loading