[FEATURE] Finished notifications system

This commit is contained in:
JKetelaar
2017-02-07 00:32:50 +01:00
parent 0bb3e9b7dd
commit bff0bfbe6a
10 changed files with 147 additions and 151 deletions
+1 -1
View File
@@ -73,7 +73,7 @@
<dependency>
<groupId>org.parabot</groupId>
<artifactId>internal-api</artifactId>
<version>1.4.5.1</version>
<version>1.51.1</version>
</dependency>
</dependencies>
@@ -1,9 +1,5 @@
package org.parabot.core.build;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
/**
*
* Class used for adding urls to the buildpath
@@ -11,16 +7,6 @@ import java.net.URLClassLoader;
* @author Everel
*
*/
public class BuildPath {
public static void add(final URL url) {
try {
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
method.setAccessible(true);
method.invoke((URLClassLoader) ClassLoader.getSystemClassLoader(), url);
} catch (Exception e) {
e.printStackTrace();
}
}
public class BuildPath extends org.parabot.api.io.build.BuildPath {
}
@@ -1,67 +1,10 @@
package org.parabot.core.lib;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
/**
*
* @author Everel
*
*/
public abstract class Library {
/**
* Determines if this library jar has already been downloaded.
* @return <b>false</b> if library jar has not been downloaded, otherwise <b>true</b>
*/
public boolean hasJar() {
return getJarFile().exists();
}
/**
* Adds the library to the buildpath and validates if it has been added
*/
public abstract void init();
/**
* Determines if library has been added to the buildpath
* @return <b>true</b> if library has been added to the buildpath, otherwise <b>false</b>.
*/
public abstract boolean isAdded();
/**
* Gets the local file target/location of the jar file
* @return local file (target) to library
*/
public abstract File getJarFile();
/**
* Gets download url to the library
* @return url
*/
public abstract URL getDownloadLink();
/**
* Defines if the system requires a jar
* @return boolean
*/
public abstract boolean requiresJar();
/**
* Fetches URL from {@link Library#getJarFile()}
* @return URL to local library jar file
*/
public URL getJarFileURL() {
try {
return getJarFile().toURI().toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
public abstract String getLibraryName();
public abstract class Library extends org.parabot.api.io.libraries.Library {
}
@@ -1,72 +0,0 @@
package org.parabot.core.lib.jpushbullet;
import org.parabot.core.Configuration;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.build.BuildPath;
import org.parabot.core.lib.Library;
import java.io.File;
import java.net.URL;
/**
* @author EmmaStone
*/
public class JPushBullet extends Library {
private static boolean valid;
@Override
public void init() {
if (!hasJar()) {
System.err.println("Failed to load jpushbullet... [jar missing]");
return;
}
Core.verbose("Adding jpushbullet jar file to build path: "
+ getJarFileURL().getPath());
BuildPath.add(getJarFileURL());
try {
Class.forName("com.shakethat.jpushbullet.net.PushbulletClient");
valid = true;
} catch (ClassNotFoundException e) {
System.err
.println("Failed to add jpushbullet to build path, or incorrupt download");
}
Core.verbose("JPushBullet initialized.");
}
@Override
public boolean isAdded() {
return valid;
}
@Override
public File getJarFile() {
return new File(Directories.getCachePath(), "jpushbullet.jar");
}
@Override
public URL getDownloadLink() {
try {
return new URL(Configuration.LIBRARIES_DOWNLOAD + "/JPushBullet");
} catch (Throwable t) {
t.printStackTrace();
}
return null;
}
@Override
public boolean requiresJar() {
return true;
}
@Override
public String getLibraryName() {
return "JPushBullet";
}
public static boolean isValid() {
return valid;
}
}
@@ -1,10 +1,12 @@
package org.parabot.core.ui;
import javafx.application.Application;
import org.parabot.core.Configuration;
import org.parabot.core.Context;
import org.parabot.core.Directories;
import org.parabot.core.ui.components.GamePanel;
import org.parabot.core.ui.components.VerboseLoader;
import org.parabot.core.ui.components.notifications.NotificationUI;
import org.parabot.core.ui.images.Images;
import org.parabot.core.ui.utils.SwingUtil;
import org.parabot.environment.OperatingSystem;
@@ -105,6 +107,9 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
JMenuItem cacheClear = new JMenuItem("Clear cache");
cacheClear.setIcon(new ImageIcon(Images.getResource("/storage/images/trash.png")));
JMenuItem notifications = new JMenuItem("Notifications");
notifications.setIcon(new ImageIcon(Images.getResource("/storage/images/bell.png")));
screenshot.addActionListener(this);
proxy.addActionListener(this);
randoms.addActionListener(this);
@@ -113,6 +118,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
explorer.addActionListener(this);
exit.addActionListener(this);
cacheClear.addActionListener(this);
notifications.addActionListener(this);
run.addActionListener(this);
pause.addActionListener(this);
@@ -131,6 +137,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
scripts.add(stop);
features.add(cacheClear);
features.add(notifications);
menuBar.add(file);
menuBar.add(scripts);
@@ -237,6 +244,9 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
case "Clear cache":
Directories.clearCache();
break;
case "Notifications":
Application.launch(NotificationUI.class);
break;
default:
System.out.println("Invalid command: " + command);
}
@@ -0,0 +1,20 @@
package org.parabot.core.ui.components.notifications;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import org.parabot.core.Configuration;
public class NotificationUI extends Application {
@Override
public void start(Stage stage) throws Exception {
//noinspection RedundantCast
BorderPane root = (BorderPane) FXMLLoader.load(this.getClass().getResource("/storage/ui/notifications.fxml"));
stage.setTitle(Configuration.BOT_TITLE);
stage.setScene(new Scene(root));
stage.show();
}
}
@@ -0,0 +1,72 @@
package org.parabot.core.ui.components.notifications;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ListView;
import javafx.stage.Stage;
import org.parabot.api.notifications.NotificationManager;
import org.parabot.api.notifications.types.NotificationType;
import java.net.URL;
import java.util.ResourceBundle;
/**
* @author JKetelaar
*/
public class NotificationUIController implements Initializable {
@FXML // fx:id="availableTypes"
private ListView availableTypes;
@FXML // fx:id="enabledTypes"
private ListView enabledTypes;
@Override
public void initialize(URL location, ResourceBundle resources) {
this.refreshTypes();
}
private void refreshTypes() {
availableTypes.getItems().clear();
for (NotificationType notificationType : NotificationManager.getContext().getAvailableNotificationTypes()) {
availableTypes.getItems().add(notificationType.getName());
}
enabledTypes.getItems().clear();
for (NotificationType notificationType : NotificationManager.getContext().getEnabledTypes()) {
enabledTypes.getItems().add(notificationType.getName());
}
}
@FXML
private void enableType() {
Object object = availableTypes.getSelectionModel().getSelectedItem();
if (object != null) {
String name = (String) object;
NotificationType type = NotificationManager.getContext().getNotificationType(name);
NotificationManager.getContext().enableNotificationType(type);
this.refreshTypes();
}
}
@FXML
private void disableType() {
Object object = enabledTypes.getSelectionModel().getSelectedItem();
if (object != null) {
String name = (String) object;
NotificationType type = NotificationManager.getContext().getNotificationType(name);
NotificationManager.getContext().disableNotificationType(type);
this.refreshTypes();
}
}
@FXML
private void save() {
Stage stage = (Stage) this.enabledTypes.getScene().getWindow();
stage.close();
}
}
@@ -16,7 +16,13 @@ import java.util.LinkedList;
*
* @author Everel, JKetelaar
*/
public class Environment {
public class Environment extends org.parabot.api.io.libraries.Environment {
private static LinkedList<Library> libs = new LinkedList<>();
static {
libs.add(new JavaFX());
}
/**
* Loads a new environment
@@ -24,10 +30,6 @@ public class Environment {
* @param desc
*/
public static void load(final ServerDescription desc) {
LinkedList<Library> libs = new LinkedList<>();
libs.add(new JavaFX());
for (Library lib : libs) {
loadLibrary(lib, true);
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="231.0"
prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="org.parabot.core.ui.components.notifications.NotificationUIController">
<bottom>
<Button mnemonicParsing="false" text="Save" BorderPane.alignment="CENTER" onAction="#save">
<BorderPane.margin>
<Insets bottom="10.0" top="10.0"/>
</BorderPane.margin>
</Button>
</bottom>
<left>
<ListView fx:id="availableTypes" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER"/>
</left>
<right>
<ListView fx:id="enabledTypes" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER"/>
</right>
<center>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<Button mnemonicParsing="false" onAction="#enableType" text="&gt;&gt;"/>
<Separator orientation="VERTICAL" prefHeight="40.0" prefWidth="0.0" visible="false"/>
<Button mnemonicParsing="false" onAction="#disableType" text="&lt;&lt;"/>
</children>
</VBox>
</center>
<top>
<Separator orientation="VERTICAL" prefHeight="7.0" prefWidth="15.0" visible="false"
BorderPane.alignment="CENTER"/>
</top>
</BorderPane>