Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/swing/SwingAccessor.java
38829 views
/*1* Copyright (c) 2009, 2014, 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 sun.misc.Unsafe;2829import java.awt.Point;30import javax.swing.RepaintManager;3132import javax.swing.text.JTextComponent;33import javax.swing.TransferHandler;3435/**36* The SwingAccessor utility class.37* The main purpose of this class is to enable accessing38* private and package-private fields of classes from39* different classes/packages. See sun.misc.SharedSecretes40* for another example.41*/42public final class SwingAccessor {43private static final Unsafe unsafe = Unsafe.getUnsafe();4445/**46* We don't need any objects of this class.47* It's rather a collection of static methods48* and interfaces.49*/50private SwingAccessor() {51}5253/**54* An accessor for the JTextComponent class.55* Note that we intentionally introduce the JTextComponentAccessor,56* and not the JComponentAccessor because the needed methods57* aren't override methods.58*/59public interface JTextComponentAccessor {6061/**62* Calculates a custom drop location for the text component,63* representing where a drop at the given point should insert data.64*/65TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p);6667/**68* Called to set or clear the drop location during a DnD operation.69*/70Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,71Object state, boolean forDrop);72}7374/**75* An accessor for the JLightweightFrame class.76*/77public interface JLightweightFrameAccessor {78/**79* Notifies the JLightweight frame that it needs to update a cursor80*/81void updateCursor(JLightweightFrame frame);82}8384/**85* An accessor for the RepaintManager class.86*/87public interface RepaintManagerAccessor {88void addRepaintListener(RepaintManager rm, SwingUtilities2.RepaintListener l);89void removeRepaintListener(RepaintManager rm, SwingUtilities2.RepaintListener l);90}9192/**93* The javax.swing.text.JTextComponent class accessor object.94*/95private static JTextComponentAccessor jtextComponentAccessor;9697/**98* Set an accessor object for the javax.swing.text.JTextComponent class.99*/100public static void setJTextComponentAccessor(JTextComponentAccessor jtca) {101jtextComponentAccessor = jtca;102}103104/**105* Retrieve the accessor object for the javax.swing.text.JTextComponent class.106*/107public static JTextComponentAccessor getJTextComponentAccessor() {108if (jtextComponentAccessor == null) {109unsafe.ensureClassInitialized(JTextComponent.class);110}111112return jtextComponentAccessor;113}114115/**116* The JLightweightFrame class accessor object117*/118private static JLightweightFrameAccessor jLightweightFrameAccessor;119120/**121* Set an accessor object for the JLightweightFrame class.122*/123public static void setJLightweightFrameAccessor(JLightweightFrameAccessor accessor) {124jLightweightFrameAccessor = accessor;125}126127/**128* Retrieve the accessor object for the JLightweightFrame class129*/130public static JLightweightFrameAccessor getJLightweightFrameAccessor() {131if (jLightweightFrameAccessor == null) {132unsafe.ensureClassInitialized(JLightweightFrame.class);133}134return jLightweightFrameAccessor;135}136137/**138* The RepaintManager class accessor object.139*/140private static RepaintManagerAccessor repaintManagerAccessor;141142/**143* Set an accessor object for the RepaintManager class.144*/145public static void setRepaintManagerAccessor(RepaintManagerAccessor accessor) {146repaintManagerAccessor = accessor;147}148149/**150* Retrieve the accessor object for the RepaintManager class.151*/152public static RepaintManagerAccessor getRepaintManagerAccessor() {153if (repaintManagerAccessor == null) {154unsafe.ensureClassInitialized(RepaintManager.class);155}156return repaintManagerAccessor;157}158}159160161