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,4 +1,4 @@
|
||||
package envoy.client.ui;
|
||||
package envoy.client.ui.primary;
|
||||
|
||||
import java.awt.Graphics;
|
||||
|
@ -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,4 +1,4 @@
|
||||
package envoy.client.ui;
|
||||
package envoy.client.ui.primary;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
@ -7,6 +7,7 @@ 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
|
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;
|
@ -8,9 +8,9 @@ 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;
|
||||
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}.
|
||||
|
@ -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