Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / src / javajs / swing / JDialog.java
1 package javajs.swing;
2
3 import javajs.awt.Color;
4 import javajs.awt.Container;
5 import javajs.util.SB;
6
7
8 /**
9  * There is really no need here for awt.Dialog.
10  * We would not use FileDialog in an HTML5 context anyway.
11  * 
12  */
13 public class JDialog extends Container {
14
15   private static final int headerHeight = 25;
16   private int defaultWidth = 600;
17   private int defaultHeight = 300;
18   
19   private JContentPane contentPane;
20   private String title;
21   private String html;
22   private int zIndex = 9000;
23   
24   public void setZIndex(int zIndex) {
25     this.zIndex = zIndex;
26   }
27   
28   int[] loc;
29
30   public JDialog() {
31     super("JD");
32     add(contentPane = new JContentPane());
33     setBackground(Color.get3(210, 210, 240));
34     contentPane.setBackground(Color.get3(230, 230, 230));
35   }
36   
37   public void setLocation(int[] loc) {
38     this.loc = loc;
39   }
40   
41   public JContentPane getContentPane() {
42     return contentPane;
43   }
44
45   public void setTitle(String title) {
46     this.title = title;
47   }
48
49   public void pack() {
50     html = null;
51   }
52
53   public void validate() {
54     html = null;
55   }
56
57   @Override
58   public void setVisible(boolean tf) {
59     if (tf && html == null)
60       setDialog();
61     super.setVisible(tf);
62   }
63
64   public void dispose() {
65     {
66       
67       /**
68        * @j2sNative
69        * 
70        * SwingController.dispose(this);
71        * 
72        */
73       {
74       }
75       
76     }
77   }
78
79   @Override
80   public void repaint() {
81     setDialog();
82   }
83   
84   /**
85    * Set it into DOM, but don't show it yet.
86    * this.loc, this.manager, this.id, etc.
87    * 
88    */
89   private void setDialog() {
90     html = toHTML();
91     /**
92      * @j2sNative
93      * 
94      * SwingController.setDialog(this);
95      * 
96      * 
97      */
98     {
99       System.out.println(html);
100     }
101   }
102   
103   @Override
104   public String toHTML() {
105     renderWidth = getSubcomponentWidth();
106     if (renderWidth == 0)
107       renderWidth = defaultWidth;
108     renderHeight = contentPane.getSubcomponentHeight();
109     if (renderHeight == 0)
110       renderHeight = defaultHeight;
111     int h = renderHeight - headerHeight;
112     SB sb = new SB();
113     sb.append("\n<div id='" + id + "' class='JDialog' style='" + getCSSstyle(0, 0) + "z-index:" + zIndex + ";position:relative;top:0px;left:0px;reize:both;'>\n");
114     sb.append("\n<div id='" + id + "_title' class='JDialogTitle' style='width:100%;height:25px;padding:5px 5px 5px 5px;height:"+headerHeight+"px'>"
115         +"<span style='text-align:center;'>" + title + "</span><span style='position:absolute;text-align:right;right:1px;'>"
116         + "<input type=button id='" + id + "_closer' onclick='SwingController.windowClosing(this)' value='x' /></span></div>\n");
117     sb.append("\n<div id='" + id + "_body' class='JDialogBody' style='width:100%;height:"+h+"px;"
118         +"position: relative;left:0px;top:0px'>\n");
119     sb.append(contentPane.toHTML());
120     sb.append("\n</div></div>\n");
121     return sb.toString();
122   }
123
124
125
126 }