/*
 * The MIT License
 *
 * Copyright 2014-2015 TweetWallFX
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.tweetwallfx.generic;

import javafx.application.Application;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.tweetwallfx.config.Configuration;
import org.tweetwallfx.tweet.StopList;
import org.tweetwallfx.tweet.StringPropertyAppender;
import org.tweetwallfx.tweet.api.Tweeter;
import org.tweetwallfx.twod.TagTweets;
import org.tweetwallfx.tweet.TweetSetData;

/**
 * @author martin
 */
public class Main extends Application {

    private static final String STARTUP = "org.tweetwallfx.startup";
    Logger startupLogger = Logger.getLogger(STARTUP);
    
    private static final String query = Configuration.getInstance().getConfig("tweetwall.twitter.query");
    private static final String title = Configuration.getInstance().getConfig("tweetwall.title");
    private static final String stylesheet = Configuration.getInstance().getConfig("tweetwall.stylesheet", null);
    private Tweeter tweeter;
    private TagTweets tweetsTask;

    @Override
    public void start(Stage primaryStage) {
        BorderPane borderPane = new BorderPane();
        Scene scene = new Scene(borderPane, 800, 600);
        StopList.add(query);
        startupLogger.addAppender(new StringPropertyAppender());
        startupLogger.setLevel(Level.TRACE);

        HBox statusLineHost = new HBox();
        Text statusLineText = new Text();
        statusLineText.getStyleClass().addAll("statusline");
        statusLineText.textProperty().bind(((StringPropertyAppender)startupLogger.getAppender(StringPropertyAppender.class.getName())).stringProperty());
        statusLineHost.getChildren().add(statusLineText);
        borderPane.setBottom(statusLineHost);
        
        final Service<Void> service = new Service<Void>() {
            @Override
            protected Task<Void> createTask() {
                Task<Void> task = new Task<Void>() {
                    @Override
                    protected Void call() throws Exception {
                        startupLogger.trace("Create Tweeter ...");
                        tweeter = Tweeter.getInstance();
                        startupLogger.trace("Tweeter created!");
                        return null;
                    }
                };
                return task;
            }
        };

        service.setOnSucceeded(e -> {
            startupLogger.trace("Start Tweet task ...");
            if (!query.isEmpty() && tweeter != null) {
                tweetsTask = new TagTweets(new TweetSetData(tweeter, query), borderPane);
                tweetsTask.start();
            }
        });
        service.setOnFailed(e -> {
            System.err.println("FAILED!");
            Main.this.stop();
            primaryStage.close();
        });

        primaryStage.setTitle(title);
        primaryStage.setScene(scene);
        
        if (null != stylesheet) {
            scene.getStylesheets().add(ClassLoader.getSystemClassLoader().getResource(stylesheet).toExternalForm());
        }

        primaryStage.show();
        primaryStage.setFullScreen(true);
        service.start();
    }

    @Override
    public void stop() {
        System.out.println("closing...");
        if (tweetsTask != null) {
            tweetsTask.stop();
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
}

@@ -1316,19 +1316,127 @@
 afx.
-scene.Scene
+event.EventHandler;%0D%0Aimport javafx.scene.Scene;%0D%0Aimport javafx.scene.input.KeyCode;%0D%0Aimport javafx.scene.input.KeyEvent
 ;%0D%0Ai
@@ -2656,24 +2656,216 @@
 800, 600);%0D%0A
+        %0D%0A        if (null != stylesheet) %7B%0D%0A            scene.getStylesheets().add(ClassLoader.getSystemClassLoader().getResource(stylesheet).toExternalForm());%0D%0A        %7D        %0D%0A        %0D%0A
         Stop
@@ -3362,55 +3362,8 @@
 );%0D%0A
-        borderPane.setBottom(statusLineHost);%0D%0A
     
@@ -4444,24 +4444,32 @@
        %7D);%0D%0A
+        
 %0D%0A        pr
@@ -4470,76 +4470,124 @@
     
-primaryStage.setTitle(title);%0D%0A        primaryStage.setScene(scene);
+scene.setOnKeyTyped((KeyEvent event) -%3E %7B%0D%0A            if (event.isMetaDown() && event.getCharacter().equals(%22d%22)) %7B
 %0D%0A  
@@ -4584,34 +4584,32 @@
 d%22)) %7B%0D%0A        
-%0D%0A
         if (null
@@ -4605,37 +4605,53 @@
    if (null 
-!
+=
 = st
-ylesheet
+atusLineHost.getParent()
 ) %7B%0D%0A       
@@ -4659,110 +4659,291 @@
     
-scene.getStylesheets().add(ClassLoader.getSystemClassLoader().getResource(stylesheet).toExternalForm()
+        borderPane.setBottom(statusLineHost);%0D%0A                %7D%0D%0A                else %7B%0D%0A                    borderPane.getChildren().remove(statusLineHost);%0D%0A                %7D%0D%0A            %7D%0D%0A        %7D);%0D%0A%0D%0A        primaryStage.setTitle(title);%0D%0A        primaryStage.setScene(scene
 );%0D%0A
@@ -4946,27 +4946,24 @@
 );%0D%0A        
-%7D%0D%0A
 %0D%0A        pr

Add keyboard interaction to get toggle the developer status line