Added dock icon support for mac users (working for windows this time)

This commit is contained in:
JKetelaar
2014-04-28 14:03:48 +02:00
parent f5e09e5631
commit 53325dc99d
5 changed files with 172 additions and 20 deletions
@@ -14,6 +14,8 @@ 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;
/**
*
@@ -42,6 +44,20 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
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
}
setLayout(new BorderLayout());
addComponentListener(this);
addWindowListener(this);
+24 -19
View File
@@ -1,29 +1,21 @@
package org.parabot.core.ui;
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.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 javax.swing.*;
import java.awt.*;
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;
/**
*
* Users must login with their parabot account through this LoginUI class
@@ -91,6 +83,19 @@ public class LoginUI extends JFrame {
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
}
int w = 250;
int x = 8;
int y = 64;
@@ -8,8 +8,9 @@ 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;
@@ -50,6 +51,19 @@ public class ServerSelector extends JFrame {
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
}
this.panel = new JPanel(new BorderLayout());
this.panel.setPreferredSize(new Dimension(600, 400));
@@ -0,0 +1,67 @@
package org.parabot.environment.scripts;
import java.util.Collection;
import org.parabot.environment.scripts.framework.AbstractFramework;
import org.parabot.environment.scripts.framework.LoopTask;
import org.parabot.environment.scripts.framework.Strategy;
/**
*
* Holds various script frameworks
*
* @author Everel
*
*/
public class Frameworks {
public static Looper getLooper(LoopTask loopTask) {
return new Looper(loopTask);
}
public static StrategyWorker getStrategyWorker(Collection<Strategy> strategies) {
return new StrategyWorker(strategies);
}
}
class Looper extends AbstractFramework {
private LoopTask loopTask = null;
public Looper(LoopTask loopTask) {
this.loopTask = loopTask;
}
@Override
public boolean execute() {
int sleepTime = loopTask.loop();
if(sleepTime < 0) {
return false;
}
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
return true;
}
}
class StrategyWorker extends AbstractFramework {
private Collection<Strategy> strategies;
public StrategyWorker(Collection<Strategy> strategies) {
this.strategies = strategies;
}
@Override
public boolean execute() {
for(Strategy s : strategies) {
if(s.activate()) {
s.execute();
return true;
}
}
return true;
}
}
@@ -0,0 +1,50 @@
package org.parabot.environment.servers;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.build.BuildPath;
import org.parabot.core.classpath.ClassPath;
import org.parabot.environment.servers.executers.ServerExecuter;
import java.net.MalformedURLException;
/**
*
* Loads locally stored server providers
*
* @author Everel
*
*/
public class LocalServerExecuter extends ServerExecuter {
private final ServerProvider serverProvider;
private ClassPath classPath;
private String serverName;
public LocalServerExecuter(ServerProvider serverProvider,
ClassPath classPath, final String serverName) {
this.serverProvider = serverProvider;
this.classPath = classPath;
this.serverName = serverName;
}
@Override
public void run() {
// add jar or directory to buildpath.
if (this.classPath.isJar()) {
Core.verbose("Adding server provider jar to buildpath: "
+ this.classPath.lastParsed.toString());
this.classPath.addToBuildPath();
} else {
Core.verbose("Adding server providers directory to buildpath: "
+ Directories.getServerPath().getPath());
try {
BuildPath.add(Directories.getServerPath().toURI().toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
// finalize
super.finalize(this.serverProvider, this.serverName);
}
}