jdk/test/java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java
author mfang
Wed, 17 Aug 2011 14:18:26 -0700
changeset 10294 8fcdae2a7ec7
parent 5506 202f599c92aa
child 39056 d99e63b6d962
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3089
diff changeset
     2
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3089
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3089
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3089
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
   @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
   @bug 4370316
3089
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
    27
   @summary GridLayout does not centre its component properly
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
    28
    (summary was GridLayout does not fill its Container)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
   @library ../../regtesthelpers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
   @build Util
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
   @author Andrei Dmitriev : area=awt.layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
   @run main LayoutExtraGaps
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import test.java.awt.regtesthelpers.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class LayoutExtraGaps extends Frame {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    final static int compCount = 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    public LayoutExtraGaps() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        super("GridLayoutTest");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        Panel yellowPanel = new Panel(new GridLayout(compCount, 1, 3, 3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        yellowPanel.setBackground(Color.yellow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        for(int i = 0; i < compCount ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            Label redLabel = new Label(""+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            redLabel.setBackground(Color.red);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            yellowPanel.add(redLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        Panel bluePanel = new Panel(new GridLayout(1, compCount, 3, 3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        bluePanel.setBackground(Color.blue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        for(int i = 0; i < compCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            Label greenLabel = new Label(""+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            greenLabel.setBackground(Color.green);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            bluePanel.add(greenLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        //RTL orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        Panel blackPanel = new Panel(new GridLayout(compCount, 1, 3, 3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        blackPanel.setBackground(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        blackPanel.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        for(int i = 0; i < compCount ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            Label redLabel = new Label(""+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            redLabel.setBackground(Color.red);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            blackPanel.add(redLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        Panel redPanel = new Panel(new GridLayout(1, compCount, 3, 3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        redPanel.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        redPanel.setBackground(Color.red);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        for(int i = 0; i < compCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            Label greenLabel = new Label(""+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            greenLabel.setBackground(Color.green);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            redPanel.add(greenLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        setLayout(new GridLayout(2, 2, 20, 20));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        add(yellowPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        add(bluePanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        add(redPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        add(blackPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        setSize((int)getPreferredSize().getWidth() + 50, (int)getPreferredSize().getHeight() + 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        Util.waitForIdle(Util.createRobot());
3089
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
    94
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
    95
        if (isComponentCentredLTR(yellowPanel) && isComponentCentredLTR(bluePanel)
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
    96
                && isComponentCentredLTR(blackPanel) && isComponentCentredRTL(redPanel))
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
    97
        {
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
    98
            System.out.println("Test passed.");
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
    99
        } else {
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   100
            throw new RuntimeException("Test failed. GridLayout doesn't center component.");
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   101
        }
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   102
    }
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   103
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   104
    /**
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   105
     * Checks if the components under Panel p are properly centred (i.e.
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   106
     * opposite borders between the Panel and component are equal). Panel p
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   107
     * must not be affect by RTL orientation (RTL only affects horizontal
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   108
     * positioning and components lay out from top right corner).
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   109
     *
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   110
     * @param      p the panel where the components exist and is not affected
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   111
     *             by right to left orientation
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   112
     * @return     true if components of panel p are properly centre, false
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   113
     *             otherwise
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   114
     */
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   115
    public static boolean isComponentCentredLTR(Panel p) {
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   116
        double borderLeft;
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   117
        double borderRight;
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   118
        double borderTop;
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   119
        double borderBottom;
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   120
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   121
        //The first component(rectangle) in panel p.
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   122
        Rectangle firstRec = p.getComponent(0).getBounds();
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   123
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   124
        //The last component(rectangle) in panel p.
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   125
        Rectangle lastRec = p.getComponent(compCount - 1).getBounds();
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   126
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   127
        System.out.println("bounds of the first rectangle in "+ p.getName() + " = " + firstRec);
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   128
        System.out.println("bounds of the last rectangle in "+ p.getName() + " = " + lastRec);
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   129
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   130
        borderLeft = firstRec.getX();
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   131
        borderRight = p.getWidth() - lastRec.getWidth() - lastRec.getX();
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   132
        borderTop = firstRec.getY();
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   133
        borderBottom = p.getHeight() - lastRec.getHeight() - lastRec.getY();
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   134
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   135
        return areBordersEqual(borderLeft, borderRight) &&
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   136
                areBordersEqual(borderTop, borderBottom);
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   137
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
3089
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   139
    /**
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   140
     * Checks if the components under Panel p are properly centred (i.e.
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   141
     * opposite borders between the Panel and component are equal). Panel p
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   142
     * must be affect by RTL orientation (RTL only affects horizontal positioning
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   143
     * and components lay out from top right corner).
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   144
     *
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   145
     * @param      p the panel where the components exist and is affected by
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   146
     *             right to left orientation
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   147
     * @return     true if components of panel p are properly centre, false
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   148
     *             otherwise
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   149
     */
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   150
    public static boolean isComponentCentredRTL(Panel p) {
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   151
        double borderLeft;
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   152
        double borderRight;
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   153
        double borderTop;
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   154
        double borderBottom;
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   155
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   156
        //The first component(rectangle) in panel p.
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   157
        Rectangle firstRec = p.getComponent(0).getBounds();
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   158
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   159
        //The last component(rectangle) in panel p.
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   160
        Rectangle lastRec = p.getComponent(compCount - 1).getBounds();
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   161
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   162
        System.out.println("bounds of the first rectangle in "+ p.getName() + " = " + firstRec);
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   163
        System.out.println("bounds of the last rectangle in "+ p.getName() + " = " + lastRec);
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   164
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   165
        borderLeft = lastRec.getX();
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   166
        borderRight = p.getWidth() - firstRec.getWidth() - firstRec.getX();
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   167
        borderTop = lastRec.getY();
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   168
        borderBottom = p.getHeight() - firstRec.getHeight() - firstRec.getY();
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   169
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   170
        return areBordersEqual(borderLeft, borderRight) &&
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   171
                areBordersEqual(borderTop, borderBottom);
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   172
    }
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   173
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   174
    /**
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   175
     * Given two borders border1 and border2 check if they are equal.
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   176
     *
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   177
     * @param      border1 one of the borders being compared
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   178
     * @param      border2 the other border being compared
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   179
     * @return     true if border1 and border2 are equal to each other (i.e.
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   180
     *             their width/height difference is at most 1, assuming the
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   181
     *             smallest pixel is of size 1), false otherwise
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   182
     */
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   183
    public static boolean areBordersEqual(double border1, double border2) {
31511b19b797 6848458: java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java fails
dav
parents: 2
diff changeset
   184
        return Math.abs(border1 - border2) <= 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        new LayoutExtraGaps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
}