1 package jalviewfx.controllers;
3 import jalview.bin.Cache;
4 import jalview.datamodel.AlignmentI;
5 import jalview.gui.AlignFrame;
6 import jalview.gui.AlignmentPanel;
7 import jalview.io.AppletFormatAdapter;
8 import jalview.util.MessageManager;
9 import jalviewfx.controllers.engine.ControlledScreen;
10 import jalviewfx.controllers.engine.ScreensController;
12 import java.awt.print.PrinterException;
13 import java.io.IOException;
15 import java.util.Arrays;
16 import java.util.List;
17 import java.util.ResourceBundle;
19 import javafx.application.Platform;
20 import javafx.embed.swing.SwingNode;
21 import javafx.fxml.FXML;
22 import javafx.fxml.Initializable;
23 import javafx.scene.Node;
24 import javafx.scene.control.TreeCell;
25 import javafx.scene.control.TreeItem;
26 import javafx.scene.control.TreeView;
27 import javafx.scene.image.Image;
28 import javafx.scene.image.ImageView;
29 import javafx.util.Callback;
31 import javax.swing.JComponent;
33 import application.Project;
34 import application.TextFieldTreeCellImpl;
36 public class Desktop implements Initializable, ControlledScreen {
38 private MainMenuController mainMenuController;
40 private AlignmentViewController alignmentViewController;
42 private TreeView<String> projectExplorer;
43 // @FXML private Canvas allignmentCanvas;
45 private SwingNode jalviewNode;
47 private final Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("/images/Jalview_Logo_small.png")));
48 private final Image depIcon = new Image(getClass().getResourceAsStream("/images/Jalview_Logo_small.png"));
49 List<Project> projects = Arrays.<Project> asList(new Project("Spinach Ferodoxin", "exampleFile_2_3"), new Project("FE2S2 Representation", "exampleFile_2_3"), new Project("Mafft Alignment Ordering", "exampleFile_2_3"), new Project("Phosporylation SP", "exampleFile_2_3"), new Project("Mafft example", "exampleFile_2_3"), new Project("FS3ES", "globins"), new Project("Mafft2", "globins"), new Project("Judy", "plantfdx"), new Project("Gregory", "plantfdx"), new Project("Jacob", "plantfdx"), new Project("Isabella", "globins"));
51 ScreensController myController;
54 public void setScreenParent(ScreensController screenParent) {
55 myController = screenParent;
59 public void initialize(URL paramURL, ResourceBundle paramResourceBundle) {
60 loadProjectExplorer();
63 } catch (IOException | PrinterException e) {
67 final static String TEST_DATA = ">FER_CAPAA/13-56 Ferredoxin\nJRFIJOIERFEOIJOIREFOIJETBGNJEWRPOKPWEOIJWEW----X-\n"
68 + ">FER_CAPAN/13-51 Ferredoxin, chloroplast precursor\nWFEXLFWEOPKOWEFPO--EWF-FWE-WEF-WFW-BRWGEWF---FWE-\n"
69 + ">FER1_SOLLC/13-56 Ferredoxin-1, chloroplast precursor\n-WEFWEFWFW3FLIKFOILKWFEIOEWFJIJWEFLIKWE-EWF--WEF-\n";
72 AlignmentPanel parentPanel;
75 public void loadJalview() throws IOException, PrinterException {
76 System.out.println("--------------> Loading jalview");
77 alignment = new jalview.io.FormatAdapter().readFile(TEST_DATA, AppletFormatAdapter.PASTE, "FASTA");
78 af = new AlignFrame(alignment, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
80 // parentPanel = new AlignmentPanel(af, af.getViewport());
81 // System.out.println("alignment Canvas : "+ allignmentCanvas);
82 // FXGraphics2D g = new
83 // FXGraphics2D(allignmentCanvas.getGraphicsContext2D());
84 createSwingContent(jalviewNode, af.alignPanel);
85 // parentPanel.paintComponent(g);
90 private void startDesktop() {
91 Platform.runLater(new Runnable() {
96 jalview.gui.Desktop desktop = new jalview.gui.Desktop();
97 desktop.setInBatchMode(true); // indicate we are starting up
98 desktop.setVisible(true);
99 desktop.startServiceDiscovery();
101 jalview.gui.Desktop.addInternalFrame(af, MessageManager.formatMessage("label.input_cut_paste_params", new String[] { "paste" }), AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
102 af.statusBar.setText(MessageManager.getString("label.successfully_pasted_alignment_file"));
105 // af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", true));
106 } catch (Exception ex) {
107 ex.printStackTrace();
114 private void createSwingContent(final SwingNode swingNode, final JComponent swingComp) {
115 Platform.runLater(new Runnable() {
118 swingNode.setContent(swingComp);
123 public void loadProjectExplorer() {
124 rootIcon.setScaleX(.5);
125 rootIcon.setScaleY(.5);
126 TreeItem<String> rootNode = new TreeItem<String>("Project Explorer", rootIcon);
127 projectExplorer.setRoot(rootNode);
128 projectExplorer.setEditable(true);
129 rootNode.setExpanded(true);
130 for (Project project : projects) {
131 TreeItem<String> empLeaf = new TreeItem<String>(project.getName());
132 boolean found = false;
133 for (TreeItem<String> typeNode : rootNode.getChildren()) {
134 if (typeNode.getValue().contentEquals(project.getType())) {
135 typeNode.getChildren().add(empLeaf);
140 ImageView imgView = new ImageView(depIcon);
141 imgView.setScaleX(.5);
142 imgView.setScaleY(.5);
144 TreeItem<String> typeNode = new TreeItem<String>(project.getType(), imgView);
145 rootNode.getChildren().add(typeNode);
146 typeNode.getChildren().add(empLeaf);
150 projectExplorer.setCellFactory(new Callback<TreeView<String>, TreeCell<String>>() {
152 public TreeCell<String> call(TreeView<String> p) {
153 return new TextFieldTreeCellImpl();