< prev index next >

src/java.desktop/share/classes/sun/swing/SwingUtilities2.java

Print this page


   1 /*
   2  * Copyright (c) 2002, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  35 import static java.awt.geom.AffineTransform.TYPE_FLIP;
  36 import static java.awt.geom.AffineTransform.TYPE_MASK_SCALE;
  37 import static java.awt.geom.AffineTransform.TYPE_TRANSLATION;
  38 import java.awt.print.PrinterGraphics;
  39 import java.text.BreakIterator;
  40 import java.text.CharacterIterator;
  41 import java.text.AttributedCharacterIterator;
  42 import java.text.AttributedString;
  43 
  44 import javax.swing.*;
  45 import javax.swing.event.TreeModelEvent;
  46 import javax.swing.text.Highlighter;
  47 import javax.swing.text.JTextComponent;
  48 import javax.swing.text.DefaultHighlighter;
  49 import javax.swing.text.DefaultCaret;
  50 import javax.swing.table.TableCellRenderer;
  51 import javax.swing.table.TableColumnModel;
  52 import javax.swing.tree.TreeModel;
  53 import javax.swing.tree.TreePath;
  54 

  55 import sun.print.ProxyPrintGraphics;
  56 import sun.awt.*;
  57 import java.io.*;
  58 import java.security.AccessController;
  59 import java.security.PrivilegedAction;
  60 import java.util.*;
  61 import sun.font.FontDesignMetrics;
  62 import sun.font.FontUtilities;
  63 import sun.java2d.SunGraphicsEnvironment;
  64 
  65 import java.util.concurrent.Callable;
  66 import java.util.concurrent.Future;
  67 import java.util.concurrent.FutureTask;
  68 
  69 /**
  70  * A collection of utility methods for Swing.
  71  * <p>
  72  * <b>WARNING:</b> While this class is public, it should not be treated as
  73  * public API and its API may change in incompatable ways between dot dot
  74  * releases and even patch releases. You should not rely on this class even


2224     /**
2225      * Returns the client property for the given key if it is set; otherwise
2226      * returns the {@L&F} property.
2227      *
2228      * @param component the component
2229      * @param key an {@code String} specifying the key for the desired boolean value
2230      * @return the boolean value of the client property if it is set or the {@L&F}
2231      *         property in other case.
2232      */
2233     public static boolean getBoolean(JComponent component, String key) {
2234         Object clientProperty = component.getClientProperty(key);
2235 
2236         if (clientProperty instanceof Boolean) {
2237             return Boolean.TRUE.equals(clientProperty);
2238         }
2239 
2240         return UIManager.getBoolean(key);
2241     }
2242 
2243     /**
2244      *
2245      * Returns the graphics configuration which bounds contain the given
2246      * point
2247      *
2248      * @param current the default configuration which is checked in the first place
2249      * @param x the x coordinate of the given point
2250      * @param y the y coordinate of the given point
2251      * @return the graphics configuration
2252      */
2253     public static GraphicsConfiguration getGraphicsConfigurationAtPoint(GraphicsConfiguration current, double x, double y) {
2254 
2255         if (current.getBounds().contains(x, y)) {
2256             return current;
2257         }
2258 
2259         GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
2260         GraphicsDevice[] devices = env.getScreenDevices();
2261 
2262         for (GraphicsDevice device : devices) {
2263             GraphicsConfiguration config = device.getDefaultConfiguration();
2264             if (config.getBounds().contains(x, y)) {
2265                 return config;
2266             }
2267         }
2268 
2269         return current;
2270     }
2271 
2272     /**
2273      * Used to listen to "blit" repaints in RepaintManager.
2274      */
2275     public interface RepaintListener {
2276         void repaintPerformed(JComponent c, int x, int y, int w, int h);
2277     }
2278 }
   1 /*
   2  * Copyright (c) 2002, 2018, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  35 import static java.awt.geom.AffineTransform.TYPE_FLIP;
  36 import static java.awt.geom.AffineTransform.TYPE_MASK_SCALE;
  37 import static java.awt.geom.AffineTransform.TYPE_TRANSLATION;
  38 import java.awt.print.PrinterGraphics;
  39 import java.text.BreakIterator;
  40 import java.text.CharacterIterator;
  41 import java.text.AttributedCharacterIterator;
  42 import java.text.AttributedString;
  43 
  44 import javax.swing.*;
  45 import javax.swing.event.TreeModelEvent;
  46 import javax.swing.text.Highlighter;
  47 import javax.swing.text.JTextComponent;
  48 import javax.swing.text.DefaultHighlighter;
  49 import javax.swing.text.DefaultCaret;
  50 import javax.swing.table.TableCellRenderer;
  51 import javax.swing.table.TableColumnModel;
  52 import javax.swing.tree.TreeModel;
  53 import javax.swing.tree.TreePath;
  54 
  55 import sun.java2d.pipe.Region;
  56 import sun.print.ProxyPrintGraphics;
  57 import sun.awt.*;
  58 import java.io.*;
  59 import java.security.AccessController;
  60 import java.security.PrivilegedAction;
  61 import java.util.*;
  62 import sun.font.FontDesignMetrics;
  63 import sun.font.FontUtilities;
  64 import sun.java2d.SunGraphicsEnvironment;
  65 
  66 import java.util.concurrent.Callable;
  67 import java.util.concurrent.Future;
  68 import java.util.concurrent.FutureTask;
  69 
  70 /**
  71  * A collection of utility methods for Swing.
  72  * <p>
  73  * <b>WARNING:</b> While this class is public, it should not be treated as
  74  * public API and its API may change in incompatable ways between dot dot
  75  * releases and even patch releases. You should not rely on this class even


2225     /**
2226      * Returns the client property for the given key if it is set; otherwise
2227      * returns the {@L&F} property.
2228      *
2229      * @param component the component
2230      * @param key an {@code String} specifying the key for the desired boolean value
2231      * @return the boolean value of the client property if it is set or the {@L&F}
2232      *         property in other case.
2233      */
2234     public static boolean getBoolean(JComponent component, String key) {
2235         Object clientProperty = component.getClientProperty(key);
2236 
2237         if (clientProperty instanceof Boolean) {
2238             return Boolean.TRUE.equals(clientProperty);
2239         }
2240 
2241         return UIManager.getBoolean(key);
2242     }
2243 
2244     /**





























2245      * Used to listen to "blit" repaints in RepaintManager.
2246      */
2247     public interface RepaintListener {
2248         void repaintPerformed(JComponent c, int x, int y, int w, int h);
2249     }
2250 }
< prev index next >