Math2mat

/home/ythoma/docs/math2mat/svn/wp1/framework/m2mGUI/src/m2m/frontend/dynamicview/figure/LoopIteratorPropertyFigure.java

Go to the documentation of this file.
00001 
00015 package m2m.frontend.dynamicview.figure;
00016 
00017 import java.util.ArrayList;
00018 
00019 import m2m.backend.buildingblocks.BuildingBlock;
00020 import m2m.backend.buildingblocks.BuildingBlocksManager;
00021 import m2m.backend.structure.Operation;
00022 import m2m.frontend.dynamicview.model.*;
00023 
00024 import org.eclipse.draw2d.ActionEvent;
00025 import org.eclipse.draw2d.ActionListener;
00026 import org.eclipse.draw2d.CheckBox;
00027 import org.eclipse.draw2d.ColorConstants;
00028 import org.eclipse.draw2d.Figure;
00029 import org.eclipse.draw2d.Label;
00030 import org.eclipse.draw2d.ToolbarLayout;
00031 import org.eclipse.draw2d.XYLayout;
00032 import org.eclipse.draw2d.geometry.Rectangle;
00033 
00034 
00035 public class LoopIteratorPropertyFigure extends Figure implements ActionListener
00036 {
00040         private Schema schema;
00044         private GraphicLoopIterator graphicLoopIterator;
00048     private XYLayout layout;
00052     private Label labelName = new Label();
00056     private Label labelStart = new Label();
00060     private Label labelIncrementation= new Label();
00064     private Label labelEnd = new Label();
00068     private CheckBox checkBoxMonitor = new CheckBox("Monitor mode");
00072     private Label labelNameOperation = new Label();
00076     private Label labelDescriptionBlock = new Label();
00080     private ArrayList<BuildingBlock> blockList = new ArrayList<BuildingBlock>();
00084     private ArrayList<CheckBox> checkBoxesBlockList = new ArrayList<CheckBox>();
00088     private CheckBox checkBoxSelectAll = new CheckBox("Select for all same operation");
00089     
00090     
00094     public LoopIteratorPropertyFigure(Schema schema) 
00095     {
00096         this.schema = schema;
00097         
00098         /* Set the type of layout */
00099         layout = new XYLayout();
00100         setLayoutManager(layout);
00101         
00102         /* Initialisation of the name label */
00103         labelName.setForegroundColor(ColorConstants.black);
00104         add(labelName, ToolbarLayout.VERTICAL); 
00105         setConstraint(labelName, new Rectangle(0, 0, -1, -1));
00106         labelName.setText("Unknown");
00107         
00108         /* Initialisation of the start label */
00109         labelStart.setForegroundColor(ColorConstants.black);
00110         add(labelStart, ToolbarLayout.VERTICAL); 
00111         setConstraint(labelStart, new Rectangle(0, 30, -1, -1));
00112         labelStart.setText("Unknown");
00113         
00114         /* Initialisation of the incrementation label */
00115         labelIncrementation.setForegroundColor(ColorConstants.black);
00116         add(labelIncrementation, ToolbarLayout.VERTICAL); 
00117         setConstraint(labelIncrementation, new Rectangle(0, 45, -1, -1));
00118         labelIncrementation.setText("Unknown");
00119         
00120         /* Initialisation of the end label */
00121         labelEnd.setForegroundColor(ColorConstants.black);
00122         add(labelEnd, ToolbarLayout.VERTICAL); 
00123         setConstraint(labelEnd, new Rectangle(0, 60, -1, -1));
00124         labelEnd.setText("Unknown");
00125         
00126         /* Initialisation of the checkBoxMonitor */
00127         add(checkBoxMonitor);
00128         setConstraint(checkBoxMonitor, new Rectangle(0, 85, -1, -1));
00129         checkBoxMonitor.addActionListener(this);
00130         
00131         /* Initialisation of the figure */
00132         setOpaque(true);     
00133         setBackgroundColor(ColorConstants.menuBackground);
00134         setForegroundColor(ColorConstants.menuForeground);
00135         
00136         /* Initialisation of the labelName */
00137         labelNameOperation.setForegroundColor(ColorConstants.black);
00138         add(labelNameOperation, ToolbarLayout.VERTICAL); 
00139         setConstraint(labelNameOperation, new Rectangle(0, 150, -1, -1));
00140         labelNameOperation.setText("Unknown");
00141 
00142         /* Initialisation of the labelDescriptionBlock */
00143         labelDescriptionBlock.setForegroundColor(ColorConstants.black);
00144         add(labelDescriptionBlock, ToolbarLayout.VERTICAL); 
00145         setConstraint(labelDescriptionBlock, new Rectangle(0, 300, -1, -1));
00146         labelDescriptionBlock.setText("Unknown");
00147         
00148         /* Initialisation of the checkBoxSelectAll */
00149         add(checkBoxSelectAll);
00150         setConstraint(checkBoxSelectAll, new Rectangle(0, 180, -1, -1));
00151         checkBoxSelectAll.addActionListener(this);
00152     }
00153     
00154     
00159     public void setProperty(GraphicLoopIterator graphicLoopIterator)
00160     {
00161         int space = 180;
00162         this.graphicLoopIterator = graphicLoopIterator;
00163         labelNameOperation.setText("Name : " + graphicLoopIterator.getIterOperation().getName());
00164         
00165         // Initialize the state of the checkBox 
00166         checkBoxMonitor.setSelected(graphicLoopIterator.getMonitor());
00167         
00168         /* Get and show the name of GraphicIf properties */
00169         labelName.setText("Name : " + graphicLoopIterator.getName());
00170         labelStart.setText("Start value : " + graphicLoopIterator.getStartInitialisation());
00171         labelIncrementation.setText("Increment value : " + graphicLoopIterator.getIncrementation());
00172         labelEnd.setText("End value : " + graphicLoopIterator.getEndCondition());
00173         
00174         if(((Operation)(graphicLoopIterator.getIterOperation())).getBlock() == null) {
00175                 if(getChildren().contains(checkBoxSelectAll))
00176                         remove(checkBoxSelectAll); 
00177                 if(getChildren().contains(labelDescriptionBlock))
00178                         remove(labelDescriptionBlock); 
00179                 for(CheckBox cb : checkBoxesBlockList)
00180                         if(getChildren().contains(cb))
00181                                 remove(cb);     
00182                         System.out.println("There is no bloc for this operation. Please check the lib path.");
00183                 }       
00184                 else {
00185                         add(labelDescriptionBlock, ToolbarLayout.VERTICAL); 
00186                 for(CheckBox cb : checkBoxesBlockList)
00187                         if(getChildren().contains(cb))
00188                                 remove(cb);
00189                         checkBoxesBlockList.removeAll(checkBoxesBlockList); 
00190                         /* Get all possible BuildingBlocks for this operation */
00191                 blockList.removeAll(blockList);
00192                 Operation opElement = (Operation)(graphicLoopIterator.getIterOperation());              
00193                 for(BuildingBlock block : BuildingBlocksManager.getInstance().blockNamed(opElement.getOpName()))
00194                         if(block.numType() == schema.getDataType())
00195                                 blockList.add(block);                                           
00196                 
00197                 if(blockList.size() != 0)
00198                 {
00199                         /* Add and initialize the checkBoxSelectAll */
00200                         add(checkBoxSelectAll); 
00201                         setConstraint(checkBoxSelectAll, new Rectangle(0, space, -1, -1));
00202                         checkBoxSelectAll.setSelected(graphicLoopIterator.getSelectAll());
00203                         space += 15;
00204                 }               
00205                 
00206                 /* Create CheckBoxes for the blockList */
00207                 for(BuildingBlock block : blockList)
00208                 {               
00209                         checkBoxesBlockList.add(new CheckBox(block.entityName()));
00210                         add(checkBoxesBlockList.get(blockList.indexOf(block)));
00211                         setConstraint(checkBoxesBlockList.get(blockList.indexOf(block)), new Rectangle(20, space, -1, -1));
00212                         checkBoxesBlockList.get(blockList.indexOf(block)).addActionListener(this);
00213                         if(opElement.getBlock() == block)
00214                                 checkBoxesBlockList.get(blockList.indexOf(block)).setSelected(true);
00215                         space += 15;
00216                 }
00217                         
00218                 if(!blockList.contains(opElement.getBlock()))
00219                         {
00220                                 /* Set the default buildingBlock */
00221                                 checkBoxesBlockList.get(0).setSelected(true);
00222                                 opElement.setBlock(blockList.get(0));
00223                         }
00224                         
00225                         setConstraint(labelDescriptionBlock, new Rectangle(0, space+15, -1, -1));
00226                         labelDescriptionBlock.setText("--------------------------------------\n" +
00227                                                                                   "Function name\t : " + opElement.getBlock().functionName() + "\n" +
00228                                                                                   "Entity name\t : " + opElement.getBlock().entityName() + "\n" +
00229                                                                                   "Author\t\t : " + opElement.getBlock().author() + "\n" +
00230                                                                                   "Description\t : " + opElement.getBlock().description()+ "\n" +
00231                                                                                   "--------------------------------------\n");
00232                 }
00233     }
00234 
00235 
00240         @Override
00241         public void actionPerformed(ActionEvent arg) 
00242         {
00243                 graphicLoopIterator.setMonitor(checkBoxMonitor.isSelected());
00244                 
00245                 /* Update the state of all checkBoxesBlockList */
00246                 if(checkBoxesBlockList.contains(arg.getSource()))
00247                         for(int i = 0; i < blockList.size(); i++)
00248                                 if(checkBoxesBlockList.get(i) == arg.getSource())
00249                                 {
00250                                         checkBoxesBlockList.get(i).setSelected(true);
00251                                         graphicLoopIterator.getIterOperation().setBlock(blockList.get(i));
00252                                         labelDescriptionBlock.setText("--------------------------------------\n" +
00253                                                           "Function name\t : " + graphicLoopIterator.getIterOperation().getBlock().functionName() + "\n" +
00254                                                           "Entity name\t : " + graphicLoopIterator.getIterOperation().getBlock().entityName() + "\n" +
00255                                                           "Author\t\t : " + graphicLoopIterator.getIterOperation().getBlock().author() + "\n" +
00256                                                           "Description\t : " + graphicLoopIterator.getIterOperation().getBlock().description()+ "\n" +
00257                                                           "--------------------------------------\n");
00258                                 }
00259                                 else
00260                                         checkBoxesBlockList.get(i).setSelected(false);          
00261                 
00262                 /* Get the selected building block */
00263                 BuildingBlock block = null;
00264         for(CheckBox cb : checkBoxesBlockList)  
00265                 if(cb.isSelected())
00266                         block = blockList.get(checkBoxesBlockList.indexOf(cb));
00267         
00268         /* Set the building block for all same operations if the is checkBoxSelectAll selected */
00269                 if(checkBoxSelectAll.isSelected())
00270                 {
00271                 for(Node node : schema.getAllNodes())
00272                 {
00273                                 if(node instanceof GraphicOperation && ((Operation)(node.getElement())).getOpName() == block.functionName())
00274                                 {
00275                                         ((Operation)(node.getElement())).setBlock(block);
00276                                         ((GraphicOperation)node).setSelectAll(true);
00277                                 }
00278                                 else if(node instanceof GraphicLoopIterator && ((GraphicLoopIterator)node).getIterOperation().getOpName() == block.functionName())
00279                                 {
00280                                         ((GraphicLoopIterator)node).getIterOperation().setBlock(block);
00281                                         ((GraphicLoopIterator)node).setSelectAll(true);
00282                                 }
00283                 }
00284                 }
00285                 else
00286                 for(Node node : schema.getAllNodes())
00287                 {
00288                                 if(node instanceof GraphicOperation && ((Operation)(node.getElement())).getOpName() == block.functionName())
00289                                         ((GraphicOperation)node).setSelectAll(false);
00290                                 else if(node instanceof GraphicLoopIterator && ((GraphicLoopIterator)node).getIterOperation().getOpName() == block.functionName())
00291                                         ((GraphicLoopIterator)node).setSelectAll(false);
00292                 }
00293         }
00294 }
00295 
 All Classes Namespaces Files Functions Variables Enumerations