OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 67 | Go to most recent revision | Details | 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
 
45
        WindowStateManager stateManager = new WindowStateManager(frame, new File(Configuration.getInstance().getConfDir(), "Configuration" + File.separator + "Frame" + File.separator
46
                + this.getValue(Action.NAME).toString() + ".xml"), true);
47
 
48
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
49
        frame.pack();
50
 
51
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
52
        int w = Math.min(d.width - 100, frame.getWidth());
53
        int h = Math.min(d.height - 100, frame.getHeight());
54
        frame.setMinimumSize(new Dimension(w, h));
55
        frame.setLocationRelativeTo(null);
56
        if (mustLoadState) {
57
            stateManager.loadState();
58
        }
59
        FrameUtil.show(frame);
60
 
61
    }
62
 
63
    abstract public JFrame createFrame();
64
}