< 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


  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
  75  * existing.
  76  *
  77  */
  78 public class SwingUtilities2 {
  79     /**
  80      * The {@code AppContext} key for our one {@code LAFState}
  81      * instance.
  82      */
  83     public static final Object LAF_STATE_KEY =


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


  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 import sun.java2d.pipe.Region;
  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
  76  * existing.
  77  *
  78  */
  79 public class SwingUtilities2 {
  80     /**
  81      * The {@code AppContext} key for our one {@code LAFState}
  82      * instance.
  83      */
  84     public static final Object LAF_STATE_KEY =


2254     public static GraphicsConfiguration getGraphicsConfigurationAtPoint(GraphicsConfiguration current, double x, double y) {
2255 
2256         if (current.getBounds().contains(x, y)) {
2257             return current;
2258         }
2259 
2260         GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
2261         GraphicsDevice[] devices = env.getScreenDevices();
2262 
2263         for (GraphicsDevice device : devices) {
2264             GraphicsConfiguration config = device.getDefaultConfiguration();
2265             if (config.getBounds().contains(x, y)) {
2266                 return config;
2267             }
2268         }
2269 
2270         return current;
2271     }
2272 
2273     /**
2274      * Converts coordinates from the user's space to the device space using
2275      * appropriate device transformation.
2276      *
2277      * @param  x coordinate in the user space
2278      * @param  y coordinate in the user space
2279      * @return the point which uses device space(pixels)
2280      */
2281     public static Point convertToDeviceSpace(double x, double y) {
2282         GraphicsConfiguration gc =
2283                 GraphicsEnvironment.getLocalGraphicsEnvironment()
2284                         .getDefaultScreenDevice().getDefaultConfiguration();
2285         gc = getGraphicsConfigurationAtPoint(gc, x, y);
2286 
2287         AffineTransform tx = gc.getDefaultTransform();
2288         x = Region.clipRound(x * tx.getScaleX());
2289         y = Region.clipRound(y * tx.getScaleY());
2290 
2291         return new Point((int) x, (int) y);
2292     }
2293 
2294     /**
2295      * Used to listen to "blit" repaints in RepaintManager.
2296      */
2297     public interface RepaintListener {
2298         void repaintPerformed(JComponent c, int x, int y, int w, int h);
2299     }
2300 }
< prev index next >