📄 visualization.java
字号:
* from any registered focus groups.
* @param group the data group to remove
* @return true if the group was found and removed, false if the group
* was not found in this visualization.
*/
public synchronized boolean removeGroup(String group) {
// check for focus group first
TupleSet ts = getFocusGroup(group);
if ( ts != null ) {
// invalidate the item to reflect group membership change
for ( Iterator items = ts.tuples(ValidatedPredicate.TRUE);
items.hasNext(); )
{
((VisualItem)items.next()).setValidated(false);
}
ts.clear(); // trigger group removal callback
m_focus.remove(group);
return true;
}
// focus group not found, check for primary group
ts = getVisualGroup(group);
if ( ts == null ) {
// exit with false if group not found
return false;
}
// remove group members from focus sets and invalidate them
TupleSet[] focus = new TupleSet[m_focus.size()];
m_focus.values().toArray(focus);
for ( Iterator items = ts.tuples(); items.hasNext(); ) {
VisualItem item = (VisualItem)items.next();
for ( int j=0; j<focus.length; ++j ) {
focus[j].removeTuple(item);
}
item.setValidated(false);
}
// remove data
if ( ts instanceof CompositeTupleSet ) {
CompositeTupleSet cts = (CompositeTupleSet)ts;
for ( Iterator names = cts.setNames(); names.hasNext(); ) {
String name = (String)names.next();
String subgroup = PrefuseLib.getGroupName(group,name);
m_visual.remove(subgroup);
m_source.remove(subgroup);
}
}
m_visual.remove(group);
m_source.remove(group);
return true;
}
/**
* Reset this visualization, clearing out all visualization tuples. All
* data sets added using the "addXXX" methods will be removed from the
* visualization. All registered focus groups added using the
* addFocusGroup() methods will be retained, but will be cleared of all
* tuples.
*/
public synchronized void reset() {
// first clear out all the focus groups
Iterator iter = m_focus.entrySet().iterator();
while ( iter.hasNext() ) {
Map.Entry entry = (Map.Entry)iter.next();
TupleSet ts = (TupleSet)entry.getValue();
ts.clear();
}
// finally clear out all map entries
m_visual.clear();
m_source.clear();
}
// ------------------------------------------------------------------------
// Groups
/**
* Get the source data TupleSet backing the given visual data group.
* @return the backing source data set, or null if there is no such
* data set
*/
public TupleSet getSourceData(String group) {
return (TupleSet)m_source.get(group);
}
/**
* Get the source data TupleSet backing the given visual tuple set.
* @return the backing source data set, or null if there is no such
* data set
*/
public TupleSet getSourceData(VisualTupleSet ts) {
return (TupleSet)m_source.get(ts.getGroup());
}
/**
* Get the Tuple from a backing source data set that corresponds most
* closely to the given VisualItem.
* @param item the VisualItem for which to retreive the source tuple
* @return the data source tuple, or null if no such tuple could
* be found
*/
public Tuple getSourceTuple(VisualItem item) {
// get the source group and tuple set, exit if none
String group = item.getGroup();
TupleSet source = getSourceData(group);
if ( source == null ) return null;
// first get the source table and row value
int row = item.getRow();
Table t = item.getTable();
while ( t instanceof VisualTable ) {
VisualTable vt = (VisualTable)t;
row = vt.getParentRow(row);
t = vt.getParentTable();
}
// now get the appropriate source tuple
// graphs maintain their own tuple managers so treat them specially
String cgroup = PrefuseLib.getChildGroup(group);
if ( cgroup != null ) {
String pgroup = PrefuseLib.getParentGroup(group);
Graph g = (Graph)getSourceData(pgroup);
if ( t == g.getNodeTable() ) {
return g.getNode(row);
} else {
return g.getEdge(row);
}
} else {
return t.getTuple(row);
}
}
/**
* Get the VisualItem associated with a source data tuple, if it exists.
* @param group the data group from which to lookup the source tuple,
* only primary visual groups are valid, focus groups will not work
* @param t the source data tuple
* @return the associated VisualItem from the given data group, or
* null if no such VisualItem exists
*/
public VisualItem getVisualItem(String group, Tuple t) {
TupleSet ts = getVisualGroup(group);
VisualTable vt;
if ( ts instanceof VisualTable ) {
vt = (VisualTable)ts;
} else if ( ts instanceof Graph ) {
Graph g = (Graph)ts;
vt = (VisualTable)(t instanceof Node ? g.getNodeTable()
: g.getEdgeTable());
} else {
return null;
}
int pr = t.getRow();
int cr = vt.getChildRow(pr);
return cr<0 ? null : vt.getItem(cr);
}
// ------------------------------------------------------------------------
/**
* Get the TupleSet associated with the given data group name.
* @param group a visual data group name
* @return the data group TupleSet
*/
public TupleSet getGroup(String group) {
TupleSet ts = getVisualGroup(group);
if ( ts == null )
ts = getFocusGroup(group);
return ts;
}
/**
* Indicates if a given VisualItem is contained in the given visual
* data group.
* @param item the VisualItem instance
* @param group the data group to check for containment
* @return true if the VisualItem is in the group, false otherwise
*/
public boolean isInGroup(VisualItem item, String group) {
if ( ALL_ITEMS.equals(group) )
return true;
if ( item.getGroup() == group )
return true;
TupleSet tset = getGroup(group);
return ( tset==null ? false : tset.containsTuple(item) );
}
/**
* Add a new secondary, or focus, group to this visualization. By
* default the added group is an instance of
* {@link prefuse.data.tuple.DefaultTupleSet}.
* @param group the name of the focus group to add
*/
public void addFocusGroup(String group) {
checkGroupExists(group);
m_focus.put(group, new DefaultTupleSet());
}
/**
* Add a new secondary, or focus, group to this visualization.
* @param group the name of the focus group to add
* @param tset the TupleSet for the focus group
*/
public void addFocusGroup(String group, TupleSet tset) {
checkGroupExists(group);
m_focus.put(group, tset);
}
// ------------------------------------------------------------------------
// VisualItems
/**
* Get the size of the given visual data group.
* @param group the visual data group
* @return the size (number of tuples) of the group
*/
public int size(String group) {
TupleSet tset = getGroup(group);
return ( tset==null ? 0 : tset.getTupleCount() );
}
/**
* Retrieve the visual data group of the given group name. Only primary
* visual groups will be considered.
* @param group the visual data group
* @return the requested data group, or null if not found
*/
public TupleSet getVisualGroup(String group) {
return (TupleSet)m_visual.get(group);
}
/**
* Retrieve the focus data group of the given group name. Only secondary,
* or focus, groups will be considered.
* @param group the focus data group
* @return the requested data group, or null if not found
*/
public TupleSet getFocusGroup(String group) {
return (TupleSet)m_focus.get(group);
}
/**
* Invalidate the bounds of all VisualItems in the given group. This
* will cause the bounds to be recomputed for all items upon the next
* redraw.
* @param group the visual data group to invalidate
*/
public void invalidate(String group) {
Iterator items = items(group, ValidatedPredicate.TRUE);
while ( items.hasNext() ) {
VisualItem item = (VisualItem)items.next();
item.setValidated(false);
}
}
/**
* Invalidate the bounds of all VisualItems in this visualization. This
* will cause the bounds to be recomputed for all items upon the next
* redraw.
*/
public void invalidateAll() {
invalidate(ALL_ITEMS);
}
/**
* Get an iterator over all visible items.
* @return an iterator over all visible items.
*/
public Iterator visibleItems() {
return items(VisiblePredicate.TRUE);
}
/**
* Get an iterator over all visible items in the specified group.
* @param group the visual data group name
* @return an iterator over all visible items in the specified group
*/
public Iterator visibleItems(String group) {
return items(group, VisiblePredicate.TRUE);
}
/**
* Get an iterator over all items, visible or not.
* @return an iterator over all items, visible or not.
*/
public Iterator items() {
return items((Predicate)null);
}
/**
* Get an iterator over all items which match the given
* Predicate filter.
* @param filter a Predicate indicating which items should be included
* in the iteration
* @return a filtered iterator over VisualItems
*/
public Iterator items(Predicate filter) {
int size = m_visual.size();
if ( size == 0 ) {
return Collections.EMPTY_LIST.iterator();
} else if ( size == 1 ) {
Iterator it = m_visual.keySet().iterator();
return items((String)it.next(), filter);
} else {
CompositeIterator iter = new CompositeIterator(m_visual.size());
Iterator it = m_visual.keySet().iterator();
for ( int i=0; it.hasNext(); ) {
String group = (String)it.next();
if ( !PrefuseLib.isChildGroup(group) )
iter.setIterator(i++, items(group, filter));
}
return iter;
}
}
/**
* Get an iterator over all items in the specified group.
* @param group the visual data group name
* @return an iterator over all items in the specified group.
*/
public Iterator items(String group) {
return items(group, (Predicate)null);
}
/**
* Get an iterator over all items in the given group which match the given
* filter expression.
* @param group the visual data group to iterate over
* @param expr an expression string that should parse to a Predicate
* indicating which items should be included in the iteration. The input
* string will be parsed using the
* {@link prefuse.data.expression.parser.ExpressionParser} class. If a
* parse error occurs, an empty iterator is returned.
* @return a filtered iterator over VisualItems
*/
public Iterator items(String group, String expr) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -