nodelabelfigure.java

来自「对eclipse gef进行封装,可以生成图形化编辑器」· Java 代码 · 共 92 行

JAVA
92
字号
/*******************************************************************************
 * $Header: /cvsroot/EOS6/work_dir/niegy/com.primeton.studio.gef.ui/src/com/primeton/studio/gef/ui/figure/NodeLabelFigure.java,v 1.1 2006/12/12 08:26:39 niegy Exp $
 * $Revision: 1.1 $
 * $Date: 2006/12/12 08:26:39 $
 *
 *==============================================================================
 *
 * Copyright (c) 2001-2006 Primeton Technologies, Ltd.
 * All rights reserved.
 * 
 * Created on 2006-12-11
 *******************************************************************************/


package com.primeton.studio.gef.ui.figure;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.CompoundBorder;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Image;

/**
 * TODO 此处填写 class 信息
 *
 * @author niegy (mailto:niegy@primeton.com)
 */
/*
 * 修改历史
 * $Log: NodeLabelFigure.java,v $
 * Revision 1.1  2006/12/12 08:26:39  niegy
 * 重构代码,实现一般图元的编辑框
 * 
 */
public class NodeLabelFigure extends Figure {
	private IFigure body;
	private Image fImage = null;   
	public NodeLabelFigure(Image image,Label label){		
		this();
	    fImage = image;
	    body = label;
//	    body.setLayoutManager(new ToolbarLayout());
	    add(body);
	}
	
    public NodeLabelFigure(){
//    	ToolbarLayout layout = new ToolbarLayout();
//		setLayoutManager(layout);	
//		setOpaque(true);
    }  
    
	public void addLabel(Label label){
		this.body = label;
		label.setText("asdf");
		body.setLayoutManager(new ToolbarLayout());
		add(body);
	}
	
	public IFigure getLabel() {
		return body;
	}
    
    public void setImage(Image iamge){
        fImage = iamge;
    }
    
    protected void paintFigure(Graphics g){
        if(fImage != null){
            Point p = getBounds().getLocation();
            Rectangle src = new Rectangle(fImage.getBounds().x,
                    fImage.getBounds().y,
                    fImage.getBounds().width,
                    fImage.getBounds().height);
            if (fImage != null)
                g.drawImage(fImage,src ,getBounds());
        }
        else{
        	g.setBackgroundColor(ColorConstants.red);
        	g.fillRectangle(getBounds());
            super.paintFigure(g);
        }
    }
}

⌨️ 快捷键说明

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