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

📄 ganttgraphicarea.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                                new Runnable() {                                    public void run() {                                        try {                                            getTaskManager()                                                    .getDependencyCollection()                                                    .createDependency(                                                            myDependant,                                                            dependee,                                                            new FinishStartConstraintImpl());                                        } catch (TaskDependencyException e1) {                                            e1.printStackTrace();                                        }                                        appli.setAskForSave(true);                                        // appli.setQuickSave (true);                                        // appli.quickSave ("Draw dependency");                                    }                                });                    }                } else {                    myArrow = new DependencyInteractionRenderer();                    repaint();                }            }        }        public void paint(Graphics g) {            myArrow.paint(g);        }    }    class MoveTaskInteraction extends MouseInteractionBase implements            MouseInteraction {        private Task myTask;        private TaskMutator myMutator;        private GanttCalendar myInitialStart;        MoveTaskInteraction(MouseEvent e, Task task) {            super(e);            myTask = task;            myMutator = task.createMutator();            myInitialStart = myTask.getStart();        }        public void apply(MouseEvent event) {            float diff = getChartModel().calculateLengthNoWeekends(getStartX(),                    event.getX());            TaskLength bottomUnitLength = getTaskManager().createLength(                    getViewState().getBottomTimeUnit(), diff);            TaskLength taskLength = myTask.translateDuration(bottomUnitLength);            int dayDiff = (int) (taskLength.getValue());            // System.err.println("[MoveTaskInteraction] apply():            // dayDiff="+dayDiff+" bottomUnitLength="+bottomUnitLength+"            // translated="+taskLength);            if (dayDiff != 0) {                myMutator.shift(dayDiff);            }        }        public void finish() {            myMutator.setIsolationLevel(TaskMutator.READ_COMMITED);            getUndoManager().undoableEdit("Task moved", new Runnable() {                public void run() {                    doFinish();                }            });        }        private void doFinish() {            myMutator.commit();            try {                getTaskManager().getAlgorithmCollection()                        .getRecalculateTaskScheduleAlgorithm().run();            } catch (TaskDependencyException e) {                // TODO Auto-generated catch block                e.printStackTrace();            }            GanttGraphicArea.this.repaint();        }    }    class MoveTaskInteractions extends MouseInteractionBase implements            MouseInteraction {        private List myTasks; // of Task        private List myMutators; // of TaskMutator        private List myInitialStarts; // of GanttCalendar        MoveTaskInteractions(MouseEvent e, List tasks) {            super(e);            myTasks = tasks;            myMutators = new ArrayList(myTasks.size());            myInitialStarts = new ArrayList(myTasks.size());            Iterator itTasks = myTasks.iterator();            while (itTasks.hasNext()) {                Task t = (Task) itTasks.next();                myMutators.add(t.createMutator());                myInitialStarts.add(t.getStart());            }        }        public void apply(MouseEvent event) {            float diff = getLengthDiff(event);            TaskLength bottomUnitLength = getTaskManager().createLength(                    getViewState().getBottomTimeUnit(), diff);            for (int i = 0; i < myTasks.size(); i++) {                Task task = (Task) myTasks.get(i);                TaskLength taskLength = task                        .translateDuration(bottomUnitLength);                int dayDiff = (int) (taskLength.getValue());                if (dayDiff != 0) {                    ((TaskMutator) myMutators.get(i)).shift(dayDiff);                }            }        }        public void finish() {            Iterator itMutators = myMutators.iterator();            while (itMutators.hasNext())                ((TaskMutator) itMutators.next())                        .setIsolationLevel(TaskMutator.READ_COMMITED);            getUndoManager().undoableEdit("Task moved", new Runnable() {                public void run() {                    doFinish();                }            });        }        private void doFinish() {            Iterator itMutators = myMutators.iterator();            while (itMutators.hasNext())                ((TaskMutator) itMutators.next()).commit();            try {                getTaskManager().getAlgorithmCollection()                        .getRecalculateTaskScheduleAlgorithm().run();            } catch (TaskDependencyException e) {                e.printStackTrace();            }            Iterator itTasks = myTasks.iterator();            while (itTasks.hasNext()) {                Task t = ((Task) itTasks.next());                t.applyThirdDateConstraint();            }            GanttGraphicArea.this.repaint();        }    }    public interface ChartImplementation extends ZoomListener {        void paintChart(Graphics g);        void paintComponent(Graphics g, List/*<Task>*/ visibleTasks);        MouseListener getMouseListener();        MouseMotionListener getMouseMotionListener();        void beginChangeTaskEndInteraction(MouseEvent initiatingEvent,                TaskBoundaryChartItem taskBoundary);        MouseInteraction getActiveInteraction();        void beginChangeTaskStartInteraction(MouseEvent e,                TaskBoundaryChartItem taskBoundary);        MouseInteraction finishInteraction();        void beginChangeTaskProgressInteraction(MouseEvent e,                TaskProgressChartItem item);        void beginDrawDependencyInteraction(MouseEvent initiatingEvent,                TaskRegularAreaChartItem taskArea,                GanttGraphicArea.MouseSupport mouseSupport);        void beginMoveTaskInteraction(MouseEvent e, Task task);        void beginMoveTaskInteractions(MouseEvent e, List tasks);        void beginScrollViewInteraction(MouseEvent e);    }    private class NewChartComponentImpl extends AbstractChartImplementation implements ChartImplementation {        public NewChartComponentImpl(IGanttProject project, ChartModelBase chartModel, ChartComponentBase chartComponent) {            super(project, chartModel, chartComponent);            // TODO Auto-generated constructor stub        }        public void beginChangeTaskEndInteraction(MouseEvent initiatingEvent,                TaskBoundaryChartItem taskBoundary) {            setActiveInteraction(new ChangeTaskEndInteraction(initiatingEvent,                    taskBoundary));        }        public void beginChangeTaskStartInteraction(MouseEvent e,                TaskBoundaryChartItem taskBoundary) {            setActiveInteraction(new ChangeTaskStartInteraction(e, taskBoundary));        }        public void beginChangeTaskProgressInteraction(MouseEvent e,                TaskProgressChartItem taskProgress) {            setActiveInteraction(new ChangeTaskProgressInteraction(e,                    taskProgress));        }        public void beginDrawDependencyInteraction(MouseEvent initiatingEvent,                TaskRegularAreaChartItem taskArea,                GanttGraphicArea.MouseSupport mouseSupport) {            setActiveInteraction(new DrawDependencyInteraction(initiatingEvent,                    taskArea, mouseSupport));        }        public void beginMoveTaskInteraction(MouseEvent e, Task task) {            setActiveInteraction(new MoveTaskInteraction(e, task));        }        public void beginMoveTaskInteractions(MouseEvent e, List tasks) {            setActiveInteraction(new MoveTaskInteractions(e, tasks));        }        public void paintComponent(Graphics g, List/*<Task>*/ visibleTasks) {        	synchronized(ChartModelBase.STATIC_MUTEX) {	            GanttGraphicArea.super.paintComponent(g);	            ChartModel model = myChartModel;	            model.setTaskContainment(appli.getTaskContainment());	            // model.setBounds(getSize());	            // System.err.println("[NewChartComponentImpl] paintComponent. unit	            // width="+getViewState().getBottomUnitWidth());	            model.setBottomUnitWidth(getViewState().getBottomUnitWidth());	            model.setRowHeight(((GanttTree2) tree).getTreeTable()	                    .getRowHeight());	            model.setTopTimeUnit(getViewState().getTopTimeUnit());	            model.setBottomTimeUnit(getViewState().getBottomTimeUnit());	            model.setVisibleTasks(visibleTasks);	            model.paint(g);	            if (getActiveInteraction() != null) {	                getActiveInteraction().paint(g);	            }        	}        }        public void paintChart(Graphics g) {        	synchronized(ChartModelBase.STATIC_MUTEX) {	            //GanttGraphicArea.super.paintComponent(g);	            ChartModel model = myChartModel;	            model.setTaskContainment(appli.getTaskContainment());	            // model.setBounds(getSize());	            // System.err.println("[NewChartComponentImpl] paintComponent. unit	            // width="+getViewState().getBottomUnitWidth());	            model.setBottomUnitWidth(getViewState().getBottomUnitWidth());	            model.setRowHeight(((GanttTree2) tree).getTreeTable()	                    .getRowHeight());	            model.setTopTimeUnit(getViewState().getTopTimeUnit());	            model.setBottomTimeUnit(getViewState().getBottomTimeUnit());	            VisibleNodesFilter visibleNodesFilter = new VisibleNodesFilter();	            List visibleTasks = visibleNodesFilter.getVisibleNodes(tree	                    .getJTree(), getScrollBar(), getHeight(), tree	                    .getTreeTable().getRowHeight());	            model.setVisibleTasks(visibleTasks);                model.setVerticalOffset(getScrollBar() % tree.getTreeTable().getRowHeight());	            model.paint(g);	            if (getActiveInteraction() != null) {	                getActiveInteraction().paint(g);	            }        	}        }        public MouseListener getMouseListener() {            return myMouseListener;        }        public MouseMotionListener getMouseMotionListener() {            return myMouseMotionListener;        }		public IStatus canPaste(ChartSelection selection) {			return Status.OK_STATUS;		}		public ChartSelection getSelection() {			ChartSelectionImpl result = new ChartSelectionImpl() {				public boolean isEmpty() {					return false;				}				public void startCopyClipboardTransaction() {					super.startCopyClipboardTransaction();					tree.copySelectedNode();				}				public void startMoveClipboardTransaction() {					super.startMoveClipboardTransaction();					tree.cutSelectedNode();				}			};			return result;		}		public void paste(ChartSelection selection) {			tree.pasteNode();		}                        private OldChartMouseListenerImpl myMouseListener = new OldChartMouseListenerImpl();        private OldMouseMotionListenerImpl myMouseMotionListener = new OldMouseMotionListenerImpl();    }    protected AbstractChartImplementation getImplementation() {        return (AbstractChartImplementation) getChartImplementation();    }    private ChartImplementation getChartImplementation() {        if (myChartComponentImpl == null) {            myChartComponentImpl = new NewChartComponentImpl(getProject(), getChartModel(), this);        }        return myChartComponentImpl;    }    public Action getScrollCenterAction(ScrollingManager scrollMgr,            TaskSelectionManager taskSelMgr, String iconSize) {        if (myScrollCenterAction == null)            myScrollCenterAction = new ScrollGanttChartCenterAction(scrollMgr,                    taskSelMgr, iconSize);        return myScrollCenterAction;    }    public void setPreviousStateTasks(ArrayList tasks) {        int rowHeight = myChartModel.setPreviousStateTasks(tasks);        ((GanttTree2) appli.getTree()).getTable().setRowHeight(rowHeight);    }    private ChartImplementation myChartComponentImpl;    private ScrollGanttChartCenterAction myScrollCenterAction;    protected class ScrollGanttChartCenterAction extends GPAction {        private final ScrollingManager myScrollingManager;        private final TaskSelectionManager myTaskSelectionManager;        public ScrollGanttChartCenterAction(ScrollingManager scrollingManager,                TaskSelectionManager taskSelectionManager, String iconSize) {            super("ScrollCenter", iconSize);            myScrollingManager = scrollingManager;            myTaskSelectionManager = taskSelectionManager;        }                public void actionPerformed(ActionEvent e) {        	getUIFacade().setStatusText(GanttLanguage.getInstance().getText("centerOnSelectedTasks"));            scroll();            //moves the block of the scroll bar//            Mediator.getGanttProjectSingleton().getMyGanttChartTabContent().getCustomScrollPane().setBlockFromChart();            Mediator.getGanttProjectSingleton().getResourcePanel().getCustomScrollPane().setBlockFromChart();            	        }        private void scroll() {            GanttCalendar min = null;            GanttCalendar max = null;            Date scrollDate = null;            Iterator it = null;            if (myTaskSelectionManager.getSelectedTasks().isEmpty()) {                // scrollDate = getTaskManager().getProjectStart();                it = Arrays.asList(getTaskManager().getTasks()).iterator();            } else {                it = myTaskSelectionManager.getSelectedTasks().iterator();            }            while (it.hasNext()) {                Task t = (Task) it.next();                GanttCalendar dStart = t.getStart();

⌨️ 快捷键说明

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