Coverage Report - org.openpermis.editor.policy.gui.CompoundIcon
 
Classes in this File Line Coverage Branch Coverage Complexity
CompoundIcon
0%
0/23
0%
0/4
2
 
 1  
 /*
 2  
  * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport
 3  
  *                     (http://www.vbs.admin.ch)
 4  
  * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch)
 5  
  * All rights reserved.
 6  
  *
 7  
  * Licensed under the Open Permis License which accompanies this distribution,
 8  
  * and is available at http://www.openpermis.org/BSDlicenceKent.txt
 9  
  */
 10  
 package org.openpermis.editor.policy.gui;
 11  
 
 12  
 import java.awt.Component;
 13  
 import java.awt.Graphics;
 14  
 
 15  
 import javax.swing.Icon;
 16  
 
 17  
 
 18  
 /**
 19  
  * Icon that consists of two icons.
 20  
  * <p>The compound icon draws two icons, the first at the bottom and the second on top of it.</p>
 21  
  * @since 0.3.0
 22  
  */
 23  
 public class CompoundIcon
 24  
         implements Icon
 25  
 {
 26  
 
 27  
         //---- State
 28  
         
 29  
         /**
 30  
          * Cache for the combined icon width.
 31  
          * @since 0.3.0
 32  
          */
 33  
         private final int width;
 34  
         
 35  
         /**
 36  
          * Cache for the combined icon height.
 37  
          * @since 0.3.0
 38  
          */
 39  
         private final int height;
 40  
         
 41  
         /**
 42  
          * The first icon to display.
 43  
          * @since 0.3.0
 44  
          */
 45  
         private final Icon icon1;
 46  
         
 47  
         /**
 48  
          * Drawing x offset for the first icon.
 49  
          * @since 0.3.0
 50  
          */
 51  
         private final int x1;
 52  
         
 53  
         /**
 54  
          * Drawing y offset for the first icon.
 55  
          * @since 0.3.0
 56  
          */
 57  
         private final int y1;
 58  
         
 59  
         /**
 60  
          * The secound icon to display.
 61  
          * @since 0.3.0
 62  
          */
 63  
         private final Icon icon2;
 64  
         
 65  
         /**
 66  
          * Drawing x offset for the second icon.
 67  
          * @since 0.3.0
 68  
          */
 69  
         private final int x2;
 70  
         
 71  
         /**
 72  
          * Drawing y offset for the second icon.
 73  
          * @since 0.3.0
 74  
          */
 75  
         private final int y2;
 76  
         
 77  
         //---- Constructors
 78  
         
 79  
         /**
 80  
          * Creates a new annotated icon.
 81  
          * @param icon1 the first icon to display, must not be {@code null}.
 82  
          * @param icon2 the second icon to display, must not be {@code null}.
 83  
          * @since 0.3.0
 84  
          */
 85  0
         public CompoundIcon (Icon icon1, Icon icon2) {
 86  0
                 if (icon1 == null) {
 87  0
                         throw new IllegalArgumentException(
 88  
                                 "The first icon of a compound icon must not be [null]."
 89  
                         );
 90  
                 }
 91  0
                 if (icon2 == null) {
 92  0
                         throw new IllegalArgumentException(
 93  
                                 "The second icon of a compound icon must not be [null]."
 94  
                         );
 95  
                 }
 96  0
                 this.icon1 = icon1;
 97  0
                 this.icon2 = icon2;
 98  0
                 final int width1 = this.icon1.getIconWidth();
 99  0
                 final int width2 = this.icon2.getIconWidth();
 100  0
                 this.width = Math.max(width1, width2);
 101  0
                 this.x1 = this.width - width1;
 102  0
                 this.x2 = this.width - width2;
 103  0
                 final int height1 = this.icon1.getIconHeight();
 104  0
                 final int height2 = this.icon2.getIconHeight();
 105  0
                 this.height = Math.max(height1, height2);
 106  0
                 this.y1 = this.height - height1;
 107  0
                 this.y2 = this.height - height2;
 108  0
         }
 109  
         
 110  
         //---- Methods
 111  
         
 112  
         /**
 113  
          * @since 0.3.0
 114  
          */
 115  
         public int getIconHeight () {
 116  0
                 return this.width;
 117  
         }
 118  
 
 119  
         /**
 120  
          * @since 0.3.0
 121  
          */
 122  
         public int getIconWidth () {
 123  0
                 return this.height;
 124  
         }
 125  
 
 126  
         /**
 127  
          * @since 0.3.0
 128  
          */
 129  
         public void paintIcon (Component c, Graphics g, int x, int y) {
 130  0
                 this.icon1.paintIcon(c, g, (x + this.x1), (y + this.y1));
 131  0
                 this.icon2.paintIcon(c, g, (x + this.x2), (y + this.y2));
 132  0
         }
 133  
 
 134  
 }