Coverage Report - org.argouml.uml.reveng.ConfigPanelExtension
 
Classes in this File Line Coverage Branch Coverage Complexity
ConfigPanelExtension
0%
0/80
0%
0/14
2.167
 
 1  
 /* $Id: ConfigPanelExtension.java 17870 2010-01-12 20:49:32Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    tfmorris
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2006 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies.  This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.uml.reveng;
 40  
 
 41  
 import java.awt.GridBagConstraints;
 42  
 import java.awt.GridBagLayout;
 43  
 import java.awt.Insets;
 44  
 
 45  
 import javax.swing.ButtonGroup;
 46  
 import javax.swing.JCheckBox;
 47  
 import javax.swing.JLabel;
 48  
 import javax.swing.JPanel;
 49  
 import javax.swing.JRadioButton;
 50  
 import javax.swing.JTextField;
 51  
 
 52  
 import org.argouml.configuration.Configuration;
 53  
 import org.argouml.configuration.ConfigurationKey;
 54  
 import org.argouml.i18n.Translator;
 55  
 
 56  
 /**
 57  
  * Default extended configuration panel for file import.
 58  
  */
 59  
 public class ConfigPanelExtension extends JPanel {
 60  
 
 61  
     /**
 62  
      * Key for RE extended settings: model attributes as:
 63  
      * 0: attibutes
 64  
      * 1: associations
 65  
      */
 66  0
     public static final ConfigurationKey KEY_IMPORT_EXTENDED_MODEL_ATTR =
 67  
         Configuration
 68  
             .makeKey("import", "extended", "java", "model", "attributes");
 69  
 
 70  
     /**
 71  
      * Key for RE extended settings: model arrays as:
 72  
      * 0: datatype
 73  
      * 1: associations
 74  
      */
 75  0
     public static final ConfigurationKey KEY_IMPORT_EXTENDED_MODEL_ARRAYS =
 76  
         Configuration.makeKey("import", "extended", "java", "model", "arrays");
 77  
 
 78  
     /**
 79  
      * Key for RE extended settings: flag for modelling of listed collections,
 80  
      * if to model them as associations with multiplicity *.
 81  
      */
 82  0
     public static final ConfigurationKey KEY_IMPORT_EXTENDED_COLLECTIONS_FLAG =
 83  
         Configuration
 84  
             .makeKey("import", "extended", "java", "collections", "flag");
 85  
 
 86  
     /**
 87  
      * Key for RE extended settings: list of collections, that will be modelled
 88  
      * as associations with multiplicity *.
 89  
      */
 90  0
     public static final ConfigurationKey KEY_IMPORT_EXTENDED_COLLECTIONS_LIST =
 91  
         Configuration
 92  
             .makeKey("import", "extended", "java", "collections", "list");
 93  
 
 94  
     /**
 95  
      * Key for RE extended settings: flag for modelling of listed collections,
 96  
      * if to model them as ordered associations with multiplicity *.
 97  
      */
 98  0
     public static final ConfigurationKey KEY_IMPORT_EXTENDED_ORDEREDCOLLS_FLAG =
 99  
         Configuration
 100  
             .makeKey("import", "extended", "java", "orderedcolls", "flag");
 101  
 
 102  
     /**
 103  
      * Key for RE extended settings: list of collections, that will be modelled
 104  
      * as ordered associations with multiplicity *.
 105  
      */
 106  0
     public static final ConfigurationKey KEY_IMPORT_EXTENDED_ORDEREDCOLLS_LIST =
 107  
         Configuration
 108  
             .makeKey("import", "extended", "java", "orderedcolls", "list");
 109  
 
 110  
     private JPanel configPanel;
 111  
 
 112  
     private JRadioButton attribute;
 113  
 
 114  
     private JRadioButton datatype;
 115  
 
 116  
     private JCheckBox modelcollections, modelorderedcollections;
 117  
 
 118  
     private JTextField collectionlist, orderedcollectionlist;
 119  
 
 120  
     /**
 121  
      * Construct a new default configuration extension panel.
 122  
      */
 123  0
     public ConfigPanelExtension() {
 124  
 
 125  0
         configPanel = this;
 126  0
         configPanel.setLayout(new GridBagLayout());
 127  
 
 128  0
         JLabel attributeLabel1 =
 129  
             new JLabel(
 130  
                     Translator.localize("action.import-java-attr-model"));
 131  0
         configPanel.add(attributeLabel1,
 132  
                 createGridBagConstraints(true, false, false));
 133  0
         ButtonGroup group1 = new ButtonGroup();
 134  0
         attribute =
 135  
             new JRadioButton(
 136  
                     Translator.localize("action.import-java-UML-attr"));
 137  0
         group1.add(attribute);
 138  0
         configPanel.add(attribute,
 139  
                 createGridBagConstraints(false, false, false));
 140  0
         JRadioButton association =
 141  
             new JRadioButton(
 142  
                     Translator.localize("action.import-java-UML-assoc"));
 143  0
         group1.add(association);
 144  0
         configPanel.add(association,
 145  
                 createGridBagConstraints(false, true, false));
 146  0
         String modelattr =
 147  
             Configuration.getString(KEY_IMPORT_EXTENDED_MODEL_ATTR);
 148  0
         if ("1".equals(modelattr)) {
 149  0
             association.setSelected(true);
 150  
         } else {
 151  0
             attribute.setSelected(true);
 152  
         }
 153  
         
 154  0
         JLabel attributeLabel2 =
 155  
             new JLabel(
 156  
                     Translator.localize("action.import-java-array-model"));
 157  0
         configPanel.add(attributeLabel2,
 158  
                 createGridBagConstraints(true, false, false));
 159  0
         ButtonGroup group2 = new ButtonGroup();
 160  0
         datatype =
 161  
             new JRadioButton(
 162  
                     Translator.localize(
 163  
                             "action.import-java-array-model-datatype"));
 164  0
         group2.add(datatype);
 165  0
         configPanel.add(datatype,
 166  
                 createGridBagConstraints(false, false, false));
 167  0
         JRadioButton multi =
 168  
             new JRadioButton(
 169  
                     Translator.localize(
 170  
                     "action.import-java-array-model-multi"));
 171  0
         group2.add(multi);
 172  0
         configPanel.add(multi,
 173  
                 createGridBagConstraints(false, true, false));
 174  0
         String modelarrays =
 175  
             Configuration.getString(KEY_IMPORT_EXTENDED_MODEL_ARRAYS);
 176  0
         if ("1".equals(modelarrays)) {
 177  0
             multi.setSelected(true);
 178  
         } else {
 179  0
             datatype.setSelected(true);
 180  
         }
 181  
 
 182  0
         String s = Configuration
 183  
                 .getString(KEY_IMPORT_EXTENDED_COLLECTIONS_FLAG);
 184  0
         boolean flag = ("true".equals(s));
 185  0
         modelcollections =
 186  
             new JCheckBox(Translator.localize(
 187  
                     "action.import-option-model-collections"), flag);
 188  0
         configPanel.add(modelcollections,
 189  
                 createGridBagConstraints(true, false, false));
 190  
 
 191  0
         s = Configuration.getString(KEY_IMPORT_EXTENDED_COLLECTIONS_LIST);
 192  0
         collectionlist = new JTextField(s);
 193  0
         configPanel.add(collectionlist,
 194  
                 createGridBagConstraints(false, false, true));
 195  0
         JLabel listLabel =
 196  
             new JLabel(
 197  
                     Translator.localize("action.import-comma-separated-names"));
 198  0
         configPanel.add(listLabel,
 199  
                 createGridBagConstraints(false, true, false));
 200  
 
 201  0
         s = Configuration.getString(KEY_IMPORT_EXTENDED_ORDEREDCOLLS_FLAG);
 202  0
         flag = ("true".equals(s));
 203  0
         modelorderedcollections =
 204  
             new JCheckBox(Translator.localize(
 205  
                     "action.import-option-model-ordered-collections"), flag);
 206  0
         configPanel.add(modelorderedcollections,
 207  
                 createGridBagConstraints(true, false, false));
 208  
 
 209  0
         s = Configuration.getString(KEY_IMPORT_EXTENDED_ORDEREDCOLLS_LIST);
 210  0
         orderedcollectionlist = new JTextField(s);
 211  0
         configPanel.add(orderedcollectionlist,
 212  
                 createGridBagConstraints(false, false, true));
 213  0
         listLabel =
 214  
             new JLabel(
 215  
                     Translator.localize("action.import-comma-separated-names"));
 216  0
         configPanel.add(listLabel,
 217  
                 createGridBagConstraintsFinal());
 218  
 
 219  
         // TODO: Get the list of extended settings from the current
 220  
         // language importer and add those too
 221  0
     }
 222  
 
 223  
 
 224  
     /**
 225  
      * Create a GridBagConstraints object to use with the layout.
 226  
      * 
 227  
      * @param topInset true to use a top inset 
 228  
      * @param bottomInset true to use a bottom inset
 229  
      * @param fill true to fill (horizontally)
 230  
      * @return the grid bag constraints
 231  
      */
 232  
     private GridBagConstraints createGridBagConstraints(boolean topInset,
 233  
             boolean bottomInset, boolean fill) {
 234  0
         GridBagConstraints gbc = new GridBagConstraints();
 235  0
         gbc.gridx = GridBagConstraints.RELATIVE;
 236  0
         gbc.gridy = GridBagConstraints.RELATIVE;
 237  0
         gbc.gridwidth = GridBagConstraints.REMAINDER;
 238  0
         gbc.gridheight = 1;
 239  0
         gbc.weightx = 1.0;
 240  0
         gbc.weighty = 0.0;
 241  0
         gbc.anchor = GridBagConstraints.NORTHWEST;
 242  0
         gbc.fill = fill ? GridBagConstraints.HORIZONTAL
 243  
                 : GridBagConstraints.NONE;
 244  0
         gbc.insets = 
 245  
             new Insets(
 246  
                     topInset ? 5 : 0, 
 247  
                     5, 
 248  
                     bottomInset ? 5 : 0, 
 249  
                     5);
 250  0
         gbc.ipadx = 0;
 251  0
         gbc.ipady = 0;
 252  0
         return gbc;
 253  
     }
 254  
 
 255  
     /**
 256  
      * A GridBagConstraints for the last item to take up the rest of the space.
 257  
      * @return the GridBagConstraints object
 258  
      */
 259  
     private GridBagConstraints createGridBagConstraintsFinal() {
 260  0
         GridBagConstraints gbc = createGridBagConstraints(false, true, false);
 261  0
         gbc.gridheight = GridBagConstraints.REMAINDER;
 262  0
         gbc.weighty = 1.0;
 263  0
         return gbc;
 264  
     }
 265  
 
 266  
     /**
 267  
      * @return the attribute radio button
 268  
      */
 269  
     public JRadioButton getAttribute() {
 270  0
         return attribute;
 271  
     }
 272  
 
 273  
     /**
 274  
      * @return the datatype radio button
 275  
      */
 276  
     public JRadioButton getDatatype() {
 277  0
         return datatype;
 278  
     }
 279  
 
 280  
     public void disposeDialog() {
 281  0
         Configuration.setString(KEY_IMPORT_EXTENDED_MODEL_ATTR,
 282  
                 String.valueOf(getAttribute().isSelected() ? "0" : "1"));
 283  0
         Configuration.setString(KEY_IMPORT_EXTENDED_MODEL_ARRAYS,
 284  
                 String.valueOf(getDatatype().isSelected() ? "0" : "1"));
 285  0
         Configuration.setString(KEY_IMPORT_EXTENDED_COLLECTIONS_FLAG,
 286  
                 String.valueOf(modelcollections.isSelected()));
 287  0
         Configuration.setString(KEY_IMPORT_EXTENDED_COLLECTIONS_LIST,
 288  
                 String.valueOf(collectionlist.getText()));
 289  0
         Configuration.setString(KEY_IMPORT_EXTENDED_ORDEREDCOLLS_FLAG,
 290  
                 String.valueOf(modelorderedcollections.isSelected()));
 291  0
         Configuration.setString(KEY_IMPORT_EXTENDED_ORDEREDCOLLS_LIST,
 292  
                 String.valueOf(orderedcollectionlist.getText()));
 293  0
     }
 294  
 }