From 64d6299018556d1c32d01e87a77e4a747d44230b Mon Sep 17 00:00:00 2001 From: Sogomn Date: Thu, 18 Feb 2016 17:04:59 +0100 Subject: [PATCH] Major changes More GUI! --- .../{menu_icons.png => gui_menu_icons.png} | Bin Ratty/res/gui_notification_icons.png | Bin 0 -> 402 bytes ...menu_icons_tree.png => gui_tree_icons.png} | Bin Ratty/res/language/lang.properties | 6 +- Ratty/res/language/lang_de.properties | 6 +- Ratty/res/language/lang_en.properties | 6 +- Ratty/src/de/sogomn/rat/GUISettings.java | 62 +++++++++++++++--- Ratty/src/de/sogomn/rat/Ratty.java | 2 +- .../de/sogomn/rat/server/gui/FileTree.java | 2 +- .../de/sogomn/rat/server/gui/RattyGui.java | 19 ++++-- .../rat/server/gui/RattyGuiController.java | 22 ++++++- 11 files changed, 104 insertions(+), 21 deletions(-) rename Ratty/res/{menu_icons.png => gui_menu_icons.png} (100%) create mode 100644 Ratty/res/gui_notification_icons.png rename Ratty/res/{menu_icons_tree.png => gui_tree_icons.png} (100%) diff --git a/Ratty/res/menu_icons.png b/Ratty/res/gui_menu_icons.png similarity index 100% rename from Ratty/res/menu_icons.png rename to Ratty/res/gui_menu_icons.png diff --git a/Ratty/res/gui_notification_icons.png b/Ratty/res/gui_notification_icons.png new file mode 100644 index 0000000000000000000000000000000000000000..3eca384a67e533abc5a174389fb64803f50d9c58 GIT binary patch literal 402 zcmV;D0d4+?P)0lGmbmdGO=u1u9CSM(y((R0!gkM-ZNIsr})Eb0G8E_4=gys|TZ5+YlA3h`3_8jC8h34qsve}D;qB#Y+X1CV610dx`&M9ml? zi1azYAP|5xX8`3CSP1tt^xA>UEd*%yv z9Ug!+M*tAQ17PNx14QG9%o)H0LVifH%o$J%zyzy+ATs6m%vlA}RoD!mgz(y-|3@F+ wtTvR(NR6z}GLm~qHb?H!T(geZ^N}R>6AsUKg#KVwl>h($07*qoM6N<$f-yR+H2?qr literal 0 HcmV?d00001 diff --git a/Ratty/res/menu_icons_tree.png b/Ratty/res/gui_tree_icons.png similarity index 100% rename from Ratty/res/menu_icons_tree.png rename to Ratty/res/gui_tree_icons.png diff --git a/Ratty/res/language/lang.properties b/Ratty/res/language/lang.properties index 7a12641..3a65854 100644 --- a/Ratty/res/language/lang.properties +++ b/Ratty/res/language/lang.properties @@ -4,6 +4,10 @@ debug.client=Client server.port_question=Which port should the server be bind to? server.port_error=Invalid port. +server.free_warning=The client won't be available until the device restarts.\r\n\ +Continue? +server.free_yes=Yes +server.free_no=Cancel builder.address_question=Which address should the client connect to? builder.port_question=Which port? @@ -42,7 +46,7 @@ POPUP : Shows a popup on the client's device\r\n\ WEBSITE : Opens a website on the client's device\r\n\ \r\n\ : Either a number (the index) or an IP address\r\n\ -: A string +: A string surrounded by quotation marks cmd.start=Ratty command line tool\r\n\ Type 'HELP' to get a list of commands cmd.invalid=Invalid command or parameters diff --git a/Ratty/res/language/lang_de.properties b/Ratty/res/language/lang_de.properties index fda8edd..79c664a 100644 --- a/Ratty/res/language/lang_de.properties +++ b/Ratty/res/language/lang_de.properties @@ -4,6 +4,10 @@ debug.client=Client server.port_question=An welchen Port soll der Server gebunden werden? server.port_error=Ungültiger Port. +server.free_warning=Der Client wird bis zum Neustart des Gerätes nicht erreichbar sein.\r\n\ +Fortfahren? +server.free_yes=Ja +server.free_no=Abbrechen builder.address_question=Mit welcher Adresse soll sich der Client verbinden? builder.port_question=Welcher Port? @@ -42,7 +46,7 @@ POPUP : WEBSITE : Öffnet eine Webseite beim Client\r\n\ \r\n\ : Entweder eine Nummer (der Index) oder eine IP-Adresse\r\n\ -: Eine Zeichenkette +: Eine Zeichenkette in Anführungszeichen cmd.start=Ratty Kommandozeilen-Tool\r\n\ Gib 'HELP' für eine Listen von Befehlen ein cmd.invalid=Ungültiger Befehl oder Parameter diff --git a/Ratty/res/language/lang_en.properties b/Ratty/res/language/lang_en.properties index 7a12641..3a65854 100644 --- a/Ratty/res/language/lang_en.properties +++ b/Ratty/res/language/lang_en.properties @@ -4,6 +4,10 @@ debug.client=Client server.port_question=Which port should the server be bind to? server.port_error=Invalid port. +server.free_warning=The client won't be available until the device restarts.\r\n\ +Continue? +server.free_yes=Yes +server.free_no=Cancel builder.address_question=Which address should the client connect to? builder.port_question=Which port? @@ -42,7 +46,7 @@ POPUP : Shows a popup on the client's device\r\n\ WEBSITE : Opens a website on the client's device\r\n\ \r\n\ : Either a number (the index) or an IP address\r\n\ -: A string +: A string surrounded by quotation marks cmd.start=Ratty command line tool\r\n\ Type 'HELP' to get a list of commands cmd.invalid=Invalid command or parameters diff --git a/Ratty/src/de/sogomn/rat/GUISettings.java b/Ratty/src/de/sogomn/rat/GUISettings.java index 3aab890..dee4ee1 100644 --- a/Ratty/src/de/sogomn/rat/GUISettings.java +++ b/Ratty/src/de/sogomn/rat/GUISettings.java @@ -1,21 +1,39 @@ package de.sogomn.rat; import java.awt.Color; +import java.awt.Font; +import java.awt.image.BufferedImage; +import javax.swing.ImageIcon; import javax.swing.Painter; import javax.swing.UIDefaults; +import javax.swing.border.EmptyBorder; +import javax.swing.plaf.ColorUIResource; +import de.sogomn.engine.fx.SpriteSheet; +import de.sogomn.engine.util.ImageUtils; + +/* + * WHEEE! Hardcoding! + */ final class GUISettings { - private static final Color BACKGROUND = new Color(255, 245, 245); + private static final Color BACKGROUND = new Color(250, 250, 255); + private static final Color BASE = new Color(245, 205, 175); + private static final Color BRIGHTER = new Color(255, 220, 190); + private static final Color DARKER = new Color(225, 185, 155); + private static final Color ALTERNATIVE = new Color(245, 235, 215); + private static final Color SELECTION = new Color(225, 215, 195); + + private static final EmptyBorder TABLE_CELL_BORDER = new EmptyBorder(2, 5, 2, 5); - private static final Color BASE = new Color(240, 160, 100); - private static final Color BRIGHTER = new Color(250, 170, 110); - private static final Color DARKER = new Color(230, 150, 90); + private static final Font FONT = new Font("Trebuchet MS", Font.PLAIN, 12); - private static final Color ALTERNATIVE = new Color(255, 240, 220); - private static final Color ALTERNATIVE_DARKER = new Color(245, 230, 210); - private static final Color SELECTION = new Color(205, 170, 160); + private static final BufferedImage[] ICONS = new SpriteSheet("/gui_notification_icons.png", 16, 16).getSprites(); + private static final ImageIcon ERROR_ICON = new ImageIcon(ImageUtils.scaleImage(ICONS[0], 2)); + private static final ImageIcon INFORMATION_ICON = new ImageIcon(ImageUtils.scaleImage(ICONS[1], 2)); + private static final ImageIcon QUESTION_ICON = new ImageIcon(ImageUtils.scaleImage(ICONS[2], 2)); + private static final ImageIcon WARNING_ICON = new ImageIcon(ImageUtils.scaleImage(ICONS[3], 2)); private static final Painter BASE_PAINTER = (g, object, width, height) -> { g.setColor(BASE); @@ -66,9 +84,12 @@ final class GUISettings { defaults.put("ToggleButton[Pressed+Selected].backgroundPainter", DARKER_PAINTER); defaults.put("ToggleButton[Focused+Pressed+Selected].backgroundPainter", DARKER_PAINTER); + defaults.put("Table.background", new ColorUIResource(ALTERNATIVE)); defaults.put("Table:\"Table.cellRenderer\".background", ALTERNATIVE); - defaults.put("Table.alternateRowColor", ALTERNATIVE_DARKER); + defaults.put("Table.alternateRowColor", ALTERNATIVE); defaults.put("Table[Enabled+Selected].textBackground", SELECTION); + defaults.put("Table[Enabled+Selected].textForeground", Color.BLACK); + defaults.put("Table.focusCellHighlightBorder", TABLE_CELL_BORDER); defaults.put("TableHeader:\"TableHeader.renderer\"[Enabled].backgroundPainter", BASE_PAINTER); defaults.put("TableHeader:\"TableHeader.renderer\"[MouseOver].backgroundPainter", BASE_PAINTER); defaults.put("TableHeader:\"TableHeader.renderer\"[Enabled+Sorted].backgroundPainter", BASE_PAINTER); @@ -78,10 +99,31 @@ final class GUISettings { defaults.put("ScrollBar:ScrollBarTrack[Enabled].backgroundPainter", DARKER_PAINTER); defaults.put("ScrollBar:ScrollBarThumb[Enabled].backgroundPainter", BASE_PAINTER); defaults.put("ScrollBar:ScrollBarThumb[MouseOver].backgroundPainter", BRIGHTER_PAINTER); - defaults.put("ScrollBar:ScrollBarThumb[Pressed].backgroundPainter", BRIGHTER_PAINTER); + defaults.put("ScrollBar:ScrollBarThumb[Pressed].backgroundPainter", BASE_PAINTER); defaults.put("ScrollBar:\"ScrollBar.button\"[Enabled].foregroundPainter", BASE_PAINTER); defaults.put("ScrollBar:\"ScrollBar.button\"[MouseOver].foregroundPainter", BRIGHTER_PAINTER); - defaults.put("ScrollBar:\"ScrollBar.button\"[Pressed].foregroundPainter", BRIGHTER_PAINTER); + defaults.put("ScrollBar:\"ScrollBar.button\"[Pressed].foregroundPainter", BASE_PAINTER); + + defaults.put("Button.font", FONT); + defaults.put("Table.font", FONT); + defaults.put("Label.font", FONT); + defaults.put("TableHeader.font", FONT); + defaults.put("FileChooser.font", FONT); + defaults.put("TextField.font", FONT); + defaults.put("FormattedTextField.font", FONT); + defaults.put("PopupMenu.font", FONT); + defaults.put("Menu.font", FONT); + defaults.put("MenuItem.font", FONT); + defaults.put("Panel.font", FONT); + defaults.put("Tree.font", FONT); + defaults.put("ToggleButton.font", FONT); + defaults.put("List.font", FONT); + defaults.put("OptionPane.font", FONT); + + defaults.put("OptionPane.errorIcon", ERROR_ICON); + defaults.put("OptionPane.informationIcon", INFORMATION_ICON); + defaults.put("OptionPane.questionIcon", QUESTION_ICON); + defaults.put("OptionPane.warningIcon", WARNING_ICON); } } diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index 81b8d20..e53fd7c 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -183,7 +183,7 @@ public final class Ratty { if (port != -1) { startServer(port, true); } else { - JOptionPane.showMessageDialog(null, PORT_ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, PORT_ERROR_MESSAGE, null, JOptionPane.ERROR_MESSAGE); } } } diff --git a/Ratty/src/de/sogomn/rat/server/gui/FileTree.java b/Ratty/src/de/sogomn/rat/server/gui/FileTree.java index 7606d51..8579b29 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/FileTree.java +++ b/Ratty/src/de/sogomn/rat/server/gui/FileTree.java @@ -38,7 +38,7 @@ public final class FileTree extends AbstractListenerContainer { private static final String ROOT_NAME = ""; private static final Dimension DEFAULT_SIZE = new Dimension(500, 500); - private static final BufferedImage[] MENU_ICONS = new SpriteSheet(ImageUtils.scaleImage(ImageUtils.loadImage("/menu_icons_tree.png"), 2), 16 * 2, 16 * 2).getSprites(); + private static final BufferedImage[] MENU_ICONS = new SpriteSheet(ImageUtils.scaleImage(ImageUtils.loadImage("/gui_tree_icons.png"), 2), 16 * 2, 16 * 2).getSprites(); public static final String REQUEST = LANGUAGE.getString("action.request_files"); public static final String DOWNLOAD = LANGUAGE.getString("action.download"); diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java index b8d2cf6..c51d16a 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java @@ -25,6 +25,7 @@ import javax.swing.JOptionPane; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.ListSelectionModel; import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileNameExtensionFilter; @@ -51,11 +52,11 @@ final class RattyGui extends AbstractListenerContainer { private static final Dimension SIZE = new Dimension(800, 600); private static final BufferedImage GUI_ICON_SMALL = ImageUtils.loadImage("/gui_icon.png"); - private static final BufferedImage GUI_ICON_MEDIUM = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 64, 64); - private static final BufferedImage GUI_ICON_LARGE = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 128, 128); - private static final BufferedImage GUI_ICON_HUGE = ImageUtils.scaleImage(ImageUtils.loadImage("/gui_icon.png"), 128, 128); + private static final BufferedImage GUI_ICON_MEDIUM = ImageUtils.scaleImage(GUI_ICON_SMALL, 64, 64); + private static final BufferedImage GUI_ICON_LARGE = ImageUtils.scaleImage(GUI_ICON_SMALL, 128, 128); + private static final BufferedImage GUI_ICON_HUGE = ImageUtils.scaleImage(GUI_ICON_SMALL, 256, 256); private static final List GUI_ICONS = Arrays.asList(GUI_ICON_SMALL, GUI_ICON_MEDIUM, GUI_ICON_LARGE, GUI_ICON_HUGE); - private static final BufferedImage[] MENU_ICONS = new SpriteSheet(ImageUtils.scaleImage(ImageUtils.loadImage("/menu_icons.png"), 2), 16 * 2, 16 * 2).getSprites(); + private static final BufferedImage[] MENU_ICONS = new SpriteSheet(ImageUtils.scaleImage(ImageUtils.loadImage("/gui_menu_icons.png"), 2), 16 * 2, 16 * 2).getSprites(); public static final String POPUP = LANGUAGE.getString("action.popup"); public static final String SCREENSHOT = LANGUAGE.getString("action.screenshot"); @@ -122,6 +123,8 @@ final class RattyGui extends AbstractListenerContainer { table.setComponentPopupMenu(menu); table.addMouseListener(mouseAdapter); table.setModel(tableModel); + table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + table.setShowHorizontalLines(true); container.add(scrollPane, BorderLayout.CENTER); container.add(menuBar, BorderLayout.SOUTH); @@ -164,8 +167,14 @@ final class RattyGui extends AbstractListenerContainer { tableModel.removeServerClient(client); } + public int showWarning(final String message, final String... options) { + final int input = JOptionPane.showOptionDialog(frame, message, null, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, null); + + return input; + } + public void showMessage(final String message) { - final JOptionPane pane = new JOptionPane(message); + final JOptionPane pane = new JOptionPane(message, JOptionPane.INFORMATION_MESSAGE); final JDialog dialog = pane.createDialog(frame, null); dialog.setModal(false); diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java index c09b096..53eab5f 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java @@ -1,10 +1,14 @@ package de.sogomn.rat.server.gui; +import static de.sogomn.rat.Ratty.LANGUAGE; + import java.awt.image.BufferedImage; import java.io.File; import java.util.HashMap; import java.util.Set; +import javax.swing.JOptionPane; + import de.sogomn.engine.fx.Sound; import de.sogomn.rat.ActiveConnection; import de.sogomn.rat.builder.StubBuilder; @@ -38,6 +42,10 @@ public final class RattyGuiController extends AbstractRattyController implements private HashMap clients; + private static final String FREE_WARNING = LANGUAGE.getString("server.free_warning"); + private static final String FREE_OPTION_YES = LANGUAGE.getString("server.free_yes"); + private static final String FREE_OPTION_NO = LANGUAGE.getString("server.free_no"); + public RattyGuiController() { gui = new RattyGui(); clients = new HashMap(); @@ -154,6 +162,18 @@ public final class RattyGuiController extends AbstractRattyController implements return null; } + private FreePacket createFreePacket() { + final int input = gui.showWarning(FREE_WARNING, FREE_OPTION_YES, FREE_OPTION_NO); + + if (input == JOptionPane.YES_OPTION) { + final FreePacket packet = new FreePacket(); + + return packet; + } + + return null; + } + private void toggleDesktopStream(final ServerClient client) { final boolean streamingDesktop = client.isStreamingDesktop(); @@ -203,7 +223,7 @@ public final class RattyGuiController extends AbstractRattyController implements IPacket packet = null; if (command == RattyGui.FREE) { - packet = new FreePacket(); + packet = createFreePacket(); } else if (command == RattyGui.POPUP) { packet = createPopupPacket(); } else if (command == RattyGui.CLIPBOARD) {