1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.vectomatic.svg.edit.client.inspector;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.vectomatic.dom.svg.utils.SVGConstants;
24 import org.vectomatic.svg.edit.client.AppBundle;
25 import org.vectomatic.svg.edit.client.AppConstants;
26 import org.vectomatic.svg.edit.client.event.SelectionChangedProcessor;
27 import org.vectomatic.svg.edit.client.event.SelectionChangedProxy;
28 import org.vectomatic.svg.edit.client.model.ModelCategory;
29 import org.vectomatic.svg.edit.client.model.ModelConstants;
30 import org.vectomatic.svg.edit.client.model.svg.SVGAnimatedPointsModelBase;
31 import org.vectomatic.svg.edit.client.model.svg.SVGPointsStore;
32 import org.vectomatic.svg.edit.client.model.svg.SVGPointsStore.SVGPoint;
33
34 import com.extjs.gxt.ui.client.event.ButtonEvent;
35 import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
36 import com.extjs.gxt.ui.client.event.SelectionListener;
37 import com.extjs.gxt.ui.client.store.ListStore;
38 import com.extjs.gxt.ui.client.util.Format;
39 import com.extjs.gxt.ui.client.util.Margins;
40 import com.extjs.gxt.ui.client.widget.Component;
41 import com.extjs.gxt.ui.client.widget.ContentPanel;
42 import com.extjs.gxt.ui.client.widget.LayoutContainer;
43 import com.extjs.gxt.ui.client.widget.button.Button;
44 import com.extjs.gxt.ui.client.widget.form.NumberField;
45 import com.extjs.gxt.ui.client.widget.grid.CellEditor;
46 import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
47 import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
48 import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
49 import com.extjs.gxt.ui.client.widget.grid.EditorGrid.ClicksToEdit;
50 import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
51 import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
52 import com.extjs.gxt.ui.client.widget.layout.VBoxLayout;
53 import com.extjs.gxt.ui.client.widget.layout.VBoxLayout.VBoxLayoutAlign;
54 import com.extjs.gxt.ui.client.widget.layout.VBoxLayoutData;
55 import com.google.gwt.core.client.GWT;
56 import com.google.gwt.user.client.ui.AbstractImagePrototype;
57
58
59
60
61
62 public class SVGPointsInspectorSection implements IInspectorSection<SVGAnimatedPointsModelBase> {
63 private class SVGPointsPanel extends ContentPanel implements SelectionChangedProcessor<SVGPoint> {
64 protected ColumnModel cm;
65 protected EditorGrid<SVGPoint> grid;
66 protected Button addPointButton;
67 protected Button insertPointButton;
68 protected Button removePointsButton;
69 protected SelectionChangedProxy<SVGPoint> selChangeProxy = new SelectionChangedProxy<SVGPointsStore.SVGPoint>(this);
70
71 public SVGPointsPanel() {
72 setHeading(Format.capitalize(category.getDescription()));
73 ModelConstants constants = ModelConstants.INSTANCE;
74 List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
75
76 ColumnConfig xColumn = new ColumnConfig();
77 xColumn.setSortable(false);
78 xColumn.setId(SVGConstants.SVG_X_ATTRIBUTE);
79 xColumn.setHeader(constants.x());
80 xColumn.setWidth(220);
81 NumberField xField = new NumberField();
82 xField.setPropertyEditorType(Float.class);
83 xField.setAllowBlank(false);
84 xColumn.setEditor(new CellEditor(xField));
85 configs.add(xColumn);
86
87 ColumnConfig yColumn = new ColumnConfig();
88 yColumn.setSortable(false);
89 yColumn.setId(SVGConstants.SVG_Y_ATTRIBUTE);
90 yColumn.setHeader(constants.y());
91 yColumn.setWidth(220);
92 NumberField yField = new NumberField();
93 yField.setPropertyEditorType(Float.class);
94 yField.setAllowBlank(false);
95 yColumn.setEditor(new CellEditor(yField));
96 configs.add(yColumn);
97
98 cm = new ColumnModel(configs);
99
100 grid = new EditorGrid<SVGPoint>(new ListStore<SVGPoint>(), cm);
101 grid.setClicksToEdit(ClicksToEdit.TWO);
102 addPointButton = new Button();
103 addPointButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
104 @Override
105 public void componentSelected(ButtonEvent ce) {
106 GWT.log("Append point");
107 getStore().appendPoint();
108 }
109 });
110 addPointButton.setIcon(AbstractImagePrototype.create(AppBundle.INSTANCE.addPoint()));
111 addPointButton.setToolTip(Format.capitalize(constants.addPointButton()));
112
113 insertPointButton = new Button();
114 insertPointButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
115 @Override
116 public void componentSelected(ButtonEvent ce) {
117 GWT.log("Insert point");
118 getStore().insertPoint();
119 }
120 });
121 insertPointButton.setIcon(AbstractImagePrototype.create(AppBundle.INSTANCE.insertPoint()));
122 insertPointButton.setToolTip(Format.capitalize(constants.insertPointButton()));
123
124 removePointsButton = new Button();
125 removePointsButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
126 @Override
127 public void componentSelected(ButtonEvent ce) {
128 GWT.log("Remove point");
129 getStore().removeSelectedPoints();
130 }
131 });
132 removePointsButton.setIcon(AbstractImagePrototype.create(AppBundle.INSTANCE.removePoints()));
133 removePointsButton.setToolTip(Format.capitalize(constants.removePointsButton()));
134
135 LayoutContainer c = new LayoutContainer(new ColumnLayout());
136 c.add(addPointButton);
137 c.add(insertPointButton);
138 c.add(removePointsButton);
139
140 Button showManipulatorButton = new Button(AppConstants.INSTANCE.displayManipulatorButton());
141 showManipulatorButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
142 @Override
143 public void componentSelected(ButtonEvent ce) {
144
145 }
146 });
147
148 setLayout(new VBoxLayout(VBoxLayoutAlign.STRETCH));
149 VBoxLayoutData fl1 = new VBoxLayoutData(new Margins(10, 10, 0, 10));
150 fl1.setFlex(0);
151 add(c, fl1);
152 VBoxLayoutData fl2 = new VBoxLayoutData(new Margins(10));
153 fl2.setFlex(1);
154 add(grid, fl2);
155 VBoxLayoutData fl3 = new VBoxLayoutData(new Margins(10));
156 fl3.setFlex(0);
157 add(showManipulatorButton, fl3);
158 }
159
160 public void bind(SVGPointsStore store) {
161 grid.reconfigure(store, cm);
162 final GridSelectionModel<SVGPoint> selectionModel = store.getSelectionModel();
163 selectionModel.addSelectionChangedListener(selChangeProxy);
164 grid.setSelectionModel(selectionModel);
165 selectionModel.refresh();
166 }
167
168 public void unbind() {
169 GridSelectionModel<SVGPoint> selectionModel = grid.getSelectionModel();
170 if (selectionModel != null) {
171 selectionModel.removeSelectionListener(selChangeProxy);
172 }
173 grid.setSelectionModel(null);
174 }
175
176 @Override
177 public boolean processSelectionChanged(SelectionChangedEvent<SVGPoint> se) {
178 List<SVGPoint> selection = se.getSelection();
179 GWT.log("SVGPointsPanel.selectionChanged: " + selection);
180 SVGPointsStore store = getStore();
181 insertPointButton.setEnabled(store.canInsertPoint());
182 removePointsButton.setEnabled(store.canRemoveSelectedPoints());
183 return true;
184 }
185 private SVGPointsStore getStore() {
186 return (SVGPointsStore) grid.getStore();
187 }
188
189 }
190 private SVGPointsPanel panel;
191 private ModelCategory category;
192
193 public SVGPointsInspectorSection(ModelCategory category) {
194 this.category = category;
195 panel = new SVGPointsPanel();
196 }
197 @Override
198 public Component getPanel() {
199 return panel ;
200 }
201 @Override
202 public String toString() {
203 StringBuilder builder = new StringBuilder("SVGPointsInspectorSection(");
204 builder.append(category);
205 builder.append(")");
206 return builder.toString();
207 }
208
209 @Override
210 public void bind(SVGAnimatedPointsModelBase model) {
211 GWT.log("SVGPointsInspectorSection.bind(" + model + ")");
212 panel.bind(model.getPointsStore());
213
214 }
215
216 @Override
217 public void unbind() {
218 panel.unbind();
219 }
220
221 }