Coverage Report - net.miginfocom.layout.ComponentWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentWrapper
N/A
N/A
1
 
 1  
 package net.miginfocom.layout;
 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  
 /** A class that wraps the important parts of a Component.
 37  
  * <p>
 38  
  * <b>NOTE!</b>.equals() and .hashcode() should be shunted to the wrapped component. E.g.
 39  
  * <pre>
 40  
  *         public int hashCode()
 41  
         {
 42  
                 return getComponent().hashCode();
 43  
         }
 44  
 
 45  
         public final boolean equals(Object o)
 46  
         {
 47  
                  if (o instanceof ComponentWrapper == false)
 48  
                          return false;
 49  
 
 50  
                  return getComponent().equals(((ComponentWrapper) o).getComponent());
 51  
         }
 52  
  * </pre>
 53  
  */
 54  
 public interface ComponentWrapper
 55  
 {
 56  
         static final int TYPE_UNSET = -1;
 57  
         public static final int TYPE_UNKNOWN = 0;
 58  
         public static final int TYPE_CONTAINER = 1;
 59  
         public static final int TYPE_LABEL = 2;
 60  
         public static final int TYPE_TEXT_FIELD = 3;
 61  
         public static final int TYPE_TEXT_AREA = 4;
 62  
         public static final int TYPE_BUTTON = 5;
 63  
         public static final int TYPE_LIST = 6;
 64  
         public static final int TYPE_TABLE = 7;
 65  
         public static final int TYPE_SCROLL_PANE = 8;
 66  
         public static final int TYPE_IMAGE = 9;
 67  
         public static final int TYPE_PANEL = 10;
 68  
         public static final int TYPE_COMBO_BOX = 11;
 69  
         public static final int TYPE_SLIDER = 12;
 70  
         public static final int TYPE_SPINNER = 13;
 71  
         public static final int TYPE_PROGRESS_BAR = 14;
 72  
         public static final int TYPE_TREE = 15;
 73  
         public static final int TYPE_CHECK_BOX = 16;
 74  
         public static final int TYPE_SCROLL_BAR = 17;
 75  
         public static final int TYPE_SEPARATOR = 18;
 76  
 
 77  
         /** Returns the actual object that this wrapper is aggregating. This might be needed for getting
 78  
          * information about the object that the wrapper interface does not provide.
 79  
          * <p>
 80  
          * If this is a container the container should be returned instead.
 81  
          * @return The actual object that this wrapper is aggregating. Not <code>null</code>.
 82  
          */
 83  
         public abstract Object getComponent();
 84  
 
 85  
         /** Returns the current x coordinate for this component.
 86  
          * @return The current x coordinate for this component.
 87  
          */
 88  
         public abstract int getX();
 89  
 
 90  
         /** Returns the current y coordinate for this component.
 91  
          * @return The current y coordinate for this component.
 92  
          */
 93  
         public abstract int getY();
 94  
 
 95  
         /** Returns the current width for this component.
 96  
          * @return The current width for this component.
 97  
          */
 98  
         public abstract int getWidth();
 99  
 
 100  
         /** Returns the current height for this component.
 101  
          * @return The current height for this component.
 102  
          */
 103  
         public abstract int getHeight();
 104  
 
 105  
         /** Returns the screen x-coordinate for the upper left coordinate of the component layout-able bounds.
 106  
          * @return The screen x-coordinate for the upper left coordinate of the component layout-able bounds.
 107  
          */
 108  
         public abstract int getScreenLocationX();
 109  
 
 110  
         /** Returns the screen y-coordinate for the upper left coordinate of the component layout-able bounds.
 111  
          * @return The screen y-coordinate for the upper left coordinate of the component layout-able bounds.
 112  
          */
 113  
         public abstract int getScreenLocationY();
 114  
 
 115  
         /** Returns the minimum width of the component.
 116  
          * @param hHint The Size hint for the other dimension. An implementation can use this value or the
 117  
          * current size for the widget in this dimension, or a combination of both, to calculate the correct size.<br>
 118  
          * Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
 119  
          * @return The minimum width of the component.
 120  
          * @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is necessary for
 121  
          * any implementing classes. This change was worth it though.
 122  
          */
 123  
         public abstract int getMinimumWidth(int hHint);
 124  
 
 125  
         /** Returns the minimum height of the component.
 126  
          * @param wHint The Size hint for the other dimension. An implementation can use this value or the
 127  
          * current size for the widget in this dimension, or a combination of both, to calculate the correct size.<br>
 128  
          * Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
 129  
          * @return The minimum height of the component.
 130  
          * @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is necessary for
 131  
          * any implementing classes. This change was worth it though.
 132  
          */
 133  
         public abstract int getMinimumHeight(int wHint);
 134  
 
 135  
         /** Returns the preferred width of the component.
 136  
          * @param hHint The Size hint for the other dimension. An implementation can use this value or the
 137  
          * current size for the widget in this dimension, or a combination of both, to calculate the correct size.<br>
 138  
          * Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
 139  
          * @return The preferred width of the component.
 140  
          * @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is necessary for
 141  
          * any implementing classes. This change was worth it though.
 142  
          */
 143  
         public abstract int getPreferredWidth(int hHint);
 144  
 
 145  
         /** Returns the preferred height of the component.
 146  
          * @param wHint The Size hint for the other dimension. An implementation can use this value or the
 147  
          * current size for the widget in this dimension, or a combination of both, to calculate the correct size.<br>
 148  
          * Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
 149  
          * @return The preferred height of the component.
 150  
          * @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is necessary for
 151  
          * any implementing classes. This change was worth it though.
 152  
          */
 153  
         public abstract int getPreferredHeight(int wHint);
 154  
 
 155  
         /** Returns the maximum width of the component.
 156  
          * @param hHint The Size hint for the other dimension. An implementation can use this value or the
 157  
          * current size for the widget in this dimension, or a combination of both, to calculate the correct size.<br>
 158  
          * Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
 159  
          * @return The maximum width of the component.
 160  
          * @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is necessary for
 161  
          * any implementing classes. This change was worth it though.
 162  
          */
 163  
         public abstract int getMaximumWidth(int hHint);
 164  
 
 165  
         /** Returns the maximum height of the component.
 166  
          * @param wHint The Size hint for the other dimension. An implementation can use this value or the
 167  
          * current size for the widget in this dimension, or a combination of both, to calculate the correct size.<br>
 168  
          * Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.
 169  
          * @return The maximum height of the component.
 170  
          * @since 3.5. Added the hint as a parameter knowing that a correction and recompilation is necessary for
 171  
          * any implementing classes. This change was worth it though.
 172  
          */
 173  
         public abstract int getMaximumHeight(int wHint);
 174  
 
 175  
         /** Sets the component's bounds.
 176  
          * @param x The x coordinate.
 177  
          * @param y The y coordinate.
 178  
          * @param width The width.
 179  
          * @param height The height.
 180  
          */
 181  
         public abstract void setBounds(int x, int y, int width, int height);
 182  
 
 183  
         /** Returns if the component's visibility is set to <code>true</code>. This should not return if the component is
 184  
          * actually visible, but if the visibility is set to true or not.
 185  
          * @return <code>true</code> means visible.
 186  
          */
 187  
         public abstract boolean isVisible();
 188  
 
 189  
         /** Returns the baseline for the component given the suggested height.
 190  
          * @param width The width to calculate for if other than the current. If <code>-1</code> the current size should be used.
 191  
          * @param height The height to calculate for if other than the current. If <code>-1</code> the current size should be used.
 192  
          * @return The baseline from the top or -1 if not applicable.
 193  
          */
 194  
         public abstract int getBaseline(int width, int height);
 195  
 
 196  
         /** Returns if the component has a baseline and if it can be retrieved. Should for instance return
 197  
          * <code>false</code> for Swing before mustang.
 198  
          * @return If the component has a baseline and if it can be retrieved.
 199  
          */
 200  
         public abstract boolean hasBaseline();
 201  
 
 202  
         /** Returns the container for this component.
 203  
          * @return The container for this component. Will return <code>null</code> if the component has no parent.
 204  
          */
 205  
         public abstract ContainerWrapper getParent();
 206  
 
 207  
         /** Returns the pixel unit factor for the horizontal or vertical dimension.
 208  
          * <p>
 209  
          * The factor is 1 for both dimensions on the normal font in a JPanel on Windows. The factor should increase with a bigger "X".
 210  
          * <p>
 211  
          * This is the Swing version:
 212  
          * <pre>
 213  
          * Rectangle2D r = fm.getStringBounds("X", parent.getGraphics());
 214  
          * wFactor = r.getWidth() / 6;
 215  
          * hFactor = r.getHeight() / 13.27734375f;
 216  
          * </pre>
 217  
          * @param isHor If it is the horizontal factor that should be returned.
 218  
          * @return The factor.
 219  
          */
 220  
         public abstract float getPixelUnitFactor(boolean isHor);
 221  
 
 222  
         /** Returns the DPI (Dots Per Inch) of the screen the component is currently in or for the default
 223  
          * screen if the component is not visible.
 224  
          * <p>
 225  
          * If headless mode {@link net.miginfocom.layout.PlatformDefaults#getDefaultDPI} will be returned.
 226  
          * @return The DPI.
 227  
          */
 228  
         public abstract int getHorizontalScreenDPI();
 229  
 
 230  
         /** Returns the DPI (Dots Per Inch) of the screen the component is currently in or for the default
 231  
          * screen if the component is not visible.
 232  
          * <p>
 233  
          * If headless mode {@link net.miginfocom.layout.PlatformDefaults#getDefaultDPI} will be returned.
 234  
          * @return The DPI.
 235  
          */
 236  
         public abstract int getVerticalScreenDPI();
 237  
 
 238  
         /** Returns the pixel size of the screen that the component is currently in or for the default
 239  
          * screen if the component is not visible or <code>null</code>.
 240  
          * <p>
 241  
          * If in headless mode <code>1024</code> is returned.
 242  
          * @return The screen size. E.g. <code>1280</code>.
 243  
          */
 244  
         public abstract int getScreenWidth();
 245  
 
 246  
         /** Returns the pixel size of the screen that the component is currently in or for the default
 247  
          * screen if the component is not visible or <code>null</code>.
 248  
          * <p>
 249  
          * If in headless mode <code>768</code> is returned.
 250  
          * @return The screen size. E.g. <code>1024</code>.
 251  
          */
 252  
         public abstract int getScreenHeight();
 253  
 
 254  
         /** Returns a String id that can be used to reference the component in link constraints. This value should
 255  
          * return the default id for the component. The id can be set for a component in the constraints and if
 256  
          * so the value returned by this method will never be used. If there are no sensible id for the component
 257  
          * <code>null</code> should be returned.
 258  
          * <p>
 259  
          * For instance the Swing implementation returns the string returned from <code>Component.getName()</code>.
 260  
          * @return The string link id or <code>null</code>.
 261  
          */
 262  
         public abstract String getLinkId();
 263  
 
 264  
         /** Returns a hash code that should be reasonably different for anything that might change the layout. This value is used to
 265  
          *  know if the component layout needs to clear any caches.
 266  
          * @return A hash code that should be reasonably different for anything that might change the layout. Returns -1 if the widget is
 267  
          * disposed.
 268  
          */
 269  
         public abstract int getLayoutHashCode();
 270  
 
 271  
         /** Returns the padding on a component by component basis. This method can be overridden to return padding to compensate for example for
 272  
          * borders that have shadows or where the outer most pixel is not the visual "edge" to align to.
 273  
          * <p>
 274  
          * Default implementation returns <code>null</code> for all components except for Windows XP's JTabbedPane which will return new Insets(0, 0, 2, 2).
 275  
          * <p>
 276  
          * <b>NOTE!</B> To reduce generated garbage the returned padding should never be changed so that the same insets can be returned many times.
 277  
          * @return <code>null</code> if no padding. <b>NOTE!</B> To reduce generated garbage the returned padding should never be changed so that
 278  
          * the same insets can be returned many times. [top, left, bottom, right]
 279  
          */
 280  
         public int[] getVisualPadding();
 281  
 
 282  
         /** Paints component outline to indicate where it is.
 283  
          */
 284  
         public abstract void paintDebugOutline();
 285  
 
 286  
         /** Returns the type of component that this wrapper is wrapping.
 287  
          * <p>
 288  
          * This method can be invoked often so the result should be cached.
 289  
          * <p>
 290  
          * <b>NOTE!</b> This is misspelled. Keeping it that way though since this is only used by developers who
 291  
          * port MigLayout.
 292  
          * @param disregardScrollPane Is <code>true</code> any wrapping scroll pane should be disregarded and the type
 293  
          * of the scrolled component should be returned.
 294  
          * @return The type of component that this wrapper is wrapping. E.g. {@link #TYPE_LABEL}.
 295  
          */
 296  
         public abstract int getComponetType(boolean disregardScrollPane);
 297  
 }