Updated license info

This commit is contained in:
nathan 2015-08-19 02:25:38 +02:00
parent 01271e9e5d
commit 1607d0a087
3 changed files with 143 additions and 30 deletions

View File

@ -1,3 +1,18 @@
/*
* Copyright 2015 dorkbox, llc
*
* 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 dorkbox.util.javafx; package dorkbox.util.javafx;
import com.sun.javafx.application.PlatformImpl; import com.sun.javafx.application.PlatformImpl;
@ -23,6 +38,7 @@ import java.util.concurrent.CountDownLatch;
/** /**
* This class is necessary, because JavaFX stage is crap on linux. This offers sort-of the same functionality, but via swing instead. * This class is necessary, because JavaFX stage is crap on linux. This offers sort-of the same functionality, but via swing instead.
* Annoying caveat. All swing setters MUST happen on the EDT.
*/ */
public public
class StageViaSwing { class StageViaSwing {
@ -30,6 +46,9 @@ class StageViaSwing {
final JFXPanel panel; final JFXPanel panel;
private boolean inNestedEventLoop = false; private boolean inNestedEventLoop = false;
private final CountDownLatch showlatch = new CountDownLatch(1);
private final CountDownLatch showAndWaitlatch = new CountDownLatch(1);
final WritableValue<Float> opacityProperty; final WritableValue<Float> opacityProperty;
@ -69,6 +88,8 @@ class StageViaSwing {
}); });
} }
private boolean center = false;
private private
StageViaSwing() { StageViaSwing() {
@ -91,7 +112,7 @@ class StageViaSwing {
@Override @Override
public void setValue(Float value) { public void setValue(Float value) {
frame.setOpacity(value); SwingUtil.invokeLater(() -> frame.setOpacity(value));
} }
}; };
@ -106,13 +127,24 @@ class StageViaSwing {
Thread.sleep(500); Thread.sleep(500);
sizeToScene(); sizeToScene();
SwingUtil.showOnSameScreenAsMouseCenter(frame);
if (center) {
SwingUtil.invokeAndWait(() -> SwingUtil.showOnSameScreenAsMouseCenter(frame));
}
Timeline timeline = new Timeline(); Timeline timeline = new Timeline();
timeline.setCycleCount(1); timeline.setCycleCount(1);
timeline.getKeyFrames() timeline.getKeyFrames()
.addAll(new KeyFrame(Duration.millis(700), .addAll(new KeyFrame(Duration.millis(700),
new KeyValue(opacityProperty, 1F, Interpolator.EASE_OUT))); new KeyValue(opacityProperty, 1F, Interpolator.EASE_OUT)));
timeline.setOnFinished(event -> {
if (inNestedEventLoop) {
inNestedEventLoop= false;
com.sun.javafx.tk.Toolkit.getToolkit().exitNestedEventLoop(StageViaSwing.this, null);
} else {
showlatch.countDown();
}
});
timeline.play(); timeline.play();
} catch(InterruptedException ignored) { } catch(InterruptedException ignored) {
} }
@ -126,7 +158,7 @@ class StageViaSwing {
public public
void setTitle(final String title) { void setTitle(final String title) {
frame.setTitle(title); SwingUtil.invokeAndWait(() -> frame.setTitle(title));
} }
public public
@ -136,11 +168,12 @@ class StageViaSwing {
public public
void close() { void close() {
SwingUtil.invokeAndWait(() -> frame.dispose()); SwingUtil.invokeAndWait(frame::dispose);
if (inNestedEventLoop) { if (inNestedEventLoop) {
inNestedEventLoop= false;
com.sun.javafx.tk.Toolkit.getToolkit().exitNestedEventLoop(this, null); com.sun.javafx.tk.Toolkit.getToolkit().exitNestedEventLoop(this, null);
} else { } else {
latch.countDown(); showAndWaitlatch.countDown();
} }
} }
@ -159,9 +192,6 @@ class StageViaSwing {
SwingUtil.invokeAndWait(() -> frame.setIconImage(icon)); SwingUtil.invokeAndWait(() -> frame.setIconImage(icon));
} }
private final
CountDownLatch latch = new CountDownLatch(1);
public public
void show() { void show() {
SwingUtil.invokeAndWait(() -> { SwingUtil.invokeAndWait(() -> {
@ -179,18 +209,33 @@ class StageViaSwing {
sizeToScene(); sizeToScene();
SwingUtil.invokeAndWait(() -> frame.setVisible(true)); SwingUtil.invokeAndWait(() -> frame.setVisible(true));
// false-positive
//noinspection Duplicates
if (Platform.isFxApplicationThread()) {
inNestedEventLoop = true;
com.sun.javafx.tk.Toolkit.getToolkit().enterNestedEventLoop(this);
} else {
try {
showlatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} }
public public
void showAndWait() { void showAndWait() {
show(); show();
// false-positive
//noinspection Duplicates
if (Platform.isFxApplicationThread()) { if (Platform.isFxApplicationThread()) {
inNestedEventLoop = true; inNestedEventLoop = true;
com.sun.javafx.tk.Toolkit.getToolkit().enterNestedEventLoop(this); com.sun.javafx.tk.Toolkit.getToolkit().enterNestedEventLoop(this);
} else { } else {
try { try {
latch.await(); showAndWaitlatch.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -226,11 +271,7 @@ class StageViaSwing {
method.invoke(scene); method.invoke(scene);
// must be on the EDT // must be on the EDT
SwingUtil.invokeAndWait(() -> { SwingUtil.invokeAndWait(() -> frame.setSize((int)scene.getWidth(), (int)scene.getHeight()));
frame.setSize((int)scene.getWidth(), (int)scene.getHeight());
});
} catch (InvocationTargetException | IllegalAccessException e) { } catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -251,4 +292,24 @@ class StageViaSwing {
WritableValue<Float> getOpacityProperty() { WritableValue<Float> getOpacityProperty() {
return opacityProperty; return opacityProperty;
} }
public
void setLocation(final double anchorX, final double anchorY) {
SwingUtil.invokeAndWait(() -> frame.setLocation((int)anchorX, (int)anchorY));
}
public
Point getLocation() {
return frame.getLocation();
}
public
void center() {
this.center = true;
}
public
Dimension getSize() {
return frame.getSize();
}
} }

View File

@ -26,6 +26,19 @@
* *
* *
* MODIFIED BY DORKBOX * MODIFIED BY DORKBOX
* Copyright 2015 dorkbox, llc
*
* 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 dorkbox.util.javafx; package dorkbox.util.javafx;
@ -195,6 +208,8 @@ public class Wizard {
*/ */
public public
Wizard(String title) { Wizard(String title) {
stage.center();
stage.initModality(java.awt.Dialog.ModalExclusionType.APPLICATION_EXCLUDE); stage.initModality(java.awt.Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
setTitle(title); setTitle(title);
@ -656,8 +671,7 @@ public class Wizard {
.addAll(new KeyFrame(Duration.millis(200), .addAll(new KeyFrame(Duration.millis(200),
new KeyValue(stage.getOpacityProperty(), 0F, Interpolator.EASE_OUT))); new KeyValue(stage.getOpacityProperty(), 0F, Interpolator.EASE_OUT)));
timeline.setOnFinished(event -> { timeline.setOnFinished(event -> currentPage.ifPresent(currentPage -> {
currentPage.ifPresent(currentPage -> {
refreshCurrentPage(stage, currentPage); refreshCurrentPage(stage, currentPage);
SwingUtil.invokeAndWait(() -> SwingUtil.showOnSameScreenAsMouseCenter(stage.frame)); SwingUtil.invokeAndWait(() -> SwingUtil.showOnSameScreenAsMouseCenter(stage.frame));
@ -668,17 +682,14 @@ public class Wizard {
.addAll(new KeyFrame(Duration.millis(500), .addAll(new KeyFrame(Duration.millis(500),
new KeyValue(stage.getOpacityProperty(), 1F, Interpolator.EASE_OUT))); new KeyValue(stage.getOpacityProperty(), 1F, Interpolator.EASE_OUT)));
timeline2.play(); timeline2.play();
}); })
}
); );
sequentialTransition.getChildren().add(timeline); sequentialTransition.getChildren().add(timeline);
}); });
// only run this if we don't have a prev page, otherwise, we run this at the end of our animation // only run this if we don't have a prev page, otherwise, we run this at the end of our animation
if (!prevPage.isPresent()) { if (!prevPage.isPresent()) {
currentPage.ifPresent(currentPage -> { currentPage.ifPresent(currentPage -> refreshCurrentPage(stage, currentPage));
refreshCurrentPage(stage, currentPage);
});
} }
sequentialTransition.play(); sequentialTransition.play();

View File

@ -1,7 +1,48 @@
/**
* Copyright (c) 2014, 2015 ControlsFX
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of ControlsFX, any associated website, nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CONTROLSFX BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* MODIFIED BY DORKBOX
* Copyright 2015 dorkbox, llc
*
* 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 dorkbox.util.javafx; package dorkbox.util.javafx;
import dorkbox.util.JavaFxUtil; import dorkbox.util.JavaFxUtil;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty; import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;