OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 144 Rev 151
Line 25... Line 25...
25
import java.awt.GridLayout;
25
import java.awt.GridLayout;
26
import java.awt.event.MouseAdapter;
26
import java.awt.event.MouseAdapter;
27
import java.awt.event.MouseEvent;
27
import java.awt.event.MouseEvent;
28
import java.util.ArrayList;
28
import java.util.ArrayList;
29
import java.util.Collections;
29
import java.util.Collections;
-
 
30
import java.util.Enumeration;
30
import java.util.List;
31
import java.util.List;
31
import java.util.Properties;
32
import java.util.Properties;
32
 
33
 
33
import javax.swing.BorderFactory;
34
import javax.swing.BorderFactory;
34
import javax.swing.JComboBox;
35
import javax.swing.JComboBox;
Line 43... Line 44...
43
 
44
 
44
    private static final String UI_PROPERTIES = "ui.properties";
45
    private static final String UI_PROPERTIES = "ui.properties";
45
    private static final String ALTERNATE_COLOR_BLUE = "ui.list.alternate.color.blue";
46
    private static final String ALTERNATE_COLOR_BLUE = "ui.list.alternate.color.blue";
46
    private static final String ALTERNATE_COLOR_GREEN = "ui.list.alternate.color.green";
47
    private static final String ALTERNATE_COLOR_GREEN = "ui.list.alternate.color.green";
47
    private static final String ALTERNATE_COLOR_RED = "ui.list.alternate.color.red";
48
    private static final String ALTERNATE_COLOR_RED = "ui.list.alternate.color.red";
-
 
49
    private static final String UI_DPI = "ui.default.dpi";
48
    private static final String UI_LOOK = "ui.look";
50
    private static final String UI_LOOK = "ui.look";
49
    private JLabel selectedButton;
51
    private JLabel selectedButton;
50
    private JComboBox comboLook;
52
    private JComboBox comboLook, comboDPI;
51
 
53
 
52
    public UIPreferencePanel() {
54
    public UIPreferencePanel() {
53
        super("Interface graphique", UI_PROPERTIES);
55
        super("Interface graphique", UI_PROPERTIES);
54
    }
56
    }
55
 
57
 
Line 67... Line 69...
67
            comboLook.setSelectedIndex(0);
69
            comboLook.setSelectedIndex(0);
68
        }
70
        }
69
 
71
 
70
        c.gridx++;
72
        c.gridx++;
71
        this.add(comboLook, c);
73
        this.add(comboLook, c);
-
 
74
 
-
 
75
        c.gridy++;
-
 
76
        c.gridx = 0;
-
 
77
        this.add(new JLabel("High DPI"), c);
-
 
78
        this.comboDPI = new JComboBox(new String[] { "Désactivé", "x1.3", "x2", "x3", "x4" });
-
 
79
        String dpi = this.properties.getProperty(UI_DPI);
-
 
80
        if (dpi != null && !dpi.equals("1")) {
-
 
81
            comboDPI.setSelectedIndex(Float.valueOf(dpi).intValue());
-
 
82
        }
-
 
83
 
-
 
84
        c.gridx++;
-
 
85
        this.add(comboDPI, c);
-
 
86
 
72
        final JLabel labelAlternate = new JLabel("Couleur de fond dans les liste pour l'alternance");
87
        final JLabel labelAlternate = new JLabel("Couleur de fond dans les liste pour l'alternance");
73
        c.gridx = 0;
88
        c.gridx = 0;
74
        c.gridwidth = 2;
89
        c.gridwidth = 2;
75
        c.gridy++;
90
        c.gridy++;
76
        this.add(labelAlternate, c);
91
        this.add(labelAlternate, c);
Line 197... Line 212...
197
        if (this.comboLook.getSelectedIndex() == 0) {
212
        if (this.comboLook.getSelectedIndex() == 0) {
198
            properties.setProperty(UI_LOOK, "system");
213
            properties.setProperty(UI_LOOK, "system");
199
        } else {
214
        } else {
200
            properties.setProperty(UI_LOOK, "nimbus");
215
            properties.setProperty(UI_LOOK, "nimbus");
201
        }
216
        }
-
 
217
 
-
 
218
        if (this.comboDPI.getSelectedIndex() == 1) {
-
 
219
            properties.setProperty(UI_DPI, "1.3");
-
 
220
        } else if (this.comboDPI.getSelectedIndex() == 2) {
-
 
221
            properties.setProperty(UI_DPI, "2");
-
 
222
        } else if (this.comboDPI.getSelectedIndex() == 3) {
-
 
223
            properties.setProperty(UI_DPI, "3");
-
 
224
        } else if (this.comboDPI.getSelectedIndex() == 4) {
-
 
225
            properties.setProperty(UI_DPI, "4");
-
 
226
        } else {
-
 
227
            properties.setProperty(UI_DPI, "1");
-
 
228
        }
-
 
229
 
202
        super.storeValues();
230
        super.storeValues();
203
    }
231
    }
204
 
232
 
205
    private static void useNimbusLF() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
233
    private static void useNimbusLF() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
206
        UIManager.setLookAndFeel(getNimbusClassName());
234
        UIManager.setLookAndFeel(getNimbusClassName());
Line 252... Line 280...
252
            } else if (nimbusClassName == null || !System.getProperty("os.name", "??").toLowerCase().contains("linux")) {
280
            } else if (nimbusClassName == null || !System.getProperty("os.name", "??").toLowerCase().contains("linux")) {
253
                useSystemLF();
281
                useSystemLF();
254
            } else {
282
            } else {
255
                useNimbusLF();
283
                useNimbusLF();
256
            }
284
            }
-
 
285
            final String dpi = properties.getProperty(UI_DPI);
-
 
286
            if (dpi != null && dpi.length() > 0 && !dpi.equalsIgnoreCase("1")) {
-
 
287
                setUIFont(Float.valueOf(dpi));
-
 
288
                UIManager.put("dpi.scale", Float.valueOf(dpi));
-
 
289
            } else {
-
 
290
                UIManager.put("dpi.scale", Float.valueOf(1));
257
 
291
            }
258
        } catch (Exception e) {
292
        } catch (Exception e) {
259
            ExceptionHandler.handle("Unable to restore UI preferences", e);
293
            ExceptionHandler.handle("Unable to restore UI preferences", e);
260
        }
294
        }
261
    }
295
    }
262
 
296
 
-
 
297
    public static void setUIFont(float factor) {
-
 
298
        Enumeration<Object> keys = UIManager.getDefaults().keys();
-
 
299
 
-
 
300
        while (keys.hasMoreElements()) {
-
 
301
            Object key = keys.nextElement();
-
 
302
            Object value = UIManager.get(key);
-
 
303
            if (value instanceof javax.swing.plaf.FontUIResource) {
-
 
304
                javax.swing.plaf.FontUIResource r = (javax.swing.plaf.FontUIResource) value;
-
 
305
 
-
 
306
                UIManager.put(key, r.deriveFont(r.getSize() * factor));
-
 
307
            }
-
 
308
        }
-
 
309
    }
-
 
310
 
263
    private static void useSystemLF() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
311
    private static void useSystemLF() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
264
        LAFUtils.setLookAndFeel();
312
        LAFUtils.setLookAndFeel();
265
    }
313
    }
266
}
314
}