Source Code Cross Referenced for LGanttMain.java in  » Project-Management » lgantt » com » csa » lgantt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Project Management » lgantt » com.csa.lgantt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *   Copyright 2004 Carlos Silva A.
003:         * 
004:         *   Licensed under the Apache License, Version 2.0 (the "License");
005:         *   you may not use this file except in compliance with the License. 
006:         *   You may obtain a copy of the License at  
007:         * 
008:         *   http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         *   Unless required by applicable law or agreed to in writing, software
011:         *   distributed under the License is distributed on an "AS IS" BASIS,
012:         *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *   See the License for the specific language governing permissions and
014:         *   limitations under the License.
015:         * 
016:         */package com.csa.lgantt;
017:
018:        import java.awt.Dimension;
019:        import java.awt.Image;
020:        import java.awt.Toolkit;
021:        import java.io.File;
022:        import java.io.FileInputStream;
023:        import java.io.FileOutputStream;
024:        import java.io.IOException;
025:        import java.net.URL;
026:        import java.util.ArrayList;
027:        import java.util.List;
028:        import java.util.Properties;
029:
030:        import javax.swing.ImageIcon;
031:        import javax.swing.JFrame;
032:        import javax.swing.JOptionPane;
033:        import javax.swing.SwingUtilities;
034:        import javax.swing.UIManager;
035:        import javax.swing.plaf.metal.DefaultMetalTheme;
036:        import javax.swing.plaf.metal.MetalLookAndFeel;
037:
038:        import com.csa.lgantt.model.IOManager;
039:        import com.csa.lgantt.model.Project;
040:        import com.csa.lgantt.view.GanttActionListener;
041:        import com.csa.lgantt.view.MainFrame;
042:
043:        /**
044:         * Aplicacion principal, lee la linea de comandos y carga un archivo si lo hay.
045:         * 
046:         * @version $Header: /cvs/java/App_JGantt/source/jgantt/JGanttMain.java,v 1.5
047:         *          2004/12/05 04:06:45 csilva Exp $
048:         * @author Carlos Silva
049:         */
050:        public class LGanttMain implements  Runnable {
051:            String fileName = null;
052:
053:            public static final String LAST_USED_REF = "abcdefg";
054:
055:            /**
056:             * Properties file, normally on the user.dir folder
057:             */
058:            public static final String PROPERTIES_FILE = ".lgantt.properties";
059:
060:            /**
061:             * Crea una ventana de gantt, editando un cierto archivo.
062:             * 
063:             * @param fn
064:             */
065:            public LGanttMain(String fn) {
066:                fileName = fn;
067:            }
068:
069:            /**
070:             * Crea la ventana de Gantt y comienza la ejecucion... Esta funcion se llama
071:             * desde el thread de swing.
072:             */
073:            public void run() {
074:                try {
075:                    JFrame mainFrame = null;
076:                    if (fileName == null)
077:                        mainFrame = new MainFrame();
078:                    else {
079:                        File source = new File(fileName);
080:                        Project p = IOManager.loadFrom(source);
081:                        mainFrame = new MainFrame(p, source);
082:                    }
083:                    URL res = getClass().getClassLoader().getResource(
084:                            Messages.getString("MainFrame.icon.file"));
085:                    ImageIcon icon = new ImageIcon(res);
086:                    mainFrame.setIconImage(icon.getImage());
087:                    mainFrame.pack();
088:                    mainFrame.setSize(new Dimension(680, 350));
089:                    mainFrame.setVisible(true);
090:
091:                    File config = getConfigFile();
092:                    if (!config.exists()) {
093:                        GanttActionListener.cmdHelpHints();
094:                        config.createNewFile();
095:                    }
096:
097:                } catch (Exception e) {
098:                    reportError("Excepcion al iniciar jGantt", e);
099:                    System.exit(1);
100:                }
101:            }
102:
103:            /**
104:             * Shows an exception on the interface
105:             * 
106:             * @param title
107:             * @param ex
108:             */
109:            public static void reportError(String title, Exception ex) {
110:                ex.printStackTrace();
111:                JOptionPane.showMessageDialog(null, ex, title,
112:                        JOptionPane.ERROR_MESSAGE);
113:            }
114:
115:            public static File getConfigFile() {
116:                String userDir = System.getProperty("user.home");
117:                return new File(userDir, PROPERTIES_FILE);
118:            }
119:
120:            static Properties properties = null;
121:
122:            /**
123:             * Returns the content of a property on the properties file
124:             * 
125:             * @param name
126:             * @return
127:             * @throws IOException
128:             */
129:            public static String getProperty(String name) {
130:                if (properties == null) {
131:                    properties = new Properties();
132:                    File f = getConfigFile();
133:                    if (f.exists()) {
134:                        try {
135:                            FileInputStream fis = new FileInputStream(f);
136:                            properties.load(fis);
137:                            fis.close();
138:                        } catch (IOException ex) {
139:                            reportError("Loading the properties file", ex);
140:                        }
141:                    }
142:                }
143:                return properties.getProperty(name);
144:            }
145:
146:            /**
147:             * Saves the config into the config properties file
148:             * 
149:             * @throws IOException
150:             */
151:            public static void saveConfig() {
152:                if (properties == null)
153:                    return;
154:                try {
155:                    File f = getConfigFile();
156:                    FileOutputStream out = new FileOutputStream(f);
157:                    properties.store(out, "");
158:                    out.close();
159:                } catch (IOException ex) {
160:                    reportError("Saving configuration properties...", ex);
161:                }
162:            }
163:
164:            /**
165:             * Agrega un archivo abierto recientemente a la configuracion.
166:             * 
167:             * TODO: Verificar que no sea igual a otro archivo ya abierto.
168:             * 
169:             * @param f
170:             * @throws IOException
171:             */
172:            public static void addLastUsed(File f) {
173:                String lastUsed = getProperty("last.used");
174:                if (lastUsed == null)
175:                    lastUsed = "";
176:                StringBuffer lu = new StringBuffer(lastUsed);
177:                int l = lastUsed.length();
178:                char newKey = 'a';
179:                if (l == 0) {
180:                    lu.insert(0, newKey);
181:                } else {
182:                    // do not repeat a file reference
183:                    for (int i = 0; i < lastUsed.length(); i++) {
184:                        char k = lastUsed.charAt(i);
185:                        String filePath = getProperty("lru." + k);
186:                        if (filePath.equals(f.getAbsolutePath())) {
187:                            if (i > 0) { // move the option to the top.
188:                                lu.deleteCharAt(i);
189:                                lu.insert(0, k);
190:                                properties.setProperty("last.used", lu
191:                                        .toString());
192:                            }
193:                            return;
194:                        }
195:                    }
196:                    if (l < LAST_USED_REF.length()) {
197:                        newKey = LAST_USED_REF.charAt(lastUsed.length());
198:                        lu.insert(0, newKey);
199:                    } else {
200:                        newKey = lastUsed.charAt(lastUsed.length() - 1);
201:                        lu.insert(0, newKey);
202:                        lu.setLength(l);
203:                    }
204:                }
205:                properties.setProperty("last.used", lu.toString());
206:                properties.setProperty("lru." + newKey, f.getAbsolutePath());
207:                saveConfig();
208:            }
209:
210:            /**
211:             * retrieves the list of the last used files
212:             * 
213:             * @return
214:             */
215:            public static List getLastUsed() {
216:                List l = new ArrayList();
217:                String lastUsed = getProperty("last.used");
218:                if (lastUsed != null)
219:                    for (int i = 0; i < lastUsed.length(); i++) {
220:                        String ref = "lru." + lastUsed.charAt(i);
221:                        String fileName = getProperty(ref);
222:                        l.add(new File(fileName));
223:                    }
224:                return l;
225:            }
226:
227:            /**
228:             * Funcion principal utiliza MetalLookAndFeel.
229:             * 
230:             * @param args
231:             * @throws Exception
232:             */
233:            public static void main(String[] args) throws Exception {
234:                try {
235:                    MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
236:                    UIManager
237:                            .setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
238:                } catch (Exception e) {
239:                    System.err
240:                            .println("ERROR: LookAndFeel could not be loaded: "
241:                                    + e.toString());
242:                }
243:                String fileName = null;
244:                for (int i = 0; i < args.length; i++) {
245:                    if (!args[i].startsWith("-")) {
246:                        fileName = args[i];
247:                    }
248:                }
249:
250:                SwingUtilities.invokeLater(new LGanttMain(fileName));
251:            }
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.