1 /* 2 * Copyright (c) 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 import java.awt.Color; 24 import java.awt.Component; 25 import java.util.Enumeration; 26 import javax.swing.JComponent; 27 import javax.swing.SwingUtilities; 28 import javax.swing.text.AttributeSet; 29 import javax.swing.text.Document; 30 import javax.swing.text.Element; 31 import javax.swing.text.html.HTML; 32 import javax.swing.text.html.ObjectView; 33 /* 34 * @test 35 * @bug 8080972 8169887 36 * @summary Audit Core Reflection in module java.desktop for places that will 37 * require changes to work with modules 38 * @author Alexander Scherbatiy 39 * @run main/othervm TestObjectView 40 */ 41 42 public class TestObjectView { 43 44 public static void main(String[] args) throws Exception { 45 SwingUtilities.invokeAndWait(TestObjectView::testObjectView); 46 System.setSecurityManager(new SecurityManager()); 47 SwingUtilities.invokeAndWait(TestObjectView::testObjectView); 48 } 49 50 private static void testObjectView() { 51 52 UserObjectView objectView = new UserObjectView(new UserElement()); 53 54 Component comp = objectView.createComponent(); 55 56 if (!(comp instanceof UserJComponent)) { 57 throw new RuntimeException("Component is not UserJComponent!"); 58 } 59 } 60 public static class UserJComponent extends JComponent { 61 62 public static final Color USER_COLOR = new Color(10, 20, 30); 63 public static final Color TEST_COLOR = new Color(15, 25, 35); 64 65 Color color = USER_COLOR; 66 67 public UserJComponent() { 68 69 } 70 71 public Color getUserColor() { 72 System.out.println("[user component] get user color"); 73 return color; 74 } 75 76 public void setUserColor(Color color) { 77 System.out.println("[user component] set user color"); 78 this.color = color; 79 } 80 81 } 82 83 public static class UserObjectView extends ObjectView { 84 85 public UserObjectView(Element elem) { 86 super(elem); 87 } 88 89 @Override 90 public Component createComponent() { 91 return super.createComponent(); 92 } 93 } 94 95 public static class UserElement implements Element { 96 97 @Override 98 public Document getDocument() { 99 throw new UnsupportedOperationException("Not supported yet."); 100 } 101 102 @Override 103 public Element getParentElement() { 104 throw new UnsupportedOperationException("Not supported yet."); 105 } 106 107 @Override 108 public String getName() { 109 throw new UnsupportedOperationException("Not supported yet."); 110 } 111 112 @Override 113 public AttributeSet getAttributes() { 114 return new AttributeSet() { 115 116 @Override 117 public int getAttributeCount() { 118 throw new UnsupportedOperationException("Not supported yet."); 119 } 120 121 @Override 122 public boolean isDefined(Object attrName) { 123 throw new UnsupportedOperationException("Not supported yet."); 124 } 125 126 @Override 127 public boolean isEqual(AttributeSet attr) { 128 throw new UnsupportedOperationException("Not supported yet."); 129 } 130 131 @Override 132 public AttributeSet copyAttributes() { 133 throw new UnsupportedOperationException("Not supported yet."); 134 } 135 136 @Override 137 public Object getAttribute(Object key) { 138 if (key.equals(HTML.Attribute.CLASSID)) { 139 return UserJComponent.class.getName(); 140 } 141 142 return null; 143 } 144 145 @Override 146 public Enumeration<?> getAttributeNames() { 147 throw new UnsupportedOperationException("Not supported yet."); 148 } 149 150 @Override 151 public boolean containsAttribute(Object name, Object value) { 152 throw new UnsupportedOperationException("Not supported yet."); 153 } 154 155 @Override 156 public boolean containsAttributes(AttributeSet attributes) { 157 throw new UnsupportedOperationException("Not supported yet."); 158 } 159 160 @Override 161 public AttributeSet getResolveParent() { 162 throw new UnsupportedOperationException("Not supported yet."); 163 } 164 }; 165 } 166 167 @Override 168 public int getStartOffset() { 169 throw new UnsupportedOperationException("Not supported yet."); 170 } 171 172 @Override 173 public int getEndOffset() { 174 throw new UnsupportedOperationException("Not supported yet."); 175 } 176 177 @Override 178 public int getElementIndex(int offset) { 179 throw new UnsupportedOperationException("Not supported yet."); 180 } 181 182 @Override 183 public int getElementCount() { 184 throw new UnsupportedOperationException("Not supported yet."); 185 } 186 187 @Override 188 public Element getElement(int index) { 189 throw new UnsupportedOperationException("Not supported yet."); 190 } 191 192 @Override 193 public boolean isLeaf() { 194 throw new UnsupportedOperationException("Not supported yet."); 195 } 196 } 197 }