Coverage Report - org.xmlhammer.gui.util.SelectablePanel
 
Classes in this File Line Coverage Branch Coverage Complexity
SelectablePanel
65% 
75% 
1.4
 
 1  
 /*
 2  
  * $Id: SelectablePanel.java,v 1.6 2007/02/15 09:02:28 edankert Exp $
 3  
  *
 4  
  * The contents of this file are subject to the Mozilla Public License 
 5  
  * Version 1.1 (the "License"); you may not use this file except in 
 6  
  * compliance with the License. You may obtain a copy of the License at 
 7  
  * http://www.mozilla.org/MPL/ 
 8  
  *
 9  
  * Software distributed under the License is distributed on an "AS IS" basis, 
 10  
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
 11  
  * for the specific language governing rights and limitations under the License.
 12  
  *
 13  
  * The Original Code is XML Hammer code. (org.xmlhammer.*)
 14  
  *
 15  
  * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
 16  
  * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
 17  
  * All Rights Reserved.
 18  
  *
 19  
  * Contributor(s): Edwin Dankert <edankert@gmail.com>
 20  
  */
 21  
 
 22  
 
 23  
 package org.xmlhammer.gui.util;
 24  
 
 25  
 import java.awt.LayoutManager;
 26  
 import java.awt.SystemColor;
 27  
 
 28  
 import javax.swing.JPanel;
 29  
 import javax.swing.border.Border;
 30  
 import javax.swing.border.CompoundBorder;
 31  
 import javax.swing.border.MatteBorder;
 32  
 
 33  
 /**
 34  
  * Put comment...
 35  
  * 
 36  
  * @version $Revision: 1.6 $, $Date: 2007/02/15 09:02:28 $
 37  
  * @author Edwin Dankert <edankert@gmail.com>
 38  
  */
 39  
 
 40  
 public class SelectablePanel extends JPanel {
 41  
     private static final long serialVersionUID = -6907086273550806994L;
 42  
 
 43  22
     private static final Border UNSELECTED_BORDER = 
 44  
 //      new CompoundBorder(
 45  
           new CompoundBorder(
 46  
               new MatteBorder( 1, 1, 0, 0, SystemColor.controlDkShadow),
 47  
               new MatteBorder(0, 0, 1, 1, SystemColor.controlLtHighlight));
 48  
 
 49  
 //                new CompoundBorder(
 50  
 //                        new CompoundBorder(
 51  
 //                                new MatteBorder( 1, 1, 0, 0, SystemColor.controlDkShadow),
 52  
 //                                new MatteBorder(0, 0, 1, 1, SystemColor.controlLtHighlight)),
 53  
 //                        new CompoundBorder( 
 54  
 //                                new EmptyBorder( 1, 1, 1, 1),
 55  
 //                                new EmptyBorder( 0, 1, 1, 1)));
 56  
 
 57  22
         private static final Border SELECTED_BORDER = UNSELECTED_BORDER;
 58  
 //                new CompoundBorder(
 59  
 //                        new CompoundBorder(
 60  
 //                                new MatteBorder( 1, 1, 0, 0, SystemColor.controlDkShadow),
 61  
 //                                new MatteBorder(0, 0, 1, 1, SystemColor.controlLtHighlight)),
 62  
 //                        new CompoundBorder( 
 63  
 //                                new MatteBorder( 1, 1, 1, 1, UIManager.getColor( "TabbedPane.focus")),
 64  
 //                                new EmptyBorder( 0, 1, 1, 1)));
 65  
 
 66  660
     private Border insideBorder = null;
 67  660
         private boolean selected = false;
 68  660
         private SelectablePanelGroup group = null;
 69  
 
 70  
         /**
 71  
          * @param layout
 72  
          * @param isDoubleBuffered
 73  
          */
 74  
         public SelectablePanel( LayoutManager layout, boolean isDoubleBuffered) {
 75  0
                 super( layout, isDoubleBuffered);
 76  
                 
 77  0
                 init();
 78  0
         }
 79  
 
 80  
         /**
 81  
          * @param layout
 82  
          */
 83  
         public SelectablePanel( LayoutManager layout) {
 84  660
                 super( layout);
 85  
                 
 86  660
                 init();
 87  660
         }
 88  
 
 89  
         /**
 90  
          * @param isDoubleBuffered
 91  
          */
 92  
         public SelectablePanel( boolean isDoubleBuffered) {
 93  0
                 super( isDoubleBuffered);
 94  
 
 95  0
                 init();
 96  0
         }
 97  
 
 98  
         /**
 99  
          * 
 100  
          */
 101  
         public SelectablePanel() {
 102  0
                 super();
 103  
 
 104  0
                 init();
 105  0
         }
 106  
         
 107  
         private void init() {
 108  660
         updateBorder();
 109  660
         }
 110  
     
 111  
     public void setBorder(Border border) {
 112  660
         insideBorder = border;
 113  
 
 114  660
         updateBorder();
 115  660
     }
 116  
         
 117  
         public void setSelected( boolean selected) {
 118  220
                 if ( selected && group != null && !group.isSelected( this)) {
 119  0
                         group.setSelected( this, selected);
 120  
                 } 
 121  
 
 122  220
                 this.selected = selected;
 123  
         
 124  220
         updateBorder();
 125  220
         }
 126  
         
 127  
         public boolean isSelected() {
 128  660
                 return selected;
 129  
         }
 130  
 
 131  
         public void setGroup( SelectablePanelGroup group) {
 132  660
                 this.group = group;
 133  660
         }
 134  
     
 135  
     private void updateBorder() {
 136  1540
         Border border = null;
 137  
         
 138  1540
         if (insideBorder != null) {
 139  0
             if (selected) {
 140  0
                 border = new CompoundBorder(SELECTED_BORDER, insideBorder);
 141  0
             } else {
 142  0
                 border = new CompoundBorder(UNSELECTED_BORDER, insideBorder);
 143  
             }
 144  0
         } else {
 145  1540
             if (selected) {
 146  220
                 border = SELECTED_BORDER;
 147  220
             } else {
 148  1320
                 border = UNSELECTED_BORDER;
 149  
             }
 150  
         }
 151  
         
 152  1540
         super.setBorder(border);
 153  1540
     }
 154  
 }