UI icon updates

This commit is contained in:
Clisprail
2014-04-28 14:27:50 +02:00
parent 1f96eb6f29
commit f83acee021
4 changed files with 84 additions and 78 deletions
+29 -31
View File
@@ -1,21 +1,28 @@
package org.parabot.core.ui;
import org.parabot.core.Context;
import org.parabot.core.ui.components.GamePanel;
import org.parabot.core.ui.images.Images;
import org.parabot.environment.scripts.Script;
import javax.swing.*;
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import org.parabot.core.Context;
import org.parabot.core.ui.components.GamePanel;
import org.parabot.core.ui.images.Images;
import org.parabot.core.ui.utils.SwingUtil;
import org.parabot.environment.scripts.Script;
/**
*
@@ -43,25 +50,23 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
setTitle("Parabot");
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
/** Adds the dock icon to mac users */
try {
Class util = Class.forName("com.apple.eawt.Application");
Method getApplication = util.getMethod("getApplication", new Class[0]);
Object application = getApplication.invoke(util);
Class params[] = new Class[1];
params[0] = Image.class;
Method setDockIconImage = util.getMethod("setDockIconImage", params);
setDockIconImage.invoke(application, Images.getResource("/org/parabot/core/ui/images/icon.png"));
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
// Ignore for windows
}
createMenu();
setLayout(new BorderLayout());
addComponentListener(this);
addWindowListener(this);
add(GamePanel.getInstance());
GamePanel.getInstance().addLoader();
SwingUtil.setParabotIcons(this);
pack();
setLocationRelativeTo(null);
BotDialog.getInstance(this);
}
private void createMenu() {
JMenuBar menuBar = new JMenuBar();
JMenu file = new JMenu("File");
@@ -103,13 +108,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
menuBar.add(scripts);
setJMenuBar(menuBar);
add(GamePanel.getInstance());
GamePanel.getInstance().addLoader();
pack();
setLocationRelativeTo(null);
BotDialog.getInstance(this);
}
@Override
+20 -24
View File
@@ -1,21 +1,30 @@
package org.parabot.core.ui;
import org.parabot.core.Core;
import org.parabot.core.forum.AccountManager;
import org.parabot.core.forum.AccountManagerAccess;
import org.parabot.core.ui.images.Images;
import javax.swing.*;
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URI;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import org.parabot.core.Core;
import org.parabot.core.forum.AccountManager;
import org.parabot.core.forum.AccountManagerAccess;
import org.parabot.core.ui.images.Images;
import org.parabot.core.ui.utils.SwingUtil;
/**
*
* Users must login with their parabot account through this LoginUI class
@@ -80,21 +89,8 @@ public class LoginUI extends JFrame {
this.setLocationByPlatform(true);
this.setLayout(new BorderLayout());
this.setResizable(false);
this.setIconImage(Images
.getResource("/org/parabot/core/ui/images/icon.png"));
/** Adds the dock icon to mac users */
try {
Class util = Class.forName("com.apple.eawt.Application");
Method getApplication = util.getMethod("getApplication", new Class[0]);
Object application = getApplication.invoke(util);
Class params[] = new Class[1];
params[0] = Image.class;
Method setDockIconImage = util.getMethod("setDockIconImage", params);
setDockIconImage.invoke(application, Images.getResource("/org/parabot/core/ui/images/icon.png"));
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
// Ignore for windows
}
SwingUtil.setParabotIcons(this);
int w = 250;
int x = 8;
@@ -1,19 +1,20 @@
package org.parabot.core.ui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.LinkedList;
import java.util.Queue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import org.parabot.core.desc.ServerDescription;
import org.parabot.core.parsers.servers.ServerParser;
import org.parabot.core.ui.components.ServerComponent;
import org.parabot.core.ui.images.Images;
import org.parabot.core.ui.utils.SwingUtil;
import org.parabot.environment.Environment;
import javax.swing.*;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.Queue;
/**
*
* Shows a list of every supported server which can be started
@@ -49,20 +50,8 @@ public class ServerSelector extends JFrame {
this.setTitle("Servers");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
/** Adds the dock icon to mac users */
try {
Class util = Class.forName("com.apple.eawt.Application");
Method getApplication = util.getMethod("getApplication", new Class[0]);
Object application = getApplication.invoke(util);
Class params[] = new Class[1];
params[0] = Image.class;
Method setDockIconImage = util.getMethod("setDockIconImage", params);
setDockIconImage.invoke(application, Images.getResource("/org/parabot/core/ui/images/icon.png"));
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
// Ignore for windows
}
SwingUtil.setParabotIcons(this);
this.panel = new JPanel(new BorderLayout());
this.panel.setPreferredSize(new Dimension(600, 400));
@@ -103,7 +92,6 @@ public class ServerSelector extends JFrame {
* @param widgets
*/
private boolean runServer(Queue<ServerComponent> widgets) {
// TODO: test this method
if (widgets == null || widgets.isEmpty()) {
return false;
}
@@ -1,7 +1,14 @@
package org.parabot.core.ui.utils;
import java.awt.Image;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.swing.JFrame;
import org.parabot.core.ui.images.Images;
import org.parabot.environment.OperatingSystem;
/**
*
* Holds various swing util based methods
@@ -21,5 +28,22 @@ public class SwingUtil {
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void setParabotIcons(JFrame f) {
f.setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
if(OperatingSystem.getOS() == OperatingSystem.MAC) {
/** Adds the dock icon to mac users */
try {
Class<?> util = Class.forName("com.apple.eawt.Application");
Object application = util.getMethod("getApplication", new Class[] { }).invoke(null);
Method setDockIconImage = util.getMethod("setDockIconImage", new Class[] { Image.class });
setDockIconImage.invoke(application, Images.getResource("/org/parabot/core/ui/images/icon.png"));
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) {
} catch (Throwable t) {
t.printStackTrace();
}
}
}
}