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

📄 gantttreetablemodel.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package net.sourceforge.ganttproject;import java.util.ArrayList;import java.util.Enumeration;import java.util.GregorianCalendar;import java.util.List;import java.util.Vector;import javax.swing.Icon;import javax.swing.ImageIcon;import javax.swing.event.ChangeEvent;import javax.swing.event.ListSelectionEvent;import javax.swing.event.TableColumnModelEvent;import javax.swing.event.TableColumnModelListener;import javax.swing.tree.MutableTreeNode;import javax.swing.tree.TreeNode;import net.sourceforge.ganttproject.delay.Delay;import net.sourceforge.ganttproject.language.GanttLanguage;import net.sourceforge.ganttproject.language.GanttLanguage.Event;import net.sourceforge.ganttproject.task.CustomColumnsException;import net.sourceforge.ganttproject.task.ResourceAssignment;import net.sourceforge.ganttproject.task.Task;import net.sourceforge.ganttproject.task.TaskContainmentHierarchyFacade;import net.sourceforge.ganttproject.task.TaskInfo;import net.sourceforge.ganttproject.task.TaskLength;import net.sourceforge.ganttproject.task.TaskLengthImpl;import net.sourceforge.ganttproject.task.TaskManager;import net.sourceforge.ganttproject.task.TaskNode;import net.sourceforge.ganttproject.task.dependency.TaskDependency;import org.jdesktop.swing.treetable.DefaultTreeTableModel;/** * This class is the model for GanttTreeTable to display tasks. *  * @author bbaranne (Benoit Baranne) */public class GanttTreeTableModel extends DefaultTreeTableModel implements        TableColumnModelListener, TaskContainmentHierarchyFacade,        GanttLanguage.Listener {    private static GanttLanguage language = GanttLanguage.getInstance();    public static String strColType = null;    public static String strColPriority = null;    public static String strColInfo = null;    public static String strColName = null;    public static String strColBegDate = null;    public static String strColEndDate = null;    public static String strColDuration = null;    public static String strColCompletion = null;    public static String strColCoordinator = null;    public static String strColPredecessors = null;    public static String strColID = null;        public static String strColLineNumber = null;    /* TODO translation managment */    public static String strAssignments = "Assignments";    /** The colums titles */    public List titles = null;    /**     * Custom columns list.     */    private Vector customColumns = null;    /**     * Number of columns (presently in the model)     */    private int nbCol = 13;    /**     * Number of columns (at all, even hiden)     */    private int nbColTot = nbCol;    private final TaskManager myTaskManager;    /**     * Creates an instance of GanttTreeTableModel with a root.     *      * @param root     *            The root.     * @param taskManager      */    public GanttTreeTableModel(TreeNode root, TaskManager taskManager) {        super(root);        myTaskManager = taskManager;        titles = new ArrayList();        customColumns = new Vector();        changeLanguage(language);    }    /**     * Changes the language.     *      * @param ganttLanguage     *            New language to use.     */    public void changeLanguage(GanttLanguage ganttLanguage) {        strColType = language.getText("tableColType");        strColPriority = language.getText("tableColPriority");        strColInfo = language.getText("tableColInfo");        strColName = language.getText("tableColName");        strColBegDate = language.getText("tableColBegDate");        strColEndDate = language.getText("tableColEndDate");        strColDuration = language.getText("tableColDuration");        strColCompletion = language.getText("tableColCompletion");        strColCoordinator = language.getText("tableColCoordinator");        strColPredecessors = language.getText("tableColPredecessors");        strColID = language.getText("tableColID");        strColLineNumber = language.getText("tableColTaskLineNumber");        titles.clear();        String[] cols = new String[] { strColType, strColPriority, strColInfo,                strColName, strColBegDate, strColEndDate, strColDuration,                strColCompletion, strColCoordinator, strColPredecessors,                strColID, strAssignments, strColLineNumber };        for (int i = 0; i < cols.length; i++)            titles.add(new String(cols[i]));    }    /**     * Invoked this to insert newChild at location index in parents children.     * This will then message nodesWereInserted to create the appropriate event.     * This is the preferred way to add children as it will create the     * appropriate event.     */    public void insertNodeInto(MutableTreeNode newChild,            MutableTreeNode parent, int index) {        parent.insert(newChild, index);        int[] newIndexs = new int[1];        newIndexs[0] = index;        nodesWereInserted(parent, newIndexs);    }    /**     * Message this to remove node from its parent. This will message     * nodesWereRemoved to create the appropriate event. This is the preferred     * way to remove a node as it handles the event creation for you.     */    public void removeNodeFromParent(MutableTreeNode node) {        MutableTreeNode parent = (MutableTreeNode) node.getParent();        if (parent == null)            throw new IllegalArgumentException("node does not have a parent.");        int[] childIndex = new int[1];        Object[] removedArray = new Object[1];        childIndex[0] = parent.getIndex(node);        parent.remove(childIndex[0]);        removedArray[0] = node;        nodesWereRemoved(parent, childIndex, removedArray);    }    /**     * Add a custom column to the model.     *      * @param title     */    public void addCustomColumn(String title) {        customColumns.add(title);        nbColTot++;    }    /**     * Delete a custom column.     *      * @param title     */    public void deleteCustomColumn(String title) {        customColumns.remove(title);        this.columnRemoved(null);        nbColTot--;    }    public void renameCustomColumn(String oldName, String newName) {        customColumns.set(customColumns.indexOf(oldName), newName);    }    // /**    // * Returns the number of custom columns.    // * @return    // */    // public int getCustomColumnCount()    // {    // return customColumns.size();    // }    public int getColumnCount() {        return nbCol;    }    public int getColumnCountTotal() {        return nbColTot;    }    /**     * {@inheritDoc}     */    public Class getColumnClass(int column) {        switch (column) {        case 0:        case 1:        case 2:            return Icon.class;        case 3:            return hierarchicalColumnClass;        case 4:        case 5:            return GregorianCalendar.class;        case 6:        case 7:            return Integer.class;        case 8:            return String.class;        case 9:            return String.class;        case 10:            return Integer.class;        case 11:            return String.class;        case 12:        	return Integer.class;        default: {            TaskNode tn = (TaskNode) this.getRoot();            // tn = (TaskNode)tn.children().nextElement();            Object o = this.getValueAt(tn, column);            if (o == null) {                o = "erreur";                System.err.println("!!!!!!!!!!!!!!!!!");            }            return o.getClass();        }        }    }    public String getColumnName(int column) {        if (column < titles.size())            return (String) titles.get(column);        try {            return (String) customColumns.get(column - titles.size());        } catch (IndexOutOfBoundsException e) {            return (String) customColumns.get(column - titles.size() - 1);        }    }    /**     * @inheritDoc     */    public boolean isCellEditable(Object node, int column) {        if (node instanceof TaskNode)            return column != 8 && column != 9 && column != 10 && column != 2;        return false;    }    // public Object getChild(Object parent, int index)    // {    //	 	    // }    //	     // public int getChildCount(Object parent)    // {    //     	    // }    /**     * @inheritDoc     */    public Object getValueAt(Object node, int column) {        Object res = null;        if (!(node instanceof TaskNode))            return null;        TaskNode tn = (TaskNode) node;        Task t = (Task) tn.getUserObject();        // if(tn.getParent()!=null){        switch (column) {        case 0:            if (((Task) tn.getUserObject()).isProjectTask()) {                res = new ImageIcon(getClass().getResource(                        "/icons/mproject.gif"));            } else if (!tn.isLeaf())                res = new ImageIcon(getClass().getResource("/icons/mtask.gif"));            else if (t.isMilestone())                res = new ImageIcon(getClass()                        .getResource("/icons/meeting.gif"));            else                res = new ImageIcon(getClass().getResource("/icons/tasks2.png"));            break;

⌨️ 快捷键说明

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