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

📄 ganttresourcepanel.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        setLayout(new BorderLayout());        add(scrollPane2, BorderLayout.CENTER);        right.add(scrollPane2, "Center");           if (lang.getComponentOrientation() == ComponentOrientation.LEFT_TO_RIGHT) {            mySplitPane.setLeftComponent(left);              mySplitPane.setRightComponent(right);        } else {            mySplitPane.setRightComponent(left);            mySplitPane.setLeftComponent(right);            mySplitPane.setDividerLocation((int) (Toolkit.getDefaultToolkit()                    .getScreenSize().getWidth() - left.getPreferredSize()                    .getWidth()));        }        mySplitPane.setOneTouchExpandable(true);        mySplitPane.setPreferredSize(new Dimension(800, 500));        add(mySplitPane, BorderLayout.CENTER);        scrollpane.getViewport().setBackground(new Color(1.0f, 1.0f, 1.0f));        left.setBackground(new Color(1.0f, 1.0f, 1.0f));        table.setBackground(new Color(1.0f, 1.0f, 1.0f));        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        this.setBackground(new Color(0.0f, 0.0f, 0.0f));        applyComponentOrientation(lang.getComponentOrientation());        table.addKeyListener(prj); // callback for keyboard pressed        // Add listener for mouse click        MouseListener ml = new MouseAdapter() {            public void mousePressed(MouseEvent e) {                handlePopupTrigger(e);            }            public void mouseReleased(MouseEvent e) {                handlePopupTrigger(e);            }            public void mouseClicked(MouseEvent e) {                e.consume();                                TreePath selPath = table.getTreeTable().getPathForLocation(                        e.getX(), e.getY());                if (selPath != null) {                    table.getTreeTable().getTree().setSelectionPath(selPath);                }                if (e.getClickCount()==2 && e.getButton()==MouseEvent.BUTTON1) {                	handleDoubleClick(e);                }                else {                    handlePopupTrigger(e);                }            }        };        table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.ALT_DOWN_MASK), "properties");        table.getActionMap().put("properties", myPropertiesAction);        table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete");        table.getActionMap().put("delete", myDeleteAssignmentAction);        table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(GPAction.getKeyStroke("newArtifact.shortcut")                , "newHuman");        table.getActionMap().put("newHuman", new AbstractAction() {			public void actionPerformed(ActionEvent e) {				prj.newHumanResource();			}        });        if (!prj.isOnlyViewer) {            table.addMouseListener(ml);            table.getTreeTable().getParent().addMouseListener(ml);        }        myResourcePropertiesAction = new ResourcePropertiesAction(prj.getProject(), prj.getUIFacade());         myContextListener = new ListSelectionListener() {			public void valueChanged(ListSelectionEvent e) {				myResourcePropertiesAction.setContext(getContext());			}        };        table.getTable().getSelectionModel().addListSelectionListener(myContextListener);    }    public void setActions()    {    	table.setAction(appli.getCopyAction());        table.setAction(appli.getPasteAction());        table.setAction(appli.getCutAction());    }        private void handlePopupTrigger(MouseEvent e) {        if (e.isPopupTrigger() || e.getButton()==MouseEvent.BUTTON3) {        	DefaultMutableTreeNode[] selectedNodes = table.getSelectedNodes();        	if (selectedNodes.length==0) {        		return;        	}        	if (selectedNodes.length==1 && selectedNodes[0] instanceof AssignmentNode) {        		AssignmentNode assignmentNode = (AssignmentNode) selectedNodes[0];        		Mediator.getTaskSelectionManager().clear();        		Mediator.getTaskSelectionManager().addTask(assignmentNode.getTask());        		Point popupPoint = getPopupMenuPoint(e);        		getUIFacade().showPopupMenu(this, new Action[] {getTaskPropertiesAction(), myDeleteAssignmentAction}, popupPoint.x, popupPoint.y);        	}        	else {        		createPopupMenu(e);        	}        }    	    }        private void handleDoubleClick(MouseEvent e) {    	myPropertiesAction.actionPerformed(null);    }    private Point getPopupMenuPoint(MouseEvent popupTriggerEvent) {    	final int x = popupTriggerEvent.getX() - scrollpane.getHorizontalScrollBar().getValue()        + (vbar.isVisible() ? vbar.getWidth() : 0);    	final int y = popupTriggerEvent.getY() + table.getRowHeight() +        + myImagePanel.getHeight();    	return new Point(x,y);    }    /* Create the popup menu */    private void createPopupMenu(MouseEvent e) {        JPopupMenu menu = new JPopupMenu();        AbstractAction[] resourceActions = myResourceActionSet.getActions();        menu.add(myResourcePropertiesAction);        for (int i = 0; i < resourceActions.length; i++) {            menu.add(resourceActions[i]);        }        menu.add(appli.createNewItem(GanttProject.correctLabel(lang                .getText("sendMail")), "/icons/send_mail_16.gif"));        menu.addSeparator();        menu.add(myMoveUpAction);        menu.add(myMoveDownAction);        menu.addSeparator();        menu.add(appli.getCutAction());        menu.add(appli.getCopyAction());        menu.add(appli.getPasteAction());        menu.applyComponentOrientation(lang.getComponentOrientation());        Point popupPoint = getPopupMenuPoint(e);        menu.show(this, popupPoint.x, popupPoint.y);    }    /** Function called when the language is changed */    public void refresh(GanttLanguage language) {        lang = language;        model.changeLanguage(lang);    }    public void resourceAdded(ResourceEvent event) {        newHuman((HumanResource) event.getResource());    }    public void resourcesRemoved(ResourceEvent event) {        model.deleteResources(event.getResources());    }        public void resourceChanged(ResourceEvent e) {    	model.resourceChanged(e.getResource());    	repaint();    }    public void resourceAssignmentsChanged(ResourceEvent e) {        model.resourceAssignmentsChanged(e.getResources());    }            // //////////////////////////////////////////////////////////////////////////    // ResourceContext interface    public ProjectResource[] getResources() {        // ProjectResource[] res;        // List allRes = model.getAllResouces();        // res = new ProjectResource[allRes.size()];        // model.getAllResouces().toArray(res);        // return res;        ProjectResource[] res;        DefaultMutableTreeNode[] tNodes = table.getSelectedNodes();        if (tNodes==null) {        	return new ProjectResource[0];        }        int nbProjectResource = 0;        for (int i = 0; i < tNodes.length; i++)            if (tNodes[i] instanceof ResourceNode)                nbProjectResource++;        res = new ProjectResource[nbProjectResource];        for (int i = 0; i < nbProjectResource; i++)            if (tNodes[i] instanceof ResourceNode)                res[i] = (ProjectResource) ((ResourceNode) tNodes[i])                        .getUserObject();        return res;    }    public void moveScrollBarBlockRight(){    	scrollPane2.m_horzSB.setValue(scrollPane2.m_horzSB.getValue()+1);    	    }        public void moveScrollBarBlockLeft(){    	scrollPane2.m_horzSB.setValue(scrollPane2.m_horzSB.getValue()-1);    	    }        public void setScrollBarBlockPosition(){    	float startFrameDate;    	float startProjectDate;    	float endProjectDate;		float ratio;		    	startFrameDate = Mediator.getGanttProjectSingleton().getArea().getChartModel().getStartDate().getTime();		startProjectDate = Mediator.getGanttProjectSingleton().getTaskManager().getProjectStart().getTime(); 				endProjectDate = Mediator.getGanttProjectSingleton().getTaskManager().getProjectEnd().getTime();		ratio =  (startFrameDate - startProjectDate)/ (endProjectDate - startProjectDate);				if (ratio > 0 && ratio < 1){			float wid =  scrollPane2.m_horzSB.getWidth();			int tot =  Math.round(ratio * wid );			scrollPane2.m_horzSB.setValue(tot);				}		else if (ratio <= 0){			scrollPane2.m_horzSB.setValue(0);		}		else{			scrollPane2.m_horzSB.setValue(scrollPane2.m_horzSB.getWidth());				}    }        /**     * Listener when scrollbar moves     */    public class GanttAdjustmentListener implements AdjustmentListener {        public void adjustmentValueChanged(AdjustmentEvent e) {            if (area != null) {                area.setScrollBar(e.getValue());                area.repaint();            }        }    }    /** Create a new Human */    public void newHuman(HumanResource people) {        if (people != null) {            DefaultMutableTreeNode result = model.addResource(people);            table.getTree().scrollPathToVisible(new TreePath(result.getPath()));        }    }    /** Send an Email to the current resource */    public void sendMail(GanttProject parent) {    	if(table != null && table.getSelectedNodes()!=null && table.getSelectedNodes().length>0)    	{    		HumanResource people = (HumanResource) table.getSelectedNodes()[0]                .getUserObject();    		if (people != null) {    			try {    				BrowserControl.displayURL("mailto:" + people.getMail());    			} catch (Exception e) {    				System.err.println(e);    			}    		}    	}    	else    	{    		GanttDialogInfo gdi = new GanttDialogInfo(                    appli, GanttDialogInfo.INFO,                    GanttDialogInfo.YES_OPTION, GanttLanguage.getInstance()                            .getText("msg26"),                    GanttLanguage.getInstance().getText("sendMail"));            gdi.show();    	    	}    }    /** Move up the selected resource */    private void upResource() {    	table.upResource();    }    /** Move down the selected resource */    private void downResource() {    	table.downResource();    }    /** Return the list of the person */    public List getPeople() {        return model.getAllResouces();    }    public ResourceTreeTable getResourceTreeTable() {        return table;    }    public ResourceTreeTableModel getResourceTreeTableModel() {        return model;    }    /** Return the number of people on the list */    public int nbPeople() {        return model.getAllResouces().size();    }    /** Reset all human... */    public void reset() {        model.reset();    }    public void setResourceActions(ResourceActionSet actionSet) {        myResourceActionSet = actionSet;    }    public ResourceContext getContext() {        return myContext;    }    public ResourceAssignment[] getResourceAssignments() {        ResourceAssignment[] res = null;        DefaultMutableTreeNode[] tNodes = table.getSelectedNodes();        if (tNodes != null) {            int nbAssign = 0;            for (int i = 0; i < tNodes.length; i++)                if (tNodes[i] instanceof AssignmentNode)                    nbAssign++;            res = new ResourceAssignment[nbAssign];            for (int i = 0; i < nbAssign; i++)                if (tNodes[i] instanceof AssignmentNode)                    res[i] = (ResourceAssignment) ((AssignmentNode) tNodes[i])                            .getUserObject();        }        return res;    }    public void setDividerLocation(int location) {        mySplitPane.setDividerLocation(location);    }    public int getDividerLocation() {        return mySplitPane.getDividerLocation();    }    public void projectModified() {        // TODO Auto-generated method stub            }    public void projectSaved() {        // TODO Auto-generated method stub            }    public void projectClosed() {        area.repaint();        reset();    }        public void copySelection()    {    	this.saveSelectionToClipboard(false);    	this.isCut = false;    }        public void cutSelection()    {    	this.saveSelectionToClipboard(true);    	this.isCut = true;    }        public void pasteSelection()    {    	if(this.clipboard == null)    		return;    	    	for(int i=0; i<this.clipboard.length; i++)    	{    		if(this.isCut)    		{    			this.appli.getHumanResourceManager().add(this.clipboard[i]);    		}    		else    		{    			this.appli.getHumanResourceManager().add(clipboard[i].unpluggedClone());    		}    	}    	    	/*if the selection was cut, we clear the clipboard after pasting*/    	if(this.isCut)    	{    		this.isCut = false;    	}    	model.updateResources();    }        public void saveSelectionToClipboard(boolean cut)    {    	DefaultMutableTreeNode selectedNodes[] = this.table.getSelectedNodes();    	    	if(selectedNodes == null)    		return;    		    	/*count instances of ResourceNode*/    	int count=0;    	for(int i=0; i<selectedNodes.length; i++)    	{    		if(selectedNodes[i] instanceof ResourceNode)    		{    			count++;    		}    	}    	    	this.clipboard = new ProjectResource[count];    	    	int index=0;    	for(int i=0; i<selectedNodes.length; i++)    	{    		if(selectedNodes[i] instanceof ResourceNode)    		{    			ResourceNode rn = (ResourceNode)selectedNodes[i];    			    			this.clipboard[index] = (HumanResource)rn.getUserObject();    			if(cut)    			{    				this.appli.getHumanResourceManager().remove(this.clipboard[index], this.appli.getUndoManager());    			}    			    			index++;    		}    	}    }    public Action getMoveUpAction() {        return myMoveUpAction;    }    public Action getMoveDownAction() {        return myMoveDownAction;    }    public Component getUIComponent() {        return this;    }    public CustomScrollPane getCustomScrollPane(){    	return scrollPane2;    }    public void zoomChanged(ZoomEvent e) {        getCustomScrollPane().setChartDateFromBlockPosition();    }    public Action getResourcePropertiesAction() {    	return myResourcePropertiesAction;    }        void setTaskPropertiesAction(Action action) {    	myTaskPropertiesAction = action;    }        private Action getTaskPropertiesAction() {    	return myTaskPropertiesAction;    }        private UIFacade getUIFacade() {    	return myUIFacade;    }}

⌨️ 快捷键说明

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