Coverage Report - net.miginfocom.swing.SwingContainerWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
SwingContainerWrapper
N/A
N/A
1.75
 
 1  
 package net.miginfocom.swing;
 2  
 /*
 3  
  * License (BSD):
 4  
  * ==============
 5  
  *
 6  
  * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
 7  
  * All rights reserved.
 8  
  *
 9  
  * Redistribution and use in source and binary forms, with or without modification,
 10  
  * are permitted provided that the following conditions are met:
 11  
  * Redistributions of source code must retain the above copyright notice, this list
 12  
  * of conditions and the following disclaimer.
 13  
  * Redistributions in binary form must reproduce the above copyright notice, this
 14  
  * list of conditions and the following disclaimer in the documentation and/or other
 15  
  * materials provided with the distribution.
 16  
  * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
 17  
  * used to endorse or promote products derived from this software without specific
 18  
  * prior written permission.
 19  
  *
 20  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 21  
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 22  
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 23  
  * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 24  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 25  
  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 26  
  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 27  
  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 28  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 29  
  * OF SUCH DAMAGE.
 30  
  *
 31  
  * @version 1.0
 32  
  * @author Mikael Grev, MiG InfoCom AB
 33  
  *         Date: 2006-sep-08
 34  
  */
 35  
 
 36  
 import net.miginfocom.layout.ComponentWrapper;
 37  
 import net.miginfocom.layout.ContainerWrapper;
 38  
 
 39  
 import java.awt.*;
 40  
 
 41  
 /**
 42  
  */
 43  
 public final class SwingContainerWrapper extends SwingComponentWrapper implements ContainerWrapper
 44  
 {
 45  
         /** Debug color for cell outline.
 46  
          */
 47  
         private static final Color DB_CELL_OUTLINE = new Color(255, 0, 0);
 48  
 
 49  
         public SwingContainerWrapper(Container c)
 50  
         {
 51  
                 super(c);
 52  
         }
 53  
 
 54  
         public ComponentWrapper[] getComponents()
 55  
         {
 56  
                 Container c = (Container) getComponent();
 57  
                 ComponentWrapper[] cws = new ComponentWrapper[c.getComponentCount()];
 58  
                 for (int i = 0; i < cws.length; i++)
 59  
                         cws[i] = new SwingComponentWrapper(c.getComponent(i));
 60  
                 return cws;
 61  
         }
 62  
 
 63  
         public int getComponentCount()
 64  
         {
 65  
                 return ((Container) getComponent()).getComponentCount();
 66  
         }
 67  
 
 68  
         public Object getLayout()
 69  
         {
 70  
                 return ((Container) getComponent()).getLayout();
 71  
         }
 72  
 
 73  
         public final boolean isLeftToRight()
 74  
         {
 75  
                 return ((Container) getComponent()).getComponentOrientation().isLeftToRight();
 76  
         }
 77  
 
 78  
         public final void paintDebugCell(int x, int y, int width, int height)
 79  
         {
 80  
                 Component c = (Component) getComponent();
 81  
                 if (c.isShowing() == false)
 82  
                         return;
 83  
 
 84  
                 Graphics2D g = (Graphics2D) c.getGraphics();
 85  
                 if (g == null)
 86  
                         return;
 87  
 
 88  
                 g.setStroke(new BasicStroke(1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10f, new float[] {2f, 3f}, 0));
 89  
                 g.setPaint(DB_CELL_OUTLINE);
 90  
                 g.drawRect(x, y, width - 1, height - 1);
 91  
         }
 92  
 
 93  
         public int getComponetType(boolean disregardScrollPane)
 94  
         {
 95  
                 return TYPE_CONTAINER;
 96  
         }
 97  
 
 98  
         // Removed for 2.3 because the parent.isValid() in MigLayout will catch this instead.
 99  
         public int getLayoutHashCode()
 100  
         {
 101  
                 long n = System.nanoTime();
 102  
                 int h = super.getLayoutHashCode();
 103  
 
 104  
                 if (isLeftToRight())
 105  
                         h += 416343;
 106  
 
 107  
                 return 0;
 108  
         }
 109  
 }