package jalviewfx.controllers; import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.gui.AlignFrame; import jalview.gui.AlignmentPanel; import jalview.io.AppletFormatAdapter; import jalview.util.MessageManager; import jalviewfx.controllers.engine.ControlledScreen; import jalviewfx.controllers.engine.ScreensController; import java.awt.print.PrinterException; import java.io.IOException; import java.net.URL; import java.util.Arrays; import java.util.List; import java.util.ResourceBundle; import javafx.application.Platform; import javafx.embed.swing.SwingNode; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.Node; import javafx.scene.control.TreeCell; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeView; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.util.Callback; import javax.swing.JComponent; import application.Project; import application.TextFieldTreeCellImpl; public class Desktop implements Initializable, ControlledScreen { @FXML private MainMenuController mainMenuController; @FXML private AlignmentViewController alignmentViewController; @FXML private TreeView projectExplorer; // @FXML private Canvas allignmentCanvas; @FXML private SwingNode jalviewNode; private final Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("/images/Jalview_Logo_small.png"))); private final Image depIcon = new Image(getClass().getResourceAsStream("/images/Jalview_Logo_small.png")); List projects = Arrays. 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")); ScreensController myController; @Override public void setScreenParent(ScreensController screenParent) { myController = screenParent; } @Override public void initialize(URL paramURL, ResourceBundle paramResourceBundle) { loadProjectExplorer(); try { loadJalview(); } catch (IOException | PrinterException e) { e.printStackTrace(); } } final static String TEST_DATA = ">FER_CAPAA/13-56 Ferredoxin\nJRFIJOIERFEOIJOIREFOIJETBGNJEWRPOKPWEOIJWEW----X-\n" + ">FER_CAPAN/13-51 Ferredoxin, chloroplast precursor\nWFEXLFWEOPKOWEFPO--EWF-FWE-WEF-WFW-BRWGEWF---FWE-\n" + ">FER1_SOLLC/13-56 Ferredoxin-1, chloroplast precursor\n-WEFWEFWFW3FLIKFOILKWFEIOEWFJIJWEFLIKWE-EWF--WEF-\n"; AlignmentI alignment; AlignmentPanel parentPanel; AlignFrame af; public void loadJalview() throws IOException, PrinterException { System.out.println("--------------> Loading jalview"); alignment = new jalview.io.FormatAdapter().readFile(TEST_DATA, AppletFormatAdapter.PASTE, "FASTA"); af = new AlignFrame(alignment, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); // parentPanel = new AlignmentPanel(af, af.getViewport()); // System.out.println("alignment Canvas : "+ allignmentCanvas); // FXGraphics2D g = new // FXGraphics2D(allignmentCanvas.getGraphicsContext2D()); createSwingContent(jalviewNode, af.alignPanel); // parentPanel.paintComponent(g); // startDesktop(); } private void startDesktop() { Platform.runLater(new Runnable() { @Override public void run() { try { Cache.initLogger(); jalview.gui.Desktop desktop = new jalview.gui.Desktop(); desktop.setInBatchMode(true); // indicate we are starting up desktop.setVisible(true); desktop.startServiceDiscovery(); jalview.gui.Desktop.addInternalFrame(af, MessageManager.formatMessage("label.input_cut_paste_params", new String[] { "paste" }), AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); af.statusBar.setText(MessageManager.getString("label.successfully_pasted_alignment_file")); // // af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", true)); } catch (Exception ex) { ex.printStackTrace(); } } }); } private void createSwingContent(final SwingNode swingNode, final JComponent swingComp) { Platform.runLater(new Runnable() { @Override public void run() { swingNode.setContent(swingComp); } }); } public void loadProjectExplorer() { rootIcon.setScaleX(.5); rootIcon.setScaleY(.5); TreeItem rootNode = new TreeItem("Project Explorer", rootIcon); projectExplorer.setRoot(rootNode); projectExplorer.setEditable(true); rootNode.setExpanded(true); for (Project project : projects) { TreeItem empLeaf = new TreeItem(project.getName()); boolean found = false; for (TreeItem typeNode : rootNode.getChildren()) { if (typeNode.getValue().contentEquals(project.getType())) { typeNode.getChildren().add(empLeaf); found = true; break; } } ImageView imgView = new ImageView(depIcon); imgView.setScaleX(.5); imgView.setScaleY(.5); if (!found) { TreeItem typeNode = new TreeItem(project.getType(), imgView); rootNode.getChildren().add(typeNode); typeNode.getChildren().add(empLeaf); } } projectExplorer.setCellFactory(new Callback, TreeCell>() { @Override public TreeCell call(TreeView p) { return new TextFieldTreeCellImpl(); } }); } }