Search in sources :

Example 56 with Component

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

the class MultimonFullscreenTest method actionPerformed.

public void actionPerformed(ActionEvent ae) {
    GraphicsDevice dev = deviceMap.get(ae.getSource());
    System.err.println("Setting FS on device:" + dev);
    final Window fsWindow;
    if (useFSWindow) {
        fsWindow = new Window(this, dev.getDefaultConfiguration()) {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        };
    } else if (useFSDialog) {
        fsWindow = new Dialog((Frame) null, "FS Dialog on device " + dev, false, dev.getDefaultConfiguration());
        fsWindow.add(new Component() {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        });
    } else {
        fsWindow = new Frame("FS Frame on device " + dev, dev.getDefaultConfiguration()) {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        };
        if (addHWChildren) {
            fsWindow.add("South", new Panel() {

                public void paint(Graphics g) {
                    g.setColor(Color.red);
                    g.fillRect(0, 0, getWidth(), getHeight());
                }
            });
            fsWindow.add("North", new Button("Button, sucka!"));
        }
    }
    fsWindow.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                done = true;
                fsWindow.dispose();
            }
        }
    });
    fsWindow.addWindowListener(new WindowHandler());
    dev.setFullScreenWindow(fsWindow);
    if (dmChange && dev.isDisplayChangeSupported()) {
        DisplayMode[] dms = dev.getDisplayModes();
        DisplayMode myDM = null;
        for (DisplayMode dm : dms) {
            if (dm.getWidth() == 800 && dm.getHeight() == 600 && (dm.getBitDepth() >= 16 || dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) && (dm.getRefreshRate() >= 60 || dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN)) {
                myDM = dm;
                break;
            }
        }
        if (myDM != null) {
            System.err.println("Setting Display Mode: " + myDM.getWidth() + "x" + myDM.getHeight() + "x" + myDM.getBitDepth() + "@" + myDM.getRefreshRate() + "Hz on device" + dev);
            dev.setDisplayMode(myDM);
        } else {
            System.err.println("Can't find suitable display mode.");
        }
    }
    done = false;
    if (runRenderLoop) {
        Thread updateThread = new Thread(new Runnable() {

            public void run() {
                BufferStrategy bs = null;
                if (useBS) {
                    fsWindow.createBufferStrategy(2);
                    bs = fsWindow.getBufferStrategy();
                }
                while (!done) {
                    if (useBS) {
                        Graphics g = bs.getDrawGraphics();
                        renderDimensions(g, fsWindow.getBounds(), fsWindow.getGraphicsConfiguration());
                        bs.show();
                    } else {
                        fsWindow.repaint();
                    }
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
                if (useBS) {
                    bs.dispose();
                }
            }
        });
        updateThread.start();
    }
}
Also used : Window(java.awt.Window) Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) BufferStrategy(java.awt.image.BufferStrategy) MouseAdapter(java.awt.event.MouseAdapter) Graphics(java.awt.Graphics) DisplayMode(java.awt.DisplayMode) Panel(java.awt.Panel) GraphicsDevice(java.awt.GraphicsDevice) Button(java.awt.Button) Dialog(java.awt.Dialog) Component(java.awt.Component)

Example 57 with Component

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

the class NoResizeEventOnDMChangeTest method testFSWindow.

private static void testFSWindow(final GraphicsDevice gd, final DisplayMode[] dms, final Window fsWin) {
    System.out.println("Testing FS window: " + fsWin);
    Component c = new Canvas() {

        @Override
        public void paint(Graphics g) {
            g.setColor(Color.blue);
            g.fillRect(0, 0, getWidth(), getHeight());
            g.setColor(Color.magenta);
            g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
            g.setColor(Color.red);
            g.drawString("FS Window   : " + fsWin, 50, 50);
            DisplayMode dm = getGraphicsConfiguration().getDevice().getDisplayMode();
            g.drawString("Display Mode: " + dm.getWidth() + "x" + dm.getHeight(), 50, 75);
        }
    };
    fsWin.add("Center", c);
    fsWin.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            fsWin.dispose();
            if (fsWin.getOwner() != null) {
                fsWin.getOwner().dispose();
            }
        }
    });
    try {
        EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                gd.setFullScreenWindow(fsWin);
            }
        });
    } catch (Exception ex) {
    }
    sleep(1000);
    final ResizeEventChecker r1 = new ResizeEventChecker();
    final ResizeEventChecker r2 = new ResizeEventChecker();
    if (gd.isDisplayChangeSupported()) {
        fsWin.addComponentListener(r1);
        c.addComponentListener(r2);
        for (final DisplayMode dm1 : dms) {
            try {
                EventQueue.invokeAndWait(new Runnable() {

                    public void run() {
                        System.err.printf("----------- Setting DM %dx%d:\n", dm1.getWidth(), dm1.getHeight());
                        try {
                            gd.setDisplayMode(dm1);
                            r1.incDmChanges();
                            r2.incDmChanges();
                        } catch (IllegalArgumentException iae) {
                        }
                    }
                });
            } catch (Exception ex) {
            }
            for (int i = 0; i < 3; i++) {
                fsWin.repaint();
                sleep(1000);
            }
        }
        fsWin.removeComponentListener(r1);
        c.removeComponentListener(r2);
    }
    try {
        EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                gd.setFullScreenWindow(null);
                fsWin.dispose();
                if (fsWin.getOwner() != null) {
                    fsWin.getOwner().dispose();
                }
            }
        });
    } catch (Exception ex) {
    }
    System.out.printf("FS Window: resizes=%d, dm changes=%d\n", r1.getResizes(), r1.getDmChanges());
    System.out.printf("Component: resizes=%d, dm changes=%d\n", r2.getResizes(), r2.getDmChanges());
    if (r1.getResizes() < r1.getDmChanges()) {
        throw new RuntimeException("FS Window didn't receive all resizes!");
    }
    if (r2.getResizes() < r2.getDmChanges()) {
        throw new RuntimeException("Component didn't receive all resizes!");
    }
}
Also used : Canvas(java.awt.Canvas) WindowAdapter(java.awt.event.WindowAdapter) Graphics(java.awt.Graphics) DisplayMode(java.awt.DisplayMode) WindowEvent(java.awt.event.WindowEvent) Component(java.awt.Component)

Example 58 with Component

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

the class java_awt_Component method getObject.

@Override
protected Component getObject() {
    Component component = new MyComponent();
    component.setBackground(Color.WHITE);
    component.setFont(new Font(null, Font.BOLD, 5));
    return component;
}
Also used : Component(java.awt.Component) Font(java.awt.Font)

Example 59 with Component

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

the class java_awt_Component method getAnotherObject.

@Override
protected Component getAnotherObject() {
    Component component = new MyComponent();
    component.setForeground(Color.BLACK);
    component.setFont(new Font(null, Font.ITALIC, 6));
    return component;
}
Also used : Component(java.awt.Component) Font(java.awt.Font)

Example 60 with Component

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

the class JPEGsNotAcceleratedTest method showRes.

private static void showRes(String desc, final BufferedImage src) {
    final int w = src.getWidth();
    final int h = src.getHeight();
    Frame f = new Frame(desc + ": dbl-click to exit");
    Component c;
    f.add(c = new Component() {

        public Dimension getPreferredSize() {
            return new Dimension(w, h);
        }

        public void paint(Graphics g) {
            g.clearRect(0, 0, getWidth(), getHeight());
            g.drawImage(src, 0, 0, null);
        }
    });
    c.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                System.exit(0);
            }
        }
    });
    f.pack();
    synchronized (JPEGsNotAcceleratedTest.class) {
        f.setLocation(frameX, frameY);
        frameX += f.getWidth();
        if ((frameX + f.getWidth()) > f.getGraphicsConfiguration().getBounds().width) {
            frameY += TEST_H;
            if ((frameY + f.getHeight()) > f.getGraphicsConfiguration().getBounds().height) {
                startY += 30;
                startX += 30;
                frameY = startY;
            }
            frameX = startX;
        }
    }
    ;
    f.setVisible(true);
}
Also used : Graphics(java.awt.Graphics) Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) Dimension(java.awt.Dimension) Component(java.awt.Component)

Aggregations

Component (java.awt.Component)645 JComponent (javax.swing.JComponent)163 Dimension (java.awt.Dimension)81 JLabel (javax.swing.JLabel)65 JPanel (javax.swing.JPanel)60 Insets (java.awt.Insets)55 Point (java.awt.Point)55 TableCellRenderer (javax.swing.table.TableCellRenderer)47 Container (java.awt.Container)46 JScrollPane (javax.swing.JScrollPane)42 JTable (javax.swing.JTable)36 JButton (javax.swing.JButton)35 BorderLayout (java.awt.BorderLayout)34 GridBagConstraints (java.awt.GridBagConstraints)34 JTextComponent (javax.swing.text.JTextComponent)34 GridBagLayout (java.awt.GridBagLayout)33 Color (java.awt.Color)32 JList (javax.swing.JList)31 TableColumn (javax.swing.table.TableColumn)31 MouseEvent (java.awt.event.MouseEvent)27