📄 alphabeticalpropertytablemodel.java
字号:
/*
* 08/10/2005
*
* AlphabeticalPropertyTableModel.java - Model used in a property sheet's table
* when it is sorted alphabetically.
* Copyright (C) 2005 Robert Futrell
* email@address.com
* www.website.com
*
* 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 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.
*/
package org.fife.ui.propertysheet;
import java.util.*;
import javax.swing.table.*;
import org.fife.ui.propertysheet.infos.PropertyInfo;
/**
* A table model for <code>PropertyTable</code> that keeps all properties
* together, in alphabetical order.
*
* @author Robert Futrell
* @version 1.0
*/
class AlphabeticalPropertyTableModel extends PropertyTableModel {
/**
*
*/
private static final long serialVersionUID = 1725508037505445868L;
/*****************************************************************************/
/**
* Adds a property to this table model.
*
* @param info The property to add.
*/
public void addProperty(PropertyInfo info) {
String displayName = info.getDisplayName();
Object[] rowData = new Object[] { displayName, info };
int rowCount = getRowCount();
if (rowCount==0) {
insertRow(0, rowData);
return;
}
boolean inserted = false;
for (int i=0; i<rowCount; i++) {
String rowName = (String)getValueAt(i, 0);
if (displayName.compareTo(rowName)<=0) {
insertRow(i, rowData);
inserted = true;
break;
}
}
// If it's lexicographically at the end, add it to the end.
if (!inserted) {
addRow(rowData);
}
}
/*****************************************************************************/
/**
* Returns the renderer for a given cell.
*
* @param row The row of the cell.
* @param column The column of the cell.
* @return <code>null</code> is returned, signifying that the table
* itself will decide on a renderer.
*/
public TableCellRenderer getCellRenderer(int row, int column) {
return null;
}
/*****************************************************************************/
/**
* Returns the number of properties in this property container.
*
* @return The property count.
*/
public int getPropertyCount() {
return getRowCount();
}
/*****************************************************************************/
/**
* Returns an iterator over the properties in this property sheet.
*
* @return The iterator.
*/
public Iterator getPropertyIterator() {
return new PropertyTableIterator();
}
/*****************************************************************************/
/**
* Returns whether the specified cell is editable.
*
* @param row The row of the cell.
* @param column The column of the cell.
* @return Whether the cell is editable.
*/
public boolean isCellEditable(int row, int column) {
return column==1 &&
((PropertyInfo)getValueAt(row, column)).isModifiable();
}
/*****************************************************************************/
/**
* Returns whether the specified row is expandable (that is, it contains
* "sub-rows" that can optionally be displayed).
*
* @param row The row in question. This is a row index into this table
* as it is currently displayed.
* @return Whether the row is expandable.
*/
public boolean isExpandableRow(int row) {
return false;
}
/*****************************************************************************/
/**
* If the specified row is expandable, its expanded state is toggled.
*
* @param row The row in question. This is a row index into this table
* as it is currently displayed.
*/
void toggleExpandedState(int row) {
// Do nothing.
}
/*****************************************************************************/
/******************* PRIVATE INNER CLASSES ***********************************/
/*****************************************************************************/
class PropertyTableIterator implements Iterator {
protected int index;
public PropertyTableIterator() {
index = 0;
}
public boolean hasNext() {
return index<getPropertyCount();
}
public Object next() {
if (!hasNext())
throw new NoSuchElementException();
return getValueAt(index++, 1);
}
public void remove() {
throw new UnsupportedOperationException();
}
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -