Coverage Report - org.argouml.cognitive.ui.ToDoTreeRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
ToDoTreeRenderer
57%
35/61
27%
12/44
13
 
 1  
 /* $Id: ToDoTreeRenderer.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.Color;
 42  
 import java.awt.Component;
 43  
 
 44  
 import javax.swing.ImageIcon;
 45  
 import javax.swing.JLabel;
 46  
 import javax.swing.JTree;
 47  
 import javax.swing.plaf.metal.MetalIconFactory;
 48  
 import javax.swing.tree.DefaultTreeCellRenderer;
 49  
 
 50  
 import org.argouml.application.helpers.ResourceLoaderWrapper;
 51  
 import org.argouml.cognitive.Decision;
 52  
 import org.argouml.cognitive.Designer;
 53  
 import org.argouml.cognitive.Goal;
 54  
 import org.argouml.cognitive.Poster;
 55  
 import org.argouml.cognitive.ToDoItem;
 56  
 import org.argouml.model.Model;
 57  
 import org.argouml.uml.ui.UMLTreeCellRenderer;
 58  
 import org.tigris.gef.base.Diagram;
 59  
 import org.tigris.gef.base.Globals;
 60  
 import org.tigris.gef.presentation.Fig;
 61  
 
 62  
 
 63  
 /**
 64  
  * Displays an entry in the ToDo tree.
 65  
  *
 66  
  */
 67  900
 public class ToDoTreeRenderer extends DefaultTreeCellRenderer {
 68  
     ////////////////////////////////////////////////////////////////
 69  
     // class variables
 70  
 
 71  
     // general icons for poster
 72  900
     private final ImageIcon postIt0     = lookupIconResource("PostIt0");
 73  900
     private final ImageIcon postIt25    = lookupIconResource("PostIt25");
 74  900
     private final ImageIcon postIt50    = lookupIconResource("PostIt50");
 75  900
     private final ImageIcon postIt75    = lookupIconResource("PostIt75");
 76  900
     private final ImageIcon postIt99    = lookupIconResource("PostIt99");
 77  900
     private final ImageIcon postIt100   = lookupIconResource("PostIt100");
 78  
 
 79  
     // specialised icons for designer
 80  900
     private final ImageIcon postItD0    = lookupIconResource("PostItD0");
 81  900
     private final ImageIcon postItD25   = lookupIconResource("PostItD25");
 82  900
     private final ImageIcon postItD50   = lookupIconResource("PostItD50");
 83  900
     private final ImageIcon postItD75   = lookupIconResource("PostItD75");
 84  900
     private final ImageIcon postItD99   = lookupIconResource("PostItD99");
 85  900
     private final ImageIcon postItD100  = lookupIconResource("PostItD100");
 86  
 
 87  900
     private UMLTreeCellRenderer treeCellRenderer = new UMLTreeCellRenderer();
 88  
 
 89  
     private static ImageIcon lookupIconResource(String name) {
 90  10800
         return ResourceLoaderWrapper.lookupIconResource(name);
 91  
     }
 92  
 
 93  
     ////////////////////////////////////////////////////////////////
 94  
     // TreeCellRenderer implementation
 95  
 
 96  
     /*
 97  
      * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(
 98  
      * javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int,
 99  
      * boolean)
 100  
      */
 101  
     public Component getTreeCellRendererComponent(JTree tree, Object value,
 102  
     boolean sel,
 103  
     boolean expanded,
 104  
     boolean leaf, int row,
 105  
     boolean hasTheFocus) {
 106  
 
 107  11466
         Component r = super.getTreeCellRendererComponent(tree, value, sel,
 108  
                                                          expanded, leaf,
 109  
                                                          row, hasTheFocus);
 110  
 
 111  11466
         if (r instanceof JLabel) {
 112  11466
             JLabel lab = (JLabel) r;
 113  11466
             if (value instanceof ToDoItem) {
 114  0
                 ToDoItem item = (ToDoItem) value;
 115  0
                 Poster post = item.getPoster();
 116  0
                 if (post instanceof Designer) {
 117  0
                     if (item.getProgress() == 0) lab.setIcon(postItD0);
 118  0
                     else if (item.getProgress() <= 25) lab.setIcon(postItD25);
 119  0
                     else if (item.getProgress() <= 50) lab.setIcon(postItD50);
 120  0
                     else if (item.getProgress() <= 75) lab.setIcon(postItD75);
 121  0
                     else if (item.getProgress() <= 100) lab.setIcon(postItD99);
 122  0
                     else lab.setIcon(postItD100);
 123  
                 } else {
 124  0
                     if (item.getProgress() == 0) lab.setIcon(postIt0);
 125  0
                     else if (item.getProgress() <= 25) lab.setIcon(postIt25);
 126  0
                     else if (item.getProgress() <= 50) lab.setIcon(postIt50);
 127  0
                     else if (item.getProgress() <= 75) lab.setIcon(postIt75);
 128  0
                     else if (item.getProgress() <= 100) lab.setIcon(postIt99);
 129  0
                     else lab.setIcon(postIt100);
 130  
                 }
 131  
 
 132  0
             } else if (value instanceof Decision) {
 133  0
                 lab.setIcon(MetalIconFactory.getTreeFolderIcon());
 134  11466
             } else if (value instanceof Goal) {
 135  0
                 lab.setIcon(MetalIconFactory.getTreeFolderIcon());
 136  11466
             } else if (value instanceof Poster) {
 137  0
                 lab.setIcon(MetalIconFactory.getTreeFolderIcon());
 138  11466
             } else if (value instanceof PriorityNode) {
 139  9666
                 lab.setIcon(MetalIconFactory.getTreeFolderIcon());
 140  1800
             } else if (value instanceof KnowledgeTypeNode) {
 141  0
                 lab.setIcon(MetalIconFactory.getTreeFolderIcon());
 142  1800
             } else if (value instanceof Diagram) {
 143  0
                 return treeCellRenderer.getTreeCellRendererComponent(tree,
 144  
                                                                  value,
 145  
                                                                  sel,
 146  
                                                                  expanded,
 147  
                                                                  leaf,
 148  
                                                                  row,
 149  
                                                                  hasTheFocus);
 150  
             } else {
 151  1800
                 Object newValue = value;
 152  1800
                 if (newValue instanceof Fig) {
 153  0
                     newValue = ((Fig) value).getOwner();
 154  
                 }
 155  1800
                 if (Model.getFacade().isAUMLElement(newValue)) {
 156  0
                     return treeCellRenderer.getTreeCellRendererComponent(
 157  
                             tree, newValue, sel, expanded, leaf, row,
 158  
                             hasTheFocus);
 159  
                 }
 160  
             }
 161  
 
 162  
 
 163  
 
 164  11466
             String tip = lab.getText() + " ";
 165  11466
             lab.setToolTipText(tip);
 166  11466
             tree.setToolTipText(tip);
 167  
 
 168  11466
             if (!sel) {
 169  11466
                 lab.setBackground(getBackgroundNonSelectionColor());
 170  
             } else {
 171  0
                 Color high = Globals.getPrefs().getHighlightColor();
 172  0
                 high = high.brighter().brighter();
 173  0
                 lab.setBackground(high);
 174  
             }
 175  11466
             lab.setOpaque(sel);
 176  
         }
 177  11466
         return r;
 178  
     }
 179  
 
 180  
 
 181  
 } /* end class ToDoTreeRenderer */