From 141df6f553887076e7f6a8d24339499faa6c5283 Mon Sep 17 00:00:00 2001 From: Sennacherib Date: Sun, 26 Nov 2017 19:43:22 -0600 Subject: [PATCH 1/3] Add Fullscreen Button -Toggles hiding bottompanel and sidepanel --- src/rsclient/coregui/RSClient.java | 40 ++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/src/rsclient/coregui/RSClient.java b/src/rsclient/coregui/RSClient.java index d835cfa..5198df8 100755 --- a/src/rsclient/coregui/RSClient.java +++ b/src/rsclient/coregui/RSClient.java @@ -8,10 +8,13 @@ import java.awt.Color; import java.awt.Image; import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.ImageIcon; +import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JPanel; @@ -58,13 +61,13 @@ public static void initUI() { mainwnd.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - JPanel mainpanel = new JPanel(new MigLayout("fill, insets 5")); + final JPanel mainpanel = new JPanel(new MigLayout("fill, insets 5")); mainpanel.setBackground(Color.black); mainpanel.add(toolbar, "dock north, growx, gap 0"); toolbar.setVisible(true); - - mainwnd.getContentPane().add(mainpanel); - JPanel gamepanel = new JPanel(new MigLayout(" gap 0, ins 0 ")); + + mainwnd.getContentPane().add(mainpanel); + final JPanel gamepanel = new JPanel(new MigLayout(" gap 0, ins 0 ")); gamepanel.setBackground(Color.gray); boolean debug = false; @@ -73,8 +76,8 @@ public static void initUI() { mainpanel.add(gamepanel, "height 503:503,width 765:765, cell 0 0, growx, growy"); //height 503:503:503,width 765:765:765, gamepanel.setVisible(true); - JPanel sidepanel = new JPanel(new MigLayout("ins 0")); - JPanel bottompanel = new JPanel(new MigLayout("ins 0")); + final JPanel sidepanel = new JPanel(new MigLayout("ins 0")); + final JPanel bottompanel = new JPanel(new MigLayout("ins 0")); sidepanel.setBackground(Color.black); bottompanel.setBackground(Color.black); @@ -83,7 +86,17 @@ public static void initUI() { mainpanel.add(sidepanel, "width 250, height 503, cell 1 0,growy, spany, dock east "); mainpanel.add(bottompanel, "height 200, width 765,cell 0 1, growx, dock south"); - + final JButton fullScreen = new JButton("Fullscreen"); + fullScreen.addActionListener(new ActionListener(){ + boolean full = false; + @Override + public void actionPerformed(ActionEvent e){ + fullscreen(full, mainpanel, sidepanel, bottompanel, gamepanel); + full = !full; + } + }); + toolbar.add(fullScreen); + mainwnd.setVisible(true); mainwnd.pack(); @@ -116,4 +129,17 @@ public static void initUI() { } } + + + private static void fullscreen(boolean full, JPanel mainpanel, JPanel sidepanel, JPanel bottompanel, JPanel gamepanel){ + if(!full){ + mainpanel.remove(sidepanel); + mainpanel.remove(bottompanel); + } else { + mainpanel.add(sidepanel, "width 250, height 503, cell 1 0,growy, spany, dock east "); + mainpanel.add(bottompanel, "height 200, width 765,cell 0 1, growx, dock south"); + } + gamepanel.revalidate(); + gamepanel.repaint(); + } } From f260a4a64f737ff37f2ba08781c20b28f315d739 Mon Sep 17 00:00:00 2001 From: Sennacherib Date: Tue, 5 Dec 2017 22:23:17 -0600 Subject: [PATCH 2/3] Update geGuidePanel #1 - Add a small image of the chosen item to the panel --- src/rsclient/geguide/geGuidePanel.java | 61 ++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/src/rsclient/geguide/geGuidePanel.java b/src/rsclient/geguide/geGuidePanel.java index 9c33b22..63bd695 100644 --- a/src/rsclient/geguide/geGuidePanel.java +++ b/src/rsclient/geguide/geGuidePanel.java @@ -12,16 +12,20 @@ import java.awt.Color; import java.awt.Font; +import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.text.NumberFormat; +import javax.imageio.ImageIO; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -42,14 +46,20 @@ public class geGuidePanel extends JPanel { JLabel lowAlchLabel; JLabel highAlchLabel; JLabel updateLabel; + JLabel imageLabel; + BufferedImage image; + ImageIcon imageIcon; JButton searchButton; Timeline rolloverTimeline; boolean isValidItem; - static String baseURL = "http://oldschoolrunescape.wikia.com/wiki/Exchange:" ; + static String baseURL = "http://oldschoolrunescape.wikia.com/wiki/" ; URL itemURL; public geGuidePanel() { + image = null; + imageIcon = null; + imageLabel = new JLabel(); setLayout(new MigLayout("ins 5, center")); setBackground(Color.black); Border loweredbevel = BorderFactory.createEtchedBorder(EtchedBorder.RAISED); @@ -90,8 +100,9 @@ public geGuidePanel() { add(itemLabel, "cell 0 0, gap 0, align left"); add(searchButton, "cell 2 0,align right "); add(itemInputField, "width 60%, cell 1 0,align left,"); - + add(priceLabel, "newline, spanx"); + add(imageLabel, "cell 2 1, height :50, align right, spany 3"); add(lowAlchLabel, "newline, spanx"); add(highAlchLabel, "newline, spanx"); add(updateLabel, "newline, spanx"); @@ -126,7 +137,7 @@ public void mouseExited(MouseEvent e) { private void loadInfo(String item) throws IOException { BufferedReader in = null; try{ - itemURL = new URL(baseURL + item); + itemURL = new URL(baseURL + "Exchange:" + item); URLConnection yc = itemURL.openConnection(); in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; @@ -166,12 +177,54 @@ private void loadInfo(String item) throws IOException { in.close(); } } + if(isValidItem) { + loadimage(item); + } + } + + private void loadimage(String item) throws IOException{ + BufferedReader in = null; + String urlText = "https://ewebdesign.com/wp-content/uploads/2015/10/7-Flickering-404-Error-Page-by-Spiderone.jpg"; //404 not found image + + try{ + itemURL = new URL(baseURL + item); + URLConnection yc = itemURL.openConnection(); + in = new BufferedReader(new InputStreamReader(yc.getInputStream())); + String inputLine; + while ((inputLine = in.readLine()) != null) { + String[] tokens = inputLine.split("\""); + for(int i = 0; i < tokens.length; i++) { + if(tokens[i].contains("/" + item + ".png")){ + urlText = tokens[i]; + break; + } + } + } + + isValidItem = true; + } + catch(Exception e){} + finally { + if (in != null) { + in.close(); + } + } + + try{ + URL imageURL = new URL(urlText); + imageIcon = new ImageIcon(imageURL); + Image oldimg = imageIcon.getImage(); + Image newimg = oldimg.getScaledInstance(50, 50, java.awt.Image.SCALE_FAST); + imageIcon = new ImageIcon(newimg); + } catch(Exception e) {e.printStackTrace();} + imageLabel.setIcon(imageIcon); } private class ItemSearchListener implements ActionListener { @Override public void actionPerformed(ActionEvent ae) { - final String itemName = itemInputField.getText().replace(" ", "_"); + String formatter = itemInputField.getText().replace(" ", "_").toLowerCase(); //format request + final String itemName = formatter.substring(0, 1).toUpperCase() + formatter.substring(1); Runnable r1; r1 = new Runnable() { @Override From 471a80d111b7a447617c23669dbebb98853b1e5c Mon Sep 17 00:00:00 2001 From: Sennacherib Date: Wed, 6 Dec 2017 22:49:11 -0600 Subject: [PATCH 3/3] Add UTC Clock to MainToolBar - UTC clock helps players coordinate events across timezones --- src/rsclient/toolbar/MainToolBar.java | 24 ++++++++++++++--- src/rsclient/toolbar/UTCClock.java | 37 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/rsclient/toolbar/UTCClock.java diff --git a/src/rsclient/toolbar/MainToolBar.java b/src/rsclient/toolbar/MainToolBar.java index c822ba4..99b241b 100755 --- a/src/rsclient/toolbar/MainToolBar.java +++ b/src/rsclient/toolbar/MainToolBar.java @@ -6,8 +6,13 @@ package rsclient.toolbar; import java.awt.Color; +import java.awt.ComponentOrientation; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.time.Clock; +import javax.swing.JLabel; +import javax.swing.JPanel; + import javax.swing.JToolBar; import net.miginfocom.swing.MigLayout; @@ -17,8 +22,10 @@ */ public class MainToolBar extends JToolBar { + UTCClock clock; + public MainToolBar() { - setLayout(new MigLayout()); + setLayout(new MigLayout("fillx", "[shrink 10]")); setFloatable(false); setBackground(new Color(24, 24, 24)); setRollover(true); @@ -32,21 +39,32 @@ public MainToolBar() { final HelpMenu helpmenu = new HelpMenu(); linksButton.addMouseListener(new MouseAdapter() { + @Override public void mousePressed(MouseEvent e) { linksmenu.show(e.getComponent(), e.getX(), e.getY()); } }); helpButton.addMouseListener(new MouseAdapter() { + @Override public void mousePressed(MouseEvent e) { helpmenu.show(e.getComponent(), e.getX(), e.getY()); } }); - + + JPanel clockPanel = new JPanel(); + clockPanel.setBackground(Color.BLACK); + JLabel clockLabel = new JLabel(); + clock = new UTCClock(clockLabel); + clockLabel.setForeground(Color.white); + clockPanel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); + clockPanel.setLayout(new MigLayout()); + clockPanel.add(clockLabel); + add(optionsButton); add(linksButton); add(screenshotButton); add(helpButton); - + add(clockPanel, "pushx 10, growx, dock east"); } } diff --git a/src/rsclient/toolbar/UTCClock.java b/src/rsclient/toolbar/UTCClock.java new file mode 100644 index 0000000..e617bf1 --- /dev/null +++ b/src/rsclient/toolbar/UTCClock.java @@ -0,0 +1,37 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package rsclient.toolbar; + +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.util.TimerTask; +import java.util.Timer; +import java.time.ZoneId; +import javax.swing.JLabel; + +/** + * + * @author Adam + */ +class UTCClock { + + public UTCClock(JLabel clockLabel) { + final JLabel label = clockLabel; + final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("kk:mm:ss VV").withZone(ZoneId.of("UTC")); + Timer t; + t = new Timer(true); + t.scheduleAtFixedRate(new TimerTask() { + + @Override + public void run() { + + label.setText(LocalTime.now(ZoneId.of("UTC")).format(formatter)); + } + }, 0, 1000); + } + +}