Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package app;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javafx.application.Application;
- import javafx.event.EventHandler;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.control.Tooltip;
- import javafx.scene.effect.Reflection;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- import javafx.scene.input.MouseEvent;
- import javafx.stage.Stage;
- import javafx.stage.StageStyle;
- /**
- *
- * @author Kalt Wulx
- */
- public class Dock extends Application {
- private ImageView fondo;
- private final Image fondoImg = new Image("fondos/fondo.png");
- private static final String OS = System.getProperty("os.name").toLowerCase();
- @Override
- public void start(final Stage stage) {
- stage.initStyle(StageStyle.TRANSPARENT);
- Group raiz = new Group();
- fondo = new ImageView(fondoImg);
- raiz.getChildren().add(fondo);
- calculadora(raiz);
- navegador(raiz);
- terminal(raiz);
- cerrar(raiz);
- draggDock(stage);
- Scene escena = new Scene(raiz, (int) fondoImg.getWidth(), (int) fondoImg.getHeight());
- escena.setFill(null);
- stage.setScene(escena);
- stage.centerOnScreen();
- stage.show();
- }
- private void draggDock(final Stage stage) {
- final Delta delta = new Delta();
- fondo.setOnMousePressed(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- delta.x = stage.getX() - t.getScreenX();
- delta.y = stage.getY() - t.getScreenY();
- }
- });
- fondo.setOnMouseDragged(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- stage.setX(t.getScreenX() + delta.x);
- stage.setY(t.getScreenY() + delta.y);
- }
- });
- }
- private void calculadora(Group raiz) {
- final ImageView icono = new ImageView(new Image("iconos/accessories-calculator.png"));
- icono.setCache(true);
- icono.setSmooth(true);
- Tooltip tip = new Tooltip("Calculadora");
- Tooltip.install(icono, tip);
- icono.setEffect(new Reflection());
- icono.setTranslateX(60 + 80 * 0);
- icono.setTranslateY(3);
- raiz.getChildren().add(icono);
- icono.setOnMouseEntered(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- icono.setScaleX(1.2);
- icono.setScaleY(1.2);
- }
- });
- icono.setOnMouseExited(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- icono.setScaleX(1);
- icono.setScaleY(1);
- }
- });
- icono.setOnMouseClicked(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- icono.setScaleX(0.7);
- icono.setScaleY(0.7);
- Process p = null;
- if(isMac()) {
- } else if(isWindows()) {
- } else if(isUnix()) {
- try {
- p = Runtime.getRuntime().exec("gcalctool");
- } catch (IOException ex) {
- Logger.getLogger(Dock.class.getName()).log(Level.SEVERE, null, ex);
- }
- } else if(isSolaris()) {
- }
- }
- });
- }
- private void navegador(Group raiz) {
- final ImageView icono = new ImageView(new Image("iconos/firefox-4.0.png"));
- Tooltip tip = new Tooltip("Navegador");
- icono.setCache(true);
- icono.setSmooth(true);
- Tooltip.install(icono, tip);
- icono.setEffect(new Reflection());
- icono.setTranslateX(60 + 80 * 1);
- icono.setTranslateY(3);
- raiz.getChildren().add(icono);
- icono.setOnMouseEntered(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- icono.setScaleX(1.2);
- icono.setScaleY(1.2);
- }
- });
- icono.setOnMouseExited(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- icono.setScaleX(1);
- icono.setScaleY(1);
- }
- });
- icono.setOnMouseClicked(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- icono.setScaleX(0.7);
- icono.setScaleY(0.7);
- Process p = null;
- if(isMac()) {
- } else if(isWindows()) {
- } else if(isUnix()) {
- try {
- p = Runtime.getRuntime().exec("firefox");
- } catch (IOException ex) {
- Logger.getLogger(Dock.class.getName()).log(Level.SEVERE, null, ex);
- }
- } else if(isSolaris()) {
- }
- }
- });
- }
- private void terminal(Group raiz) {
- final ImageView icono = new ImageView(new Image("iconos/bash.png"));
- icono.setCache(true);
- icono.setSmooth(true);
- Tooltip tip = new Tooltip("Terminal");
- Tooltip.install(icono, tip);
- icono.setEffect(new Reflection());
- icono.setTranslateX(60 + 80 * 2);
- icono.setTranslateY(3);
- raiz.getChildren().add(icono);
- icono.setOnMouseEntered(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- icono.setScaleX(1.2);
- icono.setScaleY(1.2);
- }
- });
- icono.setOnMouseExited(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- icono.setScaleX(1);
- icono.setScaleY(1);
- }
- });
- icono.setOnMouseClicked(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- icono.setScaleX(0.7);
- icono.setScaleY(0.7);
- Process p = null;
- if(isMac()) {
- } else if(isWindows()) {
- } else if(isUnix()) {
- try {
- p = Runtime.getRuntime().exec("pantheon-terminal");
- } catch (IOException ex) {
- Logger.getLogger(Dock.class.getName()).log(Level.SEVERE, null, ex);
- }
- } else if(isSolaris()) {
- }
- }
- });
- }
- private void cerrar(Group raiz) {
- final ImageView icono = new ImageView(new Image("iconos/boot.png"));
- icono.setCache(true);
- icono.setSmooth(true);
- Tooltip tip = new Tooltip("Cerrar");
- Tooltip.install(icono, tip);
- icono.setEffect(new Reflection());
- icono.setTranslateX(60 + 80 * 3);
- icono.setTranslateY(3);
- raiz.getChildren().add(icono);
- icono.setOnMouseEntered(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- icono.setScaleX(1.2);
- icono.setScaleY(1.2);
- }
- });
- icono.setOnMouseExited(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- icono.setScaleX(1);
- icono.setScaleY(1);
- }
- });
- icono.setOnMouseClicked(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- icono.setScaleX(0.7);
- icono.setScaleY(0.7);
- System.exit(0);
- }
- });
- }
- private static boolean isWindows() {
- return (OS.indexOf("win") >= 0);
- }
- private static boolean isMac() {
- return (OS.indexOf("mac") >= 0);
- }
- private static boolean isUnix() {
- return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0);
- }
- private static boolean isSolaris() {
- return (OS.indexOf("sunos") >= 0);
- }
- public static void main(String args[]) {
- Application.launch(args);
- }
- class Delta { double x, y; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement