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

📄 connectioneditpart.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 net.sf.freenote.FreeNoteConstants;import net.sf.freenote.commands.ConnectionDeleteCommand;import net.sf.freenote.directedit.DescDirectEditPolicy;import net.sf.freenote.directedit.LabelCellEditorLocator;import net.sf.freenote.directedit.ShapeDirectEditManager;import net.sf.freenote.figure.ConnectionFigure;import net.sf.freenote.model.Connection;import net.sf.freenote.model.ModelElement;import org.eclipse.draw2d.IFigure;import org.eclipse.gef.EditPolicy;import org.eclipse.gef.Request;import org.eclipse.gef.RequestConstants;import org.eclipse.gef.commands.Command;import org.eclipse.gef.editparts.AbstractConnectionEditPart;import org.eclipse.gef.editpolicies.ConnectionEditPolicy;import org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy;import org.eclipse.gef.requests.GroupRequest;import org.eclipse.swt.graphics.Color;/** * Edit part for Connection model elements. * <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 ConnectionEditPart extends AbstractConnectionEditPart 	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() {	// Selection handle edit policy. 	// Makes the connection show a feedback, when selected by the user.	installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE,			new ConnectionEndpointEditPolicy());	// Allows the removal of the connection model element	installEditPolicy(EditPolicy.CONNECTION_ROLE, new ConnectionEditPolicy() {		protected Command getDeleteCommand(GroupRequest request) {			return new ConnectionDeleteCommand(getCastedModel());		}	});	installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new DescDirectEditPolicy());}/* (non-Javadoc) * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure() */protected IFigure createFigure() {	ConnectionFigure connection = new ConnectionFigure();	connection.setLineStyle(getCastedModel().getLineStyle());  // line drawing style	connection.setDesc(getCastedModel().getDesc());	connection.setBackgroundColor(new Color(null,getCastedModel().getBackColor()));	connection.setForegroundColor(new Color(null,getCastedModel().getForeColor()));	connection.setSourceDecoration(getCastedModel().getSourceDecoration());	connection.setTargetDecoration(getCastedModel().getTargetDecoration());	return connection;}/** * Upon deactivation, detach from the model element as a property change listener. */public void deactivate() {	if (isActive()) {		super.deactivate();		((ModelElement) getModel()).removePropertyChangeListener(this);	}}public Connection getCastedModel() {	return (Connection) getModel();}private ConnectionFigure getCastedFigure(){	return (ConnectionFigure)getFigure();}/* (non-Javadoc) * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */public void propertyChange(PropertyChangeEvent event) {	String property = event.getPropertyName();	if (Connection.LINESTYLE_PROP.equals(property)) {		getCastedFigure().setLineStyle(getCastedModel().getLineStyle());	}	if(FreeNoteConstants.DESC_PROPERTY.equals(property)){		getCastedFigure().setDesc(getCastedModel().getDesc());	}	if(FreeNoteConstants.BACKCOLOR.equals(property)){		getCastedFigure().setBackgroundColor(new Color(null,getCastedModel().getBackColor()));	}	if(FreeNoteConstants.FORECOLOR.equals(property)){		getCastedFigure().setForegroundColor(new Color(null,getCastedModel().getForeColor()));	}	if(Connection.SOURCE_DECORATION_PROP.equals(property)){		getCastedFigure().setSourceDecoration(getCastedModel().getSourceDecoration());	}	if(Connection.TARGET_DECORATION_PROP.equals(property)){		getCastedFigure().setTargetDecoration(getCastedModel().getTargetDecoration());	}}@Overridepublic void performRequest(Request req) {	if (req.getType() == RequestConstants.REQ_DIRECT_EDIT){		new ShapeDirectEditManager(this,new LabelCellEditorLocator(((ConnectionFigure) getFigure()).getDescLabel())).show();	}}}

⌨️ 快捷键说明

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