View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2009 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-core Project
18  //
19  // WeaverCanvas.java
20  // Since: 2010/04/23
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.ribbon.client.ui;
26  
27  import org.utgenome.gwt.utgb.client.ui.FixedWidthLabel;
28  import org.utgenome.gwt.utgb.client.ui.RoundCornerFrame;
29  import org.utgenome.gwt.widget.client.Style;
30  
31  import com.google.gwt.event.dom.client.ClickEvent;
32  import com.google.gwt.event.dom.client.ClickHandler;
33  import com.google.gwt.user.client.ui.AbsolutePanel;
34  import com.google.gwt.user.client.ui.Button;
35  import com.google.gwt.user.client.ui.Composite;
36  import com.google.gwt.user.client.ui.Label;
37  import com.google.gwt.user.client.ui.SimplePanel;
38  import com.google.gwt.user.client.ui.TabPanel;
39  import com.google.gwt.widgetideas.graphics.client.Color;
40  import com.google.gwt.widgetideas.graphics.client.GWTCanvas;
41  
42  /**
43   * Multi layer canvas for drawing genome data
44   * 
45   * @author leo
46   * 
47   */
48  public class WeaverCanvas extends Composite {
49  
50  	private final AbsolutePanel mainPanel;
51  	private final GWTCanvas canvas1;
52  	private final GWTCanvas canvas2;
53  
54  	public WeaverCanvas() {
55  
56  		int width = 800;
57  		int height = 500;
58  		mainPanel = new AbsolutePanel();
59  		mainPanel.setPixelSize(width, height);
60  		canvas1 = new GWTCanvas(width, height);
61  		canvas2 = new GWTCanvas(width, height);
62  
63  		//		CanvasGradient gr = canvas1.createRadialGradient(45, 45, 10, 52, 50, 30);
64  		//		gr.addColorStop(0, new Color(0xA7, 0XD3, 0x0C));
65  		//		gr.addColorStop(0.9f, new Color(0x01, 0x9F, 0x62, 0f));
66  		//		gr.addColorStop(1, new Color("rgba(1,159,98,0)"));
67  		//canvas1.setFillStyle(gr);
68  		canvas1.setFillStyle(new Color(200, 0, 0, 0.7f));
69  		canvas1.fillRect(0, 0, 150, 150);
70  
71  		canvas2.setFillStyle(new Color(100, 200, 250));
72  		canvas2.fillRect(30, 20, 200, 150);
73  		canvas2.setFillStyle(new Color(200, 50, 240, 0.4f));
74  		canvas2.fillRect(130, 40, 150, 40);
75  
76  		mainPanel.add(canvas2, 0, 0);
77  		mainPanel.add(canvas1, 0, 0);
78  
79  		TabPanel tabPanel = new TabPanel();
80  
81  		RoundCornerFrame tab1 = new RoundCornerFrame("336699", 0.8f, 4);
82  		RoundCornerFrame tab2 = new RoundCornerFrame("336699", 0.8f, 4);
83  		tab2.setFrameColor("336699", 0.3f);
84  
85  		Label tl = new Label("Track Groups");
86  		Style.fontColor(tl, "white");
87  		Style.bold(tl);
88  		Style.nowrap(tl);
89  		Label tl2 = new Label("Tracks");
90  		Style.fontColor(tl2, "white");
91  		Style.bold(tl2);
92  		Style.nowrap(tl2);
93  
94  		tab1.setWidget(tl);
95  		tab2.setWidget(tl2);
96  		tabPanel.add(new SimplePanel(), tab1);
97  		tabPanel.add(new SimplePanel(), tab2);
98  
99  		mainPanel.add(tabPanel, 100, 100);
100 
101 		final RoundCornerFrame f = new RoundCornerFrame("3E5A77", 0.8f, 4);
102 		final FixedWidthLabel l = new FixedWidthLabel("Hello World. Nice to meet you. Welcome to UTGB Toolkit", 200);
103 		Style.fontSize(l, 12);
104 		Style.fontColor(l, "white");
105 		//Style.semiTransparentBackground(l, "3E5A77", 0.8f);
106 		f.setWidget(l);
107 
108 		//		l.setPixelSize(200, 19);
109 		//		//l.setStyleName("label");
110 		//		DOM.setStyleAttribute(l.getElement(), "backgroundImage", "url(utgb-core/transparent?color=3E5A77&opacity=0.7)");
111 		//		DOM.setStyleAttribute(l.getElement(), "textOverflow", "ellipsis");
112 		//		DOM.setStyleAttribute(l.getElement(), "overflow", "hidden");
113 		//		DOM.setStyleAttribute(l.getElement(), "whiteSpace", "nowrap");
114 		//		DOM.setStyleAttribute(l.getElement(), "display", "block");
115 		//DOM.setStyleAttribute(l.getElement(), "color", "white");
116 
117 		mainPanel.add(f, 10, 10);
118 
119 		final GWTCanvas canvas = new GWTCanvas(100, 100);
120 		canvas.setFillStyle(new Color("rgba(100, 100, 255, 0.5)"));
121 		canvas.fillRect(10, 20, 50, 30);
122 
123 		mainPanel.add(canvas, 40, 40);
124 
125 		Button scale = new Button("scale");
126 		scale.addClickHandler(new ClickHandler() {
127 
128 			boolean on = false;
129 
130 			public void onClick(ClickEvent event) {
131 				Style.scaleXwithAnimation(canvas, on ? 5 : 1.5, 0.5);
132 				on = !on;
133 			}
134 		});
135 
136 		mainPanel.add(scale, 100, 300);
137 
138 		initWidget(mainPanel);
139 	}
140 
141 	private int pos = 0;
142 
143 	public void move() {
144 
145 		pos += 2;
146 
147 		//Style.set(w, cssPropertyName, value)
148 		mainPanel.add(canvas1, pos, pos);
149 
150 	}
151 
152 	public void fade() {
153 
154 	}
155 
156 }