From 384329d00d13e2ebb95fb03caa674f8aa9d97f24 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 14 Mar 2020 21:34:17 +0100 Subject: [PATCH] Created packages ui.renderer and ui.primary --- .../java/envoy/client/data/SettingsItem.java | 2 +- src/main/java/envoy/client/ui/ChatWindow.java | 14 + .../java/envoy/client/ui/LoginDialog.java | 1 + .../ui/{ => primary}/PrimaryButton.java | 126 ++--- .../ui/{ => primary}/PrimaryScrollBar.java | 3 +- .../ui/{ => primary}/PrimaryScrollPane.java | 4 +- .../ui/{ => primary}/PrimaryTextArea.java | 2 +- .../ui/{ => primary}/PrimaryToggleSwitch.java | 115 ++--- .../envoy/client/ui/primary/package-info.java | 17 + .../ContactsSearchRenderer.java | 4 +- .../{ => renderer}/MessageListRenderer.java | 39 +- .../ui/{ => renderer}/UserListRenderer.java | 2 +- .../client/ui/renderer/package-info.java | 14 + .../client/ui/settings/NewThemeScreen.java | 456 +++++++++--------- .../client/ui/settings/SettingsScreen.java | 2 +- 15 files changed, 440 insertions(+), 361 deletions(-) rename src/main/java/envoy/client/ui/{ => primary}/PrimaryButton.java (94%) rename src/main/java/envoy/client/ui/{ => primary}/PrimaryScrollBar.java (98%) rename src/main/java/envoy/client/ui/{ => primary}/PrimaryScrollPane.java (97%) rename src/main/java/envoy/client/ui/{ => primary}/PrimaryTextArea.java (98%) rename src/main/java/envoy/client/ui/{ => primary}/PrimaryToggleSwitch.java (95%) create mode 100644 src/main/java/envoy/client/ui/primary/package-info.java rename src/main/java/envoy/client/ui/{ => renderer}/ContactsSearchRenderer.java (95%) rename src/main/java/envoy/client/ui/{ => renderer}/MessageListRenderer.java (70%) rename src/main/java/envoy/client/ui/{ => renderer}/UserListRenderer.java (98%) create mode 100644 src/main/java/envoy/client/ui/renderer/package-info.java diff --git a/src/main/java/envoy/client/data/SettingsItem.java b/src/main/java/envoy/client/data/SettingsItem.java index 57ba600..cd85c71 100644 --- a/src/main/java/envoy/client/data/SettingsItem.java +++ b/src/main/java/envoy/client/data/SettingsItem.java @@ -7,7 +7,7 @@ import java.util.function.Consumer; import javax.swing.JComponent; -import envoy.client.ui.PrimaryToggleSwitch; +import envoy.client.ui.primary.PrimaryToggleSwitch; /** * Encapsulates a persistent value that is directly or indirectly mutable by the diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index 6a5ae38..2db2d3d 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -20,6 +20,12 @@ import envoy.client.net.Client; import envoy.client.net.WriteProxy; import envoy.client.ui.list.ComponentList; import envoy.client.ui.list.ComponentListModel; +import envoy.client.ui.primary.PrimaryButton; +import envoy.client.ui.primary.PrimaryScrollPane; +import envoy.client.ui.primary.PrimaryTextArea; +import envoy.client.ui.renderer.ContactsSearchRenderer; +import envoy.client.ui.renderer.MessageListRenderer; +import envoy.client.ui.renderer.UserListRenderer; import envoy.client.ui.settings.SettingsScreen; import envoy.data.Message; import envoy.data.Message.MessageStatus; @@ -110,7 +116,15 @@ public class ChatWindow extends JFrame { contentPane.setLayout(gbl_contentPane); messageList.setBorder(new EmptyBorder(space, space, space, space)); + messageList.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.isPopupTrigger()) { + + } + } + }); scrollPane.setViewportView(messageList); scrollPane.addComponentListener(new ComponentAdapter() { diff --git a/src/main/java/envoy/client/ui/LoginDialog.java b/src/main/java/envoy/client/ui/LoginDialog.java index 193ae8d..9cd645d 100644 --- a/src/main/java/envoy/client/ui/LoginDialog.java +++ b/src/main/java/envoy/client/ui/LoginDialog.java @@ -16,6 +16,7 @@ import javax.swing.border.EmptyBorder; import envoy.client.data.*; import envoy.client.event.HandshakeSuccessfulEvent; import envoy.client.net.Client; +import envoy.client.ui.primary.PrimaryButton; import envoy.data.LoginCredentials; import envoy.data.Message; import envoy.data.User; diff --git a/src/main/java/envoy/client/ui/PrimaryButton.java b/src/main/java/envoy/client/ui/primary/PrimaryButton.java similarity index 94% rename from src/main/java/envoy/client/ui/PrimaryButton.java rename to src/main/java/envoy/client/ui/primary/PrimaryButton.java index 3486acd..efcfd9f 100644 --- a/src/main/java/envoy/client/ui/PrimaryButton.java +++ b/src/main/java/envoy/client/ui/primary/PrimaryButton.java @@ -1,63 +1,63 @@ -package envoy.client.ui; - -import java.awt.Graphics; - -import javax.swing.JButton; - -/** - * Project: envoy-client
- * File: PrimaryButton.javaEvent.java
- * Created: 07.12.2019
- * - * @author Kai S. K. Engelbart - * @author Maximilian Käfer - * @since Envoy v0.2-alpha - */ -public class PrimaryButton extends JButton { - - private static final long serialVersionUID = 3662266120667728364L; - - private int arcSize; - - /** - * Creates a primary button - * - * @param title the title of the button - * @since Envoy 0.2-alpha - */ - public PrimaryButton(String title) { this(title, 6); } - - /** - * Creates a primary button - * - * @param title the title of the button - * @param arcSize the size of the arc used to draw the round button edges - * @since Envoy 0.2-alpha - */ - public PrimaryButton(String title, int arcSize) { - super(title); - setBorderPainted(false); - setFocusPainted(false); - setContentAreaFilled(false); - this.arcSize = arcSize; - } - - @Override - protected void paintComponent(Graphics g) { - g.setColor(getBackground()); - g.fillRoundRect(0, 0, getWidth(), getHeight(), arcSize, arcSize); - super.paintComponent(g); - } - - /** - * @return the arcSize - * @since Envoy 0.2-alpha - */ - public int getArcSize() { return arcSize; } - - /** - * @param arcSize the arcSize to set - * @since Envoy 0.2-alpha - */ - public void setArcSize(int arcSize) { this.arcSize = arcSize; } -} +package envoy.client.ui.primary; + +import java.awt.Graphics; + +import javax.swing.JButton; + +/** + * Project: envoy-client
+ * File: PrimaryButton.javaEvent.java
+ * Created: 07.12.2019
+ * + * @author Kai S. K. Engelbart + * @author Maximilian Käfer + * @since Envoy v0.2-alpha + */ +public class PrimaryButton extends JButton { + + private static final long serialVersionUID = 3662266120667728364L; + + private int arcSize; + + /** + * Creates a primary button + * + * @param title the title of the button + * @since Envoy 0.2-alpha + */ + public PrimaryButton(String title) { this(title, 6); } + + /** + * Creates a primary button + * + * @param title the title of the button + * @param arcSize the size of the arc used to draw the round button edges + * @since Envoy 0.2-alpha + */ + public PrimaryButton(String title, int arcSize) { + super(title); + setBorderPainted(false); + setFocusPainted(false); + setContentAreaFilled(false); + this.arcSize = arcSize; + } + + @Override + protected void paintComponent(Graphics g) { + g.setColor(getBackground()); + g.fillRoundRect(0, 0, getWidth(), getHeight(), arcSize, arcSize); + super.paintComponent(g); + } + + /** + * @return the arcSize + * @since Envoy 0.2-alpha + */ + public int getArcSize() { return arcSize; } + + /** + * @param arcSize the arcSize to set + * @since Envoy 0.2-alpha + */ + public void setArcSize(int arcSize) { this.arcSize = arcSize; } +} diff --git a/src/main/java/envoy/client/ui/PrimaryScrollBar.java b/src/main/java/envoy/client/ui/primary/PrimaryScrollBar.java similarity index 98% rename from src/main/java/envoy/client/ui/PrimaryScrollBar.java rename to src/main/java/envoy/client/ui/primary/PrimaryScrollBar.java index 8e8131c..7dd560e 100644 --- a/src/main/java/envoy/client/ui/PrimaryScrollBar.java +++ b/src/main/java/envoy/client/ui/primary/PrimaryScrollBar.java @@ -1,4 +1,4 @@ -package envoy.client.ui; +package envoy.client.ui.primary; import java.awt.Color; import java.awt.Dimension; @@ -13,6 +13,7 @@ import javax.swing.JScrollBar; import javax.swing.plaf.basic.BasicScrollBarUI; import envoy.client.data.Settings; +import envoy.client.ui.Theme; /** * Project: envoy-client
diff --git a/src/main/java/envoy/client/ui/PrimaryScrollPane.java b/src/main/java/envoy/client/ui/primary/PrimaryScrollPane.java similarity index 97% rename from src/main/java/envoy/client/ui/PrimaryScrollPane.java rename to src/main/java/envoy/client/ui/primary/PrimaryScrollPane.java index f8e4dbc..47c2abb 100644 --- a/src/main/java/envoy/client/ui/PrimaryScrollPane.java +++ b/src/main/java/envoy/client/ui/primary/PrimaryScrollPane.java @@ -1,7 +1,9 @@ -package envoy.client.ui; +package envoy.client.ui.primary; import javax.swing.JScrollPane; +import envoy.client.ui.Theme; + /** * Project: envoy-client
* File: PrimaryScrollPane.java
diff --git a/src/main/java/envoy/client/ui/PrimaryTextArea.java b/src/main/java/envoy/client/ui/primary/PrimaryTextArea.java similarity index 98% rename from src/main/java/envoy/client/ui/PrimaryTextArea.java rename to src/main/java/envoy/client/ui/primary/PrimaryTextArea.java index 29ed2f9..9f6a7ce 100644 --- a/src/main/java/envoy/client/ui/PrimaryTextArea.java +++ b/src/main/java/envoy/client/ui/primary/PrimaryTextArea.java @@ -1,4 +1,4 @@ -package envoy.client.ui; +package envoy.client.ui.primary; import java.awt.Font; import java.awt.Graphics; diff --git a/src/main/java/envoy/client/ui/PrimaryToggleSwitch.java b/src/main/java/envoy/client/ui/primary/PrimaryToggleSwitch.java similarity index 95% rename from src/main/java/envoy/client/ui/PrimaryToggleSwitch.java rename to src/main/java/envoy/client/ui/primary/PrimaryToggleSwitch.java index 7b4f41f..30ee098 100644 --- a/src/main/java/envoy/client/ui/PrimaryToggleSwitch.java +++ b/src/main/java/envoy/client/ui/primary/PrimaryToggleSwitch.java @@ -1,57 +1,58 @@ -package envoy.client.ui; - -import java.awt.Dimension; -import java.awt.Graphics; - -import javax.swing.JButton; - -import envoy.client.data.Settings; -import envoy.client.data.SettingsItem; - -/** - * This component can be used to toggle between two options. This will change - * the state of a {@code boolean} {@link SettingsItem}.
- *
- * Project: envoy-client
- * File: PrimaryToggleSwitch.java
- * Created: 21 Dec 2019
- * - * @author Maximilian Käfer - * @author Kai S. K. Engelbart - * @since Envoy v0.3-alpha - */ -public class PrimaryToggleSwitch extends JButton { - - private boolean state; - - private static final long serialVersionUID = -721155303106833184L; - - /** - * Initializes a {@link PrimaryToggleSwitch}. - * - * @param settingsItem the {@link SettingsItem} that is controlled by this - * {@link PrimaryToggleSwitch} - * @since Envoy v0.3-alpha - */ - public PrimaryToggleSwitch(SettingsItem settingsItem) { - setPreferredSize(new Dimension(50, 25)); - setMinimumSize(new Dimension(50, 25)); - setMaximumSize(new Dimension(50, 25)); - - setBorderPainted(false); - setFocusPainted(false); - setContentAreaFilled(false); - - state = settingsItem.get(); - addActionListener((evt) -> { state = !state; settingsItem.set(state); revalidate(); repaint(); }); - } - - @Override - public void paintComponent(Graphics g) { - g.setColor(state ? Color.GREEN : Color.LIGHT_GRAY); - g.fillRoundRect(0, 0, getWidth(), getHeight(), 25, 25); - - g.setColor(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableBackgroundColor()); - g.fillRoundRect(state ? 25 : 0, 0, 25, 25, 25, 25); - } -} +package envoy.client.ui.primary; + +import java.awt.Dimension; +import java.awt.Graphics; + +import javax.swing.JButton; + +import envoy.client.data.Settings; +import envoy.client.data.SettingsItem; +import envoy.client.ui.Color; + +/** + * This component can be used to toggle between two options. This will change + * the state of a {@code boolean} {@link SettingsItem}.
+ *
+ * Project: envoy-client
+ * File: PrimaryToggleSwitch.java
+ * Created: 21 Dec 2019
+ * + * @author Maximilian Käfer + * @author Kai S. K. Engelbart + * @since Envoy v0.3-alpha + */ +public class PrimaryToggleSwitch extends JButton { + + private boolean state; + + private static final long serialVersionUID = -721155303106833184L; + + /** + * Initializes a {@link PrimaryToggleSwitch}. + * + * @param settingsItem the {@link SettingsItem} that is controlled by this + * {@link PrimaryToggleSwitch} + * @since Envoy v0.3-alpha + */ + public PrimaryToggleSwitch(SettingsItem settingsItem) { + setPreferredSize(new Dimension(50, 25)); + setMinimumSize(new Dimension(50, 25)); + setMaximumSize(new Dimension(50, 25)); + + setBorderPainted(false); + setFocusPainted(false); + setContentAreaFilled(false); + + state = settingsItem.get(); + addActionListener((evt) -> { state = !state; settingsItem.set(state); revalidate(); repaint(); }); + } + + @Override + public void paintComponent(Graphics g) { + g.setColor(state ? Color.GREEN : Color.LIGHT_GRAY); + g.fillRoundRect(0, 0, getWidth(), getHeight(), 25, 25); + + g.setColor(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableBackgroundColor()); + g.fillRoundRect(state ? 25 : 0, 0, 25, 25, 25, 25); + } +} diff --git a/src/main/java/envoy/client/ui/primary/package-info.java b/src/main/java/envoy/client/ui/primary/package-info.java new file mode 100644 index 0000000..8ede25f --- /dev/null +++ b/src/main/java/envoy/client/ui/primary/package-info.java @@ -0,0 +1,17 @@ +/** + * This package defines all "primary" components that were defined specifically + * for the visual improvement of Envoy. However, they can still be used in + * general for other projects.
+ * Primary elements are supposed to provide the main functionality of a UI + * component.
+ *
+ * Project: envoy-client
+ * File: package-info.java
+ * Created: 14 Mar 2020
+ * + * @author Leon Hofmeister + * @author Kai S. K. Engelbart + * @author Maximilian Käfer + * @since Envoy v0.1-beta + */ +package envoy.client.ui.primary; diff --git a/src/main/java/envoy/client/ui/ContactsSearchRenderer.java b/src/main/java/envoy/client/ui/renderer/ContactsSearchRenderer.java similarity index 95% rename from src/main/java/envoy/client/ui/ContactsSearchRenderer.java rename to src/main/java/envoy/client/ui/renderer/ContactsSearchRenderer.java index aa96b62..60a0ef2 100644 --- a/src/main/java/envoy/client/ui/ContactsSearchRenderer.java +++ b/src/main/java/envoy/client/ui/renderer/ContactsSearchRenderer.java @@ -1,4 +1,4 @@ -package envoy.client.ui; +package envoy.client.ui.renderer; import java.awt.Component; import java.awt.Dimension; @@ -8,8 +8,10 @@ import javax.swing.*; import envoy.client.data.Settings; import envoy.client.event.SendEvent; +import envoy.client.ui.Color; import envoy.client.ui.list.ComponentList; import envoy.client.ui.list.ComponentListCellRenderer; +import envoy.client.ui.primary.PrimaryButton; import envoy.data.User; import envoy.event.ContactOperationEvent; import envoy.event.EventBus; diff --git a/src/main/java/envoy/client/ui/MessageListRenderer.java b/src/main/java/envoy/client/ui/renderer/MessageListRenderer.java similarity index 70% rename from src/main/java/envoy/client/ui/MessageListRenderer.java rename to src/main/java/envoy/client/ui/renderer/MessageListRenderer.java index 6b70e1b..047f12c 100644 --- a/src/main/java/envoy/client/ui/MessageListRenderer.java +++ b/src/main/java/envoy/client/ui/renderer/MessageListRenderer.java @@ -1,15 +1,21 @@ -package envoy.client.ui; +package envoy.client.ui.renderer; -import java.awt.BorderLayout; import java.awt.Font; +import java.awt.image.BufferedImage; +import java.io.IOException; import java.text.SimpleDateFormat; +import java.util.EnumMap; +import javax.imageio.ImageIO; import javax.swing.*; import envoy.client.data.Settings; +import envoy.client.ui.Color; +import envoy.client.ui.Theme; import envoy.client.ui.list.ComponentList; import envoy.client.ui.list.ComponentListCellRenderer; import envoy.data.Message; +import envoy.data.Message.MessageStatus; /** * Defines how a message is displayed.
@@ -25,12 +31,23 @@ import envoy.data.Message; */ public class MessageListRenderer implements ComponentListCellRenderer { + private static final EnumMap statusIcons = new EnumMap<>(MessageStatus.class); + + static { + for (MessageStatus ms : MessageStatus.values()) + try { + statusIcons.put(ms, ImageIO.read(MessageListRenderer.class.getResourceAsStream(ms.toString().toLowerCase() + "_icon.png"))); + } catch (IOException e) { + e.printStackTrace(); + } + } + private JTextArea messageTextArea; @Override public JPanel getListCellComponent(ComponentList list, Message value, boolean isSelected) { final JPanel panel = new JPanel(); - panel.setLayout(new BorderLayout()); + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); final Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()); // Panel background @@ -47,7 +64,17 @@ public class MessageListRenderer implements ComponentListCellRenderer { // Set the date color to be the value of DateColorChat dateLabel.setForeground(theme.getDateColor()); - panel.add(dateLabel, BorderLayout.NORTH); + panel.add(dateLabel); + + if (value.isForwarded()) try { + var forwardLabel = new JLabel("Forwarded", new ImageIcon(ClassLoader.getSystemResourceAsStream(null).readAllBytes()), + SwingConstants.CENTER); + forwardLabel.setBackground(panel.getBackground()); + forwardLabel.setForeground(Color.lightGray); + panel.add(forwardLabel); + } catch (IOException e) { + e.printStackTrace(); + } // The JTextArea that displays the text content of a message and its status messageTextArea = new JTextArea(text + System.getProperty("line.separator")); @@ -58,7 +85,7 @@ public class MessageListRenderer implements ComponentListCellRenderer { messageTextArea.setBackground(panel.getBackground()); messageTextArea.setEditable(false); - panel.add(messageTextArea, BorderLayout.CENTER); + panel.add(messageTextArea); JLabel statusLabel = new JLabel(state); statusLabel.setFont(new Font("Arial", Font.BOLD, 14)); @@ -83,7 +110,7 @@ public class MessageListRenderer implements ComponentListCellRenderer { statusLabel.setForeground(statusColor); statusLabel.setBackground(panel.getBackground()); - panel.add(statusLabel, BorderLayout.SOUTH); + panel.add(statusLabel); // Define some space to the messages below panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(), BorderFactory.createEtchedBorder())); diff --git a/src/main/java/envoy/client/ui/UserListRenderer.java b/src/main/java/envoy/client/ui/renderer/UserListRenderer.java similarity index 98% rename from src/main/java/envoy/client/ui/UserListRenderer.java rename to src/main/java/envoy/client/ui/renderer/UserListRenderer.java index 2bdefca..7f6bc0c 100644 --- a/src/main/java/envoy/client/ui/UserListRenderer.java +++ b/src/main/java/envoy/client/ui/renderer/UserListRenderer.java @@ -1,4 +1,4 @@ -package envoy.client.ui; +package envoy.client.ui.renderer; import java.awt.Component; import java.awt.Dimension; diff --git a/src/main/java/envoy/client/ui/renderer/package-info.java b/src/main/java/envoy/client/ui/renderer/package-info.java new file mode 100644 index 0000000..68748ef --- /dev/null +++ b/src/main/java/envoy/client/ui/renderer/package-info.java @@ -0,0 +1,14 @@ +/** + * This package contains all Envoy-specific renderers for lists that store an + * arbitrary number of JComponents.
+ *
+ * Project: envoy-client
+ * File: package-info.java
+ * Created: 14 Mar 2020
+ * + * @author Leon Hofmeister + * @author Kai S. K. Engelbart + * @author Maximilian Käfer + * @since Envoy v0.1-beta + */ +package envoy.client.ui.renderer; diff --git a/src/main/java/envoy/client/ui/settings/NewThemeScreen.java b/src/main/java/envoy/client/ui/settings/NewThemeScreen.java index e30adc9..4fdab10 100644 --- a/src/main/java/envoy/client/ui/settings/NewThemeScreen.java +++ b/src/main/java/envoy/client/ui/settings/NewThemeScreen.java @@ -1,228 +1,228 @@ -package envoy.client.ui.settings; - -import java.awt.*; -import java.util.function.Consumer; - -import javax.swing.JDialog; -import javax.swing.JPanel; -import javax.swing.JTextPane; - -import envoy.client.data.Settings; -import envoy.client.ui.PrimaryButton; -import envoy.client.ui.PrimaryTextArea; -import envoy.client.ui.Theme; - -/** - * Displays window where you can choose a name for the new {@link Theme}. - *
- * Project: envoy-client
- * File: NewThemeScreen.java
- * Created: 26 Dec 2019
- * - * @author Maximilian Käfer - * @since Envoy v0.3-alpha - */ -public class NewThemeScreen extends JDialog { - - private final JPanel standardPanel = new JPanel(); - private final JPanel secondaryPanel = new JPanel(); - private JTextPane text = new JTextPane(); - private PrimaryTextArea nameEnterTextArea = new PrimaryTextArea(4); - private PrimaryButton confirmButton = new PrimaryButton("Confirm"); - - private JTextPane errorText = new JTextPane(); - private PrimaryButton otherName = new PrimaryButton("Other Name"); - private PrimaryButton overwrite = new PrimaryButton("Overwrite"); - - private final Consumer newThemeAction, modifyThemeAction; - - private static final long serialVersionUID = 2369985550946300976L; - - /** - * Creates a window, where you can choose a name for a new {@link Theme}.
- * There are two versions of this Window. The first one is responsible for - * choosing the name, the second one appears, if the name already exists. - * - * @param parent the dialog is launched with its location relative to - * this {@link SettingsScreen} - * @param newThemeAction is executed when a new theme name is entered - * @param modifyThemeAction is executed when an existing theme name is entered - * and confirmed - * @since Envoy v0.3-alpha - */ - public NewThemeScreen(SettingsScreen parent, Consumer newThemeAction, Consumer modifyThemeAction) { - this.newThemeAction = newThemeAction; - this.modifyThemeAction = modifyThemeAction; - - setLocationRelativeTo(parent); - setTitle("New Theme"); - setModal(true); - - setDimensions(true); - setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - - Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()); - - getContentPane().setLayout(new BorderLayout()); - standardPanel.setBackground(theme.getBackgroundColor()); - secondaryPanel.setBackground(theme.getBackgroundColor()); - loadStandardContent(theme); - } - - private void setDimensions(boolean isStandard) { - Dimension size = isStandard ? new Dimension(300, 170) : new Dimension(300, 225); - setPreferredSize(size); - setMinimumSize(size); - setMaximumSize(size); - } - - private void loadStandardContent(Theme theme) { - getContentPane().removeAll(); - - // ContentPane - GridBagLayout gbl_contentPanel = new GridBagLayout(); - - gbl_contentPanel.columnWidths = new int[] { 1, 1 }; - gbl_contentPanel.rowHeights = new int[] { 1, 1, 1 }; - gbl_contentPanel.columnWeights = new double[] { 1, 1 }; - gbl_contentPanel.rowWeights = new double[] { 1, 1, 1 }; - - getContentPane().add(standardPanel, BorderLayout.CENTER); - standardPanel.setLayout(gbl_contentPanel); - - // text.setFont(new Font()); - text.setText("Please enter a name for the new Theme"); - text.setAlignmentX(CENTER_ALIGNMENT); - text.setBackground(theme.getCellColor()); - text.setForeground(theme.getUserNameColor()); - text.setEditable(false); - - GridBagConstraints gbc_text = new GridBagConstraints(); - gbc_text.fill = GridBagConstraints.HORIZONTAL; - gbc_text.gridx = 0; - gbc_text.gridy = 0; - gbc_text.gridwidth = 2; - gbc_text.insets = new Insets(5, 5, 5, 5); - - standardPanel.add(text, gbc_text); - - nameEnterTextArea.setBackground(theme.getCellColor()); - nameEnterTextArea.setForeground(theme.getTypingMessageColor()); - nameEnterTextArea.setText(""); - nameEnterTextArea.setEditable(true); - - GridBagConstraints gbc_input = new GridBagConstraints(); - gbc_input.fill = GridBagConstraints.HORIZONTAL; - gbc_input.gridx = 0; - gbc_input.gridy = 1; - gbc_input.gridwidth = 2; - gbc_input.insets = new Insets(5, 5, 5, 5); - - standardPanel.add(nameEnterTextArea, gbc_input); - - confirmButton.setBackground(theme.getInteractableBackgroundColor()); - confirmButton.setForeground(theme.getInteractableForegroundColor()); - - GridBagConstraints gbc_confirmButton = new GridBagConstraints(); - gbc_confirmButton.gridx = 0; - gbc_confirmButton.gridy = 2; - gbc_confirmButton.gridwidth = 2; - gbc_confirmButton.insets = new Insets(5, 5, 5, 5); - - standardPanel.add(confirmButton, gbc_confirmButton); - - confirmButton.addActionListener((evt) -> { - if (!nameEnterTextArea.getText().isEmpty()) if (Settings.getInstance().getThemes().containsKey(nameEnterTextArea.getText())) { - // load other panel - setDimensions(false); - loadSecondaryPage(theme); - } else { - newThemeAction.accept(nameEnterTextArea.getText()); - dispose(); - } - }); - } - - private void loadSecondaryPage(Theme theme) { - // ContentPane - getContentPane().removeAll(); - - GridBagLayout gbl_secondaryPanel = new GridBagLayout(); - - gbl_secondaryPanel.columnWidths = new int[] { 1, 1 }; - gbl_secondaryPanel.rowHeights = new int[] { 1, 1, 1, 1 }; - gbl_secondaryPanel.columnWeights = new double[] { 1, 1 }; - gbl_secondaryPanel.rowWeights = new double[] { 1, 1, 1, 1 }; - - getContentPane().add(secondaryPanel, BorderLayout.CENTER); - secondaryPanel.setLayout(gbl_secondaryPanel); - - // text.setFont(new Font()); - text.setText("Please enter a name for the new Theme"); - text.setAlignmentX(CENTER_ALIGNMENT); - text.setBackground(theme.getCellColor()); - text.setForeground(theme.getUserNameColor()); - text.setEditable(false); - - GridBagConstraints gbc_text = new GridBagConstraints(); - gbc_text.fill = GridBagConstraints.HORIZONTAL; - gbc_text.gridx = 0; - gbc_text.gridy = 0; - gbc_text.gridwidth = 2; - gbc_text.insets = new Insets(5, 5, 5, 5); - - secondaryPanel.add(text, gbc_text); - - nameEnterTextArea.setBackground(theme.getCellColor()); - nameEnterTextArea.setForeground(theme.getTypingMessageColor()); - nameEnterTextArea.setEditable(false); - - GridBagConstraints gbc_input = new GridBagConstraints(); - gbc_input.fill = GridBagConstraints.HORIZONTAL; - gbc_input.gridx = 0; - gbc_input.gridy = 1; - gbc_input.gridwidth = 2; - gbc_input.insets = new Insets(5, 5, 5, 5); - - secondaryPanel.add(nameEnterTextArea, gbc_input); - - errorText.setText("The name does already exist. Choose another one or overwrite the old theme."); - errorText.setAlignmentX(CENTER_ALIGNMENT); - errorText.setBackground(theme.getCellColor()); - errorText.setForeground(theme.getUserNameColor()); - errorText.setEditable(false); - - GridBagConstraints gbc_errorText = new GridBagConstraints(); - gbc_errorText.fill = GridBagConstraints.HORIZONTAL; - gbc_errorText.gridx = 0; - gbc_errorText.gridy = 2; - gbc_errorText.gridwidth = 2; - gbc_errorText.insets = new Insets(5, 5, 5, 5); - - secondaryPanel.add(errorText, gbc_errorText); - - otherName.setBackground(theme.getInteractableBackgroundColor()); - otherName.setForeground(theme.getInteractableForegroundColor()); - - GridBagConstraints gbc_otherName = new GridBagConstraints(); - gbc_otherName.gridx = 0; - gbc_otherName.gridy = 3; - gbc_otherName.insets = new Insets(5, 5, 5, 5); - - secondaryPanel.add(otherName, gbc_otherName); - - overwrite.setBackground(theme.getInteractableBackgroundColor()); - overwrite.setForeground(theme.getInteractableForegroundColor()); - - GridBagConstraints gbc_overwrite = new GridBagConstraints(); - gbc_overwrite.gridx = 1; - gbc_overwrite.gridy = 3; - gbc_overwrite.insets = new Insets(5, 5, 5, 5); - - secondaryPanel.add(overwrite, gbc_overwrite); - - otherName.addActionListener((evt) -> { setDimensions(true); loadStandardContent(theme); }); - - overwrite.addActionListener((evt) -> { modifyThemeAction.accept(nameEnterTextArea.getText()); dispose(); }); - } -} +package envoy.client.ui.settings; + +import java.awt.*; +import java.util.function.Consumer; + +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.JTextPane; + +import envoy.client.data.Settings; +import envoy.client.ui.Theme; +import envoy.client.ui.primary.PrimaryButton; +import envoy.client.ui.primary.PrimaryTextArea; + +/** + * Displays window where you can choose a name for the new {@link Theme}. + *
+ * Project: envoy-client
+ * File: NewThemeScreen.java
+ * Created: 26 Dec 2019
+ * + * @author Maximilian Käfer + * @since Envoy v0.3-alpha + */ +public class NewThemeScreen extends JDialog { + + private final JPanel standardPanel = new JPanel(); + private final JPanel secondaryPanel = new JPanel(); + private JTextPane text = new JTextPane(); + private PrimaryTextArea nameEnterTextArea = new PrimaryTextArea(4); + private PrimaryButton confirmButton = new PrimaryButton("Confirm"); + + private JTextPane errorText = new JTextPane(); + private PrimaryButton otherName = new PrimaryButton("Other Name"); + private PrimaryButton overwrite = new PrimaryButton("Overwrite"); + + private final Consumer newThemeAction, modifyThemeAction; + + private static final long serialVersionUID = 2369985550946300976L; + + /** + * Creates a window, where you can choose a name for a new {@link Theme}.
+ * There are two versions of this Window. The first one is responsible for + * choosing the name, the second one appears, if the name already exists. + * + * @param parent the dialog is launched with its location relative to + * this {@link SettingsScreen} + * @param newThemeAction is executed when a new theme name is entered + * @param modifyThemeAction is executed when an existing theme name is entered + * and confirmed + * @since Envoy v0.3-alpha + */ + public NewThemeScreen(SettingsScreen parent, Consumer newThemeAction, Consumer modifyThemeAction) { + this.newThemeAction = newThemeAction; + this.modifyThemeAction = modifyThemeAction; + + setLocationRelativeTo(parent); + setTitle("New Theme"); + setModal(true); + + setDimensions(true); + setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + + Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()); + + getContentPane().setLayout(new BorderLayout()); + standardPanel.setBackground(theme.getBackgroundColor()); + secondaryPanel.setBackground(theme.getBackgroundColor()); + loadStandardContent(theme); + } + + private void setDimensions(boolean isStandard) { + Dimension size = isStandard ? new Dimension(300, 170) : new Dimension(300, 225); + setPreferredSize(size); + setMinimumSize(size); + setMaximumSize(size); + } + + private void loadStandardContent(Theme theme) { + getContentPane().removeAll(); + + // ContentPane + GridBagLayout gbl_contentPanel = new GridBagLayout(); + + gbl_contentPanel.columnWidths = new int[] { 1, 1 }; + gbl_contentPanel.rowHeights = new int[] { 1, 1, 1 }; + gbl_contentPanel.columnWeights = new double[] { 1, 1 }; + gbl_contentPanel.rowWeights = new double[] { 1, 1, 1 }; + + getContentPane().add(standardPanel, BorderLayout.CENTER); + standardPanel.setLayout(gbl_contentPanel); + + // text.setFont(new Font()); + text.setText("Please enter a name for the new Theme"); + text.setAlignmentX(CENTER_ALIGNMENT); + text.setBackground(theme.getCellColor()); + text.setForeground(theme.getUserNameColor()); + text.setEditable(false); + + GridBagConstraints gbc_text = new GridBagConstraints(); + gbc_text.fill = GridBagConstraints.HORIZONTAL; + gbc_text.gridx = 0; + gbc_text.gridy = 0; + gbc_text.gridwidth = 2; + gbc_text.insets = new Insets(5, 5, 5, 5); + + standardPanel.add(text, gbc_text); + + nameEnterTextArea.setBackground(theme.getCellColor()); + nameEnterTextArea.setForeground(theme.getTypingMessageColor()); + nameEnterTextArea.setText(""); + nameEnterTextArea.setEditable(true); + + GridBagConstraints gbc_input = new GridBagConstraints(); + gbc_input.fill = GridBagConstraints.HORIZONTAL; + gbc_input.gridx = 0; + gbc_input.gridy = 1; + gbc_input.gridwidth = 2; + gbc_input.insets = new Insets(5, 5, 5, 5); + + standardPanel.add(nameEnterTextArea, gbc_input); + + confirmButton.setBackground(theme.getInteractableBackgroundColor()); + confirmButton.setForeground(theme.getInteractableForegroundColor()); + + GridBagConstraints gbc_confirmButton = new GridBagConstraints(); + gbc_confirmButton.gridx = 0; + gbc_confirmButton.gridy = 2; + gbc_confirmButton.gridwidth = 2; + gbc_confirmButton.insets = new Insets(5, 5, 5, 5); + + standardPanel.add(confirmButton, gbc_confirmButton); + + confirmButton.addActionListener((evt) -> { + if (!nameEnterTextArea.getText().isEmpty()) if (Settings.getInstance().getThemes().containsKey(nameEnterTextArea.getText())) { + // load other panel + setDimensions(false); + loadSecondaryPage(theme); + } else { + newThemeAction.accept(nameEnterTextArea.getText()); + dispose(); + } + }); + } + + private void loadSecondaryPage(Theme theme) { + // ContentPane + getContentPane().removeAll(); + + GridBagLayout gbl_secondaryPanel = new GridBagLayout(); + + gbl_secondaryPanel.columnWidths = new int[] { 1, 1 }; + gbl_secondaryPanel.rowHeights = new int[] { 1, 1, 1, 1 }; + gbl_secondaryPanel.columnWeights = new double[] { 1, 1 }; + gbl_secondaryPanel.rowWeights = new double[] { 1, 1, 1, 1 }; + + getContentPane().add(secondaryPanel, BorderLayout.CENTER); + secondaryPanel.setLayout(gbl_secondaryPanel); + + // text.setFont(new Font()); + text.setText("Please enter a name for the new Theme"); + text.setAlignmentX(CENTER_ALIGNMENT); + text.setBackground(theme.getCellColor()); + text.setForeground(theme.getUserNameColor()); + text.setEditable(false); + + GridBagConstraints gbc_text = new GridBagConstraints(); + gbc_text.fill = GridBagConstraints.HORIZONTAL; + gbc_text.gridx = 0; + gbc_text.gridy = 0; + gbc_text.gridwidth = 2; + gbc_text.insets = new Insets(5, 5, 5, 5); + + secondaryPanel.add(text, gbc_text); + + nameEnterTextArea.setBackground(theme.getCellColor()); + nameEnterTextArea.setForeground(theme.getTypingMessageColor()); + nameEnterTextArea.setEditable(false); + + GridBagConstraints gbc_input = new GridBagConstraints(); + gbc_input.fill = GridBagConstraints.HORIZONTAL; + gbc_input.gridx = 0; + gbc_input.gridy = 1; + gbc_input.gridwidth = 2; + gbc_input.insets = new Insets(5, 5, 5, 5); + + secondaryPanel.add(nameEnterTextArea, gbc_input); + + errorText.setText("The name does already exist. Choose another one or overwrite the old theme."); + errorText.setAlignmentX(CENTER_ALIGNMENT); + errorText.setBackground(theme.getCellColor()); + errorText.setForeground(theme.getUserNameColor()); + errorText.setEditable(false); + + GridBagConstraints gbc_errorText = new GridBagConstraints(); + gbc_errorText.fill = GridBagConstraints.HORIZONTAL; + gbc_errorText.gridx = 0; + gbc_errorText.gridy = 2; + gbc_errorText.gridwidth = 2; + gbc_errorText.insets = new Insets(5, 5, 5, 5); + + secondaryPanel.add(errorText, gbc_errorText); + + otherName.setBackground(theme.getInteractableBackgroundColor()); + otherName.setForeground(theme.getInteractableForegroundColor()); + + GridBagConstraints gbc_otherName = new GridBagConstraints(); + gbc_otherName.gridx = 0; + gbc_otherName.gridy = 3; + gbc_otherName.insets = new Insets(5, 5, 5, 5); + + secondaryPanel.add(otherName, gbc_otherName); + + overwrite.setBackground(theme.getInteractableBackgroundColor()); + overwrite.setForeground(theme.getInteractableForegroundColor()); + + GridBagConstraints gbc_overwrite = new GridBagConstraints(); + gbc_overwrite.gridx = 1; + gbc_overwrite.gridy = 3; + gbc_overwrite.insets = new Insets(5, 5, 5, 5); + + secondaryPanel.add(overwrite, gbc_overwrite); + + otherName.addActionListener((evt) -> { setDimensions(true); loadStandardContent(theme); }); + + overwrite.addActionListener((evt) -> { modifyThemeAction.accept(nameEnterTextArea.getText()); dispose(); }); + } +} diff --git a/src/main/java/envoy/client/ui/settings/SettingsScreen.java b/src/main/java/envoy/client/ui/settings/SettingsScreen.java index 56e8cf4..e1ae290 100644 --- a/src/main/java/envoy/client/ui/settings/SettingsScreen.java +++ b/src/main/java/envoy/client/ui/settings/SettingsScreen.java @@ -11,8 +11,8 @@ import javax.swing.*; import envoy.client.data.Settings; import envoy.client.event.ThemeChangeEvent; -import envoy.client.ui.PrimaryButton; import envoy.client.ui.Theme; +import envoy.client.ui.primary.PrimaryButton; import envoy.event.EventBus; import envoy.util.EnvoyLog;