package com.widgetworkbench.cheerpj; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Frame; import java.util.concurrent.atomic.AtomicReference; import javax.swing.JFrame; import javax.swing.JSplitPane; import javax.swing.SwingUtilities; /** * Optional adapter for resizing the iTAC MES.Suite Workplace inside a CheerpJ display. * No iTAC class dependencies, no modifications to vendor-signed JARs. * The adapter must be loaded into the SAME JVM as the Workplace. * This affects the Swing frame, NOT browser-side display scaling. */ public final class WorkplaceResizeBridge { private static final String FRAME_NAME = "com.itac.mes.suite.presentation.MesSuiteFrame"; private static final String PANEL_NAME = "com.itac.mes.gui.suite.MesSuitePanel"; private WorkplaceResizeBridge() { } /** * Requests a resize of the matching iTAC Workplace window. * Returns number of matching frames found; update may be scheduled on EDT. */ public static int resize(final int width, final int height) { if (width < 200 || height < 150 || width > 16000 || height > 16000) { return 0; } int matches = 0; for (final Frame frame : Frame.getFrames()) { if (!(frame instanceof JFrame) || !FRAME_NAME.equals(frame.getClass().getName())) { continue; } final JFrame window = (JFrame) frame; final Container content = window.getContentPane(); if (content == null || !PANEL_NAME.equals(content.getClass().getName())) { continue; } matches++; final Runnable action = new Runnable() { @Override public void run() { if (!window.isDisplayable()) return; // MesSuitePanel contains BorderLayout: north toolbar, center split navigation. // Respect iTAC navigation preference (divider initially at 150 px). window.setSize(width, height); window.setLocation(0, 0); content.invalidate(); window.validate(); window.repaint(); } }; if (SwingUtilities.isEventDispatchThread()) action.run(); else SwingUtilities.invokeLater(action); } return matches; } /** Inspect live dimensions without changing iTAC settings or window sizes. */ public static String diagnose() { final AtomicReference result = new AtomicReference("diagnostic unavailable"); Runnable task = new Runnable() { @Override public void run() { StringBuilder sb = new StringBuilder(); int count = 0; for (Frame frame : Frame.getFrames()) { if (!(frame instanceof JFrame) || !FRAME_NAME.equals(frame.getClass().getName())) continue; JFrame window = (JFrame) frame; Container panel = window.getContentPane(); if (panel == null || !PANEL_NAME.equals(panel.getClass().getName())) continue; count++; appendSize(sb, "frame", window); appendSize(sb, "MesSuitePanel", panel); JSplitPane split = findSplit(panel); if (split == null) sb.append("split: not yet mounted; "); else { appendSize(sb, "split", split); sb.append("dividerPx=").append(split.getDividerLocation()).append("; "); } } if (count == 0) sb.append("Workplace window not found"); result.set(sb.toString()); } }; if (SwingUtilities.isEventDispatchThread()) task.run(); else { try { SwingUtilities.invokeAndWait(task); } catch (Exception ex) { return "diagnostic error: " + ex.getClass().getSimpleName(); } } return result.get(); } private static void appendSize(StringBuilder sb, String title, Component c) { Dimension preferred = c.getPreferredSize(); Dimension minimum = c.getMinimumSize(); Dimension actual = c.getSize(); sb.append(title).append("=").append(actual.width).append('x').append(actual.height) .append(" pref=").append(preferred.width).append('x').append(preferred.height) .append(" min=").append(minimum.width).append('x').append(minimum.height) .append("; "); } private static JSplitPane findSplit(Container parent) { for (Component child : parent.getComponents()) { if (child instanceof JSplitPane) return (JSplitPane) child; if (child instanceof Container) { JSplitPane found = findSplit((Container) child); if (found != null) return found; } } return null; } }