Search in sources :

Example 51 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project com.revolsys.open by revolsys.

the class SwingUtil method getScreenBounds.

/**
 * Get the screen rectangle in which the mouse is in. If the mouse is outside all bounds return the current screen.
 *
 * @param point
 * @return
 */
static Rectangle getScreenBounds(final Point point) {
    Rectangle firstBounds = null;
    final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    for (final GraphicsDevice device : graphicsEnvironment.getScreenDevices()) {
        for (final GraphicsConfiguration config : device.getConfigurations()) {
            final Rectangle bounds = config.getBounds();
            if (point != null && bounds.contains(point)) {
                final Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(config);
                return applyInsets(bounds, insets);
            } else if (firstBounds == null) {
                firstBounds = bounds;
            }
        }
    }
    final GraphicsDevice defaultScreenDevice = graphicsEnvironment.getDefaultScreenDevice();
    for (final GraphicsConfiguration config : defaultScreenDevice.getConfigurations()) {
        final Rectangle bounds = config.getBounds();
        final Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(config);
        return applyInsets(bounds, insets);
    }
    return firstBounds;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Insets(java.awt.Insets) Rectangle(java.awt.Rectangle) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 52 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project selenium_java by sergueik.

the class VideoRecorder method startRecording.

public void startRecording(WebDriver driver) {
    try {
        GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
        File dir = new File(RECORD_DIRECTORY);
        Point point = driver.manage().window().getPosition();
        Dimension dimension = driver.manage().window().getSize();
        System.err.println(" Rectangle: " + dimension.width + " " + dimension.height);
        Rectangle rectangle = new Rectangle(point.x, point.y, dimension.width, dimension.height);
        this.screenRecorder = new ScreenRecorder(gc, rectangle, new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI), new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, DepthKey, 24, FrameRateKey, Rational.valueOf(15), QualityKey, 1.0f, KeyFrameIntervalKey, 15 * 60), new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black", FrameRateKey, Rational.valueOf(30)), null, dir);
        this.screenRecorder.start();
    } catch (Exception e) {
        System.out.println(e);
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Format(org.monte.media.Format) Rectangle(java.awt.Rectangle) ScreenRecorder(org.monte.screenrecorder.ScreenRecorder) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) File(java.io.File) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 53 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project Zong by Xenoage.

the class ImageUtils method convertToCompatibleImage.

/**
 * Converts the given image to a system-compatible image, which is much faster when drawn.
 */
public static BufferedImage convertToCompatibleImage(BufferedImage image) {
    GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    BufferedImage newImage = gc.createCompatibleImage(image.getWidth(), image.getHeight(), Transparency.TRANSLUCENT);
    Graphics2D g = newImage.createGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return newImage;
}
Also used : BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 54 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project CCEmuX by CCEmuX.

the class TerminalComponent method drawChar.

private void drawChar(AWTTerminalFont font, Graphics g, char c, int x, int y, int color) {
    if (c == '\0' || Character.isSpaceChar(c))
        // nothing to do here
        return;
    Rectangle r = font.getCharCoords(c);
    Color colour = paletteCacher.getColor(color);
    BufferedImage charImg = null;
    float[] zero = new float[4];
    try {
        charImg = charImgCache.get(Pair.of(c, colour), () -> {
            float[] rgb = new float[4];
            colour.getRGBComponents(rgb);
            RescaleOp rop = new RescaleOp(rgb, zero, null);
            GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
            BufferedImage img = font.getBitmap().getSubimage(r.x, r.y, r.width, r.height);
            BufferedImage pixel = gc.createCompatibleImage(r.width, r.height, Transparency.TRANSLUCENT);
            Graphics ig = pixel.getGraphics();
            ig.drawImage(img, 0, 0, null);
            ig.dispose();
            rop.filter(pixel, pixel);
            return pixel;
        });
    } catch (ExecutionException e) {
        log.error("Could not retrieve char image from cache!", e);
    }
    g.drawImage(charImg, x, y, pixelWidth, pixelHeight, null);
}
Also used : RescaleOp(java.awt.image.RescaleOp) Graphics(java.awt.Graphics) Color(java.awt.Color) Rectangle(java.awt.Rectangle) ExecutionException(java.util.concurrent.ExecutionException) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 55 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project gate-core by GateNLP.

the class Main method runGui.

// getMainFrame()
/**
 * Run the user interface.
 */
protected static void runGui() throws GateException {
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
    // initialise the library and load user CREOLE directories
    try {
        Gate.runInSandbox(false);
        Gate.init();
    } catch (Throwable t) {
        log.error("Problem while initialising GATE", t);
        int selection = JOptionPane.showOptionDialog(null, "Error during initialisation:\n" + t.toString() + "\nDo you still want to start GATE?", "GATE", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, new String[] { "Cancel", "Start anyway" }, "Cancel");
        if (selection != 1) {
            System.exit(1);
        }
    }
    // create the main frame, show it
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
            // this needs to run before any GUI component is constructed.
            applyUserPreferences();
            // all the defaults tables have been updated; build the GUI
            frame = MainFrame.getInstance(gc);
            if (DEBUG)
                Out.prln("constructing GUI");
            // run the GUI
            frame.setTitleChangable(true);
            frame.setTitle(name + " " + version + " build " + build);
            // Set title from Java properties
            String title = System.getProperty(GateConstants.TITLE_JAVA_PROPERTY_NAME);
            if (title != null) {
                frame.setTitle(title);
            }
            // if
            frame.setTitleChangable(false);
            // Set icon from Java properties
            // iconName could be absolute or "gate:/img/..."
            String iconName = System.getProperty(GateConstants.APP_ICON_JAVA_PROPERTY_NAME);
            if (iconName != null) {
                try {
                    frame.setIconImage(Toolkit.getDefaultToolkit().getImage(new URL(iconName)));
                } catch (MalformedURLException mue) {
                    log.warn("Could not load application icon.", mue);
                }
            }
            // if
            // Validate frames that have preset sizes
            frame.validate();
            // Center the window
            Rectangle screenBounds = gc.getBounds();
            Dimension screenSize = screenBounds.getSize();
            Dimension frameSize = frame.getSize();
            if (frameSize.height > screenSize.height) {
                frameSize.height = screenSize.height;
            }
            if (frameSize.width > screenSize.width) {
                frameSize.width = screenSize.width;
            }
            frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
            frame.setVisible(true);
            // load session if required and available;
            // do everything from a new thread.
            Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    try {
                        File sessionFile = Gate.getUserSessionFile();
                        if (sessionFile != null && sessionFile.exists()) {
                            MainFrame.lockGUI("Loading saved session...");
                            PersistenceManager.loadObjectFromFile(sessionFile);
                        }
                    } catch (Exception e) {
                        log.warn("Failed to load session data", e);
                    } finally {
                        MainFrame.unlockGUI();
                    }
                }
            };
            Thread thread = new Thread(Thread.currentThread().getThreadGroup(), runnable, "Session loader");
            thread.setPriority(Thread.MIN_PRIORITY);
            thread.start();
        }
    });
    registerCreoleUrls();
}
Also used : MalformedURLException(java.net.MalformedURLException) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) File(java.io.File) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) GateException(gate.util.GateException) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Aggregations

GraphicsConfiguration (java.awt.GraphicsConfiguration)134 GraphicsEnvironment (java.awt.GraphicsEnvironment)55 BufferedImage (java.awt.image.BufferedImage)46 Rectangle (java.awt.Rectangle)43 GraphicsDevice (java.awt.GraphicsDevice)38 Graphics2D (java.awt.Graphics2D)33 VolatileImage (java.awt.image.VolatileImage)31 Point (java.awt.Point)29 Dimension (java.awt.Dimension)21 Insets (java.awt.Insets)16 File (java.io.File)16 Graphics (java.awt.Graphics)13 IOException (java.io.IOException)13 Frame (java.awt.Frame)11 JFrame (javax.swing.JFrame)8 HeadlessException (java.awt.HeadlessException)7 Window (java.awt.Window)7 ImageIcon (javax.swing.ImageIcon)7 Color (java.awt.Color)6 AffineTransform (java.awt.geom.AffineTransform)6