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

📄 diagrameditpart.java

📁 mywork是rcp开发的很好的例子
💻 JAVA
字号:
/******************************************************************************* * Copyright (c) 2004, 2005 Elias Volanakis and others.�* All rights reserved. This program and the accompanying materials�* are made available under the terms of the Eclipse Public License v1.0�* which accompanies this distribution, and is available at�* http://www.eclipse.org/legal/epl-v10.html�*�* Contributors:�*����Elias Volanakis - initial API and implementation�*******************************************************************************/package net.sf.freenote.parts;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.List;import net.sf.freenote.FreeNoteConstants;import net.sf.freenote.model.ModelElement;import net.sf.freenote.model.ShapesDiagram;import org.eclipse.draw2d.ConnectionLayer;import org.eclipse.draw2d.Figure;import org.eclipse.draw2d.FreeformLayer;import org.eclipse.draw2d.FreeformLayout;import org.eclipse.draw2d.IFigure;import org.eclipse.draw2d.MarginBorder;import org.eclipse.draw2d.ShortestPathConnectionRouter;import org.eclipse.gef.EditPolicy;import org.eclipse.gef.LayerConstants;import org.eclipse.gef.editparts.AbstractGraphicalEditPart;import org.eclipse.gef.editpolicies.RootComponentEditPolicy;/** * EditPart for the a ShapesDiagram instance. * <p>This edit part server as the main diagram container, the white area where * everything else is in. Also responsible for the container's layout (the * way the container rearanges is contents) and the container's capabilities * (edit policies). * </p> * <p>This edit part must implement the PropertyChangeListener interface,  * so it can be notified of property changes in the corresponding model element. * </p> *  * @author Elias Volanakis */public class DiagramEditPart extends AbstractGraphicalEditPart 	implements PropertyChangeListener  {/** * Upon activation, attach to the model element as a property change listener. */public void activate() {	if (!isActive()) {		super.activate();		((ModelElement) getModel()).addPropertyChangeListener(this);	}}/* (non-Javadoc) * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies() */protected void createEditPolicies() {	// disallows the removal of this edit part from its parent	installEditPolicy(EditPolicy.COMPONENT_ROLE, new RootComponentEditPolicy());	// handles constraint changes (e.g. moving and/or resizing) of model elements	// and creation of new model elements	installEditPolicy(EditPolicy.LAYOUT_ROLE,  new ShapesXYLayoutEditPolicy());	installEditPolicy(EditPolicy.CONTAINER_ROLE, new ShapesContainerEditPolicy());}/* (non-Javadoc) * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure() */protected IFigure createFigure() {	Figure f = new FreeformLayer();	f.setBorder(new MarginBorder(3));	f.setLayoutManager(new FreeformLayout());	// Create the static router for the connection layer	ConnectionLayer connLayer = (ConnectionLayer)getLayer(LayerConstants.CONNECTION_LAYER);	connLayer.setConnectionRouter(new ShortestPathConnectionRouter(f));		return f;}/** * Upon deactivation, detach from the model element as a property change listener. */public void deactivate() {	if (isActive()) {		super.deactivate();		((ModelElement) getModel()).removePropertyChangeListener(this);	}}private ShapesDiagram getCastedModel() {	return (ShapesDiagram) getModel();}/* (non-Javadoc) * @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren() */protected List getModelChildren() {	return getCastedModel().getChildren(); // return a list of shapes}/* (non-Javadoc) * @see java.beans.PropertyChangeListener#propertyChange(PropertyChangeEvent) */public void propertyChange(PropertyChangeEvent evt) {	String prop = evt.getPropertyName();	// these properties are fired when Shapes are added into or removed from 	// the ShapeDiagram instance and must cause a call of refreshChildren()	// to update the diagram's contents.	if (FreeNoteConstants.CHILD_ADDED_PROP.equals(prop)			|| FreeNoteConstants.CHILD_REMOVED_PROP.equals(prop)) {		refreshChildren();	}}}

⌨️ 快捷键说明

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