class AttributeTableCellRenderer extends DefaultTableCellRenderer
{
private Color colour1 = Color.LIGHT_GRAY;
private Color colour2 = Color.PINK;
ResultsModel rm;
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
rm = (ResultsModel) table.getModel();
Attribute a = (Attribute) value;
Component c = super.getTableCellRendererComponent(table, a.getAttribute(), isSelected, false, row, column);
if(value instanceof Attribute)
{
try
{
Attribute b = (Attribute)rm.getValueAt(row - 1, column);
System.out.println("passed rm.getValue");
String s1 = (String) a.getAttribute();
String s2 = (String) b.getAttribute();
if(s1.compareTo(s2) == 0)
{
// System.out.println(s1+ " "+ s2);
c.setBackground(rm.getColour(row-1));
rm.setColour(rm.getColour(row-1));
}
else
{
if(rm.getColour(row-1) != matchColour)
{
c.setBackground(matchColour);
rm.setColour(matchColour);
}
}
return c;
}
catch(Exception e)
{
System.out.println(e);
c = super.getTableCellRendererComponent(table, a.getAttribute(), isSelected, false, row, column);
c.setBackground(colour1);
rm.setColour(colour1);
table.repaint();
return c;
}
}
c = super.getTableCellRendererComponent(table, a.getAttribute(), isSelected, false, row, column);
c.setBackground(colour2);
rm.setColour(colour2);
return c;
}
} public void setColour(Color c)
{
colourList.add(c);
//System.out.println(colourList.size());
}
public Color getColour(int i)
{
return (Color)colourList.get(i);
}class ResultsModel extends AbstractTableModel implements Comparator {
private List data;
private List plugins;
private List markedList;
private List colours;
private boolean isMode2;
private boolean isAdvanced;
private boolean markAll = false;
private int sorting;
boolean isAdvancedMode() {
return isAdvanced;
}
void updateUIMode(boolean isAdvanced) {
if (isAdvanced) {
lastColumnCount = 2;
} else {
lastColumnCount = 1;
}
if (this.isAdvanced != isAdvanced) {
this.isAdvanced = isAdvanced;
resetColumns();
}
}
private void resetColumns() {
fireTableStructureChanged();
TableColumnModel tcm = tblResults.getColumnModel();
TableColumn tc = tcm.getColumn(0);
tc.setMaxWidth(24);
tc.setResizable(false);
if (isAdvanced) {
tc = tcm.getColumn(1 + firstColumnCount + attributeColumnCount);
tc.setMaxWidth(18);
tc.setResizable(false);
}
}
void mark() {
for (int i = 0; i < markedList.size(); i++) {
markedList.set(i, new Boolean(!markAll));
}
markAll = !markAll;
}
void sort(int col) {
sorting = col - 2;
Collections.sort(data, this);
fireTableRowsUpdated(0, data.size());
}
public ResultsModel() {
data = new ArrayList();
markedList = new ArrayList();
plugins = new ArrayList();
colourList = new ArrayList();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 0 ? true : false;
}
public Class getColumnClass(int columnIndex) {
if (columnIndex == 0)
{
return Boolean.class;
}
else if (columnIndex == 1)
{
return AttributedFile.class;
}
else if(columnIndex == 2)
{
return String.class;
}
else if(columnIndex == 3)
{
return String.class;
}
else if(columnIndex == firstColumnCount+attributeColumnCount)
{
return ImageIcon.class;
}
else if(columnIndex == 1+firstColumnCount+attributeColumnCount)
{
return ImageIcon.class;
}
//return Attribute.class;
//else if(columnIndex < firstColumnCount + attributeColumnCount)
//{
return Attribute.class;
//}
//return String.class;
}
public String getColumnName(int columnIndex)
{
if(columnIndex == 0) {
return "{}";
}
else if(columnIndex == 1)
{
return "File";
}
else if(columnIndex == 2)
{
return "Path";
}
else if(columnIndex == 3)
{
return "Last-Modified";
}
else if(columnIndex < firstColumnCount + attributeColumnCount)
{
Object p = plugins.get(columnIndex - firstColumnCount);
if(p instanceof ProcessingPlugin)
{
return ((ProcessingPlugin) p).getAttributeName();
}
else
{
return "";
}
}
else
{
return "";
}
}
public int getRowCount() {
return data.size();
}
private int attributeColumnCount = 0;
private int firstColumnCount = 3;
private int lastColumnCount = 1;
public int getColumnCount() {
return firstColumnCount + attributeColumnCount + lastColumnCount;
}
public List getColourList()
{
return colourList;
}
public Object getValueAt(int rowIndex, int columnIndex) {
if (columnIndex == 0)
{
return markedList.get(rowIndex);
}
else if(columnIndex == 1)
{
return ((AttributedFile)data.get(rowIndex)).getFile();
}
else if (columnIndex == 2)
{
return ((AttributedFile) data.get(rowIndex)).getPath();
}
else if(columnIndex == 3)
{
return ((AttributedFile) data.get(rowIndex)).getDate();
}
else if(columnIndex == attributeColumnCount + firstColumnCount)
{
return iconReveal;
}
else if(columnIndex == 1+attributeColumnCount + firstColumnCount)
{
return iconGear;
}
else if(columnIndex < firstColumnCount + attributeColumnCount)
{
ProcessingPlugin plugin = (ProcessingPlugin) plugins.get(columnIndex - firstColumnCount);
AttributedFile file = (AttributedFile) data.get(rowIndex);
return file.getAttributes().get(plugin);
}
else
return "?";
}
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if (columnIndex == 0 && aValue instanceof Boolean) {
markedList.set(rowIndex, aValue);
}
}
void setResults(List results) {
data = results;
// ProcessingPlugin p = (ProcessingPlugin) plugins.get(columnIndex)
markedList = new ArrayList(results.size());
for (int i = 0; i < results.size(); i++) {
markedList.add(new Boolean(false));
}
colourScheme(data);
resetColumns();
}
public List getReults()
{
//System.out.println(data.size());
return data;
}
public int returnsize()
{
return data.size();
}
public void setColour(Color c)
{
colourList.add(c);
//System.out.println(colourList.size());
}
public Color getColour(int i)
{
return (Color)colourList.get(i);
}
public int getPlugins()
{
return plugins.size();
}
void setUsedPlugins(List usedPlugins) {
plugins = usedPlugins;
attributeColumnCount = plugins.size();
System.out.println(attributeColumnCount + " plugins count");
}
void resultsWillBeInMode2(boolean mode2) {
isMode2 = mode2;
}
public int compare(Object o1, Object o2) {
if (o1 == null && o2 == null) {
return 0;
}
if (o1 == null) {
return 1;
}
if (o2 == null) {
return -1;
}
AttributedFile a = (AttributedFile) o1;
AttributedFile b = (AttributedFile) o2;
ProcessingPlugin p = (ProcessingPlugin) plugins.get(sorting);
Object aa = a.getAttributes().get(p);
Object bb = b.getAttributes().get(p);
if (aa == null && bb == null) {
return 0;
}
if (aa == null || aa.equals("")) {
return 1;
}
if (bb == null || bb.equals("")) {
return -1;
}
if (aa.equals("") && bb.equals("")) {
return 0;
//System.out.println(aa+"::"+aa.getClass());
}
try {
return ((Attribute) aa).getAttribute().compareTo(bb);
} catch (Exception exception) {
}
return 1;
}
}public class Attribute {
private Comparable attribute;
private boolean highlighted;
public Comparable getAttribute() {
return attribute;
}
public boolean isHighlighted()
{
return highlighted;
}
public void setHighlighted(boolean highlighted)
{
this.highlighted = highlighted;
}
public Attribute(Comparable attribute)
{
this.attribute = attribute;
}
}-Xlint:unchecked Programming stay easier.class ResultsModel extends AbstractTableModel implements Comparator<AttributedFile> {
private List<AttributedFile> data;
private List<ProcessingPlugin> plugins;
private List<Boolean> markedList;
private List<Color> colours;
private boolean isMode2;
private boolean isAdvanced;
private boolean markAll = false;
private int sorting;
...
public class Attribute { private Comparable attribute; private boolean highlighted; public Attribute(Comparable attribute) { this.attribute = attribute; } public Comparable getAttribute() { return attribute; } public boolean isHighlighted() { return highlighted; } public void setHighlighted(boolean highlighted) { this.highlighted = highlighted; } public <?> get(ProcessingPlugin plugin) { // throw new UnsupportedOperationException("Not yet implemented"); } }
public int compare(AttributedFile a, AttributedFile b) {...} and go forward| DaniWeb Message | |
| Cancel Changes | |