OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 18 | 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();
43
        frame.setIconImages(Gestion.getFrameIcon());
44
 
67 ilm 45
        final Object name = this.getValue(Action.NAME);
46
        WindowStateManager stateManager = null;
47
        if (name != null) {
48
            stateManager = new WindowStateManager(frame, new File(Configuration.getInstance().getConfDir(), "Configuration" + File.separator + "Frame" + File.separator + name.toString() + ".xml"),
49
                    true);
50
        } else {
51
            System.err.println("Warning: no action name for action " + this + ", unable to use a window state manager.");
52
        }
18 ilm 53
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
54
        frame.pack();
55
 
56
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
57
        int w = Math.min(d.width - 100, frame.getWidth());
58
        int h = Math.min(d.height - 100, frame.getHeight());
59
        frame.setMinimumSize(new Dimension(w, h));
60
        frame.setLocationRelativeTo(null);
67 ilm 61
        if (mustLoadState && stateManager != null) {
18 ilm 62
            stateManager.loadState();
63
        }
64
        FrameUtil.show(frame);
65
 
66
    }
67
 
68
    abstract public JFrame createFrame();
69
}