From 9ebd11feee8aa679b58ee8502bc09bb7178eeff6 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Sun, 10 Sep 2023 23:04:40 -0500 Subject: [PATCH 01/93] svg loader for UI icons --- pom.xml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d2ea194..7470132 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ me.knighthat InteractiveDeckDesktop - 0.0.2 + 0.0.3 Interactive Deck @@ -83,7 +83,6 @@ org.slf4j slf4j-api 2.0.7 - compile ch.qos.logback @@ -95,6 +94,16 @@ gson 2.8.9 + + org.apache.xmlgraphics + batik-dom + 1.17 + + + org.apache.xmlgraphics + batik-swing + 1.17 + \ No newline at end of file From 98ec6ed85326e6f1c8e342e3a19c3a2b43534393 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Sun, 10 Sep 2023 23:05:30 -0500 Subject: [PATCH 02/93] shows UUID next to display name --- .../interactivedeck/component/plist/PBoxRenderer.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/knighthat/interactivedeck/component/plist/PBoxRenderer.java b/src/main/java/me/knighthat/interactivedeck/component/plist/PBoxRenderer.java index 956a7d8..e468ae5 100644 --- a/src/main/java/me/knighthat/interactivedeck/component/plist/PBoxRenderer.java +++ b/src/main/java/me/knighthat/interactivedeck/component/plist/PBoxRenderer.java @@ -16,17 +16,19 @@ import me.knighthat.interactivedeck.file.Profile; +import me.knighthat.interactivedeck.utils.UuidUtils; import javax.swing.*; import java.awt.*; public class PBoxRenderer extends JLabel implements ListCellRenderer { - public PBoxRenderer() { - } - public Component getListCellRendererComponent( JList list, Profile profile, int i, boolean isSelected, boolean cellHasFocus ) { - super.setText( profile == null ? "" : profile.displayName() ); + String display = "NULL (You weren't supposed to see this)"; + if (profile != null) + display = "%s (%s)".formatted( profile.displayName(), UuidUtils.lastFiveChars( profile.uuid ) ); + + super.setText( display ); super.setBackground( isSelected ? list.getSelectionBackground() : list.getBackground() ); super.setForeground( isSelected ? list.getSelectionForeground() : list.getForeground() ); return this; From c5bd34dc8d1e8bfcfb894b3a9914c69ca5ec60a7 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Sun, 10 Sep 2023 23:11:26 -0500 Subject: [PATCH 03/93] moved buttons to JSVGCanvas components --- .../interactivedeck/menus/MainMenu.java | 91 +++++++------------ 1 file changed, 35 insertions(+), 56 deletions(-) diff --git a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java index 0be688b..28abc76 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java @@ -17,11 +17,10 @@ import java.awt.event.WindowEvent; import javax.swing.*; import me.knighthat.interactivedeck.component.ibutton.IButton; -import me.knighthat.interactivedeck.component.netstatus.ConStatus; -import me.knighthat.interactivedeck.component.plist.ProfilesComboBox; -import me.knighthat.interactivedeck.file.Profile; +import me.knighthat.interactivedeck.component.plist.ProfileButton; import me.knighthat.interactivedeck.connection.Connection; -import me.knighthat.interactivedeck.logging.Log; +import me.knighthat.interactivedeck.file.Profile; + import me.knighthat.interactivedeck.json.Json; import me.knighthat.interactivedeck.observable.Observable; import me.knighthat.interactivedeck.utils.ColorUtils; @@ -29,7 +28,6 @@ import me.knighthat.interactivedeck.utils.UuidUtils;import org.jetbrains.annotations.NotNull; import static me.knighthat.interactivedeck.file.Settings.*; - /** * * @author knighthat @@ -87,14 +85,14 @@ public void windowClosing(WindowEvent e) { private void initComponents() { javax.swing.JPanel profilesSection = new javax.swing.JPanel(); - javax.swing.JButton addProfileButton = new javax.swing.JButton(); - javax.swing.JButton removeProfileButton = new javax.swing.JButton(); - javax.swing.JButton configureProfileButton = new javax.swing.JButton(); - profilesList = new ProfilesComboBox(); + profilesList = new me.knighthat.interactivedeck.component.plist.ProfilesComboBox(); + me.knighthat.interactivedeck.component.plist.ProfileButton addProfileButton = new ProfileButton(ProfileButton.ButtonType.ADD); + me.knighthat.interactivedeck.component.plist.ProfileButton removeProfileButton = new ProfileButton(ProfileButton.ButtonType.REMOVE); + me.knighthat.interactivedeck.component.plist.ProfileButton configureProfileButton = new ProfileButton(ProfileButton.ButtonType.CONFIGURE); iBtnSection = new javax.swing.JPanel(); btnModifierSection = new javax.swing.JPanel(); javax.swing.JPanel statusSection = new javax.swing.JPanel(); - ConStatus conStatus = Connection.component(); + me.knighthat.interactivedeck.component.netstatus.ConStatus conStatus = Connection.component(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setBackground(new java.awt.Color(153, 153, 153)); @@ -106,52 +104,43 @@ private void initComponents() { profilesSection.setBackground(new java.awt.Color(36, 36, 36)); profilesSection.setPreferredSize(new java.awt.Dimension(1000, 50)); - addProfileButton.setBackground(new java.awt.Color(51, 51, 51)); - addProfileButton.setText("Add"); - addProfileButton.setAlignmentY(0.0F); - addProfileButton.setMaximumSize(new java.awt.Dimension(100, 30)); - addProfileButton.setMinimumSize(new java.awt.Dimension(100, 30)); - addProfileButton.setPreferredSize(new java.awt.Dimension(100, 30)); + profilesList.setBackground(new java.awt.Color(51, 51, 51)); + profilesList.setMaximumSize(new java.awt.Dimension(300, 30)); + profilesList.setMinimumSize(new java.awt.Dimension(300, 30)); + profilesList.setPreferredSize(new java.awt.Dimension(300, 30)); + profilesList.addItemListener(new java.awt.event.ItemListener() { + public void itemStateChanged(java.awt.event.ItemEvent evt) { + profileItemChangedEvent(evt); + } + }); + + addProfileButton.setMaximumSize(new java.awt.Dimension(30, 30)); + addProfileButton.setMinimumSize(new java.awt.Dimension(30, 30)); + addProfileButton.setPreferredSize(new java.awt.Dimension(30, 30)); addProfileButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { addButtonClicked(evt); } }); - removeProfileButton.setBackground(new java.awt.Color(51, 51, 51)); - removeProfileButton.setText("Remove"); - removeProfileButton.setAlignmentY(0.0F); - removeProfileButton.setMaximumSize(new java.awt.Dimension(100, 30)); - removeProfileButton.setMinimumSize(new java.awt.Dimension(100, 30)); - removeProfileButton.setPreferredSize(new java.awt.Dimension(100, 30)); + removeProfileButton.setMaximumSize(new java.awt.Dimension(30, 30)); + removeProfileButton.setMinimumSize(new java.awt.Dimension(30, 30)); + removeProfileButton.setPreferredSize(new java.awt.Dimension(30, 30)); removeProfileButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { removeProfilesButtonClicked(evt); } }); - configureProfileButton.setBackground(new java.awt.Color(51, 51, 51)); - configureProfileButton.setText("Configure"); - configureProfileButton.setAlignmentY(0.0F); - configureProfileButton.setMaximumSize(new java.awt.Dimension(100, 30)); - configureProfileButton.setMinimumSize(new java.awt.Dimension(100, 30)); - configureProfileButton.setPreferredSize(new java.awt.Dimension(100, 30)); + configureProfileButton.setMaximumSize(new java.awt.Dimension(30, 30)); + configureProfileButton.setMinimumSize(new java.awt.Dimension(30, 30)); + configureProfileButton.setPreferredSize(new java.awt.Dimension(30, 30)); configureProfileButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { configureProfileButtonClicked(evt); } }); - profilesList.setBackground(new java.awt.Color(51, 51, 51)); - profilesList.setMaximumSize(new java.awt.Dimension(300, 30)); - profilesList.setMinimumSize(new java.awt.Dimension(300, 30)); - profilesList.setPreferredSize(new java.awt.Dimension(300, 30)); - profilesList.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - profileSelected(evt); - } - }); - javax.swing.GroupLayout profilesSectionLayout = new javax.swing.GroupLayout(profilesSection); profilesSection.setLayout(profilesSectionLayout); profilesSectionLayout.setHorizontalGroup( @@ -163,19 +152,20 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(addProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(removeProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(configureProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) + .addGap(538, 538, 538)) ); profilesSectionLayout.setVerticalGroup( profilesSectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(profilesSectionLayout.createSequentialGroup() .addGap(10, 10, 10) - .addGroup(profilesSectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(addProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(removeProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(profilesSectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(configureProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(profilesList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(removeProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(addProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(profilesList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(10, 10, 10)) ); getContentPane().add(profilesSection, java.awt.BorderLayout.NORTH); @@ -185,18 +175,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { iBtnSection.setMaximumSize(new java.awt.Dimension(750, 520)); iBtnSection.setMinimumSize(new java.awt.Dimension(750, 520)); iBtnSection.setPreferredSize(new java.awt.Dimension(750, 520)); - - javax.swing.GroupLayout iBtnSectionLayout = new javax.swing.GroupLayout(iBtnSection); - iBtnSection.setLayout(iBtnSectionLayout); - iBtnSectionLayout.setHorizontalGroup( - iBtnSectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 750, Short.MAX_VALUE) - ); - iBtnSectionLayout.setVerticalGroup( - iBtnSectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 520, Short.MAX_VALUE) - ); - + iBtnSection.setLayout(new java.awt.GridBagLayout()); getContentPane().add(iBtnSection, java.awt.BorderLayout.WEST); btnModifierSection.setBackground(new java.awt.Color(36, 36, 36)); From f2ddcf6f2a94a78c1ed8be740cec1b5c2e0f56a5 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Sun, 10 Sep 2023 23:13:07 -0500 Subject: [PATCH 04/93] redesigned how profile is displayed on screen --- .../interactivedeck/menus/MainMenu.java | 94 +++++++++---------- 1 file changed, 44 insertions(+), 50 deletions(-) diff --git a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java index 28abc76..0258ac5 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java @@ -11,10 +11,7 @@ import com.google.gson.JsonObject; import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; +import java.awt.event.*; import javax.swing.*; import me.knighthat.interactivedeck.component.ibutton.IButton; import me.knighthat.interactivedeck.component.plist.ProfileButton; @@ -22,10 +19,12 @@ import me.knighthat.interactivedeck.file.Profile; import me.knighthat.interactivedeck.json.Json; +import me.knighthat.interactivedeck.logging.Log; import me.knighthat.interactivedeck.observable.Observable; import me.knighthat.interactivedeck.utils.ColorUtils; import me.knighthat.interactivedeck.utils.GlobalVars; -import me.knighthat.interactivedeck.utils.UuidUtils;import org.jetbrains.annotations.NotNull; +import me.knighthat.interactivedeck.utils.UuidUtils; +import org.jetbrains.annotations.NotNull; import static me.knighthat.interactivedeck.file.Settings.*; /** @@ -39,17 +38,11 @@ public class MainMenu extends javax.swing.JFrame { */ public MainMenu() { super(GlobalVars.name() + " - " + GlobalVars.version()); - setLocationRelativeTo(null); - setAlwaysOnTop(false); initComponents(); - this.bSelected = Observable.of( null ); initButtonObserver(); - GridBagLayout layout = new GridBagLayout(); - this.iBtnSection.setLayout(layout); - initActiveProfileObserver(); - this.profilesList.setSelectedItem( MenuProperty.defaultProfile() ); + MenuProperty.observeActive( profilesList::setSelectedItem ); addWindowListener(new WindowAdapter() { @Override @@ -72,6 +65,12 @@ public void windowClosing(WindowEvent e) { super.windowClosing(e); } }); + + // Show default profile + MenuProperty.active(MenuProperty.defaultProfile()); + + setLocationRelativeTo(null); + setAlwaysOnTop(false); } /** @@ -223,7 +222,6 @@ private void removeProfilesButtonClicked(java.awt.event.MouseEvent evt) {//GEN-F updateProfilesList(); Profile profile = MenuProperty.defaultProfile(); - profilesList.setSelectedItem(profile); MenuProperty.active(profile); }//GEN-LAST:event_removeProfilesButtonClicked @@ -236,16 +234,39 @@ private void configureProfileButtonClicked(java.awt.event.MouseEvent evt) {//GEN dialog.setVisible(true); }//GEN-LAST:event_configureProfileButtonClicked - private void profileSelected(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_profileSelected - Profile profile = (Profile) profilesList.getSelectedItem(); - if (profile == null) - return; - - MenuProperty.active( profile ); + private void profileItemChangedEvent(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_profileItemChangedEvent + if (evt.getStateChange() != ItemEvent.SELECTED) + return; + + Profile profile = (Profile) evt.getItem(); + + String shortUuid = UuidUtils.lastFiveChars( profile.uuid ); + String info = "Now showing %s (%s) with %s button(s)"; + Log.info( info.formatted( profile.displayName(), shortUuid, profile.buttons().size() ) ); + + iBtnSection.removeAll(); + + bSelected.value().ifPresent( IButton::toggleSelect ); + bSelected.value(null); + + GridBagConstraints constraints = genConstraints( profile ); - String info = "Now showing: %s (%s)"; - Log.info( info.formatted( profile.displayName(), profile.uuid ) ); - }//GEN-LAST:event_profileSelected + profile.buttons().forEach((button) -> { + if (button.getMouseListeners().length == 0) + button.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + iBtnClickEvent(e); + } + }); + + constraints.gridx = button.x; + constraints.gridy = button.y; + this.iBtnSection.add(button, constraints); + }); + + iBtnSection.revalidate(); + iBtnSection.repaint(); + }//GEN-LAST:event_profileItemChangedEvent void iBtnClickEvent(java.awt.event.MouseEvent evt) { IButton selected = (IButton) evt.getComponent(); @@ -267,34 +288,7 @@ void iBtnClickEvent(java.awt.event.MouseEvent evt) { private javax.swing.JPanel iBtnSection; private me.knighthat.interactivedeck.component.plist.ProfilesComboBox profilesList; // End of variables declaration//GEN-END:variables - private final @NotNull Observable bSelected; - - private void initActiveProfileObserver() { - MenuProperty.observeActive( profile -> { - iBtnSection.removeAll(); - - bSelected.value().ifPresent( IButton::toggleSelect ); - bSelected.value(null); - - GridBagConstraints constraints = genConstraints( profile ); - - profile.buttons().forEach((button) -> { - if (button.getMouseListeners().length == 0) - button.addMouseListener(new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - iBtnClickEvent(e); - } - }); - - constraints.gridx = button.x; - constraints.gridy = button.y; - this.iBtnSection.add(button, constraints); - }); - - iBtnSection.revalidate(); - iBtnSection.repaint(); - } ); - } + private final @NotNull Observable bSelected = Observable.of( null );; @NotNull GridBagConstraints genConstraints(@NotNull Profile profile) { int gap = profile.gap(); From 71e322bcdb0395d9fabb2b6e6e33fa370aac0bd9 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Sun, 10 Sep 2023 23:47:48 -0500 Subject: [PATCH 05/93] SVG parser & default SVG for null input --- .../interactivedeck/svg/SVGNotFound.java | 41 ++++++++++++++ .../interactivedeck/svg/SVGParser.java | 55 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/main/java/me/knighthat/interactivedeck/svg/SVGNotFound.java create mode 100644 src/main/java/me/knighthat/interactivedeck/svg/SVGParser.java diff --git a/src/main/java/me/knighthat/interactivedeck/svg/SVGNotFound.java b/src/main/java/me/knighthat/interactivedeck/svg/SVGNotFound.java new file mode 100644 index 0000000..41b6bba --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/svg/SVGNotFound.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.knighthat.interactivedeck.svg; + +import org.jetbrains.annotations.NotNull; +import org.w3c.dom.svg.SVGDocument; + +public class SVGNotFound { + + public static final SVGDocument DOCUMENT; + + /* + * This string is licensed under CC BY 4.0 - https://creativecommons.org/licenses/by/4.0/ + * https://www.svgrepo.com/svg/441689/page-not-found + */ + private static final @NotNull String D = "M38.155 140.475L48.988 62.1108L92.869 67.0568L111.437 91.0118L103.396 148.121L38.155 140.475ZM84.013 94.0018L88.827 71.8068L54.046 68.3068L44.192 135" + + ".457L98.335 142.084L104.877 96.8088L84.013 94.0018ZM59.771 123.595C59.394 123.099 56.05 120.299 55.421 119.433C64.32 109.522 86.05 109.645 92.085 122.757C91.08 123.128 86.59 125.072 " + + "85.71 125.567C83.192 118.25 68.445 115.942 59.771 123.595ZM76.503 96.4988L72.837 99.2588L67.322 92.6168L59.815 96.6468L56.786 91.5778L63.615 88.1508L59.089 82.6988L64.589 79.0188L68" + + ".979 85.4578L76.798 81.5328L79.154 86.2638L72.107 90.0468L76.503 96.4988Z"; + + static { + String header = ""; + String footer = ""; + String path = "".formatted( D ); + + String formatted = "%s%s%s".formatted( header, path, footer ); + DOCUMENT = SVGParser.fromString( formatted ).get(); + } +} diff --git a/src/main/java/me/knighthat/interactivedeck/svg/SVGParser.java b/src/main/java/me/knighthat/interactivedeck/svg/SVGParser.java new file mode 100644 index 0000000..c1204b4 --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/svg/SVGParser.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.knighthat.interactivedeck.svg; + +import org.apache.batik.anim.dom.SAXSVGDocumentFactory; +import org.apache.batik.util.XMLResourceDescriptor; +import org.jetbrains.annotations.NotNull; +import org.w3c.dom.svg.SVGDocument; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.net.URL; +import java.util.Optional; + +public class SVGParser { + + private static final @NotNull SAXSVGDocumentFactory FACTORY; + + static { + String parser = XMLResourceDescriptor.getXMLParserClassName(); + FACTORY = new SAXSVGDocumentFactory( parser ); + } + + public static @NotNull Optional fromString( @NotNull String SVGString ) { + SVGDocument document = null; + try { + Reader reader = new StringReader( SVGString ); + document = FACTORY.createSVGDocument( null, reader ); + } catch (IOException ignored) { + } + return Optional.ofNullable( document ); + } + + public static @NotNull Optional fromURL( @NotNull URL url ) { + SVGDocument document = null; + try { + document = FACTORY.createSVGDocument( url.toExternalForm() ); + } catch (IOException ignored) { + } + return Optional.ofNullable( document ); + } +} From 3b33e523c286aad549bf0d231ac62fe9531af192 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Sun, 10 Sep 2023 23:48:49 -0500 Subject: [PATCH 06/93] added first icons to UI --- .../interactivedeck/component/icon/Icons.java | 22 ++++++++ .../component/icon/InternalIcons.java | 54 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/main/java/me/knighthat/interactivedeck/component/icon/Icons.java create mode 100644 src/main/java/me/knighthat/interactivedeck/component/icon/InternalIcons.java diff --git a/src/main/java/me/knighthat/interactivedeck/component/icon/Icons.java b/src/main/java/me/knighthat/interactivedeck/component/icon/Icons.java new file mode 100644 index 0000000..edfefe4 --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/component/icon/Icons.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.knighthat.interactivedeck.component.icon; + +import org.jetbrains.annotations.NotNull; + +public interface Icons { + + @NotNull InternalIcons INTERNAL = new InternalIcons(); +} diff --git a/src/main/java/me/knighthat/interactivedeck/component/icon/InternalIcons.java b/src/main/java/me/knighthat/interactivedeck/component/icon/InternalIcons.java new file mode 100644 index 0000000..82babeb --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/component/icon/InternalIcons.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.knighthat.interactivedeck.component.icon; + +import me.knighthat.interactivedeck.svg.SVGNotFound; +import me.knighthat.interactivedeck.svg.SVGParser; +import org.jetbrains.annotations.NotNull; +import org.w3c.dom.svg.SVGDocument; + +import java.net.URL; +import java.util.Optional; + +public class InternalIcons { + + public final @NotNull SVGDocument PROFILE_ADD; + public final @NotNull SVGDocument PROFILE_ADD_HOVER; + public final @NotNull SVGDocument PROFILE_REMOVE; + public final @NotNull SVGDocument PROFILE_REMOVE_HOVER; + public final @NotNull SVGDocument PROFILE_CONFIGURE; + public final @NotNull SVGDocument PROFILE_CONFIGURE_HOVER; + + public InternalIcons() { + PROFILE_ADD = fromResource( "add" ); + PROFILE_ADD_HOVER = fromResource( "add-hover" ); + PROFILE_REMOVE = fromResource( "remove" ); + PROFILE_REMOVE_HOVER = fromResource( "remove-hover" ); + PROFILE_CONFIGURE = fromResource( "configure" ); + PROFILE_CONFIGURE_HOVER = fromResource( "configure-hover" ); + } + + @NotNull SVGDocument fromResource( @NotNull String name ) { + String path = "/internal/icons/%s.svg".formatted( name ); + URL url = getClass().getResource( path ); + SVGDocument document = SVGNotFound.DOCUMENT; + if (url != null) { + Optional parsed = SVGParser.fromURL( url ); + if (parsed.isPresent()) + document = parsed.get(); + } + return document; + } +} From 3c04d1f6eabef3320eff8ef7fe58559f049b28d9 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Sun, 10 Sep 2023 23:49:18 -0500 Subject: [PATCH 07/93] button that loads svg as background --- .../component/plist/ProfileButton.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/main/java/me/knighthat/interactivedeck/component/plist/ProfileButton.java diff --git a/src/main/java/me/knighthat/interactivedeck/component/plist/ProfileButton.java b/src/main/java/me/knighthat/interactivedeck/component/plist/ProfileButton.java new file mode 100644 index 0000000..751aa83 --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/component/plist/ProfileButton.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.knighthat.interactivedeck.component.plist; + +import me.knighthat.interactivedeck.component.icon.Icons; +import org.apache.batik.swing.JSVGCanvas; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.w3c.dom.svg.SVGDocument; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import static me.knighthat.interactivedeck.utils.ColorUtils.TRANSPARENT; + +public class ProfileButton extends JSVGCanvas { + + private @Nullable SVGDocument ICON; + private @Nullable SVGDocument ICON_HOVER; + + public ProfileButton() { + } + + public ProfileButton( @NotNull ButtonType type ) { + ICON = switch (type) { + case ADD -> Icons.INTERNAL.PROFILE_ADD; + case REMOVE -> Icons.INTERNAL.PROFILE_REMOVE; + case CONFIGURE -> Icons.INTERNAL.PROFILE_CONFIGURE; + }; + ICON_HOVER = switch (type) { + case ADD -> Icons.INTERNAL.PROFILE_ADD_HOVER; + case REMOVE -> Icons.INTERNAL.PROFILE_REMOVE_HOVER; + case CONFIGURE -> Icons.INTERNAL.PROFILE_CONFIGURE_HOVER; + }; + + setBackground( TRANSPARENT ); + setDocument( ICON ); + + addMouseListener( new MouseAdapter() { + @Override + public void mouseEntered( MouseEvent e ) { + setDocument( ICON_HOVER ); + } + + @Override + public void mouseExited( MouseEvent e ) { + setDocument( ICON ); + } + } ); + } + + public enum ButtonType { + ADD, REMOVE, CONFIGURE + } +} From 98f884a9f8530aca4723902bebb56cf6f18acd92 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Sun, 10 Sep 2023 23:49:41 -0500 Subject: [PATCH 08/93] first icons of UI --- src/main/resources/internal/icons/LICENSE.md | 3 +++ .../resources/internal/icons/add-hover.svg | 16 +++++++++++++ src/main/resources/internal/icons/add.svg | 16 +++++++++++++ .../internal/icons/configure-hover.svg | 23 +++++++++++++++++++ .../resources/internal/icons/configure.svg | 23 +++++++++++++++++++ .../resources/internal/icons/remove-hover.svg | 15 ++++++++++++ src/main/resources/internal/icons/remove.svg | 15 ++++++++++++ 7 files changed, 111 insertions(+) create mode 100644 src/main/resources/internal/icons/LICENSE.md create mode 100644 src/main/resources/internal/icons/add-hover.svg create mode 100644 src/main/resources/internal/icons/add.svg create mode 100644 src/main/resources/internal/icons/configure-hover.svg create mode 100644 src/main/resources/internal/icons/configure.svg create mode 100644 src/main/resources/internal/icons/remove-hover.svg create mode 100644 src/main/resources/internal/icons/remove.svg diff --git a/src/main/resources/internal/icons/LICENSE.md b/src/main/resources/internal/icons/LICENSE.md new file mode 100644 index 0000000..bf0cd1e --- /dev/null +++ b/src/main/resources/internal/icons/LICENSE.md @@ -0,0 +1,3 @@ +All icons are subjected under [Font Awesome Free License](https://fontawesome.com/license/free) ([Creative Commons Attribution 4.0](https://creativecommons.org/licenses/by/4.0/legalcode)) + +ATTENTION: Icons distributed to you (consumer) may not in original form diff --git a/src/main/resources/internal/icons/add-hover.svg b/src/main/resources/internal/icons/add-hover.svg new file mode 100644 index 0000000..bed46e1 --- /dev/null +++ b/src/main/resources/internal/icons/add-hover.svg @@ -0,0 +1,16 @@ + + + + + + + diff --git a/src/main/resources/internal/icons/add.svg b/src/main/resources/internal/icons/add.svg new file mode 100644 index 0000000..29954cf --- /dev/null +++ b/src/main/resources/internal/icons/add.svg @@ -0,0 +1,16 @@ + + + + + + + diff --git a/src/main/resources/internal/icons/configure-hover.svg b/src/main/resources/internal/icons/configure-hover.svg new file mode 100644 index 0000000..f27d5db --- /dev/null +++ b/src/main/resources/internal/icons/configure-hover.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + diff --git a/src/main/resources/internal/icons/configure.svg b/src/main/resources/internal/icons/configure.svg new file mode 100644 index 0000000..896d14e --- /dev/null +++ b/src/main/resources/internal/icons/configure.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + diff --git a/src/main/resources/internal/icons/remove-hover.svg b/src/main/resources/internal/icons/remove-hover.svg new file mode 100644 index 0000000..79db21d --- /dev/null +++ b/src/main/resources/internal/icons/remove-hover.svg @@ -0,0 +1,15 @@ + + + + + + diff --git a/src/main/resources/internal/icons/remove.svg b/src/main/resources/internal/icons/remove.svg new file mode 100644 index 0000000..78df13a --- /dev/null +++ b/src/main/resources/internal/icons/remove.svg @@ -0,0 +1,15 @@ + + + + + + From e4c44c0b4f2a3e9a3d3d805a99110d5af2066aa5 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Sun, 10 Sep 2023 23:50:53 -0500 Subject: [PATCH 09/93] updated to match MainMenu --- .../interactivedeck/menus/MainMenu.form | 114 ++++++++---------- 1 file changed, 52 insertions(+), 62 deletions(-) diff --git a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form index 4620b8e..8a06934 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form +++ b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form @@ -64,121 +64,122 @@ - + - + - + - - - - - + + + + + + - + - - - + - + - + - + - - - - - + - - - - - - + - + - + - + + - - + + + + + + - - - - - - + - + - + - + + - - + + + + + + - - - - + - + - + - + - + + + + + + + + + + @@ -203,18 +204,7 @@ - - - - - - - - - - - - + From 4db7564e8827d31beceeae8c4c3d9ae99cb0d3ef Mon Sep 17 00:00:00 2001 From: KnightHat Date: Mon, 11 Sep 2023 20:57:39 -0500 Subject: [PATCH 10/93] extracted common steps to method --- .../menus/ProfileConfigurationMenu.java | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/main/java/me/knighthat/interactivedeck/menus/ProfileConfigurationMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/ProfileConfigurationMenu.java index ed287c8..b421b8c 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/ProfileConfigurationMenu.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/ProfileConfigurationMenu.java @@ -198,28 +198,14 @@ private void cancelButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRS }//GEN-LAST:event_cancelButtonMouseClicked private void saveButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveButtonMouseClicked - String newDisplayName = displayNameInput.getText(); - if (!newDisplayName.isBlank()) - profile.displayName(newDisplayName); - - int newColumns = (int) columnsSpinner.getValue(); - newColumns = newColumns < 1 ? 1 : Math.min(newColumns, 10); - if (newColumns != profile.columns()) - profile.columns(newColumns); - - int newRows = (int) rowsSpinner.getValue(); - newRows = newRows < 1 ? 1 : Math.min(newRows, 10); - if (newRows != profile.rows()) - profile.rows(newRows); - - int newGap = (int ) this.gapSpinner.getValue(); - newGap = newGap < 0 ? 0 : Math.min(newGap, 10); - if (newGap != profile.gap()) - profile.gap(newGap); - - MenuProperty.active(profile); + profile.displayName(displayNameInput.getText()); + profile.columns(validate(columnsSpinner.getValue(), 1 )); + profile.rows(validate(rowsSpinner.getValue(), 1 )); + profile.gap(validate(gapSpinner.getValue(), 0 )); - finish(); + ((MainMenu) getOwner()).updateButtons( profile ); + + finish(); }//GEN-LAST:event_saveButtonMouseClicked // Variables declaration - do not modify//GEN-BEGIN:variables @@ -230,6 +216,12 @@ private void saveButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST: // End of variables declaration//GEN-END:variables private final @NotNull Profile profile; + + int validate(@NotNull Object obj, int min) { + if (!( obj instanceof Integer number )) + return min; + return number < min ? min : Math.min(number, 10); + } private void finish() { this.setVisible(false); From 0036e123889964c2b60d981028c1592a08fa3777 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Mon, 11 Sep 2023 20:59:04 -0500 Subject: [PATCH 11/93] press Enter to apply, Esc to cancel --- .../interactivedeck/menus/AddProfileMenu.form | 3 ++ .../interactivedeck/menus/AddProfileMenu.java | 39 +++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.form b/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.form index 6463b61..99cd2e4 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.form +++ b/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.form @@ -92,6 +92,9 @@ + + + diff --git a/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.java index 04f3766..69cf2f6 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.java @@ -11,8 +11,8 @@ import javax.swing.JRootPane; -import com.google.gson.JsonArray; -import me.knighthat.interactivedeck.connection.request.AddRequest;import me.knighthat.interactivedeck.file.Profiles;import me.knighthat.interactivedeck.file.Profile; +import me.knighthat.interactivedeck.file.Profile; +import me.knighthat.interactivedeck.file.Profiles; /** * @@ -75,6 +75,11 @@ private void initComponents() { displayNameInput.setMaximumSize(new java.awt.Dimension(150, 30)); displayNameInput.setMinimumSize(new java.awt.Dimension(150, 30)); displayNameInput.setPreferredSize(new java.awt.Dimension(150, 30)); + displayNameInput.addKeyListener(new java.awt.event.KeyAdapter() { + public void keyPressed(java.awt.event.KeyEvent evt) { + keyPressedEvent(evt); + } + }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; @@ -119,25 +124,35 @@ public void mouseClicked(java.awt.event.MouseEvent evt) { }// //GEN-END:initComponents private void createButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createButtonMouseClicked - String fromUser = this.displayNameInput.getText().trim(); - if (fromUser.isBlank()) return; - - Profile profile = Profiles.create( fromUser ); - - MenuProperty.add(profile); - ( (MainMenu) super.getOwner() ).updateProfilesList(); - MenuProperty.active(profile); - - finish(); + createProfile(); }//GEN-LAST:event_createButtonMouseClicked private void cancelButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cancelButtonMouseClicked finish(); }//GEN-LAST:event_cancelButtonMouseClicked + private void keyPressedEvent(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyPressedEvent + if (evt.getKeyCode() == 27) + finish(); + else if (evt.getKeyCode() == 10) + createProfile(); + }//GEN-LAST:event_keyPressedEvent + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField displayNameInput; // End of variables declaration//GEN-END:variables + + void createProfile() { + String fromUser = displayNameInput.getText().trim(); + if (fromUser.isBlank()) return; // TODO Notify user about empty input + + Profile profile = Profiles.create( fromUser ); + MenuProperty.add(profile); + ( (MainMenu) super.getOwner() ).updateProfilesList(); + MenuProperty.active(profile); + + finish(); + } private void finish() { this.setVisible(false); From 5d595fd9f013a3025122279419f3cc7a28c67a0d Mon Sep 17 00:00:00 2001 From: KnightHat Date: Mon, 11 Sep 2023 21:02:23 -0500 Subject: [PATCH 12/93] switched back to using actionPerformEvent & extracted steps to update buttons --- .../interactivedeck/menus/MainMenu.form | 2 +- .../interactivedeck/menus/MainMenu.java | 62 +++++++++---------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form index 8a06934..72d7558 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form +++ b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form @@ -102,7 +102,7 @@ - + diff --git a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java index 0258ac5..f934fda 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java @@ -107,9 +107,9 @@ private void initComponents() { profilesList.setMaximumSize(new java.awt.Dimension(300, 30)); profilesList.setMinimumSize(new java.awt.Dimension(300, 30)); profilesList.setPreferredSize(new java.awt.Dimension(300, 30)); - profilesList.addItemListener(new java.awt.event.ItemListener() { - public void itemStateChanged(java.awt.event.ItemEvent evt) { - profileItemChangedEvent(evt); + profilesList.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + profilesListActionPerformed(evt); } }); @@ -234,23 +234,41 @@ private void configureProfileButtonClicked(java.awt.event.MouseEvent evt) {//GEN dialog.setVisible(true); }//GEN-LAST:event_configureProfileButtonClicked - private void profileItemChangedEvent(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_profileItemChangedEvent - if (evt.getStateChange() != ItemEvent.SELECTED) - return; + private void profilesListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_profilesListActionPerformed + Profile profile = (Profile) profilesList.getSelectedItem(); + if (profile != null && evt.getActionCommand().equals( "comboBoxChanged" )) + updateButtons( profile ); + }//GEN-LAST:event_profilesListActionPerformed + + void iBtnClickEvent(java.awt.event.MouseEvent evt) { + IButton selected = (IButton) evt.getComponent(); + + bSelected.value().ifPresentOrElse( currentlySelected -> { + + currentlySelected.toggleSelect(); + bSelected.value(currentlySelected == selected ? null : selected); + + }, () -> bSelected.value(selected) ); - Profile profile = (Profile) evt.getItem(); + String deb = "Button %s@x:%s,y:%s clicked!"; + String shortUuid = UuidUtils.lastFiveChars( selected.uuid ); + Log.deb( deb.formatted( shortUuid, selected.x, selected.y) ); + } - String shortUuid = UuidUtils.lastFiveChars( profile.uuid ); - String info = "Now showing %s (%s) with %s button(s)"; - Log.info( info.formatted( profile.displayName(), shortUuid, profile.buttons().size() ) ); + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel btnModifierSection; + private javax.swing.JPanel iBtnSection; + private me.knighthat.interactivedeck.component.plist.ProfilesComboBox profilesList; + // End of variables declaration//GEN-END:variables + private final @NotNull Observable bSelected = Observable.of( null );; + public void updateButtons(@NotNull Profile profile) { iBtnSection.removeAll(); bSelected.value().ifPresent( IButton::toggleSelect ); bSelected.value(null); GridBagConstraints constraints = genConstraints( profile ); - profile.buttons().forEach((button) -> { if (button.getMouseListeners().length == 0) button.addMouseListener(new MouseAdapter() { @@ -266,30 +284,8 @@ public void mouseClicked(MouseEvent e) { iBtnSection.revalidate(); iBtnSection.repaint(); - }//GEN-LAST:event_profileItemChangedEvent - - void iBtnClickEvent(java.awt.event.MouseEvent evt) { - IButton selected = (IButton) evt.getComponent(); - - bSelected.value().ifPresentOrElse( currentlySelected -> { - - currentlySelected.toggleSelect(); - bSelected.value(currentlySelected == selected ? null : selected); - - }, () -> bSelected.value(selected) ); - - String deb = "Button %s@x:%s,y:%s clicked!"; - String shortUuid = UuidUtils.lastFiveChars( selected.uuid ); - Log.deb( deb.formatted( shortUuid, selected.x, selected.y) ); } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JPanel btnModifierSection; - private javax.swing.JPanel iBtnSection; - private me.knighthat.interactivedeck.component.plist.ProfilesComboBox profilesList; - // End of variables declaration//GEN-END:variables - private final @NotNull Observable bSelected = Observable.of( null );; - @NotNull GridBagConstraints genConstraints(@NotNull Profile profile) { int gap = profile.gap(); int spaceX = profile.columns() * (IButton.DIMENSION.width + gap) - gap; // Horizontal space (includes gaps) taken by buttons From 511d7e4168e73f6c7639f18b4b6ec76483cdbfb9 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Mon, 11 Sep 2023 21:03:10 -0500 Subject: [PATCH 13/93] log when new active profile is set --- .../me/knighthat/interactivedeck/menus/MenuProperty.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/me/knighthat/interactivedeck/menus/MenuProperty.java b/src/main/java/me/knighthat/interactivedeck/menus/MenuProperty.java index 181d757..2b8e593 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/MenuProperty.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/MenuProperty.java @@ -16,8 +16,10 @@ import me.knighthat.interactivedeck.component.ibutton.IButton; import me.knighthat.interactivedeck.file.Profile; +import me.knighthat.interactivedeck.logging.Log; import me.knighthat.interactivedeck.observable.Observable; import me.knighthat.interactivedeck.observable.Observer; +import me.knighthat.interactivedeck.utils.UuidUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Unmodifiable; @@ -87,6 +89,10 @@ public static void remove( @NotNull IButton button ) { } public static void active( @NotNull Profile profile ) { + String shortUuid = UuidUtils.lastFiveChars( profile.uuid ); + String info = "Now showing %s (%s) with %s button(s)"; + Log.info( info.formatted( profile.displayName(), shortUuid, profile.buttons().size() ) ); + INTERNAL.active.value( profile ); } From 2a9e7f7e415b2e0d52cae2fb62942bb09ec25b59 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Mon, 11 Sep 2023 21:03:30 -0500 Subject: [PATCH 14/93] check if given is blank before proceed --- src/main/java/me/knighthat/interactivedeck/file/Profile.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/knighthat/interactivedeck/file/Profile.java b/src/main/java/me/knighthat/interactivedeck/file/Profile.java index ee7596f..08fe1d0 100644 --- a/src/main/java/me/knighthat/interactivedeck/file/Profile.java +++ b/src/main/java/me/knighthat/interactivedeck/file/Profile.java @@ -60,7 +60,7 @@ public class Profile implements JsonSerializable { } public void displayName( @NotNull String displayName ) { - if (displayName.equals( displayName() )) + if (displayName.equals( displayName() ) || displayName.isBlank()) return; Log.profileUpdate( displayName, "name", this.displayName, displayName ); From 86e1590bc150c928920111efd4c1ff216ead3ccb Mon Sep 17 00:00:00 2001 From: KnightHat Date: Tue, 12 Sep 2023 10:13:14 -0500 Subject: [PATCH 15/93] convert SVGDocument to BufferedImage using PNGTranscoder --- .../interactivedeck/svg/SVGParser.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/knighthat/interactivedeck/svg/SVGParser.java b/src/main/java/me/knighthat/interactivedeck/svg/SVGParser.java index c1204b4..b26b035 100644 --- a/src/main/java/me/knighthat/interactivedeck/svg/SVGParser.java +++ b/src/main/java/me/knighthat/interactivedeck/svg/SVGParser.java @@ -14,14 +14,18 @@ package me.knighthat.interactivedeck.svg; +import me.knighthat.interactivedeck.utils.ColorUtils; import org.apache.batik.anim.dom.SAXSVGDocumentFactory; +import org.apache.batik.transcoder.*; +import org.apache.batik.transcoder.image.ImageTranscoder; +import org.apache.batik.transcoder.image.PNGTranscoder; import org.apache.batik.util.XMLResourceDescriptor; import org.jetbrains.annotations.NotNull; import org.w3c.dom.svg.SVGDocument; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.*; import java.net.URL; import java.util.Optional; @@ -52,4 +56,25 @@ public class SVGParser { } return Optional.ofNullable( document ); } + + public static @NotNull BufferedImage toBufferedImage( @NotNull SVGDocument document ) { + try { + Transcoder transcoder = new PNGTranscoder(); + TranscodingHints hints = new TranscodingHints(); + hints.put( ImageTranscoder.KEY_BACKGROUND_COLOR, ColorUtils.TRANSPARENT ); + transcoder.setTranscodingHints( hints ); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + TranscoderOutput output = new TranscoderOutput( baos ); + + TranscoderInput input = new TranscoderInput( document ); + transcoder.transcode( input, output ); + + ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() ); + + return ImageIO.read( bais ); + } catch (TranscoderException | IOException e) { + throw new RuntimeException( e ); + } + } } From e9d33913c157d31d8e8e23dbd2f8c641d7315f09 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Tue, 12 Sep 2023 10:13:49 -0500 Subject: [PATCH 16/93] switched to complete version of batik --- pom.xml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 7470132..781b116 100644 --- a/pom.xml +++ b/pom.xml @@ -96,12 +96,7 @@ org.apache.xmlgraphics - batik-dom - 1.17 - - - org.apache.xmlgraphics - batik-swing + batik-all 1.17 From 2ba28622afff47fc5fa04f21330af3286d35adab Mon Sep 17 00:00:00 2001 From: KnightHat Date: Tue, 12 Sep 2023 10:15:03 -0500 Subject: [PATCH 17/93] renamed & anonymous JTabbedPane that handles SVGDocument --- .../menus/ButtonModifierPanel.java | 61 ----------------- .../interactivedeck/menus/MainMenu.java | 4 +- .../menus/ModifierContainer.java | 66 +++++++++++++++++++ 3 files changed, 67 insertions(+), 64 deletions(-) delete mode 100644 src/main/java/me/knighthat/interactivedeck/menus/ButtonModifierPanel.java create mode 100644 src/main/java/me/knighthat/interactivedeck/menus/ModifierContainer.java diff --git a/src/main/java/me/knighthat/interactivedeck/menus/ButtonModifierPanel.java b/src/main/java/me/knighthat/interactivedeck/menus/ButtonModifierPanel.java deleted file mode 100644 index 270cf26..0000000 --- a/src/main/java/me/knighthat/interactivedeck/menus/ButtonModifierPanel.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2023. Knight Hat - * All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package me.knighthat.interactivedeck.menus; - -import me.knighthat.interactivedeck.component.ibutton.IButton; -import me.knighthat.interactivedeck.menus.modifier.IconModifierPanel; -import me.knighthat.interactivedeck.menus.modifier.TaskModifierPanel; -import me.knighthat.interactivedeck.menus.modifier.TextModifierPanel; -import org.jetbrains.annotations.NotNull; - -/** - * @author knighthat - */ -public class ButtonModifierPanel extends javax.swing.JPanel { - - // Variables declaration - do not modify//GEN-BEGIN:variables - // End of variables declaration//GEN-END:variables - private final @NotNull IButton selected; - - public ButtonModifierPanel( @NotNull IButton selected ) { - this.selected = selected; - - initComponents(); - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings( "unchecked" ) - // //GEN-BEGIN:initComponents - private void initComponents() { - - javax.swing.JTabbedPane modifierTabbedPane = new javax.swing.JTabbedPane(); - me.knighthat.interactivedeck.menus.modifier.TextModifierPanel textModifier = new TextModifierPanel(selected); - me.knighthat.interactivedeck.menus.modifier.IconModifierPanel iconModifier = new IconModifierPanel(selected); - me.knighthat.interactivedeck.menus.modifier.TaskModifierPanel taskModifier = new TaskModifierPanel(selected); - - setMaximumSize(new java.awt.Dimension(250, 520)); - setMinimumSize(new java.awt.Dimension(250, 520)); - setOpaque(false); - setPreferredSize(new java.awt.Dimension(250, 520)); - setLayout(new java.awt.BorderLayout()); - - modifierTabbedPane.setBackground(new java.awt.Color(36, 36, 36)); - modifierTabbedPane.addTab("Text", textModifier); - modifierTabbedPane.addTab("Icon", iconModifier); - modifierTabbedPane.addTab("Task", taskModifier); - - add(modifierTabbedPane, java.awt.BorderLayout.PAGE_START); - }// //GEN-END:initComponents - -} diff --git a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java index f934fda..25e530d 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java @@ -17,7 +17,6 @@ import me.knighthat.interactivedeck.component.plist.ProfileButton; import me.knighthat.interactivedeck.connection.Connection; import me.knighthat.interactivedeck.file.Profile; - import me.knighthat.interactivedeck.json.Json; import me.knighthat.interactivedeck.logging.Log; import me.knighthat.interactivedeck.observable.Observable; @@ -70,7 +69,6 @@ public void windowClosing(WindowEvent e) { MenuProperty.active(MenuProperty.defaultProfile()); setLocationRelativeTo(null); - setAlwaysOnTop(false); } /** @@ -313,7 +311,7 @@ void initButtonObserver() { btn.toggleSelect(); - ButtonModifierPanel panel = new ButtonModifierPanel(btn); + ModifierContainer panel = new ModifierContainer(btn); btnModifierSection.add( panel, BorderLayout.PAGE_START ); } ); } diff --git a/src/main/java/me/knighthat/interactivedeck/menus/ModifierContainer.java b/src/main/java/me/knighthat/interactivedeck/menus/ModifierContainer.java new file mode 100644 index 0000000..54913e5 --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/menus/ModifierContainer.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package me.knighthat.interactivedeck.menus; + +import me.knighthat.interactivedeck.component.ibutton.IButton; +import me.knighthat.interactivedeck.component.icon.Icons; +import me.knighthat.interactivedeck.menus.modifier.IconModifierPanel; +import me.knighthat.interactivedeck.menus.modifier.TaskModifierPanel; +import me.knighthat.interactivedeck.menus.modifier.TextModifierPanel; +import me.knighthat.interactivedeck.svg.SVGParser; +import org.jetbrains.annotations.NotNull; +import org.w3c.dom.svg.SVGDocument; + +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; + +/** + * @author knighthat + */ +public class ModifierContainer extends JPanel { + + private final @NotNull IButton selected; + + public ModifierContainer( @NotNull IButton selected ) { + this.selected = selected; + + initComponents(); + } + + private void initComponents() { + TextModifierPanel textModifier = new TextModifierPanel( selected ); + IconModifierPanel iconModifier = new IconModifierPanel( selected ); + TaskModifierPanel taskModifier = new TaskModifierPanel( selected ); + var modifierTabbedPane = new JTabbedPane() { + public void addTab( @NotNull SVGDocument svg, @NotNull Component component ) { + BufferedImage bufferedImage = SVGParser.toBufferedImage( svg ); + super.addTab( "", new ImageIcon( bufferedImage ), component ); + } + }; + + Dimension dimension = new java.awt.Dimension( 250, 520 ); + setMaximumSize( dimension ); + setMinimumSize( dimension ); + setPreferredSize( dimension ); + setOpaque( false ); + setLayout( new java.awt.BorderLayout() ); + + modifierTabbedPane.addTab( Icons.INTERNAL.TAB_TEXT, textModifier ); + modifierTabbedPane.addTab( Icons.INTERNAL.TAB_ICON, iconModifier ); + modifierTabbedPane.addTab( Icons.INTERNAL.TAB_TASK, taskModifier ); + + add( modifierTabbedPane, java.awt.BorderLayout.PAGE_START ); + } +} From 531adfb37e26bffd54888d0b15d6a412a6ea0061 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Tue, 12 Sep 2023 20:04:47 -0500 Subject: [PATCH 18/93] added UI render for tabs --- .../interactivedeck/component/tab/TabUI.java | 76 +++++++++++++++ .../menus/ButtonModifierPanel.form | 94 ------------------- .../menus/ModifierContainer.java | 10 +- 3 files changed, 83 insertions(+), 97 deletions(-) create mode 100644 src/main/java/me/knighthat/interactivedeck/component/tab/TabUI.java delete mode 100644 src/main/java/me/knighthat/interactivedeck/menus/ButtonModifierPanel.form diff --git a/src/main/java/me/knighthat/interactivedeck/component/tab/TabUI.java b/src/main/java/me/knighthat/interactivedeck/component/tab/TabUI.java new file mode 100644 index 0000000..e342318 --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/component/tab/TabUI.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.knighthat.interactivedeck.component.tab; + +import me.knighthat.interactivedeck.utils.ColorUtils; + +import javax.swing.plaf.basic.BasicTabbedPaneUI; +import java.awt.*; +import java.awt.geom.QuadCurve2D; + +public class TabUI extends BasicTabbedPaneUI { + + @Override + protected LayoutManager createLayoutManager() { + return new SpacedLayout(); + } + + @Override + protected void paintTabBorder( Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected ) { + Graphics2D g2d = (Graphics2D) g; + g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); + g2d.setColor( Color.WHITE ); + g2d.drawLine( x, y + 10, x, y + h - 2 ); // Left Post + g2d.drawLine( x + w - 1, y + 10, x + w - 1, y + h - 2 ); // Right Post + g2d.drawLine( x + 10, y, x + w - 11, y ); // Top Post + QuadCurve2D leftCurve = new QuadCurve2D.Float( + x, y + 10, + x, y, + x + 10, y + ); + g2d.draw( leftCurve ); + QuadCurve2D rightCurve = new QuadCurve2D.Float( + x + w - 11, y, + x + w - 1, y, + x + w - 1, y + 10 + ); + g2d.draw( rightCurve ); + } + + @Override + protected void paintContentBorderLeftEdge( Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h ) { + g.setColor( ColorUtils.TRANSPARENT ); + g.fillRect( x, y, w, h ); + } + + @Override + protected void paintContentBorderRightEdge( Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h ) { + g.setColor( ColorUtils.TRANSPARENT ); + g.fillRect( x, y, w, h ); + } + + private class SpacedLayout extends BasicTabbedPaneUI.TabbedPaneLayout { + + private static final int GAP = 5; + + @Override + protected void calculateTabRects( int tabPlacement, int tabCount ) { + super.calculateTabRects( tabPlacement, tabCount ); + + for (int i = 0 ; i < rects.length ; i++) + rects[i].x += i * GAP; + } + } +} diff --git a/src/main/java/me/knighthat/interactivedeck/menus/ButtonModifierPanel.form b/src/main/java/me/knighthat/interactivedeck/menus/ButtonModifierPanel.form deleted file mode 100644 index 042c1ce..0000000 --- a/src/main/java/me/knighthat/interactivedeck/menus/ButtonModifierPanel.form +++ /dev/null @@ -1,94 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/me/knighthat/interactivedeck/menus/ModifierContainer.java b/src/main/java/me/knighthat/interactivedeck/menus/ModifierContainer.java index 54913e5..d445031 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/ModifierContainer.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/ModifierContainer.java @@ -15,6 +15,7 @@ import me.knighthat.interactivedeck.component.ibutton.IButton; import me.knighthat.interactivedeck.component.icon.Icons; +import me.knighthat.interactivedeck.component.tab.TabUI; import me.knighthat.interactivedeck.menus.modifier.IconModifierPanel; import me.knighthat.interactivedeck.menus.modifier.TaskModifierPanel; import me.knighthat.interactivedeck.menus.modifier.TextModifierPanel; @@ -45,22 +46,25 @@ private void initComponents() { TaskModifierPanel taskModifier = new TaskModifierPanel( selected ); var modifierTabbedPane = new JTabbedPane() { public void addTab( @NotNull SVGDocument svg, @NotNull Component component ) { + svg.getRootElement().setAttribute( "width", "48px" ); + svg.getRootElement().setAttribute( "height", "28px" ); BufferedImage bufferedImage = SVGParser.toBufferedImage( svg ); super.addTab( "", new ImageIcon( bufferedImage ), component ); } }; - Dimension dimension = new java.awt.Dimension( 250, 520 ); + Dimension dimension = new Dimension( 250, 520 ); setMaximumSize( dimension ); setMinimumSize( dimension ); setPreferredSize( dimension ); setOpaque( false ); - setLayout( new java.awt.BorderLayout() ); + setLayout( new BorderLayout() ); + modifierTabbedPane.setUI( new TabUI() ); modifierTabbedPane.addTab( Icons.INTERNAL.TAB_TEXT, textModifier ); modifierTabbedPane.addTab( Icons.INTERNAL.TAB_ICON, iconModifier ); modifierTabbedPane.addTab( Icons.INTERNAL.TAB_TASK, taskModifier ); - add( modifierTabbedPane, java.awt.BorderLayout.PAGE_START ); + add( modifierTabbedPane, BorderLayout.PAGE_START ); } } From 92e33b5dfc8c88d34917ae56763e95d9453ac366 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Tue, 12 Sep 2023 20:59:03 -0500 Subject: [PATCH 19/93] fixed typo --- .../java/me/knighthat/interactivedeck/connection/Client.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/knighthat/interactivedeck/connection/Client.java b/src/main/java/me/knighthat/interactivedeck/connection/Client.java index 91e9628..f515910 100644 --- a/src/main/java/me/knighthat/interactivedeck/connection/Client.java +++ b/src/main/java/me/knighthat/interactivedeck/connection/Client.java @@ -48,7 +48,7 @@ public static boolean isConnected() { String brand = json.get( "brand" ).getAsString(); String device = json.get( "device" ).getAsString(); String manufacturer = json.get( "brand" ).getAsString(); - String model = json.get( "brand" ).getAsString(); + String model = json.get( "model" ).getAsString(); String version = json.get( "androidVersion" ).getAsString(); return INSTANCE = new Client( brand, device, manufacturer, model, version ); From 8459270f20fbe0a03ddebfbb9edea4f112bc97d5 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Tue, 12 Sep 2023 20:59:26 -0500 Subject: [PATCH 20/93] added notification bar --- .../interactivedeck/menus/MainMenu.form | 11 ++- .../interactivedeck/menus/MainMenu.java | 13 ++-- .../menus/NotificationCenter.form | 30 ++++++++ .../menus/NotificationCenter.java | 70 +++++++++++++++++++ 4 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 src/main/java/me/knighthat/interactivedeck/menus/NotificationCenter.form create mode 100644 src/main/java/me/knighthat/interactivedeck/menus/NotificationCenter.java diff --git a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form index 72d7558..efc9e0f 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form +++ b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form @@ -257,14 +257,19 @@ - + + + - + + + + @@ -278,6 +283,8 @@
+ + diff --git a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java index 25e530d..c595efe 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java @@ -17,6 +17,7 @@ import me.knighthat.interactivedeck.component.plist.ProfileButton; import me.knighthat.interactivedeck.connection.Connection; import me.knighthat.interactivedeck.file.Profile; +import static me.knighthat.interactivedeck.file.Settings.*; import me.knighthat.interactivedeck.json.Json; import me.knighthat.interactivedeck.logging.Log; import me.knighthat.interactivedeck.observable.Observable; @@ -24,8 +25,6 @@ import me.knighthat.interactivedeck.utils.GlobalVars; import me.knighthat.interactivedeck.utils.UuidUtils; import org.jetbrains.annotations.NotNull; - -import static me.knighthat.interactivedeck.file.Settings.*; /** * * @author knighthat @@ -90,6 +89,7 @@ private void initComponents() { btnModifierSection = new javax.swing.JPanel(); javax.swing.JPanel statusSection = new javax.swing.JPanel(); me.knighthat.interactivedeck.component.netstatus.ConStatus conStatus = Connection.component(); + notificationCenter1 = new me.knighthat.interactivedeck.menus.NotificationCenter(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setBackground(new java.awt.Color(153, 153, 153)); @@ -195,12 +195,16 @@ public void mouseClicked(java.awt.event.MouseEvent evt) { .addGroup(statusSectionLayout.createSequentialGroup() .addGap(30, 30, 30) .addComponent(conStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(855, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 349, Short.MAX_VALUE) + .addComponent(notificationCenter1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) ); statusSectionLayout.setVerticalGroup( statusSectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(statusSectionLayout.createSequentialGroup() - .addComponent(conStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(statusSectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(conStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(notificationCenter1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(0, 0, Short.MAX_VALUE)) ); @@ -256,6 +260,7 @@ void iBtnClickEvent(java.awt.event.MouseEvent evt) { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel btnModifierSection; private javax.swing.JPanel iBtnSection; + private me.knighthat.interactivedeck.menus.NotificationCenter notificationCenter1; private me.knighthat.interactivedeck.component.plist.ProfilesComboBox profilesList; // End of variables declaration//GEN-END:variables private final @NotNull Observable bSelected = Observable.of( null );; diff --git a/src/main/java/me/knighthat/interactivedeck/menus/NotificationCenter.form b/src/main/java/me/knighthat/interactivedeck/menus/NotificationCenter.form new file mode 100644 index 0000000..d14179a --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/menus/NotificationCenter.form @@ -0,0 +1,30 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/me/knighthat/interactivedeck/menus/NotificationCenter.java b/src/main/java/me/knighthat/interactivedeck/menus/NotificationCenter.java new file mode 100644 index 0000000..9fd60be --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/menus/NotificationCenter.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package me.knighthat.interactivedeck.menus; + +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.*; + +/** + * @author Knight Hat + */ +public class NotificationCenter extends javax.swing.JPanel { + + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables + private static final @NotNull JLabel label = new JLabel(); + + private final @NotNull Dimension dimension = new Dimension( 500, 30 ); + + /** + * Creates new form NotificationContainer + */ + public NotificationCenter() { + initComponents(); + addLabel(); + } + + public static void createConstantMessage( @NotNull String message ) { + label.setText( message ); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings( "unchecked" ) + // //GEN-BEGIN:initComponents + private void initComponents() { + + setMaximumSize( dimension ); + setMinimumSize( dimension ); + setOpaque( false ); + setPreferredSize( dimension ); + setLayout( new javax.swing.BoxLayout( this, javax.swing.BoxLayout.LINE_AXIS ) ); + }// //GEN-END:initComponents + + void addLabel() { + label.setHorizontalAlignment( SwingConstants.RIGHT ); + label.setMaximumSize( dimension ); + label.setMinimumSize( dimension ); + label.setPreferredSize( dimension ); + + label.setForeground( Color.WHITE ); + + add( label ); + } +} From b5db730cf7da97e9852dd097deef592d2da1c1b3 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Tue, 12 Sep 2023 20:59:56 -0500 Subject: [PATCH 21/93] set notification --- .../connection/request/RequestHandler.java | 16 +++++++++++----- .../connection/wireless/WirelessController.java | 5 ++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/knighthat/interactivedeck/connection/request/RequestHandler.java b/src/main/java/me/knighthat/interactivedeck/connection/request/RequestHandler.java index df9bbfd..4d1b22e 100644 --- a/src/main/java/me/knighthat/interactivedeck/connection/request/RequestHandler.java +++ b/src/main/java/me/knighthat/interactivedeck/connection/request/RequestHandler.java @@ -26,6 +26,7 @@ import me.knighthat.interactivedeck.file.Profile; import me.knighthat.interactivedeck.logging.Log; import me.knighthat.interactivedeck.menus.MenuProperty; +import me.knighthat.interactivedeck.menus.NotificationCenter; import org.jetbrains.annotations.NotNull; import java.util.HashSet; @@ -69,11 +70,16 @@ static void handlePairing( @NotNull JsonElement content ) { static void logClientInfo() { assert Client.isConnected(); - String deviceInfo = "Client: %s running on Android %s"; - String model = Client.INSTANCE.model(); - String aVer = Client.INSTANCE.androidVersion(); - String message = String.format( deviceInfo, model, aVer ); - Log.info( message ); + Client client = Client.INSTANCE; + String manufacturer = client.manufacturer(); + String model = client.model(); + String aVer = client.androidVersion(); + + String deviceInfo = "Client %s %s running on Android %s".formatted( manufacturer, model, aVer ); + Log.info( deviceInfo ); + + String device = "%s %s (Android %s)".formatted( manufacturer, model, aVer ); + NotificationCenter.createConstantMessage( device ); } static void handleAction( @NotNull JsonElement content ) { diff --git a/src/main/java/me/knighthat/interactivedeck/connection/wireless/WirelessController.java b/src/main/java/me/knighthat/interactivedeck/connection/wireless/WirelessController.java index d93b8d7..d99dfe0 100644 --- a/src/main/java/me/knighthat/interactivedeck/connection/wireless/WirelessController.java +++ b/src/main/java/me/knighthat/interactivedeck/connection/wireless/WirelessController.java @@ -22,6 +22,7 @@ import me.knighthat.interactivedeck.connection.request.Request; import me.knighthat.interactivedeck.connection.request.RequestHandler; import me.knighthat.interactivedeck.logging.Log; +import me.knighthat.interactivedeck.menus.NotificationCenter; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -50,7 +51,9 @@ public void run() { while (!Thread.interrupted()) try (ServerSocket socket = new ServerSocket( PORT, 1, IP )) { - Log.info( "Listening on: " + address() ); + String message = "Listening on: " + address(); + Log.info( message ); + NotificationCenter.createConstantMessage( message ); handleConnection( socket.accept() ); From 69dc1d5ac6f74d619bb8e5c461024db58457051c Mon Sep 17 00:00:00 2001 From: KnightHat Date: Tue, 12 Sep 2023 21:04:43 -0500 Subject: [PATCH 22/93] added tab icons --- .../component/icon/InternalIcons.java | 6 +++++ .../resources/internal/icons/tab-icon.svg | 22 ++++++++++++++++++ .../resources/internal/icons/tab-task.svg | 23 +++++++++++++++++++ .../resources/internal/icons/tab-text.svg | 17 ++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 src/main/resources/internal/icons/tab-icon.svg create mode 100644 src/main/resources/internal/icons/tab-task.svg create mode 100644 src/main/resources/internal/icons/tab-text.svg diff --git a/src/main/java/me/knighthat/interactivedeck/component/icon/InternalIcons.java b/src/main/java/me/knighthat/interactivedeck/component/icon/InternalIcons.java index 82babeb..6781bbb 100644 --- a/src/main/java/me/knighthat/interactivedeck/component/icon/InternalIcons.java +++ b/src/main/java/me/knighthat/interactivedeck/component/icon/InternalIcons.java @@ -30,6 +30,9 @@ public class InternalIcons { public final @NotNull SVGDocument PROFILE_REMOVE_HOVER; public final @NotNull SVGDocument PROFILE_CONFIGURE; public final @NotNull SVGDocument PROFILE_CONFIGURE_HOVER; + public final @NotNull SVGDocument TAB_TEXT; + public final @NotNull SVGDocument TAB_ICON; + public final @NotNull SVGDocument TAB_TASK; public InternalIcons() { PROFILE_ADD = fromResource( "add" ); @@ -38,6 +41,9 @@ public InternalIcons() { PROFILE_REMOVE_HOVER = fromResource( "remove-hover" ); PROFILE_CONFIGURE = fromResource( "configure" ); PROFILE_CONFIGURE_HOVER = fromResource( "configure-hover" ); + TAB_TEXT = fromResource( "tab-text" ); + TAB_ICON = fromResource( "tab-icon" ); + TAB_TASK = fromResource( "tab-task" ); } @NotNull SVGDocument fromResource( @NotNull String name ) { diff --git a/src/main/resources/internal/icons/tab-icon.svg b/src/main/resources/internal/icons/tab-icon.svg new file mode 100644 index 0000000..6a48ef6 --- /dev/null +++ b/src/main/resources/internal/icons/tab-icon.svg @@ -0,0 +1,22 @@ + + + + + + + + + + diff --git a/src/main/resources/internal/icons/tab-task.svg b/src/main/resources/internal/icons/tab-task.svg new file mode 100644 index 0000000..756e903 --- /dev/null +++ b/src/main/resources/internal/icons/tab-task.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/src/main/resources/internal/icons/tab-text.svg b/src/main/resources/internal/icons/tab-text.svg new file mode 100644 index 0000000..7fadaf5 --- /dev/null +++ b/src/main/resources/internal/icons/tab-text.svg @@ -0,0 +1,17 @@ + + + + + + + From 861e189512bbe5f7e12e3bd4c4b438d8469e77aa Mon Sep 17 00:00:00 2001 From: KnightHat Date: Tue, 12 Sep 2023 22:01:01 -0500 Subject: [PATCH 23/93] update license --- src/main/resources/internal/icons/LICENSE.md | 12 ++++++++++-- src/main/resources/internal/icons/add-hover.svg | 2 -- src/main/resources/internal/icons/add.svg | 2 -- .../resources/internal/icons/configure-hover.svg | 1 - src/main/resources/internal/icons/configure.svg | 1 - src/main/resources/internal/icons/remove-hover.svg | 1 - src/main/resources/internal/icons/remove.svg | 1 - src/main/resources/internal/icons/tab-icon.svg | 3 +-- src/main/resources/internal/icons/tab-task.svg | 3 +-- src/main/resources/internal/icons/tab-text.svg | 3 +-- 10 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/resources/internal/icons/LICENSE.md b/src/main/resources/internal/icons/LICENSE.md index bf0cd1e..1da2d30 100644 --- a/src/main/resources/internal/icons/LICENSE.md +++ b/src/main/resources/internal/icons/LICENSE.md @@ -1,3 +1,11 @@ -All icons are subjected under [Font Awesome Free License](https://fontawesome.com/license/free) ([Creative Commons Attribution 4.0](https://creativecommons.org/licenses/by/4.0/legalcode)) +# [Creative Commons](https://creativecommons.org/licenses/by/4.0/legalcode) -ATTENTION: Icons distributed to you (consumer) may not in original form +- add.svg +- add-hover.svg +- configure.svg +- configure-hover.svg +- remove.svg +- remove-hover.svg +- tab-icon.svg +- tab-task.svg +- tab-text.svg diff --git a/src/main/resources/internal/icons/add-hover.svg b/src/main/resources/internal/icons/add-hover.svg index bed46e1..a9eac57 100644 --- a/src/main/resources/internal/icons/add-hover.svg +++ b/src/main/resources/internal/icons/add-hover.svg @@ -9,8 +9,6 @@ --> - - diff --git a/src/main/resources/internal/icons/add.svg b/src/main/resources/internal/icons/add.svg index 29954cf..08fe3a7 100644 --- a/src/main/resources/internal/icons/add.svg +++ b/src/main/resources/internal/icons/add.svg @@ -9,8 +9,6 @@ --> - - diff --git a/src/main/resources/internal/icons/configure-hover.svg b/src/main/resources/internal/icons/configure-hover.svg index f27d5db..fe77b99 100644 --- a/src/main/resources/internal/icons/configure-hover.svg +++ b/src/main/resources/internal/icons/configure-hover.svg @@ -9,7 +9,6 @@ --> - diff --git a/src/main/resources/internal/icons/configure.svg b/src/main/resources/internal/icons/configure.svg index 896d14e..5d0d57a 100644 --- a/src/main/resources/internal/icons/configure.svg +++ b/src/main/resources/internal/icons/configure.svg @@ -9,7 +9,6 @@ --> - diff --git a/src/main/resources/internal/icons/remove-hover.svg b/src/main/resources/internal/icons/remove-hover.svg index 79db21d..7b42d5c 100644 --- a/src/main/resources/internal/icons/remove-hover.svg +++ b/src/main/resources/internal/icons/remove-hover.svg @@ -9,7 +9,6 @@ --> - diff --git a/src/main/resources/internal/icons/remove.svg b/src/main/resources/internal/icons/remove.svg index 78df13a..ac124e6 100644 --- a/src/main/resources/internal/icons/remove.svg +++ b/src/main/resources/internal/icons/remove.svg @@ -9,7 +9,6 @@ --> - diff --git a/src/main/resources/internal/icons/tab-icon.svg b/src/main/resources/internal/icons/tab-icon.svg index 6a48ef6..81d6ab1 100644 --- a/src/main/resources/internal/icons/tab-icon.svg +++ b/src/main/resources/internal/icons/tab-icon.svg @@ -1,4 +1,4 @@ - - diff --git a/src/main/resources/internal/icons/tab-task.svg b/src/main/resources/internal/icons/tab-task.svg index 756e903..e10001c 100644 --- a/src/main/resources/internal/icons/tab-task.svg +++ b/src/main/resources/internal/icons/tab-task.svg @@ -1,4 +1,4 @@ - - diff --git a/src/main/resources/internal/icons/tab-text.svg b/src/main/resources/internal/icons/tab-text.svg index 7fadaf5..a2ba83f 100644 --- a/src/main/resources/internal/icons/tab-text.svg +++ b/src/main/resources/internal/icons/tab-text.svg @@ -1,4 +1,4 @@ - - From bfa4f2ae62e37094d52e441f25fab99ac3653066 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Wed, 13 Sep 2023 09:37:02 -0500 Subject: [PATCH 24/93] abstraction for popup menu --- .../menus/popup/PopupMenu.java | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/main/java/me/knighthat/interactivedeck/menus/popup/PopupMenu.java diff --git a/src/main/java/me/knighthat/interactivedeck/menus/popup/PopupMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/popup/PopupMenu.java new file mode 100644 index 0000000..16f108d --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/menus/popup/PopupMenu.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.knighthat.interactivedeck.menus.popup; + +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.*; +import java.util.function.Consumer; + +public abstract class PopupMenu extends JDialog { + + protected final @NotNull JPanel content; + private final @NotNull JPanel buttonContainer; + + public PopupMenu( @NotNull Window owner, @NotNull String title ) { + super( owner ); + + setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE ); + setBackground( new Color( 51, 51, 51 ) ); + + getRootPane().setWindowDecorationStyle( JRootPane.NONE ); + setUndecorated( true ); + + title( title ); + + this.content = new JPanel(); + content.setOpaque( false ); + content.setLayout( new GridBagLayout() ); + initContent(); + getContentPane().add( content, BorderLayout.CENTER ); + + this.buttonContainer = new JPanel(); + initButtons(); + getContentPane().add( buttonContainer, BorderLayout.SOUTH ); + + pack(); + setLocationRelativeTo( owner ); + } + + abstract void initContent(); + + void title( @NotNull String title ) { + JLabel label = new JLabel( title ); + + label.setHorizontalAlignment( SwingConstants.CENTER ); + + Dimension dimension = new Dimension( 300, 30 ); + label.setMaximumSize( dimension ); + label.setMinimumSize( dimension ); + label.setPreferredSize( dimension ); + + getContentPane().add( label, BorderLayout.PAGE_START ); + } + + void initButtons() { + Dimension dimension = new Dimension( 300, 50 ); + buttonContainer.setMaximumSize( dimension ); + buttonContainer.setMinimumSize( dimension ); + buttonContainer.setPreferredSize( dimension ); + + buttonContainer.setOpaque( false ); + + FlowLayout layout = new FlowLayout( FlowLayout.RIGHT, 20, 15 ); + layout.setAlignOnBaseline( true ); + buttonContainer.setLayout( layout ); + } + + void addButton( @NotNull Consumer consumer ) { + JButton button = new JButton(); + + Dimension dimension = new java.awt.Dimension( 80, 25 ); + button.setMaximumSize( dimension ); + button.setMinimumSize( dimension ); + button.setPreferredSize( dimension ); + + consumer.accept( button ); + buttonContainer.add( button ); + } + + @NotNull JComponent addContent( @NotNull JComponent component, @NotNull Consumer conComp, @NotNull Consumer conCons ) { + GridBagConstraints constraints = new GridBagConstraints(); + conCons.accept( constraints ); + conComp.accept( component ); + content.add( component, constraints ); + + return component; + } + + void setDimension( @NotNull JComponent component, int width, int height ) { + Dimension dimension = new Dimension( width, height ); + component.setMaximumSize( dimension ); + component.setMinimumSize( dimension ); + component.setPreferredSize( dimension ); + } + + void finish() { + this.setVisible( false ); + } +} From 41fcbf6299e6fe439a463ff804be29c5f5d52d01 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Wed, 13 Sep 2023 09:37:47 -0500 Subject: [PATCH 25/93] extends PopupMenu & moved to popup dir --- .../interactivedeck/menus/AddProfileMenu.form | 275 ------------ .../interactivedeck/menus/AddProfileMenu.java | 161 ------- .../menus/ProfileConfigurationMenu.form | 421 ------------------ .../menus/ProfileConfigurationMenu.java | 229 ---------- .../menus/popup/AddProfilePopup.java | 102 +++++ .../popup/ProfileConfigurationPopup.java | 123 +++++ 6 files changed, 225 insertions(+), 1086 deletions(-) delete mode 100644 src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.form delete mode 100644 src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.java delete mode 100644 src/main/java/me/knighthat/interactivedeck/menus/ProfileConfigurationMenu.form delete mode 100644 src/main/java/me/knighthat/interactivedeck/menus/ProfileConfigurationMenu.java create mode 100644 src/main/java/me/knighthat/interactivedeck/menus/popup/AddProfilePopup.java create mode 100644 src/main/java/me/knighthat/interactivedeck/menus/popup/ProfileConfigurationPopup.java diff --git a/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.form b/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.form deleted file mode 100644 index 99cd2e4..0000000 --- a/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.form +++ /dev/null @@ -1,275 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.java deleted file mode 100644 index 69cf2f6..0000000 --- a/src/main/java/me/knighthat/interactivedeck/menus/AddProfileMenu.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2023. Knight Hat - * All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package me.knighthat.interactivedeck.menus; - - -import javax.swing.JRootPane; -import me.knighthat.interactivedeck.file.Profile; -import me.knighthat.interactivedeck.file.Profiles; - -/** - * - * @author knighthat - */ -public class AddProfileMenu extends javax.swing.JDialog { - - /** - * Creates new form AddProfileDialog - */ - public AddProfileMenu(java.awt.Frame parent) { - super(parent, false); - - super.getRootPane().setWindowDecorationStyle( JRootPane.NONE ); - super.setUndecorated( true ); - - initComponents(); - - super.setLocationRelativeTo(parent); - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - java.awt.GridBagConstraints gridBagConstraints; - - javax.swing.JLabel addProfileTitle = new javax.swing.JLabel(); - javax.swing.JPanel contentContainer = new javax.swing.JPanel(); - javax.swing.JLabel inputLabel = new javax.swing.JLabel(); - displayNameInput = new javax.swing.JTextField(); - javax.swing.JPanel buttonContainer = new javax.swing.JPanel(); - javax.swing.JButton createButton = new javax.swing.JButton(); - javax.swing.JButton cancelButton = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - setBackground(new java.awt.Color(51, 51, 51)); - - addProfileTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); - addProfileTitle.setText("Add Profile"); - addProfileTitle.setMaximumSize(new java.awt.Dimension(300, 30)); - addProfileTitle.setMinimumSize(new java.awt.Dimension(300, 30)); - addProfileTitle.setPreferredSize(new java.awt.Dimension(300, 30)); - getContentPane().add(addProfileTitle, java.awt.BorderLayout.PAGE_START); - - contentContainer.setOpaque(false); - contentContainer.setLayout(new java.awt.GridBagLayout()); - - inputLabel.setText("Display Name:"); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10); - contentContainer.add(inputLabel, gridBagConstraints); - - displayNameInput.setMaximumSize(new java.awt.Dimension(150, 30)); - displayNameInput.setMinimumSize(new java.awt.Dimension(150, 30)); - displayNameInput.setPreferredSize(new java.awt.Dimension(150, 30)); - displayNameInput.addKeyListener(new java.awt.event.KeyAdapter() { - public void keyPressed(java.awt.event.KeyEvent evt) { - keyPressedEvent(evt); - } - }); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; - contentContainer.add(displayNameInput, gridBagConstraints); - - getContentPane().add(contentContainer, java.awt.BorderLayout.CENTER); - - buttonContainer.setBackground(new java.awt.Color(51, 51, 51)); - buttonContainer.setMaximumSize(new java.awt.Dimension(300, 50)); - buttonContainer.setMinimumSize(new java.awt.Dimension(300, 50)); - buttonContainer.setOpaque(false); - buttonContainer.setPreferredSize(new java.awt.Dimension(300, 50)); - java.awt.FlowLayout flowLayout1 = new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 20, 15); - flowLayout1.setAlignOnBaseline(true); - buttonContainer.setLayout(flowLayout1); - - createButton.setText("Create"); - createButton.setMaximumSize(new java.awt.Dimension(80, 25)); - createButton.setMinimumSize(new java.awt.Dimension(80, 25)); - createButton.setPreferredSize(new java.awt.Dimension(80, 25)); - createButton.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - createButtonMouseClicked(evt); - } - }); - buttonContainer.add(createButton); - - cancelButton.setText("Cancel"); - cancelButton.setMaximumSize(new java.awt.Dimension(80, 25)); - cancelButton.setMinimumSize(new java.awt.Dimension(80, 25)); - cancelButton.setPreferredSize(new java.awt.Dimension(80, 25)); - cancelButton.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - cancelButtonMouseClicked(evt); - } - }); - buttonContainer.add(cancelButton); - - getContentPane().add(buttonContainer, java.awt.BorderLayout.SOUTH); - - pack(); - }// //GEN-END:initComponents - - private void createButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createButtonMouseClicked - createProfile(); - }//GEN-LAST:event_createButtonMouseClicked - - private void cancelButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cancelButtonMouseClicked - finish(); - }//GEN-LAST:event_cancelButtonMouseClicked - - private void keyPressedEvent(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyPressedEvent - if (evt.getKeyCode() == 27) - finish(); - else if (evt.getKeyCode() == 10) - createProfile(); - }//GEN-LAST:event_keyPressedEvent - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JTextField displayNameInput; - // End of variables declaration//GEN-END:variables - - void createProfile() { - String fromUser = displayNameInput.getText().trim(); - if (fromUser.isBlank()) return; // TODO Notify user about empty input - - Profile profile = Profiles.create( fromUser ); - MenuProperty.add(profile); - ( (MainMenu) super.getOwner() ).updateProfilesList(); - MenuProperty.active(profile); - - finish(); - } - - private void finish() { - this.setVisible(false); - } -} - diff --git a/src/main/java/me/knighthat/interactivedeck/menus/ProfileConfigurationMenu.form b/src/main/java/me/knighthat/interactivedeck/menus/ProfileConfigurationMenu.form deleted file mode 100644 index d331f18..0000000 --- a/src/main/java/me/knighthat/interactivedeck/menus/ProfileConfigurationMenu.form +++ /dev/null @@ -1,421 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/main/java/me/knighthat/interactivedeck/menus/ProfileConfigurationMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/ProfileConfigurationMenu.java deleted file mode 100644 index b421b8c..0000000 --- a/src/main/java/me/knighthat/interactivedeck/menus/ProfileConfigurationMenu.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2023. Knight Hat - * All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package me.knighthat.interactivedeck.menus; - -import javax.swing.JRootPane; -import javax.swing.SpinnerNumberModel; -import me.knighthat.interactivedeck.file.Profile; -import me.knighthat.interactivedeck.utils.ColorUtils; -import org.jetbrains.annotations.NotNull; - -/** - * - * @author knighthatProfiles.active() - */ -public class ProfileConfigurationMenu extends javax.swing.JDialog { - - /** - * Creates new form ProfileConfigurationMenu - */ - public ProfileConfigurationMenu(java.awt.Frame parent) { - super(parent, false); - - this.profile = MenuProperty.active().get(); - - super.getRootPane().setWindowDecorationStyle( JRootPane.NONE ); - super.setUndecorated( true ); - - initComponents(); - - super.setLocationRelativeTo(parent); - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - java.awt.GridBagConstraints gridBagConstraints; - - javax.swing.JLabel menuTitle = new javax.swing.JLabel(); - javax.swing.JPanel contentContainer = new javax.swing.JPanel(); - javax.swing.JLabel displayNameLabel = new javax.swing.JLabel(); - displayNameInput = new javax.swing.JTextField(profile.displayName()); - javax.swing.JLabel columnsLabel = new javax.swing.JLabel(); - columnsSpinner = new javax.swing.JSpinner(); - javax.swing.JLabel rowsLabel = new javax.swing.JLabel(); - rowsSpinner = new javax.swing.JSpinner(); - javax.swing.JLabel gapLabel = new javax.swing.JLabel(); - gapSpinner = new javax.swing.JSpinner(); - javax.swing.JPanel buttonContainer = new javax.swing.JPanel(); - javax.swing.JButton saveButton = new javax.swing.JButton(); - javax.swing.JButton cancelButton = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - setAutoRequestFocus(false); - setBackground(new java.awt.Color(51, 51, 51)); - setForeground(new java.awt.Color(51, 51, 51)); - setMaximumSize(new java.awt.Dimension(300, 400)); - setMinimumSize(new java.awt.Dimension(300, 400)); - setPreferredSize(new java.awt.Dimension(300, 400)); - setResizable(false); - - menuTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); - menuTitle.setText("Profile Configuration"); - menuTitle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - menuTitle.setMaximumSize(new java.awt.Dimension(200, 30)); - menuTitle.setMinimumSize(new java.awt.Dimension(200, 30)); - menuTitle.setOpaque(true); - menuTitle.setPreferredSize(new java.awt.Dimension(200, 30)); - getContentPane().add(menuTitle, java.awt.BorderLayout.NORTH); - - contentContainer.setMaximumSize(new java.awt.Dimension(200, 50)); - contentContainer.setMinimumSize(new java.awt.Dimension(200, 50)); - contentContainer.setPreferredSize(new java.awt.Dimension(200, 50)); - contentContainer.setLayout(new java.awt.GridBagLayout()); - - displayNameLabel.setText("Display Name"); - displayNameLabel.setMaximumSize(new java.awt.Dimension(150, 20)); - displayNameLabel.setMinimumSize(new java.awt.Dimension(150, 20)); - displayNameLabel.setPreferredSize(new java.awt.Dimension(150, 20)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; - contentContainer.add(displayNameLabel, gridBagConstraints); - - displayNameInput.setPreferredSize(new java.awt.Dimension(150, 30)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 1; - contentContainer.add(displayNameInput, gridBagConstraints); - - columnsLabel.setText("Columns"); - columnsLabel.setMaximumSize(new java.awt.Dimension(150, 20)); - columnsLabel.setMinimumSize(new java.awt.Dimension(150, 20)); - columnsLabel.setPreferredSize(new java.awt.Dimension(150, 20)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 2; - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; - gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0); - contentContainer.add(columnsLabel, gridBagConstraints); - - SpinnerNumberModel cModel = new SpinnerNumberModel(profile.columns(), 1, 10, 1); - columnsSpinner.setModel(cModel); - columnsSpinner.getEditor().getComponent(0).setBackground(ColorUtils.DEFAULT_DARK); - columnsSpinner.setPreferredSize(new java.awt.Dimension(150, 30)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 3; - contentContainer.add(columnsSpinner, gridBagConstraints); - - rowsLabel.setText("Rows"); - rowsLabel.setMaximumSize(new java.awt.Dimension(150, 20)); - rowsLabel.setMinimumSize(new java.awt.Dimension(150, 20)); - rowsLabel.setPreferredSize(new java.awt.Dimension(150, 20)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 4; - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; - gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0); - contentContainer.add(rowsLabel, gridBagConstraints); - - SpinnerNumberModel rModel = new SpinnerNumberModel(profile.rows(), 1, 10, 1); - rowsSpinner.setModel(rModel); - rowsSpinner.getEditor().getComponent(0).setBackground(ColorUtils.DEFAULT_DARK); - rowsSpinner.setPreferredSize(new java.awt.Dimension(150, 30)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 5; - contentContainer.add(rowsSpinner, gridBagConstraints); - - gapLabel.setText("Gap"); - gapLabel.setMaximumSize(new java.awt.Dimension(150, 20)); - gapLabel.setMinimumSize(new java.awt.Dimension(150, 20)); - gapLabel.setPreferredSize(new java.awt.Dimension(150, 20)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 6; - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; - gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0); - contentContainer.add(gapLabel, gridBagConstraints); - - SpinnerNumberModel gModel = new SpinnerNumberModel(profile.gap(), 0, 10, 1); - gapSpinner.setModel(gModel); - gapSpinner.setPreferredSize(new java.awt.Dimension(150, 30)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 7; - contentContainer.add(gapSpinner, gridBagConstraints); - - getContentPane().add(contentContainer, java.awt.BorderLayout.CENTER); - - buttonContainer.setMaximumSize(new java.awt.Dimension(200, 50)); - buttonContainer.setMinimumSize(new java.awt.Dimension(200, 50)); - buttonContainer.setPreferredSize(new java.awt.Dimension(200, 50)); - java.awt.FlowLayout flowLayout1 = new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 20, 15); - flowLayout1.setAlignOnBaseline(true); - buttonContainer.setLayout(flowLayout1); - - saveButton.setText("save"); - saveButton.setMaximumSize(new java.awt.Dimension(80, 25)); - saveButton.setMinimumSize(new java.awt.Dimension(80, 25)); - saveButton.setPreferredSize(new java.awt.Dimension(80, 25)); - saveButton.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - saveButtonMouseClicked(evt); - } - }); - buttonContainer.add(saveButton); - - cancelButton.setText("Cancel"); - cancelButton.setMaximumSize(new java.awt.Dimension(80, 25)); - cancelButton.setMinimumSize(new java.awt.Dimension(80, 25)); - cancelButton.setPreferredSize(new java.awt.Dimension(80, 25)); - cancelButton.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - cancelButtonMouseClicked(evt); - } - }); - buttonContainer.add(cancelButton); - - getContentPane().add(buttonContainer, java.awt.BorderLayout.PAGE_END); - - pack(); - }// //GEN-END:initComponents - - private void cancelButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cancelButtonMouseClicked - finish(); - }//GEN-LAST:event_cancelButtonMouseClicked - - private void saveButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveButtonMouseClicked - profile.displayName(displayNameInput.getText()); - profile.columns(validate(columnsSpinner.getValue(), 1 )); - profile.rows(validate(rowsSpinner.getValue(), 1 )); - profile.gap(validate(gapSpinner.getValue(), 0 )); - - ((MainMenu) getOwner()).updateButtons( profile ); - - finish(); - }//GEN-LAST:event_saveButtonMouseClicked - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JSpinner columnsSpinner; - private javax.swing.JTextField displayNameInput; - private javax.swing.JSpinner gapSpinner; - private javax.swing.JSpinner rowsSpinner; - // End of variables declaration//GEN-END:variables - - private final @NotNull Profile profile; - - int validate(@NotNull Object obj, int min) { - if (!( obj instanceof Integer number )) - return min; - return number < min ? min : Math.min(number, 10); - } - - private void finish() { - this.setVisible(false); - } -} diff --git a/src/main/java/me/knighthat/interactivedeck/menus/popup/AddProfilePopup.java b/src/main/java/me/knighthat/interactivedeck/menus/popup/AddProfilePopup.java new file mode 100644 index 0000000..d172be6 --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/menus/popup/AddProfilePopup.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.knighthat.interactivedeck.menus.popup; + +import me.knighthat.interactivedeck.file.Profile; +import me.knighthat.interactivedeck.file.Profiles; +import me.knighthat.interactivedeck.menus.MainMenu; +import me.knighthat.interactivedeck.menus.MenuProperty; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +public class AddProfilePopup extends PopupMenu { + + private JTextField displayNameInput; + + public AddProfilePopup( @NotNull Window owner ) { + super( owner, "Add Profile" ); + + // Create and add "Create" button + addButton( button -> { + button.setText( "Create" ); + button.addMouseListener( new MouseAdapter() { + @Override + public void mouseClicked( MouseEvent e ) { + createProfile(); + } + } ); + } ); + + // Create and add "Cancel" button + addButton( button -> { + button.setText( "Cancel" ); + button.addMouseListener( new MouseAdapter() { + public void mouseClicked( MouseEvent evt ) { + finish(); + } + } ); + } ); + } + + @Override + void initContent() { + + addContent( new JLabel( "Display Name:" ), label -> {}, constraints -> { + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.anchor = GridBagConstraints.WEST; + constraints.insets = new Insets( 0, 0, 0, 10 ); + } ); + addContent( + new JTextField(), + comp -> { + setDimension( comp, 150, 30 ); + + this.displayNameInput = (JTextField) comp; + + comp.addKeyListener( new KeyAdapter() { + public void keyPressed( KeyEvent evt ) { + if (evt.getKeyCode() == 27) + finish(); + else if (evt.getKeyCode() == 10) + createProfile(); + } + } ); + }, + constraints -> { + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.anchor = GridBagConstraints.EAST; + } + ); + } + + private void createProfile() { + String fromUser = displayNameInput.getText().trim(); + if (fromUser.isBlank()) + return; // TODO Notify user about empty input + + Profile profile = Profiles.create( fromUser ); + MenuProperty.add( profile ); + ( (MainMenu) super.getOwner() ).updateProfilesList(); + MenuProperty.active( profile ); + + finish(); + } +} diff --git a/src/main/java/me/knighthat/interactivedeck/menus/popup/ProfileConfigurationPopup.java b/src/main/java/me/knighthat/interactivedeck/menus/popup/ProfileConfigurationPopup.java new file mode 100644 index 0000000..04b7bd5 --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/menus/popup/ProfileConfigurationPopup.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.knighthat.interactivedeck.menus.popup; + +import me.knighthat.interactivedeck.file.Profile; +import me.knighthat.interactivedeck.menus.MainMenu; +import me.knighthat.interactivedeck.menus.MenuProperty; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +public class ProfileConfigurationPopup extends PopupMenu { + + private Profile profile; + private JTextField displayNameInput; + private JSpinner columns; + private JSpinner rows; + private JSpinner gap; + + public ProfileConfigurationPopup( @NotNull Window owner ) { + super( owner, "Profile Configuration" ); + + // Create and add "Create" button + addButton( button -> { + button.setText( "Apply" ); + button.addMouseListener( new MouseAdapter() { + @Override + public void mouseClicked( MouseEvent e ) { + apply(); + } + } ); + } ); + + // Create and add "Cancel" button + addButton( button -> { + button.setText( "Cancel" ); + button.addMouseListener( new MouseAdapter() { + public void mouseClicked( MouseEvent evt ) { + finish(); + } + } ); + } ); + } + + @Override + void initContent() { + profile = MenuProperty.active().orElse( MenuProperty.defaultProfile() ); + + addContent( + new JLabel( "Display Name" ), + label -> setDimension( label, 150, 20 ), + constraints -> constraints.anchor = GridBagConstraints.WEST + ); + addContent( + new JTextField(), + comp -> { + setDimension( comp, 150, 30 ); + displayNameInput = (JTextField) comp; + displayNameInput.setText( profile.displayName() ); + }, + constraints -> constraints.gridy = 1 + ); + + + columns = spinner( "Columns", 2, profile.columns(), 1 ); + rows = spinner( "Rows", 4, profile.rows(), 1 ); + gap = spinner( "Gap", 6, profile.gap(), 0 ); + } + + private @NotNull JSpinner spinner( @NotNull String name, int gridy, int curValue, int min ) { + addContent( + new JLabel( name ), + label -> setDimension( label, 150, 20 ), + constraints -> { + constraints.gridy = gridy; + constraints.anchor = GridBagConstraints.WEST; + constraints.insets = new Insets( 10, 0, 0, 0 ); + } + ); + return (JSpinner) addContent( + new JSpinner(), + comp -> { + setDimension( comp, 150, 30 ); + + SpinnerModel model = new SpinnerNumberModel( curValue, min, 10, 1 ); + ( (JSpinner) comp ).setModel( model ); + }, + constraints -> constraints.gridy = gridy + 1 + ); + } + + private void apply() { + profile.displayName( displayNameInput.getText() ); + profile.columns( validate( columns.getValue(), 1 ) ); + profile.rows( validate( rows.getValue(), 1 ) ); + profile.gap( validate( gap.getValue(), 0 ) ); + + ( (MainMenu) getOwner() ).updateButtons( profile ); + + finish(); + } + + int validate( @NotNull Object obj, int min ) { + if (!( obj instanceof Integer number )) + return min; + return number < min ? min : Math.min( number, 10 ); + } +} From 1fe6d2a4c0a5e8851efe2220448c40dc55a5f064 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Wed, 13 Sep 2023 09:39:53 -0500 Subject: [PATCH 26/93] switched to PopupMenu for add/configure profile menus --- .../interactivedeck/menus/MainMenu.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java index c595efe..b1d7f44 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java @@ -211,9 +211,9 @@ public void mouseClicked(java.awt.event.MouseEvent evt) { getContentPane().add(statusSection, java.awt.BorderLayout.SOUTH); }// //GEN-END:initComponents - private void addButtonClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addButtonClicked - JDialog dialog = new AddProfileMenu(this); - dialog.setVisible(true); + private void addButtonClicked( java.awt.event.MouseEvent evt ) {//GEN-FIRST:event_addButtonClicked + PopupMenu dialog = new AddProfilePopup( this ); + dialog.setVisible( true ); }//GEN-LAST:event_addButtonClicked private void removeProfilesButtonClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeProfilesButtonClicked @@ -227,13 +227,9 @@ private void removeProfilesButtonClicked(java.awt.event.MouseEvent evt) {//GEN-F MenuProperty.active(profile); }//GEN-LAST:event_removeProfilesButtonClicked - private void configureProfileButtonClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_configureProfileButtonClicked - Profile selected = (Profile) profilesList.getSelectedItem(); - if (selected == null) - return; - - JDialog dialog = new ProfileConfigurationMenu(this); - dialog.setVisible(true); + private void configureProfileButtonClicked( java.awt.event.MouseEvent evt ) {//GEN-FIRST:event_configureProfileButtonClicked + PopupMenu dialog = new ProfileConfigurationPopup( this ); + dialog.setVisible( true ); }//GEN-LAST:event_configureProfileButtonClicked private void profilesListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_profilesListActionPerformed From 33a72c4e8b1d161c4317fd8eb5aa42adbe677956 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Wed, 13 Sep 2023 09:41:02 -0500 Subject: [PATCH 27/93] re-format to improve readability --- .../interactivedeck/menus/MainMenu.form | 10 +- .../interactivedeck/menus/MainMenu.java | 323 +++++++++--------- .../menus/modifier/IconModifierPanel.java | 167 ++++----- .../menus/modifier/TaskModifierPanel.java | 19 +- .../menus/modifier/TextModifierPanel.java | 159 ++++----- 5 files changed, 354 insertions(+), 324 deletions(-) diff --git a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form index efc9e0f..ca06eb7 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form +++ b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.form @@ -66,13 +66,13 @@ - + - + @@ -80,7 +80,7 @@ - + @@ -284,6 +284,10 @@
+ + + + diff --git a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java index b1d7f44..c96e877 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java @@ -1,50 +1,70 @@ /* * Copyright (c) 2023. Knight Hat * All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package me.knighthat.interactivedeck.menus; import com.google.gson.JsonObject; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; import me.knighthat.interactivedeck.component.ibutton.IButton; import me.knighthat.interactivedeck.component.plist.ProfileButton; import me.knighthat.interactivedeck.connection.Connection; import me.knighthat.interactivedeck.file.Profile; -import static me.knighthat.interactivedeck.file.Settings.*; import me.knighthat.interactivedeck.json.Json; import me.knighthat.interactivedeck.logging.Log; +import me.knighthat.interactivedeck.menus.popup.AddProfilePopup; +import me.knighthat.interactivedeck.menus.popup.PopupMenu; +import me.knighthat.interactivedeck.menus.popup.ProfileConfigurationPopup; import me.knighthat.interactivedeck.observable.Observable; import me.knighthat.interactivedeck.utils.ColorUtils; import me.knighthat.interactivedeck.utils.GlobalVars; import me.knighthat.interactivedeck.utils.UuidUtils; import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import static me.knighthat.interactivedeck.file.Settings.*; + /** - * * @author knighthat */ public class MainMenu extends javax.swing.JFrame { + private final @NotNull Observable bSelected = Observable.of( null ); + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel btnModifierSection; + private javax.swing.JPanel iBtnSection; + private me.knighthat.interactivedeck.component.plist.ProfilesComboBox profilesList; + // End of variables declaration//GEN-END:variables + /** * Creates new form MainMenu */ public MainMenu() { - super(GlobalVars.name() + " - " + GlobalVars.version()); + super( GlobalVars.name() + " - " + GlobalVars.version() ); initComponents(); initButtonObserver(); MenuProperty.observeActive( profilesList::setSelectedItem ); - addWindowListener(new WindowAdapter() { + addWindowListener( new WindowAdapter() { @Override - public void windowClosing(WindowEvent e) { + public void windowClosing( WindowEvent e ) { bSelected.value().ifPresent( IButton::toggleSelect ); Json.dump( FILE.getName(), () -> { @@ -57,17 +77,17 @@ public void windowClosing(WindowEvent e) { return json; } ); MenuProperty - .profiles() - .forEach( profile -> Json.dump( profile.uuid + ".profile", profile ) ); + .profiles() + .forEach( profile -> Json.dump( profile.uuid + ".profile", profile ) ); - super.windowClosing(e); + super.windowClosing( e ); } - }); + } ); // Show default profile - MenuProperty.active(MenuProperty.defaultProfile()); + MenuProperty.active( MenuProperty.defaultProfile() ); - setLocationRelativeTo(null); + setLocationRelativeTo( null ); } /** @@ -75,140 +95,140 @@ public void windowClosing(WindowEvent e) { * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) // //GEN-BEGIN:initComponents private void initComponents() { javax.swing.JPanel profilesSection = new javax.swing.JPanel(); profilesList = new me.knighthat.interactivedeck.component.plist.ProfilesComboBox(); - me.knighthat.interactivedeck.component.plist.ProfileButton addProfileButton = new ProfileButton(ProfileButton.ButtonType.ADD); - me.knighthat.interactivedeck.component.plist.ProfileButton removeProfileButton = new ProfileButton(ProfileButton.ButtonType.REMOVE); - me.knighthat.interactivedeck.component.plist.ProfileButton configureProfileButton = new ProfileButton(ProfileButton.ButtonType.CONFIGURE); + me.knighthat.interactivedeck.component.plist.ProfileButton addProfileButton = new ProfileButton( ProfileButton.ButtonType.ADD ); + me.knighthat.interactivedeck.component.plist.ProfileButton removeProfileButton = new ProfileButton( ProfileButton.ButtonType.REMOVE ); + me.knighthat.interactivedeck.component.plist.ProfileButton configureProfileButton = new ProfileButton( ProfileButton.ButtonType.CONFIGURE ); iBtnSection = new javax.swing.JPanel(); btnModifierSection = new javax.swing.JPanel(); javax.swing.JPanel statusSection = new javax.swing.JPanel(); me.knighthat.interactivedeck.component.netstatus.ConStatus conStatus = Connection.component(); - notificationCenter1 = new me.knighthat.interactivedeck.menus.NotificationCenter(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - setBackground(new java.awt.Color(153, 153, 153)); - setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); - setMaximumSize(new java.awt.Dimension(1000, 600)); - setMinimumSize(new java.awt.Dimension(1000, 600)); - setResizable(false); - - profilesSection.setBackground(new java.awt.Color(36, 36, 36)); - profilesSection.setPreferredSize(new java.awt.Dimension(1000, 50)); - - profilesList.setBackground(new java.awt.Color(51, 51, 51)); - profilesList.setMaximumSize(new java.awt.Dimension(300, 30)); - profilesList.setMinimumSize(new java.awt.Dimension(300, 30)); - profilesList.setPreferredSize(new java.awt.Dimension(300, 30)); - profilesList.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - profilesListActionPerformed(evt); + me.knighthat.interactivedeck.menus.NotificationCenter notificationCenter1 = new me.knighthat.interactivedeck.menus.NotificationCenter(); + + setDefaultCloseOperation( javax.swing.WindowConstants.EXIT_ON_CLOSE ); + setBackground( new java.awt.Color( 153, 153, 153 ) ); + setCursor( new java.awt.Cursor( java.awt.Cursor.DEFAULT_CURSOR ) ); + setMaximumSize( new java.awt.Dimension( 1000, 600 ) ); + setMinimumSize( new java.awt.Dimension( 1000, 600 ) ); + setResizable( false ); + + profilesSection.setBackground( new java.awt.Color( 36, 36, 36 ) ); + profilesSection.setPreferredSize( new java.awt.Dimension( 1000, 50 ) ); + + profilesList.setBackground( new java.awt.Color( 51, 51, 51 ) ); + profilesList.setMaximumSize( new java.awt.Dimension( 300, 30 ) ); + profilesList.setMinimumSize( new java.awt.Dimension( 300, 30 ) ); + profilesList.setPreferredSize( new java.awt.Dimension( 300, 30 ) ); + profilesList.addActionListener( new java.awt.event.ActionListener() { + public void actionPerformed( java.awt.event.ActionEvent evt ) { + profilesListActionPerformed( evt ); } - }); - - addProfileButton.setMaximumSize(new java.awt.Dimension(30, 30)); - addProfileButton.setMinimumSize(new java.awt.Dimension(30, 30)); - addProfileButton.setPreferredSize(new java.awt.Dimension(30, 30)); - addProfileButton.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - addButtonClicked(evt); + } ); + + addProfileButton.setMaximumSize( new java.awt.Dimension( 30, 30 ) ); + addProfileButton.setMinimumSize( new java.awt.Dimension( 30, 30 ) ); + addProfileButton.setPreferredSize( new java.awt.Dimension( 30, 30 ) ); + addProfileButton.addMouseListener( new java.awt.event.MouseAdapter() { + public void mouseClicked( java.awt.event.MouseEvent evt ) { + addButtonClicked( evt ); } - }); - - removeProfileButton.setMaximumSize(new java.awt.Dimension(30, 30)); - removeProfileButton.setMinimumSize(new java.awt.Dimension(30, 30)); - removeProfileButton.setPreferredSize(new java.awt.Dimension(30, 30)); - removeProfileButton.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - removeProfilesButtonClicked(evt); + } ); + + removeProfileButton.setMaximumSize( new java.awt.Dimension( 30, 30 ) ); + removeProfileButton.setMinimumSize( new java.awt.Dimension( 30, 30 ) ); + removeProfileButton.setPreferredSize( new java.awt.Dimension( 30, 30 ) ); + removeProfileButton.addMouseListener( new java.awt.event.MouseAdapter() { + public void mouseClicked( java.awt.event.MouseEvent evt ) { + removeProfilesButtonClicked( evt ); } - }); - - configureProfileButton.setMaximumSize(new java.awt.Dimension(30, 30)); - configureProfileButton.setMinimumSize(new java.awt.Dimension(30, 30)); - configureProfileButton.setPreferredSize(new java.awt.Dimension(30, 30)); - configureProfileButton.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { - configureProfileButtonClicked(evt); + } ); + + configureProfileButton.setMaximumSize( new java.awt.Dimension( 30, 30 ) ); + configureProfileButton.setMinimumSize( new java.awt.Dimension( 30, 30 ) ); + configureProfileButton.setPreferredSize( new java.awt.Dimension( 30, 30 ) ); + configureProfileButton.addMouseListener( new java.awt.event.MouseAdapter() { + public void mouseClicked( java.awt.event.MouseEvent evt ) { + configureProfileButtonClicked( evt ); } - }); + } ); - javax.swing.GroupLayout profilesSectionLayout = new javax.swing.GroupLayout(profilesSection); - profilesSection.setLayout(profilesSectionLayout); + javax.swing.GroupLayout profilesSectionLayout = new javax.swing.GroupLayout( profilesSection ); + profilesSection.setLayout( profilesSectionLayout ); profilesSectionLayout.setHorizontalGroup( - profilesSectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(profilesSectionLayout.createSequentialGroup() - .addGap(30, 30, 30) - .addComponent(profilesList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addComponent(addProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(removeProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(configureProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(538, 538, 538)) + profilesSectionLayout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING ) + .addGroup( profilesSectionLayout.createSequentialGroup() + .addGap( 30, 30, 30 ) + .addComponent( profilesList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ) + .addGap( 18, 18, 18 ) + .addComponent( addProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ) + .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED ) + .addComponent( removeProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ) + .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED ) + .addComponent( configureProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ) + .addContainerGap( 544, Short.MAX_VALUE ) ) ); profilesSectionLayout.setVerticalGroup( - profilesSectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(profilesSectionLayout.createSequentialGroup() - .addGap(10, 10, 10) - .addGroup(profilesSectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(configureProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(removeProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(addProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(profilesList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(10, 10, 10)) + profilesSectionLayout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING ) + .addGroup( profilesSectionLayout.createSequentialGroup() + .addGap( 10, 10, 10 ) + .addGroup( profilesSectionLayout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING ) + .addComponent( configureProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ) + .addComponent( removeProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ) + .addComponent( addProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ) + .addComponent( profilesList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ) ) + .addContainerGap( 10, Short.MAX_VALUE ) ) ); - getContentPane().add(profilesSection, java.awt.BorderLayout.NORTH); - - iBtnSection.setBackground(new java.awt.Color(51, 51, 51)); - iBtnSection.setDoubleBuffered(false); - iBtnSection.setMaximumSize(new java.awt.Dimension(750, 520)); - iBtnSection.setMinimumSize(new java.awt.Dimension(750, 520)); - iBtnSection.setPreferredSize(new java.awt.Dimension(750, 520)); - iBtnSection.setLayout(new java.awt.GridBagLayout()); - getContentPane().add(iBtnSection, java.awt.BorderLayout.WEST); - - btnModifierSection.setBackground(new java.awt.Color(36, 36, 36)); - btnModifierSection.setDoubleBuffered(false); - btnModifierSection.setMaximumSize(new java.awt.Dimension(250, 520)); - btnModifierSection.setMinimumSize(new java.awt.Dimension(250, 520)); - btnModifierSection.setPreferredSize(new java.awt.Dimension(250, 520)); - btnModifierSection.setLayout(new java.awt.BorderLayout()); - getContentPane().add(btnModifierSection, java.awt.BorderLayout.CENTER); - - statusSection.setBackground(new java.awt.Color(36, 36, 36)); - statusSection.setAlignmentX(0.0F); - statusSection.setAlignmentY(0.0F); - statusSection.setPreferredSize(new java.awt.Dimension(1000, 30)); - - javax.swing.GroupLayout statusSectionLayout = new javax.swing.GroupLayout(statusSection); - statusSection.setLayout(statusSectionLayout); + getContentPane().add( profilesSection, java.awt.BorderLayout.NORTH ); + + iBtnSection.setBackground( new java.awt.Color( 51, 51, 51 ) ); + iBtnSection.setDoubleBuffered( false ); + iBtnSection.setMaximumSize( new java.awt.Dimension( 750, 520 ) ); + iBtnSection.setMinimumSize( new java.awt.Dimension( 750, 520 ) ); + iBtnSection.setPreferredSize( new java.awt.Dimension( 750, 520 ) ); + iBtnSection.setLayout( new java.awt.GridBagLayout() ); + getContentPane().add( iBtnSection, java.awt.BorderLayout.WEST ); + + btnModifierSection.setBackground( new java.awt.Color( 36, 36, 36 ) ); + btnModifierSection.setDoubleBuffered( false ); + btnModifierSection.setMaximumSize( new java.awt.Dimension( 250, 520 ) ); + btnModifierSection.setMinimumSize( new java.awt.Dimension( 250, 520 ) ); + btnModifierSection.setPreferredSize( new java.awt.Dimension( 250, 520 ) ); + btnModifierSection.setLayout( new java.awt.BorderLayout() ); + getContentPane().add( btnModifierSection, java.awt.BorderLayout.CENTER ); + + statusSection.setBackground( new java.awt.Color( 36, 36, 36 ) ); + statusSection.setAlignmentX( 0.0F ); + statusSection.setAlignmentY( 0.0F ); + statusSection.setPreferredSize( new java.awt.Dimension( 1000, 30 ) ); + + javax.swing.GroupLayout statusSectionLayout = new javax.swing.GroupLayout( statusSection ); + statusSection.setLayout( statusSectionLayout ); statusSectionLayout.setHorizontalGroup( - statusSectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(statusSectionLayout.createSequentialGroup() - .addGap(30, 30, 30) - .addComponent(conStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 349, Short.MAX_VALUE) - .addComponent(notificationCenter1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) + statusSectionLayout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING ) + .addGroup( statusSectionLayout.createSequentialGroup() + .addGap( 30, 30, 30 ) + .addComponent( conStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ) + .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, 349, Short.MAX_VALUE ) + .addComponent( notificationCenter1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ) + .addContainerGap() ) ); statusSectionLayout.setVerticalGroup( - statusSectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(statusSectionLayout.createSequentialGroup() - .addGroup(statusSectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(conStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(notificationCenter1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 0, Short.MAX_VALUE)) + statusSectionLayout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING ) + .addGroup( statusSectionLayout.createSequentialGroup() + .addGroup( statusSectionLayout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING ) + .addComponent( conStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ) + .addComponent( notificationCenter1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ) ) + .addGap( 0, 0, Short.MAX_VALUE ) ) ); - getContentPane().add(statusSection, java.awt.BorderLayout.SOUTH); + getContentPane().add( statusSection, java.awt.BorderLayout.SOUTH ); }// //GEN-END:initComponents private void addButtonClicked( java.awt.event.MouseEvent evt ) {//GEN-FIRST:event_addButtonClicked @@ -216,7 +236,7 @@ private void addButtonClicked( java.awt.event.MouseEvent evt ) {//GEN-FIRST:even dialog.setVisible( true ); }//GEN-LAST:event_addButtonClicked - private void removeProfilesButtonClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeProfilesButtonClicked + private void removeProfilesButtonClicked( java.awt.event.MouseEvent evt ) {//GEN-FIRST:event_removeProfilesButtonClicked Profile selected = (Profile) profilesList.getSelectedItem(); if (selected == null || selected.isDefault) return; @@ -224,7 +244,7 @@ private void removeProfilesButtonClicked(java.awt.event.MouseEvent evt) {//GEN-F updateProfilesList(); Profile profile = MenuProperty.defaultProfile(); - MenuProperty.active(profile); + MenuProperty.active( profile ); }//GEN-LAST:event_removeProfilesButtonClicked private void configureProfileButtonClicked( java.awt.event.MouseEvent evt ) {//GEN-FIRST:event_configureProfileButtonClicked @@ -232,63 +252,55 @@ private void configureProfileButtonClicked( java.awt.event.MouseEvent evt ) {//G dialog.setVisible( true ); }//GEN-LAST:event_configureProfileButtonClicked - private void profilesListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_profilesListActionPerformed + private void profilesListActionPerformed( java.awt.event.ActionEvent evt ) {//GEN-FIRST:event_profilesListActionPerformed Profile profile = (Profile) profilesList.getSelectedItem(); if (profile != null && evt.getActionCommand().equals( "comboBoxChanged" )) updateButtons( profile ); }//GEN-LAST:event_profilesListActionPerformed - void iBtnClickEvent(java.awt.event.MouseEvent evt) { + void iBtnClickEvent( java.awt.event.MouseEvent evt ) { IButton selected = (IButton) evt.getComponent(); bSelected.value().ifPresentOrElse( currentlySelected -> { currentlySelected.toggleSelect(); - bSelected.value(currentlySelected == selected ? null : selected); + bSelected.value( currentlySelected == selected ? null : selected ); - }, () -> bSelected.value(selected) ); + }, () -> bSelected.value( selected ) ); String deb = "Button %s@x:%s,y:%s clicked!"; String shortUuid = UuidUtils.lastFiveChars( selected.uuid ); - Log.deb( deb.formatted( shortUuid, selected.x, selected.y) ); + Log.deb( deb.formatted( shortUuid, selected.x, selected.y ) ); } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JPanel btnModifierSection; - private javax.swing.JPanel iBtnSection; - private me.knighthat.interactivedeck.menus.NotificationCenter notificationCenter1; - private me.knighthat.interactivedeck.component.plist.ProfilesComboBox profilesList; - // End of variables declaration//GEN-END:variables - private final @NotNull Observable bSelected = Observable.of( null );; - - public void updateButtons(@NotNull Profile profile) { + public void updateButtons( @NotNull Profile profile ) { iBtnSection.removeAll(); bSelected.value().ifPresent( IButton::toggleSelect ); - bSelected.value(null); + bSelected.value( null ); GridBagConstraints constraints = genConstraints( profile ); - profile.buttons().forEach((button) -> { + profile.buttons().forEach( ( button ) -> { if (button.getMouseListeners().length == 0) - button.addMouseListener(new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - iBtnClickEvent(e); + button.addMouseListener( new MouseAdapter() { + public void mouseClicked( MouseEvent e ) { + iBtnClickEvent( e ); } - }); + } ); constraints.gridx = button.x; constraints.gridy = button.y; - this.iBtnSection.add(button, constraints); - }); + this.iBtnSection.add( button, constraints ); + } ); iBtnSection.revalidate(); iBtnSection.repaint(); } - @NotNull GridBagConstraints genConstraints(@NotNull Profile profile) { + @NotNull GridBagConstraints genConstraints( @NotNull Profile profile ) { int gap = profile.gap(); - int spaceX = profile.columns() * (IButton.DIMENSION.width + gap) - gap; // Horizontal space (includes gaps) taken by buttons - int spaceY = profile.rows() * (IButton.DIMENSION.height + gap) - gap; // Vertical space (includes gaps taken by buttons + int spaceX = profile.columns() * ( IButton.DIMENSION.width + gap ) - gap; // Horizontal space (includes gaps) taken by buttons + int spaceY = profile.rows() * ( IButton.DIMENSION.height + gap ) - gap; // Vertical space (includes gaps taken by buttons Dimension sectionSize = iBtnSection.getPreferredSize(); // Area buttons can be shown GridBagConstraints constraints = new GridBagConstraints(); @@ -308,18 +320,19 @@ void initButtonObserver() { btnModifierSection.revalidate(); btnModifierSection.repaint(); - if (btn == null) return; + if (btn == null) + return; btn.toggleSelect(); - ModifierContainer panel = new ModifierContainer(btn); + ModifierContainer panel = new ModifierContainer( btn ); btnModifierSection.add( panel, BorderLayout.PAGE_START ); } ); } public void updateProfilesList() { profilesList.removeAll(); - ComboBoxModel model = new DefaultComboBoxModel<>(MenuProperty.profileArray()); + ComboBoxModel model = new DefaultComboBoxModel<>( MenuProperty.profileArray() ); profilesList.setModel( model ); profilesList.revalidate(); profilesList.repaint(); diff --git a/src/main/java/me/knighthat/interactivedeck/menus/modifier/IconModifierPanel.java b/src/main/java/me/knighthat/interactivedeck/menus/modifier/IconModifierPanel.java index e418933..e9f4a17 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/modifier/IconModifierPanel.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/modifier/IconModifierPanel.java @@ -1,32 +1,45 @@ /* * Copyright (c) 2023. Knight Hat * All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package me.knighthat.interactivedeck.menus.modifier; -import java.awt.*; import me.knighthat.interactivedeck.component.ibutton.IButton; import me.knighthat.interactivedeck.component.input.HexColorTextField; import me.knighthat.interactivedeck.utils.ColorUtils; -import org.jetbrains.annotations.NotNull;/** - * +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +/** * @author knighthat */ public class IconModifierPanel extends javax.swing.JPanel { + // Variables declaration - do not modify//GEN-BEGIN:variables + private me.knighthat.interactivedeck.component.input.HexColorTextField bdInput; + private me.knighthat.interactivedeck.component.input.HexColorTextField bgInput; + private me.knighthat.interactivedeck.component.input.HexColorTextField fgInput; + // End of variables declaration//GEN-END:variables + private @NotNull IButton selected; + /** * Creates new form IconModifierPanel */ public IconModifierPanel() { initComponents(); } - - public IconModifierPanel(@NotNull IButton selected) { + + public IconModifierPanel( @NotNull IButton selected ) { this(); this.selected = selected; updateInputColors(); @@ -37,7 +50,7 @@ public IconModifierPanel(@NotNull IButton selected) { * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) // //GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; @@ -49,112 +62,105 @@ private void initComponents() { javax.swing.JLabel bdLabel = new javax.swing.JLabel(); bdInput = new me.knighthat.interactivedeck.component.input.HexColorTextField(); - setBackground(new java.awt.Color(36, 36, 36)); - setMaximumSize(new java.awt.Dimension(250, 489)); - setMinimumSize(new java.awt.Dimension(250, 489)); + setBackground( new java.awt.Color( 36, 36, 36 ) ); + setMaximumSize( new java.awt.Dimension( 250, 489 ) ); + setMinimumSize( new java.awt.Dimension( 250, 489 ) ); java.awt.GridBagLayout layout = new java.awt.GridBagLayout(); - layout.columnWidths = new int[] {210}; - setLayout(layout); + layout.columnWidths = new int[]{ 210 }; + setLayout( layout ); - fgLabel.setForeground(new java.awt.Color(255, 255, 255)); - fgLabel.setText("Foreground"); + fgLabel.setForeground( new java.awt.Color( 255, 255, 255 ) ); + fgLabel.setText( "Foreground" ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; - add(fgLabel, gridBagConstraints); - - fgInput.setMaximumSize(new java.awt.Dimension(210, 40)); - fgInput.setMinimumSize(new java.awt.Dimension(210, 40)); - fgInput.setPreferredSize(new java.awt.Dimension(210, 40)); - fgInput.addFocusListener(new java.awt.event.FocusAdapter() { - public void focusLost(java.awt.event.FocusEvent evt) { - inputLostFocusEvent(evt); + add( fgLabel, gridBagConstraints ); + + fgInput.setMaximumSize( new java.awt.Dimension( 210, 40 ) ); + fgInput.setMinimumSize( new java.awt.Dimension( 210, 40 ) ); + fgInput.setPreferredSize( new java.awt.Dimension( 210, 40 ) ); + fgInput.addFocusListener( new java.awt.event.FocusAdapter() { + public void focusLost( java.awt.event.FocusEvent evt ) { + inputLostFocusEvent( evt ); } - }); - fgInput.addKeyListener(new java.awt.event.KeyAdapter() { - public void keyPressed(java.awt.event.KeyEvent evt) { - inputEnterPressedEvent(evt); + } ); + fgInput.addKeyListener( new java.awt.event.KeyAdapter() { + public void keyPressed( java.awt.event.KeyEvent evt ) { + inputEnterPressedEvent( evt ); } - }); + } ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 40, 0); - add(fgInput, gridBagConstraints); + gridBagConstraints.insets = new java.awt.Insets( 0, 0, 40, 0 ); + add( fgInput, gridBagConstraints ); - bgLabel1.setForeground(new java.awt.Color(255, 255, 255)); - bgLabel1.setText("Background"); + bgLabel1.setForeground( new java.awt.Color( 255, 255, 255 ) ); + bgLabel1.setText( "Background" ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; - add(bgLabel1, gridBagConstraints); - - bgInput.setMaximumSize(new java.awt.Dimension(210, 40)); - bgInput.setMinimumSize(new java.awt.Dimension(210, 40)); - bgInput.setPreferredSize(new java.awt.Dimension(210, 40)); - bgInput.addFocusListener(new java.awt.event.FocusAdapter() { - public void focusLost(java.awt.event.FocusEvent evt) { - inputLostFocusEvent(evt); + add( bgLabel1, gridBagConstraints ); + + bgInput.setMaximumSize( new java.awt.Dimension( 210, 40 ) ); + bgInput.setMinimumSize( new java.awt.Dimension( 210, 40 ) ); + bgInput.setPreferredSize( new java.awt.Dimension( 210, 40 ) ); + bgInput.addFocusListener( new java.awt.event.FocusAdapter() { + public void focusLost( java.awt.event.FocusEvent evt ) { + inputLostFocusEvent( evt ); } - }); - bgInput.addKeyListener(new java.awt.event.KeyAdapter() { - public void keyPressed(java.awt.event.KeyEvent evt) { - inputEnterPressedEvent(evt); + } ); + bgInput.addKeyListener( new java.awt.event.KeyAdapter() { + public void keyPressed( java.awt.event.KeyEvent evt ) { + inputEnterPressedEvent( evt ); } - }); + } ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 40, 0); - add(bgInput, gridBagConstraints); + gridBagConstraints.insets = new java.awt.Insets( 0, 0, 40, 0 ); + add( bgInput, gridBagConstraints ); - bdLabel.setForeground(new java.awt.Color(255, 255, 255)); - bdLabel.setText("Border"); + bdLabel.setForeground( new java.awt.Color( 255, 255, 255 ) ); + bdLabel.setText( "Border" ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; - add(bdLabel, gridBagConstraints); - - bdInput.setMaximumSize(new java.awt.Dimension(210, 40)); - bdInput.setMinimumSize(new java.awt.Dimension(210, 40)); - bdInput.setPreferredSize(new java.awt.Dimension(210, 40)); - bdInput.addFocusListener(new java.awt.event.FocusAdapter() { - public void focusLost(java.awt.event.FocusEvent evt) { - inputLostFocusEvent(evt); + add( bdLabel, gridBagConstraints ); + + bdInput.setMaximumSize( new java.awt.Dimension( 210, 40 ) ); + bdInput.setMinimumSize( new java.awt.Dimension( 210, 40 ) ); + bdInput.setPreferredSize( new java.awt.Dimension( 210, 40 ) ); + bdInput.addFocusListener( new java.awt.event.FocusAdapter() { + public void focusLost( java.awt.event.FocusEvent evt ) { + inputLostFocusEvent( evt ); } - }); - bdInput.addKeyListener(new java.awt.event.KeyAdapter() { - public void keyPressed(java.awt.event.KeyEvent evt) { - inputEnterPressedEvent(evt); + } ); + bdInput.addKeyListener( new java.awt.event.KeyAdapter() { + public void keyPressed( java.awt.event.KeyEvent evt ) { + inputEnterPressedEvent( evt ); } - }); + } ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 5; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - add(bdInput, gridBagConstraints); + add( bdInput, gridBagConstraints ); }// //GEN-END:initComponents - private void inputLostFocusEvent(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_inputLostFocusEvent + private void inputLostFocusEvent( java.awt.event.FocusEvent evt ) {//GEN-FIRST:event_inputLostFocusEvent this.applyColor( evt.getSource() ); }//GEN-LAST:event_inputLostFocusEvent - private void inputEnterPressedEvent(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_inputEnterPressedEvent - if (evt.getKeyCode() != 10) return; + private void inputEnterPressedEvent( java.awt.event.KeyEvent evt ) {//GEN-FIRST:event_inputEnterPressedEvent + if (evt.getKeyCode() != 10) + return; this.applyColor( evt.getSource() ); }//GEN-LAST:event_inputEnterPressedEvent - - // Variables declaration - do not modify//GEN-BEGIN:variables - private me.knighthat.interactivedeck.component.input.HexColorTextField bdInput; - private me.knighthat.interactivedeck.component.input.HexColorTextField bgInput; - private me.knighthat.interactivedeck.component.input.HexColorTextField fgInput; - // End of variables declaration//GEN-END:variables - private @NotNull IButton selected; - private void updateInputColors() { Color background = selected.background(); updateColor( bgInput, background ); @@ -166,7 +172,7 @@ private void updateInputColors() { updateColor( bdInput, border ); } - private void updateColor(@NotNull HexColorTextField target, @NotNull Color color) { + private void updateColor( @NotNull HexColorTextField target, @NotNull Color color ) { Color contrast = ColorUtils.getContrast( color ); String bgHex = ColorUtils.toHex( color ); target.setBackground( color ); @@ -174,21 +180,22 @@ private void updateColor(@NotNull HexColorTextField target, @NotNull Color color target.setText( bgHex ); } - private void applyColor(@NotNull Object source) { + private void applyColor( @NotNull Object source ) { if (!( source instanceof HexColorTextField input )) return; String hexCode = input.getText(); // TODO Notify users - if (hexCode.length() < 7) return; + if (hexCode.length() < 7) + return; Color color = ColorUtils.fromHex( hexCode ); if (input == fgInput) - selected.foreground(color); + selected.foreground( color ); else if (input == bgInput) - selected.background(color); + selected.background( color ); else - selected.border(color); + selected.border( color ); updateInputColors(); } diff --git a/src/main/java/me/knighthat/interactivedeck/menus/modifier/TaskModifierPanel.java b/src/main/java/me/knighthat/interactivedeck/menus/modifier/TaskModifierPanel.java index 11d7a28..71b7c9f 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/modifier/TaskModifierPanel.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/modifier/TaskModifierPanel.java @@ -29,6 +29,15 @@ */ public class TaskModifierPanel extends javax.swing.JPanel { + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton applyButton; + private javax.swing.JRadioButton gotoButton; + private me.knighthat.interactivedeck.component.plist.ProfilesComboBox profilesList; + private javax.swing.JRadioButton runScriptButton; + private javax.swing.JTextField runScriptInput; + // End of variables declaration//GEN-END:variables + private @NotNull IButton selected; + /** * Creates new form TaskModifierPanel */ @@ -153,16 +162,6 @@ private void applyButtonClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:even selected.task(task); }//GEN-LAST:event_applyButtonClicked - - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton applyButton; - private javax.swing.JRadioButton gotoButton; - private me.knighthat.interactivedeck.component.plist.ProfilesComboBox profilesList; - private javax.swing.JRadioButton runScriptButton; - private javax.swing.JTextField runScriptInput; - // End of variables declaration//GEN-END:variables - private @NotNull IButton selected; private void loadButtonTask() { Task task = selected.task(); diff --git a/src/main/java/me/knighthat/interactivedeck/menus/modifier/TextModifierPanel.java b/src/main/java/me/knighthat/interactivedeck/menus/modifier/TextModifierPanel.java index 2311ace..a5b21d0 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/modifier/TextModifierPanel.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/modifier/TextModifierPanel.java @@ -1,19 +1,25 @@ /* * Copyright (c) 2023. Knight Hat * All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package me.knighthat.interactivedeck.menus.modifier; -import java.awt.*; -import javax.swing.*; -import me.knighthat.interactivedeck.component.ibutton.IButton;import org.jetbrains.annotations.NotNull; +import me.knighthat.interactivedeck.component.ibutton.IButton; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.*; +import java.awt.*; + /** * @author knighthat */ @@ -59,119 +65,120 @@ private void initComponents() { italicButton = new javax.swing.JToggleButton(); underlineButton = new javax.swing.JToggleButton(); String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); - fontSelector = new javax.swing.JComboBox<>(fonts); + fontSelector = new javax.swing.JComboBox<>( fonts ); - setBackground(new java.awt.Color(36, 36, 36)); - setMaximumSize(new java.awt.Dimension(250, 489)); - setMinimumSize(new java.awt.Dimension(250, 489)); - setPreferredSize(new java.awt.Dimension(250, 489)); + setBackground( new java.awt.Color( 36, 36, 36 ) ); + setMaximumSize( new java.awt.Dimension( 250, 489 ) ); + setMinimumSize( new java.awt.Dimension( 250, 489 ) ); + setPreferredSize( new java.awt.Dimension( 250, 489 ) ); java.awt.GridBagLayout layout = new java.awt.GridBagLayout(); - layout.columnWidths = new int[] {70, 70, 70}; - setLayout(layout); + layout.columnWidths = new int[]{ 70, 70, 70 }; + setLayout( layout ); - titleLabel.setForeground(new java.awt.Color(255, 255, 255)); - titleLabel.setText("Label"); + titleLabel.setForeground( new java.awt.Color( 255, 255, 255 ) ); + titleLabel.setText( "Label" ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - add(titleLabel, gridBagConstraints); - - titleInput.setMaximumSize(new java.awt.Dimension(140, 40)); - titleInput.setMinimumSize(new java.awt.Dimension(140, 40)); - titleInput.setPreferredSize(new java.awt.Dimension(140, 40)); - titleInput.addFocusListener(new java.awt.event.FocusAdapter() { - public void focusLost(java.awt.event.FocusEvent evt) { - titleInputFocusLost(evt); + add( titleLabel, gridBagConstraints ); + + titleInput.setMaximumSize( new java.awt.Dimension( 140, 40 ) ); + titleInput.setMinimumSize( new java.awt.Dimension( 140, 40 ) ); + titleInput.setPreferredSize( new java.awt.Dimension( 140, 40 ) ); + titleInput.addFocusListener( new java.awt.event.FocusAdapter() { + public void focusLost( java.awt.event.FocusEvent evt ) { + titleInputFocusLost( evt ); } - }); - titleInput.addKeyListener(new java.awt.event.KeyAdapter() { - public void keyPressed(java.awt.event.KeyEvent evt) { - titleInputEnterPressed(evt); + } ); + titleInput.addKeyListener( new java.awt.event.KeyAdapter() { + public void keyPressed( java.awt.event.KeyEvent evt ) { + titleInputEnterPressed( evt ); } - }); + } ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 0); - add(titleInput, gridBagConstraints); - - fontSizeSpinner.setMaximumSize(new java.awt.Dimension(55, 30)); - fontSizeSpinner.setMinimumSize(new java.awt.Dimension(55, 30)); - fontSizeSpinner.setPreferredSize(new java.awt.Dimension(55, 30)); - fontSizeSpinner.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - fontSizeChanged(evt); + gridBagConstraints.insets = new java.awt.Insets( 0, 0, 20, 0 ); + add( titleInput, gridBagConstraints ); + + fontSizeSpinner.setMaximumSize( new java.awt.Dimension( 55, 30 ) ); + fontSizeSpinner.setMinimumSize( new java.awt.Dimension( 55, 30 ) ); + fontSizeSpinner.setPreferredSize( new java.awt.Dimension( 55, 30 ) ); + fontSizeSpinner.addChangeListener( new javax.swing.event.ChangeListener() { + public void stateChanged( javax.swing.event.ChangeEvent evt ) { + fontSizeChanged( evt ); } - }); + } ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0); - add(fontSizeSpinner, gridBagConstraints); + gridBagConstraints.insets = new java.awt.Insets( 0, 0, 10, 0 ); + add( fontSizeSpinner, gridBagConstraints ); - boldButton.setText("B"); - boldButton.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - boldButtonStateChanged(evt); + boldButton.setText( "B" ); + boldButton.addChangeListener( new javax.swing.event.ChangeListener() { + public void stateChanged( javax.swing.event.ChangeEvent evt ) { + boldButtonStateChanged( evt ); } - }); + } ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; - add(boldButton, gridBagConstraints); + add( boldButton, gridBagConstraints ); - italicButton.setText("I"); - italicButton.addChangeListener(new javax.swing.event.ChangeListener() { - public void stateChanged(javax.swing.event.ChangeEvent evt) { - italicButtonStateChanged(evt); + italicButton.setText( "I" ); + italicButton.addChangeListener( new javax.swing.event.ChangeListener() { + public void stateChanged( javax.swing.event.ChangeEvent evt ) { + italicButtonStateChanged( evt ); } - }); + } ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; - add(italicButton, gridBagConstraints); + add( italicButton, gridBagConstraints ); - underlineButton.setText("U"); + underlineButton.setText( "U" ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 3; - add(underlineButton, gridBagConstraints); - - fontSelector.setMaximumSize(new java.awt.Dimension(140, 30)); - fontSelector.setMinimumSize(new java.awt.Dimension(140, 30)); - fontSelector.setPreferredSize(new java.awt.Dimension(140, 30)); - fontSelector.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - fontSelectedEvent(evt); + add( underlineButton, gridBagConstraints ); + + fontSelector.setMaximumSize( new java.awt.Dimension( 140, 30 ) ); + fontSelector.setMinimumSize( new java.awt.Dimension( 140, 30 ) ); + fontSelector.setPreferredSize( new java.awt.Dimension( 140, 30 ) ); + fontSelector.addActionListener( new java.awt.event.ActionListener() { + public void actionPerformed( java.awt.event.ActionEvent evt ) { + fontSelectedEvent( evt ); } - }); + } ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 2; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0); - add(fontSelector, gridBagConstraints); + gridBagConstraints.insets = new java.awt.Insets( 0, 0, 10, 0 ); + add( fontSelector, gridBagConstraints ); }// //GEN-END:initComponents - private void titleInputFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_titleInputFocusLost - this.applyTitle( evt.getSource() ); + private void titleInputFocusLost( java.awt.event.FocusEvent evt ) {//GEN-FIRST:event_titleInputFocusLost + this.applyTitle( evt.getSource() ); }//GEN-LAST:event_titleInputFocusLost - private void titleInputEnterPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_titleInputEnterPressed - if (evt.getKeyCode() != 10) return; - this.applyTitle( evt.getSource() ); + private void titleInputEnterPressed( java.awt.event.KeyEvent evt ) {//GEN-FIRST:event_titleInputEnterPressed + if (evt.getKeyCode() != 10) + return; + this.applyTitle( evt.getSource() ); }//GEN-LAST:event_titleInputEnterPressed - private void fontSizeChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_fontSizeChanged + private void fontSizeChanged( javax.swing.event.ChangeEvent evt ) {//GEN-FIRST:event_fontSizeChanged int value = (int) this.fontSizeSpinner.getValue(); this.apply( null, null, value ); }//GEN-LAST:event_fontSizeChanged - private void boldButtonStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_boldButtonStateChanged + private void boldButtonStateChanged( javax.swing.event.ChangeEvent evt ) {//GEN-FIRST:event_boldButtonStateChanged int style = this.boldButton.isSelected() ? Font.BOLD : Font.PLAIN; if (this.italicButton.isSelected()) @@ -180,7 +187,7 @@ private void boldButtonStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FI this.apply( null, style, null ); }//GEN-LAST:event_boldButtonStateChanged - private void italicButtonStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_italicButtonStateChanged + private void italicButtonStateChanged( javax.swing.event.ChangeEvent evt ) {//GEN-FIRST:event_italicButtonStateChanged int style = this.italicButton.isSelected() ? Font.ITALIC : Font.PLAIN; if (this.boldButton.isSelected()) @@ -189,19 +196,19 @@ private void italicButtonStateChanged(javax.swing.event.ChangeEvent evt) {//GEN- this.apply( null, style, null ); }//GEN-LAST:event_italicButtonStateChanged - private void fontSelectedEvent(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontSelectedEvent + private void fontSelectedEvent( java.awt.event.ActionEvent evt ) {//GEN-FIRST:event_fontSelectedEvent String family = (String) this.fontSelector.getSelectedItem(); this.apply( family, null, null ); }//GEN-LAST:event_fontSelectedEvent - private void applyTitle(@NotNull Object source) { + private void applyTitle( @NotNull Object source ) { JTextField input = (JTextField) source; String text = input.getText(); - selected.text(text); + selected.text( text ); } - private void apply(@Nullable String family, @Nullable Integer style, @Nullable Integer size) { + private void apply( @Nullable String family, @Nullable Integer style, @Nullable Integer size ) { Font currentFont = selected.font(); Font newFont = new Font( family != null ? family : currentFont.getFamily(), @@ -209,7 +216,7 @@ private void apply(@Nullable String family, @Nullable Integer style, @Nullable I size != null ? size : currentFont.getSize() ); - selected.font(newFont); + selected.font( newFont ); } private void loadButtonTextProperties() { From f03d8371149387b20f04d28832b92c143b12a323 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Wed, 13 Sep 2023 20:40:51 -0500 Subject: [PATCH 28/93] implemented new format --- .../menus/popup/AddProfilePopup.java | 60 +++++----- .../popup/{PopupMenu.java => Popup.java} | 86 +++++++------- .../popup/ProfileConfigurationPopup.java | 106 ++++++++---------- 3 files changed, 113 insertions(+), 139 deletions(-) rename src/main/java/me/knighthat/interactivedeck/menus/popup/{PopupMenu.java => Popup.java} (60%) diff --git a/src/main/java/me/knighthat/interactivedeck/menus/popup/AddProfilePopup.java b/src/main/java/me/knighthat/interactivedeck/menus/popup/AddProfilePopup.java index d172be6..a590cd3 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/popup/AddProfilePopup.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/popup/AddProfilePopup.java @@ -24,46 +24,37 @@ import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -public class AddProfilePopup extends PopupMenu { +public class AddProfilePopup extends YesNoPopup { private JTextField displayNameInput; - public AddProfilePopup( @NotNull Window owner ) { - super( owner, "Add Profile" ); + public AddProfilePopup( @NotNull Window window ) { + super( window, "Add Profile", "Create", "Cancel" ); + } - // Create and add "Create" button - addButton( button -> { - button.setText( "Create" ); - button.addMouseListener( new MouseAdapter() { - @Override - public void mouseClicked( MouseEvent e ) { - createProfile(); - } - } ); - } ); + private void createProfile() { + String fromUser = displayNameInput.getText().trim(); + if (fromUser.isBlank()) + return; // TODO Notify user about empty input - // Create and add "Cancel" button - addButton( button -> { - button.setText( "Cancel" ); - button.addMouseListener( new MouseAdapter() { - public void mouseClicked( MouseEvent evt ) { - finish(); - } - } ); - } ); + Profile profile = Profiles.create( fromUser ); + MenuProperty.add( profile ); + ( (MainMenu) super.getOwner() ).updateProfilesList(); + MenuProperty.active( profile ); + + finish(); } @Override - void initContent() { - + protected void loadContent() { addContent( new JLabel( "Display Name:" ), label -> {}, constraints -> { constraints.fill = GridBagConstraints.HORIZONTAL; constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets( 0, 0, 0, 10 ); } ); + addContent( new JTextField(), comp -> { @@ -87,16 +78,15 @@ else if (evt.getKeyCode() == 10) ); } - private void createProfile() { - String fromUser = displayNameInput.getText().trim(); - if (fromUser.isBlank()) - return; // TODO Notify user about empty input - - Profile profile = Profiles.create( fromUser ); - MenuProperty.add( profile ); - ( (MainMenu) super.getOwner() ).updateProfilesList(); - MenuProperty.active( profile ); + @Override + public void present() { + super.present(); + displayNameInput.setText( "" ); + displayNameInput.requestFocus(); + } - finish(); + @Override + protected void positiveButtonClickEvent( @NotNull MouseEvent event ) { + createProfile(); } } diff --git a/src/main/java/me/knighthat/interactivedeck/menus/popup/PopupMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/popup/Popup.java similarity index 60% rename from src/main/java/me/knighthat/interactivedeck/menus/popup/PopupMenu.java rename to src/main/java/me/knighthat/interactivedeck/menus/popup/Popup.java index 16f108d..eef1ce1 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/popup/PopupMenu.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/popup/Popup.java @@ -20,13 +20,13 @@ import java.awt.*; import java.util.function.Consumer; -public abstract class PopupMenu extends JDialog { +public abstract class Popup extends JDialog { - protected final @NotNull JPanel content; - private final @NotNull JPanel buttonContainer; + protected JPanel contentContainer; + protected JPanel buttonContainer; - public PopupMenu( @NotNull Window owner, @NotNull String title ) { - super( owner ); + public Popup( @NotNull Window window, @NotNull String title ) { + super( window ); setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE ); setBackground( new Color( 51, 51, 51 ) ); @@ -34,43 +34,31 @@ public PopupMenu( @NotNull Window owner, @NotNull String title ) { getRootPane().setWindowDecorationStyle( JRootPane.NONE ); setUndecorated( true ); - title( title ); - - this.content = new JPanel(); - content.setOpaque( false ); - content.setLayout( new GridBagLayout() ); - initContent(); - getContentPane().add( content, BorderLayout.CENTER ); - - this.buttonContainer = new JPanel(); - initButtons(); - getContentPane().add( buttonContainer, BorderLayout.SOUTH ); - - pack(); - setLocationRelativeTo( owner ); + setupTitle( title ); + setupContentContainer(); + setupButtonContainer(); } - abstract void initContent(); + protected abstract void loadContent(); - void title( @NotNull String title ) { - JLabel label = new JLabel( title ); + protected abstract void loadButtons(); + private void setupTitle( @NotNull String title ) { + JLabel label = new JLabel( title ); label.setHorizontalAlignment( SwingConstants.CENTER ); - - Dimension dimension = new Dimension( 300, 30 ); - label.setMaximumSize( dimension ); - label.setMinimumSize( dimension ); - label.setPreferredSize( dimension ); - + setDimension( label, 300, 30 ); getContentPane().add( label, BorderLayout.PAGE_START ); } - void initButtons() { - Dimension dimension = new Dimension( 300, 50 ); - buttonContainer.setMaximumSize( dimension ); - buttonContainer.setMinimumSize( dimension ); - buttonContainer.setPreferredSize( dimension ); + private void setupContentContainer() { + this.contentContainer = new JPanel(); + contentContainer.setOpaque( false ); + contentContainer.setLayout( new GridBagLayout() ); + } + private void setupButtonContainer() { + this.buttonContainer = new JPanel(); + setDimension( buttonContainer, 300, 50 ); buttonContainer.setOpaque( false ); FlowLayout layout = new FlowLayout( FlowLayout.RIGHT, 20, 15 ); @@ -78,35 +66,43 @@ void initButtons() { buttonContainer.setLayout( layout ); } - void addButton( @NotNull Consumer consumer ) { - JButton button = new JButton(); - - Dimension dimension = new java.awt.Dimension( 80, 25 ); - button.setMaximumSize( dimension ); - button.setMinimumSize( dimension ); - button.setPreferredSize( dimension ); + protected void finish() { + setVisible( false ); + } + public @NotNull JButton addButton( @NotNull Consumer consumer ) { + JButton button = new JButton(); + setDimension( button, 80, 25 ); consumer.accept( button ); buttonContainer.add( button ); + + return button; } - @NotNull JComponent addContent( @NotNull JComponent component, @NotNull Consumer conComp, @NotNull Consumer conCons ) { + public @NotNull JComponent addContent( @NotNull JComponent component, @NotNull Consumer conComp, @NotNull Consumer conCons ) { GridBagConstraints constraints = new GridBagConstraints(); conCons.accept( constraints ); conComp.accept( component ); - content.add( component, constraints ); + contentContainer.add( component, constraints ); return component; } - void setDimension( @NotNull JComponent component, int width, int height ) { + public void setDimension( @NotNull JComponent component, int width, int height ) { Dimension dimension = new Dimension( width, height ); component.setMaximumSize( dimension ); component.setMinimumSize( dimension ); component.setPreferredSize( dimension ); } - void finish() { - this.setVisible( false ); + public void present() { + loadContent(); + getContentPane().add( contentContainer, BorderLayout.CENTER ); + loadButtons(); + getContentPane().add( buttonContainer, BorderLayout.SOUTH ); + setVisible( true ); + pack(); + + setLocationRelativeTo( getOwner() ); } } diff --git a/src/main/java/me/knighthat/interactivedeck/menus/popup/ProfileConfigurationPopup.java b/src/main/java/me/knighthat/interactivedeck/menus/popup/ProfileConfigurationPopup.java index 04b7bd5..e78249e 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/popup/ProfileConfigurationPopup.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/popup/ProfileConfigurationPopup.java @@ -16,73 +16,24 @@ import me.knighthat.interactivedeck.file.Profile; import me.knighthat.interactivedeck.menus.MainMenu; -import me.knighthat.interactivedeck.menus.MenuProperty; import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; -import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -public class ProfileConfigurationPopup extends PopupMenu { +public class ProfileConfigurationPopup extends ProfilePopup { - private Profile profile; private JTextField displayNameInput; private JSpinner columns; private JSpinner rows; private JSpinner gap; - public ProfileConfigurationPopup( @NotNull Window owner ) { - super( owner, "Profile Configuration" ); - - // Create and add "Create" button - addButton( button -> { - button.setText( "Apply" ); - button.addMouseListener( new MouseAdapter() { - @Override - public void mouseClicked( MouseEvent e ) { - apply(); - } - } ); - } ); - - // Create and add "Cancel" button - addButton( button -> { - button.setText( "Cancel" ); - button.addMouseListener( new MouseAdapter() { - public void mouseClicked( MouseEvent evt ) { - finish(); - } - } ); - } ); - } - - @Override - void initContent() { - profile = MenuProperty.active().orElse( MenuProperty.defaultProfile() ); - - addContent( - new JLabel( "Display Name" ), - label -> setDimension( label, 150, 20 ), - constraints -> constraints.anchor = GridBagConstraints.WEST - ); - addContent( - new JTextField(), - comp -> { - setDimension( comp, 150, 30 ); - displayNameInput = (JTextField) comp; - displayNameInput.setText( profile.displayName() ); - }, - constraints -> constraints.gridy = 1 - ); - - - columns = spinner( "Columns", 2, profile.columns(), 1 ); - rows = spinner( "Rows", 4, profile.rows(), 1 ); - gap = spinner( "Gap", 6, profile.gap(), 0 ); + public ProfileConfigurationPopup( @NotNull Window window ) { + super( window, "Profile Configuration", "Apply", "Cancel" ); } - private @NotNull JSpinner spinner( @NotNull String name, int gridy, int curValue, int min ) { + private @NotNull JSpinner spinner( @NotNull String name, int gridy, int min ) { addContent( new JLabel( name ), label -> setDimension( label, 150, 20 ), @@ -92,16 +43,17 @@ void initContent() { constraints.insets = new Insets( 10, 0, 0, 0 ); } ); - return (JSpinner) addContent( - new JSpinner(), + JSpinner spinner = new JSpinner(); + addContent( + spinner, comp -> { setDimension( comp, 150, 30 ); - - SpinnerModel model = new SpinnerNumberModel( curValue, min, 10, 1 ); + SpinnerModel model = new SpinnerNumberModel( min, min, 10, 1 ); ( (JSpinner) comp ).setModel( model ); }, constraints -> constraints.gridy = gridy + 1 ); + return spinner; } private void apply() { @@ -110,14 +62,50 @@ private void apply() { profile.rows( validate( rows.getValue(), 1 ) ); profile.gap( validate( gap.getValue(), 0 ) ); - ( (MainMenu) getOwner() ).updateButtons( profile ); + MainMenu menu = (MainMenu) getOwner(); + menu.updateProfilesList(); + menu.updateButtons( profile ); finish(); } - int validate( @NotNull Object obj, int min ) { + private int validate( @NotNull Object obj, int min ) { if (!( obj instanceof Integer number )) return min; return number < min ? min : Math.min( number, 10 ); } + + @Override + protected void loadContent() { + addContent( + new JLabel( "Display Name" ), + label -> setDimension( label, 150, 20 ), + constraints -> constraints.anchor = GridBagConstraints.WEST + ); + addContent( + new JTextField(), + comp -> { + setDimension( comp, 150, 30 ); + displayNameInput = (JTextField) comp; + }, + constraints -> constraints.gridy = 1 + ); + columns = spinner( "Columns", 2, 1 ); + rows = spinner( "Rows", 4, 1 ); + gap = spinner( "Gap", 6, 0 ); + } + + @Override + protected void loadProfile( @NotNull Profile profile ) { + displayNameInput.setText( profile.displayName() ); + columns.setValue( profile.columns() ); + rows.setValue( profile.rows() ); + gap.setValue( profile.gap() ); + displayNameInput.requestFocus(); + } + + @Override + protected void positiveButtonClickEvent( @NotNull MouseEvent event ) { + apply(); + } } From 2773ea50c17fa0248a7a6970808036bcc64c2137 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Wed, 13 Sep 2023 20:43:05 -0500 Subject: [PATCH 29/93] persistent popup only hides dialog for future reuse --- .../menus/popup/PersistentDataPopup.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/me/knighthat/interactivedeck/menus/popup/PersistentDataPopup.java diff --git a/src/main/java/me/knighthat/interactivedeck/menus/popup/PersistentDataPopup.java b/src/main/java/me/knighthat/interactivedeck/menus/popup/PersistentDataPopup.java new file mode 100644 index 0000000..c81467e --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/menus/popup/PersistentDataPopup.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.knighthat.interactivedeck.menus.popup; + +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +public abstract class PersistentDataPopup extends Popup { + + private boolean isInstantiated = false; + + public PersistentDataPopup( @NotNull Window window, @NotNull String title ) { + super( window, title ); + } + + @Override + protected void finish() { + setVisible( false ); + } + + @Override + public void present() { + if (!isInstantiated) { + super.present(); + isInstantiated = true; + } else + setVisible( true ); + } +} From 41dab6cae44743d3971943af003364fd973c3eaf Mon Sep 17 00:00:00 2001 From: KnightHat Date: Wed, 13 Sep 2023 20:44:01 -0500 Subject: [PATCH 30/93] popup that reloads value(s) on display --- .../menus/popup/ProfilePopup.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/me/knighthat/interactivedeck/menus/popup/ProfilePopup.java diff --git a/src/main/java/me/knighthat/interactivedeck/menus/popup/ProfilePopup.java b/src/main/java/me/knighthat/interactivedeck/menus/popup/ProfilePopup.java new file mode 100644 index 0000000..de57219 --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/menus/popup/ProfilePopup.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.knighthat.interactivedeck.menus.popup; + +import me.knighthat.interactivedeck.file.Profile; +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +public abstract class ProfilePopup extends YesNoPopup { + + protected Profile profile; + + public ProfilePopup( @NotNull Window window, @NotNull String title, @NotNull String positiveButtonText, @NotNull String negativeButtonText ) { + super( window, title, positiveButtonText, negativeButtonText ); + } + + protected abstract void loadProfile( @NotNull Profile profile ); + + public void present( @NotNull Profile profile ) { + this.profile = profile; + present(); + loadProfile( profile ); + } +} From 532eecf1c8b954bf57462f5b0ec8acd9c3af1906 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Wed, 13 Sep 2023 20:44:19 -0500 Subject: [PATCH 31/93] confirmation popup when user try to remove a profile --- .../menus/popup/RemoveProfilePopup.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/main/java/me/knighthat/interactivedeck/menus/popup/RemoveProfilePopup.java diff --git a/src/main/java/me/knighthat/interactivedeck/menus/popup/RemoveProfilePopup.java b/src/main/java/me/knighthat/interactivedeck/menus/popup/RemoveProfilePopup.java new file mode 100644 index 0000000..c4b648e --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/menus/popup/RemoveProfilePopup.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.knighthat.interactivedeck.menus.popup; + +import me.knighthat.interactivedeck.file.Profile; +import me.knighthat.interactivedeck.menus.MainMenu; +import me.knighthat.interactivedeck.menus.MenuProperty; +import me.knighthat.interactivedeck.utils.UuidUtils; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseEvent; + +public class RemoveProfilePopup extends ProfilePopup { + + private JLabel message; + + public RemoveProfilePopup( @NotNull Window window ) { + super( window, "Remove Profile", "Remove", "Cancel" ); + } + + @Override + protected void loadContent() { + addContent( + new JLabel(), + label -> { + message = (JLabel) label; + setDimension( label, 250, 50 ); + }, + constraints -> {} + ); + } + + @Override + protected void loadProfile( @NotNull Profile profile ) { + String msg = "You are about to remove profile %s (%s). Do you want to continue?"; + String uuid = UuidUtils.lastFiveChars( profile.uuid ); + message.setText( msg.formatted( profile.displayName(), uuid ) ); + } + + @Override + protected void positiveButtonClickEvent( @NotNull MouseEvent event ) { + profile.remove(); + ( (MainMenu) getOwner() ).updateProfilesList(); + MenuProperty.active( MenuProperty.defaultProfile() ); + } +} From a6ed70607605c6cdf1d9b5f3f41140f4360ab93a Mon Sep 17 00:00:00 2001 From: KnightHat Date: Wed, 13 Sep 2023 20:44:54 -0500 Subject: [PATCH 32/93] comes with 2 "yes" and "no" buttons by default --- .../menus/popup/YesNoPopup.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/main/java/me/knighthat/interactivedeck/menus/popup/YesNoPopup.java diff --git a/src/main/java/me/knighthat/interactivedeck/menus/popup/YesNoPopup.java b/src/main/java/me/knighthat/interactivedeck/menus/popup/YesNoPopup.java new file mode 100644 index 0000000..5c9011b --- /dev/null +++ b/src/main/java/me/knighthat/interactivedeck/menus/popup/YesNoPopup.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023. Knight Hat + * All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.knighthat.interactivedeck.menus.popup; + +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +public abstract class YesNoPopup extends PersistentDataPopup { + + protected final @NotNull String positiveButtonText; + protected final @NotNull String negativeButtonText; + + public YesNoPopup( @NotNull Window window, @NotNull String title, @NotNull String positiveButtonText, @NotNull String negativeButtonText ) { + super( window, title ); + this.positiveButtonText = positiveButtonText; + this.negativeButtonText = negativeButtonText; + } + + protected abstract void positiveButtonClickEvent( @NotNull MouseEvent event ); + + protected void positiveButton( @NotNull JButton button ) { + button.setText( positiveButtonText ); + button.addMouseListener( new MouseAdapter() { + @Override + public void mouseClicked( MouseEvent e ) { + positiveButtonClickEvent( e ); + finish(); + } + } ); + } + + protected void negativeButton( @NotNull JButton button ) { + button.setText( negativeButtonText ); + button.addMouseListener( new MouseAdapter() { + @Override + public void mouseClicked( MouseEvent e ) { + finish(); + } + } ); + } + + @Override + protected void loadButtons() { + addButton( this::positiveButton ); + addButton( this::negativeButton ); + } +} From 3d2d7356748dd0fcaa336802c81e6b4e484047b7 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Wed, 13 Sep 2023 20:45:05 -0500 Subject: [PATCH 33/93] dispose on finish --- .../java/me/knighthat/interactivedeck/menus/popup/Popup.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/me/knighthat/interactivedeck/menus/popup/Popup.java b/src/main/java/me/knighthat/interactivedeck/menus/popup/Popup.java index eef1ce1..83eb351 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/popup/Popup.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/popup/Popup.java @@ -68,6 +68,7 @@ private void setupButtonContainer() { protected void finish() { setVisible( false ); + dispose(); } public @NotNull JButton addButton( @NotNull Consumer consumer ) { From 5f33768a94a93c156d3ade22bc67748b9a214cc6 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Wed, 13 Sep 2023 20:46:01 -0500 Subject: [PATCH 34/93] reusable persistent popup instead of creating one each time --- .../interactivedeck/menus/MainMenu.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java index c96e877..fa05cc4 100644 --- a/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java +++ b/src/main/java/me/knighthat/interactivedeck/menus/MainMenu.java @@ -21,8 +21,8 @@ import me.knighthat.interactivedeck.json.Json; import me.knighthat.interactivedeck.logging.Log; import me.knighthat.interactivedeck.menus.popup.AddProfilePopup; -import me.knighthat.interactivedeck.menus.popup.PopupMenu; import me.knighthat.interactivedeck.menus.popup.ProfileConfigurationPopup; +import me.knighthat.interactivedeck.menus.popup.RemoveProfilePopup; import me.knighthat.interactivedeck.observable.Observable; import me.knighthat.interactivedeck.utils.ColorUtils; import me.knighthat.interactivedeck.utils.GlobalVars; @@ -44,6 +44,9 @@ public class MainMenu extends javax.swing.JFrame { private final @NotNull Observable bSelected = Observable.of( null ); + private final @NotNull AddProfilePopup addProfilePopup; + private final @NotNull ProfileConfigurationPopup profileConfigurationPopup; + private final @NotNull RemoveProfilePopup removeProfilePopup; // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel btnModifierSection; @@ -56,6 +59,11 @@ public class MainMenu extends javax.swing.JFrame { */ public MainMenu() { super( GlobalVars.name() + " - " + GlobalVars.version() ); + + this.addProfilePopup = new AddProfilePopup( this ); + this.profileConfigurationPopup = new ProfileConfigurationPopup( this ); + this.removeProfilePopup = new RemoveProfilePopup( this ); + initComponents(); initButtonObserver(); @@ -232,24 +240,19 @@ public void mouseClicked( java.awt.event.MouseEvent evt ) { }// //GEN-END:initComponents private void addButtonClicked( java.awt.event.MouseEvent evt ) {//GEN-FIRST:event_addButtonClicked - PopupMenu dialog = new AddProfilePopup( this ); - dialog.setVisible( true ); + addProfilePopup.present(); }//GEN-LAST:event_addButtonClicked private void removeProfilesButtonClicked( java.awt.event.MouseEvent evt ) {//GEN-FIRST:event_removeProfilesButtonClicked Profile selected = (Profile) profilesList.getSelectedItem(); if (selected == null || selected.isDefault) return; - selected.remove(); - updateProfilesList(); - - Profile profile = MenuProperty.defaultProfile(); - MenuProperty.active( profile ); + removeProfilePopup.present( selected ); }//GEN-LAST:event_removeProfilesButtonClicked private void configureProfileButtonClicked( java.awt.event.MouseEvent evt ) {//GEN-FIRST:event_configureProfileButtonClicked - PopupMenu dialog = new ProfileConfigurationPopup( this ); - dialog.setVisible( true ); + Profile profile = MenuProperty.active().orElse( MenuProperty.defaultProfile() ); + profileConfigurationPopup.present( profile ); }//GEN-LAST:event_configureProfileButtonClicked private void profilesListActionPerformed( java.awt.event.ActionEvent evt ) {//GEN-FIRST:event_profilesListActionPerformed @@ -331,9 +334,12 @@ void initButtonObserver() { } public void updateProfilesList() { + Profile active = MenuProperty.active().orElse( MenuProperty.defaultProfile() ); + profilesList.removeAll(); ComboBoxModel model = new DefaultComboBoxModel<>( MenuProperty.profileArray() ); profilesList.setModel( model ); + profilesList.setSelectedItem( active ); profilesList.revalidate(); profilesList.repaint(); } From 3c42930d95aa6e7352aecefbdd5e79287701f726 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Wed, 13 Sep 2023 20:46:30 -0500 Subject: [PATCH 35/93] adjusted scope of licence to "Project Files" only --- .idea/copyright/profiles_settings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml index 76ca3db..77c4fa5 100644 --- a/.idea/copyright/profiles_settings.xml +++ b/.idea/copyright/profiles_settings.xml @@ -1,7 +1,7 @@ - + \ No newline at end of file From 20c3bed8c7b2a73005abb24edcd78d86dda22746 Mon Sep 17 00:00:00 2001 From: KnightHat Date: Wed, 13 Sep 2023 20:47:06 -0500 Subject: [PATCH 36/93] preserve the order of getters/setters/overridden methods --- .idea/codeStyles/Project.xml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index f11d7fa..8904166 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -4,8 +4,6 @@ @@ -27,6 +25,18 @@