OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 180
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
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.erp.action;
14
 package org.openconcerto.erp.action;
15
 
15
 
16
import org.openconcerto.erp.config.Gestion;
16
import org.openconcerto.erp.config.Gestion;
17
import org.openconcerto.sql.Configuration;
17
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.ui.FrameUtil;
18
import org.openconcerto.ui.FrameUtil;
19
import org.openconcerto.ui.state.WindowStateManager;
19
import org.openconcerto.ui.state.WindowStateManager;
20
 
20
 
21
import java.awt.Dimension;
21
import java.awt.Dimension;
22
import java.awt.Toolkit;
22
import java.awt.Toolkit;
23
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionEvent;
24
import java.io.File;
24
import java.io.File;
25
 
25
 
26
import javax.swing.AbstractAction;
26
import javax.swing.AbstractAction;
27
import javax.swing.Action;
27
import javax.swing.Action;
28
import javax.swing.JFrame;
28
import javax.swing.JFrame;
29
 
29
 
30
public abstract class CreateFrameAbstractAction extends AbstractAction {
30
public abstract class CreateFrameAbstractAction extends AbstractAction {
31
    protected boolean mustLoadState = true;
31
    protected boolean mustLoadState = true;
32
 
32
 
33
    protected CreateFrameAbstractAction() {
33
    protected CreateFrameAbstractAction() {
34
        super();
34
        super();
35
    }
35
    }
36
 
36
 
37
    protected CreateFrameAbstractAction(String name) {
37
    protected CreateFrameAbstractAction(String name) {
38
        super(name);
38
        super(name);
39
    }
39
    }
40
 
40
 
41
    public void actionPerformed(ActionEvent e) {
41
    public void actionPerformed(ActionEvent e) {
42
        final JFrame frame = createFrame();
42
        final JFrame frame = createFrame();
43
        initFrame(frame, this, Configuration.getInstance(), this.mustLoadState);
43
        initFrame(frame, this, Configuration.getInstance(), this.mustLoadState);
44
        FrameUtil.show(frame);
44
        FrameUtil.show(frame);
45
    }
45
    }
46
 
46
 
47
    protected static void initFrame(final JFrame frame, final Action action, final Configuration conf, final boolean mustLoadState) {
47
    protected static void initFrame(final JFrame frame, final Action action, final Configuration conf, final boolean mustLoadState) {
48
        frame.setIconImages(Gestion.getFrameIcon());
48
        frame.setIconImages(Gestion.getFrameIcon());
49
 
49
 
50
        final Object name = action.getValue(Action.NAME);
50
        final Object name = action.getValue(Action.NAME);
51
        WindowStateManager stateManager = null;
51
        WindowStateManager stateManager = null;
52
        if (name != null) {
52
        if (name != null) {
-
 
53
            if (conf == null) {
-
 
54
                System.err.println("Warning: no configuration for action " + action + ", unable to use a window state manager.");
-
 
55
            } else {
53
            stateManager = new WindowStateManager(frame, new File(conf.getConfDir(), "Configuration" + File.separator + "Frame" + File.separator + name.toString() + ".xml"),
56
                stateManager = new WindowStateManager(frame, new File(conf.getConfDir(), "Configuration" + File.separator + "Frame" + File.separator + name.toString() + ".xml"), true);
54
                    true);
57
            }
55
        } else {
58
        } else {
56
            System.err.println("Warning: no action name for action " + action + ", unable to use a window state manager.");
59
            System.err.println("Warning: no action name for action " + action + ", unable to use a window state manager.");
57
        }
60
        }
58
 
61
 
59
        frame.pack();
62
        frame.pack();
60
 
63
 
61
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
64
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
62
        int w = Math.min(d.width - 100, frame.getWidth());
65
        int w = Math.min(d.width - 100, frame.getWidth());
63
        int h = Math.min(d.height - 100, frame.getHeight());
66
        int h = Math.min(d.height - 100, frame.getHeight());
64
        frame.setMinimumSize(new Dimension(w, h));
67
        frame.setMinimumSize(new Dimension(w, h));
65
        frame.setLocationRelativeTo(null);
68
        frame.setLocationRelativeTo(null);
66
        if (mustLoadState && stateManager != null) {
69
        if (mustLoadState && stateManager != null) {
67
            stateManager.loadState();
70
            stateManager.loadState();
68
        }
71
        }
69
 
72
 
70
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
73
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
71
    }
74
    }
72
 
75
 
73
    abstract public JFrame createFrame();
76
    abstract public JFrame createFrame();
74
}
77
}