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

📄 nodeview.java

📁 思维导图(Mind Mapping)以放射性思考(Radiant Thinking)为基础的收放自如方式
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*FreeMind - A Program for creating and viewing Mindmaps *Copyright (C) 2000-2001  Joerg Mueller <joergmueller@bigfoot.com> *See COPYING for Details * *This program is free software; you can redistribute it and/or *modify it under the terms of the GNU General Public License *as published by the Free Software Foundation; either version 2 *of the License, or (at your option) any later version. * *This program is distributed in the hope that it will be useful, *but WITHOUT ANY WARRANTY; without even the implied warranty of *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *GNU General Public License for more details. * *You should have received a copy of the GNU General Public License *along with this program; if not, write to the Free Software *Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. *//*$Id: NodeView.java,v 1.27.14.17 2005/07/03 20:53:50 christianfoltin Exp $*/package freemind.view.mindmapview;import java.awt.Color;import java.awt.Cursor;import java.awt.Dimension;import java.awt.Font;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Point;import java.awt.RenderingHints;import java.awt.dnd.DnDConstants;import java.awt.dnd.DragGestureListener;import java.awt.dnd.DragSource;import java.awt.dnd.DropTarget;import java.awt.dnd.DropTargetListener;import java.net.MalformedURLException;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.ListIterator;import java.util.Map;import java.util.Set;import java.util.TreeSet;import javax.swing.ImageIcon;import javax.swing.JLabel;import javax.swing.SwingConstants;import freemind.controller.Controller;import freemind.main.FreeMind;import freemind.main.FreeMindMain;import freemind.main.Tools;import freemind.modes.MindIcon;import freemind.modes.MindMapCloud;import freemind.modes.MindMapNode;import freemind.modes.NodeAdapter;import freemind.preferences.FreemindPropertyListener;/** * This class represents a single Node of a MindMap * (in analogy to TreeCellRenderer). */public abstract class NodeView extends JLabel {    protected MindMapNode model;    protected MapView map;    protected EdgeView edge;    /** the Color of the Rectangle of a selected Node */	protected final static Color selectedColor = new Color(210,210,210); //Color.lightGray; //the Color of the Rectangle of a selected Node    protected final static Color dragColor = Color.lightGray; //the Color of appearing GradientBox on drag over	protected int treeWidth = 0;	protected int treeHeight = 0;	protected int upperChildShift = 0;    private boolean left = true; //is the node left of root?    int relYPos = 0;//the relative Y Position to it's parent    private boolean isLong = false;        public final static int DRAGGED_OVER_NO = 0;    public final static int DRAGGED_OVER_SON = 1;    public final static int DRAGGED_OVER_SIBLING = 2;    /** For RootNodeView.*/    public final static int DRAGGED_OVER_SON_LEFT = 3;    protected int isDraggedOver = DRAGGED_OVER_NO;    public void setDraggedOver(int draggedOver) {       isDraggedOver = draggedOver; }    public void setDraggedOver(Point p) {       setDraggedOver( (dropAsSibling(p.getX())) ? NodeView.DRAGGED_OVER_SIBLING : NodeView.DRAGGED_OVER_SON) ; }    public int getDraggedOver() {       return isDraggedOver; }	final static int ALIGN_BOTTOM = -1;	final static int ALIGN_CENTER = 0;	final static int ALIGN_TOP = 1;        //    // Constructors    //        private static Color standardSelectColor;    private static Color standardNodeColor;    protected NodeView(MindMapNode model, MapView map) {	setHorizontalAlignment(CENTER);	this.model = model;	setMap(map);	// initialize the standard node color.	if (standardNodeColor == null) {        standardNodeColor =            Tools.xmlToColor(                map.getController().getProperty(FreeMind.RESOURCES_NODE_COLOR));        // add listener:        Controller                    .addPropertyChangeListener(new FreemindPropertyListener() {                        public void propertyChanged(String propertyName,                                String newValue, String oldValue) {                            if (propertyName                                    .equals(FreeMind.RESOURCES_NODE_COLOR)) {                                standardNodeColor = Tools.xmlToColor(newValue);                            }                            if (propertyName                                    .equals(FreeMind.RESOURCES_SELECTED_NODE_COLOR)) {                                standardSelectColor = Tools.xmlToColor(newValue);                            }                        }                    });    }	// initialize the selectedColor:	if(standardSelectColor== null) {		String stdcolor = map.getController().getFrame().getProperty(FreeMind.RESOURCES_SELECTED_NODE_COLOR);		if (stdcolor.length() == 7) {			standardSelectColor = Tools.xmlToColor(stdcolor);		} else {			standardSelectColor = new Color(210,210,210);		}	}	//Root has no edge	if (!isRoot()) {	    if (getModel().getEdge().getStyle().equals("linear")) {		edge = new LinearEdgeView(getParentView(),this);	    } else if (getModel().getEdge().getStyle().equals("bezier")) {		edge = new BezierEdgeView(getParentView(),this);	    } else if (getModel().getEdge().getStyle().equals("sharp_linear")) {		edge = new SharpLinearEdgeView(getParentView(),this);	    } else if (getModel().getEdge().getStyle().equals("sharp_bezier")) {		edge = new SharpBezierEdgeView(getParentView(),this);	    } else {		System.err.println("Unknown Edge Type.");	    }	}	addMouseListener( map.getNodeMouseMotionListener() );	addMouseMotionListener( map.getNodeMouseMotionListener() );	addKeyListener( map.getNodeKeyListener() );	addDragListener( map.getNodeDragListener() );	addDropListener( map.getNodeDropListener() );    }        protected void addToMap(){    	map.add(this);    }        protected void removeFromMap(){    	map.remove(this);    }    void addDragListener(DragGestureListener dgl) {	DragSource dragSource = DragSource.getDefaultDragSource();	dragSource.createDefaultDragGestureRecognizer            (this, DnDConstants.ACTION_COPY | DnDConstants.ACTION_MOVE | DnDConstants.ACTION_LINK ,dgl);    }    void addDropListener(DropTargetListener dtl) {	DropTarget dropTarget = new DropTarget(this,dtl);	dropTarget.setActive(true);    }    /**     * Factory method which creates the right NodeView for the model.     */     protected static NodeView newNodeView(MindMapNode model, MapView map) {	NodeView newView;	if (model.isRoot()) {	    newView = new RootNodeView( model, map );	} else if (model.getStyle().equals(MindMapNode.STYLE_FORK) ) {	    newView = new ForkNodeView( model, map );//		newView = new BubbleNodeView( model, map );	} else if (model.getStyle().equals(MindMapNode.STYLE_BUBBLE) ) {//		newView = new ForkNodeView( model, map );		newView = new BubbleNodeView( model, map );	} else {	    System.err.println("Tried to create a NodeView of unknown Style.");	    newView = new ForkNodeView(model, map);	}	model.setViewer(newView);	newView.addToMap();	newView.update();	return newView;    }    //    // public methods    //    public boolean dropAsSibling(double xCoord) {        return isInVerticalRegion(xCoord, 1./3);     }    /** Determines whether or not the xCoord is in the part p of the node:     *  if node is on the left: part [1-p,1]      *  if node is on the right: part[  0,p] of the total width.     */    public boolean isInVerticalRegion(double xCoord, double p) {        return isLeft() ?           xCoord > getSize().width*(1.0-p) :           xCoord < getSize().width*p;      }    /** @return true if should be on the left, false otherwise.*/    public boolean dropPosition (double xCoord) {        /* here it is the same as me. */       return isLeft();     }    public boolean isInFollowLinkRegion(double xCoord) {       return getModel().getLink() != null &&          (getModel().isRoot() || !getModel().hasChildren() || isInVerticalRegion(xCoord, 1./2));     }    /**     * @param xCoord     * @return true if a link is to be displayed and the curser is the hand now.     */    public boolean updateCursor(double xCoord) {      boolean followLink = isInFollowLinkRegion(xCoord);    int requiredCursor = followLink ? Cursor.HAND_CURSOR : Cursor.DEFAULT_CURSOR;      if (getCursor().getType() != requiredCursor) {        setCursor(new Cursor(requiredCursor));      }      return followLink;    }    public boolean isRoot() {	return model.isRoot();    }    public boolean getIsLong() {        return isLong; }    /* fc, 25.1.2004: Refactoring necessary: should call the model. */    public boolean isSiblingOf(NodeView myNodeView) {        return getParentView() == myNodeView.getParentView(); }    /* fc, 25.1.2004: Refactoring necessary: should call the model. */    public boolean isChildOf(NodeView myNodeView) {        return getParentView() == myNodeView; }    /* fc, 25.1.2004: Refactoring necessary: should call the model. */    public boolean isParentOf(NodeView myNodeView) {        return (this == myNodeView.getParentView()); }    public MindMapNode getModel() {	return model;    }    /** Returns the coordinates occupied by the node and its children as a vector of four point per node.*/	public void getCoordinates(LinkedList inList) {		getCoordinates(inList, 0, false);	}	private void getCoordinates(LinkedList inList, int additionalDistanceForConvexHull, boolean byChildren) {		MindMapCloud cloud = getModel().getCloud();		// consider existing clouds of children		if (byChildren && cloud != null){			additionalDistanceForConvexHull  += CloudView.getAdditionalHeigth(cloud, this) / 2; 		}        inList.addLast(new Point( -additionalDistanceForConvexHull + getExtendedX()             ,  -additionalDistanceForConvexHull + getExtendedY()              ));        inList.addLast(new Point( -additionalDistanceForConvexHull + getExtendedX()             ,   additionalDistanceForConvexHull + getExtendedY() + getExtendedHeight()));        inList.addLast(new Point(  additionalDistanceForConvexHull + getExtendedX() + getExtendedWidth(),   additionalDistanceForConvexHull + getExtendedY() + getExtendedHeight()));        inList.addLast(new Point(  additionalDistanceForConvexHull + getExtendedX() + getExtendedWidth(),  -additionalDistanceForConvexHull + getExtendedY()              ));		        LinkedList childrenViews = getChildrenViews();        ListIterator children_it = childrenViews.listIterator();        while(children_it.hasNext()) {            NodeView child = (NodeView)children_it.next();	        child.getCoordinates(inList, additionalDistanceForConvexHull, true);        }    }   	private static boolean NEED_PREF_SIZE_BUG_FIX = Controller.JAVA_VERSION.compareTo("1.5.0") < 0;	private static final int MIN_HOR_NODE_SIZE = 10;    public Dimension getPreferredSize() {        boolean isEmpty = getText().length() == 0;        if(isEmpty){            setText("!");        }    	Dimension prefSize = super.getPreferredSize();        if(map.isCurrentlyPrinting() && NEED_PREF_SIZE_BUG_FIX) {        	prefSize.width += (int)(10f*map.getZoom());        }         prefSize.width = Math.max(map.getZoomed(MIN_HOR_NODE_SIZE), prefSize.width);        if (isEmpty){            setText("");        }		prefSize.width += 4;		prefSize.height += 4;        return prefSize;    }        /** get width including folding symbol*/		public int getExtendedWidth()	{		return getExtendedWidth(getWidth());	}  	/** get height including folding symbol*/		public int getExtendedHeight()	{		return getExtendedHeight(getHeight());	}  	protected int getExtendedWidth(int w)	{		return w;	}  	/** get height including folding symbol*/		protected int getExtendedHeight(int h)	{		return h;	}  	/** get x coordinate including folding symbol*/		public int getExtendedX()	{		return getX();	}  	/** get y coordinate including folding symbol*/		public int getExtendedY()	{		return getY();	}  	public void setBounds(int x,	int y){		setLocation(x, y);		setSize(getPreferredSize());	}   public void requestFocus(){      map.getController().getMode().getModeController().anotherNodeSelected(getModel());

⌨️ 快捷键说明

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