view.TimelinePanel.java Source code

Java tutorial

Introduction

Here is the source code for view.TimelinePanel.java

Source

/*
 * 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 view;

import entity.Projects;
import entity.Tasks;
import entity.Users;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import java.io.FileWriter;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import services.ApplicationController;

/**
 *
 * @author Cherry
 */
public class TimelinePanel extends javax.swing.JPanel {

    private JFXPanel fxPanel;

    private static String TEMPLATE = "<!DOCTYPE html> <html lang=\"en\"> <head>"
            + " <title></title> <meta charset=\"utf-8\">"
            + " <meta name=\"apple-mobile-web-app-capable\" content=\"yes\">"
            + " <meta name=\"apple-touch-fullscreen\" content=\"yes\">" + " </html>";

    /**
     * Creates new form TimelinePanel
     */
    public TimelinePanel() {
        initComponents();

        fxPanel = new JFXPanel();
        final Dimension size = new Dimension(960, 750);
        fxPanel.setSize(size);
        setLayout(new BorderLayout(0, 0));
        add(fxPanel);

        Platform.runLater(new Runnable() { // this will run initFX as JavaFX-Thread
            @Override
            public void run() {
                Group group = new Group();
                Scene scene = new Scene(group);
                fxPanel.setScene(scene);

                WebView webView = new WebView();

                group.getChildren().add(webView);
                webView.setMinSize(size.getWidth(), size.getHeight());
                webView.setMaxSize(size.getWidth(), size.getHeight());

                WebEngine webEngine = webView.getEngine();
                webEngine.load(
                        "http://cdn.knightlab.com/libs/timeline/latest/embed/index.html?source=0Ag1_iE674IuvdEFaZi0wOVBFY2l2OHdPUWlrZEMwaHc&font=Bevan-PotanoSans&maptype=toner&lang=en");
            }
        });
    }

    private String getJsonConfig() {
        EntityManager em = ApplicationController.getEnitityManager();
        TypedQuery<Tasks> queryTasks = (TypedQuery<Tasks>) em.createNamedQuery("Tasks.findByProjectId");
        Integer proId = ApplicationController.getCurrentProject().getId();
        List<Tasks> tasks = queryTasks.setParameter("projectId", proId).getResultList();
        return tasks.get(0).getTaskName();
    }

    /* Creates a WebView and fires up google.com */
    private static void initFX(final JFXPanel fxPanel) {
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0,
                769, Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 528,
                Short.MAX_VALUE));
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}