Changeset 5276

Show
Ignore:
Timestamp:
08/27/08 10:43:01 (3 months ago)
Author:
risto.yrjana@…
Message:

Updated test case, added internal caption handling, fixed IE issues

Location:
incubator/widgets/coordinatelayout/src/com/itmill/toolkit
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • incubator/widgets/coordinatelayout/src/com/itmill/toolkit/tests/tickets/Ticket1267.java

    r5258 r5276  
    22 
    33import java.util.Arrays; 
     4import java.util.HashMap; 
    45 
    56import com.itmill.toolkit.Application; 
     7import com.itmill.toolkit.data.Item; 
    68import com.itmill.toolkit.data.Property.ValueChangeEvent; 
    79import com.itmill.toolkit.data.Property.ValueChangeListener; 
     10import com.itmill.toolkit.data.util.IndexedContainer; 
     11import com.itmill.toolkit.data.validator.StringLengthValidator; 
     12import com.itmill.toolkit.terminal.ThemeResource; 
    813import com.itmill.toolkit.ui.Button; 
    914import com.itmill.toolkit.ui.CheckBox; 
    1015import com.itmill.toolkit.ui.Component; 
    1116import com.itmill.toolkit.ui.CoordinateLayout; 
    12 import com.itmill.toolkit.ui.DateField; 
    13 import com.itmill.toolkit.ui.ExpandLayout; 
    1417import com.itmill.toolkit.ui.GridLayout; 
    1518import com.itmill.toolkit.ui.Label; 
    16 import com.itmill.toolkit.ui.Layout; 
     19import com.itmill.toolkit.ui.MenuBar; 
    1720import com.itmill.toolkit.ui.OrderedLayout; 
    1821import com.itmill.toolkit.ui.Panel; 
    19 import com.itmill.toolkit.ui.Select; 
     22import com.itmill.toolkit.ui.PopupView; 
    2023import com.itmill.toolkit.ui.Slider; 
    2124import com.itmill.toolkit.ui.Table; 
    2225import com.itmill.toolkit.ui.TextField; 
     26import com.itmill.toolkit.ui.Tree; 
    2327import com.itmill.toolkit.ui.Window; 
     28import com.itmill.toolkit.ui.CoordinateLayout.Coordinates; 
     29import com.itmill.toolkit.ui.MenuBar.Command; 
     30import com.itmill.toolkit.ui.MenuBar.MenuItem; 
     31import com.itmill.toolkit.ui.PopupView.Content; 
     32import com.itmill.toolkit.ui.Window.CloseEvent; 
     33import com.itmill.toolkit.ui.Window.CloseListener; 
    2434 
    2535public class Ticket1267 extends Application { 
    2636 
    27     final CoordinateLayout coordinateLayout = new CoordinateLayout(); 
     37    CoordinateLayout coordinateLayout = new CoordinateLayout(); 
     38    Window main = new Window("Coordinatelayout demo"); 
     39    HashMap<Component, Panel> control = new HashMap<Component, Panel>(); 
     40    // Components 
     41    Window controlPanel = new Window("Control panel for components"); 
     42    Table table = new Table("Test table"); 
     43    Panel panel = new Panel("CoordinateLayout panel"); 
     44    Tree tree = new Tree("Test tree"); 
     45    TextField textField = new TextField("CoordinateLayout test", 
     46            "TextField in a coordinateLayout"); 
     47    OrderedLayout ol = new OrderedLayout(); 
     48 
     49    IndexedContainer componentContainer = new IndexedContainer(); 
    2850 
    2951    public void init() { 
    3052 
    31         final Window main = new Window("Coordinatelayout demo"); 
    32  
    33         // SplitPanel sPanel = new 
    34         // SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); 
    35  
     53        // Setup component container 
     54        componentContainer 
     55                .addContainerProperty("Component", String.class, null); 
     56        componentContainer.addContainerProperty("Coordinates", PopupView.class, 
     57                null); 
     58        // Setup table 
     59        table.setContainerDataSource(componentContainer); 
     60        table.setIcon(new ThemeResource("icons/16/globe.png")); 
     61 
     62        // Setup panel 
     63 
     64        Button addButton = new Button("Add component"); 
     65        addButton.addListener(new Button.ClickListener() { 
     66            int count = 0; 
     67 
     68            public void buttonClick(Button.ClickEvent event) { 
     69                panel.addComponent(new Label("Component nro. " + count++)); 
     70 
     71            } 
     72 
     73        }); 
     74        panel.addComponent(addButton); 
     75 
     76        // Setup textfield 
     77        textField.setImmediate(true); 
     78        textField.setIcon(new ThemeResource("icons/16/document-image.png")); 
     79        textField.setRequired(true); 
     80        textField.addValidator(new StringLengthValidator( 
     81                "5 < String.length() < 10", 5, 10, false)); 
     82 
     83        // Setup menubar 
     84        MenuBar mainMenu = getMainMenuBar(); 
     85 
     86        // Setup control panel window 
     87        controlPanel.addListener(new CloseListener() { 
     88 
     89            public void windowClose(CloseEvent e) { 
     90                main.removeWindow(e.getWindow()); 
     91 
     92            } 
     93 
     94        }); 
     95 
     96        // Setup coordinatelayout 
     97        Coordinates menuCoords = new Coordinates("0,0,100%,-1"); 
     98        coordinateLayout.addComponent(mainMenu, menuCoords); 
    3699        coordinateLayout.setMargin(true); 
    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            } 
    63340        } 
    64341 
    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        } 
    164347 
    165348    } 
    166349 
     350    private class RemoveCommand implements Command { 
     351 
     352        private Component toRemove; 
     353        private String id; 
     354 
     355        public RemoveCommand(String id, Component toRemove) { 
     356            this.id = id; 
     357            this.toRemove = toRemove; 
     358        } 
     359 
     360        public void menuSelected(MenuItem selectedItem) { 
     361            if (coordinateLayout.contains(toRemove)) { 
     362 
     363                componentContainer.removeItem(id); 
     364                coordinateLayout.removeComponent(toRemove); 
     365                controlPanel.removeComponent(toRemove); 
     366                MenuItem parent = selectedItem.getParent(); 
     367                parent.removeChild(selectedItem); 
     368                controlPanel.removeComponent(getControlPanel(toRemove)); 
     369                control.remove(toRemove); 
     370            } 
     371        } 
     372    } 
     373 
    167374    public Panel getControlPanel(final Component c) { 
    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(); 
    217443 
    218444                        CoordinateLayout.Coordinates newCoord = new CoordinateLayout.Coordinates( 
     
    222448                                true); 
    223449                        coordinateLayout.setCoordinates(c, newCoord); 
     450                        labelArray[j].setValue(new Integer(values[j])); 
    224451                    } 
    225                 } 
    226             }); 
    227  
    228             sliderArray[j].addListener(new ValueChangeListener() { 
    229                 public void valueChange(ValueChangeEvent event) { 
    230                     Double newValue = (Double) event.getProperty().getValue(); 
    231                     values[j] = (int) newValue.doubleValue(); 
    232  
    233                     CoordinateLayout.Coordinates newCoord = new CoordinateLayout.Coordinates( 
    234                             values[0], values[1], values[2], values[3], 
    235                             values[4], values[5]); 
    236                     newCoord 
    237                             .setUnitsPercent(true, true, true, true, true, true); 
    238                     coordinateLayout.setCoordinates(c, newCoord); 
    239                     labelArray[j].setValue(new Integer(values[j])); 
    240                 } 
    241             }); 
     452                }); 
     453            } 
     454 
     455            for (int i = 0; i < sliderArray.length; i++) { 
     456                newPanel.addComponent(checkBoxArray[i]); 
     457                newPanel.addComponent(sliderArray[i]); 
     458                newPanel.addComponent(labelArray[i]); 
     459            } 
     460            control.put(c, newPanel); 
     461            return newPanel; 
     462        } else { 
     463            return control.get(c); 
    242464        } 
    243  
    244         for (int i = 0; i < sliderArray.length; i++) { 
    245             newPanel.addComponent(checkBoxArray[i]); 
    246             newPanel.addComponent(sliderArray[i]); 
    247             newPanel.addComponent(labelArray[i]); 
    248         } 
    249  
    250         return newPanel; 
    251465    } 
    252466} 
  • incubator/widgets/coordinatelayout/src/com/itmill/toolkit/ui/CoordinateLayout.java

    r5264 r5276  
    9393            throw new IllegalArgumentException(); 
    9494  &nbs