Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
leosarra committed Oct 19, 2019
1 parent c3a8bc1 commit d5fd7b8
Show file tree
Hide file tree
Showing 10 changed files with 698 additions and 736 deletions.
47 changes: 26 additions & 21 deletions src/chooser/DirChooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
import java.util.logging.Logger;

public class DirChooser {
private JFileChooser f=new JFileChooser();
private boolean cancel=false;
private boolean fired=false;
private static Logger log = Logger.getLogger( CoreUpdater.class.getName() );
private JFileChooser f = new JFileChooser();
private boolean cancel = false;
private boolean fired = false;
private static Logger log = Logger.getLogger(CoreUpdater.class.getName());

public void execute() {
//Functor pattern
LauncherHelper.LogSetup(log,false);
//Functor pattern
LauncherHelper.LogSetup(log, false);
if (!fired) {
boolean found = false;
fired = true;
fired = true;
f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
f.setDialogTitle("Select Guild Wars 2 directory");
//Workaround to add an icon in the JFileChooser dialog
JFrame icon= new JFrame();
JFrame icon = new JFrame();
icon.setLocationRelativeTo(null);
icon.setUndecorated(true);
icon.setVisible(true);
Expand All @@ -36,17 +36,17 @@ public void execute() {
//Loop until "Cancel" is pressed or a valid directory is selected
while (!found) {
//int input = f.showDialog(icon, "Select");
int input = f.showDialog(icon, "Select");
int input = f.showDialog(icon, "Select");
if (input == JFileChooser.APPROVE_OPTION) {
File file = f.getSelectedFile();

boolean check = DirChooser.validDir(file.getAbsolutePath());
if (check) {
found = true;
log.log( Level.INFO,"Valid dir selected: "+file.getAbsolutePath());
log.log(Level.INFO, "Valid dir selected: " + file.getAbsolutePath());
changePathProp(file.getAbsolutePath());
} else {
log.log( Level.INFO,"Invalid dir selected: "+file.getAbsolutePath());
log.log(Level.INFO, "Invalid dir selected: " + file.getAbsolutePath());
JOptionPane.showMessageDialog(null, "Executable not found. Please select a valid directory", "Directory not valid", JOptionPane.ERROR_MESSAGE);
}

Expand All @@ -61,25 +61,30 @@ public void execute() {


//Check if a given path is a valid path for GW2
public static boolean validDir(String path){
boolean result=new File(path+"\\Gw2-64.exe").exists();
public static boolean validDir(String path) {
boolean result = new File(path + "\\Gw2-64.exe").exists();
return result;
}

//setter and getter required for the functor pattern
public boolean getCancel() { return cancel;}
public boolean getCancel() {
return cancel;
}

public JFileChooser getJFileChooser() { return f;}
public JFileChooser getJFileChooser() {
return f;
}

public boolean isFired() {
return fired;
}

public void changePathProp(String path){
public void changePathProp(String path) {
Properties prop = new Properties();
LauncherHelper.loadProp(prop,"gw2_launcher.cfg");
OutputStream output= null;
LauncherHelper.loadProp(prop, "gw2_launcher.cfg");
OutputStream output = null;
prop.put("path", path);
LauncherHelper.saveProp(prop,"gw2_launcher.cfg");
LauncherHelper.saveProp(prop, "gw2_launcher.cfg");

}
}
118 changes: 58 additions & 60 deletions src/frame/CoreFrame.java
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
package frame;

import javax.swing.*;

import listeners.MyActionListener;
import listeners.MyMouseListener;

import java.awt.*;
import java.io.File;

public class CoreFrame extends JFrame{
public class CoreFrame extends JFrame {

/**
*
*/
private static final long serialVersionUID = 1L;
public JButton startwith= new JButton("Run with ArcDPS");
private JButton startwithout= new JButton("Run only Gw2");
public JLabel status = new JLabel ("- Updater is starting...");

private JLabel path= new JLabel("- Guild Wars 2 executable found");
private JLabel arg=new JLabel("Arguments: ");
public JCheckBox autostart= new JCheckBox("Start with these settings each time (Fast-start)");
public JCheckBox background= new JCheckBox("Hide the GUI when fast-start is enabled ");
public JTextField arg_string=new JTextField(20);
private JButton arc= new JButton("Install ArcDPS");
*
*/
private static final long serialVersionUID = 1L;
public JButton startwith = new JButton("Run with ArcDPS");
private JButton startwithout = new JButton("Run only Gw2");
public JLabel status = new JLabel("- Updater is starting...");

private JLabel path = new JLabel("- Guild Wars 2 executable found");
private JLabel arg = new JLabel("Arguments: ");
public JCheckBox autostart = new JCheckBox("Start with these settings each time (Fast-start)");
public JCheckBox background = new JCheckBox("Hide the GUI when fast-start is enabled ");
public JTextField arg_string = new JTextField(20);
private JButton arc = new JButton("Install ArcDPS");
private String path_string;
private JButton me= new JButton("?");
private JButton me = new JButton("?");
private String mode;


public CoreFrame(String dir) {
super("Guild Wars 2 Launcher");
path_string = dir;


public CoreFrame(String dir){
super("Guild Wars 2 Launcher");
path_string=dir;

this.setIconImage(Toolkit.getDefaultToolkit().
getImage(CoreFrame.class.getResource("/gw2_64_1-1.png")));
getImage(CoreFrame.class.getResource("/gw2_64_1-1.png")));


//Settings of the CoreFrame object
this.setSize(345,381);
this.setSize(345, 381);
this.setVisible(true);
getContentPane().setLayout(new GridLayout(1,2));
getContentPane().setLayout(new GridLayout(1, 2));
this.setResizable(true);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setResizable(false);


//Default settings for some elements of the CoreFrame
arg_string.setText("Example: -autologin, -noaudio, -bmp ");
arg_string.setForeground(Color.GRAY);
status.setForeground(new Color(204,102,0));
arg_string.setSize(3,5);
path.setForeground(new Color(0,102,51));
status.setForeground(new Color(204, 102, 0));
arg_string.setSize(3, 5);
path.setForeground(new Color(0, 102, 51));

//Setting up the action commands to be used by the listeners
startwith.setActionCommand("with");
startwithout.setActionCommand("without");
background.setActionCommand("background");
arc.setActionCommand("arc");
//Create MyActionListener
MyActionListener mal= new MyActionListener(path_string,this);
MyActionListener mal = new MyActionListener(path_string, this);

//Add Listeners
arc.addActionListener(mal);
startwith.addActionListener(mal);
Expand All @@ -70,17 +70,17 @@ public CoreFrame(String dir){
arg_string.addMouseListener(new MyMouseListener(this));

//Creation of multiple JPanel
JPanel top =new JPanel (new GridLayout(2,1));
JPanel top = new JPanel(new GridLayout(2, 1));
JPanel bot = new JPanel(new FlowLayout());
JPanel mid= new JPanel();
JPanel sel=new JPanel((new FlowLayout(FlowLayout.LEADING)));
JPanel sel2=new JPanel((new FlowLayout(FlowLayout.LEADING)));
JPanel install=new JPanel(new FlowLayout());
JPanel settings=new JPanel(new GridLayout(5,1));
JPanel main1 =new JPanel (new BorderLayout());
JPanel about= new JPanel(new BorderLayout());
JPanel mid = new JPanel();
JPanel sel = new JPanel((new FlowLayout(FlowLayout.LEADING)));
JPanel sel2 = new JPanel((new FlowLayout(FlowLayout.LEADING)));
JPanel install = new JPanel(new FlowLayout());
JPanel settings = new JPanel(new GridLayout(5, 1));
JPanel main1 = new JPanel(new BorderLayout());
JPanel about = new JPanel(new BorderLayout());


sel.add(status);
sel2.add(path);
install.add(arc);
Expand All @@ -96,34 +96,30 @@ public CoreFrame(String dir){
bot.add(startwith);
bot.add(startwithout);
mid.add(about, BorderLayout.SOUTH);
about.add(me,BorderLayout.EAST);
about.add(me, BorderLayout.EAST);


main1.add(top,BorderLayout.NORTH);
main1.add(bot,BorderLayout.SOUTH);
main1.add(mid,BorderLayout.CENTER);
main1.add(top, BorderLayout.NORTH);
main1.add(bot, BorderLayout.SOUTH);
main1.add(mid, BorderLayout.CENTER);
getContentPane().add(main1);


//Creating borders
install.setBorder(BorderFactory.createTitledBorder("Setup"));
top.setBorder(BorderFactory.createTitledBorder("Status"));
settings.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Settings"),
BorderFactory.createEmptyBorder(5,5,5,5)));
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
me.setActionCommand("me");
me.addActionListener(mal);






}

public void setMode(String mode) {
this.mode=mode;
this.mode = mode;
switch (mode) {
case "none":
arc.setText("Install ArcDPS");
Expand All @@ -142,9 +138,11 @@ public void setMode(String mode) {
break;
}
}


public String getMode() { return mode;}


public String getMode() {
return mode;
}


}
59 changes: 27 additions & 32 deletions src/frame/FastFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,64 @@
import javax.swing.*;



import java.awt.*;
import java.io.File;


@SuppressWarnings("serial")
public class FastFrame extends JFrame{


private JButton startwith= new JButton("Run with ArcDPS");
private JButton startwithout= new JButton("Run only GW2 ");
public JLabel status = new JLabel ("- Updater is starting...");
private JLabel path= new JLabel("- Guild Wars 2 executable found");
private JLabel arg=new JLabel("Arguments: ");
private JCheckBox autostart= new JCheckBox("Start with these settings each time");
public JTextField arg_string=new JTextField(20);
private String path_string;
private JButton arc= new JButton("Install ArcDPS");
private String mode;
public class FastFrame extends JFrame {




private JButton startwith = new JButton("Run with ArcDPS");
private JButton startwithout = new JButton("Run only GW2 ");
public JLabel status = new JLabel("- Updater is starting...");
private JLabel path = new JLabel("- Guild Wars 2 executable found");
private JLabel arg = new JLabel("Arguments: ");
private JCheckBox autostart = new JCheckBox("Start with these settings each time");
public JTextField arg_string = new JTextField(20);
private String path_string;
private JButton arc = new JButton("Install ArcDPS");
private String mode;



public FastFrame(String dir, boolean hide){
public FastFrame(String dir, boolean hide) {
super("Guild Wars 2 Launcher");
//Settings of the FastFrame object

this.setIconImage(Toolkit.getDefaultToolkit().
getImage(CoreFrame.class.getResource("/img/gw2_64_1-1.png")));
getImage(CoreFrame.class.getResource("/img/gw2_64_1-1.png")));
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(310,160);
this.setSize(310, 160);
this.setResizable(false);

if (!hide) {
this.setVisible(true); //if background option is selected the frame will not show up
this.setVisible(true); //if background option is selected the frame will not show up
}

//JPanel setup
JPanel grid=new JPanel(new GridLayout(2,1));
JPanel grid = new JPanel(new GridLayout(2, 1));
grid.setBorder(BorderFactory.createTitledBorder("Status"));

//Color setup
status.setForeground(Color.orange);
path.setForeground(new Color(0, 102, 51));

//Add elements to the JPanel and FastFrame
getContentPane().add(grid);
grid.add(path);
grid.add(status);


}


public String getMode() {
return mode;
}


public String getMode() { return mode;}

public void setMode(String mode) {
this.mode=mode;
this.mode = mode;
switch (mode) {
case "none":
arc.setText("Install ArcDPS");
Expand All @@ -81,4 +75,5 @@ public void setMode(String mode) {
arc.setText("Install ArcDPS");
break;
}
}}
}
}
Loading

0 comments on commit d5fd7b8

Please sign in to comment.