Java Code Examples for java.awt.GraphicsConfiguration

The following are top voted examples for showing how to use java.awt.GraphicsConfiguration. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: incubator-netbeans   File: Utilities.java   View source code 7 votes vote down vote up
/**
    * Finds out the monitor where the user currently has the input focus.
    * This method is usually used to help the client code to figure out on
    * which monitor it should place newly created windows/frames/dialogs.
    *
    * @return the GraphicsConfiguration of the monitor which currently has the
    * input focus
    */
   private static GraphicsConfiguration getCurrentGraphicsConfiguration() {
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
       if (focusOwner != null) {
           Window w = SwingUtilities.getWindowAncestor(focusOwner);
           if (w != null) {
               return w.getGraphicsConfiguration();
           } else {
               //#217737 - try to find the main window which could be placed in secondary screen
               for( Frame f : Frame.getFrames() ) {
                   if( "NbMainWindow".equals(f.getName())) { //NOI18N
                       return f.getGraphicsConfiguration();
                   }
               }
           }
       }

       return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
   }
 
Example 2
Project: openjdk-jdk10   File: VolatileImageConfigurationTest.java   View source code 7 votes vote down vote up
private void drawBackingStoreImage(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    GraphicsConfiguration gc = g2d.getDeviceConfiguration();
    if (vImg == null ||
        vImg.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) {
        /* Create a new volatile image */
        vImg = createVolatileImage(PANEL_WIDTH, PANEL_HEIGHT / 3);
    }

    Graphics vImgGraphics = vImg.createGraphics();
    vImgGraphics.setColor(Color.WHITE);
    vImgGraphics.fillRect(0, 0, PANEL_WIDTH, PANEL_HEIGHT / 3);
    drawInfo(vImgGraphics,
             PANEL_X,
             PANEL_Y,
             "Backbuffer",
             Color.MAGENTA);
    g.drawImage(vImg, 0, PANEL_Y * 2, this);
}
 
Example 3
Project: openjdk-jdk10   File: PopupMenuLocation.java   View source code 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
    GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] sds = ge.getScreenDevices();
    for (GraphicsDevice sd : sds) {
        GraphicsConfiguration gc = sd.getDefaultConfiguration();
        Rectangle bounds = gc.getBounds();
        Point point = new Point(bounds.x, bounds.y);
        Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
        while (point.y < bounds.y + bounds.height - insets.bottom - SIZE) {
            while (point.x
                    < bounds.x + bounds.width - insets.right - SIZE) {
                test(point);
                point.translate(bounds.width / 5, 0);
            }
            point.setLocation(bounds.x, point.y + bounds.height / 5);
        }
    }
}
 
Example 4
Project: jdk8u-jdk   File: bug8071705.java   View source code 6 votes vote down vote up
private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {

        GraphicsDevice correctDevice = null;
        if (devices.length < 2) {
            return correctDevice;
        }

        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
        int halfScreen = screenBounds.height/2;

        for(int i = 0; i < devices.length; i++) {
            if(devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
                GraphicsConfiguration conf =
                        devices[i].getDefaultConfiguration();
                Rectangle bounds = conf.getBounds();
                if (bounds.y >= halfScreen) {
                    // found
                    correctDevice = devices[i];
                    break;
                }
            }
        }
        return correctDevice;
    }
 
Example 5
Project: jdk8u-jdk   File: IncorrectAlphaConversionBicubic.java   View source code 6 votes vote down vote up
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc,
                                             int type) {
    BufferedImage img = gc.createCompatibleImage(SIZE, SIZE, type);
    Graphics2D g2d = img.createGraphics();
    g2d.setColor(RGB);
    g2d.fillRect(0, 0, SIZE, SIZE);
    g2d.dispose();
    final DataBuffer db = img.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            img.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return img;
}
 
Example 6
Project: incubator-netbeans   File: BufferedCanvasComponent.java   View source code 6 votes vote down vote up
private int updateOffscreenImage() {
    // Update offscreen image reference
    if (offscreenImage == null) offscreenImage = offscreenImageReference.get();
    
    // Offscreen image not available
    if (offscreenImage == null) return VolatileImage.IMAGE_INCOMPATIBLE;
    
    // Buffered image is always valid
    if (bufferType != BUFFER_VOLATILE_IMAGE) return VolatileImage.IMAGE_OK;
    
    // Determine GraphicsConfiguration context
    GraphicsConfiguration gConfiguration = getGraphicsConfiguration();
    if (gConfiguration == null) return VolatileImage.IMAGE_INCOMPATIBLE;
    
    // Return Volatile image state
    return ((VolatileImage)offscreenImage).validate(gConfiguration);
}
 
Example 7
Project: openjdk-jdk10   File: VolatileSurfaceManager.java   View source code 6 votes vote down vote up
/**
 * 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 8
Project: jdk8u-jdk   File: TransformSetGet.java   View source code 6 votes vote down vote up
public static void main(final String[] args) {
    final GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsConfiguration gc =
            ge.getDefaultScreenDevice().getDefaultConfiguration();
    final VolatileImage vi = gc.createCompatibleVolatileImage(200, 200);
    final SunGraphics2D sg2d = (SunGraphics2D) vi.createGraphics();

    sg2d.constrain(0, 61, 100, 100);
    final AffineTransform expected = sg2d.cloneTransform();
    sg2d.setTransform(sg2d.getTransform());
    final AffineTransform actual = sg2d.cloneTransform();
    sg2d.dispose();
    vi.flush();
    if (!expected.equals(actual)) {
        System.out.println("Expected = " + expected);
        System.out.println("Actual = " + actual);
        throw new RuntimeException("Wrong transform");
    }
}
 
Example 9
Project: jdk8u-jdk   File: TranslucentWindowPainter.java   View source code 6 votes vote down vote up
/**
 * Creates an instance of the painter for particular peer.
 */
public static TranslucentWindowPainter createInstance(WWindowPeer peer) {
    GraphicsConfiguration gc = peer.getGraphicsConfiguration();
    if (!forceSW && gc instanceof AccelGraphicsConfig) {
        String gcName = gc.getClass().getSimpleName();
        AccelGraphicsConfig agc = (AccelGraphicsConfig)gc;
        // this is a heuristic to check that we have a pcix board
        // (those have higher transfer rate from gpu to cpu)
        if ((agc.getContextCapabilities().getCaps() & CAPS_PS30) != 0 ||
            forceOpt)
        {
            // we check for name to avoid loading classes unnecessarily if
            // a pipeline isn't enabled
            if (gcName.startsWith("D3D")) {
                return new VIOptD3DWindowPainter(peer);
            } else if (forceOpt && gcName.startsWith("WGL")) {
                // on some boards (namely, ATI, even on pcix bus) ogl is
                // very slow reading pixels back so for now it is disabled
                // unless forced
                return new VIOptWGLWindowPainter(peer);
            }
        }
    }
    return new BIWindowPainter(peer);
}
 
Example 10
Project: incubator-netbeans   File: OptionsDisplayerImpl.java   View source code 6 votes vote down vote up
private Point getUserLocation(GraphicsConfiguration gconf, OptionsPanel optionsPanel) {
      final Rectangle screenBounds = Utilities.getUsableScreenBounds(gconf);
      int x = NbPreferences.forModule(OptionsDisplayerImpl.class).getInt("OptionsX", Integer.MAX_VALUE);//NOI18N
      int y = NbPreferences.forModule(OptionsDisplayerImpl.class).getInt("OptionsY", Integer.MAX_VALUE);//NOI18N
      Dimension userSize = optionsPanel.getUserSize();
      if (x > screenBounds.x + screenBounds.getWidth() || y > screenBounds.y + screenBounds.getHeight()
              || x + userSize.width > screenBounds.x + screenBounds.getWidth() 
              || y + userSize.height > screenBounds.y + screenBounds.getHeight()
              || (x < screenBounds.x && screenBounds.x >= 0)
|| (x > screenBounds.x && screenBounds.x < 0)
|| (y < screenBounds.y && screenBounds.y >= 0)
|| (y > screenBounds.y && screenBounds.y < 0)){
          return null;
      } else {
          return new Point(x, y);
      }
  }
 
Example 11
Project: incubator-netbeans   File: TooltipWindow.java   View source code 6 votes vote down vote up
public void show(Point location) {
    Rectangle screenBounds = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    for (GraphicsDevice device : gds) {
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        screenBounds = gc.getBounds();
        if (screenBounds.contains(location)) {
            break;
        }
    }

    // showing the popup tooltip
    cp = new TooltipContentPanel(master.getTextComponent());

    Window w = SwingUtilities.windowForComponent(master.getTextComponent());
    contentWindow = new JWindow(w);
    contentWindow.add(cp);
    contentWindow.pack();
    Dimension dim = contentWindow.getSize();

    if (location.y + dim.height + SCREEN_BORDER > screenBounds.y + screenBounds.height) {
        dim.height = (screenBounds.y + screenBounds.height) - (location.y + SCREEN_BORDER);
    }
    if (location.x + dim.width + SCREEN_BORDER > screenBounds.x + screenBounds.width) {
        dim.width = (screenBounds.x + screenBounds.width) - (location.x + SCREEN_BORDER);
    }

    contentWindow.setSize(dim);

    contentWindow.setLocation(location.x, location.y - 1);  // slight visual adjustment
    contentWindow.setVisible(true);

    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
    w.addWindowFocusListener(this);
    contentWindow.addWindowFocusListener(this);
}
 
Example 12
Project: openjdk-jdk10   File: bug8071705.java   View source code 6 votes vote down vote up
private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {

        GraphicsDevice correctDevice = null;
        if (devices.length < 2) {
            return correctDevice;
        }

        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
        int halfScreen = screenBounds.height/2;

        for(int i = 0; i < devices.length; i++) {
            if(devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
                GraphicsConfiguration conf =
                        devices[i].getDefaultConfiguration();
                Rectangle bounds = conf.getBounds();
                if (bounds.y >= halfScreen) {
                    // found
                    correctDevice = devices[i];
                    break;
                }
            }
        }
        return correctDevice;
    }
 
Example 13
Project: rapidminer   File: FancyDropDownButton.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent ae) {
	JPopupMenu popup = getPopupMenu();
	popup.addPopupMenuListener(popupMenuListener);

	int popupPrefHeight = (int) popup.getPreferredSize().getHeight();
	int buttonY = mainButton.getLocationOnScreen().y;

	boolean showOnTop = false;

	GraphicsConfiguration graphicsConf = ApplicationFrame.getApplicationFrame().getGraphicsConfiguration();
	if (graphicsConf != null) {
		int windowHeight = (int) graphicsConf.getBounds().getHeight();
		showOnTop = buttonY + mainButton.getHeight() + popupPrefHeight > windowHeight;
	}

	if (showOnTop) {
		popup.show(mainButton, 0, -popupPrefHeight);
	} else {
		popup.show(mainButton, 0, mainButton.getHeight());
	}
}
 
Example 14
Project: BrainControl   File: LevelScene.java   View source code 6 votes vote down vote up
/**
 * Constructor
 * 
 * @param graphicsConfiguration
 * @param renderer
 * @param seed
 * @param levelDifficulty
 * @param type
 * @param levelLength
 * @param timeLimit
 */
public LevelScene(GraphicsConfiguration graphicsConfiguration,
		GameWorld renderer, long seed, int levelDifficulty,
		int type, int levelLength, int timeLimit, String ownLevelName)
{
	this.graphicsConfiguration = graphicsConfiguration;
	this.renderer = renderer;
	this.levelSeed = seed;
	this.levelDifficulty = levelDifficulty;
	this.levelType = type;
	this.levelLength = levelLength;
	this.totalTime = timeLimit;
	// TODO should these be initialized in an object constructor?
	killedCreaturesTotal = 0;
	killedCreaturesByFireBall = 0;
	killedCreaturesByStomp = 0;
	killedCreaturesByGrumpy = 0;
	playersAtEnd = 0;
	this.ownLevelName = ownLevelName;		
}
 
Example 15
Project: jdk8u-jdk   File: SourceClippingBlitTest.java   View source code 6 votes vote down vote up
static void initImage(GraphicsConfiguration gc, Image image) {
    Graphics g = image.getGraphics();
    g.setColor(Color.RED);
    int w = image.getWidth(null);
    int h = image.getHeight(null);
    g.fillRect(0, 0, w, h);
    g.dispose();

    // need to 'accelerate' the image
    if (dstImage == null) {
        dstImage =
            gc.createCompatibleVolatileImage(TESTW, TESTH,
                                             Transparency.OPAQUE);
    }
    dstImage.validate(gc);
    g = dstImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.drawImage(image, 0, 0, null);
    g.drawImage(image, 0, 0, null);
}
 
Example 16
Project: OpenJSharp   File: TranslucentWindowPainter.java   View source code 6 votes vote down vote up
/**
 * Creates an instance of the painter for particular peer.
 */
public static TranslucentWindowPainter createInstance(WWindowPeer peer) {
    GraphicsConfiguration gc = peer.getGraphicsConfiguration();
    if (!forceSW && gc instanceof AccelGraphicsConfig) {
        String gcName = gc.getClass().getSimpleName();
        AccelGraphicsConfig agc = (AccelGraphicsConfig)gc;
        // this is a heuristic to check that we have a pcix board
        // (those have higher transfer rate from gpu to cpu)
        if ((agc.getContextCapabilities().getCaps() & CAPS_PS30) != 0 ||
            forceOpt)
        {
            // we check for name to avoid loading classes unnecessarily if
            // a pipeline isn't enabled
            if (gcName.startsWith("D3D")) {
                return new VIOptD3DWindowPainter(peer);
            } else if (forceOpt && gcName.startsWith("WGL")) {
                // on some boards (namely, ATI, even on pcix bus) ogl is
                // very slow reading pixels back so for now it is disabled
                // unless forced
                return new VIOptWGLWindowPainter(peer);
            }
        }
    }
    return new BIWindowPainter(peer);
}
 
Example 17
Project: openjdk-jdk10   File: NonOpaqueDestLCDAATest.java   View source code 6 votes vote down vote up
private void initImages(int w, int h) {
    if (images == null) {
        images = new Image[6];
        GraphicsConfiguration gc = getGraphicsConfiguration();
        for (int i = OPAQUE; i <= TRANSLUCENT; i++) {
            VolatileImage vi =
                gc.createCompatibleVolatileImage(w,h/images.length,i);
            images[i-1] = vi;
            vi.validate(gc);
            String s = "LCD AA Text rendered to " + tr[i - 1] + " HW destination";
            render(vi, i, s);

            s = "LCD AA Text rendered to " + tr[i - 1] + " SW destination";
            images[i-1+3] = gc.createCompatibleImage(w, h/images.length, i);
            render(images[i-1+3], i, s);
        }
    }
}
 
Example 18
Project: jdk8u-jdk   File: ImageCache.java   View source code 6 votes vote down vote up
public boolean equals(GraphicsConfiguration config,
         int w, int h, Object[] args) {
    if (this.w == w && this.h == h &&
            ((this.config != null && this.config.equals(config)) ||
            (this.config == null && config == null))) {
        if (this.args == null && args == null) {
            return true;
        }
        if (this.args != null && args != null &&
                this.args.length == args.length) {
            for (int counter = args.length - 1; counter >= 0;
            counter--) {
                Object a1 = this.args[counter];
                Object a2 = args[counter];
                if ((a1 == null && a2 != null) ||
                        (a1 != null && !a1.equals(a2))) {
                    return false;
                }
            }
            return true;
        }
    }
    return false;
}
 
Example 19
Project: openjdk-jdk10   File: TransformedPaintTest.java   View source code 6 votes vote down vote up
private void runTest() {
    GraphicsConfiguration gc = GraphicsEnvironment.
        getLocalGraphicsEnvironment().getDefaultScreenDevice().
            getDefaultConfiguration();

    if (gc.getColorModel().getPixelSize() < 16) {
        System.out.println("8-bit desktop depth found, test passed");
        return;
    }

    VolatileImage vi = gc.createCompatibleVolatileImage(R_WIDTH, R_HEIGHT);
    BufferedImage bi = null;
    do {
        vi.validate(gc);
        Graphics2D g = vi.createGraphics();
        render(g, vi.getWidth(), vi.getHeight());
        bi = vi.getSnapshot();
    } while (vi.contentsLost());

    checkBI(bi);
    System.out.println("Test PASSED.");
}
 
Example 20
Project: OpenJSharp   File: SurfaceManager.java   View source code 6 votes vote down vote up
public boolean isAccelerated() {
    // Note that when img.getAccelerationPriority() gets set to 0
    // we remove SurfaceDataProxy objects from the cache and the
    // answer will be false.
    GraphicsConfiguration tmpGc = gc;
    if (tmpGc == null) {
        tmpGc = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration();
    }
    if (tmpGc instanceof ProxiedGraphicsConfig) {
        Object proxyKey =
            ((ProxiedGraphicsConfig) tmpGc).getProxyKey();
        if (proxyKey != null) {
            SurfaceDataProxy sdp =
                (SurfaceDataProxy) getCacheData(proxyKey);
            return (sdp != null && sdp.isAccelerated());
        }
    }
    return false;
}
 
Example 21
Project: openjdk-jdk10   File: RSLAPITest.java   View source code 5 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    testGC(gc);

    if (failed) {
        throw new RuntimeException("Test FAILED. See err output for more");
    }

    System.out.println("Test PASSED.");
}
 
Example 22
Project: litiengine   File: ImageProcessing.java   View source code 5 votes vote down vote up
public static BufferedImage getCompatibleImage(final int width, final int height) {
  if (width == 0 && height == 0) {
    return null;
  }

  final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
  final GraphicsDevice device = env.getDefaultScreenDevice();
  final GraphicsConfiguration config = device.getDefaultConfiguration();
  return config.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
}
 
Example 23
Project: jdk8u-jdk   File: DrawCachedImageAndTransform.java   View source code 5 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice()
                                 .getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);

    Graphics2D g2d = vi.createGraphics();
    g2d.scale(2, 2);
    BufferedImage img = new BufferedImage(50, 50,
                                          BufferedImage.TYPE_INT_ARGB);

    g2d.drawImage(img, 10, 25, Color.blue, null);
    g2d.dispose();
}
 
Example 24
Project: incubator-netbeans   File: Utilities.java   View source code 5 votes vote down vote up
/**
 * Returns the usable area of the screen where applications can place its
 * windows. The method subtracts from the screen the area of taskbars,
 * system menus and the like.
 * On certain platforms this methods uses a cache to avoid performance degradation due to repeated calls.
 * This can be disabled by setting the property "-Dnetbeans.screen.insetsCache=false"
 * See issue http://netbeans.org/bugzilla/show_bug.cgi?id=219507
 *
 * @param gconf the GraphicsConfiguration of the monitor
 * @return the rectangle of the screen where one can place windows
 *
 * @since 2.5
 */
public static Rectangle getUsableScreenBounds(GraphicsConfiguration gconf) {
    if( gconf == null ) {
        gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    }
    if( screenBoundsCache == null ) {
        return calculateUsableScreenBounds( gconf );
    }

    synchronized( screenBoundsCache ) {
        Map<Rectangle, Long> cacheEntry = screenBoundsCache.get( gconf );
        if( cacheEntry != null ) {
            final long now = System.currentTimeMillis();
            Entry<Rectangle, Long> entry = cacheEntry.entrySet().iterator().next();
            if( entry.getValue() < now + 10000 ) { // cache hit, 10 seconds lifetime
                return new Rectangle( entry.getKey() ); // return copy
            }
        }

        final Rectangle screenBounds = calculateUsableScreenBounds( gconf );
        cacheEntry = new HashMap<Rectangle, Long>( 1 );
        cacheEntry.put( screenBounds, System.currentTimeMillis() );
        if( screenBoundsCache.size() > 20 ) { //maximum entries
            screenBoundsCache.clear();
        }
        screenBoundsCache.put( gconf, cacheEntry );
        return new Rectangle( screenBounds );
    }
}
 
Example 25
Project: incubator-netbeans   File: Utilities.java   View source code 5 votes vote down vote up
/**
 * Helps client code place components on the center of the screen.  It
 * handles multiple monitor configuration correctly
 *
 * @param gconf the GraphicsConfiguration of the monitor
 * @param componentSize the size of the component
 * @return bounds of the centered component
 */
private static Rectangle findCenterBounds(GraphicsConfiguration gconf, Dimension componentSize) {
    if (gconf == null) {
        gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    }

    Rectangle bounds = gconf.getBounds();

    return new Rectangle(
        bounds.x + ((bounds.width - componentSize.width) / 2),
        bounds.y + ((bounds.height - componentSize.height) / 2), componentSize.width, componentSize.height
    );
}
 
Example 26
Project: openjdk-jdk10   File: NormalizingTransformTest.java   View source code 5 votes vote down vote up
public static void main(String[] args) {
    GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration();
    AffineTransform normTransform = gc.getNormalizingTransform();
    int dpiX = Toolkit.getDefaultToolkit().getScreenResolution();
    int normDpiX = (int)(normTransform.getScaleX() * 72.0);
    if (dpiX != normDpiX) {
        throw new RuntimeException(
            "Test FAILED. Toolkit.getScreenResolution()=" + dpiX +
            " GraphicsConfiguration.getNormalizingTransform()="+normDpiX);
    }
    System.out.println("Test PASSED. DPI="+normDpiX);
}
 
Example 27
Project: jdk8u-jdk   File: Permissions.java   View source code 5 votes vote down vote up
public static void main(String[] args) {
    MySecurityManager sm = MySecurityManager.install();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    sm.prepare("Toolkit.getSystemClipboard()");
    toolkit.getSystemClipboard();
    sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Toolkit.getSystemEventQueue()");
    toolkit.getSystemEventQueue();
    sm.assertChecked(AWTPermission.class, "accessEventQueue");

    sm.prepare("Toolkit.getSystemSelection()");
    toolkit.getSystemSelection();
    //sm.assertChecked(AWTPermission.class, "accessClipboard");

    sm.prepare("Window(Frame)");
    new Window((Frame)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window)");
    new Window((Window)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");

    sm.prepare("Window(Window,GraphicsConfiguration)");
    new Window((Window)null, (GraphicsConfiguration)null);
    sm.assertChecked(AWTPermission.class, "showWindowWithoutWarningBanner");
}
 
Example 28
Project: incubator-netbeans   File: ColumnSelectionPanel.java   View source code 5 votes vote down vote up
private static Rectangle getUsableScreenBounds(GraphicsConfiguration gconf) {
    if (gconf == null) {
        gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    }

    return new Rectangle(gconf.getBounds());
}
 
Example 29
Project: OpenJSharp   File: D3DGraphicsDevice.java   View source code 5 votes vote down vote up
@Override
public GraphicsConfiguration getDefaultConfiguration() {
    if (defaultConfig == null) {
        if (isD3DEnabledOnDevice()) {
            defaultConfig = new D3DGraphicsConfig(this);
        } else {
            defaultConfig = super.getDefaultConfiguration();
        }
    }
    return defaultConfig;
}
 
Example 30
Project: jdk8u-jdk   File: OpaqueImageToSurfaceBlitTest.java   View source code 5 votes vote down vote up
public static void main(String[] args) {

        GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        VolatileImage vi = gc.createCompatibleVolatileImage(16, 16);
        vi.validate(gc);

        BufferedImage bi =
            new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
        int data[] = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
        data[0] = 0x0000007f;
        data[1] = 0x0000007f;
        data[2] = 0xff00007f;
        data[3] = 0xff00007f;
        Graphics2D g = vi.createGraphics();
        g.setComposite(AlphaComposite.SrcOver.derive(0.999f));
        g.drawImage(bi, 0, 0, null);

        bi = vi.getSnapshot();
        if (bi.getRGB(0, 0) != bi.getRGB(1, 1)) {
            throw new RuntimeException("Test FAILED: color at 0x0 ="+
                Integer.toHexString(bi.getRGB(0, 0))+" differs from 1x1 ="+
                Integer.toHexString(bi.getRGB(1,1)));
        }

        System.out.println("Test PASSED.");
    }
 
Example 31
Project: jdk8u-jdk   File: ImageCache.java   View source code 5 votes vote down vote up
public PixelCountSoftReference(Image referent, ReferenceQueue<? super Image> q, int pixelCount, int hash,
                               GraphicsConfiguration config, int w, int h, Object[] args) {
    super(referent, q);
    this.pixelCount = pixelCount;
    this.hash = hash;
    this.config = config;
    this.w = w;
    this.h = h;
    this.args = args;
}
 
Example 32
Project: openjdk-jdk10   File: IncorrectUnmanagedImageRotatedClip.java   View source code 5 votes vote down vote up
private static void test(final BufferedImage bi) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice()
                                 .getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(500, 200,
                                                        TRANSLUCENT);
    BufferedImage gold = gc.createCompatibleImage(500, 200, TRANSLUCENT);
    // draw to compatible Image
    draw(bi, gold);
    // draw to volatile image
    int attempt = 0;
    BufferedImage snapshot;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            continue;
        }
        draw(bi, vi);
        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            continue;
        }
        break;
    }
    // validate images
    for (int x = 0; x < gold.getWidth(); ++x) {
        for (int y = 0; y < gold.getHeight(); ++y) {
            if (gold.getRGB(x, y) != snapshot.getRGB(x, y)) {
                ImageIO.write(gold, "png", new File("gold.png"));
                ImageIO.write(snapshot, "png", new File("bi.png"));
                throw new RuntimeException("Test failed.");
            }
        }
    }
}
 
Example 33
Project: incubator-netbeans   File: DnDSupport.java   View source code 5 votes vote down vote up
private BufferedImage createContentImage( JComponent c, Dimension contentSize ) {
    GraphicsConfiguration cfg = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getDefaultConfiguration();

    boolean opaque = c.isOpaque();
    c.setOpaque(true);
    BufferedImage res = cfg.createCompatibleImage(contentSize.width, contentSize.height);
    Graphics2D g = res.createGraphics();
    g.setColor( c.getBackground() );
    g.fillRect(0, 0, contentSize.width, contentSize.height);
    g.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f ));
    c.paint(g);
    c.setOpaque(opaque);
    return res;
}
 
Example 34
Project: openjdk-jdk10   File: InfiniteValidationLoopTest.java   View source code 5 votes vote down vote up
private void runTest(Graphics g) {
    int status = IMAGE_OK;
    int count1 = 0;
    do {
        GraphicsConfiguration gc = getGraphicsConfiguration();
        int count2 = 0;
        while (vi == null || (status = vi.validate(gc)) != IMAGE_OK) {
            if (++count2 > LOOP_THRESHOLD) {
                System.err.println("Infinite loop detected: count2="+count2);
                failed = true;
                return;
            }
            if (vi == null || status == IMAGE_INCOMPATIBLE) {
                if (vi != null) { vi.flush(); vi = null; }
                vi = gc.createCompatibleVolatileImage(100, 100);
                continue;
            }
            if (status == IMAGE_RESTORED) {
                Graphics gg = vi.getGraphics();
                gg.setColor(Color.green);
                gg.fillRect(0, 0, vi.getWidth(), vi.getHeight());
                break;
            }
        }
        g.drawImage(vi, getInsets().left, getInsets().top, null);
        if (++count1 > LOOP_THRESHOLD) {
            System.err.println("Infinite loop detected: count1="+count1);
            failed = true;
            return;
        }
    } while (vi.contentsLost());
}
 
Example 35
Project: OpenJSharp   File: ImageCache.java   View source code 5 votes vote down vote up
/**
 * Get the cached image for given keys
 *
 * @param config The graphics configuration, needed if cached image is a Volatile Image. Used as part of cache key
 * @param w      The image width, used as part of cache key
 * @param h      The image height, used as part of cache key
 * @param args   Other arguments to use as part of the cache key
 * @return Returns the cached Image, or null there is no cached image for key
 */
public Image getImage(GraphicsConfiguration config, int w, int h, Object... args) {
    lock.readLock().lock();
    try {
        PixelCountSoftReference ref = map.get(hash(config, w, h, args));
        // check reference has not been lost and the key truly matches, in case of false positive hash match
        if (ref != null && ref.equals(config,w, h, args)) {
            return ref.get();
        } else {
            return null;
        }
    } finally {
        lock.readLock().unlock();
    }
}
 
Example 36
Project: openjdk-jdk10   File: ServiceDialog.java   View source code 5 votes vote down vote up
/**
 * Constructor for the "standard" print dialog (containing all relevant
 * tabs)
 */
public ServiceDialog(GraphicsConfiguration gc,
                     int x, int y,
                     PrintService[] services,
                     int defaultServiceIndex,
                     DocFlavor flavor,
                     PrintRequestAttributeSet attributes,
                     Dialog dialog)
{
    super(dialog, getMsg("dialog.printtitle"), true, gc);
    initPrintDialog(x, y, services, defaultServiceIndex,
                    flavor, attributes);
}
 
Example 37
Project: rapidminer   File: ToolbarHandlerBuffer.java   View source code 5 votes vote down vote up
public boolean hasSameConfiguration(GraphicsConfiguration gc, Color aTopColor, Color aShadowColor) {
	if (this.gc != null) {
		if (!this.gc.equals(gc)) {
			return false;
		}
	} else if (gc != null) {
		return false;
	}
	return this.topColor.equals(aTopColor) && this.shadowColor.equals(aShadowColor);
}
 
Example 38
Project: OpenJSharp   File: WindowsSurfaceManagerFactory.java   View source code 5 votes vote down vote up
/**
 * Creates a new instance of a VolatileSurfaceManager given any
 * arbitrary SunVolatileImage.  An optional context Object can be supplied
 * as a way for the caller to pass pipeline-specific context data to
 * the VolatileSurfaceManager (such as a backbuffer handle, for example).
 *
 * For Windows platforms, this method returns a Windows-specific
 * VolatileSurfaceManager.
 */
public VolatileSurfaceManager createVolatileManager(SunVolatileImage vImg,
                                                    Object context)
{
    GraphicsConfiguration gc = vImg.getGraphicsConfig();
    if (gc instanceof D3DGraphicsConfig) {
        return new D3DVolatileSurfaceManager(vImg, context);
    } else if (gc instanceof WGLGraphicsConfig) {
        return new WGLVolatileSurfaceManager(vImg, context);
    } else {
        return new BufImgVolatileSurfaceManager(vImg, context);
    }
}
 
Example 39
Project: OpenJSharp   File: SunVolatileImage.java   View source code 5 votes vote down vote up
private SunVolatileImage(Component comp,
                         GraphicsConfiguration graphicsConfig,
                         int width, int height, Object context,
                         ImageCapabilities caps)
{
    this(comp, graphicsConfig,
         width, height, context, Transparency.OPAQUE, caps, UNDEFINED);
}
 
Example 40
Project: openjdk-jdk10   File: ImageCache.java   View source code 5 votes vote down vote up
/**
 * Get the cached image for given keys
 *
 * @param config The graphics configuration, needed if cached image is a Volatile Image. Used as part of cache key
 * @param w      The image width, used as part of cache key
 * @param h      The image height, used as part of cache key
 * @param args   Other arguments to use as part of the cache key
 * @return Returns the cached Image, or null there is no cached image for key
 */
public Image getImage(GraphicsConfiguration config, int w, int h, Object... args) {
    lock.readLock().lock();
    try {
        PixelCountSoftReference ref = map.get(hash(config, w, h, args));
        // check reference has not been lost and the key truly matches, in case of false positive hash match
        if (ref != null && ref.equals(config,w, h, args)) {
            return ref.get();
        } else {
            return null;
        }
    } finally {
        lock.readLock().unlock();
    }
}