OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
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
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.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.action;
15
 
16
import org.openconcerto.erp.config.Gestion;
17
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.ui.FrameUtil;
19
import org.openconcerto.ui.state.WindowStateManager;
20
 
21
import java.awt.Dimension;
22
import java.awt.Toolkit;
23
import java.awt.event.ActionEvent;
24
import java.io.File;
25
 
26
import javax.swing.AbstractAction;
27
import javax.swing.Action;
28
import javax.swing.JFrame;
29
 
30
public abstract class CreateFrameAbstractAction extends AbstractAction {
31
    protected boolean mustLoadState = true;
32
 
33
    protected CreateFrameAbstractAction() {
34
        super();
35
    }
36
 
37
    protected CreateFrameAbstractAction(String name) {
38
        super(name);
39
    }
40
 
41
    public void actionPerformed(ActionEvent e) {
42
        final JFrame frame = createFrame();
156 ilm 43
        initFrame(frame, this, Configuration.getInstance(), this.mustLoadState);
44
        FrameUtil.show(frame);
45
    }
46
 
47
    protected static void initFrame(final JFrame frame, final Action action, final Configuration conf, final boolean mustLoadState) {
18 ilm 48
        frame.setIconImages(Gestion.getFrameIcon());
49
 
156 ilm 50
        final Object name = action.getValue(Action.NAME);
67 ilm 51
        WindowStateManager stateManager = null;
52
        if (name != null) {
156 ilm 53
            stateManager = new WindowStateManager(frame, new File(conf.getConfDir(), "Configuration" + File.separator + "Frame" + File.separator + name.toString() + ".xml"),
67 ilm 54
                    true);
55
        } else {
156 ilm 56
            System.err.println("Warning: no action name for action " + action + ", unable to use a window state manager.");
67 ilm 57
        }
80 ilm 58
 
18 ilm 59
        frame.pack();
60
 
61
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
62
        int w = Math.min(d.width - 100, frame.getWidth());
63
        int h = Math.min(d.height - 100, frame.getHeight());
64
        frame.setMinimumSize(new Dimension(w, h));
65
        frame.setLocationRelativeTo(null);
67 ilm 66
        if (mustLoadState && stateManager != null) {
18 ilm 67
            stateManager.loadState();
68
        }
80 ilm 69
 
70
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
18 ilm 71
    }
72
 
73
    abstract public JFrame createFrame();
74
}