Path: blob/master/src/java.desktop/share/classes/sun/swing/SwingAccessor.java
41153 views
/*1* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.swing;2627import java.awt.*;28import java.lang.invoke.MethodHandles;29import javax.swing.*;3031import javax.swing.text.JTextComponent;3233/**34* The SwingAccessor utility class.35* The main purpose of this class is to enable accessing36* private and package-private fields of classes from37* different classes/packages. See sun.misc.SharedSecretes38* for another example.39*/40public final class SwingAccessor {41/**42* We don't need any objects of this class.43* It's rather a collection of static methods44* and interfaces.45*/46private SwingAccessor() {47}4849/**50* An accessor for the JComponent class.51*/52public interface JComponentAccessor {5354boolean getFlag(JComponent comp, int aFlag);5556void compWriteObjectNotify(JComponent comp);57}5859/**60* An accessor for the JTextComponent class.61* Note that we intentionally introduce the JTextComponentAccessor,62* and not the JComponentAccessor because the needed methods63* aren't override methods.64*/65public interface JTextComponentAccessor {6667/**68* Calculates a custom drop location for the text component,69* representing where a drop at the given point should insert data.70*/71TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p);7273/**74* Called to set or clear the drop location during a DnD operation.75*/76Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,77Object state, boolean forDrop);78}7980/**81* An accessor for the JLightweightFrame class.82*/83public interface JLightweightFrameAccessor {84/**85* Notifies the JLightweight frame that it needs to update a cursor86*/87void updateCursor(JLightweightFrame frame);88}8990/**91* An accessor for the UIDefaults class.92*/93public interface UIDefaultsAccessor {94/**95* Adds a resource bundle to the list of resource bundles.96*/97void addInternalBundle(UIDefaults uiDefaults, String bundleName);98}99100/**101* An accessor for the RepaintManager class.102*/103public interface RepaintManagerAccessor {104void addRepaintListener(RepaintManager rm, SwingUtilities2.RepaintListener l);105void removeRepaintListener(RepaintManager rm, SwingUtilities2.RepaintListener l);106}107108/**109* An accessor for PopupFactory class.110*/111public interface PopupFactoryAccessor {112Popup getHeavyWeightPopup(PopupFactory factory, Component owner, Component contents,113int ownerX, int ownerY);114}115116/*117* An accessor for the KeyStroke class118*/119public interface KeyStrokeAccessor {120121KeyStroke create();122}123124/**125* The javax.swing.JComponent class accessor object.126*/127private static JComponentAccessor jComponentAccessor;128129/**130* Set an accessor object for the javax.swing.JComponent class.131*/132public static void setJComponentAccessor(JComponentAccessor jCompAccessor) {133jComponentAccessor = jCompAccessor;134}135136/**137* Retrieve the accessor object for the javax.swing.JComponent class.138*/139public static JComponentAccessor getJComponentAccessor() {140if (jComponentAccessor == null) {141ensureClassInitialized(JComponent.class);142}143144return jComponentAccessor;145}146147/**148* The javax.swing.text.JTextComponent class accessor object.149*/150private static JTextComponentAccessor jtextComponentAccessor;151152/**153* Set an accessor object for the javax.swing.text.JTextComponent class.154*/155public static void setJTextComponentAccessor(JTextComponentAccessor jtca) {156jtextComponentAccessor = jtca;157}158159/**160* Retrieve the accessor object for the javax.swing.text.JTextComponent class.161*/162public static JTextComponentAccessor getJTextComponentAccessor() {163if (jtextComponentAccessor == null) {164ensureClassInitialized(JTextComponent.class);165}166167return jtextComponentAccessor;168}169170/**171* The JLightweightFrame class accessor object172*/173private static JLightweightFrameAccessor jLightweightFrameAccessor;174175/**176* Set an accessor object for the JLightweightFrame class.177*/178public static void setJLightweightFrameAccessor(JLightweightFrameAccessor accessor) {179jLightweightFrameAccessor = accessor;180}181182/**183* Retrieve the accessor object for the JLightweightFrame class184*/185public static JLightweightFrameAccessor getJLightweightFrameAccessor() {186if (jLightweightFrameAccessor == null) {187ensureClassInitialized(JLightweightFrame.class);188}189return jLightweightFrameAccessor;190}191192/**193* The UIDefaults class accessor object194*/195private static UIDefaultsAccessor uiDefaultsAccessor;196197/**198* Set an accessor object for the UIDefaults class.199*/200public static void setUIDefaultsAccessor(UIDefaultsAccessor accessor) {201uiDefaultsAccessor = accessor;202}203204/**205* Retrieve the accessor object for the JLightweightFrame class206*/207public static UIDefaultsAccessor getUIDefaultsAccessor() {208if (uiDefaultsAccessor == null) {209ensureClassInitialized(UIDefaults.class);210}211return uiDefaultsAccessor;212}213214/**215* The RepaintManager class accessor object.216*/217private static RepaintManagerAccessor repaintManagerAccessor;218219/**220* Set an accessor object for the RepaintManager class.221*/222public static void setRepaintManagerAccessor(RepaintManagerAccessor accessor) {223repaintManagerAccessor = accessor;224}225226/**227* Retrieve the accessor object for the RepaintManager class.228*/229public static RepaintManagerAccessor getRepaintManagerAccessor() {230if (repaintManagerAccessor == null) {231ensureClassInitialized(RepaintManager.class);232}233return repaintManagerAccessor;234}235236/**237* The PopupFactory class accessor object.238*/239private static PopupFactoryAccessor popupFactoryAccessor;240241/**242* Retrieve the accessor object for the PopupFactory class.243*/244public static PopupFactoryAccessor getPopupFactoryAccessor() {245if (popupFactoryAccessor == null) {246ensureClassInitialized(PopupFactory.class);247}248return popupFactoryAccessor;249}250251/**252* Set an Accessor object for the PopupFactory class.253*/254public static void setPopupFactoryAccessor(PopupFactoryAccessor popupFactoryAccessor) {255SwingAccessor.popupFactoryAccessor = popupFactoryAccessor;256}257258/**259* The KeyStroke class accessor object.260*/261private static KeyStrokeAccessor keyStrokeAccessor;262263/**264* Retrieve the accessor object for the KeyStroke class.265*/266public static KeyStrokeAccessor getKeyStrokeAccessor() {267if (keyStrokeAccessor == null) {268ensureClassInitialized(KeyStroke.class);269}270return keyStrokeAccessor;271}272273/*274* Set the accessor object for the KeyStroke class.275*/276public static void setKeyStrokeAccessor(KeyStrokeAccessor accessor) {277SwingAccessor.keyStrokeAccessor = accessor;278}279280private static void ensureClassInitialized(Class<?> c) {281try {282MethodHandles.lookup().ensureInitialized(c);283} catch (IllegalAccessException e) {}284}285}286287288