⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ganttxmlopen.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************** * GanttXMLOpen.java  -  description * ------------------- * begin                : feb 2003 * copyright            : (C) 2002 by Thomas Alexandre * email                : alexthomas(at)ganttproject.org ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************/package net.sourceforge.ganttproject.io;import java.awt.Color;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.util.ArrayList;import java.util.Iterator;import java.util.Stack;import java.util.regex.Pattern;import javax.swing.JFrame;import javax.xml.parsers.ParserConfigurationException;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import net.sourceforge.ganttproject.GanttCalendar;import net.sourceforge.ganttproject.GanttGraphicArea;import net.sourceforge.ganttproject.PrjInfos;import net.sourceforge.ganttproject.gui.GanttDialogInfo;import net.sourceforge.ganttproject.gui.UIFacade;import net.sourceforge.ganttproject.language.GanttLanguage;import net.sourceforge.ganttproject.parser.FileFormatException;import net.sourceforge.ganttproject.parser.GPParser;import net.sourceforge.ganttproject.parser.ParsingContext;import net.sourceforge.ganttproject.parser.ParsingListener;import net.sourceforge.ganttproject.parser.TagHandler;import net.sourceforge.ganttproject.task.Task;import net.sourceforge.ganttproject.task.TaskManager;import org.xml.sax.Attributes;import org.xml.sax.SAXException;import org.xml.sax.helpers.DefaultHandler;/** * Class allow the programm to load a gantt file from xml format Use Sax parser */public class GanttXMLOpen implements GPParser {    /** The tree that contains data */    // GanttTree treePanel;    // /** The main frame */    // GanttProject prj;    private PrjInfos myProjectInfo = null;    /** The ressources */    // GanttResourcePanel peop;    /** 0-->description of project, 1->note for task */    int typeChar = -1;    /** The graphic area */    GanttGraphicArea area;    /** A stack of all father */    // ArrayList lot = new ArrayList();    /* List for depends */    // ArrayList lod = new ArrayList();    /** The id of the current task */    // int taskID;    // GanttDependStructure gds; //By CL    String indent = "";    String marge = "    "; // the marge    /** The language */    GanttLanguage language = GanttLanguage.getInstance();    // boolean bImport = false;    // int maxID = 0;    private ArrayList myTagHandlers = new ArrayList();    private ArrayList myListeners = new ArrayList();    private ParsingContext myContext;    private final TaskManager myTaskManager;    private int viewIndex;    private int ganttDividerLocation;    private int resourceDividerLocation;    private UIFacade myUIFacade = null;    private boolean bMerge = false;    /**     * Constructor     *      * @param uiFacade     *            TODO     */    public GanttXMLOpen(PrjInfos info, GanttGraphicArea gra,            TaskManager taskManager, UIFacade uiFacade) {        this(taskManager);        // this.treePanel = tree;        myProjectInfo = info;        // this.peop = resources;        this.area = gra;        // this.bImport = bImport;        this.viewIndex = 0;        this.ganttDividerLocation = 300; // todo does this arbitrary value is        // right ?        this.resourceDividerLocation = 300;        // if(bImport)        // maxID = ((TaskManagerImpl)taskManager).getMaxID();        myUIFacade = uiFacade;    }    public GanttXMLOpen(TaskManager taskManager) {        myContext = new ParsingContext();        myTaskManager = taskManager;    }    public boolean load(String filename) {        boolean temp = load(new File(filename));        // constructRelationship();        return temp;    }    public boolean load(InputStream inStream) throws IOException {        // Use an instance of ourselves as the SAX event handler        myTaskManager.getAlgorithmCollection().getAdjustTaskBoundsAlgorithm()                .setEnabled(false);        myTaskManager.getAlgorithmCollection()                .getRecalculateTaskScheduleAlgorithm().setEnabled(false);        DefaultHandler handler = new GanttXMLParser();        // Use the default (non-validating) parser        SAXParserFactory factory = SAXParserFactory.newInstance();        try {            // Parse the input            SAXParser saxParser;            saxParser = factory.newSAXParser();            saxParser.parse(inStream, handler);        } catch (ParserConfigurationException e) {            e.printStackTrace();        } catch (SAXException e) {            e.printStackTrace();            throw new IOException(e.getMessage());        }        myTaskManager.getAlgorithmCollection()                .getRecalculateTaskScheduleAlgorithm().setEnabled(true);        myTaskManager.getAlgorithmCollection().getAdjustTaskBoundsAlgorithm()                .setEnabled(true);        // treePanel.refreshAllId(treePanel.getRoot());        // treePanel.forwardScheduling();        if (!bMerge) {            myUIFacade.setViewIndex(viewIndex);            myUIFacade.setGanttDividerLocation(ganttDividerLocation);            if (resourceDividerLocation != 0)                myUIFacade.setResourceDividerLocation(resourceDividerLocation);        }        return true;    }    public boolean load(File file) {        // Use an instance of ourselves as the SAX event handler        DefaultHandler handler = new GanttXMLParser();        // Use the default (non-validating) parser        SAXParserFactory factory = SAXParserFactory.newInstance();        try {            // Parse the input            SAXParser saxParser = factory.newSAXParser();            saxParser.parse(file, handler);        } catch (Exception e) {            e.printStackTrace();            GanttDialogInfo gdi = new GanttDialogInfo((JFrame) myUIFacade,                    GanttDialogInfo.ERROR, GanttDialogInfo.YES_OPTION, language                            .getText("msg2")                            + file.getAbsolutePath(), language.getText("error"));            gdi.show();            return false;        }        // if(treePanel!=null) {        // treePanel.forwardScheduling();//refreshAllId(treePanel.getRoot());        // }        return true;    }    public void addTagHandler(TagHandler handler) {        myTagHandlers.add(handler);    }    public void addParsingListener(ParsingListener listener) {        myListeners.add(listener);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -