Coverage Report - org.argouml.cognitive.ui.WizStepChoice
 
Classes in this File Line Coverage Branch Coverage Complexity
WizStepChoice
0%
0/79
0%
0/10
3
 
 1  
 /* $Id: WizStepChoice.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-2007 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.GridBagConstraints;
 42  
 import java.awt.GridBagLayout;
 43  
 import java.awt.event.ActionEvent;
 44  
 import java.util.ArrayList;
 45  
 import java.util.List;
 46  
 
 47  
 import javax.swing.JLabel;
 48  
 import javax.swing.JRadioButton;
 49  
 import javax.swing.JTextArea;
 50  
 import javax.swing.border.EtchedBorder;
 51  
 
 52  
 import org.argouml.cognitive.critics.Wizard;
 53  
 import org.argouml.swingext.SpacerPanel;
 54  
 
 55  
 
 56  
 /**
 57  
  * A non-modal wizard step that shows instructions and allows
 58  
  * the user to select one of a series of radio-buttons.
 59  
  *
 60  
  * @see org.argouml.cognitive.Critic
 61  
  * @see org.argouml.cognitive.critics.Wizard
 62  
  */
 63  
 
 64  
 public class WizStepChoice extends WizStep {
 65  0
     private JTextArea instructions = new JTextArea();
 66  0
     private List<String> choices = new ArrayList<String>();
 67  0
     private int selectedIndex = -1;
 68  
 
 69  
 
 70  
     /**
 71  
      * The constructor.
 72  
      *
 73  
      * @param w the wizard
 74  
      * @param instr the instructions
 75  
      * @param ch the choices
 76  
      */
 77  0
     public WizStepChoice(Wizard w, String instr, List<String> ch) {
 78  
         // store wizard?
 79  0
         choices = ch;
 80  
 
 81  0
         instructions.setText(instr);
 82  0
         instructions.setWrapStyleWord(true);
 83  0
         instructions.setEditable(false);
 84  0
         instructions.setBorder(null);
 85  0
         instructions.setBackground(getMainPanel().getBackground());
 86  
 
 87  0
         getMainPanel().setBorder(new EtchedBorder());
 88  
 
 89  0
         GridBagLayout gb = new GridBagLayout();
 90  0
         getMainPanel().setLayout(gb);
 91  
 
 92  0
         GridBagConstraints c = new GridBagConstraints();
 93  0
         c.ipadx = 3; c.ipady = 3;
 94  0
         c.weightx = 0.0; c.weighty = 0.0;
 95  0
         c.anchor = GridBagConstraints.EAST;
 96  
 
 97  0
         JLabel image = new JLabel("");
 98  
         //image.setMargin(new Insets(0, 0, 0, 0));
 99  0
         image.setIcon(getWizardIcon());
 100  0
         image.setBorder(null);
 101  0
         c.gridx = 0;
 102  0
         c.gridheight = GridBagConstraints.REMAINDER;
 103  0
         c.gridy = 0;
 104  0
         c.anchor = GridBagConstraints.NORTH;
 105  0
         gb.setConstraints(image, c);
 106  0
         getMainPanel().add(image);
 107  
 
 108  0
         c.weightx = 1.0;
 109  0
         c.gridx = 2;
 110  0
         c.gridheight = 1;
 111  0
         c.gridwidth = 3;
 112  0
         c.gridy = 0;
 113  0
         c.fill = GridBagConstraints.HORIZONTAL;
 114  0
         gb.setConstraints(instructions, c);
 115  0
         getMainPanel().add(instructions);
 116  
 
 117  0
         c.gridx = 1;
 118  0
         c.gridy = 1;
 119  0
         c.weightx = 0.0;
 120  0
         c.gridwidth = 1;
 121  0
         c.fill = GridBagConstraints.NONE;
 122  0
         SpacerPanel spacer = new SpacerPanel();
 123  0
         gb.setConstraints(spacer, c);
 124  0
         getMainPanel().add(spacer);
 125  
 
 126  0
         c.gridx = 2;
 127  0
         c.weightx = 1.0;
 128  0
         c.anchor = GridBagConstraints.WEST;
 129  0
         c.gridwidth = 1;
 130  0
         int size = ch.size();
 131  0
         for (int i = 0; i < size; i++) {
 132  0
             c.gridy = 2 + i;
 133  0
             String s = ch.get(i);
 134  0
             JRadioButton rb = new JRadioButton(s);
 135  0
             rb.setActionCommand(s);
 136  0
             rb.addActionListener(this);
 137  0
             gb.setConstraints(rb, c);
 138  0
             getMainPanel().add(rb);
 139  
         }
 140  
 
 141  0
         c.gridx = 1;
 142  0
         c.gridy = 3 + ch.size();
 143  0
         c.weightx = 0.0;
 144  0
         c.gridwidth = 1;
 145  0
         c.fill = GridBagConstraints.NONE;
 146  0
         SpacerPanel spacer2 = new SpacerPanel();
 147  0
         gb.setConstraints(spacer2, c);
 148  0
         getMainPanel().add(spacer2);
 149  
 
 150  0
     }
 151  
 
 152  
     /**
 153  
      * @return the index of the selected item
 154  
      */
 155  
     public int getSelectedIndex() {
 156  0
         return selectedIndex;
 157  
     }
 158  
 
 159  
 
 160  
     /*
 161  
      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 162  
      */
 163  
     @Override
 164  
     public void actionPerformed(ActionEvent e) {
 165  0
         super.actionPerformed(e);
 166  0
         if (e.getSource() instanceof JRadioButton) {
 167  0
             String cmd = e.getActionCommand();
 168  0
             if (cmd == null) {
 169  0
                 selectedIndex = -1;
 170  0
                 return;
 171  
             }
 172  0
             int size = choices.size();
 173  0
             for (int i = 0; i < size; i++) {
 174  0
                 String s = choices.get(i);
 175  0
                 if (s.equals(cmd)) {
 176  0
                     selectedIndex = i;
 177  
                 }
 178  
             }
 179  0
             getWizard().doAction();
 180  0
             enableButtons();
 181  
         }
 182  0
     }
 183  
 
 184  
     /**
 185  
      * The UID.
 186  
      */
 187  
     private static final long serialVersionUID = 8055896491830976354L;
 188  
 } 
 189  
 
 190  
 
 191