📄 ganttgraphicarea.java
字号:
GanttCalendar dEnd = t.getEnd(); min = min == null ? dStart.Clone() : (min.compareTo(dStart) > 0 ? dStart.Clone() : min); max = max == null ? dEnd.Clone() : (max.compareTo(dEnd) < 0 ? dEnd.Clone() : max); } //no tasks defined, nothing to do if(min == null || max == null) return; TimeUnit defaultUnit = getTimeUnitStack().getDefaultTimeUnit(); final TaskLength selectionLength = getTaskManager().createLength( defaultUnit, min.getTime(), max.getTime()); final TaskLength viewLength = getChartModel().getVisibleLength(); float viewLengthInDefaultUnits = viewLength.getLength(defaultUnit); // if selection is shorter than view we'll scroll right, // otherwise we'll scroll left // delta is measured in the bottom line time units final float delta = (selectionLength.getValue() - viewLengthInDefaultUnits) / 2; scrollDate = GPCalendar.PLAIN.shiftDate(min.getTime(), getTaskManager().createLength(defaultUnit, delta)); myScrollingManager.scrollLeft(scrollDate); } /* * (non-Javadoc) * * @see net.sourceforge.ganttproject.action.GPAction#getIconFilePrefix() */ protected String getIconFilePrefix() { return "scrollcenter_"; } protected String getLocalizedName() { return super.getLocalizedName(); } } private class OldChartMouseListenerImpl extends MouseListenerBase implements MouseListener { private MouseSupport myMouseSupport = new MouseSupport(); public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { Task taskUnderPointer = myMouseSupport .findTaskUnderMousePointer(e.getX(), e.getY()); if (taskUnderPointer == null) { tree.selectTreeRow(-1); } } if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { if (!appli.isOnlyViewer) appli.propertiesTask(); } } protected Action[] getPopupMenuActions() { Action[] treeActions = tree.getPopupMenuActions(); int sep = 0; if (treeActions.length != 0) { sep = 1; } Action[] chartActions = GanttGraphicArea.this.getPopupMenuActions(); Action[] result = new Action[treeActions.length + sep + chartActions.length]; System.arraycopy(treeActions, 0, result, 0, treeActions.length); System.arraycopy(chartActions, 0, result, treeActions.length + sep, chartActions.length); return result; } public void mousePressed(MouseEvent e) { tree.stopEditing(); if (appli.isOnlyViewer) return; Task taskUnderPointer = myMouseSupport.findTaskUnderMousePointer(e .getX(), e.getY()); if (taskUnderPointer!=null && !Mediator.getTaskSelectionManager().isTaskSelected( taskUnderPointer)) { boolean ctrl = (e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK; tree.selectTask(taskUnderPointer, ctrl); } super.mousePressed(e); if (taskUnderPointer == null) { return; } if (e.getButton() == MouseEvent.BUTTON1) { ChartItem itemUnderPoint = myMouseSupport .getChartItemUnderMousePoint(e.getX(), e.getY()); if (itemUnderPoint instanceof TaskBoundaryChartItem) { TaskBoundaryChartItem taskBoundary = (TaskBoundaryChartItem) itemUnderPoint; if (taskBoundary.isStartBoundary()) { getChartImplementation() .beginChangeTaskStartInteraction(e, taskBoundary); } else { getChartImplementation().beginChangeTaskEndInteraction( e, taskBoundary); } } else if (itemUnderPoint instanceof TaskProgressChartItem) { getChartImplementation() .beginChangeTaskProgressInteraction(e, (TaskProgressChartItem) itemUnderPoint); // setCursor(new Cursor(Cursor.E_RESIZE_CURSOR)); } else if (itemUnderPoint instanceof TaskRegularAreaChartItem) { getChartImplementation().beginDrawDependencyInteraction(e, (TaskRegularAreaChartItem) itemUnderPoint, myMouseSupport); } repaint(); appli.recalculateCriticalPath(); } else if (e.getButton() == MouseEvent.BUTTON2) { if (!Mediator.getTaskSelectionManager().isTaskSelected( taskUnderPointer)) tree.selectTask(taskUnderPointer, false); List l = Mediator.getTaskSelectionManager().getSelectedTasks(); getChartImplementation().beginMoveTaskInteractions(e, l); } } } private class OldMouseMotionListenerImpl extends MouseMotionListenerBase { private MouseSupport myMouseSupport = new MouseSupport(); public void mouseDragged(MouseEvent e) { if (appli.isOnlyViewer) return; super.mouseDragged(e); /* * Add the repaint in order to repaint the treetable when an action * occurs on the GraphicArea. here mousedragged because all actions * modifying task properties on the graphics are made through * mousedragged (I think !) */ // Mediator.getGanttProjectSingleton().repaint(); // getUIFacade().repaint2(); if (myUIConfiguration.isCriticalPathOn()) { MouseInteraction mi = myChartComponentImpl .getActiveInteraction(); if ((mi instanceof ChangeTaskBoundaryInteraction) || (mi instanceof MoveTaskInteraction) || (mi instanceof MoveTaskInteractions)) appli.recalculateCriticalPath(); } GanttGraphicArea.this.repaint(); // avant } // Move the move on the area public void mouseMoved(MouseEvent e) { ChartItem itemUnderPoint = myMouseSupport .getChartItemUnderMousePoint(e.getX(), e.getY()); Task taskUnderPoint = itemUnderPoint == null ? null : itemUnderPoint.getTask(); // System.err.println("[OldMouseMotionListenerImpl] mouseMoved: // taskUnderPoint="+taskUnderPoint); if (taskUnderPoint == null) { setDefaultCursor(); } else { if (itemUnderPoint instanceof TaskBoundaryChartItem) { Cursor cursor = ((TaskBoundaryChartItem) itemUnderPoint) .isStartBoundary() ? W_RESIZE_CURSOR : E_RESIZE_CURSOR; setCursor(cursor); } // special cursor else if (itemUnderPoint instanceof TaskProgressChartItem) { setCursor(CHANGE_PROGRESS_CURSOR); } else { setDefaultCursor(); } // getUIFacade().repaint2(); appli.repaint(); } } } public void setTaskManager(TaskManager taskManager) { // TODO Auto-generated method stub } public void reset() { // TODO Auto-generated method stub } public Icon getIcon() { // TODO Auto-generated method stub return null; } public void customColumsChange(CustomColumEvent event) { repaint(); } public void setUIConfiguration(UIConfiguration configuration) { myUIConfiguration = configuration; } private static class ChartOptionsPreviewPanel extends JPanel implements ChangeValueListener { Text upText, downText, leftText, rightText; TaskBar taskBar; public ChartOptionsPreviewPanel() { super(); addToDispatchers(); setBackground(Color.WHITE); setPreferredSize(new Dimension(450, 70)); taskBar = new TaskBar(); upText = new Text(Text.UP, taskBar); downText = new Text(Text.DOWN, taskBar); leftText = new Text(Text.LEFT, taskBar); rightText = new Text(Text.RIGHT, taskBar); } void refresh() { } private void addToDispatchers() { List dispatchers = Mediator.getChangeValueDispatchers(); for (int i = 0; i < dispatchers.size(); i++) { ((ChangeValueDispatcher) dispatchers.get(i)) .addChangeValueListener(this); } } public void paint(Graphics g) { super.paint(g); taskBar.paintMe(g); upText.paintMe(g); downText.paintMe(g); leftText.paintMe(g); rightText.paintMe(g); } public void changeValue(ChangeValueEvent event) { Object id = event.getID(); if (id.equals("up")) { upText.text = getI18n(event.getNewValue().toString()); } else if (id.equals("down")) { downText.text = getI18n(event.getNewValue().toString()); } else if (id.equals("left")) { leftText.text = getI18n(event.getNewValue().toString()); } else if (id.equals("right")) { rightText.text = getI18n(event.getNewValue().toString()); } repaint(); } static String getI18n(String id) { String res = GanttLanguage.getInstance().getText( "optionValue." + id + ".label"); if (res.startsWith(GanttLanguage.MISSING_RESOURCE)) { res = id; } return res; } class TaskBar { int width, height, x, y; Color color; TaskBar() { width = 100; height = 12; x = (int) (ChartOptionsPreviewPanel.this.getPreferredSize() .getWidth() / 2 - width / 2); y = (int) (ChartOptionsPreviewPanel.this.getPreferredSize() .getHeight() / 2 - height / 2); color = new Color(140, 182, 206); } void paintMe(Graphics g) { g.setColor(color); g.fillRect(x, y, width, height); g.setColor(Color.BLACK); g.drawRect(x, y, width, height); } } private static class Text { static final Font FONT = Fonts.PREVIEW_BAR_FONT; static final int LEFT = 0; static final int RIGHT = 1; static final int UP = 2; static final int DOWN = 3; static final int MARGIN = 3; String text = ""; int position; private int x, y; TaskBar taskBar; Text(int position, TaskBar refBar) { this.position = position; this.taskBar = refBar; } void paintMe(Graphics g) { calculateCoordinates(g); g.setFont(FONT); g.drawString(text, x, y); } private void calculateCoordinates(Graphics g) { int textHeight = g.getFontMetrics(FONT).getHeight(); int textWidth = g.getFontMetrics(FONT).stringWidth(text); switch (position) { case UP: y = taskBar.y - MARGIN; x = taskBar.x + taskBar.width / 2 - textWidth / 2; break; case DOWN: x = taskBar.x + taskBar.width / 2 - textWidth / 2; y = taskBar.y + taskBar.height + textHeight - MARGIN; break; case LEFT: y = taskBar.y + taskBar.height / 2 + textHeight / 2 - MARGIN; x = taskBar.x - MARGIN - textWidth; break; case RIGHT: y = taskBar.y + taskBar.height / 2 + textHeight / 2 - MARGIN; x = taskBar.x + taskBar.width + MARGIN; break; } } } } public void appendBlankRow() { tree.addBlankLine(null, -1); } public void projectModified() { // TODO Auto-generated method stub } public void projectSaved() { // TODO Auto-generated method stub } public void projectClosed() { repaint(); setProjectLevelTaskColor(null); setPreviousStateTasks(null); } @Override public ChartViewState getViewState() { return myViewState; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -