Author: jflesch
Date: 2007-05-01 02:23:07 +0000 (Tue, 01 May 2007)
New Revision: 13071
Added:
trunk/apps/Thaw/src/thaw/gui/Table.java
Modified:
trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java
trunk/apps/Thaw/src/thaw/plugins/index/Tables.java
trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
Log:
Thaw can now remember all the column sizes and alternate the background color
for each row in all the JTables
Added: trunk/apps/Thaw/src/thaw/gui/Table.java
===================================================================
--- trunk/apps/Thaw/src/thaw/gui/Table.java (rev 0)
+++ trunk/apps/Thaw/src/thaw/gui/Table.java 2007-05-01 02:23:07 UTC (rev
13071)
@@ -0,0 +1,303 @@
+package thaw.gui;
+
+
+import javax.swing.table.TableModel;
+import javax.swing.table.TableColumn;
+import javax.swing.table.TableColumnModel;
+import javax.swing.event.TableColumnModelListener;
+import javax.swing.event.TableColumnModelEvent;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ChangeEvent;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.ListSelectionModel;
+import javax.swing.JTable;
+import javax.swing.JProgressBar;
+import java.awt.Color;
+import java.awt.Component;
+
+import java.util.Vector;
+
+
+import thaw.core.Logger;
+import thaw.core.Config;
+import thaw.core.I18n;
+
+import thaw.fcp.FCPTransferQuery;
+import thaw.fcp.FCPClientPut;
+import thaw.fcp.FCPClientGet;
+
+
+/**
+ * Inherits from JTable:
+ * Just add to usual JTable the capacity to store the columns sizes
+ * in the thaw configuration
+ */
+public class Table extends JTable implements TableColumnModelListener,
Runnable {
+
+ private Config config;
+ private String configPrefix;
+
+ public final static int TIME_BEFORE_SAVING = 500; /* in ms */
+ private boolean hasChanged = false;
+ private Thread savingThread;
+
+
+ public Table(Config config, String prefix) {
+ super();
+ setDefaultRenderer();
+ setConfigPrefix(config, prefix);
+ setAsListener();
+ }
+
+
+ public Table(Config config, String prefix, int numRows, int numColumns)
{
+ super(numRows, numColumns);
+ setDefaultRenderer();
+ setConfigPrefix(config, prefix);
+ setAsListener();
+ }
+
+
+ public Table(Config config, String prefix, Object[][] data, Object[]
columnNames) {
+ super(data, columnNames);
+ setDefaultRenderer();
+ setConfigPrefix(config, prefix);
+ setAsListener();
+ }
+
+
+ public Table(Config config, String prefix, TableModel model) {
+ super(model);
+ setDefaultRenderer();
+ setConfigPrefix(config, prefix);
+ setAsListener();
+ }
+
+ public Table(Config config, String prefix,
+ TableModel model, TableColumnModel cModel) {
+ super(model, cModel);
+ setDefaultRenderer();
+ setConfigPrefix(config, prefix);
+ setAsListener();
+ }
+
+ public Table(Config config, String prefix,
+ TableModel model, TableColumnModel cModel,
+ ListSelectionModel lModel) {
+ super(model, cModel, lModel);
+ setDefaultRenderer();
+ setConfigPrefix(config, prefix);
+ setAsListener();
+ }
+
+
+ public Table(Config config, String prefix, Vector data, Vector columns)
{
+ super(data, columns);
+ setDefaultRenderer();
+ setConfigPrefix(config, prefix);
+ setAsListener();
+ }
+
+
+ public void setDefaultRenderer() {
+ setDefaultRenderer(getColumnClass(0), new DefaultRenderer());
+ }
+
+
+
+ /**
+ * @param prefix prefix used in the configuration file to make the diff
with
+ * with the other tables
+ */
+ public void setConfigPrefix(Config config, String prefix) {
+ this.configPrefix = prefix;
+ this.config = config;
+ loadColumnSizes();
+ }
+
+
+ public void setColumnModel(TableColumnModel m) {
+ super.setColumnModel(m);
+ loadColumnSizes();
+ }
+
+
+ public void setModel(TableModel m) {
+ super.setModel(m);
+
+ if (config != null)
+ loadColumnSizes();
+ }
+
+
+ protected void setAsListener() {
+ super.getColumnModel().addColumnModelListener(this);
+ }
+
+
+
+ protected class DefaultRenderer extends DefaultTableCellRenderer {
+ private final static long serialVersionUID = 20060821;
+
+ private Color softGray;
+
+ public DefaultRenderer() {
+ softGray = new Color(240,240,240);
+ }
+
+ public Component getTableCellRendererComponent(final JTable
table, final Object value,
+ final boolean
isSelected, final boolean hasFocus,
+ final int row,
final int column) {
+
+ if(value == null)
+ return
super.getTableCellRendererComponent(table, "",
+
isSelected, hasFocus, row, column);
+
+ if(value instanceof FCPTransferQuery) {
+ final FCPTransferQuery query =
(FCPTransferQuery)value;
+ final JProgressBar bar = new JProgressBar(0,
100);
+
+ int progress;
+
+ bar.setStringPainted(true);
+ bar.setBorderPainted(false);
+
+ if ((query instanceof FCPClientPut &&
(query.getTransferWithTheNodeProgression() < 100))
+ || ((query instanceof FCPClientGet) &&
(query.getTransferWithTheNodeProgression() > 0)))
+ progress =
query.getTransferWithTheNodeProgression();
+ else
+ progress = query.getProgression();
+
+ bar.setValue(progress);
+
+ if(query.isFinished() && !query.isSuccessful())
+
bar.setString(I18n.getMessage("thaw.common.failed"));
+
+ if(query.isFinished() && query.isSuccessful())
+
bar.setString(I18n.getMessage("thaw.common.ok"));
+
+ if(!query.isFinished()) {
+ bar.setString(query.getStatus() +
+ " [
"+Integer.toString(progress)+"% ]");
+ }
+
+ return bar;
+ }
+
+ Component cell;
+
+ if(value instanceof Long) {
+
+ cell =
super.getTableCellRendererComponent(table,
+
thaw.gui.GUIHelper.getPrintableSize(((Long)value).longValue()),
+
isSelected, hasFocus, row, column);
+
+ } else {
+
+ cell =
super.getTableCellRendererComponent(table, value,
+
isSelected, hasFocus,
+ row,
column);
+
+ }
+
+ if (!isSelected) {
+ if (row % 2 == 0)
+ cell.setBackground(Color.WHITE);
+ else
+ cell.setBackground(softGray);
+ }
+ return cell;
+ }
+
+ }
+
+
+
+
+ public void columnAdded(TableColumnModelEvent e) {
+ super.resizeAndRepaint();
+ }
+
+ public void columnMarginChanged(ChangeEvent e) {
+ /* I don't know why I must call this function, but if I don't,
+ * the display is not refreshed as it should
+ */
+ super.resizeAndRepaint();
+ saveColumnSizes();
+ }
+
+ public void columnMoved(TableColumnModelEvent e) {
+ super.resizeAndRepaint();
+ }
+
+ public void columnRemoved(TableColumnModelEvent e) {
+ super.resizeAndRepaint();
+ }
+
+ public void columnSelectionChanged(ListSelectionEvent e) {
+ super.resizeAndRepaint();
+ }
+
+
+
+
+
+
+ public void loadColumnSizes() {
+ TableColumnModel m = super.getColumnModel();
+
+ int nmb = m.getColumnCount();
+
+ for (int i = 0 ; i < nmb ; i++) {
+ TableColumn c = m.getColumn(i);
+ String size =
config.getValue(configPrefix+"_col_width_"+Integer.toString(i));
+
+ if (size != null) {
+ c.setPreferredWidth(Integer.parseInt(size));
+ }
+ }
+ }
+
+
+ public void saveColumnSizes() {
+ hasChanged = true;
+
+ if (savingThread == null) {
+ savingThread = new Thread(this);
+ savingThread.start();
+ }
+ }
+
+
+ public void run() {
+ do {
+ hasChanged = false;
+
+ try {
+ Thread.sleep(TIME_BEFORE_SAVING);
+ } catch(java.lang.InterruptedException e) {
+ /* \_o< */
+ }
+
+ if (!hasChanged) {
+ savingThread = null;
+ reallySaveColumnSize();
+ return;
+ }
+ } while(hasChanged);
+
+ }
+
+
+ public void reallySaveColumnSize() {
+ TableColumnModel m = super.getColumnModel();
+
+ int nmb = m.getColumnCount();
+
+ for (int i = 0 ; i < nmb ; i++) {
+ TableColumn c = m.getColumn(i);
+
config.setValue(configPrefix+"_col_width_"+Integer.toString(i),
+ Integer.toString(c.getWidth()));
+ }
+ }
+}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java 2007-04-30
23:39:20 UTC (rev 13070)
+++ trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java 2007-05-01
02:23:07 UTC (rev 13071)
@@ -37,13 +37,14 @@
import thaw.fcp.FCPQueueManager;
import thaw.fcp.FCPTransferQuery;
import thaw.plugins.ToolbarModifier;
+import thaw.gui.Table;
public class FileTable implements MouseListener, KeyListener, ActionListener {
private final JPanel panel;
- private final JTable table;
+ private final Table table;
private FileListModel fileListModel;
private FileList fileList;
@@ -85,9 +86,9 @@
this.queueManager = queueManager;
fileListModel = new FileListModel();
- table = new JTable(fileListModel);
+ table = new Table(config, "index_file_table", fileListModel);
table.setShowGrid(false);
- table.setDefaultRenderer( table.getColumnClass(0), new
FileRenderer() );
+ table.setIntercellSpacing(new java.awt.Dimension(0, 0));
table.addMouseListener(this);
@@ -417,82 +418,6 @@
}
- private class FileRenderer extends DefaultTableCellRenderer {
- private final static long serialVersionUID = 20060821;
-
- private Color softGray;
-
- public FileRenderer() {
- softGray = new Color(240,240,240);
- }
-
- public Component getTableCellRendererComponent(final JTable
table, final Object value,
- final boolean
isSelected, final boolean hasFocus,
- final int row,
final int column) {
-
- if(value == null)
- return
super.getTableCellRendererComponent(table, "",
-
isSelected, hasFocus, row, column);
-
- if(value instanceof FCPTransferQuery) {
- final FCPTransferQuery query =
(FCPTransferQuery)value;
- final JProgressBar bar = new JProgressBar(0,
100);
-
- int progress;
-
- bar.setStringPainted(true);
- bar.setBorderPainted(false);
-
- if ((query instanceof FCPClientPut &&
(query.getTransferWithTheNodeProgression() < 100))
- || ((query instanceof FCPClientGet) &&
(query.getTransferWithTheNodeProgression() > 0)))
- progress =
query.getTransferWithTheNodeProgression();
- else
- progress = query.getProgression();
-
- bar.setValue(progress);
-
- if(query.isFinished() && !query.isSuccessful())
-
bar.setString(I18n.getMessage("thaw.common.failed"));
-
- if(query.isFinished() && query.isSuccessful())
-
bar.setString(I18n.getMessage("thaw.common.ok"));
-
- if(!query.isFinished()) {
- bar.setString(query.getStatus() +
- " [
"+Integer.toString(progress)+"% ]");
- }
-
- return bar;
- }
-
- Component cell;
-
- if(value instanceof Long) {
-
- cell =
super.getTableCellRendererComponent(table,
-
thaw.gui.GUIHelper.getPrintableSize(((Long)value).longValue()),
-
isSelected, hasFocus, row, column);
-
- } else {
-
- cell =
super.getTableCellRendererComponent(table, value,
-
isSelected, hasFocus,
- row,
column);
-
- }
-
- if (!isSelected) {
- if (row % 2 == 0)
- cell.setBackground(Color.WHITE);
- else
- cell.setBackground(softGray);
- }
- return cell;
- }
-
- }
-
-
private class TransferRefresher implements Runnable {
private boolean running;
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2007-04-30 23:39:20 UTC (rev 13070)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2007-05-01 02:23:07 UTC (rev 13071)
@@ -314,11 +314,11 @@
public String getPublicKey() {
- return publicKeyResult.trim();
+ return publicKeyResult;
}
public String getPrivateKey() {
- return privateKeyResult.trim();
+ return privateKeyResult;
}
public boolean getPublishPrivateKey() {
Modified: trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java 2007-04-30
23:39:20 UTC (rev 13070)
+++ trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java 2007-05-01
02:23:07 UTC (rev 13071)
@@ -31,7 +31,9 @@
import thaw.core.I18n;
import thaw.core.Logger;
+import thaw.core.Config;
import thaw.gui.IconBox;
+import thaw.gui.Table;
import thaw.fcp.FCPQueueManager;
import thaw.plugins.ToolbarModifier;
@@ -39,7 +41,7 @@
public class LinkTable implements MouseListener, KeyListener, ActionListener {
private JPanel panel;
- private JTable table;
+ private Table table;
private LinkListModel linkListModel = null;
private LinkList linkList = null;
@@ -62,13 +64,14 @@
private int firstSelectedLinkCorrespondingIndexId = -1; /* hmm .. I
should make it shorter ... */
- public LinkTable (final FCPQueueManager queueManager, IndexBrowserPanel
indexBrowser) {
+ public LinkTable (final FCPQueueManager queueManager, IndexBrowserPanel
indexBrowser,
+ Config config) {
this.indexBrowser = indexBrowser;
linkListModel = new LinkListModel();
- table = new JTable(linkListModel);
+ table = new Table(config, "index_link_table", linkListModel);
table.setShowGrid(false);
- table.setDefaultRenderer(table.getColumnClass(0), new
LinkRenderer());
+ table.setIntercellSpacing(new java.awt.Dimension(0, 0));
panel = new JPanel();
panel.setLayout(new BorderLayout());
@@ -341,44 +344,5 @@
}
}
-
- private class LinkRenderer extends DefaultTableCellRenderer {
- private final static long serialVersionUID = 20060821;
-
- private Color softGray;
-
- public LinkRenderer() {
- softGray = new Color(240,240,240);
- }
-
- public Component getTableCellRendererComponent(final JTable
table, final Object value,
- final boolean
isSelected, final boolean hasFocus,
- final int row,
final int column) {
-
- if(value == null)
- return
super.getTableCellRendererComponent(table, "",
-
isSelected, hasFocus, row, column);
-
- Component cell;
-
- if(value instanceof Long)
- cell =
super.getTableCellRendererComponent(table,
-
thaw.gui.GUIHelper.getPrintableSize(((Long)value).longValue()),
-
isSelected, hasFocus, row, column);
- else
- cell =
super.getTableCellRendererComponent(table, value,
-
isSelected, hasFocus,
- row,
column);
- if (!isSelected) {
- if (row % 2 == 0)
- cell.setBackground(Color.WHITE);
- else
- cell.setBackground(softGray);
- }
- return cell;
- }
-
- }
-
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Tables.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Tables.java 2007-04-30 23:39:20 UTC
(rev 13070)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Tables.java 2007-05-01 02:23:07 UTC
(rev 13071)
@@ -28,7 +28,7 @@
panel.setLayout(new BorderLayout(10, 10));
fileTable = new FileTable(queueManager, indexBrowser, config);
- linkTable = new LinkTable(queueManager, indexBrowser);
+ linkTable = new LinkTable(queueManager, indexBrowser, config);
searchBar = new SearchBar(indexBrowser);
Modified: trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
2007-04-30 23:39:20 UTC (rev 13070)
+++ trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
2007-05-01 02:23:07 UTC (rev 13071)
@@ -41,6 +41,9 @@
import thaw.core.Logger;
import thaw.fcp.FCPClientGet;
import thaw.fcp.FCPTransferQuery;
+import thaw.gui.Table;
+
+
import thaw.plugins.QueueWatcher;
@@ -58,7 +61,7 @@
private JButton button;
- private JTable table = null;
+ private Table table = null;
private JScrollPane scrollPane = null;
private JPanel panel;
@@ -100,7 +103,9 @@
tableModel = new QueueTableModel(isForInsertionQueue,
core.getQueueManager());
- table = new JTable(tableModel);
+ table = new Table(core.getConfig(),
+ isForInsertionQueue ? "table_insertions" :
"table_downloads",
+ tableModel);
table.setShowGrid(true);
@@ -230,12 +235,12 @@
insertionQueue = isForInsertion;
}
- public Component getTableCellRendererComponent(final JTable
table, final Object value,
+ public Component getTableCellRendererComponent(final JTable
table, Object value,
boolean
isSelected, final boolean hasFocus,
final int row,
final int column) {
if(value == null)
- return null;
+ value = "";
final FCPTransferQuery query = model.getQuery(row);
Modified: trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
2007-04-30 23:39:20 UTC (rev 13070)
+++ trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
2007-05-01 02:23:07 UTC (rev 13071)
@@ -37,6 +37,7 @@
import thaw.gui.IconBox;
import thaw.gui.FileChooser;
+import thaw.gui.Table;
import thaw.plugins.Hsqldb;
@@ -410,7 +411,7 @@
private JDialog dialog;
private IdentityModel model;
- private JTable table;
+ private Table table;
private JButton close;
@@ -431,7 +432,7 @@
model = new IdentityModel();
- table = new JTable(model);
+ table = new Table(config, "other_identities_table",
model);
dialog.getContentPane().add(new JScrollPane(table),
BorderLayout.CENTER);