Coverage Report - org.argouml.language.ui.LanguageComboBox
 
Classes in this File Line Coverage Branch Coverage Complexity
LanguageComboBox
55%
16/29
50%
1/2
1.333
 
 1  
 /* $Id: LanguageComboBox.java 17823 2010-01-12 18:47:57Z 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) 2005-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.language.ui;
 40  
 
 41  
 import java.awt.Dimension;
 42  
 import java.util.Iterator;
 43  
 
 44  
 import javax.swing.JComboBox;
 45  
 
 46  
 import org.apache.log4j.Logger;
 47  
 import org.argouml.application.events.ArgoEventPump;
 48  
 import org.argouml.application.events.ArgoEventTypes;
 49  
 import org.argouml.application.events.ArgoGeneratorEvent;
 50  
 import org.argouml.application.events.ArgoGeneratorEventListener;
 51  
 import org.argouml.uml.generator.GeneratorManager;
 52  
 import org.argouml.uml.generator.Language;
 53  
 
 54  
 /**
 55  
  * This class provides a self-updating language combo box.
 56  
  * @author Daniele Tamino
 57  
  */
 58  
 public class LanguageComboBox
 59  
     extends JComboBox
 60  
     implements ArgoGeneratorEventListener {
 61  
 
 62  
     /** logger */
 63  900
     private static final Logger LOG = Logger.getLogger(LanguageComboBox.class);
 64  
 
 65  
     /**
 66  
      * The constructor.
 67  
      */
 68  
     public LanguageComboBox() {
 69  900
         super();
 70  900
         setEditable(false);
 71  900
         setMaximumRowCount(6);
 72  
 
 73  900
         Dimension d = getPreferredSize();
 74  900
         d.width = 200;
 75  900
         setMaximumSize(d);
 76  
 
 77  900
         ArgoEventPump.addListener(ArgoEventTypes.ANY_GENERATOR_EVENT, this);
 78  900
         refresh();
 79  900
     }
 80  
 
 81  
     /*
 82  
      * @see java.lang.Object#finalize()
 83  
      */
 84  
     protected void finalize() {
 85  0
         ArgoEventPump.removeListener(this);
 86  0
     }
 87  
 
 88  
     /**
 89  
      * Refresh the combobox contents.
 90  
      */
 91  
     public void refresh() {
 92  900
         removeAllItems();
 93  900
         Iterator iterator =
 94  
             GeneratorManager.getInstance().getLanguages().iterator();
 95  900
         while (iterator.hasNext()) {
 96  
             try {
 97  0
                 Language ll = (Language) iterator.next();
 98  0
                 addItem(ll);
 99  0
             } catch (Exception e) {
 100  0
                 LOG.error("Unexpected exception", e);
 101  0
             }
 102  
         }
 103  900
         setVisible(true);
 104  900
         invalidate();
 105  900
     }
 106  
 
 107  
     /*
 108  
      * @see org.argouml.application.events.ArgoGeneratorEventListener#generatorChanged(org.argouml.application.events.ArgoGeneratorEvent)
 109  
      */
 110  
     public void generatorChanged(ArgoGeneratorEvent e) {
 111  0
         refresh();
 112  0
     }
 113  
 
 114  
     /*
 115  
      * @see org.argouml.application.events.ArgoGeneratorEventListener#generatorAdded(org.argouml.application.events.ArgoGeneratorEvent)
 116  
      */
 117  
     public void generatorAdded(ArgoGeneratorEvent e) {
 118  0
         refresh();
 119  0
     }
 120  
 
 121  
     /*
 122  
      * @see org.argouml.application.events.ArgoGeneratorEventListener#generatorRemoved(org.argouml.application.events.ArgoGeneratorEvent)
 123  
      */
 124  
     public void generatorRemoved(ArgoGeneratorEvent e) {
 125  0
         refresh();
 126  0
     }
 127  
 }