/* * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import java.awt.Dimension; import java.io.ByteArrayInputStream; import javax.swing.JSlider; import javax.swing.plaf.synth.SynthLookAndFeel; import static javax.swing.SwingUtilities.invokeAndWait; import static javax.swing.UIManager.setLookAndFeel; /* * @test * @bug 8040328 * @summary Tests insets in the preferred and minimum size of the synth slider * @author Sergey Malenkov */ public final class Test8040328 implements Runnable { private static final String XML = "" + " " + " " + " " + " " + ""; public static void main(String[] args) throws Exception { invokeAndWait(new Test8040328()); } private final Dimension minimum = new Dimension(); private final Dimension preferred = new Dimension(); @Override public void run() { test(JSlider.HORIZONTAL, "10"); test(JSlider.HORIZONTAL, "5"); // calculate delta test(JSlider.HORIZONTAL, "0"); test(JSlider.HORIZONTAL, "5"); // calculate delta test(JSlider.VERTICAL, "10"); test(JSlider.VERTICAL, "5"); // calculate delta test(JSlider.VERTICAL, "0"); test(JSlider.VERTICAL, "5"); // calculate delta } private void test(int orientation, String insets) { System.err.println(); System.err.println("INSETS: " + insets + ", " + insets + ", " + insets + ", " + insets); String xml = XML.replace("###", insets); try { SynthLookAndFeel laf = new SynthLookAndFeel(); laf.load(new ByteArrayInputStream(xml.getBytes("UTF8")), getClass()); setLookAndFeel(laf); } catch (Exception exception) { exception.printStackTrace(); System.exit(1); } JSlider slider = new JSlider(orientation); test("minimum", this.minimum, slider.getMinimumSize()); test("preferred", this.preferred, slider.getPreferredSize()); } private static void test(String prefix, Dimension old, Dimension size) { System.err.println(prefix + ": width=" + size.width + ", height=" + size.height); if ((old.width == 0) && (old.height == 0)) { old.width = size.width; old.height = size.height; } else { old.width -= size.width; old.height -= size.height; if (old.width != old.height) { System.err.println("ERROR: " + old.width + " != " + old.height); System.err.flush(); if (null != System.getProperty("test.src", null)) { System.exit(1); // automatic regression test } } // prepare dimensions for the next test old.width = 0; old.height = 0; } } }