Skip to content
Open

Dev #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions src/rsclient/coregui/RSClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
}
61 changes: 57 additions & 4 deletions src/rsclient/geguide/geGuidePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
24 changes: 21 additions & 3 deletions src/rsclient/toolbar/MainToolBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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");
}
}
37 changes: 37 additions & 0 deletions src/rsclient/toolbar/UTCClock.java
Original file line number Diff line number Diff line change
@@ -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);
}

}