📄 resulttreetable.java
字号:
/*
Copyright (C) 2001, 2008 United States Government as represented by
the Administrator of the National Aeronautics and Space Administration.
All Rights Reserved.
*/
package gov.nasa.worldwind.applications.gio.catalogui;
import gov.nasa.worldwind.applications.gio.catalogui.treetable.*;
import gov.nasa.worldwind.avlist.AVList;
import gov.nasa.worldwind.util.Logging;
import javax.swing.*;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
/**
* @author dcollins
* @version $Id: ResultTreeTable.java 5517 2008-07-15 23:36:34Z dcollins $
*/
public class ResultTreeTable extends TreeTable
{
private ResultList resultList;
private AVList params;
private final ToolTipSupport toolTipSupport = new ToolTipSupport();
public ResultTreeTable(ResultList resultList, AVList tableParams)
{
super(new TreeTableModelAdapter(tableParams));
this.resultList = resultList;
this.resultList.addResultListListener(new ResultListener(this));
this.params = initParams(tableParams);
setAskIfTreeEditable(true);
setTreeEditable(false);
setFocusable(false);
setCellSelectionEnabled(false);
getTree().setSelectionModel(null);
getTree().setLargeModel(true);
getTree().addTreeExpansionListener(new ExpansionListener(this));
addMouseMotionListener(new MouseListener(this));
setRowHeight(24);
getTree().setRootVisible(false);
getTree().setShowsRootHandles(true);
getTree().putClientProperty("JTree.lineStyle", "None");
// Shorten initial ToolTip delay by 50%.
int initialDelay = ToolTipManager.sharedInstance().getInitialDelay();
ToolTipManager.sharedInstance().setInitialDelay(initialDelay / 2);
// Disable ToolTip dismiss.
ToolTipManager.sharedInstance().setDismissDelay(Integer.MAX_VALUE);
}
public ResultList getResultList()
{
return this.resultList;
}
public AVList getTableParams()
{
return this.params;
}
public String getToolTipText(MouseEvent event)
{
String text = super.getToolTipText(event);
if (text == null)
{
if (event != null)
{
java.awt.Point p = event.getPoint();
int rowIndex = rowAtPoint(p);
int colIndex = columnAtPoint(p);
int realColumnIndex = convertColumnIndexToModel(colIndex);
Object o = getValueAt(rowIndex, realColumnIndex);
if (o != null)
{
this.toolTipSupport.clear();
this.toolTipSupport.append(o.toString(), Font.BOLD);
text = this.toolTipSupport.getText();
}
}
}
return text;
}
protected void mouseMoved(MouseEvent event)
{
Cursor cursor = null;
if (event != null)
{
java.awt.Point p = event.getPoint();
int rowIndex = rowAtPoint(p);
int colIndex = columnAtPoint(p);
int realColumnIndex = convertColumnIndexToModel(colIndex);
if (rowIndex >= 0 && realColumnIndex >= 0)
{
TableCellRenderer renderer = getCellRenderer(rowIndex, realColumnIndex);
if (renderer != null)
{
Object value = getValueAt(rowIndex, realColumnIndex);
Component c = renderer.getTableCellRendererComponent(this, value, false, false,
rowIndex, realColumnIndex);
if (c != null)
{
cursor = c.getCursor();
}
}
}
}
if (cursor == null)
cursor = Cursor.getDefaultCursor();
setCursor(cursor);
}
protected void nodeExpanded(TreeTableNode node)
{
}
protected void reloadResultList()
{
}
protected void reloadResultListInSwingThread()
{
try
{
if (SwingUtilities.isEventDispatchThread())
{
reloadResultList();
}
else
{
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
reloadResultList();
}
});
}
}
catch (Exception e)
{
String message = "catalog.ExceptionWhileInvokingOnEventDispatchThread";
Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
}
}
protected void reloadResults(int beginIndex, int endIndex)
{
TreeTableModel ttm = getTreeTableModel();
if (ttm != null)
{
if (ttm instanceof AbstractTreeTableModel)
{
for (int i = beginIndex; i <= endIndex; i++)
{
TreeTableNode node = ((AbstractTreeTableModel ) ttm).getNodeForValue(this.resultList.get(i));
if (node instanceof AbstractTreeTableNode)
((AbstractTreeTableNode) node).update();
((AbstractTreeTableModel ) ttm).reload(node);
}
}
}
}
protected void reloadResultsInSwingThread(final int beginIndex, final int endIndex)
{
try
{
if (SwingUtilities.isEventDispatchThread())
{
reloadResults(beginIndex, endIndex);
}
else
{
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
reloadResults(beginIndex, endIndex);
}
});
}
}
catch (Exception e)
{
String message = "catalog.ExceptionWhileInvokingOnEventDispatchThread";
Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
}
}
protected void repaintInSwingThread()
{
try
{
if (SwingUtilities.isEventDispatchThread())
{
repaint();
}
else
{
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
repaint();
}
});
}
}
catch (Exception e)
{
String message = "catalog.ExceptionWhileInvokingOnEventDispatchThread";
Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
}
}
protected AVList initParams(AVList params)
{
if (params == null)
{
String message = "nullValue.ParamsIsNull";
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
int columnCount = -1;
Object o = params.getValue(CatalogKey.TABLE_COLUMN_COUNT);
if (o != null)
{
Integer i = asInteger(o);
if (i != null)
{
params.setValue(CatalogKey.TABLE_COLUMN_COUNT, i);
columnCount = i;
}
}
o = params.getValue(CatalogKey.TABLE_COLUMN_PROPERTY_KEY);
if (o != null)
{
Object[] array = asPropertyKeys(o, columnCount);
if (array != null)
params.setValue(CatalogKey.TABLE_COLUMN_PROPERTY_KEY, array);
}
o = params.getValue(CatalogKey.TABLE_COLUMN_CLASS);
if (o != null)
{
Class[] c = asClassArray(o);
if (c != null)
params.setValue(CatalogKey.TABLE_COLUMN_CLASS, c);
}
o = params.getValue(CatalogKey.TABLE_COLUMN_NAME);
if (o != null)
{
String[] s = asStringArray(o);
if (s != null)
params.setValue(CatalogKey.TABLE_COLUMN_NAME, s);
}
o = params.getValue(CatalogKey.TABLE_COLUMN_EDITABLE);
if (o != null)
{
Boolean[] b = asBooleanArray(o);
if (b != null)
params.setValue(CatalogKey.TABLE_COLUMN_EDITABLE, b);
}
o = params.getValue(CatalogKey.TABLE_COLUMN_CELL_EDITOR);
if (o != null)
{
Object[] array = asInstanceArray(o);
if (array != null)
params.setValue(CatalogKey.TABLE_COLUMN_CELL_EDITOR, array);
}
o = params.getValue(CatalogKey.TABLE_COLUMN_CELL_RENDERER);
if (o != null)
{
Object[] array = asInstanceArray(o);
if (array != null)
params.setValue(CatalogKey.TABLE_COLUMN_CELL_RENDERER, array);
}
o = params.getValue(CatalogKey.TABLE_COLUMN_HEADER_RENDERER);
if (o != null)
{
Object[] array = asInstanceArray(o);
if (array != null)
params.setValue(CatalogKey.TABLE_COLUMN_HEADER_RENDERER, array);
}
o = params.getValue(CatalogKey.TABLE_COLUMN_HEADER_VALUE);
if (o != null)
{
String[] s = asStringArray(o);
if (s != null)
params.setValue(CatalogKey.TABLE_COLUMN_HEADER_VALUE, s);
}
o = params.getValue(CatalogKey.TABLE_COLUMN_MAX_WIDTH);
if (o != null)
{
Integer[] i = asIntegerArray(o);
if (i != null)
params.setValue(CatalogKey.TABLE_COLUMN_MAX_WIDTH, i);
}
o = params.getValue(CatalogKey.TABLE_COLUMN_MIN_WIDTH);
if (o != null)
{
Integer[] i = asIntegerArray(o);
if (i != null)
params.setValue(CatalogKey.TABLE_COLUMN_MIN_WIDTH, i);
}
o = params.getValue(CatalogKey.TABLE_COLUMN_PREFERRED_WIDTH);
if (o != null)
{
Integer[] i = asIntegerArray(o);
if (i != null)
params.setValue(CatalogKey.TABLE_COLUMN_PREFERRED_WIDTH, i);
}
o = params.getValue(CatalogKey.TABLE_COLUMN_RESIZABLE);
if (o != null)
{
Boolean[] b = asBooleanArray(o);
if (b != null)
params.setValue(CatalogKey.TABLE_COLUMN_RESIZABLE, b);
}
return params;
}
public void tableChanged(TableModelEvent e)
{
super.tableChanged(e);
// Columns changed
if (e == null || e.getFirstRow() == TableModelEvent.HEADER_ROW)
{
if (getAutoCreateColumnsFromModel())
updateColumnsFromModel();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -