Coverage Report - org.argouml.cognitive.ui.DesignIssuesDialog
 
Classes in this File Line Coverage Branch Coverage Complexity
DesignIssuesDialog
0%
0/110
0%
0/12
3
 
 1  
 /* $Id: DesignIssuesDialog.java 17818 2010-01-12 18:39:46Z 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.cognitive.ui;
 40  
 
 41  
 import java.awt.Dimension;
 42  
 import java.awt.GridBagConstraints;
 43  
 import java.awt.GridBagLayout;
 44  
 import java.util.Hashtable;
 45  
 import java.util.List;
 46  
 
 47  
 import javax.swing.BorderFactory;
 48  
 import javax.swing.JLabel;
 49  
 import javax.swing.JPanel;
 50  
 import javax.swing.JScrollPane;
 51  
 import javax.swing.JSlider;
 52  
 import javax.swing.SwingConstants;
 53  
 import javax.swing.event.ChangeEvent;
 54  
 import javax.swing.event.ChangeListener;
 55  
 
 56  
 import org.argouml.cognitive.Decision;
 57  
 import org.argouml.cognitive.DecisionModel;
 58  
 import org.argouml.cognitive.Designer;
 59  
 import org.argouml.cognitive.Translator;
 60  
 import org.argouml.util.ArgoDialog;
 61  
 
 62  
 
 63  
 /** A dialog to set the priorities for decisions. These will be evaluated
 64  
  *  against the critics, so that the user will only see todo items which match
 65  
  *  the priorities for a certain decision.
 66  
  */
 67  
 public class DesignIssuesDialog extends ArgoDialog implements ChangeListener {
 68  
 
 69  
     ////////////////////////////////////////////////////////////////
 70  
     // constants
 71  
     ////////////////////////////////////////////////////////////////
 72  
     // instance variables
 73  0
     private JPanel  mainPanel = new JPanel();
 74  0
     private Hashtable<JSlider, Decision> slidersToDecisions = 
 75  
         new Hashtable<JSlider, Decision>();
 76  0
     private Hashtable<JSlider, JLabel> slidersToDigits = 
 77  
         new Hashtable<JSlider, JLabel>();
 78  
 
 79  
     ////////////////////////////////////////////////////////////////
 80  
     // constructors
 81  
 
 82  
     /**
 83  
      * The constructor.
 84  
      */
 85  
     public DesignIssuesDialog() {
 86  0
         super(Translator.localize("dialog.title.design-issues"), false);
 87  
 
 88  0
         final int width = 320;
 89  0
         final int height = 400;
 90  
 
 91  0
         initMainPanel();
 92  
 
 93  0
         JScrollPane scroll = new JScrollPane(mainPanel);
 94  0
         scroll.setPreferredSize(new Dimension(width, height));
 95  
 
 96  0
         setContent(scroll);
 97  0
     }
 98  
 
 99  
 
 100  
     private void initMainPanel() {
 101  0
         DecisionModel dm = Designer.theDesigner().getDecisionModel();
 102  0
         List<Decision> decs = dm.getDecisionList();
 103  
 
 104  0
         GridBagLayout gb = new GridBagLayout();
 105  0
         mainPanel.setLayout(gb);
 106  0
         mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
 107  
 
 108  0
         GridBagConstraints c = new GridBagConstraints();
 109  0
         c.fill = GridBagConstraints.BOTH;
 110  0
         c.weightx = 1.0;
 111  0
         c.weighty = 0.0;
 112  0
         c.ipadx = 3; c.ipady = 3;
 113  
 
 114  
 
 115  0
         c.gridy = 0;
 116  0
         c.gridx = 0;
 117  0
         c.gridwidth = 1;
 118  0
         JLabel decTitleLabel = new JLabel(
 119  
             Translator.localize("label.decision"));
 120  0
         gb.setConstraints(decTitleLabel, c);
 121  0
         mainPanel.add(decTitleLabel);
 122  
 
 123  0
         c.gridy = 0;
 124  0
         c.gridx = 2;
 125  0
         c.gridwidth = 8;
 126  0
         JLabel priLabel = new JLabel(
 127  
             Translator.localize("label.decision-priority"));
 128  0
         gb.setConstraints(priLabel, c);
 129  0
         mainPanel.add(priLabel);
 130  
 
 131  0
         c.gridy = 1;
 132  0
         c.gridx = 2;
 133  0
         c.gridwidth = 2;
 134  0
         JLabel offLabel = new JLabel(Translator.localize("label.off"));
 135  0
         gb.setConstraints(offLabel, c);
 136  0
         mainPanel.add(offLabel);
 137  
 
 138  0
         c.gridy = 1;
 139  0
         c.gridx = 4;
 140  0
         c.gridwidth = 2;
 141  0
         JLabel lowLabel = new JLabel(Translator.localize("label.low"));
 142  0
         gb.setConstraints(lowLabel, c);
 143  0
         mainPanel.add(lowLabel);
 144  
 
 145  0
         c.gridy = 1;
 146  0
         c.gridx = 6;
 147  0
         c.gridwidth = 2;
 148  0
         JLabel mediumLabel = new JLabel(Translator.localize("label.medium"));
 149  0
         gb.setConstraints(mediumLabel, c);
 150  0
         mainPanel.add(mediumLabel);
 151  
 
 152  0
         c.gridy = 1;
 153  0
         c.gridx = 8;
 154  0
         c.gridwidth = 2;
 155  0
         JLabel highLabel = new JLabel(Translator.localize("label.high"));
 156  0
         gb.setConstraints(highLabel, c);
 157  0
         mainPanel.add(highLabel);
 158  
 
 159  
 
 160  0
         c.gridy = 2;
 161  0
         for (Decision d : decs) {
 162  0
             JLabel decLabel = new JLabel(d.getName());
 163  0
             JLabel valueLabel = new JLabel(getValueText(d.getPriority()));
 164  0
             JSlider decSlide =
 165  
                 new JSlider(SwingConstants.HORIZONTAL,
 166  
                             1, 4, (d.getPriority() == 0 ? 4 : d.getPriority()));
 167  
 
 168  0
             decSlide.setInverted(true);
 169  0
             decSlide.setMajorTickSpacing(1);
 170  0
             decSlide.setPaintTicks(true);
 171  0
             decSlide.setSnapToTicks(true);
 172  
             // decSlide.setPaintLabels(true);
 173  0
             decSlide.addChangeListener(this);
 174  0
             Dimension origSize = decSlide.getPreferredSize();
 175  0
             Dimension smallSize =
 176  
                 new Dimension(origSize.width / 2, origSize.height);
 177  0
             decSlide.setSize(smallSize);
 178  0
             decSlide.setPreferredSize(smallSize);
 179  
 
 180  0
             slidersToDecisions.put(decSlide, d);
 181  0
             slidersToDigits.put(decSlide, valueLabel);
 182  
 
 183  0
             c.gridx = 0;
 184  0
             c.gridwidth = 1;
 185  0
             c.weightx = 0.0;
 186  0
             c.ipadx = 3;
 187  0
             gb.setConstraints(decLabel, c);
 188  0
             mainPanel.add(decLabel);
 189  
 
 190  0
             c.gridx = 1;
 191  0
             c.gridwidth = 1;
 192  0
             c.weightx = 0.0;
 193  0
             c.ipadx = 0;
 194  0
             gb.setConstraints(valueLabel, c);
 195  0
             mainPanel.add(valueLabel);
 196  
 
 197  0
             c.gridx = 2;
 198  0
             c.gridwidth = 8;
 199  0
             c.weightx = 1.0;
 200  0
             gb.setConstraints(decSlide, c);
 201  0
             mainPanel.add(decSlide);
 202  
 
 203  0
             c.gridy++;
 204  0
         }
 205  0
     }
 206  
 
 207  
     ////////////////////////////////////////////////////////////////
 208  
     // event handlers
 209  
 
 210  
     /*
 211  
      * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
 212  
      */
 213  
     public void stateChanged(ChangeEvent ce) {
 214  0
         JSlider srcSlider = (JSlider) ce.getSource();
 215  0
         Decision d = slidersToDecisions.get(srcSlider);
 216  0
         JLabel valLab = slidersToDigits.get(srcSlider);
 217  0
         int pri = srcSlider.getValue();
 218  0
         d.setPriority((pri == 4) ? 0 : pri);
 219  0
         valLab.setText(getValueText(pri));
 220  0
     }
 221  
 
 222  
     private String getValueText(int priority) {
 223  0
         String label = "";
 224  0
         switch(priority) {
 225  
         case 1:
 226  0
             label = "    1";
 227  0
             break;
 228  
         case 2:
 229  0
             label = "    2";
 230  0
             break;
 231  
         case 3:
 232  0
             label = "    3";
 233  0
             break;
 234  
         case 0:
 235  
         case 4:
 236  0
             label = Translator.localize("label.off");
 237  
             break;
 238  
         }
 239  0
         return label;
 240  
     }
 241  
 
 242  
 }
 243  
 
 244  
 
 245  
 
 246  
 ////////////////////////////////////////////////////////////////