001: package tide.editor.linemessages;
002:
003: import java.awt.event.*;
004: import snow.utils.gui.CloseControlPanel;
005: import java.awt.BorderLayout;
006: import snow.sortabletable.*;
007: import java.util.*;
008: import javax.swing.*;
009:
010: /** Overview of all encountered categories. User can define or remove relevance.
011: */
012: public final class CategoriesTable extends FineGrainTableModel {
013: final private List<Category> cats = new ArrayList<Category>();
014: final private static String[] COLUMN_NAMES = { "Relevant",
015: "Category" };
016: final private static int[] COLUMN_PREFERED_SIZES = { 2, 40 };
017:
018: public Object getValueAt(int row, int column) {
019: if (column == 0)
020: return cats.get(row).isRelevant;
021: if (column == 1)
022: return cats.get(row).name;
023: return "?";
024: }
025:
026: public int getRowCount() {
027: return cats.size();
028: }
029:
030: public int getColumnCount() {
031: return 2;
032: }
033:
034: public void update() {
035: fireTableDataChanged();
036: fireTableModelHasChanged();
037: }
038:
039: @Override
040: public String getColumnName(int column) {
041: if (column >= 0 && column < COLUMN_NAMES.length)
042: return COLUMN_NAMES[column];
043: return "??";
044: }
045:
046: @Override
047: public int getPreferredColumnWidth(int column) {
048: if (column >= 0 && column < COLUMN_PREFERED_SIZES.length)
049: return COLUMN_PREFERED_SIZES[column];
050: return -1;
051: }
052:
053: void clear() {
054: cats.clear();
055: }
056:
057: private CategoriesTable() {
058: for (String rc : LineMessagesManager.getInstance()
059: .getRelevantCategories()) {
060: cats.add(new Category(rc, -1, true));
061: }
062: for (String rc : LineMessagesManager.getInstance()
063: .getIrrelevantCategories()) {
064: cats.add(new Category(rc, -1, false));
065: }
066:
067: }
068:
069: public static void showTable(JFrame parent) {
070: JDialog d = new JDialog(parent, "Messages categories", true);
071: d.setSize(600, 600);
072: d.setLocationRelativeTo(null);
073:
074: final CategoriesTable tm = new CategoriesTable();
075: final SortableTableModel stm = new SortableTableModel(tm);
076: final JTable table = new JTable(stm);
077: table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
078: stm.installGUI(table);
079:
080: d.add(new JScrollPane(table), BorderLayout.CENTER);
081: CloseControlPanel ccp = new CloseControlPanel(d, false, false,
082: "Close");
083: d.add(ccp, BorderLayout.SOUTH);
084:
085: MultiSearchPanel asp = new MultiSearchPanel("Filter: ", null,
086: stm);
087: d.add(asp, BorderLayout.NORTH);
088:
089: table.addMouseListener(new MouseAdapter() {
090: @Override
091: public void mousePressed(MouseEvent me) {
092: // TODO::: popup "remove" action, ...
093: }
094:
095: @Override
096: public void mouseReleased(MouseEvent me) {
097: }
098: });
099:
100: d.setVisible(true); // MODAL
101: stm.terminate();
102: tm.clear();
103: }
104:
105: @net.jcip.annotations.Immutable
106: // maybe temporary !
107: static class Category {
108: final String name;
109: final int count;
110: final boolean isRelevant;
111:
112: public Category(String name, int count, boolean isRelevant) {
113: this.name = name;
114: this.count = count;
115: this.isRelevant = isRelevant;
116: }
117: }
118:
119: }
|