Skip to content

Commit

Permalink
Merge branch 'master' into java7
Browse files Browse the repository at this point in the history
Conflicts:
	fx-onscreen-keyboard/pom.xml
  • Loading branch information
comtel committed Jan 19, 2014
2 parents ae81150 + 52dd33c commit 4893df6
Show file tree
Hide file tree
Showing 8 changed files with 591 additions and 85 deletions.
1 change: 1 addition & 0 deletions fx-onscreen-keyboard/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.project
/.classpath
/.settings
/launch_jre7.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
package org.comtel.javafx;

import java.awt.BorderLayout;
import java.awt.Point;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.ParseException;
import java.util.Locale;

import javafx.animation.Animation;
import javafx.animation.FadeTransition;
import javafx.animation.Transition;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.util.Duration;

import javax.swing.JApplet;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;

import org.comtel.javafx.control.KeyBoardPopup;
import org.comtel.javafx.control.KeyBoardPopupBuilder;
import org.comtel.javafx.robot.RobotFactory;
import org.slf4j.LoggerFactory;


public class AwtStandAloneApp extends JApplet {

private final static org.slf4j.Logger logger = LoggerFactory.getLogger(AwtStandAloneApp.class);

private static Locale locale;
private static String xmlPath = "/xml/numblock";
private static int posX = 100;
private static int posY = 100;

private static final long serialVersionUID = 1L;

private KeyBoardPopup fxKeyboardPopup;
private Transition transition;

public AwtStandAloneApp() {
}

public void init() {

String fontUrl = this.getClass().getResource("/font/FontKeyboardFX.ttf").toExternalForm();
Font.loadFont(fontUrl, -1);

setLayout(new BorderLayout());

// create javafx panel
final JFXPanel javafxPanel = new JFXPanel();
javafxPanel.setFocusable(false);
javafxPanel.setOpaque(false);

add(javafxPanel, BorderLayout.CENTER);

JWindow fxKeyboard = new JWindow();
fxKeyboard.setModalExclusionType(java.awt.Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
fxKeyboard.getContentPane().add(javafxPanel);
fxKeyboard.setFocusable(false);
fxKeyboard.setBackground(null);

fxKeyboard.pack();
fxKeyboard.setLocationByPlatform(true);

// create JavaFX scene
Platform.runLater(new Runnable() {
public void run() {
createScene(javafxPanel);
}
});

}

public void createScene(JFXPanel javafxPanel) {

Scene scene = new Scene(new Group(), 0, 0);

javafxPanel.setScene(scene);
scene.getStylesheets().add(this.getClass().getResource("/css/KeyboardButtonStyle.css").toExternalForm());

Path path = null;
try {
if (xmlPath != null && !xmlPath.isEmpty()){
path = Paths.get(this.getClass().getResource(xmlPath).toURI());
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}

fxKeyboardPopup = KeyBoardPopupBuilder.create().initLocale(locale != null ? locale : Locale.getDefault()).addIRobot(RobotFactory.createNativeAsciiRobot()).layerPath(path).build();
fxKeyboardPopup.getKeyBoard().setOnKeyboardCloseButton(new EventHandler<Event>() {
public void handle(Event event) {
System.exit(0);
// setKeyboardVisible(false, null);
}
});
fxKeyboardPopup.setOwner(scene);
setKeyboardVisible(true, new Point(posX, posY));
}

public void setKeyboardVisible(boolean flag, Point point) {
final boolean visible = flag;
final Point location = point;
Platform.runLater(new Runnable() {
public void run() {
if (fxKeyboardPopup == null) {
return;
}
if (location != null) {
fxKeyboardPopup.setX(location.getX());
fxKeyboardPopup.setY(location.getY());
}

if (transition == null) {
transition = new FadeTransition(Duration.seconds(0.1), fxKeyboardPopup.getKeyBoard());
}
if (visible) {
if (fxKeyboardPopup.isVisible() && transition.getStatus() == Animation.Status.STOPPED) {
return;
}
transition.stop();
transition.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
}
});

fxKeyboardPopup.getKeyBoard().setOpacity(0.0);
fxKeyboardPopup.setVisible(true);
((FadeTransition) transition).setFromValue(0.0f);
((FadeTransition) transition).setToValue(1.0f);
transition.play();

} else {
if (!fxKeyboardPopup.isVisible() && transition.getStatus() == Animation.Status.STOPPED) {
return;
}
transition.stop();
transition.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
fxKeyboardPopup.setVisible(false);
}
});

((FadeTransition) transition).setFromValue(1.0f);
((FadeTransition) transition).setToValue(0.0f);
transition.play();

}
}
});
}

private static void showHelp() {
System.out.println();
System.out.println("\t-lang <locale>\t\tsetting keyboard language (en,de,ru,..)");
System.out.println("\t-layout <path>\t\tpath to custom layout xml");
System.out.println("\t-pos <x,y>\t\tinitial keyboard position");
System.out.println("\t-help\t\t\tthis help screen");
}

private static void parseLocale(String l) throws Exception{
if (l == null || l.isEmpty()) {
throw new ParseException("invalid locale", 0);
}

String[] lang = l.split("_");
if (lang.length == 2) {
locale = new Locale(lang[0], lang[1]);
} else if (lang.length == 1) {
locale = Locale.forLanguageTag(l);
}
}

private static void parsePosition(String p) throws Exception {
if (p == null || p.isEmpty()) {
throw new ParseException("invalid position", 0);
}

String[] pos = p.split(",");
if (pos.length == 2) {
posX = Integer.valueOf(pos[0]);
posY = Integer.valueOf(pos[1]);
}
}

public static void main(String[] args) {

try {
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-lang")) {
parseLocale(args[++i]);
} else if (args[i].equals("-layout")) {
xmlPath = args[++i];
} else if (args[i].equals("-pos")) {
parsePosition(args[++i]);
} else {
showHelp();
return;
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
showHelp();
return;
}

SwingUtilities.invokeLater(new Runnable() {

public void run() {
JApplet applet = new AwtStandAloneApp();
applet.init();
applet.start();
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.comtel.javafx;

import java.util.Locale;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;

import org.comtel.javafx.control.KeyBoardPopup;
import org.comtel.javafx.control.KeyBoardPopupBuilder;
import org.comtel.javafx.robot.RobotFactory;

public class FxStandAloneApp extends Application {

private int posX = 0;
private int posY = 0;

@Override
public void start(Stage stage) {

stage.setTitle("FX Keyboard (" + System.getProperty("javafx.runtime.version") + ")");
stage.setResizable(false);
stage.initStyle(StageStyle.UNDECORATED);

String fontUrl = this.getClass().getResource("/font/FontKeyboardFX.ttf").toExternalForm();
Font.loadFont(fontUrl, -1);

final KeyBoardPopup popup = KeyBoardPopupBuilder.create().initScale(1.0).initLocale(Locale.ENGLISH).addIRobot(RobotFactory.createNativeAsciiRobot()).build();

Scene scene = new Scene(new Group(), 1, 1);
popup.setOwner(scene);

scene.getStylesheets().add(this.getClass().getResource("/css/KeyboardButtonStyle.css").toExternalForm());

stage.setOnCloseRequest(new EventHandler<WindowEvent>() {

public void handle(WindowEvent event) {
System.exit(0);
}
});
stage.setScene(scene);
stage.show();

popup.getScene().getWindow().setX(posX);
popup.getScene().getWindow().setY(posY);

popup.show(stage);

}

public static void main(String[] args) {
Application.launch(args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ private Region createKeyboardPane(Keyboard layout) {

@Override
public void handle(MouseEvent event) {
//on Double.isNaN(getScene().getWindow().getX()) init window position
mousePressedX = getScene().getWindow().getX() - event.getScreenX();
mousePressedY = getScene().getWindow().getY() - event.getScreenY();
}
Expand All @@ -438,7 +439,6 @@ public void handle(MouseEvent event) {
button.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {

getScene().getWindow().setX(mouseEvent.getScreenX() + mousePressedX);
getScene().getWindow().setY(mouseEvent.getScreenY() + mousePressedY);

Expand All @@ -465,14 +465,14 @@ public void handle(Event e) {
colIdx++;
rowWidth += cc.getPrefWidth();
}
logger.info("row[{}] - {}", rowIdx, rowWidth);
logger.trace("row[{}] - {}", rowIdx, rowWidth);
colPane.getRowConstraints().add(rc);
// colPane.setGridLinesVisible(true);
rPane.add(colPane, 0, rowIdx);
rowIdx++;
}

logger.debug("-----end pane-----");
logger.trace("-----end pane-----");
return rPane;
}

Expand Down
Loading

0 comments on commit 4893df6

Please sign in to comment.