allows for null Jmol viewer
[jalview.git] / src2 / net / miginfocom / swing / SwingContainerWrapper.java
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.BasicStroke;
40 import java.awt.Color;
41 import java.awt.Component;
42 import java.awt.Container;
43 import java.awt.Graphics2D;
44
45 /**
46  */
47 public final class SwingContainerWrapper extends SwingComponentWrapper implements ContainerWrapper
48 {
49         /** Debug color for cell outline.
50          */
51         private static final Color DB_CELL_OUTLINE = new Color(255, 0, 0);
52
53         public SwingContainerWrapper(Container c)
54         {
55                 super(c);
56         }
57
58         @Override
59         public ComponentWrapper[] getComponents()
60         {
61                 Container c = (Container) getComponent();
62                 ComponentWrapper[] cws = new ComponentWrapper[c.getComponentCount()];
63                 for (int i = 0; i < cws.length; i++)
64                         cws[i] = new SwingComponentWrapper(c.getComponent(i));
65                 return cws;
66         }
67
68         @Override
69         public int getComponentCount()
70         {
71                 return ((Container) getComponent()).getComponentCount();
72         }
73
74         @Override
75         public Object getLayout()
76         {
77                 return ((Container) getComponent()).getLayout();
78         }
79
80         @Override
81         public final boolean isLeftToRight()
82         {
83                 return ((Container) getComponent()).getComponentOrientation().isLeftToRight();
84         }
85
86         @Override
87         public final void paintDebugCell(int x, int y, int width, int height)
88         {
89                 Component c = (Component) getComponent();
90                 if (c.isShowing() == false)
91                         return;
92
93                 Graphics2D g = (Graphics2D) c.getGraphics();
94                 if (g == null)
95                         return;
96
97                 g.setStroke(new BasicStroke(1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10f, new float[] {2f, 3f}, 0));
98                 g.setPaint(DB_CELL_OUTLINE);
99                 g.drawRect(x, y, width - 1, height - 1);
100         }
101
102         @Override
103         public int getComponentType(boolean disregardScrollPane)
104         {
105                 return TYPE_CONTAINER;
106         }
107
108         // Removed for 2.3 because the parent.isValid() in MigLayout will catch this instead.
109         @Override
110         public int getLayoutHashCode()
111         {
112                 long n = System.nanoTime();
113                 int h = super.getLayoutHashCode();
114
115                 if (isLeftToRight())
116                         h += 416343;
117
118                 return 0;
119         }
120 }