Java Code Examples for java.awt.GraphicsConfiguration#getDefaultTransform()
The following examples show how to use
java.awt.GraphicsConfiguration#getDefaultTransform() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VolatileSurfaceManager.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Creates a software-based surface (of type BufImgSurfaceData). * The software representation is only created when needed, which * is only during some situation in which the hardware surface * cannot be allocated. This allows apps to at least run, * albeit more slowly than they would otherwise. */ protected SurfaceData getBackupSurface() { if (sdBackup == null) { GraphicsConfiguration gc = vImg.getGraphicsConfig(); AffineTransform tx = gc.getDefaultTransform(); double scaleX = tx.getScaleX(); double scaleY = tx.getScaleY(); BufferedImage bImg = vImg.getBackupImage(scaleX, scaleY); // Sabotage the acceleration capabilities of the BufImg surface SunWritableRaster.stealTrackable(bImg .getRaster() .getDataBuffer()).setUntrackable(); sdBackup = BufImgSurfaceData.createData(bImg, scaleX, scaleY); } return sdBackup; }
Example 2
Source File: VolatileSurfaceManager.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Creates a software-based surface (of type BufImgSurfaceData). * The software representation is only created when needed, which * is only during some situation in which the hardware surface * cannot be allocated. This allows apps to at least run, * albeit more slowly than they would otherwise. */ protected SurfaceData getBackupSurface() { if (sdBackup == null) { GraphicsConfiguration gc = vImg.getGraphicsConfig(); AffineTransform tx = gc.getDefaultTransform(); double scaleX = tx.getScaleX(); double scaleY = tx.getScaleY(); BufferedImage bImg = vImg.getBackupImage(scaleX, scaleY); // Sabotage the acceleration capabilities of the BufImg surface SunWritableRaster.stealTrackable(bImg .getRaster() .getDataBuffer()).setUntrackable(); sdBackup = BufImgSurfaceData.createData(bImg, scaleX, scaleY); } return sdBackup; }
Example 3
Source File: RobotMultiDPIScreenTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
static void initScreenBounds() { GraphicsDevice[] devices = GraphicsEnvironment .getLocalGraphicsEnvironment() .getScreenDevices(); screenBounds = new Rectangle[devices.length]; scales = new double[devices.length][2]; for (int i = 0; i < devices.length; i++) { GraphicsConfiguration gc = devices[i].getDefaultConfiguration(); screenBounds[i] = gc.getBounds(); AffineTransform tx = gc.getDefaultTransform(); scales[i][0] = tx.getScaleX(); scales[i][1] = tx.getScaleY(); } maxBounds = screenBounds[0]; for (int i = 0; i < screenBounds.length; i++) { maxBounds = maxBounds.union(screenBounds[i]); } }
Example 4
Source File: WindowResizingOnSetLocationTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
static void initScreenBounds() { GraphicsDevice[] devices = GraphicsEnvironment .getLocalGraphicsEnvironment() .getScreenDevices(); screenBounds = new Rectangle[devices.length]; scales = new double[devices.length][2]; for (int i = 0; i < devices.length; i++) { GraphicsConfiguration gc = devices[i].getDefaultConfiguration(); screenBounds[i] = gc.getBounds(); AffineTransform tx = gc.getDefaultTransform(); scales[i][0] = tx.getScaleX(); scales[i][1] = tx.getScaleY(); } for (int i = 0; i < devices.length; i++) { for (int j = i + 1; j < devices.length; j++) { if (scales[i][0] != scales[j][0] || scales[i][1] != scales[j][1]) { screen1 = i; screen2 = j; } } } }
Example 5
Source File: VolatileSurfaceManager.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Creates a software-based surface (of type BufImgSurfaceData). * The software representation is only created when needed, which * is only during some situation in which the hardware surface * cannot be allocated. This allows apps to at least run, * albeit more slowly than they would otherwise. */ protected SurfaceData getBackupSurface() { if (sdBackup == null) { GraphicsConfiguration gc = vImg.getGraphicsConfig(); AffineTransform tx = gc.getDefaultTransform(); double scaleX = tx.getScaleX(); double scaleY = tx.getScaleY(); BufferedImage bImg = vImg.getBackupImage(scaleX, scaleY); // Sabotage the acceleration capabilities of the BufImg surface SunWritableRaster.stealTrackable(bImg .getRaster() .getDataBuffer()).setUntrackable(); sdBackup = BufImgSurfaceData.createData(bImg, scaleX, scaleY); } return sdBackup; }
Example 6
Source File: SunGraphicsEnvironment.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Converts coordinates from the user's space to the device space using * appropriate device transformation. * * @param x coordinate in the user space * @param y coordinate in the user space * @return the point which uses device space(pixels) */ public static Point convertToDeviceSpace(double x, double y) { GraphicsConfiguration gc = getLocalGraphicsEnvironment() .getDefaultScreenDevice().getDefaultConfiguration(); gc = getGraphicsConfigurationAtPoint(gc, x, y); AffineTransform tx = gc.getDefaultTransform(); x = Region.clipRound(x * tx.getScaleX()); y = Region.clipRound(y * tx.getScaleY()); return new Point((int) x, (int) y); }
Example 7
Source File: SwingUtilities2.java From Bytecoder with Apache License 2.0 | 5 votes |
private static FontRenderContext getFRCProperty(JComponent c) { if (c != null) { GraphicsConfiguration gc = c.getGraphicsConfiguration(); AffineTransform tx = (gc == null) ? null : gc.getDefaultTransform(); Object aaHint = c.getClientProperty(KEY_TEXT_ANTIALIASING); return getFRCFromCache(tx, aaHint); } return null; }
Example 8
Source File: ScaledTransform.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void testScaleFactor(final GraphicsConfiguration gc) { final Dialog dialog = new Dialog((Frame) null, "Test", true, gc); try { dialog.setSize(100, 100); Panel panel = new Panel() { @Override public void paint(Graphics g) { if (g instanceof Graphics2D) { AffineTransform gcTx = gc.getDefaultTransform(); AffineTransform gTx = ((Graphics2D) g).getTransform(); passed = gcTx.getScaleX() == gTx.getScaleX() && gcTx.getScaleY() == gTx.getScaleY(); } else { passed = true; } dialog.setVisible(false); } }; dialog.add(panel); dialog.setVisible(true); if (!passed) { throw new RuntimeException("Transform is not scaled!"); } } finally { dialog.dispose(); } }
Example 9
Source File: ScaledTransform.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private static void testScaleFactor(final GraphicsConfiguration gc) { final Dialog dialog = new Dialog((Frame) null, "Test", true, gc); try { dialog.setSize(100, 100); Panel panel = new Panel() { @Override public void paint(Graphics g) { if (g instanceof Graphics2D) { AffineTransform gcTx = gc.getDefaultTransform(); AffineTransform gTx = ((Graphics2D) g).getTransform(); passed = gcTx.getScaleX() == gTx.getScaleX() && gcTx.getScaleY() == gTx.getScaleY(); } else { passed = true; } dialog.setVisible(false); } }; dialog.add(panel); dialog.setVisible(true); if (!passed) { throw new RuntimeException("Transform is not scaled!"); } } finally { dialog.dispose(); } }
Example 10
Source File: FlatTitlePane.java From FlatLaf with Apache License 2.0 | 4 votes |
/** * Maximizes the window. */ protected void maximize() { if( !(window instanceof Frame) ) return; Frame frame = (Frame) window; // set maximized bounds to avoid that maximized window overlaps Windows task bar // (if not running in JBR and if not modified from the application) if( !hasJBRCustomDecoration() && (frame.getMaximizedBounds() == null || Objects.equals( frame.getMaximizedBounds(), rootPane.getClientProperty( "_flatlaf.maximizedBounds" ) )) ) { GraphicsConfiguration gc = window.getGraphicsConfiguration(); // Screen bounds, which may be smaller than physical size on Java 9+. // E.g. if running a 3840x2160 screen at 200%, screenBounds.size is 1920x1080. // In Java 9+, each screen can have its own scale factor. // // On Java 8, which does not scale, screenBounds.size of the primary screen // is identical to its physical size. But when the primary screen is scaled, // then screenBounds.size of secondary screens is scaled with the scale factor // of the primary screen. // E.g. primary 3840x2160 screen at 150%, secondary 1920x1080 screen at 100%, // then screenBounds.size is 3840x2160 on primary and 2880x1560 on secondary. Rectangle screenBounds = gc.getBounds(); int maximizedX = screenBounds.x; int maximizedY = screenBounds.y; int maximizedWidth = screenBounds.width; int maximizedHeight = screenBounds.height; if( !SystemInfo.IS_JAVA_15_OR_LATER ) { // on Java 8 to 14, maximized x,y are 0,0 based on all screens in a multi-screen environment maximizedX = 0; maximizedY = 0; // scale maximized screen size to get physical screen size for Java 9 to 14 AffineTransform defaultTransform = gc.getDefaultTransform(); maximizedWidth = (int) (maximizedWidth * defaultTransform.getScaleX()); maximizedHeight = (int) (maximizedHeight * defaultTransform.getScaleY()); } // screen insets are in physical size, except for Java 15+ // (see https://bugs.openjdk.java.net/browse/JDK-8243925) // and except for Java 8 on secondary screens where primary screen is scaled Insets screenInsets = window.getToolkit().getScreenInsets( gc ); // maximized bounds are required in physical size, except for Java 15+ // (see https://bugs.openjdk.java.net/browse/JDK-8231564 and // https://bugs.openjdk.java.net/browse/JDK-8176359) // and except for Java 8 on secondary screens where primary screen is scaled Rectangle maximizedBounds = new Rectangle( maximizedX + screenInsets.left, maximizedY + screenInsets.top, maximizedWidth - screenInsets.left - screenInsets.right, maximizedHeight - screenInsets.top - screenInsets.bottom ); // change maximized bounds frame.setMaximizedBounds( maximizedBounds ); // remember maximized bounds in client property to be able to detect // whether maximized bounds are modified from the application rootPane.putClientProperty( "_flatlaf.maximizedBounds", maximizedBounds ); } // maximize window frame.setExtendedState( frame.getExtendedState() | Frame.MAXIMIZED_BOTH ); }
Example 11
Source File: SunGraphics2D.java From Bytecoder with Apache License 2.0 | 4 votes |
private AffineTransform getDefaultTransform() { GraphicsConfiguration gc = getDeviceConfiguration(); return (gc == null) ? new AffineTransform() : gc.getDefaultTransform(); }
Example 12
Source File: SunGraphics2D.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private AffineTransform getDefaultTransform() { GraphicsConfiguration gc = getDeviceConfiguration(); return (gc == null) ? new AffineTransform() : gc.getDefaultTransform(); }
Example 13
Source File: SunGraphics2D.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private AffineTransform getDefaultTransform() { GraphicsConfiguration gc = getDeviceConfiguration(); return (gc == null) ? new AffineTransform() : gc.getDefaultTransform(); }
Example 14
Source File: ImageUtil.java From bisq with GNU Affero General Public License v3.0 | 4 votes |
public static boolean isRetina() { final GraphicsConfiguration gfxConfig = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); final AffineTransform transform = gfxConfig.getDefaultTransform(); return !transform.isIdentity(); }