Created packages ui.renderer and ui.primary

This commit is contained in:
delvh 2020-03-14 21:34:17 +01:00
parent 99441b770f
commit 384329d00d
15 changed files with 440 additions and 361 deletions

View File

@ -7,7 +7,7 @@ import java.util.function.Consumer;
import javax.swing.JComponent; 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 * Encapsulates a persistent value that is directly or indirectly mutable by the

View File

@ -20,6 +20,12 @@ import envoy.client.net.Client;
import envoy.client.net.WriteProxy; import envoy.client.net.WriteProxy;
import envoy.client.ui.list.ComponentList; import envoy.client.ui.list.ComponentList;
import envoy.client.ui.list.ComponentListModel; 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.client.ui.settings.SettingsScreen;
import envoy.data.Message; import envoy.data.Message;
import envoy.data.Message.MessageStatus; import envoy.data.Message.MessageStatus;
@ -110,7 +116,15 @@ public class ChatWindow extends JFrame {
contentPane.setLayout(gbl_contentPane); contentPane.setLayout(gbl_contentPane);
messageList.setBorder(new EmptyBorder(space, space, space, space)); 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.setViewportView(messageList);
scrollPane.addComponentListener(new ComponentAdapter() { scrollPane.addComponentListener(new ComponentAdapter() {

View File

@ -16,6 +16,7 @@ import javax.swing.border.EmptyBorder;
import envoy.client.data.*; import envoy.client.data.*;
import envoy.client.event.HandshakeSuccessfulEvent; import envoy.client.event.HandshakeSuccessfulEvent;
import envoy.client.net.Client; import envoy.client.net.Client;
import envoy.client.ui.primary.PrimaryButton;
import envoy.data.LoginCredentials; import envoy.data.LoginCredentials;
import envoy.data.Message; import envoy.data.Message;
import envoy.data.User; import envoy.data.User;

View File

@ -1,63 +1,63 @@
package envoy.client.ui; package envoy.client.ui.primary;
import java.awt.Graphics; import java.awt.Graphics;
import javax.swing.JButton; import javax.swing.JButton;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>PrimaryButton.javaEvent.java</strong><br> * File: <strong>PrimaryButton.javaEvent.java</strong><br>
* Created: <strong>07.12.2019</strong><br> * Created: <strong>07.12.2019</strong><br>
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @author Maximilian K&auml;fer * @author Maximilian K&auml;fer
* @since Envoy v0.2-alpha * @since Envoy v0.2-alpha
*/ */
public class PrimaryButton extends JButton { public class PrimaryButton extends JButton {
private static final long serialVersionUID = 3662266120667728364L; private static final long serialVersionUID = 3662266120667728364L;
private int arcSize; private int arcSize;
/** /**
* Creates a primary button * Creates a primary button
* *
* @param title the title of the button * @param title the title of the button
* @since Envoy 0.2-alpha * @since Envoy 0.2-alpha
*/ */
public PrimaryButton(String title) { this(title, 6); } public PrimaryButton(String title) { this(title, 6); }
/** /**
* Creates a primary button * Creates a primary button
* *
* @param title the title of the button * @param title the title of the button
* @param arcSize the size of the arc used to draw the round button edges * @param arcSize the size of the arc used to draw the round button edges
* @since Envoy 0.2-alpha * @since Envoy 0.2-alpha
*/ */
public PrimaryButton(String title, int arcSize) { public PrimaryButton(String title, int arcSize) {
super(title); super(title);
setBorderPainted(false); setBorderPainted(false);
setFocusPainted(false); setFocusPainted(false);
setContentAreaFilled(false); setContentAreaFilled(false);
this.arcSize = arcSize; this.arcSize = arcSize;
} }
@Override @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
g.setColor(getBackground()); g.setColor(getBackground());
g.fillRoundRect(0, 0, getWidth(), getHeight(), arcSize, arcSize); g.fillRoundRect(0, 0, getWidth(), getHeight(), arcSize, arcSize);
super.paintComponent(g); super.paintComponent(g);
} }
/** /**
* @return the arcSize * @return the arcSize
* @since Envoy 0.2-alpha * @since Envoy 0.2-alpha
*/ */
public int getArcSize() { return arcSize; } public int getArcSize() { return arcSize; }
/** /**
* @param arcSize the arcSize to set * @param arcSize the arcSize to set
* @since Envoy 0.2-alpha * @since Envoy 0.2-alpha
*/ */
public void setArcSize(int arcSize) { this.arcSize = arcSize; } public void setArcSize(int arcSize) { this.arcSize = arcSize; }
} }

View File

@ -1,4 +1,4 @@
package envoy.client.ui; package envoy.client.ui.primary;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
@ -13,6 +13,7 @@ import javax.swing.JScrollBar;
import javax.swing.plaf.basic.BasicScrollBarUI; import javax.swing.plaf.basic.BasicScrollBarUI;
import envoy.client.data.Settings; import envoy.client.data.Settings;
import envoy.client.ui.Theme;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>

View File

@ -1,7 +1,9 @@
package envoy.client.ui; package envoy.client.ui.primary;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import envoy.client.ui.Theme;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>PrimaryScrollPane.java</strong><br> * File: <strong>PrimaryScrollPane.java</strong><br>

View File

@ -1,4 +1,4 @@
package envoy.client.ui; package envoy.client.ui.primary;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;

View File

@ -1,57 +1,58 @@
package envoy.client.ui; package envoy.client.ui.primary;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import javax.swing.JButton; import javax.swing.JButton;
import envoy.client.data.Settings; import envoy.client.data.Settings;
import envoy.client.data.SettingsItem; 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}.<br> * This component can be used to toggle between two options. This will change
* <br> * the state of a {@code boolean} {@link SettingsItem}.<br>
* Project: <strong>envoy-client</strong><br> * <br>
* File: <strong>PrimaryToggleSwitch.java</strong><br> * Project: <strong>envoy-client</strong><br>
* Created: <strong>21 Dec 2019</strong><br> * File: <strong>PrimaryToggleSwitch.java</strong><br>
* * Created: <strong>21 Dec 2019</strong><br>
* @author Maximilian K&auml;fer *
* @author Kai S. K. Engelbart * @author Maximilian K&auml;fer
* @since Envoy v0.3-alpha * @author Kai S. K. Engelbart
*/ * @since Envoy v0.3-alpha
public class PrimaryToggleSwitch extends JButton { */
public class PrimaryToggleSwitch extends JButton {
private boolean state;
private boolean state;
private static final long serialVersionUID = -721155303106833184L;
private static final long serialVersionUID = -721155303106833184L;
/**
* Initializes a {@link PrimaryToggleSwitch}. /**
* * Initializes a {@link PrimaryToggleSwitch}.
* @param settingsItem the {@link SettingsItem} that is controlled by this *
* {@link PrimaryToggleSwitch} * @param settingsItem the {@link SettingsItem} that is controlled by this
* @since Envoy v0.3-alpha * {@link PrimaryToggleSwitch}
*/ * @since Envoy v0.3-alpha
public PrimaryToggleSwitch(SettingsItem<Boolean> settingsItem) { */
setPreferredSize(new Dimension(50, 25)); public PrimaryToggleSwitch(SettingsItem<Boolean> settingsItem) {
setMinimumSize(new Dimension(50, 25)); setPreferredSize(new Dimension(50, 25));
setMaximumSize(new Dimension(50, 25)); setMinimumSize(new Dimension(50, 25));
setMaximumSize(new Dimension(50, 25));
setBorderPainted(false);
setFocusPainted(false); setBorderPainted(false);
setContentAreaFilled(false); setFocusPainted(false);
setContentAreaFilled(false);
state = settingsItem.get();
addActionListener((evt) -> { state = !state; settingsItem.set(state); revalidate(); repaint(); }); state = settingsItem.get();
} addActionListener((evt) -> { state = !state; settingsItem.set(state); revalidate(); repaint(); });
}
@Override
public void paintComponent(Graphics g) { @Override
g.setColor(state ? Color.GREEN : Color.LIGHT_GRAY); public void paintComponent(Graphics g) {
g.fillRoundRect(0, 0, getWidth(), getHeight(), 25, 25); 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); g.setColor(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableBackgroundColor());
} g.fillRoundRect(state ? 25 : 0, 0, 25, 25, 25, 25);
} }
}

View File

@ -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.<br>
* Primary elements are supposed to provide the main functionality of a UI
* component.<br>
* <br>
* Project: <strong>envoy-client</strong><br>
* File: <strong>package-info.java</strong><br>
* Created: <strong>14 Mar 2020</strong><br>
*
* @author Leon Hofmeister
* @author Kai S. K. Engelbart
* @author Maximilian K&auml;fer
* @since Envoy v0.1-beta
*/
package envoy.client.ui.primary;

View File

@ -1,4 +1,4 @@
package envoy.client.ui; package envoy.client.ui.renderer;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
@ -8,8 +8,10 @@ import javax.swing.*;
import envoy.client.data.Settings; import envoy.client.data.Settings;
import envoy.client.event.SendEvent; import envoy.client.event.SendEvent;
import envoy.client.ui.Color;
import envoy.client.ui.list.ComponentList; import envoy.client.ui.list.ComponentList;
import envoy.client.ui.list.ComponentListCellRenderer; import envoy.client.ui.list.ComponentListCellRenderer;
import envoy.client.ui.primary.PrimaryButton;
import envoy.data.User; import envoy.data.User;
import envoy.event.ContactOperationEvent; import envoy.event.ContactOperationEvent;
import envoy.event.EventBus; import envoy.event.EventBus;

View File

@ -1,15 +1,21 @@
package envoy.client.ui; package envoy.client.ui.renderer;
import java.awt.BorderLayout;
import java.awt.Font; import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.EnumMap;
import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
import envoy.client.data.Settings; 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.ComponentList;
import envoy.client.ui.list.ComponentListCellRenderer; import envoy.client.ui.list.ComponentListCellRenderer;
import envoy.data.Message; import envoy.data.Message;
import envoy.data.Message.MessageStatus;
/** /**
* Defines how a message is displayed.<br> * Defines how a message is displayed.<br>
@ -25,12 +31,23 @@ import envoy.data.Message;
*/ */
public class MessageListRenderer implements ComponentListCellRenderer<Message> { public class MessageListRenderer implements ComponentListCellRenderer<Message> {
private static final EnumMap<MessageStatus, BufferedImage> 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; private JTextArea messageTextArea;
@Override @Override
public JPanel getListCellComponent(ComponentList<? extends Message> list, Message value, boolean isSelected) { public JPanel getListCellComponent(ComponentList<? extends Message> list, Message value, boolean isSelected) {
final JPanel panel = new JPanel(); 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()); final Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
// Panel background // Panel background
@ -47,7 +64,17 @@ public class MessageListRenderer implements ComponentListCellRenderer<Message> {
// Set the date color to be the value of DateColorChat // Set the date color to be the value of DateColorChat
dateLabel.setForeground(theme.getDateColor()); 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 // The JTextArea that displays the text content of a message and its status
messageTextArea = new JTextArea(text + System.getProperty("line.separator")); messageTextArea = new JTextArea(text + System.getProperty("line.separator"));
@ -58,7 +85,7 @@ public class MessageListRenderer implements ComponentListCellRenderer<Message> {
messageTextArea.setBackground(panel.getBackground()); messageTextArea.setBackground(panel.getBackground());
messageTextArea.setEditable(false); messageTextArea.setEditable(false);
panel.add(messageTextArea, BorderLayout.CENTER); panel.add(messageTextArea);
JLabel statusLabel = new JLabel(state); JLabel statusLabel = new JLabel(state);
statusLabel.setFont(new Font("Arial", Font.BOLD, 14)); statusLabel.setFont(new Font("Arial", Font.BOLD, 14));
@ -83,7 +110,7 @@ public class MessageListRenderer implements ComponentListCellRenderer<Message> {
statusLabel.setForeground(statusColor); statusLabel.setForeground(statusColor);
statusLabel.setBackground(panel.getBackground()); statusLabel.setBackground(panel.getBackground());
panel.add(statusLabel, BorderLayout.SOUTH); panel.add(statusLabel);
// Define some space to the messages below // Define some space to the messages below
panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(), BorderFactory.createEtchedBorder())); panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(), BorderFactory.createEtchedBorder()));

View File

@ -1,4 +1,4 @@
package envoy.client.ui; package envoy.client.ui.renderer;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;

View File

@ -0,0 +1,14 @@
/**
* This package contains all Envoy-specific renderers for lists that store an
* arbitrary number of JComponents.<br>
* <br>
* Project: <strong>envoy-client</strong><br>
* File: <strong>package-info.java</strong><br>
* Created: <strong>14 Mar 2020</strong><br>
*
* @author Leon Hofmeister
* @author Kai S. K. Engelbart
* @author Maximilian K&auml;fer
* @since Envoy v0.1-beta
*/
package envoy.client.ui.renderer;

View File

@ -1,228 +1,228 @@
package envoy.client.ui.settings; package envoy.client.ui.settings;
import java.awt.*; import java.awt.*;
import java.util.function.Consumer; import java.util.function.Consumer;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextPane; import javax.swing.JTextPane;
import envoy.client.data.Settings; import envoy.client.data.Settings;
import envoy.client.ui.PrimaryButton; import envoy.client.ui.Theme;
import envoy.client.ui.PrimaryTextArea; import envoy.client.ui.primary.PrimaryButton;
import envoy.client.ui.Theme; import envoy.client.ui.primary.PrimaryTextArea;
/** /**
* Displays window where you can choose a name for the new {@link Theme}. * Displays window where you can choose a name for the new {@link Theme}.
* <br> * <br>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>NewThemeScreen.java</strong><br> * File: <strong>NewThemeScreen.java</strong><br>
* Created: <strong>26 Dec 2019</strong><br> * Created: <strong>26 Dec 2019</strong><br>
* *
* @author Maximilian K&auml;fer * @author Maximilian K&auml;fer
* @since Envoy v0.3-alpha * @since Envoy v0.3-alpha
*/ */
public class NewThemeScreen extends JDialog { public class NewThemeScreen extends JDialog {
private final JPanel standardPanel = new JPanel(); private final JPanel standardPanel = new JPanel();
private final JPanel secondaryPanel = new JPanel(); private final JPanel secondaryPanel = new JPanel();
private JTextPane text = new JTextPane(); private JTextPane text = new JTextPane();
private PrimaryTextArea nameEnterTextArea = new PrimaryTextArea(4); private PrimaryTextArea nameEnterTextArea = new PrimaryTextArea(4);
private PrimaryButton confirmButton = new PrimaryButton("Confirm"); private PrimaryButton confirmButton = new PrimaryButton("Confirm");
private JTextPane errorText = new JTextPane(); private JTextPane errorText = new JTextPane();
private PrimaryButton otherName = new PrimaryButton("Other Name"); private PrimaryButton otherName = new PrimaryButton("Other Name");
private PrimaryButton overwrite = new PrimaryButton("Overwrite"); private PrimaryButton overwrite = new PrimaryButton("Overwrite");
private final Consumer<String> newThemeAction, modifyThemeAction; private final Consumer<String> newThemeAction, modifyThemeAction;
private static final long serialVersionUID = 2369985550946300976L; private static final long serialVersionUID = 2369985550946300976L;
/** /**
* Creates a window, where you can choose a name for a new {@link Theme}. <br> * Creates a window, where you can choose a name for a new {@link Theme}. <br>
* There are two versions of this Window. The first one is responsible for * 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. * choosing the name, the second one appears, if the name already exists.
* *
* @param parent the dialog is launched with its location relative to * @param parent the dialog is launched with its location relative to
* this {@link SettingsScreen} * this {@link SettingsScreen}
* @param newThemeAction is executed when a new theme name is entered * @param newThemeAction is executed when a new theme name is entered
* @param modifyThemeAction is executed when an existing theme name is entered * @param modifyThemeAction is executed when an existing theme name is entered
* and confirmed * and confirmed
* @since Envoy v0.3-alpha * @since Envoy v0.3-alpha
*/ */
public NewThemeScreen(SettingsScreen parent, Consumer<String> newThemeAction, Consumer<String> modifyThemeAction) { public NewThemeScreen(SettingsScreen parent, Consumer<String> newThemeAction, Consumer<String> modifyThemeAction) {
this.newThemeAction = newThemeAction; this.newThemeAction = newThemeAction;
this.modifyThemeAction = modifyThemeAction; this.modifyThemeAction = modifyThemeAction;
setLocationRelativeTo(parent); setLocationRelativeTo(parent);
setTitle("New Theme"); setTitle("New Theme");
setModal(true); setModal(true);
setDimensions(true); setDimensions(true);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()); Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
getContentPane().setLayout(new BorderLayout()); getContentPane().setLayout(new BorderLayout());
standardPanel.setBackground(theme.getBackgroundColor()); standardPanel.setBackground(theme.getBackgroundColor());
secondaryPanel.setBackground(theme.getBackgroundColor()); secondaryPanel.setBackground(theme.getBackgroundColor());
loadStandardContent(theme); loadStandardContent(theme);
} }
private void setDimensions(boolean isStandard) { private void setDimensions(boolean isStandard) {
Dimension size = isStandard ? new Dimension(300, 170) : new Dimension(300, 225); Dimension size = isStandard ? new Dimension(300, 170) : new Dimension(300, 225);
setPreferredSize(size); setPreferredSize(size);
setMinimumSize(size); setMinimumSize(size);
setMaximumSize(size); setMaximumSize(size);
} }
private void loadStandardContent(Theme theme) { private void loadStandardContent(Theme theme) {
getContentPane().removeAll(); getContentPane().removeAll();
// ContentPane // ContentPane
GridBagLayout gbl_contentPanel = new GridBagLayout(); GridBagLayout gbl_contentPanel = new GridBagLayout();
gbl_contentPanel.columnWidths = new int[] { 1, 1 }; gbl_contentPanel.columnWidths = new int[] { 1, 1 };
gbl_contentPanel.rowHeights = new int[] { 1, 1, 1 }; gbl_contentPanel.rowHeights = new int[] { 1, 1, 1 };
gbl_contentPanel.columnWeights = new double[] { 1, 1 }; gbl_contentPanel.columnWeights = new double[] { 1, 1 };
gbl_contentPanel.rowWeights = new double[] { 1, 1, 1 }; gbl_contentPanel.rowWeights = new double[] { 1, 1, 1 };
getContentPane().add(standardPanel, BorderLayout.CENTER); getContentPane().add(standardPanel, BorderLayout.CENTER);
standardPanel.setLayout(gbl_contentPanel); standardPanel.setLayout(gbl_contentPanel);
// text.setFont(new Font()); // text.setFont(new Font());
text.setText("Please enter a name for the new Theme"); text.setText("Please enter a name for the new Theme");
text.setAlignmentX(CENTER_ALIGNMENT); text.setAlignmentX(CENTER_ALIGNMENT);
text.setBackground(theme.getCellColor()); text.setBackground(theme.getCellColor());
text.setForeground(theme.getUserNameColor()); text.setForeground(theme.getUserNameColor());
text.setEditable(false); text.setEditable(false);
GridBagConstraints gbc_text = new GridBagConstraints(); GridBagConstraints gbc_text = new GridBagConstraints();
gbc_text.fill = GridBagConstraints.HORIZONTAL; gbc_text.fill = GridBagConstraints.HORIZONTAL;
gbc_text.gridx = 0; gbc_text.gridx = 0;
gbc_text.gridy = 0; gbc_text.gridy = 0;
gbc_text.gridwidth = 2; gbc_text.gridwidth = 2;
gbc_text.insets = new Insets(5, 5, 5, 5); gbc_text.insets = new Insets(5, 5, 5, 5);
standardPanel.add(text, gbc_text); standardPanel.add(text, gbc_text);
nameEnterTextArea.setBackground(theme.getCellColor()); nameEnterTextArea.setBackground(theme.getCellColor());
nameEnterTextArea.setForeground(theme.getTypingMessageColor()); nameEnterTextArea.setForeground(theme.getTypingMessageColor());
nameEnterTextArea.setText(""); nameEnterTextArea.setText("");
nameEnterTextArea.setEditable(true); nameEnterTextArea.setEditable(true);
GridBagConstraints gbc_input = new GridBagConstraints(); GridBagConstraints gbc_input = new GridBagConstraints();
gbc_input.fill = GridBagConstraints.HORIZONTAL; gbc_input.fill = GridBagConstraints.HORIZONTAL;
gbc_input.gridx = 0; gbc_input.gridx = 0;
gbc_input.gridy = 1; gbc_input.gridy = 1;
gbc_input.gridwidth = 2; gbc_input.gridwidth = 2;
gbc_input.insets = new Insets(5, 5, 5, 5); gbc_input.insets = new Insets(5, 5, 5, 5);
standardPanel.add(nameEnterTextArea, gbc_input); standardPanel.add(nameEnterTextArea, gbc_input);
confirmButton.setBackground(theme.getInteractableBackgroundColor()); confirmButton.setBackground(theme.getInteractableBackgroundColor());
confirmButton.setForeground(theme.getInteractableForegroundColor()); confirmButton.setForeground(theme.getInteractableForegroundColor());
GridBagConstraints gbc_confirmButton = new GridBagConstraints(); GridBagConstraints gbc_confirmButton = new GridBagConstraints();
gbc_confirmButton.gridx = 0; gbc_confirmButton.gridx = 0;
gbc_confirmButton.gridy = 2; gbc_confirmButton.gridy = 2;
gbc_confirmButton.gridwidth = 2; gbc_confirmButton.gridwidth = 2;
gbc_confirmButton.insets = new Insets(5, 5, 5, 5); gbc_confirmButton.insets = new Insets(5, 5, 5, 5);
standardPanel.add(confirmButton, gbc_confirmButton); standardPanel.add(confirmButton, gbc_confirmButton);
confirmButton.addActionListener((evt) -> { confirmButton.addActionListener((evt) -> {
if (!nameEnterTextArea.getText().isEmpty()) if (Settings.getInstance().getThemes().containsKey(nameEnterTextArea.getText())) { if (!nameEnterTextArea.getText().isEmpty()) if (Settings.getInstance().getThemes().containsKey(nameEnterTextArea.getText())) {
// load other panel // load other panel
setDimensions(false); setDimensions(false);
loadSecondaryPage(theme); loadSecondaryPage(theme);
} else { } else {
newThemeAction.accept(nameEnterTextArea.getText()); newThemeAction.accept(nameEnterTextArea.getText());
dispose(); dispose();
} }
}); });
} }
private void loadSecondaryPage(Theme theme) { private void loadSecondaryPage(Theme theme) {
// ContentPane // ContentPane
getContentPane().removeAll(); getContentPane().removeAll();
GridBagLayout gbl_secondaryPanel = new GridBagLayout(); GridBagLayout gbl_secondaryPanel = new GridBagLayout();
gbl_secondaryPanel.columnWidths = new int[] { 1, 1 }; gbl_secondaryPanel.columnWidths = new int[] { 1, 1 };
gbl_secondaryPanel.rowHeights = new int[] { 1, 1, 1, 1 }; gbl_secondaryPanel.rowHeights = new int[] { 1, 1, 1, 1 };
gbl_secondaryPanel.columnWeights = new double[] { 1, 1 }; gbl_secondaryPanel.columnWeights = new double[] { 1, 1 };
gbl_secondaryPanel.rowWeights = new double[] { 1, 1, 1, 1 }; gbl_secondaryPanel.rowWeights = new double[] { 1, 1, 1, 1 };
getContentPane().add(secondaryPanel, BorderLayout.CENTER); getContentPane().add(secondaryPanel, BorderLayout.CENTER);
secondaryPanel.setLayout(gbl_secondaryPanel); secondaryPanel.setLayout(gbl_secondaryPanel);
// text.setFont(new Font()); // text.setFont(new Font());
text.setText("Please enter a name for the new Theme"); text.setText("Please enter a name for the new Theme");
text.setAlignmentX(CENTER_ALIGNMENT); text.setAlignmentX(CENTER_ALIGNMENT);
text.setBackground(theme.getCellColor()); text.setBackground(theme.getCellColor());
text.setForeground(theme.getUserNameColor()); text.setForeground(theme.getUserNameColor());
text.setEditable(false); text.setEditable(false);
GridBagConstraints gbc_text = new GridBagConstraints(); GridBagConstraints gbc_text = new GridBagConstraints();
gbc_text.fill = GridBagConstraints.HORIZONTAL; gbc_text.fill = GridBagConstraints.HORIZONTAL;
gbc_text.gridx = 0; gbc_text.gridx = 0;
gbc_text.gridy = 0; gbc_text.gridy = 0;
gbc_text.gridwidth = 2; gbc_text.gridwidth = 2;
gbc_text.insets = new Insets(5, 5, 5, 5); gbc_text.insets = new Insets(5, 5, 5, 5);
secondaryPanel.add(text, gbc_text); secondaryPanel.add(text, gbc_text);
nameEnterTextArea.setBackground(theme.getCellColor()); nameEnterTextArea.setBackground(theme.getCellColor());
nameEnterTextArea.setForeground(theme.getTypingMessageColor()); nameEnterTextArea.setForeground(theme.getTypingMessageColor());
nameEnterTextArea.setEditable(false); nameEnterTextArea.setEditable(false);
GridBagConstraints gbc_input = new GridBagConstraints(); GridBagConstraints gbc_input = new GridBagConstraints();
gbc_input.fill = GridBagConstraints.HORIZONTAL; gbc_input.fill = GridBagConstraints.HORIZONTAL;
gbc_input.gridx = 0; gbc_input.gridx = 0;
gbc_input.gridy = 1; gbc_input.gridy = 1;
gbc_input.gridwidth = 2; gbc_input.gridwidth = 2;
gbc_input.insets = new Insets(5, 5, 5, 5); gbc_input.insets = new Insets(5, 5, 5, 5);
secondaryPanel.add(nameEnterTextArea, gbc_input); secondaryPanel.add(nameEnterTextArea, gbc_input);
errorText.setText("The name does already exist. Choose another one or overwrite the old theme."); errorText.setText("The name does already exist. Choose another one or overwrite the old theme.");
errorText.setAlignmentX(CENTER_ALIGNMENT); errorText.setAlignmentX(CENTER_ALIGNMENT);
errorText.setBackground(theme.getCellColor()); errorText.setBackground(theme.getCellColor());
errorText.setForeground(theme.getUserNameColor()); errorText.setForeground(theme.getUserNameColor());
errorText.setEditable(false); errorText.setEditable(false);
GridBagConstraints gbc_errorText = new GridBagConstraints(); GridBagConstraints gbc_errorText = new GridBagConstraints();
gbc_errorText.fill = GridBagConstraints.HORIZONTAL; gbc_errorText.fill = GridBagConstraints.HORIZONTAL;
gbc_errorText.gridx = 0; gbc_errorText.gridx = 0;
gbc_errorText.gridy = 2; gbc_errorText.gridy = 2;
gbc_errorText.gridwidth = 2; gbc_errorText.gridwidth = 2;
gbc_errorText.insets = new Insets(5, 5, 5, 5); gbc_errorText.insets = new Insets(5, 5, 5, 5);
secondaryPanel.add(errorText, gbc_errorText); secondaryPanel.add(errorText, gbc_errorText);
otherName.setBackground(theme.getInteractableBackgroundColor()); otherName.setBackground(theme.getInteractableBackgroundColor());
otherName.setForeground(theme.getInteractableForegroundColor()); otherName.setForeground(theme.getInteractableForegroundColor());
GridBagConstraints gbc_otherName = new GridBagConstraints(); GridBagConstraints gbc_otherName = new GridBagConstraints();
gbc_otherName.gridx = 0; gbc_otherName.gridx = 0;
gbc_otherName.gridy = 3; gbc_otherName.gridy = 3;
gbc_otherName.insets = new Insets(5, 5, 5, 5); gbc_otherName.insets = new Insets(5, 5, 5, 5);
secondaryPanel.add(otherName, gbc_otherName); secondaryPanel.add(otherName, gbc_otherName);
overwrite.setBackground(theme.getInteractableBackgroundColor()); overwrite.setBackground(theme.getInteractableBackgroundColor());
overwrite.setForeground(theme.getInteractableForegroundColor()); overwrite.setForeground(theme.getInteractableForegroundColor());
GridBagConstraints gbc_overwrite = new GridBagConstraints(); GridBagConstraints gbc_overwrite = new GridBagConstraints();
gbc_overwrite.gridx = 1; gbc_overwrite.gridx = 1;
gbc_overwrite.gridy = 3; gbc_overwrite.gridy = 3;
gbc_overwrite.insets = new Insets(5, 5, 5, 5); gbc_overwrite.insets = new Insets(5, 5, 5, 5);
secondaryPanel.add(overwrite, gbc_overwrite); secondaryPanel.add(overwrite, gbc_overwrite);
otherName.addActionListener((evt) -> { setDimensions(true); loadStandardContent(theme); }); otherName.addActionListener((evt) -> { setDimensions(true); loadStandardContent(theme); });
overwrite.addActionListener((evt) -> { modifyThemeAction.accept(nameEnterTextArea.getText()); dispose(); }); overwrite.addActionListener((evt) -> { modifyThemeAction.accept(nameEnterTextArea.getText()); dispose(); });
} }
} }

View File

@ -11,8 +11,8 @@ import javax.swing.*;
import envoy.client.data.Settings; import envoy.client.data.Settings;
import envoy.client.event.ThemeChangeEvent; import envoy.client.event.ThemeChangeEvent;
import envoy.client.ui.PrimaryButton;
import envoy.client.ui.Theme; import envoy.client.ui.Theme;
import envoy.client.ui.primary.PrimaryButton;
import envoy.event.EventBus; import envoy.event.EventBus;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;