/programy/Java/AVRcamVIEW/src/avr/swing/table/LogTableCellRenderer.java |
---|
0,0 → 1,126 |
/* |
AVRcamVIEW: A PC application to test out the functionallity of the |
AVRcam real-time image processing engine. |
Copyright (C) 2004 Brent A. Taylor |
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 (at your option) 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 |
For more information on the AVRcamVIEW, please contact: |
taylorba@comcast.net |
or go to www.jrobot.net for more details regarding the system. |
*/ |
package avr.swing.table; |
import java.awt.*; |
import java.text.*; |
import java.util.*; |
import java.util.logging.*; |
import javax.swing.*; |
import javax.swing.table.DefaultTableCellRenderer; |
public class LogTableCellRenderer extends DefaultTableCellRenderer { |
private Color defaultBackground; |
private Color defaultForeground; |
private static final DateFormat DATE_FORMAT; |
static { |
DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss.SSS"); |
} |
public LogTableCellRenderer() { |
super(); |
defaultBackground = getBackground(); |
defaultForeground = getForeground(); |
} |
public Component getTableCellRendererComponent(JTable table, Object value, |
boolean isSelected, boolean hasFocus, int row, int column) { |
String text = null; |
switch(column) { |
case 0: |
text = DATE_FORMAT.format(new Date(((LogRecord)value).getMillis())); |
break; |
case 1: |
text = ((LogRecord)value).getLevel().toString(); |
break; |
case 2: |
LogRecord record = (LogRecord)value; |
if(record.getMessage() == null) { |
text = "No Message..."; |
} else { |
text = record.getMessage(); |
} |
if(!(text.startsWith("Sending") || text.startsWith("Received"))) { |
StringBuffer buffer = new StringBuffer(text); |
buffer.append(" "); |
if(record.getSourceClassName() != null) { |
buffer.append(record.getSourceClassName()); |
} |
if(record.getSourceMethodName() != null) { |
buffer.append(":"); |
buffer.append(record.getSourceMethodName()); |
} |
buffer.append(" "); |
text = buffer.toString(); |
} |
break; |
} |
super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column); |
if(!isSelected) { |
if(((LogRecord)value).getLevel().equals(Level.SEVERE)) { |
setBackground(Color.RED.darker()); |
setForeground(Color.WHITE); |
} else if(((LogRecord)value).getLevel().equals(Level.WARNING)) { |
setBackground(Color.ORANGE); |
setForeground(Color.BLACK); |
} else if(((LogRecord)value).getLevel().equals(Level.INFO)) { |
setBackground(Color.YELLOW); |
setForeground(Color.BLACK); |
} else if(((LogRecord)value).getLevel().equals(Level.CONFIG)) { |
setBackground(Color.CYAN); |
setForeground(Color.BLACK); |
} else { |
setBackground(defaultBackground); |
setForeground(defaultForeground); |
} |
} |
if(column != 2) { |
setHorizontalAlignment(JLabel.CENTER); |
} else { |
setHorizontalAlignment(JLabel.LEFT); |
} |
return this; |
} |
} |
/programy/Java/AVRcamVIEW/src/avr/swing/table/LogTableModel.java |
---|
0,0 → 1,131 |
/* |
AVRcamVIEW: A PC application to test out the functionallity of the |
AVRcam real-time image processing engine. |
Copyright (C) 2004 Brent A. Taylor |
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 (at your option) 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 |
For more information on the AVRcamVIEW, please contact: |
taylorba@comcast.net |
or go to www.jrobot.net for more details regarding the system. |
*/ |
package avr.swing.table; |
import java.util.*; |
import java.util.logging.*; |
import javax.swing.table.*; |
public class LogTableModel extends AbstractTableModel { |
public static final String[] COLUMN_NAMES = { |
"Time Stamp", |
"Level", |
"Message" |
}; |
private List allRecords; |
private List filteredRecords; |
private Level level; |
private boolean selectedLabel; |
public LogTableModel(Level filterLevel) { |
this(filterLevel, false); |
} |
public LogTableModel(Level filterLevel, boolean selectedLabel) { |
super(); |
allRecords = new ArrayList(10); |
filteredRecords = new ArrayList(10); |
this.level = filterLevel; |
} |
public void setFilter(Level level) { |
this.level = level; |
filteredRecords = new ArrayList(allRecords.size()); |
Iterator i = allRecords.iterator(); |
LogRecord record = null; |
while(i.hasNext()) { |
record = (LogRecord)i.next(); |
if(selectedLabel) { |
if(level.intValue() == record.getLevel().intValue()) { |
filteredRecords.add(record); |
} |
} else { |
if(level.intValue() <= record.getLevel().intValue()) { |
filteredRecords.add(record); |
} |
} |
} |
fireTableDataChanged(); |
} |
public void setOnlyShowSelectedLevel(boolean selectedLabel) { |
this.selectedLabel = selectedLabel; |
setFilter(level); |
} |
public void addRecord(LogRecord record) { |
allRecords.add(record); |
if(selectedLabel) { |
if(level.intValue() == record.getLevel().intValue()) { |
filteredRecords.add(record); |
} |
} else { |
if(level.intValue() <= record.getLevel().intValue()) { |
filteredRecords.add(record); |
} |
} |
this.fireTableRowsInserted(filteredRecords.size() - 1, filteredRecords.size() - 1); |
} |
public void clear() { |
allRecords.clear(); |
filteredRecords.clear(); |
fireTableDataChanged(); |
} |
public int getRowCount() { |
return filteredRecords.size(); |
} |
public int getColumnCount() { |
return COLUMN_NAMES.length; |
} |
public String getColumnName(int col) { |
return COLUMN_NAMES[col]; |
} |
public Class getColumnClass(int col) { |
return String.class; |
} |
public Object getValueAt(int rowIndex, int columnIndex) { |
return filteredRecords.get(rowIndex); |
} |
public LogRecord getRecord(int row) { |
return (LogRecord)allRecords.get(row); |
} |
public int getRecordCount() { |
return allRecords.size(); |
} |
} |