Example usage for java.awt Component getGraphicsConfiguration

List of usage examples for java.awt Component getGraphicsConfiguration

Introduction

In this page you can find the example usage for java.awt Component getGraphicsConfiguration.

Prototype

public GraphicsConfiguration getGraphicsConfiguration() 

Source Link

Document

Gets the GraphicsConfiguration associated with this Component .

Usage

From source file:Main.java

/**
 * Returns the GraphicsConfiguration for a point.
 *//*from ww  w  .ja  v a  2  s .  c om*/
public static GraphicsConfiguration getGraphicsConfiguration(Component aComp, int anX, int aY) {
    // Get initial GC from component (if available) and point on screen
    GraphicsConfiguration gc = aComp != null ? aComp.getGraphicsConfiguration() : null;
    Point spoint = getScreenLocation(aComp, anX, aY);

    // Replace with alternate GraphicsConfiguration if point on another screen
    for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
        if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
            GraphicsConfiguration dgc = gd.getDefaultConfiguration();
            if (dgc.getBounds().contains(spoint.x, spoint.y)) {
                gc = dgc;
                break;
            }
        }
    }

    // Return GraphicsConfiguration
    return gc;
}

From source file:edu.ku.brc.specify.prefs.SystemPrefs.java

/**
 * //from  w  w  w . j  a  v a2  s.  c om
 */
protected void clearCache() {
    final String CLEAR_CACHE = "CLEAR_CACHE";
    final JStatusBar statusBar = UIRegistry.getStatusBar();
    statusBar.setIndeterminate(CLEAR_CACHE, true);

    Component dlg = getParent();
    while (dlg != null && !(dlg instanceof JDialog)) {
        dlg = dlg.getParent();
    }
    Point loc = null;
    if (dlg != null) {
        loc = dlg.getLocation();
    }

    final JDialog parentDlg = (JDialog) dlg;

    Rectangle screenRect = dlg.getGraphicsConfiguration().getBounds();
    parentDlg.setLocation(loc.x, screenRect.height);

    javax.swing.SwingWorker<Integer, Integer> backupWorker = new javax.swing.SwingWorker<Integer, Integer>() {
        @Override
        protected Integer doInBackground() throws Exception {
            try {
                long startTm = System.currentTimeMillis();

                Specify.getCacheManager().clearAll();

                // Tell the OK btn a change has occurred and update the OK btn
                FormValidator validator = ((FormViewObj) form).getValidator();
                if (validator != null) {
                    validator.setHasChanged(true);
                    validator.wasValidated(null);
                    validator.dataChanged(null, null, null);
                }

                Thread.sleep(Math.max(0, 2000 - (System.currentTimeMillis() - startTm)));

            } catch (Exception ex) {
            }

            return null;
        }

        @Override
        protected void done() {
            super.done();

            statusBar.setProgressDone(CLEAR_CACHE);

            UIRegistry.clearSimpleGlassPaneMsg();

            UIRegistry.displayLocalizedStatusBarText("SystemPrefs.CACHE_CLEARED");

            UIHelper.centerWindow(parentDlg);
        }
    };

    UIRegistry.writeSimpleGlassPaneMsg(getLocalizedMessage("SystemPrefs.CLEARING_CACHE"), 24);
    backupWorker.execute();
}

From source file:org.pentaho.reporting.designer.core.actions.global.ScreenCaptureAction.java

public static void saveScreenShot(final int modifiers) {
    final Component component = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    final GraphicsConfiguration graphicsConfiguration = component.getGraphicsConfiguration();
    final GraphicsDevice graphicsDevice = graphicsConfiguration.getDevice();
    try {//from  w w  w .  j av a  2s .co  m
        final Robot robot = new Robot(graphicsDevice);
        final BufferedImage image;
        if ((modifiers & ActionEvent.SHIFT_MASK) == ActionEvent.SHIFT_MASK) {
            image = robot.createScreenCapture(graphicsConfiguration.getBounds());
        } else {
            image = robot.createScreenCapture(component.getBounds());
        }

        final String homeDirectory = ReportDesignerBoot.getInstance().getGlobalConfig()
                .getConfigProperty("user.home", ".");
        final File homeDir = new File(homeDirectory);
        final File f = generateName(homeDir);
        if (f == null) {
            return;
        }
        final FileOutputStream fout = new FileOutputStream(f);
        try {
            final PngEncoder encoder = new PngEncoder();
            encoder.setCompressionLevel(6);
            encoder.setEncodeAlpha(false);
            encoder.setImage(image);
            final byte[] bytes = encoder.pngEncode();
            fout.write(bytes);
        } finally {
            fout.close();
        }
    } catch (IOException ioe) {
        UncaughtExceptionsModel.getInstance().addException(ioe);
    } catch (AWTException e1) {
        // ignore
        UncaughtExceptionsModel.getInstance().addException(e1);
    }
}

From source file:VASSAL.Info.java

/**
 * Get size of screen accounting for the screen insets (i.e. Windows taskbar)
 *
 * @return//w  w  w .j av  a2  s  .  c o m
 */
public static Rectangle getScreenBounds(Component c) {
    final Rectangle bounds = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    final GraphicsConfiguration config = c.getGraphicsConfiguration();
    final Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(config);
    bounds.translate(insets.left, insets.top);
    bounds.setSize(bounds.width - insets.left - insets.right, bounds.height - insets.top - insets.bottom);
    return bounds;
}