gui: fix cell renderer in search dialog (#271)
This commit is contained in:
@@ -14,6 +14,7 @@ import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -146,7 +147,8 @@ public abstract class CommonSearchDialog extends JDialog {
|
||||
ResultsTableCellRenderer renderer = new ResultsTableCellRenderer();
|
||||
resultsModel = new ResultsModel(renderer);
|
||||
resultsModel.addTableModelListener(e -> updateProgressLabel());
|
||||
resultsTable = new ResultsTable(resultsModel);
|
||||
|
||||
resultsTable = new ResultsTable(resultsModel, renderer);
|
||||
resultsTable.setShowHorizontalLines(false);
|
||||
resultsTable.setDragEnabled(false);
|
||||
resultsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
@@ -154,7 +156,13 @@ public abstract class CommonSearchDialog extends JDialog {
|
||||
resultsTable.setColumnSelectionAllowed(false);
|
||||
resultsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
resultsTable.setAutoscrolls(false);
|
||||
|
||||
resultsTable.setDefaultRenderer(Object.class, renderer);
|
||||
Enumeration<TableColumn> columns = resultsTable.getColumnModel().getColumns();
|
||||
while (columns.hasMoreElements()) {
|
||||
TableColumn column = columns.nextElement();
|
||||
column.setCellRenderer(renderer);
|
||||
}
|
||||
|
||||
resultsTable.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
@@ -192,17 +200,17 @@ public abstract class CommonSearchDialog extends JDialog {
|
||||
JButton nextPageButton = new JButton("->");
|
||||
nextPageButton.setToolTipText(NLS.str("search_dialog.next_page"));
|
||||
nextPageButton.addActionListener(e -> {
|
||||
resultsModel.nextPage();
|
||||
resultsTable.updateTable();
|
||||
resultsTable.scrollRectToVisible(new Rectangle(0, 0, 1, 1));
|
||||
if (resultsModel.nextPage()) {
|
||||
switchPage(renderer);
|
||||
}
|
||||
});
|
||||
|
||||
JButton prevPageButton = new JButton("<-");
|
||||
prevPageButton.setToolTipText(NLS.str("search_dialog.prev_page"));
|
||||
prevPageButton.addActionListener(e -> {
|
||||
resultsModel.prevPage();
|
||||
resultsTable.updateTable();
|
||||
resultsTable.scrollRectToVisible(new Rectangle(0, 0, 1, 1));
|
||||
if (resultsModel.prevPage()) {
|
||||
switchPage(renderer);
|
||||
}
|
||||
});
|
||||
|
||||
paginationPanel.add(prevPageButton);
|
||||
@@ -214,6 +222,13 @@ public abstract class CommonSearchDialog extends JDialog {
|
||||
return resultsPanel;
|
||||
}
|
||||
|
||||
private void switchPage(ResultsTableCellRenderer renderer) {
|
||||
renderer.clear();
|
||||
resultsTable.updateTable();
|
||||
updateProgressLabel();
|
||||
resultsTable.scrollRectToVisible(new Rectangle(0, 0, 1, 1));
|
||||
}
|
||||
|
||||
protected void updateProgressLabel() {
|
||||
String statusText = String.format(
|
||||
NLS.str("search_dialog.info_label"),
|
||||
@@ -226,9 +241,11 @@ public abstract class CommonSearchDialog extends JDialog {
|
||||
|
||||
protected static class ResultsTable extends JTable {
|
||||
private static final long serialVersionUID = 3901184054736618969L;
|
||||
private final transient ResultsTableCellRenderer renderer;
|
||||
|
||||
public ResultsTable(ResultsModel resultsModel) {
|
||||
public ResultsTable(ResultsModel resultsModel, ResultsTableCellRenderer renderer) {
|
||||
super(resultsModel);
|
||||
this.renderer = renderer;
|
||||
}
|
||||
|
||||
public void updateTable() {
|
||||
@@ -246,7 +263,6 @@ public abstract class CommonSearchDialog extends JDialog {
|
||||
for (int col = 0; col < columnCount; col++) {
|
||||
int colWidth = 50;
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
TableCellRenderer renderer = getCellRenderer(row, col);
|
||||
Component comp = prepareRenderer(renderer, row, col);
|
||||
if (comp == null) {
|
||||
continue;
|
||||
@@ -324,20 +340,20 @@ public abstract class CommonSearchDialog extends JDialog {
|
||||
return Math.min(rows.size(), start + RESULTS_PER_PAGE);
|
||||
}
|
||||
|
||||
public void nextPage() {
|
||||
public boolean nextPage() {
|
||||
if (start + RESULTS_PER_PAGE < rows.size()) {
|
||||
renderer.clear();
|
||||
start += RESULTS_PER_PAGE;
|
||||
fireTableStructureChanged();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void prevPage() {
|
||||
public boolean prevPage() {
|
||||
if (start - RESULTS_PER_PAGE >= 0) {
|
||||
renderer.clear();
|
||||
start -= RESULTS_PER_PAGE;
|
||||
fireTableStructureChanged();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -345,7 +361,7 @@ public abstract class CommonSearchDialog extends JDialog {
|
||||
if (rows.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
return getDisplayedResultsEnd() - getDisplayedResultsStart();
|
||||
return getDisplayedResultsEnd() - start;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user