|
| 1 | +/* |
| 2 | + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +import java.awt.Color; |
| 25 | +import java.awt.Frame; |
| 26 | +import java.awt.Toolkit; |
| 27 | +import java.beans.PropertyChangeEvent; |
| 28 | +import java.beans.PropertyChangeListener; |
| 29 | + |
| 30 | +/* |
| 31 | + * @test |
| 32 | + * @bug 4368193 |
| 33 | + * @library /java/awt/regtesthelpers |
| 34 | + * @build PassFailJFrame |
| 35 | + * @requires (os.family == "windows") |
| 36 | + * @summary Toolkit's getDesktopProperty returns stale values on Microsoft Windows |
| 37 | + * @run main/manual ThreeDBackgroundColor |
| 38 | + */ |
| 39 | + |
| 40 | +public class ThreeDBackgroundColor { |
| 41 | + |
| 42 | + private static final String PROP_NAME = "win.3d.backgroundColor"; |
| 43 | + |
| 44 | + public static void main(String[] args) throws Exception { |
| 45 | + String INSTRUCTIONS = """ |
| 46 | + On Windows 10: |
| 47 | + 1. Open Windows Settings, in the search bar type |
| 48 | + 'high contrast', in the list of suggestions choose option |
| 49 | + 'Turn high contrast on or off' |
| 50 | + 2. In the High contrast control panel click on the on/off switch |
| 51 | + to initialize High contrast mode |
| 52 | + 3. Wait for the High contrast mode to finish initialization |
| 53 | + 4. Click on the same switch again to turn off High contrast mode |
| 54 | +
|
| 55 | + On Windows 11: |
| 56 | + 1. Open Windows settings, in the search bar type |
| 57 | + 'Contrast Theme'. |
| 58 | + 2. Select any value from 'Contrast themes' dropdown menu and press 'Apply'. |
| 59 | + 3. Wait for the High contrast mode to finish initialization |
| 60 | + 4. Select 'None' from 'Contrast themes' dropdown menu to revert the changes. |
| 61 | +
|
| 62 | + Take a look at the output window to determine if the test passed or failed."""; |
| 63 | + |
| 64 | + PassFailJFrame.builder() |
| 65 | + .title("ThreeDBackgroundColor Test Instructions") |
| 66 | + .instructions(INSTRUCTIONS) |
| 67 | + .rows((int) INSTRUCTIONS.lines().count() + 2) |
| 68 | + .columns(40) |
| 69 | + .testTimeOut(5) |
| 70 | + .testUI(ThreeDBackgroundColor::createUI) |
| 71 | + .logArea(8) |
| 72 | + .build() |
| 73 | + .awaitAndCheck(); |
| 74 | + } |
| 75 | + |
| 76 | + private static Frame createUI() { |
| 77 | + Frame f = new Frame("ThreeDBackgroundColor Test"); |
| 78 | + f.setSize(50, 50); |
| 79 | + |
| 80 | + Object value = Toolkit.getDefaultToolkit().getDesktopProperty(PROP_NAME); |
| 81 | + PassFailJFrame.log("toolkit.getDesktopProperty:" + PROP_NAME + "=" + value); |
| 82 | + |
| 83 | + Toolkit.getDefaultToolkit().addPropertyChangeListener(PROP_NAME, new PropertyChangeListener() { |
| 84 | + public void propertyChange(PropertyChangeEvent e) { |
| 85 | + PassFailJFrame.log("PropertyChangeEvent: " + e.getPropertyName() + |
| 86 | + "\n old value=" + e.getOldValue() + |
| 87 | + "\n new value=" + e.getNewValue()); |
| 88 | + |
| 89 | + Color value = (Color) Toolkit.getDefaultToolkit().getDesktopProperty(PROP_NAME); |
| 90 | + PassFailJFrame.log("toolkit.getDesktopProperty:" + PROP_NAME + "=" + value); |
| 91 | + if (value.equals((Color) e.getNewValue())) { |
| 92 | + PassFailJFrame.log("test PASSED"); |
| 93 | + } else { |
| 94 | + PassFailJFrame.log("test FAILED"); |
| 95 | + } |
| 96 | + } |
| 97 | + }); |
| 98 | + return f; |
| 99 | + } |
| 100 | +} |
0 commit comments