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

📄 ganttresourcepanel.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************** * HumanResourcePanel.java  -  description * ------------------- * begin                : jun 2003 * copyright            : to the world :) * 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;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.ComponentOrientation;import java.awt.Dimension;import java.awt.Point;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.AdjustmentEvent;import java.awt.event.AdjustmentListener;import java.awt.event.KeyEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.util.Calendar;import java.util.Date;import java.util.List;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.BorderFactory;import javax.swing.ImageIcon;import javax.swing.JComponent;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JPopupMenu;import javax.swing.JScrollBar;import javax.swing.JScrollPane;import javax.swing.JSplitPane;import javax.swing.KeyStroke;import javax.swing.ListSelectionModel;import javax.swing.border.EtchedBorder;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.TreePath;//import net.sourceforge.ganttproject.GanttChartTabContentPanel.CustomScrollPane;//import net.sourceforge.ganttproject.GanttChartTabContentPanel.CustomScrollPane.CustomViewport;import net.sourceforge.ganttproject.action.DeleteAssignmentAction;import net.sourceforge.ganttproject.action.GPAction;import net.sourceforge.ganttproject.action.ResourceActionSet;import net.sourceforge.ganttproject.action.resource.ResourcePropertiesAction;import net.sourceforge.ganttproject.gui.GanttDialogInfo;import net.sourceforge.ganttproject.gui.ResourceTreeUIFacade;import net.sourceforge.ganttproject.gui.UIFacade;import net.sourceforge.ganttproject.gui.zoom.ZoomEvent;import net.sourceforge.ganttproject.gui.zoom.ZoomListener;import net.sourceforge.ganttproject.language.GanttLanguage;import net.sourceforge.ganttproject.resource.AssignmentContext;import net.sourceforge.ganttproject.resource.AssignmentNode;import net.sourceforge.ganttproject.resource.HumanResource;import net.sourceforge.ganttproject.resource.HumanResourceManager;import net.sourceforge.ganttproject.resource.ProjectResource;import net.sourceforge.ganttproject.resource.ResourceContext;import net.sourceforge.ganttproject.resource.ResourceEvent;import net.sourceforge.ganttproject.resource.ResourceNode;import net.sourceforge.ganttproject.resource.ResourceView;import net.sourceforge.ganttproject.task.ResourceAssignment;import net.sourceforge.ganttproject.task.Task;import net.sourceforge.ganttproject.task.TaskNode;import net.sourceforge.ganttproject.util.BrowserControl;public class GanttResourcePanel extends JPanel implements ResourceView,        ResourceContext, AssignmentContext, ProjectEventListener, ResourceTreeUIFacade, ZoomListener {    private final ResourceTreeTableModel model;    private final ResourceTreeTable table;    public final GanttProject appli;    private GanttLanguage lang = GanttLanguage.getInstance();    private JScrollBar vbar;    private ResourceActionSet myResourceActionSet;    public ResourceLoadGraphicArea area;    private JScrollPane scrollpane;    private JPanel left;    private JPanel myImagePanel;    private final ResourceContext myContext = (ResourceContext) this;    private JSplitPane mySplitPane = null;        private CustomScrollPane scrollPane2;    private ProjectResource [] clipboard = null;    private boolean isCut = false;        private final GPAction myMoveUpAction = new GPAction() {        protected String getIconFilePrefix() {            return "up_";        }        public void actionPerformed(ActionEvent e) {            upResource();        }        protected String getLocalizedName() {            return getI18n("upTask");        }            };        private GPAction myMoveDownAction = new GPAction() {        protected String getIconFilePrefix() {            return "down_";        }        public void actionPerformed(ActionEvent e) {            downResource();        }        protected String getLocalizedName() {            return getI18n("downTask");        }            };    /**     *      * The pane contains the chart in its viewPort and      * a custom scroll bar     *      */        	    class CustomScrollPane extends JPanel {    	protected JScrollBar m_horzSB;    	protected CustomViewport m_viewport;    	protected JComponent m_comp;    	protected Dimension layoutSize;    	protected AdjustmentListener scroll;		protected Date startProjectDate = null;		protected Date startFrameDate = null;		protected Date endFrameDate = null;		protected Date endProjectDate = null;    	protected int xPosition = 0 ;    	protected int mini = 0;		    	public JScrollBar getHorzSB(){    		return m_horzSB;    	}    	public AdjustmentListener getAdjustmentListener(){    		return scroll;    	}    	/**     	 * Short description of what the constructor is doing    	 *    	 * @param comp    this is the chart    	 *     	 *  it fills he viewPort, the scrollbar and an     	 *  adjustment listener.    	 */  	    	public CustomScrollPane(JComponent comp){    		if (comp == null){    			throw new IllegalArgumentException("Component cannot be null");    		}    		setLayout(null);    		m_viewport = new CustomViewport();    		m_viewport.setLayout(null);    		add(m_viewport);    		m_comp = comp;    		m_viewport.add(m_comp);    		    		m_horzSB = new JScrollBar(JScrollBar.HORIZONTAL,mini,170,0,200);    		m_horzSB.setUnitIncrement(5);    		add(m_horzSB);    		scroll = new AdjustmentListener() {    			public void adjustmentValueChanged(AdjustmentEvent e){	    			setChartDateFromBlockPosition();	    			unlimitedScrolling();    	    		    	    		    			}    		};    		m_horzSB.addAdjustmentListener(scroll);    		    	}    	/**     	 *     	 * enables the block(scrolling) not to stop    	 * at the end and at the start of the scrollbar.     	 *     	 *     	 */    	public void unlimitedScrolling(){    		if(xPosition <= m_horzSB.getMinimum()){		         	    getHorzSB()        	    	.removeAdjustmentListener(scroll);        		        			m_horzSB.setMinimum(m_horzSB.getMinimum()- 10);        		getHorzSB()        	       .addAdjustmentListener(scroll);        	    xPosition=m_horzSB.getValue();        	}    		else if(xPosition >= m_horzSB.getMaximum() - m_horzSB.getVisibleAmount()){		         	    getHorzSB()    	    		.removeAdjustmentListener(scroll);    		    			m_horzSB.setMaximum(m_horzSB.getMaximum() + 10);    			    			getHorzSB()    	        	.addAdjustmentListener(scroll);    			xPosition=m_horzSB.getValue();    		}    		    	}    	    	    	    	/**     	 *     	 * It sets the scrollbar block position from    	 *  the starting date of the frame.    	 *     	 *     	 */    	 void setBlockFromChart(){    		    		long startFrameTime = Mediator.getGanttProjectSingleton().getArea().getChartModel().getStartDate().getTime();    		long startProjectTime = startProjectDate.getTime();    	    getHorzSB()    		.removeAdjustmentListener(scroll);    	    if (startFrameTime<startProjectTime)	    		m_horzSB.setValue(m_horzSB.getMinimum());    	    else    	    	m_horzSB.setValue((int)Math.abs((startFrameTime-startProjectTime)/3600000));		 			getHorzSB()        	.addAdjustmentListener(scroll);    	}    	    	/**     	 *     	 * It sets the starting date of the the frame    	 * from the clock position    	 *     	 *     	 */   	    	private void setChartDateFromBlockPosition(){    		// project length    		int xTemp = m_horzSB.getValue();    		    		    		endProjectDate = Mediator.getGanttProjectSingleton().getTaskManager().getProjectEnd();    		double endProjectTime = endProjectDate.getTime();    		startProjectDate = Mediator.getGanttProjectSingleton().getTaskManager().getProjectStart();    		double startProjectTime = startProjectDate.getTime();    		double relativeEndOfProject;    		int lgth = Mediator.getTaskManager().getTaskCount();    		if(lgth == 0 ){// no tasks    			relativeEndOfProject = 2880;    		}    		else{    			relativeEndOfProject = (endProjectTime  - startProjectTime  ) /3600000.0 *1.09; // hours    		}    		    		// scrollbar length    		float scrollLength = m_horzSB.getWidth();    	    		double bottomUnitWidth = (double)Mediator.getGanttProjectSingleton().getZoomManager().getZoomState().getBottomUnitWidth();    		int zoom = Mediator.getGanttProjectSingleton().getZoomManager().getMyZooming();    		double CONVERT;    		if (zoom>2)    			CONVERT = bottomUnitWidth/(24.0 * 7.0) ; // 24 hours ==> pix / hour    		else    			CONVERT = 26.0 / 24.0 ;    			    			    			    		double scrollHours =  scrollLength / CONVERT;  // hours    		long blockLength = Math.round(scrollHours);    		    		if (blockLength > relativeEndOfProject){    			relativeEndOfProject = blockLength * 3 ;	    		}    		m_horzSB.setValues(m_horzSB.getValue(),(int) blockLength,0, (int) relativeEndOfProject);    		double x;    		x = m_horzSB.getValue();    		if(xPosition>xTemp  ){//left scrolling    		    		long time = Math.round(startProjectTime + x /CONVERT * 3600000);    		Date blockDate = new Date();    		blockDate.setTime(time);     		Mediator.getGanttProjectSingleton().getScrollingManager().scrollLeft(blockDate);    		}    		else if (xPosition<xTemp ){        		long time = Math.round(startProjectTime + m_horzSB.getValue() /CONVERT * 3600000) + blockLength/2 * 3600000;        		Date blockDate = new Date();        		blockDate.setTime(time);        		        		Mediator.getGanttProjectSingleton().getScrollingManager().scrollLeft(blockDate);    		}    		xPosition = m_horzSB.getValue();    	}    	/**     	 *     	 *     	 * initialize the layout, viewPort, scrollbar.    	 *     	 *     	 */   	    	public void doLayout() {    		layoutSize = getSize();    		Dimension d0 = m_comp.getPreferredSize();    		Dimension d2 = m_horzSB.getPreferredSize();    		int h = Math.max(layoutSize.height - d2.height-1, 0);    		m_viewport.setBounds(0, 0, layoutSize.width+100, h);    		m_horzSB.setBounds(0, h, layoutSize.width, d2.height);    		m_horzSB.setEnabled(true);    		setChartDateFromBlockPosition();    	}    	/**     	 *     	 * bounds of the custom view port    	 *     	 *     	 */    	class CustomViewport extends JPanel {    		public void doLayout(){   	    			m_comp.setBounds(0, 0, layoutSize.width, layoutSize.height);    		}    	}    }    private GPAction myPropertiesAction = new GPAction() {        protected String getIconFilePrefix() {            return "";        }        public void actionPerformed(ActionEvent e) {        	DefaultMutableTreeNode[] selectedNodes = table.getSelectedNodes();        	if (selectedNodes.length!=1) {        		return;        	}        	if (selectedNodes[0] instanceof ResourceNode) {        		getResourcePropertiesAction().actionPerformed(null);        	}        	else if (selectedNodes[0] instanceof AssignmentNode) {        		AssignmentNode assignmentNode = (AssignmentNode) selectedNodes[0];        		Mediator.getTaskSelectionManager().clear();        		Mediator.getTaskSelectionManager().addTask(assignmentNode.getTask());        		getTaskPropertiesAction().actionPerformed(null);        	}        }        protected String getLocalizedName() {            return "";        }            	    };	private final ListSelectionListener myContextListener;	private final ResourcePropertiesAction myResourcePropertiesAction;	private Action myTaskPropertiesAction;	private final UIFacade myUIFacade;	private final DeleteAssignmentAction myDeleteAssignmentAction;        public GanttResourcePanel(final GanttProject prj, GanttTree2 tree, UIFacade uiFacade) {        super();        myUIFacade = uiFacade;        myDeleteAssignmentAction = new DeleteAssignmentAction(                prj.getProject().getHumanResourceManager(),                (AssignmentContext)this, prj);                prj.addProjectEventListener(this);        appli = prj;        model = new ResourceTreeTableModel(appli.getHumanResourceManager());        table = new ResourceTreeTable(model);        setLayout(new BorderLayout());        GanttImagePanel but = new GanttImagePanel("big.png", 300, 42);        myImagePanel = but;        left = new JPanel(new BorderLayout());        table.setRowHeight(20);        left.add(but, "North");        left.setBackground(new Color(102, 153, 153));                scrollpane = new JScrollPane();        setLayout(new BorderLayout());        add(scrollpane, BorderLayout.CENTER);        scrollpane.getViewport().add(table);        scrollpane                .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);        vbar = table.getVerticalScrollBar();        final JPanel jp = new JPanel(new BorderLayout());        jp.add(vbar, BorderLayout.CENTER);        // jp.setBorder(BorderFactory.createEmptyBorder(2,1,2,0));        // jp.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));        jp.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));        jp.setVisible(false);        vbar.addAdjustmentListener(new AdjustmentListener() {            public void adjustmentValueChanged(AdjustmentEvent e) {                if (table.getSize().getHeight() - 20 < e.getAdjustable()                        .getMaximum())                    jp.setVisible(true);                else                    jp.setVisible(false);                repaint();            }        });        left.add(jp, BorderLayout.WEST);                                vbar.addAdjustmentListener(new GanttAdjustmentListener());        left.add(scrollpane, "Center");        // A splitpane is use        mySplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);        area = new ResourceLoadGraphicArea(prj, prj                .getZoomManager()) {            protected int getHeaderHeight() {                return myImagePanel.getHeight()                        + table.getTable().getTableHeader().getHeight();            }            public boolean isExpanded(ProjectResource pr) {                return getResourceTreeTable().isExpanded(pr);            }                        protected int getRowHeight(){            	return table.getRowHeight();            }        };        prj.getZoomManager().addZoomListener(area.getZoomListener());        area.getChartModel().setRowHeight(table.getRowHeight());                JPanel right =  new JPanel(new BorderLayout());        scrollPane2 = new CustomScrollPane(area);   

⌨️ 快捷键说明

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