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

📄 ganttdisplay.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;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Font;import java.awt.Image;import java.awt.Insets;import java.awt.MediaTracker;import java.awt.Toolkit;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.net.URL;import java.util.Iterator;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JPanel;import javax.swing.JSplitPane;import jgantt.Messages;import jgantt.model.Project;import jgantt.model.ProjectChange;import jgantt.model.ProjectListener;import jgantt.view.adapters.ProjectViewModel;import jgantt.view.adapters.ProjectViewModelChange;import jgantt.view.adapters.ProjectViewModelListener;import jgantt.view.gantt.GanttGraph;import jgantt.view.tree.TaskTree;public class GanttDisplay extends JPanel implements ProjectListener,		ProjectViewModelListener {	private static final long serialVersionUID = 3257283630241165369L;	TaskTree tasksTree;	GanttGraph ganttGraph;	JComboBox snapShotList;	public ProjectViewModel pvModel;	public Project project;	public boolean isFocusTraversable() {		return false;	}	/**	 * Constructor for GanttDisplay	 */	public GanttDisplay(ProjectViewModel projectViewModel) {		super();		pvModel = projectViewModel;		pvModel.addListener(this);		setLayout(new BorderLayout());		tasksTree = new TaskTree(pvModel);		ganttGraph = new GanttGraph(pvModel);		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,				tasksTree, ganttGraph);		// splitPane.setDividerSize(12);		splitPane.setOneTouchExpandable(true);		splitPane.setDividerLocation(280);		add(splitPane, BorderLayout.CENTER);		JPanel buttonPane = new JPanel();		buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));		buttonPane.add(createButton(null, GanttActionListener.CMD_NEW, Messages				.getString("GanttDisplay.newproject.hint"), Messages				.getString("GanttDisplay.newproject.img")));		buttonPane.add(createButton(null, GanttActionListener.CMD_OPEN,				Messages.getString("GanttDisplay.open.hint"), Messages						.getString("GanttDisplay.open.img")));		buttonPane.add(Box.createRigidArea(new Dimension(10, 10)));		buttonPane.add(createButton(null, GanttActionListener.CMD_SAVE,				Messages.getString("GanttDisplay.save.hint"), Messages						.getString("GanttDisplay.save.img")));		buttonPane.add(createButton(null, GanttActionListener.CMD_SAVE_AS,				Messages.getString("GanttDisplay.saveas.hint"), Messages						.getString("GanttDisplay.saveas.img")));		buttonPane.add(Box.createRigidArea(new Dimension(10, 10)));		buttonPane.add(createButton(null, GanttActionListener.CMD_INSERT_TASK,				Messages.getString("GanttDisplay.insert.hint"), Messages						.getString("GanttDisplay.insert.img")));		buttonPane.add(createButton(null, GanttActionListener.CMD_APPEND_TASK,				Messages.getString("GanttDisplay.append.hint"), Messages						.getString("GanttDisplay.append.img")));		buttonPane.add(createButton(null, GanttActionListener.CMD_DELETE_TASK,				Messages.getString("GanttDisplay.delete.hint"), Messages						.getString("GanttDisplay.delete.img")));		buttonPane.add(Box.createRigidArea(new Dimension(10, 10)));		buttonPane.add(createButton(null, "indentl", Messages				.getString("GanttDisplay.indentLeft.hint"), Messages				.getString("GanttDisplay.indentLeft.img")));		buttonPane.add(createButton(null, "indentr", Messages				.getString("GanttDisplay.indentRight.hint"), Messages				.getString("GanttDisplay.indentRight.img")));		buttonPane.add(Box.createRigidArea(new Dimension(5, 5)));		buttonPane.add(createButton(null, "movedn", Messages				.getString("GanttDisplay.moveDown.hint"), Messages				.getString("GanttDisplay.moveDown.img")));		buttonPane.add(createButton(null, "moveup", Messages				.getString("GanttDisplay.moveUp.hint"), Messages				.getString("GanttDisplay.moveUp.img")));		buttonPane.add(Box.createRigidArea(new Dimension(5, 5)));		buttonPane.add(createButton(null,				GanttActionListener.CMD_EDIT_ASIGNATIONS, Messages						.getString("GanttDisplay.asignments.hint"), Messages						.getString("GanttDisplay.asignments.img")));		snapShotList = new JComboBox();		snapShotList.addItemListener(new SnapItemListener());		snapShotList.setFont(new java.awt.Font("宋体", Font.BOLD, 14)); 		buttonPane.add(snapShotList);				add(buttonPane, BorderLayout.NORTH);		assignViewModel(pvModel);	}	/**	 * Genera un boton para ser anexado al panel	 * 	 * @param label	 * @param action	 * @param tooltip	 * @param imgFn	 * @return	 */	public JButton createButton(String label, String action, String tooltip,			String imgFn) {		try {			URL res = getClass().getClassLoader().getResource(imgFn);			Image img = Toolkit.getDefaultToolkit().getImage(res);			MediaTracker m = new MediaTracker(this);			m.addImage(img, 0);			m.waitForAll();			ImageIcon icon = new ImageIcon(img);			JButton b = new JButton(label, icon);			b.setActionCommand(action);			b.setToolTipText(tooltip);			// b.setContentAreaFilled(false);			b.setMargin(new Insets(0, 0, 0, 0));			// Dimension d = new Dimension(26,26);			// b.setPreferredSize(d);			// b.setSize(d);			// b.setMinimumSize(d);			b.addActionListener(pvModel.getMainActionListener());			return b;		} catch (Exception e) {			e.printStackTrace();			JButton b = new JButton(label);			b.setActionCommand(action);			b.setToolTipText(tooltip);			b.setContentAreaFilled(false);			b.setMargin(new Insets(0, 0, 0, 0));			b.addActionListener(pvModel.getMainActionListener());			return b;		}	}	/**	 * Carga una imagen desde el paquete de la clase	 * 	 * @param imgName	 * @return Image	 */	Image loadImage(String imgName) {		URL imgURL = getClass().getResource(imgName);		Toolkit tk = Toolkit.getDefaultToolkit();		Image img = null;		try {			MediaTracker m = new MediaTracker(this);			img = tk.getImage(imgURL);			m.addImage(img, 0);			m.waitForAll();		} catch (Exception e) {			e.printStackTrace();		}		return img;	}	public JComponent getTaskTree() {		return tasksTree;	}	public ProjectViewModel getProjectViewModel() {		return pvModel;	}	public Object getSelectedObject() {		return ganttGraph.getViewer().lastSelectedObject();	}	/*	 * (non-Javadoc)	 * 	 * @see jgantt.view.adapters.ProjectViewModelListener#viewModelChanged(jgantt.view.adapters.ProjectViewModelChange)	 */	public void viewModelChanged(ProjectViewModelChange c) {		if (c.getId() == ProjectViewModelChange.NEW_PROJECT_LOADED)			assignViewModel(c.getProjectViewModel());	}	public void assignViewModel(ProjectViewModel pvm) {		if (project != null)			project.removeListener(this);		project = pvm.getProject();		project.addListener(this);		pvModel = pvm;		loadSnapShots(pvm.getProject());	}	public void loadSnapShots(Project p) {		snapShotList.removeAllItems();		snapShotList.addItem("Snapshot");		for (Iterator i = p.getSnapshots().iterator(); i.hasNext();) {			Project.SnapShot ss = (Project.SnapShot) i.next();			snapShotList.addItem(ss);		}	}	class SnapItemListener implements ItemListener {		public void itemStateChanged(ItemEvent ev) {			if (ev.getStateChange() == ItemEvent.SELECTED) {				Object item = ev.getItem();				if (item instanceof String)					pvModel.setCurrentSnapShot(null);				else {					Project.SnapShot ss = (Project.SnapShot) item;					pvModel.setCurrentSnapShot(ss.date);				}			}		}	}	public void projectChanged(ProjectChange change) {		switch (change.getId()) {		case ProjectChange.SNAPSHOT_ADDED:		case ProjectChange.SNAPSHOT_REMOVED:			loadSnapShots(pvModel.getProject());			break;		default:			;		}	}}

⌨️ 快捷键说明

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