OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Rev 94 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 73 Rev 83
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.ui;
14
 package org.openconcerto.ui;
15
 
15
 
-
 
16
import org.openconcerto.utils.OSFamily;
-
 
17
 
16
import java.awt.Dimension;
18
import java.awt.Dimension;
17
import java.awt.Frame;
19
import java.awt.Frame;
-
 
20
import java.awt.GraphicsConfiguration;
-
 
21
import java.awt.GraphicsDevice;
18
import java.awt.GraphicsEnvironment;
22
import java.awt.GraphicsEnvironment;
19
import java.awt.Rectangle;
23
import java.awt.Rectangle;
20
import java.awt.Window;
24
import java.awt.Window;
21
 
25
 
22
import javax.swing.UIManager;
26
import javax.swing.UIManager;
Line 50... Line 54...
50
 
54
 
51
    public static final void setBounds(Window w) {
55
    public static final void setBounds(Window w) {
52
        w.setBounds(getWindowBounds());
56
        w.setBounds(getWindowBounds());
53
    }
57
    }
54
 
58
 
-
 
59
    private static final int getArea(final GraphicsConfiguration gc) {
-
 
60
        final Rectangle dm = gc.getBounds();
-
 
61
        return dm.width * dm.height;
-
 
62
    }
-
 
63
 
55
    public static final Rectangle getWindowBounds() {
64
    public static final Rectangle getWindowBounds() {
56
        final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
65
        final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
-
 
66
        final Rectangle dm;
-
 
67
        // see https://bugs.launchpad.net/ubuntu/+source/openjdk-7/+bug/1171563
-
 
68
        // Incorrectly calculated screen insets, e.g. Insets[top=24,left=1345,bottom=0,right=0] for
-
 
69
        // Toolkit.getDefaultToolkit().getScreenInsets(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration());
-
 
70
        // see https://bugs.openjdk.java.net/browse/JDK-8020443
-
 
71
        final GraphicsDevice[] screens = ge.getScreenDevices();
-
 
72
        if (screens.length > 1 && OSFamily.getInstance() == OSFamily.Linux) {
-
 
73
            GraphicsConfiguration largest = null;
-
 
74
            for (final GraphicsDevice screen : screens) {
-
 
75
                final GraphicsConfiguration current = screen.getDefaultConfiguration();
-
 
76
                if (largest == null || getArea(current) > getArea(largest))
-
 
77
                    largest = current;
-
 
78
            }
-
 
79
            assert largest != null;
-
 
80
            dm = new Rectangle(largest.getBounds());
-
 
81
        } else {
57
        final Rectangle dm = new Rectangle(ge.getMaximumWindowBounds());
82
            dm = new Rectangle(ge.getMaximumWindowBounds());
-
 
83
        }
58
        // don't use ge.getDefaultScreenDevice().getDisplayMode(); sometimes null in NX
84
        // don't use ge.getDefaultScreenDevice().getDisplayMode(); sometimes null in NX
59
        // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6921661
85
        // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6921661
60
 
86
 
61
        // Always leave some space to see other windows (plus at least on Ubuntu with
87
        // Always leave some space to see other windows (plus at least on Ubuntu with
62
        // 1.6.0_24 dm is the screen size)
88
        // 1.6.0_24 dm is the screen size ; also with the getMaximumWindowBounds() workaround)
63
        dm.grow(dm.getWidth() <= 800 ? -20 : -50, dm.getHeight() <= 600 ? -20 : -50);
89
        dm.grow(dm.getWidth() <= 800 ? -20 : -50, dm.getHeight() <= 600 ? -20 : -50);
64
 
90
 
65
        return dm;
91
        return dm;
66
    }
92
    }
-
 
93
 
-
 
94
    // easily debug systems
-
 
95
    public static void main(String[] args) {
-
 
96
        System.out.println("getWindowBounds(): " + getWindowBounds());
-
 
97
    }
67
}
98
}