📄 jganttmain.java
字号:
/** * Copyright 2004 Carlos Silva A. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */package jgantt;import java.awt.Dimension;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.util.Properties;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.SwingUtilities;import javax.swing.UIManager;import javax.swing.plaf.metal.DefaultMetalTheme;import javax.swing.plaf.metal.MetalLookAndFeel;import jgantt.model.IOManager;import jgantt.model.Project;import jgantt.view.GanttActionListener;import jgantt.view.MainFrame;/** * Aplicacion principal, lee la linea de comandos y carga un archivo si lo hay. * * @version $Header: /cvs/java/App_JGantt/source/jgantt/JGanttMain.java,v 1.5 * 2004/12/05 04:06:45 csilva Exp $ * @author Carlos Silva */public class JGanttMain implements Runnable { String fileName = null; /** * Crea una ventana de gantt, editando un cierto archivo. * * @param fn */ public JGanttMain(String fn) { fileName = fn; } /** * Crea la ventana de Gantt y comienza la ejecucion... Esta funcion se llama * desde el thread de swing. */ public void run() { try { JFrame mainFrame = null; if (fileName == null) mainFrame = new MainFrame(); else { File source = new File(fileName); Project p = IOManager.loadFrom(source); mainFrame = new MainFrame(p, source); } mainFrame.pack(); mainFrame.setSize(new Dimension(680, 350)); mainFrame.setVisible(true); File config = getConfigFile(); if (!config.exists()) { GanttActionListener.cmdHelpHints(); config.createNewFile(); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage(), "Excepcion al iniciar jGantt", JOptionPane.ERROR_MESSAGE); System.exit(1); } } public static File getConfigFile(){ String userDir = System.getProperty("user.home"); return new File(userDir, ".lgantt.properties"); } static Properties properties=null; public static String getProperty(String name) throws IOException{ if (properties==null){ properties=new Properties(); File f = getConfigFile(); if (f.exists()){ FileInputStream fis = new FileInputStream(f); properties.load(fis); fis.close(); } } return properties.getProperty(name); } /** * Saves the config into the config properties file * @throws IOException */ public static void saveConfig() throws IOException{ if (properties==null)return; File f = getConfigFile(); FileOutputStream out = new FileOutputStream(f); System.out.println("saveConfig=="+f.getPath()+f.getName()); properties.store(out,""); out.close(); } /** * Agrega un archivo abierto recientemente a la configuracion * TODO: Verificar que no sea igual a otro archivo ya abierto. * @param f * @throws IOException */ public static void addLastUsed(File f) throws IOException{ StringBuffer lru = new StringBuffer(properties.getProperty("last.used")); int l = lru.length(); if (l<5){ lru.append( "abcdefghij".charAt(l)); } lru.insert(0, lru.charAt(l-1)); lru.setLength(l); properties.setProperty("last.used", lru.toString()); properties.setProperty("lru."+lru.charAt(0), f.getAbsolutePath()); saveConfig(); } /** * Funcion principal utiliza MetalLookAndFeel. * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { try { MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme()); UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); // UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); // UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); } catch (Exception e) { System.err.println("FATAL: Error al Cargar LookAndFeel: " + e.toString()); System.exit(1); } String fileName = null; for (int i = 0; i < args.length; i++) { if (!args[i].startsWith("-")) { fileName = args[i]; } } SwingUtilities.invokeLater(new JGanttMain(fileName)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -