1 /*
   2  * Copyright (c) 2013, 2015, 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 
  25 import java.awt.*;
  26 import java.awt.Frame;
  27 import java.awt.datatransfer.Clipboard;
  28 import java.awt.font.TextAttribute;
  29 import java.awt.im.InputMethodHighlight;
  30 import java.awt.image.ColorModel;
  31 import java.awt.image.ImageObserver;
  32 import java.awt.image.ImageProducer;
  33 import java.net.URL;
  34 import java.util.Map;
  35 import java.util.Properties;
  36 
  37 
  38 /**
  39  * @test
  40  * @bug 7172833
  41  * @summary java.awt.Toolkit methods is/setDynamicLayout() should be consistent.
  42  * @author Sergey Bylokhov
  43  */
  44 public final class bug7172833 {
  45 
  46     public static void main(final String[] args) throws Exception {
  47         final StubbedToolkit t = new StubbedToolkit();
  48         final Boolean dynamicLayoutSupported
  49                 = (Boolean) t.getDesktopProperty("awt.dynamicLayoutSupported");
  50         t.setDynamicLayout(true);
  51         if(!t.isDynamicLayoutSet()){
  52             throw new RuntimeException("'true' expected but 'false' returned");
  53         }
  54         if (dynamicLayoutSupported) {
  55             if (!t.isDynamicLayoutActive()) {
  56                 throw new RuntimeException("is inactive but set+supported");
  57             }
  58         } else {
  59             if (t.isDynamicLayoutActive()) {
  60                 throw new RuntimeException("is active but unsupported");
  61             }
  62         }
  63 
  64         t.setDynamicLayout(false);
  65         if(t.isDynamicLayoutSet()){
  66             throw new RuntimeException("'false' expected but 'true' returned");
  67         }
  68         if (dynamicLayoutSupported) {
  69             // Layout is supported and was set to false, cannot verifym because
  70             // the native system is free to ignore our request.
  71         } else {
  72             if (t.isDynamicLayoutActive()) {
  73                 throw new RuntimeException("is active but unset+unsupported");
  74             }
  75         }
  76     }
  77 
  78     static final class StubbedToolkit extends Toolkit {
  79 
  80         @Override
  81         protected boolean isDynamicLayoutSet() throws HeadlessException {
  82             return super.isDynamicLayoutSet();
  83         }
  84 
  85 
  86         @Override
  87         public Dimension getScreenSize() throws HeadlessException {
  88             return null;
  89         }
  90 
  91         @Override
  92         public int getScreenResolution() throws HeadlessException {
  93             return 0;
  94         }
  95 
  96         @Override
  97         public ColorModel getColorModel() throws HeadlessException {
  98             return null;
  99         }
 100 
 101         @Override
 102         public String[] getFontList() {
 103             return new String[0];
 104         }
 105 
 106         @Override
 107         public FontMetrics getFontMetrics(final Font font) {
 108             return null;
 109         }
 110 
 111         @Override
 112         public void sync() {
 113 
 114         }
 115 
 116         @Override
 117         public Image getImage(final String filename) {
 118             return null;
 119         }
 120 
 121         @Override
 122         public Image getImage(final URL url) {
 123             return null;
 124         }
 125 
 126         @Override
 127         public Image createImage(final String filename) {
 128             return null;
 129         }
 130 
 131         @Override
 132         public Image createImage(final URL url) {
 133             return null;
 134         }
 135 
 136         @Override
 137         public boolean prepareImage(
 138                 final Image image, final int width, final int height,
 139                                     final ImageObserver observer) {
 140             return false;
 141         }
 142 
 143         @Override
 144         public int checkImage(final Image image, final int width, final int height,
 145                               final ImageObserver observer) {
 146             return 0;
 147         }
 148 
 149         @Override
 150         public Image createImage(final ImageProducer producer) {
 151             return null;
 152         }
 153 
 154         @Override
 155         public Image createImage(final byte[] imagedata, final int imageoffset,
 156                                  final int imagelength) {
 157             return null;
 158         }
 159 
 160         @Override
 161         public PrintJob getPrintJob(final Frame frame, final String jobtitle,
 162                                     final Properties props) {
 163             return null;
 164         }
 165 
 166         @Override
 167         public void beep() {
 168 
 169         }
 170 
 171         @Override
 172         public Clipboard getSystemClipboard() throws HeadlessException {
 173             return null;
 174         }
 175 
 176         @Override
 177         protected EventQueue getSystemEventQueueImpl() {
 178             return null;
 179         }
 180 
 181         @Override
 182         public boolean isModalityTypeSupported(
 183                 final Dialog.ModalityType modalityType) {
 184             return false;
 185         }
 186 
 187         @Override
 188         public boolean isModalExclusionTypeSupported(
 189                 final Dialog.ModalExclusionType modalExclusionType) {
 190             return false;
 191         }
 192 
 193         @Override
 194         public Map<TextAttribute, ?> mapInputMethodHighlight(
 195                 final InputMethodHighlight highlight) throws HeadlessException {
 196             return null;
 197         }
 198     }
 199 }