|
| 1 | +/* |
| 2 | + * Copyright (c) 2005, 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.Button; |
| 25 | +import java.awt.Canvas; |
| 26 | +import java.awt.Checkbox; |
| 27 | +import java.awt.Choice; |
| 28 | +import java.awt.Component; |
| 29 | +import java.awt.Frame; |
| 30 | +import java.awt.GridLayout; |
| 31 | +import java.awt.Image; |
| 32 | +import java.awt.Label; |
| 33 | +import java.awt.Menu; |
| 34 | +import java.awt.MenuBar; |
| 35 | +import java.awt.MenuItem; |
| 36 | +import java.awt.Panel; |
| 37 | +import java.awt.PopupMenu; |
| 38 | +import java.awt.ScrollPane; |
| 39 | +import java.awt.Scrollbar; |
| 40 | +import java.awt.TextArea; |
| 41 | +import java.awt.TextField; |
| 42 | +import java.awt.Window; |
| 43 | +import java.awt.event.MouseAdapter; |
| 44 | +import java.awt.event.MouseEvent; |
| 45 | +import java.io.File; |
| 46 | +import java.util.ArrayList; |
| 47 | +import java.util.List; |
| 48 | + |
| 49 | +import javax.swing.ImageIcon; |
| 50 | +import javax.swing.JLabel; |
| 51 | + |
| 52 | +/* |
| 53 | + * @test |
| 54 | + * @bug 5092883 6513478 7154025 |
| 55 | + * @requires (os.family == "linux") |
| 56 | + * @summary REGRESSION: SystemColor class gives back wrong values under Linux |
| 57 | + * @library /java/awt/regtesthelpers |
| 58 | + * @build PassFailJFrame |
| 59 | + * @run main/manual XAWTDifference |
| 60 | + */ |
| 61 | + |
| 62 | +public class XAWTDifference { |
| 63 | + |
| 64 | + private static final String INSTRUCTIONS = """ |
| 65 | + You would see a frame with title "XAWTDifference Test Frame". |
| 66 | +
|
| 67 | + Test Frame (1) |
| 68 | +
|
| 69 | + a) It has three columns in it. The 1st one with ordinary components. |
| 70 | + The 2nd one with disabled components. |
| 71 | + The 3rd one with uneditable components (only text components |
| 72 | + are there). Verify that the difference between different states |
| 73 | + is visible. |
| 74 | +
|
| 75 | + Standard Frame (2) |
| 76 | +
|
| 77 | + b) You would also see a frame named StandardFrame (2) |
| 78 | + with a lot of components in it. Actually this is just a jpg-image |
| 79 | + in a frame. Verify that every component in the frame (1) looks |
| 80 | + similar to the same component in (2). |
| 81 | +
|
| 82 | + They might differ in colors and be darker or brighter but |
| 83 | + the whole picture should be the same. |
| 84 | +
|
| 85 | + c) Also check the color of the MenuBar Items in the MenuBar and |
| 86 | + the PopupMenu assigned to TextArea. |
| 87 | + As you can't compare the colors of menu items with the picture |
| 88 | + so just look if the are adequate enough. |
| 89 | + """; |
| 90 | + private static final int HGAP = 20; |
| 91 | + |
| 92 | + public static void main(String[] args) throws Exception { |
| 93 | + PassFailJFrame.builder() |
| 94 | + .title("Test Instructions") |
| 95 | + .instructions(INSTRUCTIONS) |
| 96 | + .columns(40) |
| 97 | + .testUI(XAWTDifference::createAndShowUI) |
| 98 | + .positionTestUI(XAWTDifference::positionMultiTestUI) |
| 99 | + .build() |
| 100 | + .awaitAndCheck(); |
| 101 | + } |
| 102 | + |
| 103 | + private static Panel addComponentsIntoPanel(boolean enabled, boolean editable) { |
| 104 | + TextField tf = new TextField("TextField"); |
| 105 | + TextArea ta = new TextArea("TextArea", 10, 10); |
| 106 | + |
| 107 | + Choice levelChooser = new Choice(); |
| 108 | + levelChooser.add("Item #1"); |
| 109 | + levelChooser.add("Item #2"); |
| 110 | + |
| 111 | + Button b = new Button("BUTTON"); |
| 112 | + Label label = new Label("LABEL"); |
| 113 | + java.awt.List list = new java.awt.List(4, false); |
| 114 | + list.add("one"); |
| 115 | + list.add("two"); |
| 116 | + list.add("three"); |
| 117 | + |
| 118 | + Checkbox chb = new Checkbox(); |
| 119 | + Scrollbar sb = new Scrollbar(Scrollbar.HORIZONTAL); |
| 120 | + ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS); |
| 121 | + sp.add(new TextArea("this is a textarea in scrollpane")); |
| 122 | + sp.setSize(200, 200); |
| 123 | + Canvas canvas = new Canvas(); |
| 124 | + canvas.setSize(100, 100); |
| 125 | + |
| 126 | + //add popup menu to Button |
| 127 | + final PopupMenu pm = new PopupMenu(); |
| 128 | + MenuItem i1 = new MenuItem("Item1"); |
| 129 | + MenuItem i2 = new MenuItem("Item2"); |
| 130 | + MenuItem i3 = new MenuItem("Item3"); |
| 131 | + i3.setEnabled(false); |
| 132 | + pm.add(i1); |
| 133 | + pm.add(i2); |
| 134 | + pm.add(i3); |
| 135 | + canvas.add(pm); |
| 136 | + |
| 137 | + ta.add(pm); |
| 138 | + ta.addMouseListener(new MouseAdapter() { |
| 139 | + public void mousePressed(MouseEvent me) { |
| 140 | + if (me.isPopupTrigger()) { |
| 141 | + pm.show(me.getComponent(), me.getX(), me.getY()); |
| 142 | + } |
| 143 | + } |
| 144 | + }); |
| 145 | + |
| 146 | + ArrayList<Component> componentList = new ArrayList<>(); |
| 147 | + |
| 148 | + componentList.add(tf); |
| 149 | + componentList.add(ta); |
| 150 | + if (editable){ |
| 151 | + componentList.add(levelChooser); |
| 152 | + componentList.add(b); |
| 153 | + componentList.add(label); |
| 154 | + componentList.add(list); |
| 155 | + componentList.add(chb); |
| 156 | + componentList.add(sb); |
| 157 | + componentList.add(sp); |
| 158 | + componentList.add(canvas); |
| 159 | + } else { |
| 160 | + tf.setEditable(false); |
| 161 | + ta.setEditable(false); |
| 162 | + } |
| 163 | + |
| 164 | + Panel panel = new Panel(); |
| 165 | + panel.setLayout(new GridLayout(0, 1)); |
| 166 | + for (Component c : componentList) { |
| 167 | + if (!enabled) { |
| 168 | + c.setEnabled(false); |
| 169 | + } |
| 170 | + panel.add(c); |
| 171 | + } |
| 172 | + return panel; |
| 173 | + } |
| 174 | + |
| 175 | + private static List<Window> createAndShowUI() { |
| 176 | + Frame testFrame = new Frame("XAWTDifference Test Frame"); |
| 177 | + StandardFrame standardFrame = new StandardFrame("StandardFrame"); |
| 178 | + standardFrame.pack(); |
| 179 | + |
| 180 | + testFrame.setLayout(new GridLayout(1, 3)); |
| 181 | + testFrame.add(addComponentsIntoPanel(true, true)); |
| 182 | + testFrame.add(addComponentsIntoPanel(false, true)); |
| 183 | + testFrame.add(addComponentsIntoPanel(true, false)); |
| 184 | + |
| 185 | + MenuItem mi1 = new MenuItem("Item1"); |
| 186 | + MenuItem mi2 = new MenuItem("Item2"); |
| 187 | + MenuItem mi3 = new MenuItem("Disabled Item3"); |
| 188 | + mi3.setEnabled(false); |
| 189 | + |
| 190 | + MenuBar mb = new MenuBar(); |
| 191 | + Menu enabledMenu = new Menu("Enabled Menu"); |
| 192 | + Menu disabledMenu = new Menu("Disabled Menu"); |
| 193 | + disabledMenu.setEnabled(false); |
| 194 | + mb.add(enabledMenu); |
| 195 | + mb.add(disabledMenu); |
| 196 | + enabledMenu.add(mi1); |
| 197 | + enabledMenu.add(mi2); |
| 198 | + enabledMenu.add(mi3); |
| 199 | + |
| 200 | + testFrame.setMenuBar(mb); |
| 201 | + testFrame.setSize(standardFrame.getWidth(), standardFrame.getHeight()); |
| 202 | + return List.of(testFrame, standardFrame); |
| 203 | + } |
| 204 | + |
| 205 | + private static void positionMultiTestUI(List<? extends Window> windows, |
| 206 | + PassFailJFrame.InstructionUI instructionUI) { |
| 207 | + int x = instructionUI.getLocation().x + instructionUI.getSize().width + HGAP; |
| 208 | + for (Window w : windows) { |
| 209 | + w.setLocation(x, instructionUI.getLocation().y); |
| 210 | + x += w.getWidth() + HGAP; |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + private static class StandardFrame extends Frame { |
| 215 | + public StandardFrame(String name) { |
| 216 | + super(name); |
| 217 | + String testPath = System.getProperty("test.src", "."); |
| 218 | + Panel panel = new Panel(); |
| 219 | + panel.add(new JLabel(new ImageIcon(testPath + File.separator + "XAWTColors.jpg"))); |
| 220 | + add(panel); |
| 221 | + } |
| 222 | + } |
| 223 | +} |
0 commit comments