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

📄 connection.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.model;import net.sf.freenote.FreeNoteConstants;import net.sf.freenote.directedit.DirectEditable;import org.eclipse.draw2d.Graphics;import org.eclipse.swt.graphics.RGB;import org.eclipse.ui.views.properties.ColorPropertyDescriptor;import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;import org.eclipse.ui.views.properties.IPropertyDescriptor;import org.eclipse.ui.views.properties.TextPropertyDescriptor;/** * A connection between two distinct shapes. *  * @author Elias Volanakis */public class Connection extends ModelElement implements DirectEditable {	public static final String LINESTYLE_PROP = "LineStyle";	private static IPropertyDescriptor[] descriptors;	private String desc = "";	/** True, if the connection is attached to its endpoints. */	private boolean isConnected;	/** Line drawing style for this connection. */	private Integer lineStyle = Graphics.LINE_SOLID;	/** Connection's source endpoint. */	private Shape source;	/** Connection's target endpoint. */	private Shape target;	private RGB backColor = new RGB(255, 255, 255);// 前景色	private RGB foreColor = new RGB(0, 0, 0); // 背景色	private Integer sourceDecoration = 0; // 无	private Integer targetDecoration = 1; // 实心箭头	public static final String SOURCE_DECORATION_PROP="SourceDecoration";	public static final String TARGET_DECORATION_PROP="TargetDecroation";	static {		descriptors = new IPropertyDescriptor[] {				new ComboBoxPropertyDescriptor(LINESTYLE_PROP, LINESTYLE_PROP, new String[] {"无","实线","虚线" }),				new TextPropertyDescriptor(FreeNoteConstants.DESC_PROPERTY, FreeNoteConstants.DESC_PROPERTY),				new ColorPropertyDescriptor(FreeNoteConstants.BACKCOLOR, FreeNoteConstants.BACKCOLOR),				new ColorPropertyDescriptor(FreeNoteConstants.FORECOLOR, FreeNoteConstants.FORECOLOR),				new ComboBoxPropertyDescriptor(SOURCE_DECORATION_PROP, SOURCE_DECORATION_PROP,new String[]{"无","三角形","箭头","菱形","空心三角"}), 				new ComboBoxPropertyDescriptor(TARGET_DECORATION_PROP, TARGET_DECORATION_PROP,new String[]{"无","三角形","箭头","菱形","空心三角"}),				};	}	public Connection(Shape source, Shape target) {		reconnect(source, target);	}	/**	 * Disconnect this connection from the shapes it is attached to.	 */	public void disconnect() {		if (isConnected) {			source.removeConnection(this);			target.removeConnection(this);			isConnected = false;		}	}	/**	 * Returns the line drawing style of this connection.	 * 	 * @return an int value (Graphics.LINE_DASH or Graphics.LINE_SOLID)	 */	public Integer getLineStyle() {		return lineStyle.equals(new Integer(0))?new Integer(1):lineStyle;	}	/**	 * Returns the descriptor for the lineStyle property	 * 	 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()	 */	public IPropertyDescriptor[] getPropertyDescriptors() {		return descriptors;	}	/**	 * Returns the lineStyle as String for the Property Sheet	 * 	 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)	 */	public Object getPropertyValue(Object id) {		if (id.equals(LINESTYLE_PROP)) 			return getLineStyle();		if (id.equals(FreeNoteConstants.DESC_PROPERTY))			return getDesc();		if(id.equals(FreeNoteConstants.FORECOLOR))			return getForeColor();		if(id.equals(FreeNoteConstants.BACKCOLOR))			return getBackColor();		if(id.equals(SOURCE_DECORATION_PROP))			return getSourceDecoration();		if(id.equals(TARGET_DECORATION_PROP))			return getTargetDecoration();		return super.getPropertyValue(id);	}	/**	 * Returns the source endpoint of this connection.	 * 	 * @return a non-null Shape instance	 */	public Shape getSource() {		return source;	}	/**	 * Returns the target endpoint of this connection.	 * 	 * @return a non-null Shape instance	 */	public Shape getTarget() {		return target;	}	/**	 * Reconnect this connection. The connection will reconnect with the shapes	 * it was previously attached to.	 */	public void reconnect() {		if (!isConnected) {			source.addConnection(this);			target.addConnection(this);			isConnected = true;		}	}	/**	 * Reconnect to a different source and/or target shape. The connection will	 * disconnect from its current attachments and reconnect to the new source	 * and target.	 * 	 * @param newSource	 *            a new source endpoint for this connection (non null)	 * @param newTarget	 *            a new target endpoint for this connection (non null)	 * @throws IllegalArgumentException	 *             if any of the paramers are null or newSource == newTarget	 */	public void reconnect(Shape newSource, Shape newTarget) {		if (newSource == null || newTarget == null || newSource == newTarget) {			throw new IllegalArgumentException();		}		disconnect();		this.source = newSource;		this.target = newTarget;		reconnect();	}	/**	 * Set the line drawing style of this connection.	 * 	 * @param lineStyle	 *            one of following values: Graphics.LINE_DASH or	 *            Graphics.LINE_SOLID	 * @see Graphics#LINE_DASH	 * @see Graphics#LINE_SOLID	 * @throws IllegalArgumentException	 *             if lineStyle does not have one of the above values	 */	public void setLineStyle(int lineStyle) {		this.lineStyle = lineStyle;		firePropertyChange(LINESTYLE_PROP, null, this.lineStyle);	}	/**	 * Sets the lineStyle based on the String provided by the PropertySheet	 * 	 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object,	 *      java.lang.Object)	 */	public void setPropertyValue(Object id, Object value) {		if (id.equals(LINESTYLE_PROP))			setLineStyle((Integer) value);		else if (id.equals(FreeNoteConstants.DESC_PROPERTY))			setDesc(String.valueOf(value));		else if (id.equals(FreeNoteConstants.BACKCOLOR))			setBackColor((RGB) value);		else if (id.equals(FreeNoteConstants.FORECOLOR))			setForeColor((RGB) value);		else if(id.equals(SOURCE_DECORATION_PROP))			setSourceDecoration((Integer) value);		else if(id.equals(TARGET_DECORATION_PROP))			setTargetDecoration((Integer) value);		else			super.setPropertyValue(id, value);	}	public String getDesc() {		return desc == null ? desc="" : desc;	}	public void setDesc(String lineLabel) {		this.desc = lineLabel;		firePropertyChange(FreeNoteConstants.DESC_PROPERTY, null, lineLabel);	}	public RGB getBackColor() {		return backColor == null ? backColor=new RGB(255, 255, 255):backColor;	}	public void setBackColor(RGB backColor) {		this.backColor = backColor;		firePropertyChange(FreeNoteConstants.BACKCOLOR, null, backColor);	}	public RGB getForeColor() {		return foreColor == null ? foreColor=new RGB(0,0,0):foreColor;	}	public void setForeColor(RGB foreColor) {		this.foreColor = foreColor;		firePropertyChange(FreeNoteConstants.FORECOLOR, null, foreColor);	}	public Integer getSourceDecoration() {		return sourceDecoration==null?sourceDecoration=0:sourceDecoration;	}	public void setSourceDecoration(Integer sourceDecoration) {		this.sourceDecoration = sourceDecoration;		firePropertyChange(SOURCE_DECORATION_PROP, null, sourceDecoration);	}	public Integer getTargetDecoration() {		return targetDecoration==null?targetDecoration=1:targetDecoration;	}	public void setTargetDecoration(Integer targetDecoration) {		this.targetDecoration = targetDecoration;		firePropertyChange(TARGET_DECORATION_PROP, null, targetDecoration);	}}

⌨️ 快捷键说明

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