Created packages ui.renderer and ui.primary
This commit is contained in:
parent
4c94686172
commit
9eaa9dc9d2
@ -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
|
||||
|
@ -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() {
|
||||
|
||||
|
@ -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;
|
||||
|
@ -1,63 +1,63 @@
|
||||
package envoy.client.ui;
|
||||
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JButton;
|
||||
|
||||
/**
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
* File: <strong>PrimaryButton.javaEvent.java</strong><br>
|
||||
* Created: <strong>07.12.2019</strong><br>
|
||||
*
|
||||
* @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: <strong>envoy-client</strong><br>
|
||||
* File: <strong>PrimaryButton.javaEvent.java</strong><br>
|
||||
* Created: <strong>07.12.2019</strong><br>
|
||||
*
|
||||
* @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; }
|
||||
}
|
@ -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: <strong>envoy-client</strong><br>
|
@ -1,7 +1,9 @@
|
||||
package envoy.client.ui;
|
||||
package envoy.client.ui.primary;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import envoy.client.ui.Theme;
|
||||
|
||||
/**
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
* File: <strong>PrimaryScrollPane.java</strong><br>
|
@ -1,4 +1,4 @@
|
||||
package envoy.client.ui;
|
||||
package envoy.client.ui.primary;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
@ -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}.<br>
|
||||
* <br>
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
* File: <strong>PrimaryToggleSwitch.java</strong><br>
|
||||
* Created: <strong>21 Dec 2019</strong><br>
|
||||
*
|
||||
* @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<Boolean> 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}.<br>
|
||||
* <br>
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
* File: <strong>PrimaryToggleSwitch.java</strong><br>
|
||||
* Created: <strong>21 Dec 2019</strong><br>
|
||||
*
|
||||
* @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<Boolean> 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);
|
||||
}
|
||||
}
|
17
src/main/java/envoy/client/ui/primary/package-info.java
Normal file
17
src/main/java/envoy/client/ui/primary/package-info.java
Normal 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äfer
|
||||
* @since Envoy v0.1-beta
|
||||
*/
|
||||
package envoy.client.ui.primary;
|
@ -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;
|
@ -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.<br>
|
||||
@ -25,12 +31,23 @@ import envoy.data.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;
|
||||
|
||||
@Override
|
||||
public JPanel getListCellComponent(ComponentList<? extends Message> 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<Message> {
|
||||
// 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<Message> {
|
||||
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<Message> {
|
||||
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()));
|
@ -1,4 +1,4 @@
|
||||
package envoy.client.ui;
|
||||
package envoy.client.ui.renderer;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
14
src/main/java/envoy/client/ui/renderer/package-info.java
Normal file
14
src/main/java/envoy/client/ui/renderer/package-info.java
Normal 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äfer
|
||||
* @since Envoy v0.1-beta
|
||||
*/
|
||||
package envoy.client.ui.renderer;
|
@ -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}.
|
||||
* <br>
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
* File: <strong>NewThemeScreen.java</strong><br>
|
||||
* Created: <strong>26 Dec 2019</strong><br>
|
||||
*
|
||||
* @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<String> newThemeAction, modifyThemeAction;
|
||||
|
||||
private static final long serialVersionUID = 2369985550946300976L;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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<String> newThemeAction, Consumer<String> 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}.
|
||||
* <br>
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
* File: <strong>NewThemeScreen.java</strong><br>
|
||||
* Created: <strong>26 Dec 2019</strong><br>
|
||||
*
|
||||
* @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<String> newThemeAction, modifyThemeAction;
|
||||
|
||||
private static final long serialVersionUID = 2369985550946300976L;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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<String> newThemeAction, Consumer<String> 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(); });
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user