1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.vectomatic.client.rep.view;
19
20 import org.vectomatic.common.model.IStyleVisitor;
21 import org.vectomatic.common.model.style.Color;
22 import org.vectomatic.common.model.style.IStyle;
23 import org.vectomatic.common.model.style.NoneStyle;
24
25 import com.google.gwt.user.client.DOM;
26 import com.google.gwt.user.client.Event;
27 import com.google.gwt.user.client.ui.ChangeListener;
28 import com.google.gwt.user.client.ui.PopupPanel;
29 import com.google.gwt.user.client.ui.Widget;
30
31
32
33
34 public class StyleWell extends Widget implements ChangeListener {
35 private IStyle _style;
36 private PopupPanel _menu;
37 private IStyleVisitor _styleVisitor = new IStyleVisitor() {
38
39 public void visitColor(Color color) {
40 String style = color.toString();
41 DOM.setStyleAttribute(getElement(), "backgroundColor", style);
42 }
43
44 public void visitNoneStyle(NoneStyle none) {
45 DOM.setStyleAttribute(getElement(), "backgroundColor", "rgb(255, 255, 255)");
46 }
47
48 };
49
50 public StyleWell() {
51 setElement(DOM.createDiv());
52 setStyleName("colorEditor-styleWell");
53 sinkEvents(Event.ONCLICK);
54 }
55
56 public IStyle getStyle() {
57 return _style;
58 }
59
60 public void setStyle(IStyle color, IStyleMenu menu) {
61 _style = color;
62 _menu = (PopupPanel)menu;
63 update();
64 }
65
66 public void update() {
67 if (_style != null) {
68 _style.acceptVisitor(_styleVisitor);
69 }
70 }
71
72 @Override
73 public void onBrowserEvent(Event event) {
74 switch (DOM.eventGetType(event)) {
75 case Event.ONCLICK:
76 if (_menu != null) {
77 int left = getAbsoluteLeft();
78 int top = getAbsoluteTop() + getOffsetHeight();
79 _menu.setPopupPosition(left, top);
80 _menu.show();
81 }
82 break;
83 }
84 }
85
86 public void onChange(Widget sender) {
87 update();
88 }
89 }