view java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/TreeModel.java @ 0:9418ab7b7f3f

Initial import
author Fiore Martin <fiore@eecs.qmul.ac.uk>
date Fri, 16 Dec 2011 17:35:51 +0000
parents
children 9e67171477bc
line wrap: on
line source
/*  
 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
  
 Copyright (C) 2011  Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)

 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 3 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, see <http://www.gnu.org/licenses/>.
*/
package uk.ac.qmul.eecs.ccmi.diagrammodel;

import java.util.Set;

import javax.swing.event.ChangeListener;

/**
 * 
 * Represents the tree side of a DiagramModel instance. 
 *
 * @param <N> a type extending DiagramNode
 * @param <E> a type extending DiagramEdge
 */
public interface TreeModel<N extends DiagramNode, E extends DiagramEdge> extends javax.swing.tree.TreeModel {
	
	/**
	 * insert a DiagramNode into the diagram model
	 * 
	 * @param treeNode the DiagramNode to be inserted in the collection
	 * @return true if the model changed as a result of the call
	 */
	boolean insertTreeNode(N treeNode);
	
	/**
	 * insert a DiagramEdge into the diagram model
	 * 
	 * @param treeNode the DiagramEdge to be inserted in the collection
	 * @return true if the model changed as a result of the call
	 */
	boolean insertTreeNode(E treeNode);
	
	/**
	 * remove a DiagramElement from the model 
	 * 
	 * @param treeNode the diagramElement to be removed 
	 * @return true if the model changed as a result of the call
	 */
	boolean takeTreeNodeOut(DiagramElement treeNode);
	
	/**
	 * 
	 * Add a bookmark for the specified tree node in the internal collection
	 * 
	 * @param bookmark a bookmark 
	 * @param treeNode the tree node to be bookmarked
	 * @return previous value associated with specified key, or null if there was no mapping for key.
	 * @throws IllegalArgumentException if bookmark is null 
	 */
	DiagramModelTreeNode putBookmark(String bookmark, DiagramModelTreeNode treeNode);
	
	/**
	 * Returns a bookmarked tree node
	 * @param bookmark the bookmark associated with the tree node
	 * @return the bookmarked tree node or null if no tree node was bookmarked with the argument
	 */
	DiagramModelTreeNode getBookmarkedTreeNode(String bookmark);
	
	/**
	 * Returns the list of all the bookmarks of this tree model
	 * @return the list of all the bookmarks
	 */
	Set<String> getBookmarks();
	
	/**
	 * Remove the bookmark from the bookmark internal collection
	 * 
	 * @param bookmark the bookmark to remove
	 * @return previous value associated with specified key, or null if there was no mapping for key.
	 */
	DiagramModelTreeNode removeBookmark(String bookmark);
	
	/**
	 * Set the notes for the specified tree node. Passing an empty string as notes 
	 * means actually to remove the notes from the tree node. 
	 *  
	 * @param treeNode the tree node to be noted 
	 * @param notes the notes to be assigned to the tree node 
	 */
	void setNotes(DiagramModelTreeNode treeNode, String notes);
	
	/**
	 * Add a change listener to the model. the listeners will be fired each time the model 
	 * goes from the unmodified to modified state. The model is modified when a either a 
	 * node or an edge are inserted or removed or changed when they are within the model.    
	 * @param l a ChangeListener to add to the model  
	 */
	void addChangeListener(ChangeListener l);
	
	/**
	 * Removes a change listener from the model. 
	 * @param l a ChangeListener to remove from the model
	 */
	void removeChangeListener(ChangeListener l);
	
	/**
	 * Returns true if the model has been modified
	 * @return true if the model has been modified
	 */
	boolean isModified();
	
	/**
	 * Sets the model as unmodified. This entails that {@link #isModified()} will return 
	 * false unless the model doesn't get modified again. After this call a new modification
	 * of the model would trigger the associated change listeners again. 
	 */
	public void setUnmodified();
	
	/**
	 * Returns an object that can be used to access the nodes and edges (via {@link #getNodes()}
	 * and {@link #getEdges()} in a synchronized block. The monitor is guaranteed to give 
	 * exclusive access even in regards to the access via the tree side of the model.  
	 * @return
	 */
	Object getMonitor();
}