Merge branch 'refactor-enzo' into refactor

This commit is contained in:
Chris Beams 2014-10-30 15:55:57 +01:00
commit 52a3d58493
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
11 changed files with 28 additions and 413 deletions

View File

@ -43,6 +43,7 @@ dependencies {
compile 'net.jcip:jcip-annotations:1.0'
compile 'org.jetbrains:annotations:13.0'
compile 'net.sourceforge.argparse4j:argparse4j:0.4.4'
compile 'eu.hansolo.enzo:Enzo:0.1.5'
testCompile 'junit:junit:4.11'
testCompile 'org.mockito:mockito-all:1.9.5'
}

View File

@ -1,88 +0,0 @@
/*
* Copyright (c) 2013 by Gerrit Grunwald
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.hansolo.enzo.notification;
/**
* Created by
* User: hansolo
* Date: 01.07.13
* Time: 07:10
*/
import java.util.Random;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
public class Demo extends Application {
private static final Random RND = new Random();
private static final Notification[] NOTIFICATIONS = {
NotificationBuilder.create().title("Info").message("New Information").image(Notification.INFO_ICON).build(),
NotificationBuilder.create().title("Warning").message("Attention, somethings wrong").image(Notification
.WARNING_ICON).build(),
NotificationBuilder.create().title("Success").message("Great it works").image(Notification.SUCCESS_ICON)
.build(),
NotificationBuilder.create().title("Error").message("ZOMG").image(Notification.ERROR_ICON).build()
};
private Notification.Notifier notifier;
private Button button;
// ******************** Initialization ************************************
@Override
public void init() {
button = new Button("Notify");
button.setOnAction(event -> {
notifier.notify(NOTIFICATIONS[RND.nextInt(4)]);
});
}
// ******************** Application start *********************************
@Override
public void start(Stage stage) {
notifier = NotifierBuilder.create()
//.popupLocation(Pos.BOTTOM_RIGHT)
.build();
notifier.setOnNotificationPressed(event -> System.out.println("Notification pressed: " + event.NOTIFICATION
.TITLE));
notifier.setOnShowNotification(event -> System.out.println("Notification shown: " + event.NOTIFICATION.TITLE));
notifier.setOnHideNotification(event -> System.out.println("Notification hidden: " + event.NOTIFICATION.TITLE));
StackPane pane = new StackPane();
pane.setPadding(new Insets(10, 10, 10, 10));
pane.getChildren().addAll(button);
Scene scene = new Scene(pane);
stage.setOnCloseRequest(observable -> notifier.stop());
stage.setScene(scene);
stage.show();
}
@Override
public void stop() {
}
public static void main(String[] args) {
launch(args);
}
}

View File

@ -44,10 +44,10 @@ import org.controlsfx.control.PopOver;
/**
* Created by
* User: hansolo
* Date: 01.07.13
* Time: 07:10
* A copy of the original {@link eu.hansolo.enzo.notification.Notification} class at revision eb1d321, containing
* several changes that were otherwise not possible through subclassing or other customization via the existing
* Notification API. See git history for this file for exact details as to what has been changed. All other
* {@code eu.hansolo.enzo.*} types are loaded from the enzo jar (see build.gradle for details).
*/
public class Notification {
public static final Image INFO_ICON = new Image(Notifier.class.getResourceAsStream("info.png"));
@ -112,13 +112,12 @@ public class Notification {
private void initGraphics() {
scene = new Scene(new Region());
scene.setFill(null);
// scene.getStylesheets().add(getClass().getResource("notifier.css").toExternalForm());
scene.getStylesheets().setAll(getClass().getResource("/io/bitsquare/gui/bitsquare.css").toExternalForm(),
scene.getStylesheets().setAll(
getClass().getResource("/io/bitsquare/gui/bitsquare.css").toExternalForm(),
getClass().getResource("/io/bitsquare/gui/images.css").toExternalForm());
stage = new Stage();
stage.initStyle(StageStyle.TRANSPARENT);
// stage.setAlwaysOnTop(true);
}
@ -314,54 +313,36 @@ public class Notification {
private void preOrder() {
if (popups.isEmpty()) return;
IntStream.range(0, popups.size()).parallel().forEachOrdered(
i -> {
Platform.runLater(() -> preOrderTask(i));
/* switch (popupLocation) {
case TOP_LEFT: case TOP_CENTER: case TOP_RIGHT:
popups.get(i).setY(popups.get(i).getY() + height + spacingY);
break;
case BOTTOM_LEFT: case BOTTOM_CENTER: case BOTTOM_RIGHT:
popups.get(i).setY(popups.get(i).getY() - height - spacingY);
break;
default:
popups.get(i).setY(popups.get(i).getY() - height - spacingY);
break;
} */
}
i -> Platform.runLater(() -> {
switch (popupLocation) {
case TOP_LEFT:
case TOP_CENTER:
case TOP_RIGHT:
popups.get(i).setY(popups.get(i).getY() + height + spacingY);
break;
case BOTTOM_LEFT:
case BOTTOM_CENTER:
case BOTTOM_RIGHT:
popups.get(i).setY(popups.get(i).getY() - height - spacingY);
break;
default:
popups.get(i).setY(popups.get(i).getY() - height - spacingY);
break;
}
})
);
}
private void preOrderTask(int i) {
switch (popupLocation) {
case TOP_LEFT:
case TOP_CENTER:
case TOP_RIGHT:
popups.get(i).setY(popups.get(i).getY() + height + spacingY);
break;
case BOTTOM_LEFT:
case BOTTOM_CENTER:
case BOTTOM_RIGHT:
popups.get(i).setY(popups.get(i).getY() - height - spacingY);
break;
default:
popups.get(i).setY(popups.get(i).getY() - height - spacingY);
break;
}
}
/**
* Creates and shows a popup with the data from the given Notification object
*
* @param NOTIFICATION
*/
private void showPopup(final Notification NOTIFICATION) {
ImageView icon = new ImageView(new Image(Notifier.class.getResourceAsStream("/images/notification_logo" +
".png")));
//icon.setId("notification-logo");
ImageView icon = new ImageView(
new Image(Notifier.class.getResourceAsStream("/images/notification_logo.png")));
icon.relocate(10, 7);
Label title = new Label(NOTIFICATION.TITLE);

View File

@ -1,84 +0,0 @@
/*
* Copyright (c) 2014 by Gerrit Grunwald
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.hansolo.enzo.notification;
import java.util.HashMap;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.image.*;
/**
* User: hansolo
* Date: 29.04.14
* Time: 08:53
*/
public class NotificationBuilder<B extends NotificationBuilder<B>> {
private HashMap<String, Property> properties = new HashMap<>();
// ******************** Constructors **************************************
protected NotificationBuilder() {
}
// ******************** Methods *******************************************
public final static NotificationBuilder create() {
return new NotificationBuilder();
}
public final B title(final String TITLE) {
properties.put("title", new SimpleStringProperty(TITLE));
return (B) this;
}
public final B message(final String MESSAGE) {
properties.put("message", new SimpleStringProperty(MESSAGE));
return (B) this;
}
public final B image(final Image IMAGE) {
properties.put("image", new SimpleObjectProperty<>(IMAGE));
return (B) this;
}
public final Notification build() {
final Notification NOTIFICATION;
if (properties.keySet().contains("title") && properties.keySet().contains("message") && properties.keySet()
.contains("image")) {
NOTIFICATION = new Notification(((StringProperty) properties.get("title")).get(),
((StringProperty) properties.get("message")).get(),
((ObjectProperty<Image>) properties.get("image")).get());
}
else if (properties.keySet().contains("title") && properties.keySet().contains("message")) {
NOTIFICATION = new Notification(((StringProperty) properties.get("title")).get(),
((StringProperty) properties.get("message")).get());
}
else if (properties.keySet().contains("message") && properties.keySet().contains("image")) {
NOTIFICATION = new Notification(((StringProperty) properties.get("message")).get(),
((ObjectProperty<Image>) properties.get("image")).get());
}
else {
throw new IllegalArgumentException("Wrong or missing parameters.");
}
return NOTIFICATION;
}
}

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) 2014 by Gerrit Grunwald
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.hansolo.enzo.notification;
import javafx.event.Event;
import javafx.event.EventTarget;
import javafx.event.EventType;
/**
* User: hansolo
* Date: 29.04.14
* Time: 10:03
*/
public class NotificationEvent extends Event {
public static final EventType<NotificationEvent> NOTIFICATION_PRESSED = new EventType(ANY, "NOTIFICATION_PRESSED");
public static final EventType<NotificationEvent> SHOW_NOTIFICATION = new EventType(ANY, "SHOW_NOTIFICATION");
public static final EventType<NotificationEvent> HIDE_NOTIFICATION = new EventType(ANY, "HIDE_NOTIFICATION");
public final Notification NOTIFICATION;
// ******************** Constructors **************************************
public NotificationEvent(final Notification NOTIFICATION, final Object SOURCE, final EventTarget TARGET,
EventType<NotificationEvent> TYPE) {
super(SOURCE, TARGET, TYPE);
this.NOTIFICATION = NOTIFICATION;
}
}

View File

@ -1,112 +0,0 @@
/*
* Copyright (c) 2014 by Gerrit Grunwald
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.hansolo.enzo.notification;
import java.util.HashMap;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.util.Duration;
/**
* User: hansolo
* Date: 29.04.14
* Time: 08:32
*/
public class NotifierBuilder<B extends NotifierBuilder<B>> {
private HashMap<String, Property> properties = new HashMap<>();
// ******************** Constructors **************************************
protected NotifierBuilder() {
}
// ******************** Methods *******************************************
public final static NotifierBuilder create() {
return new NotifierBuilder();
}
public final B owner(final Stage OWNER) {
properties.put("stage", new SimpleObjectProperty<>(OWNER));
return (B) this;
}
public final B popupLocation(Pos LOCATION) {
properties.put("popupLocation", new SimpleObjectProperty<>(LOCATION));
return (B) this;
}
public final B width(final double WIDTH) {
properties.put("width", new SimpleDoubleProperty(WIDTH));
return (B) this;
}
public final B height(final double HEIGHT) {
properties.put("height", new SimpleDoubleProperty(HEIGHT));
return (B) this;
}
public final B spacingY(final double SPACING_Y) {
properties.put("spacingY", new SimpleDoubleProperty(SPACING_Y));
return (B) this;
}
public final B popupLifeTime(final Duration POPUP_LIFETIME) {
properties.put("popupLifeTime", new SimpleObjectProperty<>(POPUP_LIFETIME));
return (B) this;
}
public final B popupAnimationTime(final Duration POPUP_ANIMATION_TIME) {
properties.put("popupAnimationTime", new SimpleObjectProperty<>(POPUP_ANIMATION_TIME));
return (B) this;
}
public final Notification.Notifier build() {
final Notification.Notifier NOTIFIER = Notification.Notifier.INSTANCE;
for (String key : properties.keySet()) {
if ("owner".equals(key)) {
NOTIFIER.setNotificationOwner(((ObjectProperty<Stage>) properties.get(key)).get());
}
else if ("popupLocation".equals(key)) {
NOTIFIER.setPopupLocation(null, ((ObjectProperty<Pos>) properties.get(key)).get());
}
else if ("width".equals(key)) {
NOTIFIER.setWidth(((DoubleProperty) properties.get(key)).get());
}
else if ("height".equals(key)) {
NOTIFIER.setHeight(((DoubleProperty) properties.get(key)).get());
}
else if ("spacingY".equals(key)) {
NOTIFIER.setSpacingY(((DoubleProperty) properties.get(key)).get());
}
else if ("popupLifeTime".equals(key)) {
NOTIFIER.setPopupLifetime(((ObjectProperty<Duration>) properties.get(key)).get());
}
else if ("popupAnimationTime".equals(key)) {
NOTIFIER.setPopupAnimationTime(((ObjectProperty<Duration>) properties.get(key)).get());
}
}
return NOTIFIER;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 810 B

View File

@ -1,40 +0,0 @@
/*
* Copyright (c) 2013 by Gerrit Grunwald
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
.root {
-fx-background-color: transparent;
-fx-fill : transparent;
}
.notification {
-fx-background-color : rgba(15, 15, 15, 0.8);
-fx-background-radius: 5;
-fx-effect : innershadow(two-pass-box, rgba(255, 255, 255, 0.6), 5.0, 0.25, 0, 0);
-foreground-color : white;
-icon-color : white;
}
.notification .title {
-fx-font-size : 1.083333em;
-fx-font-weight: bold;
-fx-text-fill : -foreground-color;
}
.notification .message {
-fx-font-size : 1.0em;
-fx-content-display : left;
-fx-graphic-text-gap: 10;
-fx-text-fill : -foreground-color;
}
*/

Binary file not shown.

Before

Width:  |  Height:  |  Size: 839 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 623 B