diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..70c320d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dui"] + path = dui + url = https://github.com/babaissarkar/dui.git diff --git a/dui b/dui new file mode 160000 index 0000000..33ab5bd --- /dev/null +++ b/dui @@ -0,0 +1 @@ +Subproject commit 33ab5bd3d6c2a6a00571014d9acd6bebff210b2c diff --git a/pom.xml b/pom.xml index 01ae159..68c92d0 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,11 @@ + + com.babai.dui + dui + 1.0-SNAPSHOT + com.formdev flatlaf @@ -119,6 +124,7 @@ com.formdev:flatlaf com.formdev:flatlaf-intellij-themes + com.babai.dui:dui diff --git a/src/main/java/com/babai/ssplot/ui/CenteredField.java b/src/main/java/com/babai/ssplot/ui/CenteredField.java index 075417c..ac43fab 100644 --- a/src/main/java/com/babai/ssplot/ui/CenteredField.java +++ b/src/main/java/com/babai/ssplot/ui/CenteredField.java @@ -28,7 +28,7 @@ import javax.swing.JTextField; -import com.babai.ssplot.ui.controls.DUI.Text; +import com.babai.dui.controls.DUI.Text; public class CenteredField extends JTextField { public CenteredField(int count) { diff --git a/src/main/java/com/babai/ssplot/ui/CrashFrame.java b/src/main/java/com/babai/ssplot/ui/CrashFrame.java index 58184a7..5886ea2 100644 --- a/src/main/java/com/babai/ssplot/ui/CrashFrame.java +++ b/src/main/java/com/babai/ssplot/ui/CrashFrame.java @@ -23,7 +23,7 @@ import javax.swing.*; -import com.babai.ssplot.ui.controls.DUI.Text; +import com.babai.dui.controls.DUI.Text; import com.babai.ssplot.util.SystemInfo; import static com.babai.ssplot.util.UIHelper.openLink; diff --git a/src/main/java/com/babai/ssplot/ui/DataView.java b/src/main/java/com/babai/ssplot/ui/DataView.java index 98b9264..902f1ec 100644 --- a/src/main/java/com/babai/ssplot/ui/DataView.java +++ b/src/main/java/com/babai/ssplot/ui/DataView.java @@ -49,9 +49,9 @@ import com.babai.ssplot.math.plot.Axis; import com.babai.ssplot.math.plot.PlotData; -import com.babai.ssplot.ui.controls.DUI.Text; -import com.babai.ssplot.ui.controls.UIFrame; -import static com.babai.ssplot.ui.controls.DUI.*; +import com.babai.dui.controls.DUI.Text; +import com.babai.dui.controls.UIFrame; +import static com.babai.dui.controls.DUI.*; import com.babai.ssplot.util.InfoLogger; import com.babai.ssplot.util.UIHelper; diff --git a/src/main/java/com/babai/ssplot/ui/MainFrame.java b/src/main/java/com/babai/ssplot/ui/MainFrame.java index ddc3295..5fd3efd 100644 --- a/src/main/java/com/babai/ssplot/ui/MainFrame.java +++ b/src/main/java/com/babai/ssplot/ui/MainFrame.java @@ -49,9 +49,9 @@ import com.babai.ssplot.math.io.NumParse; import com.babai.ssplot.math.plot.*; import com.babai.ssplot.math.plot.PlotData.PlotType; -import com.babai.ssplot.ui.controls.DUI.Text; -import com.babai.ssplot.ui.controls.UIButton; -import com.babai.ssplot.ui.controls.UIRadioItem; +import com.babai.dui.controls.DUI.Text; +import com.babai.dui.controls.UIButton; +import com.babai.dui.controls.UIRadioItem; import com.babai.ssplot.ui.help.HelpFrame; import com.babai.ssplot.util.SwingFileChooser; import com.babai.ssplot.util.FocusTracker; @@ -60,7 +60,7 @@ import static javax.swing.JOptionPane.*; import static com.babai.ssplot.cli.ArgParse.*; -import static com.babai.ssplot.ui.controls.DUI.*; +import static com.babai.dui.controls.DUI.*; import static com.babai.ssplot.util.UIHelper.*; public class MainFrame extends JFrame { diff --git a/src/main/java/com/babai/ssplot/ui/PlotFrame.java b/src/main/java/com/babai/ssplot/ui/PlotFrame.java index 4f82171..ce84469 100644 --- a/src/main/java/com/babai/ssplot/ui/PlotFrame.java +++ b/src/main/java/com/babai/ssplot/ui/PlotFrame.java @@ -32,14 +32,14 @@ import com.babai.ssplot.math.plot.Axis; import com.babai.ssplot.math.plot.PlotData; import com.babai.ssplot.math.plot.Plotter; -import com.babai.ssplot.ui.controls.StateVar; -import com.babai.ssplot.ui.controls.UIFrame; -import com.babai.ssplot.ui.controls.UIInput; +import com.babai.dui.controls.StateVar; +import com.babai.dui.controls.UIFrame; +import com.babai.dui.controls.UIInput; -import static com.babai.ssplot.ui.controls.DUI.button; -import static com.babai.ssplot.ui.controls.DUI.input; -import static com.babai.ssplot.ui.controls.DUI.label; -import static com.babai.ssplot.ui.controls.DUI.toolbar; +import static com.babai.dui.controls.DUI.button; +import static com.babai.dui.controls.DUI.input; +import static com.babai.dui.controls.DUI.label; +import static com.babai.dui.controls.DUI.toolbar; import static com.babai.ssplot.util.UIHelper.bindAction; /** diff --git a/src/main/java/com/babai/ssplot/ui/PlotView.java b/src/main/java/com/babai/ssplot/ui/PlotView.java index 4026456..8bd491c 100644 --- a/src/main/java/com/babai/ssplot/ui/PlotView.java +++ b/src/main/java/com/babai/ssplot/ui/PlotView.java @@ -40,7 +40,7 @@ import com.babai.ssplot.math.plot.Plotter; import com.babai.ssplot.math.plot.Project2D; -import com.babai.ssplot.ui.controls.DUI.Text; +import com.babai.dui.controls.DUI.Text; public class PlotView extends JLabel implements MouseListener, MouseMotionListener { diff --git a/src/main/java/com/babai/ssplot/ui/StatLogger.java b/src/main/java/com/babai/ssplot/ui/StatLogger.java index c19768e..7128e22 100644 --- a/src/main/java/com/babai/ssplot/ui/StatLogger.java +++ b/src/main/java/com/babai/ssplot/ui/StatLogger.java @@ -29,7 +29,7 @@ import javax.swing.JTextPane; import javax.swing.ScrollPaneConstants; -import com.babai.ssplot.ui.controls.DUI.Text; +import com.babai.dui.controls.DUI.Text; import com.babai.ssplot.util.InfoLogger; public class StatLogger implements InfoLogger { diff --git a/src/main/java/com/babai/ssplot/ui/SystemInputFrame.java b/src/main/java/com/babai/ssplot/ui/SystemInputFrame.java index e2e6189..a0bed0c 100644 --- a/src/main/java/com/babai/ssplot/ui/SystemInputFrame.java +++ b/src/main/java/com/babai/ssplot/ui/SystemInputFrame.java @@ -37,13 +37,13 @@ import com.babai.ssplot.math.system.core.SystemMode; import com.babai.ssplot.math.system.parser.ParserManager; import com.babai.ssplot.math.system.solver.Solver; -import com.babai.ssplot.ui.controls.DUI.Text; -import com.babai.ssplot.ui.controls.StateVar; -import com.babai.ssplot.ui.controls.UIFrame; -import com.babai.ssplot.ui.controls.UIGrid; -import com.babai.ssplot.ui.controls.UIInput; +import com.babai.dui.controls.DUI.Text; +import com.babai.dui.controls.StateVar; +import com.babai.dui.controls.UIFrame; +import com.babai.dui.controls.UIGrid; +import com.babai.dui.controls.UIInput; -import static com.babai.ssplot.ui.controls.DUI.*; +import static com.babai.dui.controls.DUI.*; /** * This class takes the input from user, sends data to Solver backend, @@ -415,6 +415,12 @@ public EquationSystem getSystem() { return this.builder.build(); } + // FIXME: This method imperatively mutates UI components and builder state, + // bypassing StateVar bindings and derived logic. + // Loading an EquationSystem should be a pure *state* operation: + // system -> StateVar -> UI + builder (via bindings). + // Refactor by promoting equation text and mode into StateVars + // and drive both UI and builder exclusively from state. public void setSystem(EquationSystem system) { if (system == null) return; String[] eqns = system.eqns(); diff --git a/src/main/java/com/babai/ssplot/ui/controls/DUI.java b/src/main/java/com/babai/ssplot/ui/controls/DUI.java deleted file mode 100644 index 2c050ca..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/DUI.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * DUI.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -package com.babai.ssplot.ui.controls; - -import java.awt.Component; -import java.awt.Font; -import java.awt.GraphicsEnvironment; -import java.util.Collection; -import java.util.function.IntFunction; -import java.util.stream.IntStream; - -import javax.swing.Box; -import javax.swing.JComponent; -import javax.swing.JMenuBar; -import javax.swing.JScrollPane; -import javax.swing.JToolBar; - -//TODO this does not mentions what property of this class gets bound -public class DUI { - public static U[] forEach(Collection items, IntFunction mapper, IntFunction arrayCtor) { - return IntStream.range(0, items.size()).mapToObj(mapper).toArray(arrayCtor); - } - - public static U[] forEach(T[] items, IntFunction mapper, IntFunction arrayCtor) { - return IntStream.range(0, items.length).mapToObj(mapper).toArray(arrayCtor); - } - - public static JComponent[] forEach(Collection items, IntFunction mapper) { - return forEach(items, mapper, JComponent[]::new); - } - - public static JComponent[] forEach(T[] items, IntFunction mapper) { - return forEach(items, mapper, JComponent[]::new); - } - - public static UILabel label() { - return new UILabel(); - } - - public static UILabel label(String text) { - return new UILabel().text(text); - } - - public static UIInput input() { - return new UIInput(); - } - - public static UIButton button() { - return new UIButton(); - } - - public static JMenuBar menuBar(Component... children) { - var bar = new JMenuBar(); - for (var child : children) { - bar.add(child); - } - return bar; - } - - public static UIMenu menu(String text) { - return new UIMenu().text(text); - } - - public static UIMenuItem item(String text) { - return new UIMenuItem().text(text); - } - - public static UIRadioItem radioItem(String text) { - return new UIRadioItem().text(text); - } - - public static UICheckItem checkItem(String text) { - return new UICheckItem().text(text); - } - - public static UICheckBox checkBox() { - return new UICheckBox(); - } - - public static UIRadioGroup radioGroup(Class clazz) { - return new UIRadioGroup<>(); - } - - public static JScrollPane scrollPane(JComponent child) { - return new JScrollPane( - child, - JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, - JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - } - - public static UIBorderPane borderPane() { - return new UIBorderPane(); - } - - public static UIHBox hbox(Component... children) { - var hbox = new UIHBox(); - for (var child : children) { - hbox.add(child); - } - return hbox; - } - - public static UIVBox vbox(Component... children) { - var vbox = new UIVBox(); - for (var child : children) { - vbox.add(child); - } - return vbox; - } - - public static UIVBox vbox(int vgap, Component... children) { - var vbox = new UIVBox(); - boolean isFirst = true; - for (var child : children) { - vbox.add(child); - if (!isFirst) { - vbox.add(Box.createVerticalStrut(vgap)); - } else { - isFirst = false; - } - } - return vbox; - } - - public static UIGrid grid() { - return new UIGrid(); - } - - public static UITabPane tabPane() { - return new UITabPane(); - } - - public static UISplitPane splitPane() { - return new UISplitPane(); - } - - public static JToolBar toolbar(Component... children) { - var toolbar = new JToolBar(); - for (var child : children) { - toolbar.add(child); - } - return toolbar; - } - - public static UIFrame iframe() { - return new UIFrame(); - } - - public static UIFrame iframe(String title) { - return iframe().title(title); - } - - public class Text { - - public static String bold(String text) { - return htmlAndBody(tag("b", text)); - } - - public static String htmlAndBody(String text) { - return tag("html", tag("body", text)); - } - - public static String tag(String tagName, String text) { - return "<%s>%s".formatted(tagName, text, tagName); - } - - public static String tag(String tagName, String attribute, String text) { - return "<%s %s>%s".formatted(tagName, attribute, text, tagName); - } - - public final static String LBREAK = "
"; - - // Fonts - public final static Font baseFont, headerFont; - public final static Font monoFont; - public final static Font fallbackFont; - - static { - Font f = null; - fallbackFont = new Font("Sans", Font.PLAIN, 18); - monoFont = new Font("monospace", Font.PLAIN, 14); - - final String fontPath = "/fonts/Inter-Regular.ttf"; - try (var is = Text.class.getResourceAsStream(fontPath)) { - f = Font.createFont(Font.TRUETYPE_FONT, is); - GraphicsEnvironment - .getLocalGraphicsEnvironment() - .registerFont(f); - } catch (Exception e) { - System.err.println("Failed to load bundled font, falling back to system default."); - f = fallbackFont.deriveFont(Font.PLAIN, 15f); - } - baseFont = f.deriveFont(Font.PLAIN, 15f); - - final String fontPathBold = "/fonts/Inter-SemiBold.ttf"; - try (var is = Text.class.getResourceAsStream(fontPathBold)) { - f = Font.createFont(Font.TRUETYPE_FONT, is); - GraphicsEnvironment - .getLocalGraphicsEnvironment() - .registerFont(f); - } catch (Exception e) { - System.err.println("Failed to load bundled font, falling back to system default."); - f = fallbackFont.deriveFont(Font.PLAIN, 15f); - } - headerFont = f.deriveFont(Font.PLAIN, 17f); - } - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/StateVar.java b/src/main/java/com/babai/ssplot/ui/controls/StateVar.java deleted file mode 100644 index 6104053..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/StateVar.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * StateVar.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -package com.babai.ssplot.ui.controls; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.BiFunction; -import java.util.function.Consumer; -import java.util.function.Function; - -public class StateVar { - private T value; - private List> runners = new ArrayList<>(); - - public StateVar(T value) { - this.value = value; - } - - public T get() { - return value; - } - - public void set(T value) { - if (Objects.equals(this.value, value)) { - return; - } - - this.value = value; - for (var runner : runners) { - runner.accept(value); - } - } - - public void onChange(Consumer r) { - this.runners.add(r); - } - - public void unbindAll() { - this.runners.clear(); - } - - // RULE: when() predicates must only read StateVars - public StateVar when(Function mapper) { - StateVar derived = new StateVar<>(mapper.apply(get())); - onChange(val -> derived.set(mapper.apply(val))); - return derived; - } - - public StateVar whenAny(List values) { - return this.when(val -> { - boolean res = false; - for (var v : values) { - if (v.equals(val)) { - res = true; - } - } - return res; - }); - } - - public static StateVar combine( - StateVar a, - StateVar b, - BiFunction fn - ) { - StateVar out = new StateVar<>(fn.apply(a.get(), b.get())); - - final AtomicReference av = new AtomicReference<>(a.get()); - final AtomicReference bv = new AtomicReference<>(b.get()); - - a.onChange(v -> { - av.set(v); - out.set(fn.apply(av.get(), bv.get())); - }); - - b.onChange(v -> { - bv.set(v); - out.set(fn.apply(av.get(), bv.get())); - }); - - return out; - } - - @FunctionalInterface - public interface TriFunction { - R apply(A a, B b, C c); - } - - public static StateVar combine( - StateVar a, - StateVar b, - StateVar c, - TriFunction fn - ) { - StateVar out = new StateVar<>(fn.apply(a.get(), b.get(), c.get())); - - final AtomicReference av = new AtomicReference<>(a.get()); - final AtomicReference bv = new AtomicReference<>(b.get()); - final AtomicReference cv = new AtomicReference<>(c.get()); - - a.onChange(v -> { - av.set(v); - out.set(fn.apply(av.get(), bv.get(), cv.get())); - }); - - b.onChange(v -> { - bv.set(v); - out.set(fn.apply(av.get(), bv.get(), cv.get())); - }); - - c.onChange(v -> { - cv.set(v); - out.set(fn.apply(av.get(), bv.get(), cv.get())); - }); - - return out; - } - -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UIBorderPane.java b/src/main/java/com/babai/ssplot/ui/controls/UIBorderPane.java deleted file mode 100644 index 129eb69..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UIBorderPane.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * UIBorderPane.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -package com.babai.ssplot.ui.controls; - -import java.awt.BorderLayout; -import java.awt.Component; - -import javax.swing.JPanel; - -public class UIBorderPane extends JPanel implements UIStylizable { - private BorderLayout layout; - - public UIBorderPane() { - layout = new BorderLayout(); - setLayout(layout); - } - - public UIBorderPane north(Component c) { - add(c, BorderLayout.NORTH); - return this; - } - - public UIBorderPane south(Component c) { - add(c, BorderLayout.SOUTH); - return this; - } - - public UIBorderPane east(Component c) { - add(c, BorderLayout.EAST); - return this; - } - - public UIBorderPane west(Component c) { - add(c, BorderLayout.WEST); - return this; - } - - public UIBorderPane center(Component c) { - add(c, BorderLayout.CENTER); - return this; - } - -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UIButton.java b/src/main/java/com/babai/ssplot/ui/controls/UIButton.java deleted file mode 100644 index 416b55f..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UIButton.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * UIButton.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -package com.babai.ssplot.ui.controls; - -import java.awt.Insets; - -import javax.swing.ImageIcon; -import javax.swing.JButton; - -public class UIButton extends JButton implements UIStylizable { - - public UIButton icon(String resource) { - setIcon(new ImageIcon(getClass().getResource(resource))); - return this; - } - - public UIButton text(String text) { - setText(text); - return this; - } - - public UIButton tooltip(String tip) { - setToolTipText(tip); - return this; - } - - public UIButton margin(int top, int left, int bottom, int right) { - setMargin(new Insets(top, left, bottom, right)); - return this; - } - - public UIButton margin(int gap) { - return margin(gap, gap, gap, gap); - } - - // statevar change -> enabled property change - public UIButton enabled(StateVar enabled) { - setEnabled(enabled.get()); - enabled.onChange(e -> setEnabled(e)); - return this; - } - - public UIButton enabled(boolean enabled) { - setEnabled(enabled); - return this; - } - - public UIButton onClick(Runnable action) { - addActionListener(e -> action.run()); - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UICheckBox.java b/src/main/java/com/babai/ssplot/ui/controls/UICheckBox.java deleted file mode 100644 index 5e54f31..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UICheckBox.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * UICheckBox.java - * - * Copyright 2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -package com.babai.ssplot.ui.controls; - -import javax.swing.JCheckBox; - -public class UICheckBox extends JCheckBox - implements UIStylizable, UIStateful -{ - public UICheckBox text(String text) { - setText(text); - return this; - } - - public UICheckBox selected(boolean sel) { - setSelected(sel); - return this; - } - - public UICheckBox onClick(Runnable action) { - addActionListener(e -> action.run()); - return this; - } - - // Binding type: selection StateVar -> JCheckBox's selection (on/off) - public UICheckBox bindSelectionFrom(StateVar selection) { - setSelected(selection.get()); - selection.onChange(selected -> setSelected(selected)); - return this; - } - - // Binding type: selection StateVar <- JCheckBox's selection (on/off) - public UICheckBox bindSelectionTo(StateVar selection) { - selection.set(this.isSelected()); - this.onClick(() -> selection.set(this.isSelected())); - return this; - } -} - diff --git a/src/main/java/com/babai/ssplot/ui/controls/UICheckBoxItem.java b/src/main/java/com/babai/ssplot/ui/controls/UICheckBoxItem.java deleted file mode 100644 index 1e4a22c..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UICheckBoxItem.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * UICheckBoxItem.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -package com.babai.ssplot.ui.controls; - -import javax.swing.JCheckBoxMenuItem; - -public class UICheckBoxItem extends JCheckBoxMenuItem { - - public UICheckBoxItem selected(boolean sel) { - setSelected(sel); - return this; - } - - public UICheckBoxItem onClick(Runnable action) { - addActionListener(e -> action.run()); - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UICheckItem.java b/src/main/java/com/babai/ssplot/ui/controls/UICheckItem.java deleted file mode 100644 index d3eb3a2..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UICheckItem.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * UICheckItem.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -package com.babai.ssplot.ui.controls; - -import javax.swing.JCheckBoxMenuItem; - -public class UICheckItem extends JCheckBoxMenuItem { - public UICheckItem text(String text) { - setText(text); - return this; - } - - public UICheckItem selected(boolean sel) { - setSelected(sel); - return this; - } - - public UICheckItem onClick(Runnable action) { - addActionListener(e -> action.run()); - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UIFrame.java b/src/main/java/com/babai/ssplot/ui/controls/UIFrame.java deleted file mode 100644 index 871d5cf..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UIFrame.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * UIFrame.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -package com.babai.ssplot.ui.controls; - -import java.awt.Component; -import java.awt.LayoutManager; - -import javax.swing.JInternalFrame; -import javax.swing.SwingUtilities; - -import com.babai.ssplot.ui.CrashFrame; - -import static com.babai.ssplot.ui.controls.DUI.borderPane; - -public class UIFrame extends JInternalFrame implements UIStylizable { - - public UIFrame() { - super(); - setDefaultCloseOperation(HIDE_ON_CLOSE); - } - - public UIFrame title(String title) { - setTitle(title); - return this; - } - - public UIFrame size(int width, int height) { - setSize(width, height); - return this; - } - - public UIFrame location(int x, int y) { - setLocation(x, y); - return this; - } - - public UIFrame closeOperation(int operation) { - setDefaultCloseOperation(operation); - return this; - } - - public UIFrame visible(boolean visible) { - setVisible(visible); - return this; - } - - public UIFrame resizable(boolean resizable) { - setResizable(resizable); - return this; - } - - public UIFrame closable(boolean closable) { - setClosable(closable); - return this; - } - - public UIFrame maximizable(boolean maximizable) { - setMaximizable(maximizable); - return this; - } - - public UIFrame iconifiable(boolean iconifiable) { - setIconifiable(iconifiable); - return this; - } - - public UIFrame content(Component component) { - setContentPane(borderPane().center(component)); - return this; - } - - public UIFrame layout(LayoutManager layout) { - getContentPane().setLayout(layout); - return this; - } - - public UIFrame packFrame() { - pack(); - return this; - } - - public UIFrame moveToFrontLater() { - SwingUtilities.invokeLater(() -> { - try { - setSelected(true); - moveToFront(); - } catch (Exception e) { - //FIXME do we really want to do this in DUI code? - CrashFrame.showCrash(e); - } - }); - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UIGrid.java b/src/main/java/com/babai/ssplot/ui/controls/UIGrid.java deleted file mode 100644 index c7ab55b..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UIGrid.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * UIGrid.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -package com.babai.ssplot.ui.controls; - -import java.awt.Component; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; - -import javax.swing.JPanel; - -public class UIGrid extends JPanel - implements UIStylizable, UIStateful -{ - private GridBagConstraints gbc; - - public UIGrid() { - gbc = new GridBagConstraints(); - gbc.gridx = 0; - gbc.gridy = 0; - setLayout(new GridBagLayout()); - } - - public UIGrid anchor(int anchor) { - gbc.anchor = anchor; - return this; - } - - public UIGrid fill(int fill) { - gbc.fill = fill; - return this; - } - - public UIGrid insets(Insets insets) { - gbc.insets = insets; - return this; - } - - public UIGrid insets(int gap) { - gbc.insets = new Insets(gap, gap, gap, gap); - return this; - } - - public UIGrid weightx(double weightx) { - gbc.weightx = weightx; - return this; - } - - public UIGrid weighty(double weighty) { - gbc.weighty = weighty; - return this; - } - - public UIGrid spanx(int span) { - gbc.gridwidth = span; - return this; - } - - public UIGrid spany(int span) { - gbc.gridheight = span; - return this; - } - - public UIGrid padx(int pad) { - gbc.ipadx = pad; - return this; - } - - public UIGrid pady(int pad) { - gbc.ipady = pad; - return this; - } - - public UIGrid row() { - gbc.gridwidth = 1; - gbc.gridx = 0; - gbc.weightx = 0; - gbc.fill = GridBagConstraints.NONE; - gbc.gridy++; - return this; - } - - public UIGrid column(Component comp) { - add(comp, gbc); - gbc.gridx++; - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UIHBox.java b/src/main/java/com/babai/ssplot/ui/controls/UIHBox.java deleted file mode 100644 index 61c8fe0..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UIHBox.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * UIHBox.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -package com.babai.ssplot.ui.controls; - -import java.awt.FlowLayout; -import javax.swing.JPanel; - -/** specialization of JPanel that acts like a horizontal box */ -public class UIHBox extends JPanel - implements UIStylizable, UIStateful -{ - private FlowLayout layout; - - public UIHBox() { - layout = new FlowLayout(); - setLayout(layout); - } - - public UIHBox align(int align) { - layout.setAlignment(align); - setLayout(layout); - return this; - } - - public UIHBox gap(int hgap, int vgap) { - layout.setHgap(hgap); - layout.setVgap(vgap); - setLayout(layout); - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UIInput.java b/src/main/java/com/babai/ssplot/ui/controls/UIInput.java deleted file mode 100644 index 523b8c6..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UIInput.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * UIInput.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -package com.babai.ssplot.ui.controls; - -import java.awt.Insets; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.util.function.Consumer; - -import javax.swing.JTextField; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; - -import com.babai.ssplot.ui.controls.DUI.Text; - -public class UIInput extends JTextField - implements UIStylizable, UIStateful -{ - public UIInput() { - setFont(Text.monoFont); - setMargin(new Insets(5, 5, 5, 5)); - setHorizontalAlignment(JTextField.CENTER); - } - - public UIInput chars(int columns) { - setColumns(columns); - return this; - } - - public UIInput text(String text) { - setText(text); - return this; - } - - public UIInput numeric(boolean numeric) { - var keyListener = new KeyAdapter() { - public void keyTyped(KeyEvent e) { - char c = e.getKeyChar(); - if (!Character.isDigit(c) && c != '-' && - !Character.isISOControl(c)) { - if ( (c == '.' && getText().contains(".")) || c != '.' ) { - e.consume(); - } - } - } - }; - - if (numeric) { - addKeyListener(keyListener); - } else { - removeKeyListener(keyListener); - } - - return this; - } - - public boolean empty() { - return getText().isEmpty(); - } - - public Double value() { - return empty() ? 0.0 : Double.parseDouble(getText()); - } - - public Integer intValue() { - return empty() ? 0 : Integer.parseInt(getText()); - } - - public UIInput onChange(Runnable action) { - getDocument().addDocumentListener(new DocumentListener() { - @Override - public void insertUpdate(DocumentEvent e) { - action.run(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - action.run(); - } - - @Override - public void changedUpdate(DocumentEvent e) { - action.run(); - } - }); - return this; - } - - public UIInput onChange(Consumer textAction) { - getDocument().addDocumentListener(new DocumentListener() { - @Override - public void insertUpdate(DocumentEvent e) { - runUpdateActions(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - runUpdateActions(); - } - - @Override - public void changedUpdate(DocumentEvent e) { - runUpdateActions(); - } - - private void runUpdateActions() { -// String text = getText(); -// if (!text.isEmpty()) { - textAction.accept(getText()); -// } - } - }); - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UILabel.java b/src/main/java/com/babai/ssplot/ui/controls/UILabel.java deleted file mode 100644 index b3a5adf..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UILabel.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * UILabel.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -package com.babai.ssplot.ui.controls; - -import java.awt.Component; -import java.awt.Font; - -import javax.swing.JLabel; - -public class UILabel extends JLabel - implements UIStylizable, UIStateful -{ - public UILabel() { - // for now, labels are left aligned inside layout manager by default - setAlignmentX(Component.LEFT_ALIGNMENT); - } - - public UILabel text(String text) { - setText(text); - return this; - } - - // Binding type: text StateVar -> JLabel's text - public UILabel bindTextFrom(StateVar text) { - setText(text.get()); - text.onChange(str -> setText(str)); - return this; - } - - public UILabel font(Font font) { - setFont(font); - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UIMenu.java b/src/main/java/com/babai/ssplot/ui/controls/UIMenu.java deleted file mode 100644 index 9ca7f5a..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UIMenu.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * UIMenu.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -package com.babai.ssplot.ui.controls; - -import java.awt.Component; - -import javax.swing.JMenu; - -public class UIMenu extends JMenu { - - public UIMenu text(String text) { - setText(text); - return this; - } - - public UIMenu content(Component... children) { - for (var child : children) { - this.add(child); - } - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UIMenuItem.java b/src/main/java/com/babai/ssplot/ui/controls/UIMenuItem.java deleted file mode 100644 index 598e9f0..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UIMenuItem.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * UIMenuItem.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -package com.babai.ssplot.ui.controls; - -import javax.swing.JMenuItem; -import javax.swing.KeyStroke; - -public class UIMenuItem extends JMenuItem { - - public UIMenuItem text(String text) { - setText(text); - return this; - } - - public UIMenuItem hotkey(String shortcut) { - this.setAccelerator(KeyStroke.getKeyStroke(shortcut)); - return this; - } - - public UIMenuItem onClick(Runnable action) { - this.addActionListener(e -> action.run()); - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UIRadioGroup.java b/src/main/java/com/babai/ssplot/ui/controls/UIRadioGroup.java deleted file mode 100644 index 73db0af..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UIRadioGroup.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * UIRadioGroup.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -package com.babai.ssplot.ui.controls; - -import javax.swing.ButtonGroup; -import javax.swing.JRadioButton; - -public class UIRadioGroup extends UIHBox { - private StateVar selected = null; - private ButtonGroup group = new ButtonGroup(); - - public UIRadioGroup options(E[] values, E selected) { - if (values == null) return this; - - this.selected = new StateVar<>(selected); - - for (int i = 0; i < values.length; i++) { - var radio = new JRadioButton(values[i].toString()); - group.add(radio); - add(radio); - - if (values[i] == selected) { - this.selected.set(selected); - radio.setSelected(true); - } - - final int idx = i; - radio.addActionListener(e -> { - if (radio.isSelected()) { - this.selected.set(values[idx]); - } - }); - } - - // no match found or null passed as selected - if (selected == null) { - this.selected.set(values[0]); - } - return this; - } - - // Binding type: selection StateVar <- RadioGroup's selection - public UIRadioGroup bindSelectionTo(StateVar selection) { - if (selection != null) { - this.selected = selection; - } - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UIRadioItem.java b/src/main/java/com/babai/ssplot/ui/controls/UIRadioItem.java deleted file mode 100644 index e894229..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UIRadioItem.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * UIRadioItem.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -package com.babai.ssplot.ui.controls; - -import javax.swing.JRadioButtonMenuItem; - -public class UIRadioItem extends JRadioButtonMenuItem { - public UIRadioItem text(String text) { - setText(text); - return this; - } - - public UIRadioItem selected(boolean sel) { - setSelected(sel); - return this; - } - - public UIRadioItem onClick(Runnable action) { - addActionListener(e -> action.run()); - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UISplitPane.java b/src/main/java/com/babai/ssplot/ui/controls/UISplitPane.java deleted file mode 100644 index 764e13a..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UISplitPane.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * UISplitPane.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -package com.babai.ssplot.ui.controls; - -import java.awt.Component; - -import javax.swing.JSplitPane; - -public class UISplitPane extends JSplitPane { - - public UISplitPane type(int orientation) { - setOrientation(orientation); - return this; - } - - public UISplitPane dividerLoc(int loc) { - setDividerLocation(loc); - return this; - } - - public UISplitPane top(Component c) { - setTopComponent(c); - return this; - } - - public UISplitPane bottom(Component c) { - setBottomComponent(c); - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UIStateful.java b/src/main/java/com/babai/ssplot/ui/controls/UIStateful.java deleted file mode 100644 index e89a53b..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UIStateful.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * UIStateful.java - * - * Copyright 2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -package com.babai.ssplot.ui.controls; - -import javax.swing.JComponent; - -@SuppressWarnings("unchecked") -public interface UIStateful { - - // statevar change -> enabled property change - default T enabled(StateVar enabled) { - ((JComponent) this).setEnabled(enabled.get()); - enabled.onChange(e -> ((JComponent) this).setEnabled(e)); - return (T) this; - } - - default T enabled(boolean enabled) { - ((JComponent) this).setEnabled(enabled); - return (T) this; - } - - // statevar change -> visible property change - default T visible(StateVar visible) { - ((JComponent) this).setVisible(visible.get()); - visible.onChange(v -> ((JComponent) this).setVisible(v)); - return (T) this; - } - - default T visible(boolean visible) { - ((JComponent) this).setVisible(visible); - return (T) this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UIStylizable.java b/src/main/java/com/babai/ssplot/ui/controls/UIStylizable.java deleted file mode 100644 index 07b7cc4..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UIStylizable.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * UIStylizable.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -package com.babai.ssplot.ui.controls; - -import java.awt.Color; -import java.awt.Font; - -import javax.swing.BorderFactory; -import javax.swing.JComponent; -import javax.swing.border.Border; -import javax.swing.border.TitledBorder; - -/** - * A trait-style interface that adds fluent appearance-setting methods to Swing components. - *

- * This interface is designed to be used as a mixin for classes that already extend - * {@link JComponent}. It provides default methods like {@code border(...)} and - * {@code emptyBorder(...)} that operate directly on {@code this}, enabling a - * fluent API for UI configuration. - *

- * - *

- * To use this trait, a class should both extend a {@code JComponent} subclass - * and implement {@code UIBordered}, like so: - *

- * - *
{@code
- * public class MyPanel extends JPanel implements UIBordered {
- *     public MyPanel() {
- *         emptyBorder(10).bg(Color.LIGHT_GRAY);
- *     }
- * }
- * }
- * - *

- * This approach simulates trait or mixin behavior in Java, allowing you to - * compose UI behaviors in a reusable and expressive way. - *

- * - * @param the concrete type of the component extending {@link JComponent} - */ - -@SuppressWarnings("unchecked") -public interface UIStylizable { - - default T bg(Color c) { - ((JComponent) this).setBackground(c); - return (T) this; - } - - default T fg(Color c) { - ((JComponent) this).setForeground(c); - return (T) this; - } - - default T font(Font f) { - ((JComponent) this).setFont(f); - return (T) this; - } - - default T border(Border b) { - ((JComponent) this).setBorder(b); - return (T) this; - } - - default T emptyBorder(int gap) { - return border(BorderFactory.createEmptyBorder(gap, gap, gap, gap)); - } - - default T emptyBorder(int top, int left, int bottom, int right) { - return border(BorderFactory.createEmptyBorder(top, left, bottom, right)); - } - - default TitledBorderBuilder titledBorder() { - return new TitledBorderBuilder<>((T) this); - } - - /** - * A fluent builder for configuring a titled border and applying it to a component. - */ - class TitledBorderBuilder { - private final T component; - private Border border = BorderFactory.createLineBorder(Color.GRAY); - private String title = ""; - private int justification = TitledBorder.DEFAULT_JUSTIFICATION; - private int position = TitledBorder.DEFAULT_POSITION; - private Font font = null; - private Color color = null; - - public TitledBorderBuilder(T component) { - this.component = component; - } - - public TitledBorderBuilder lineBorder(Color c, int thickness) { - this.border = BorderFactory.createLineBorder(c, thickness); - return this; - } - - public TitledBorderBuilder title(String title) { - this.title = title; - return this; - } - - public TitledBorderBuilder justify(int justification) { - this.justification = justification; - return this; - } - - public TitledBorderBuilder position(int position) { - this.position = position; - return this; - } - - public TitledBorderBuilder font(Font font) { - this.font = font; - return this; - } - - public TitledBorderBuilder color(Color color) { - this.color = color; - return this; - } - - public T apply() { - TitledBorder tb = BorderFactory.createTitledBorder( - border, title, justification, position, font, color); - component.setBorder(tb); - return component; - } - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UITabPane.java b/src/main/java/com/babai/ssplot/ui/controls/UITabPane.java deleted file mode 100644 index 1cd29de..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UITabPane.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * UITabPane.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -package com.babai.ssplot.ui.controls; - -import java.awt.Component; -import java.util.function.Consumer; - -import javax.swing.JTabbedPane; - -public class UITabPane extends JTabbedPane { - public UITabPane tab(String tabName, Component c) { - addTab(tabName, c); - return this; - } - - public UITabPane onChange(Consumer action) { - addChangeListener(e -> action.accept(getSelectedIndex())); - return this; - } -} diff --git a/src/main/java/com/babai/ssplot/ui/controls/UIVBox.java b/src/main/java/com/babai/ssplot/ui/controls/UIVBox.java deleted file mode 100644 index ad2dc10..0000000 --- a/src/main/java/com/babai/ssplot/ui/controls/UIVBox.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * UIVBox.java - * - * Copyright 2025-2026 Subhraman Sarkar - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -package com.babai.ssplot.ui.controls; - -import javax.swing.BoxLayout; -import javax.swing.JPanel; - -public class UIVBox extends JPanel implements UIStylizable { - private BoxLayout layout; - - public UIVBox() { - layout = new BoxLayout(this, BoxLayout.PAGE_AXIS); - setLayout(layout); - } -} diff --git a/src/main/java/com/babai/ssplot/util/SystemInfo.java b/src/main/java/com/babai/ssplot/util/SystemInfo.java index 65bd5c9..68c9e41 100644 --- a/src/main/java/com/babai/ssplot/util/SystemInfo.java +++ b/src/main/java/com/babai/ssplot/util/SystemInfo.java @@ -28,7 +28,7 @@ import com.babai.ssplot.ui.CrashFrame; import com.babai.ssplot.ui.MainFrame; -import static com.babai.ssplot.ui.controls.DUI.Text.*; +import static com.babai.dui.controls.DUI.Text.*; public class SystemInfo { diff --git a/src/main/java/com/babai/ssplot/util/UIHelper.java b/src/main/java/com/babai/ssplot/util/UIHelper.java index c2f5d9d..ad2e778 100644 --- a/src/main/java/com/babai/ssplot/util/UIHelper.java +++ b/src/main/java/com/babai/ssplot/util/UIHelper.java @@ -46,7 +46,7 @@ import com.babai.ssplot.ui.CrashFrame; import com.babai.ssplot.ui.MainFrame; -import com.babai.ssplot.ui.controls.DUI; +import com.babai.dui.controls.DUI; import com.formdev.flatlaf.intellijthemes.FlatArcDarkOrangeIJTheme; import com.formdev.flatlaf.intellijthemes.FlatArcOrangeIJTheme; import com.formdev.flatlaf.util.SystemInfo; diff --git a/src/main/resources/fonts/Inter-Regular.ttf b/src/main/resources/fonts/Inter-Regular.ttf deleted file mode 100644 index b7aaca8..0000000 Binary files a/src/main/resources/fonts/Inter-Regular.ttf and /dev/null differ diff --git a/src/main/resources/fonts/Inter-SemiBold.ttf b/src/main/resources/fonts/Inter-SemiBold.ttf deleted file mode 100644 index 47f8ab1..0000000 Binary files a/src/main/resources/fonts/Inter-SemiBold.ttf and /dev/null differ