📄 visualtable.java
字号:
package prefuse.visual;
import java.awt.BasicStroke;
import java.awt.Font;
import java.awt.geom.Rectangle2D;
import prefuse.Visualization;
import prefuse.data.CascadedTable;
import prefuse.data.Schema;
import prefuse.data.Table;
import prefuse.data.event.EventConstants;
import prefuse.data.expression.Predicate;
import prefuse.visual.tuple.TableVisualItem;
/**
* A visual abstraction of a Table data structure. Serves as a backing table
* for VisualItem tuples. VisualTable dervies from CascadedTable,
* so can inherit another table's values. Commonly, a VisualTable is used to
* take a raw data table and "strap" visual properties on top of it.
* VisualTables should not be created directly, they are created automatically
* by adding data to a Visualization, for example by using the
* {@link Visualization#addTable(String, Table)} method.
*
* @author <a href="http://jheer.org">jeffrey heer</a>
*/
public class VisualTable extends CascadedTable implements VisualTupleSet {
private Visualization m_vis;
private String m_group;
// ------------------------------------------------------------------------
// Constructors
/**
* Create a new VisualTable.
* @param parent the parent table whose values this table should inherit
* @param vis the Visualization associated with this table
* @param group the data group of this table
*/
public VisualTable(Table parent, Visualization vis, String group) {
this(parent, vis, group, null, VisualItem.SCHEMA);
}
/**
* Create a new VisualTable.
* @param parent the parent table whose values this table should inherit
* @param vis the Visualization associated with this table
* @param group the data group of this table
* @param rowFilter a predicate determing which rows of the parent table
* should be inherited by this table and which should be filtered out
*/
public VisualTable(Table parent, Visualization vis, String group,
Predicate rowFilter)
{
this(parent, vis, group, rowFilter, VisualItem.SCHEMA);
}
/**
* Create a new VisualTable.
* @param parent the parent table whose values this table should inherit
* @param vis the Visualization associated with this table
* @param group the data group of this table
* @param rowFilter a predicate determing which rows of the parent table
* should be inherited by this table and which should be filtered out
* @param schema the data schema to use for the table's local columns
*/
public VisualTable(Table parent, Visualization vis, String group,
Predicate rowFilter, Schema schema)
{
super(parent, rowFilter, null, TableVisualItem.class);
init(vis, group, schema);
}
// -- non-cascaded visual table -------------------------------------------
/**
* Create a new VisualTable without a parent table.
* @param vis the Visualization associated with this table
* @param group the data group of this table
*/
public VisualTable(Visualization vis, String group) {
super(TableVisualItem.class);
init(vis, group, VisualItem.SCHEMA);
}
/**
* Create a new VisualTable without a parent table.
* @param vis the Visualization associated with this table
* @param group the data group of this table
* @param schema the data schema to use for the table's local columns
*/
public VisualTable(Visualization vis, String group, Schema schema) {
super(TableVisualItem.class);
init(vis, group, schema);
}
/**
* Create a new VisualTable without a parent table.
* @param vis the Visualization associated with this table
* @param group the data group of this table
* @param schema the data schema to use for the table's local columns
* @param tupleType the type of Tuple instances to use
*/
public VisualTable(Visualization vis, String group, Schema schema,
Class tupleType)
{
super(tupleType);
init(vis, group, schema);
}
/**
* Initialize this VisualTable
* @param vis the Visualization associated with this table
* @param group the data group of this table
* @param schema the data schema to use for the table's local columns
*/
protected void init(Visualization vis, String group, Schema schema) {
setVisualization(vis);
setGroup(group);
addColumns(schema);
if ( canGetBoolean(VisualItem.VISIBLE) )
index(VisualItem.VISIBLE);
if ( canGetBoolean(VisualItem.STARTVISIBLE) )
index(VisualItem.STARTVISIBLE);
if ( canGetBoolean(VisualItem.VALIDATED) )
index(VisualItem.VALIDATED);
}
// ------------------------------------------------------------------------
/**
* Relay table events. Ensures that updated visual items are invalidated
* and that damage reports are issued for deleted items.
*/
protected void fireTableEvent(int row0, int row1, int col, int type) {
// table attributes changed, so we invalidate the bounds
if ( type==EventConstants.UPDATE )
{
if ( col != VisualItem.IDX_VALIDATED ) {
for ( int r=row0; r<=row1; ++r )
setValidated(r,false);
} else {
// change in validated status
for ( int r=row0; r<=row1; ++r ) {
if ( !isValidated(r) ) {
// retrieve the old bounds to report damage
m_vis.damageReport(getItem(r), getBounds(r));
}
}
}
}
else if ( type==EventConstants.DELETE && col==EventConstants.ALL_COLUMNS)
{
for ( int r=row0; r<=row1; ++r ) {
if ( isVisible(r) && isValidated(r) ) {
VisualItem item = (VisualItem)getTuple(r);
m_vis.damageReport(item, getBounds(r));
}
}
}
// now propagate the change event
super.fireTableEvent(row0, row1, col, type);
}
// ------------------------------------------------------------------------
// VisualItemTable Methods
/**
* @see prefuse.visual.VisualTupleSet#getVisualization()
*/
public Visualization getVisualization() {
return m_vis;
}
/**
* Set the visualization associated with this VisualTable
* @param vis the visualization to set
*/
public void setVisualization(Visualization vis) {
m_vis = vis;
}
/**
* Get the visualization data group name for this table
* @return the data group name
*/
public String getGroup() {
return m_group;
}
/**
* Set the visualization data group name for this table
* @return the data group name to use
*/
public void setGroup(String group) {
m_group = group;
}
/**
* Get the VisualItem for the given table row.
* @param row a table row index
* @return the VisualItem for the given table row
*/
public VisualItem getItem(int row) {
return (VisualItem)getTuple(row);
}
/**
* Add a new row to the table and return the VisualItem for that row. Only
* allowed if there is no parent table, otherwise an exception will result.
* @return the VisualItem for the newly added table row.
*/
public VisualItem addItem() {
return getItem(addRow());
}
// ------------------------------------------------------------------------
// VisualItem Data Access
/**
* Indicates if the given row is currently validated. If not,
* validateBounds() must be run to update the bounds to a current value.
* @param row the table row
* @return true if validated, false otherwise
*/
public boolean isValidated(int row) {
return getBoolean(row, VisualItem.VALIDATED);
}
/**
* Set the given row's validated flag. This is for internal use by prefuse
* and, in general, should not be called by application code.
* @param row the table row to set
* @param value the value of the validated flag to set.
*/
public void setValidated(int row, boolean value) {
setBoolean(row, VisualItem.VALIDATED, value);
}
/**
* Indicates if the given row is currently set to be visible. Items with
* the visible flag set false will not be drawn by a display. Invisible
* items are also by necessity not interactive, regardless of the value of
* the interactive flag.
* @param row the table row
* @return true if visible, false if invisible
*/
public boolean isVisible(int row) {
return getBoolean(row, VisualItem.VISIBLE);
}
/**
* Set the given row's visibility.
* @param row the table row to set
* @param value true to make the item visible, false otherwise.
*/
public void setVisible(int row, boolean value) {
setBoolean(row, VisualItem.VISIBLE, value);
}
/**
* Indicates if the start visible flag is set to true. This is the
* visibility value consulted for the staring value of the visibility
* field at the beginning of an animated transition.
* @param row the table row
* @return true if this item starts out visible, false otherwise.
*/
public boolean isStartVisible(int row) {
return getBoolean(row, VisualItem.STARTVISIBLE);
}
/**
* Set the start visible flag.
* @param row the table row to set
* @param value true to set the start visible flag, false otherwise
*/
public void setStartVisible(int row, boolean value) {
setBoolean(row, VisualItem.STARTVISIBLE, value);
}
/**
* Indictes if the end visible flag is set to true. This is the
* visibility value consulted for the ending value of the visibility
* field at the end of an animated transition.
* @param row the table row
* @return true if this items ends visible, false otherwise.
*/
public boolean isEndVisible(int row) {
return getBoolean(row, VisualItem.ENDVISIBLE);
}
/**
* Set the end visible flag.
* @param row the table row to set
* @param value true to set the end visible flag, false otherwise
*/
public void setEndVisible(int row, boolean value) {
setBoolean(row, VisualItem.ENDVISIBLE, value);
}
/**
* Indicates if this item is interactive, meaning it can potentially
* respond to mouse and keyboard input events.
* @param row the table row
* @return true if the item is interactive, false otherwise
*/
public boolean isInteractive(int row) {
return getBoolean(row, VisualItem.INTERACTIVE);
}
/**
* Set the interactive status of the given row.
* @param row the table row to set
* @param value true for interactive, false for non-interactive
*/
public void setInteractive(int row, boolean value) {
setBoolean(row, VisualItem.INTERACTIVE, value);
}
/**
* Indicates the given row is expanded. Only used for items that are
* part of a graph structure.
* @param row the table row
* @return true if expanded, false otherwise
*/
public boolean isExpanded(int row) {
return getBoolean(row, VisualItem.EXPANDED);
}
/**
* Set the expanded flag.
* @param row the table row to set
* @param value true to set as expanded, false as collapsed.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -