001    /**
002     * planningtool - A Planning Tool with Critiquing Support.
003     * 
004     * Copyright (C) 2006 olale
005    
006     * This program is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU General Public License
008     * as published by the Free Software Foundation; either version 2
009     * of the License, or (at your option) any later version.
010    
011     * This program is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014     * GNU General Public License for more details.
015    
016     * You should have received a copy of the GNU General Public License
017     * along with this program; if not, write to the Free Software
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019    
020     * Contact information: 
021     * E-mail: olale@ida.liu.se
022     *         olale@lysator.liu.se
023     */
024    package se.liu.ida.critiquer.gui;
025    
026    import java.awt.BorderLayout;
027    import java.awt.FileDialog;
028    import java.awt.MenuBar;
029    
030    import javax.swing.JFrame;
031    import javax.swing.JOptionPane;
032    import javax.swing.JTabbedPane;
033    
034    import se.liu.ida.critiquer.mics.ReferenceHolder;
035    
036    public class PlanningTool extends JFrame {
037    
038            /**
039             * 
040             */
041            private static final long   serialVersionUID = 1L;
042    
043            private JTabbedPane              pane;
044    
045            private TimeView                        timePane;
046    
047            private ResourceView            resourcePane;
048    
049            private CritiquePanel      critiqueChooserPane;
050    
051            private OrganizationView        orgPane;
052    
053            private GeoView                  gisPane;
054    
055            private static PlanningTool planningTool         = null;
056    
057            
058            private TaskView   graphView;
059            public static PlanningTool getPlanningTool() {
060                    if (planningTool == null) {
061                            planningTool = new PlanningTool();
062                    }
063                    return planningTool;
064            }
065    
066            private PlanningTool() {
067                    super("Planning Tool");
068                    PlanningTool.planningTool = this;
069                    initialize();
070            }
071    
072            private void initialize() {
073                    ReferenceHolder.topFrame = this;
074                    setTitle("Critiquer");
075                    pane = new JTabbedPane();
076                    critiqueChooserPane = new CritiquePanel(pane);
077                    createMenu(this);
078    
079                    timePane = new TimeView();
080                    resourcePane = new ResourceView();
081                    orgPane = new OrganizationView();
082                    gisPane = new GeoView();
083                    graphView = new TaskView();
084                    pane.addTab("Task View", graphView);
085                    pane.addTab("Organization view", orgPane);
086                    pane.addTab("Resource View", resourcePane);
087                    pane.addTab("Timeline View", timePane);
088                    pane.addTab("Geographical view", gisPane);
089                    getContentPane().setLayout(new BorderLayout());
090                    getContentPane().add(critiqueChooserPane, BorderLayout.WEST);
091                    getContentPane().add(pane, BorderLayout.CENTER);
092                    pack();
093                    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
094    
095            }
096    
097            private void createMenu(final JFrame parentFrame) {
098                    MenuBar menu = new MenuBar();
099                    parentFrame.setMenuBar(menu);
100            }
101    
102            
103            public static void main(String[] args) {
104                    for (int i = 0; i < args.length; i++) {
105                            String arg = args[i];
106                            if (arg.equals("--resource-dir")) {
107                                    ReferenceHolder.resourceDir = args[i + 1];
108                            }
109                    }
110                    if (ReferenceHolder.resourceDir == null) {
111                            
112                            FileDialog fileDialog = new FileDialog(new JFrame(), "Select resource directory", FileDialog.LOAD);
113                            fileDialog.setVisible(true);
114                            String fileName = fileDialog.getDirectory();
115                            if (fileName != null) {
116                                    ReferenceHolder.resourceDir = fileName;
117                            } else {
118                                    JOptionPane.showMessageDialog(  new JFrame(),
119                                                                                                    "Invalid resource directory.\nMap will not be available",
120                                                                                                    "Invalid directory",
121                                                                                                    JOptionPane.WARNING_MESSAGE);
122                            }
123                    }
124                    getPlanningTool().setVisible(true);
125                    
126    
127            }
128    
129            public static void forceGUIUpdate() {
130                    if (planningTool != null) {
131                            planningTool.pane.revalidate();
132                            planningTool.pane.repaint();
133                    }
134            }
135    }