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

📄 resourcestable.java

📁 Owing to the applet Gantt chart source yard, already Chinese melt, Gantt chart can demonstrate a Chi
💻 JAVA
字号:
/** *   Copyright 2004 Carlos Silva A. *  *   Licensed under the Apache License, Version 2.0 (the "License"); *   you may not use this file except in compliance with the License.  *   You may obtain a copy of the License at   *  *   http://www.apache.org/licenses/LICENSE-2.0 *  *   Unless required by applicable law or agreed to in writing, software *   distributed under the License is distributed on an "AS IS" BASIS, *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *   See the License for the specific language governing permissions and *   limitations under the License. *  */package jgantt.view.dialogs;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.Graphics;import java.awt.Rectangle;import java.awt.Toolkit;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.StringSelection;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Date;import java.util.Vector;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.event.TableModelListener;import javax.swing.table.TableCellRenderer;import javax.swing.table.TableModel;import jgantt.Messages;import jgantt.model.Resource;import jgantt.model.Task;import jgantt.view.adapters.ProjectViewModel;/** * Resources *  * TODO: redefinir Ctrl+C para copiar las filas seleccionadas al clipboard  * <p>$Date: 2005/03/25 14:58:31 $</p>  * @version $Revision: 1.9 $ * @author Carlos Silva */public class ResourcesTable extends JPanel {	private static final long serialVersionUID = 4048796775194309688L;	ResourceModel resModel;	/**	 * Constructor for TaskEditor	 */	public ResourcesTable(ProjectViewModel model) {		super();		resModel = new ResourceModel(model);		JTable jtable =new JTable(resModel);		JScrollPane js=new JScrollPane(jtable);				GraphRenderer graphRenderer = new GraphRenderer(model);		jtable.setDefaultRenderer(Resource.class, graphRenderer);		jtable.getColumnModel().getColumn(0).setMinWidth(50);		jtable.getColumnModel().getColumn(1).setMinWidth(50);		jtable.getColumnModel().getColumn(2).setMinWidth(150);		jtable.getColumnModel().getColumn(3).setMinWidth(50);		jtable.getColumnModel().getColumn(4).setMinWidth(50);		jtable.getColumnModel().getColumn(5).setMinWidth(70);				jtable.getColumnModel().getColumn(0).setMaxWidth(70);		jtable.getColumnModel().getColumn(1).setMaxWidth(70);		jtable.getColumnModel().getColumn(2).setWidth(250);		jtable.getColumnModel().getColumn(3).setMaxWidth(70);		jtable.getColumnModel().getColumn(4).setMaxWidth(70);				JButton jb = new JButton(Messages.getString("ResourcesTable.clipboard.button")); //$NON-NLS-1$		jb.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent ev) {				copyClipboard();			}		});		setLayout(new BorderLayout());		add(jb, BorderLayout.SOUTH);		add(js, BorderLayout.CENTER);	}	void copyClipboard(){		//System.out.println("ResourcesTable.copyClipboard()");		//resModel.data;		StringBuffer sb = new StringBuffer();		for (int j=0;j<resModel.cn.length-1;j++){ // no incluye el grafico			sb.append(resModel.cn[j]);			sb.append('\t');						}		sb.append('\n');		for (int i=0;i<resModel.data.length;i++){			for (int j=0;j<resModel.data[i].length-1;j++){ // no incluye el grafico				sb.append(resModel.data[i][j]);				sb.append('\t');							}			sb.append('\n');		}		StringSelection stringSelection = new StringSelection( sb.toString() );		Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();		clipboard.setContents( stringSelection, null);	}		static class GraphRenderer extends JComponent implements TableCellRenderer{				private static final long serialVersionUID = 3258125851919856178L;		public GraphRenderer(ProjectViewModel pvm){			super();		}		public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)  {			bs = (int []) value;			return this;					}		int bs[];		public void paintComponent(Graphics g ){			Rectangle r = getBounds();			int mult = r.width / bs.length;						//g.setColor(Color.black);			//g.fillRect(0,0,bs.length*mult+1,r.height);			//g.setXORMode(Color.red);						g.setColor(new Color(255,192,192));			g.fillRect(0,0,bs.length*mult+1,r.height*4/10);						//g.setXORMode(Color.green);			g.setColor(new Color(192,255,192));			g.fillRect(0,r.height*4/10,bs.length*mult+1,r.height*6/10);						//g.setXORMode(Color.yellow);			g.setColor(new Color(192,192,255));						g.fillRect(0,1+r.height*6/10,bs.length*mult+1,r.height);																		// todo es blanco			g.setColor(Color.black);			int _h=-1;			for(int i =0;i<bs.length;i++){				int h = (bs[i]*r.height)/200;				if (_h>=0) { 													g.drawLine((i-1)*mult,r.height-_h-2, i*mult, r.height-h-2);					//g.fillRect((i-1)*mult,r.height-h-2, mult, h);														}				_h=h;			} 			// colocar una mascara de color...																				}	}		static class ResourceModel implements TableModel {		String cn[]={Messages.getString("ResourcesTable.col.alias"),Messages.getString("ResourcesTable.col.initials"),Messages.getString("ResourcesTable.col.name"),Messages.getString("ResourcesTable.col.total"),Messages.getString("ResourcesTable.col.used"),Messages.getString("ResourcesTable.col.use")}; 		Object [][]data;		ProjectViewModel pvm;		public ResourceModel(ProjectViewModel model){			pvm=model;			Vector v = model.getProject().getResources();			data=new Object[v.size()][6];			for(int i=0;i<v.size();i++){				Resource r = (Resource) v.get(i);				data[i][0]=r.getAlias();				data[i][1]=r.getInitials();				data[i][2]=r.getName();				data[i][3]=""+(model.getProject().getMainTask().getTotalResourceUnits(r)/6)/10.0;				data[i][4]=""+(model.getProject().getMainTask().getWorkedResourceUnits(r)/6)/10.0;				data[i][5]=generateResourceValues(r);			}		}				int[] generateResourceValues(Resource r){			Date ds=pvm.getProject().getMainTask().getStartDate();			Date df=pvm.getProject().getMainTask().getFinishDate();			long ini0=pvm.getProject().getMainTask().getStartDate().getTime();			long fin0=pvm.getProject().getMainTask().getFinishDate().getTime();			int len = (int)((fin0-ini0)/(1000*60*60*24));			int d[]=new int[len+1];						for(int i=0;i<len;i++) 				d[i]=0;							for(int i=0;i<pvm.getProject().getTaskCount();i++){				Task t =pvm.getProject().getTask(i);				long ini=t.getStartDate().getTime();				long fin=t.getFinishDate().getTime();				int i0 = (int)((ini-ini0)/(1000*60*60*24));				int j0 = (int)((fin-ini0)/(1000*60*60*24));				int units = t.getAsignationUnits(r);				//System.out.println("R="+r.getAlias());				for (int j=i0; j<=j0; j++){					d[j]+=units; //porcentaje de uso del recurso					//System.out.println("d["+j+"]+="+units);									}			}			// TODO: Descartar festivos y feriados 			return d;		}		 		public void addTableModelListener(TableModelListener arg0) {		}		public Class getColumnClass(int i) {			if (i==5) return Resource.class;			return String.class;					}		public int getColumnCount() {			return 6;		}		public String getColumnName(int c) {			return cn[c];		}		public int getRowCount() {			return data.length;		}		public Object getValueAt(int i, int j) {			return data[i][j];		}		public boolean isCellEditable(int arg0, int arg1) {			return false;		}		public void removeTableModelListener(TableModelListener arg0) {		}		public void setValueAt(Object arg0, int arg1, int arg2) {		}	}}

⌨️ 快捷键说明

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