first commit
[jalview-fx.git] / src / application / Controller.java
1 package application;
2
3 import jalviewfx.controllers.engine.ControlledScreen;
4 import jalviewfx.controllers.engine.ScreensController;
5
6 import java.io.IOException;
7 import java.net.MalformedURLException;
8 import java.net.URL;
9 import java.util.ResourceBundle;
10
11 import javafx.fxml.FXML;
12 import javafx.fxml.FXMLLoader;
13 import javafx.fxml.Initializable;
14 import javafx.scene.Parent;
15 import javafx.scene.Scene;
16 import javafx.scene.canvas.Canvas;
17 import javafx.scene.canvas.GraphicsContext;
18 import javafx.scene.control.TextField;
19 import javafx.scene.text.TextAlignment;
20 import javafx.scene.web.WebEngine;
21 import javafx.scene.web.WebView;
22
23
24
25 public class Controller  implements Initializable, ControlledScreen {
26         @FXML
27         private WebView browser;
28         @FXML
29         private TextField tf;
30         @FXML
31         private Canvas canvas;
32
33         ScreensController myController;
34
35         @FXML
36         void initialize() {
37                 String pre_msg = "fx:id=\"";
38                 String post_msg = "\" was not ingected: check the FXML file 'TestUI.fxml' ";
39                 assert browser != null : pre_msg + "map_listview" + post_msg;
40                 assert canvas != null : pre_msg + "canvas" + post_msg;
41                 System.out.println("Textfield : "+tf);
42                 System.out.println("Canvas : "+canvas);
43         }
44
45         public void doSmt() throws MalformedURLException, IOException {
46                 System.out.println("do smt ..");
47                 System.out.println(tf.getText());
48                 System.out.println(browser.getId());
49                 WebEngine webEngine = browser.getEngine();
50                 webEngine.load(getClass().getResource("/html/alignment.html").toString());
51         }
52         
53         public void gotoStageTwo() throws IOException{
54                 System.out.println("Going to next stage");
55                 Scene sceneTwo = new Scene((Parent) FXMLLoader.load(getClass().getResource("/fxml/TestUI.fxml")));
56                 Main.getPrimaryStage().setScene(sceneTwo);
57         }
58         
59         public void useCanvas() {
60                 System.out.println("Canvas object ------> "+canvas);
61                 GraphicsContext gc = canvas.getGraphicsContext2D();
62                  gc.setTextAlign(TextAlignment.JUSTIFY);
63                 // gc.setTextBaseline(VPos.TOP);
64
65                 String longestSeq = "MASVSATMISTSFMPRKPAVTSLKPIP-NVG-EALFGLKS---ANGGKVTCMASYKVKLITPDGPIEFDCPDNVYILDQAEEAGHDLPYSCRAGSCSSCAGKIAGGAVDQT";
66
67                 int charSpace = 0;
68                 double fontSize = 8;//gc.getFont().getSize();
69                 for(int x = 1; x < longestSeq.length(); x++){
70                         if(x % 10 == 0){
71                                 gc.fillText(String.valueOf(x), charSpace, 15);  
72                         }else{                  
73                                 gc.fillText(" ", charSpace, 15);
74                         }
75                          
76                   if(x % 5 == 0){
77                                 gc.fillText("|", charSpace, 30);        
78                         }
79                         charSpace += fontSize;
80                 }
81                 gc.fillText(longestSeq, 0, 45);
82                 gc.fillText("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, 60);
83
84         }
85
86         @Override
87         public void setScreenParent(ScreensController screenParent) {
88                 myController = screenParent;
89                 
90         }
91
92         @Override
93         public void initialize(URL paramURL, ResourceBundle paramResourceBundle) {
94                 // TODO Auto-generated method stub
95                 
96         }
97
98
99 }