Search in sources :

Example 31 with GraphicsDevice

use of java.awt.GraphicsDevice in project jdk8u_jdk by JetBrains.

the class bug8071705 method main.

public static void main(String[] args) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final boolean[] result = new boolean[1];
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            JFrame frame = createGUI();
            GraphicsDevice[] devices = checkScreens();
            // check if we have more than one and if they are stacked
            // vertically
            GraphicsDevice device = checkConfigs(devices);
            if (device == null) {
                // just pass the test
                frame.dispose();
                result[0] = true;
                latch.countDown();
            } else {
                FrameListener listener = new FrameListener(device, latch, result);
                frame.addComponentListener(listener);
                frame.setVisible(true);
            }
        }
    });
    latch.await();
    if (result[0] == false) {
        throw new RuntimeException("popup menu rendered in wrong position");
    }
    System.out.println("OK");
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) JFrame(javax.swing.JFrame) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 32 with GraphicsDevice

use of java.awt.GraphicsDevice in project jdk8u_jdk by JetBrains.

the class OpaqueImageToSurfaceBlitTest method main.

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.");
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) VolatileImage(java.awt.image.VolatileImage) DataBufferInt(java.awt.image.DataBufferInt) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 33 with GraphicsDevice

use of java.awt.GraphicsDevice in project jdk8u_jdk by JetBrains.

the class TSFrame method createGui.

public static Frame createGui(final boolean useSwing, final boolean useShape, final boolean useTransl, final boolean useNonOpaque, final float factor) {
    Frame frame;
    done = false;
    if (useNonOpaque) {
        if (useSwing) {
            frame = new NonOpaqueJFrame();
        //                frame = new NonOpaqueJAppletFrame(gc);
        } else {
            frame = new NonOpaqueFrame();
        }
        animateComponent(frame);
    } else if (useSwing) {
        frame = new JFrame("Swing Frame");
        JComponent p = new JButton("Swing!");
        p.setPreferredSize(new Dimension(200, 100));
        frame.add("North", p);
        p = new MyJPanel();
        animateComponent(p);
        frame.add("Center", p);
    } else {
        frame = new Frame("AWT Frame") {

            public void paint(Graphics g) {
                g.setColor(Color.red);
                g.fillRect(0, 0, 100, 100);
            }
        };
        frame.setLayout(new BorderLayout());
        Canvas c = new MyCanvas();
        frame.add("North", c);
        animateComponent(c);
        c = new MyCanvas();
        frame.add("Center", c);
        animateComponent(c);
        c = new MyCanvas();
        frame.add("South", c);
        animateComponent(c);
    }
    final Frame finalFrame = frame;
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            finalFrame.dispose();
            done = true;
        }
    });
    frame.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            finalFrame.dispose();
            done = true;
        }
    });
    frame.setPreferredSize(new Dimension(800, 600));
    if (useShape) {
        frame.setUndecorated(true);
    }
    frame.setLocation(450, 10);
    frame.pack();
    GraphicsDevice gd = frame.getGraphicsConfiguration().getDevice();
    if (useShape) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) {
            System.out.println("applying PERPIXEL_TRANSPARENT");
            frame.setShape(new Ellipse2D.Double(0, 0, frame.getWidth(), frame.getHeight() / 3));
            frame.setTitle("PERPIXEL_TRANSPARENT");
        } else {
            System.out.println("Passed: PERPIXEL_TRANSPARENT unsupported");
        }
    }
    if (useTransl) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
            System.out.println("applying TRANSLUCENT");
            frame.setOpacity(factor);
            frame.setTitle("TRANSLUCENT");
        } else {
            System.out.println("Passed: TRANSLUCENT unsupported");
        }
    }
    if (useNonOpaque) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
            System.out.println("applying PERPIXEL_TRANSLUCENT");
            frame.setBackground(new Color(0, 0, 0, 0));
            frame.setTitle("PERPIXEL_TRANSLUCENT");
        } else {
            System.out.println("Passed: PERPIXEL_TRANSLUCENT unsupported");
        }
    }
    frame.setVisible(true);
    return frame;
}
Also used : JFrame(javax.swing.JFrame) Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) Canvas(java.awt.Canvas) Color(java.awt.Color) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) MouseAdapter(java.awt.event.MouseAdapter) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) Ellipse2D(java.awt.geom.Ellipse2D) Graphics(java.awt.Graphics) GraphicsDevice(java.awt.GraphicsDevice) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent)

Example 34 with GraphicsDevice

use of java.awt.GraphicsDevice in project knime-core by knime.

the class TableView method getPreferredSize.

// TableView(TableContentView)
/**
 * {@inheritDoc}
 */
@Override
public Dimension getPreferredSize() {
    // get pref size from all view content and limit it by 2/3 physical screen size
    Dimension superPrefSize = super.getPreferredSize();
    if (super.isPreferredSizeSet() || !isPreferredSizeDataDependent()) {
        return superPrefSize;
    }
    Dimension contentPrefSize = getContentTable().getPreferredSize();
    Dimension rowHeadPrefSize = rowHeader != null ? rowHeader.getPreferredSize() : new Dimension(0, 0);
    Dimension colHeadPrefSize = columnHeader != null ? columnHeader.getPreferredSize() : new Dimension(0, 0);
    int prefContentWidth = contentPrefSize.width + rowHeadPrefSize.width + colHeadPrefSize.width;
    int prefContentHeight = contentPrefSize.height + rowHeadPrefSize.height + rowHeadPrefSize.height;
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    int screenWidth = 2 * gd.getDisplayMode().getWidth() / 3;
    int screenHeight = 1 * gd.getDisplayMode().getHeight() / 3;
    int calcWidth = Math.max(superPrefSize.width, Math.min(screenWidth, prefContentWidth));
    int calcHeight = Math.max(superPrefSize.height, Math.min(screenHeight, prefContentHeight));
    return new Dimension(calcWidth, calcHeight);
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 35 with GraphicsDevice

use of java.awt.GraphicsDevice in project vcell by virtualcell.

the class DialogUtils method getScreenSize.

/**
 * get screensize including multi monitor environment
 * @return
 */
public static Dimension getScreenSize() {
    // http://stackoverflow.com/questions/3680221/how-can-i-get-the-monitor-size-in-java
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    int width = gd.getDisplayMode().getWidth();
    int height = gd.getDisplayMode().getHeight();
    return new Dimension(width, height);
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Dimension(java.awt.Dimension)

Aggregations

GraphicsDevice (java.awt.GraphicsDevice)80 GraphicsEnvironment (java.awt.GraphicsEnvironment)46 GraphicsConfiguration (java.awt.GraphicsConfiguration)25 Point (java.awt.Point)17 Dimension (java.awt.Dimension)15 Frame (java.awt.Frame)13 DisplayMode (java.awt.DisplayMode)12 Rectangle (java.awt.Rectangle)11 Graphics (java.awt.Graphics)7 Insets (java.awt.Insets)7 Toolkit (java.awt.Toolkit)7 BufferedImage (java.awt.image.BufferedImage)7 HeadlessException (java.awt.HeadlessException)5 Window (java.awt.Window)4 JFrame (javax.swing.JFrame)4 Test (org.junit.Test)4 MouseAdapter (java.awt.event.MouseAdapter)3 WindowAdapter (java.awt.event.WindowAdapter)3 WindowEvent (java.awt.event.WindowEvent)3 VolatileImage (java.awt.image.VolatileImage)3