| 37 | | coordinateLayout.setMargin(true, true, true, true); |
| 38 | | |
| 39 | | // Setup table |
| 40 | | Table table = new Table("Test table"); |
| 41 | | table.setPageLength(10); |
| 42 | | table.setImmediate(true); |
| 43 | | |
| 44 | | table.addContainerProperty("First Name", String.class, |
| 45 | | "(no first name)"); |
| 46 | | table.addContainerProperty("Last Name", String.class, "(no last name)"); |
| 47 | | table.addContainerProperty("Year", Integer.class, null); |
| 48 | | |
| 49 | | final String[] firstnames = new String[] { "Donald", "Patty", "Sally", |
| 50 | | "Douglas" }; |
| 51 | | final String[] lastnames = new String[] { "Smith", "Jones", "Adams", |
| 52 | | "Knuth" }; |
| 53 | | |
| 54 | | for (int i = 0; i < 20; i++) { |
| 55 | | table |
| 56 | | .addItem( |
| 57 | | new Object[] { |
| 58 | | firstnames[(int) (Math.random() * (firstnames.length - 0.01))], |
| 59 | | lastnames[(int) (Math.random() * (lastnames.length - 0.01))], |
| 60 | | new Integer( |
| 61 | | (int) (1900 + Math.random() * 100)) }, |
| 62 | | new Integer(i)); |
| | 100 | |
| | 101 | main.setLayout(coordinateLayout); |
| | 102 | // |
| | 103 | // // Setup table |
| | 104 | // Table table = new Table("Test table"); |
| | 105 | // table.setPageLength(10); |
| | 106 | // table.setImmediate(true); |
| | 107 | // |
| | 108 | // table.addContainerProperty("First Name", String.class, |
| | 109 | // "(no first name)"); |
| | 110 | // table.addContainerProperty("Last Name", String.class, |
| | 111 | // "(no last name)"); |
| | 112 | // table.addContainerProperty("Year", Integer.class, null); |
| | 113 | // |
| | 114 | // final String[] firstnames = new String[] { "Donald", "Patty", |
| | 115 | // "Sally", |
| | 116 | // "Douglas" }; |
| | 117 | // final String[] lastnames = new String[] { "Smith", "Jones", "Adams", |
| | 118 | // "Knuth" }; |
| | 119 | // |
| | 120 | // for (int i = 0; i < 20; i++) { |
| | 121 | // table |
| | 122 | // .addItem( |
| | 123 | // new Object[] { |
| | 124 | // firstnames[(int) (Math.random() * (firstnames.length - 0.01))], |
| | 125 | // lastnames[(int) (Math.random() * (lastnames.length - 0.01))], |
| | 126 | // new Integer( |
| | 127 | // (int) (1900 + Math.random() * 100)) }, |
| | 128 | // new Integer(i)); |
| | 129 | // } |
| | 130 | // |
| | 131 | // coordinateLayout.addComponent(table); |
| | 132 | // coordinateLayout.setCoordinates(table, |
| | 133 | // new CoordinateLayout.Coordinates("-1,-1,-1,-1, 5%, %5")); |
| | 134 | // |
| | 135 | // CoordinateLayout.Coordinates xy = new |
| | 136 | // CoordinateLayout.Coordinates(40, |
| | 137 | // 40, 40, 40, -1, -1); |
| | 138 | // xy.setUnitsPercent(true, true, true, true, false, false); |
| | 139 | // |
| | 140 | // coordinateLayout.addComponent(new TextField("Caption", |
| | 141 | // "TextField with a caption"), xy); |
| | 142 | // |
| | 143 | // final DateField dateField = new DateField("Removal test"); |
| | 144 | // // coordinateLayout.addComponent(dateField); |
| | 145 | // |
| | 146 | // final Panel panel = new Panel("TestPanel"); |
| | 147 | // // coordinateLayout.addComponent(panel, "0,-1,-1,-1,-1,0"); |
| | 148 | // |
| | 149 | // final Layout ol = new OrderedLayout(); |
| | 150 | // ol.addComponent(new Select("Select inside layouts", table |
| | 151 | // .getContainerDataSource())); |
| | 152 | // ol.addComponent(new Select("Select inside layouts", table |
| | 153 | // .getContainerDataSource())); |
| | 154 | // ol.addComponent(new Select("Select inside layouts", table |
| | 155 | // .getContainerDataSource())); |
| | 156 | // |
| | 157 | // // CoordinateLayout.Coordinates xy2 = new |
| | 158 | // CoordinateLayout.Coordinates( |
| | 159 | // // "-1,-1,0,0,200,200"); |
| | 160 | // // coordinateLayout.addComponent(ol, xy2); |
| | 161 | // |
| | 162 | // Button b1 = new Button("Add contents to panel"); |
| | 163 | // b1.addListener(new Button.ClickListener() { |
| | 164 | // int number = 0; |
| | 165 | // |
| | 166 | // public void buttonClick(Button.ClickEvent e) { |
| | 167 | // panel.addComponent(new Label("Label nro. " + number++)); |
| | 168 | // } |
| | 169 | // }); |
| | 170 | // |
| | 171 | // Button b2 = new Button("Switch Panel z-order"); |
| | 172 | // b2.addListener(new Button.ClickListener() { |
| | 173 | // boolean bottom = false; |
| | 174 | // |
| | 175 | // public void buttonClick(Button.ClickEvent e) { |
| | 176 | // if (bottom) { |
| | 177 | // coordinateLayout.sendToTop(panel); |
| | 178 | // bottom = false; |
| | 179 | // } else { |
| | 180 | // coordinateLayout.sendToBottom(panel); |
| | 181 | // bottom = true; |
| | 182 | // } |
| | 183 | // } |
| | 184 | // }); |
| | 185 | // |
| | 186 | // Button b3 = new Button("Switch borders on / off"); |
| | 187 | // b3.addListener(new Button.ClickListener() { |
| | 188 | // public void buttonClick(Button.ClickEvent e) { |
| | 189 | // coordinateLayout.setBorders(!coordinateLayout.hasBorders()); |
| | 190 | // } |
| | 191 | // }); |
| | 192 | // |
| | 193 | // Button b4 = new Button("Removal test"); |
| | 194 | // b4.addListener(new Button.ClickListener() { |
| | 195 | // public void buttonClick(Button.ClickEvent e) { |
| | 196 | // e.getButton().setEnabled(false); |
| | 197 | // coordinateLayout.removeComponent(dateField); |
| | 198 | // } |
| | 199 | // }); |
| | 200 | // |
| | 201 | // Button b5 = new Button("requestRepaint()"); |
| | 202 | // b5.addListener(new Button.ClickListener() { |
| | 203 | // public void buttonClick(Button.ClickEvent e) { |
| | 204 | // coordinateLayout.requestRepaint(); |
| | 205 | // } |
| | 206 | // }); |
| | 207 | // |
| | 208 | // // Setup coordinateLayout for right |
| | 209 | // OrderedLayout right = new OrderedLayout(); |
| | 210 | // right.addComponent(getControlPanel(table)); |
| | 211 | // right.addComponent(getControlPanel(panel)); |
| | 212 | // right.addComponent(b1); |
| | 213 | // right.addComponent(b2); |
| | 214 | // right.addComponent(b3); |
| | 215 | // right.addComponent(b4); |
| | 216 | // right.addComponent(b5); |
| | 217 | // |
| | 218 | // // sPanel.addComponent(coordinateLayout); |
| | 219 | // // sPanel.addComponent(right); |
| | 220 | // // |
| | 221 | // // sPanel.setSplitPosition(75); |
| | 222 | // // |
| | 223 | // // main.setLayout(sPanel); |
| | 224 | // |
| | 225 | // ExpandLayout mainLayout = new ExpandLayout( |
| | 226 | // ExpandLayout.ORIENTATION_HORIZONTAL); |
| | 227 | // mainLayout.addComponent(coordinateLayout); |
| | 228 | // mainLayout.addComponent(right); |
| | 229 | // main.setLayout(mainLayout); |
| | 230 | |
| | 231 | setMainWindow(main); |
| | 232 | |
| | 233 | } |
| | 234 | |
| | 235 | private MenuBar getMainMenuBar() { |
| | 236 | MenuBar menu = new MenuBar(); |
| | 237 | MenuItem add = menu.addItem("Add component", null); |
| | 238 | MenuItem remove = menu.addItem("Remove component", null); |
| | 239 | MenuItem cPanel = menu.addItem("Show / hide control panel", null); |
| | 240 | cPanel.setCommand(new Command() { |
| | 241 | |
| | 242 | public void menuSelected(MenuItem selectedItem) { |
| | 243 | if (main.getChildWindows().contains(controlPanel)) { |
| | 244 | main.removeWindow(controlPanel); |
| | 245 | } else { |
| | 246 | main.addWindow(controlPanel); |
| | 247 | |
| | 248 | } |
| | 249 | } |
| | 250 | }); |
| | 251 | |
| | 252 | final MenuItem margins = menu.addItem("Toggle margins", null); |
| | 253 | margins.setCommand(new Command() { |
| | 254 | |
| | 255 | boolean marginsEnabled = false; |
| | 256 | |
| | 257 | public void menuSelected(MenuItem selectedItem) { |
| | 258 | if (marginsEnabled) { |
| | 259 | margins.setIcon(null); |
| | 260 | marginsEnabled = false; |
| | 261 | coordinateLayout.setMargin(false); |
| | 262 | } else { |
| | 263 | margins.setIcon(new ThemeResource("icons/16/ok.png")); |
| | 264 | marginsEnabled = true; |
| | 265 | coordinateLayout.setMargin(true); |
| | 266 | } |
| | 267 | } |
| | 268 | |
| | 269 | }); |
| | 270 | |
| | 271 | add.addItem("Table", new AddCommand("Table", table, remove)); |
| | 272 | |
| | 273 | add.addItem("Panel", new AddCommand("Panel", panel, remove)); |
| | 274 | |
| | 275 | add |
| | 276 | .addItem("TextField", new AddCommand("TextField", textField, |
| | 277 | remove)); |
| | 278 | |
| | 279 | return menu; |
| | 280 | } |
| | 281 | |
| | 282 | private class AddCommand implements Command { |
| | 283 | |
| | 284 | private String id; |
| | 285 | private Component toAdd; |
| | 286 | private MenuItem removeMenu; |
| | 287 | |
| | 288 | public void menuSelected(MenuItem selectedItem) { |
| | 289 | if (!coordinateLayout.contains(toAdd)) { |
| | 290 | |
| | 291 | final Coordinates coords = coordinateLayout.addComponent(toAdd, |
| | 292 | "50%,50%"); |
| | 293 | |
| | 294 | Content pvContent = new Content() { |
| | 295 | TextField tf = new TextField("Edit coordinates", coords |
| | 296 | .toString()); |
| | 297 | |
| | 298 | { |
| | 299 | |
| | 300 | tf.addListener(new ValueChangeListener() { |
| | 301 | |
| | 302 | public void valueChange(ValueChangeEvent event) { |
| | 303 | try { |
| | 304 | coords.setCoords((String) event |
| | 305 | .getProperty().getValue()); |
| | 306 | } catch (Exception e) { |
| | 307 | main |
| | 308 | .showNotification( |
| | 309 | "Coordinate syntax error", |
| | 310 | Window.Notification.TYPE_ERROR_MESSAGE); |
| | 311 | } |
| | 312 | |
| | 313 | } |
| | 314 | |
| | 315 | }); |
| | 316 | tf.setImmediate(true); |
| | 317 | } |
| | 318 | |
| | 319 | public String getMinimizedValueAsHTML() { |
| | 320 | return coords.toString(); |
| | 321 | } |
| | 322 | |
| | 323 | public Component getPopupComponent() { |
| | 324 | tf.setValue(coords.toString()); |
| | 325 | return tf; |
| | 326 | } |
| | 327 | |
| | 328 | }; |
| | 329 | |
| | 330 | PopupView pv = new PopupView(pvContent); |
| | 331 | Item item = componentContainer.addItem(id); |
| | 332 | item.getItemProperty("Component").setValue(id); |
| | 333 | item.getItemProperty("Coordinates").setValue(pv); |
| | 334 | |
| | 335 | removeMenu.addItem(id, new RemoveCommand(id, toAdd)); |
| | 336 | |
| | 337 | controlPanel.addComponent(getControlPanel(toAdd)); |
| | 338 | |
| | 339 | } |
| 65 | | coordinateLayout.addComponent(table); |
| 66 | | coordinateLayout.setCoordinates(table, |
| 67 | | new CoordinateLayout.Coordinates("0,0,-1,-1")); |
| 68 | | |
| 69 | | CoordinateLayout.Coordinates xy = new CoordinateLayout.Coordinates(40, |
| 70 | | 40, 40, 40, -1, -1); |
| 71 | | xy.setUnitsPercent(true, true, true, true, false, false); |
| 72 | | |
| 73 | | coordinateLayout.addComponent(new TextField("Caption", |
| 74 | | "TextField with a caption"), xy); |
| 75 | | |
| 76 | | final DateField dateField = new DateField("Removal test"); |
| 77 | | // coordinateLayout.addComponent(dateField); |
| 78 | | |
| 79 | | final Panel panel = new Panel("TestPanel"); |
| 80 | | // coordinateLayout.addComponent(panel, "0,-1,-1,-1,-1,0"); |
| 81 | | |
| 82 | | final Layout ol = new OrderedLayout(); |
| 83 | | ol.addComponent(new Select("Select inside layouts", table |
| 84 | | .getContainerDataSource())); |
| 85 | | ol.addComponent(new Select("Select inside layouts", table |
| 86 | | .getContainerDataSource())); |
| 87 | | ol.addComponent(new Select("Select inside layouts", table |
| 88 | | .getContainerDataSource())); |
| 89 | | |
| 90 | | // CoordinateLayout.Coordinates xy2 = new CoordinateLayout.Coordinates( |
| 91 | | // "-1,-1,0,0,200,200"); |
| 92 | | // coordinateLayout.addComponent(ol, xy2); |
| 93 | | |
| 94 | | Button b1 = new Button("Add contents to panel"); |
| 95 | | b1.addListener(new Button.ClickListener() { |
| 96 | | int number = 0; |
| 97 | | |
| 98 | | public void buttonClick(Button.ClickEvent e) { |
| 99 | | panel.addComponent(new Label("Label nro. " + number++)); |
| 100 | | } |
| 101 | | }); |
| 102 | | |
| 103 | | Button b2 = new Button("Switch Panel z-order"); |
| 104 | | b2.addListener(new Button.ClickListener() { |
| 105 | | boolean bottom = false; |
| 106 | | |
| 107 | | public void buttonClick(Button.ClickEvent e) { |
| 108 | | if (bottom) { |
| 109 | | coordinateLayout.sendToTop(panel); |
| 110 | | bottom = false; |
| 111 | | } else { |
| 112 | | coordinateLayout.sendToBottom(panel); |
| 113 | | bottom = true; |
| 114 | | } |
| 115 | | } |
| 116 | | }); |
| 117 | | |
| 118 | | Button b3 = new Button("Switch borders on / off"); |
| 119 | | b3.addListener(new Button.ClickListener() { |
| 120 | | public void buttonClick(Button.ClickEvent e) { |
| 121 | | coordinateLayout.setBorders(!coordinateLayout.hasBorders()); |
| 122 | | } |
| 123 | | }); |
| 124 | | |
| 125 | | Button b4 = new Button("Removal test"); |
| 126 | | b4.addListener(new Button.ClickListener() { |
| 127 | | public void buttonClick(Button.ClickEvent e) { |
| 128 | | e.getButton().setEnabled(false); |
| 129 | | coordinateLayout.removeComponent(dateField); |
| 130 | | } |
| 131 | | }); |
| 132 | | |
| 133 | | Button b5 = new Button("requestRepaint()"); |
| 134 | | b5.addListener(new Button.ClickListener() { |
| 135 | | public void buttonClick(Button.ClickEvent e) { |
| 136 | | coordinateLayout.requestRepaint(); |
| 137 | | } |
| 138 | | }); |
| 139 | | |
| 140 | | // Setup coordinateLayout for right |
| 141 | | OrderedLayout right = new OrderedLayout(); |
| 142 | | right.addComponent(getControlPanel(table)); |
| 143 | | right.addComponent(getControlPanel(panel)); |
| 144 | | right.addComponent(b1); |
| 145 | | right.addComponent(b2); |
| 146 | | right.addComponent(b3); |
| 147 | | right.addComponent(b4); |
| 148 | | right.addComponent(b5); |
| 149 | | |
| 150 | | // sPanel.addComponent(coordinateLayout); |
| 151 | | // sPanel.addComponent(right); |
| 152 | | // |
| 153 | | // sPanel.setSplitPosition(75); |
| 154 | | // |
| 155 | | // main.setLayout(sPanel); |
| 156 | | |
| 157 | | ExpandLayout mainLayout = new ExpandLayout( |
| 158 | | ExpandLayout.ORIENTATION_HORIZONTAL); |
| 159 | | mainLayout.addComponent(coordinateLayout); |
| 160 | | mainLayout.addComponent(right); |
| 161 | | main.setLayout(mainLayout); |
| 162 | | |
| 163 | | setMainWindow(main); |
| | 342 | AddCommand(String id, Component toAdd, MenuItem removeMenu) { |
| | 343 | this.id = id; |
| | 344 | this.toAdd = toAdd; |
| | 345 | this.removeMenu = removeMenu; |
| | 346 | } |
| 168 | | Panel newPanel = new Panel("Controls for " + c.getCaption()); |
| 169 | | newPanel.setLayout(new GridLayout(3, 6)); |
| 170 | | |
| 171 | | final int[] values = new int[6]; |
| 172 | | Arrays.fill(values, -1); |
| 173 | | |
| 174 | | final CheckBox[] checkBoxArray = new CheckBox[6]; |
| 175 | | final Slider[] sliderArray = new Slider[6]; |
| 176 | | |
| 177 | | checkBoxArray[0] = new CheckBox("Top"); |
| 178 | | sliderArray[0] = new Slider(0, 100, 1); |
| 179 | | |
| 180 | | checkBoxArray[1] = new CheckBox("Right"); |
| 181 | | sliderArray[1] = new Slider(0, 100, 1); |
| 182 | | |
| 183 | | checkBoxArray[2] = new CheckBox("Bottom"); |
| 184 | | sliderArray[2] = new Slider(0, 100, 1); |
| 185 | | |
| 186 | | checkBoxArray[3] = new CheckBox("Left"); |
| 187 | | sliderArray[3] = new Slider(0, 100, 1); |
| 188 | | |
| 189 | | checkBoxArray[4] = new CheckBox("Width"); |
| 190 | | sliderArray[4] = new Slider(0, 100, 1); |
| 191 | | |
| 192 | | checkBoxArray[5] = new CheckBox("Height"); |
| 193 | | sliderArray[5] = new Slider(0, 100, 1); |
| 194 | | |
| 195 | | final Label[] labelArray = new Label[6]; |
| 196 | | |
| 197 | | for (int i = 0; i < checkBoxArray.length; i++) { |
| 198 | | final int j = i; |
| 199 | | |
| 200 | | labelArray[j] = new Label("-1"); |
| 201 | | labelArray[j].setEnabled(false); |
| 202 | | checkBoxArray[j].setImmediate(true); |
| 203 | | sliderArray[j].setImmediate(true); |
| 204 | | sliderArray[j].setEnabled(false); |
| 205 | | |
| 206 | | checkBoxArray[j].addListener(new ValueChangeListener() { |
| 207 | | public void valueChange(ValueChangeEvent event) { |
| 208 | | Boolean isChecked = (Boolean) checkBoxArray[j].getValue(); |
| 209 | | if (isChecked.booleanValue()) { |
| 210 | | sliderArray[j].setEnabled(true); |
| 211 | | labelArray[j].setEnabled(true); |
| 212 | | } else { |
| 213 | | values[j] = -1; |
| 214 | | labelArray[j].setValue(new Integer(values[j])); |
| 215 | | sliderArray[j].setEnabled(false); |
| 216 | | labelArray[j].setEnabled(false); |
| | 375 | |
| | 376 | if (control.get(c) == null) { |
| | 377 | Panel newPanel = new Panel("Controls for " + c.getCaption()); |
| | 378 | newPanel.setLayout(new GridLayout(3, 6)); |
| | 379 | |
| | 380 | final int[] values = new int[6]; |
| | 381 | Arrays.fill(values, -1); |
| | 382 | |
| | 383 | final CheckBox[] checkBoxArray = new CheckBox[6]; |
| | 384 | final Slider[] sliderArray = new Slider[6]; |
| | 385 | |
| | 386 | checkBoxArray[0] = new CheckBox("Left"); |
| | 387 | sliderArray[0] = new Slider(0, 100, 1); |
| | 388 | |
| | 389 | checkBoxArray[1] = new CheckBox("Top"); |
| | 390 | sliderArray[1] = new Slider(0, 100, 1); |
| | 391 | |
| | 392 | checkBoxArray[2] = new CheckBox("Width"); |
| | 393 | sliderArray[2] = new Slider(0, 100, 1); |
| | 394 | |
| | 395 | checkBoxArray[3] = new CheckBox("Height"); |
| | 396 | sliderArray[3] = new Slider(0, 100, 1); |
| | 397 | |
| | 398 | checkBoxArray[4] = new CheckBox("Right"); |
| | 399 | sliderArray[4] = new Slider(0, 100, 1); |
| | 400 | |
| | 401 | checkBoxArray[5] = new CheckBox("Bottom"); |
| | 402 | sliderArray[5] = new Slider(0, 100, 1); |
| | 403 | |
| | 404 | final Label[] labelArray = new Label[6]; |
| | 405 | |
| | 406 | for (int i = 0; i < checkBoxArray.length; i++) { |
| | 407 | final int j = i; |
| | 408 | |
| | 409 | labelArray[j] = new Label("-1"); |
| | 410 | labelArray[j].setEnabled(false); |
| | 411 | checkBoxArray[j].setImmediate(true); |
| | 412 | sliderArray[j].setImmediate(true); |
| | 413 | sliderArray[j].setEnabled(false); |
| | 414 | |
| | 415 | checkBoxArray[j].addListener(new ValueChangeListener() { |
| | 416 | public void valueChange(ValueChangeEvent event) { |
| | 417 | Boolean isChecked = (Boolean) checkBoxArray[j] |
| | 418 | .getValue(); |
| | 419 | if (isChecked.booleanValue()) { |
| | 420 | sliderArray[j].setEnabled(true); |
| | 421 | labelArray[j].setEnabled(true); |
| | 422 | } else { |
| | 423 | values[j] = -1; |
| | 424 | labelArray[j].setValue(new Integer(values[j])); |
| | 425 | sliderArray[j].setEnabled(false); |
| | 426 | labelArray[j].setEnabled(false); |
| | 427 | |
| | 428 | CoordinateLayout.Coordinates newCoord = new CoordinateLayout.Coordinates( |
| | 429 | values[0], values[1], values[2], values[3], |
| | 430 | values[4], values[5]); |
| | 431 | newCoord.setUnitsPercent(true, true, true, true, |
| | 432 | true, true); |
| | 433 | coordinateLayout.setCoordinates(c, newCoord); |
| | 434 | } |
| | 435 | } |
| | 436 | }); |
| | 437 | |
| | 438 | sliderArray[j].addListener(new ValueChangeListener() { |
| | 439 | public void valueChange(ValueChangeEvent event) { |
| | 440 | Double newValue = (Double) event.getProperty() |
| | 441 | .getValue(); |
| | 442 | values[j] = (int) newValue.doubleValue(); |