Skip to content

Commit 669537a

Browse files
committed
fix up the error table a little more
1 parent fe6c11b commit 669537a

3 files changed

Lines changed: 77 additions & 22 deletions

File tree

app/src/processing/app/ui/ErrorTable.java

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@
2929

3030
import javax.swing.JLabel;
3131
import javax.swing.JTable;
32-
import javax.swing.SwingWorker;
3332
import javax.swing.ToolTipManager;
3433
import javax.swing.table.DefaultTableModel;
3534
import javax.swing.table.JTableHeader;
3635
import javax.swing.table.TableCellRenderer;
37-
import javax.swing.table.TableColumnModel;
38-
import javax.swing.table.TableModel;
36+
import javax.swing.table.TableColumn;
3937

4038
import processing.app.Language;
4139
import processing.app.Messages;
@@ -53,10 +51,16 @@ public class ErrorTable extends JTable {
5351
Language.text("editor.footer.errors.line")
5452
};
5553

56-
int[] columnWidths = { Editor.LEFT_GUTTER, 400, 100, 50 };
54+
//int[] columnWidths = { Editor.LEFT_GUTTER, 400, 100, 50 };
55+
//static final int[] DEFAULT_WIDTHS = { Editor.LEFT_GUTTER, 400, 100, 50 };
5756

58-
/** Is the column being resized? */
59-
private boolean columnResizing = false;
57+
static final int DATA_COLUMN = 0;
58+
static final int PROBLEM_COLUMN = 1;
59+
static final int TAB_COLUMN = 2;
60+
static final int LINE_COLUMN = 3;
61+
62+
// /** Is the column being resized? */
63+
// private boolean columnResizing = false;
6064

6165
Font headerFont;
6266
Color headerColor;
@@ -79,22 +83,25 @@ public ErrorTable(final Editor editor) {
7983
//setShowGrid(false);
8084
setIntercellSpacing(new Dimension(0, 0));
8185

82-
// this did nothing, no columns existed yet
83-
/*
84-
TableColumnModel columnModel = getColumnModel();
85-
for (int i = 0; i < columnModel.getColumnCount(); i++) {
86-
columnModel.getColumn(i).setPreferredWidth(columnWidths[i]);
87-
//System.out.println("class is " + columnModel.getColumn(i).getClass());
88-
}
89-
*/
90-
// DefaultTableModel tm = new DefaultTableModel(columnNames, 0);
86+
// be specific about the width of the first column
87+
TableColumn emptyColumn = columnModel.getColumn(0);
88+
emptyColumn.setMaxWidth(Editor.LEFT_GUTTER);
89+
emptyColumn.setMinWidth(Editor.LEFT_GUTTER);
90+
91+
columnModel.getColumn(PROBLEM_COLUMN).setPreferredWidth(400);
92+
columnModel.getColumn(TAB_COLUMN).setPreferredWidth(100);
93+
columnModel.getColumn(LINE_COLUMN).setPreferredWidth(50);
94+
// // the other columns are just a preference
95+
// for (int i = 1; i < columnModel.getColumnCount(); i++) {
96+
// columnModel.getColumn(i).setPreferredWidth(columnWidths[i]);
97+
// }
9198

9299
addMouseListener(new MouseAdapter() {
93100
@Override
94101
synchronized public void mouseClicked(MouseEvent e) {
95102
try {
96103
int row = ((ErrorTable) e.getSource()).getSelectedRow();
97-
Object data = getModel().getValueAt(row, 0);
104+
Object data = getModel().getValueAt(row, DATA_COLUMN);
98105
int clickCount = e.getClickCount();
99106
if (clickCount == 1) {
100107
editor.errorTableClick(data);
@@ -142,7 +149,9 @@ public void mouseMoved(MouseEvent evt) {
142149
*/
143150

144151
header.setReorderingAllowed(false);
152+
// header.setResizingAllowed(false);
145153

154+
/*
146155
// Handles the resizing of columns. When mouse press is detected on
147156
// table header, Stop updating the table, store new values of column
148157
// widths, and resume updating. Updating is disabled as long as
@@ -164,6 +173,7 @@ public void mouseReleased(MouseEvent e) {
164173
}
165174
}
166175
});
176+
*/
167177

168178
ToolTipManager.sharedInstance().registerComponent(this);
169179
}
@@ -181,16 +191,59 @@ public void addRow(Object data, String message, String filename, String line) {
181191
}
182192

183193

194+
/*
195+
public void updateColumns() {
196+
// figure out the column widths
197+
TableColumnModel columnModel = getColumnModel();
198+
int tabWidth = getMaxColumnWidth(this, TAB_COLUMN);
199+
int lineWidth = getMaxColumnWidth(this, LINE_COLUMN);
200+
int problemWidth = getWidth() - Editor.LEFT_GUTTER - tabWidth - lineWidth;
201+
202+
columnModel.getColumn(DATA_COLUMN).setMaxWidth(Editor.LEFT_GUTTER);
203+
columnModel.getColumn(TAB_COLUMN).setMaxWidth(tabWidth);
204+
columnModel.getColumn(LINE_COLUMN).setMaxWidth(lineWidth);
205+
columnModel.getColumn(PROBLEM_COLUMN).setMaxWidth(problemWidth);
206+
207+
// System.out.println(tabWidth + " " + lineWidth + " " + problemWidth);
208+
209+
// for (int i = 0; i < columnModel.getColumnCount(); i++) {
210+
// columnModel.getColumn(i).setPreferredWidth(columnWidths[i]);
211+
// }
212+
}
213+
214+
215+
static private int getMaxColumnWidth(JTable table, int col) {
216+
TableCellRenderer renderer =
217+
table.getTableHeader().getDefaultRenderer();
218+
Component comp =
219+
renderer.getTableCellRendererComponent(table, columnNames[col],
220+
false, false, 0, col);
221+
int maxWidth = comp.getPreferredSize().width;
222+
223+
// TableColumn column = table.getColumnModel().getColumn(col);
224+
// renderer = column.getCellRenderer();
225+
renderer = table.getDefaultRenderer(Object.class);
226+
// System.out.println("renderer is " + renderer);
227+
228+
for (int row = 0; row < table.getModel().getRowCount(); row++) {
229+
Object value = table.getModel().getValueAt(row, col);
230+
comp = renderer.getTableCellRendererComponent(table, value,
231+
false, false, row, col);
232+
double valueWidth = comp.getPreferredSize().getWidth();
233+
maxWidth = (int) Math.max(maxWidth, valueWidth);
234+
}
235+
return maxWidth;
236+
}
237+
*/
238+
239+
184240
@Override
185241
public boolean isCellEditable(int rowIndex, int colIndex) {
186242
return false; // Disallow the editing of any cell
187243
}
188244

189245

190-
/**
191-
* Updates table contents with new data
192-
* @return boolean - If table data was updated
193-
*/
246+
/*
194247
synchronized public boolean updateTable(final TableModel tableModel) {
195248
if (!isVisible()) return false;
196249
@@ -229,6 +282,7 @@ protected void done() {
229282
}
230283
return true;
231284
}
285+
*/
232286

233287

234288
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
@@ -289,7 +343,7 @@ public Component getTableCellRendererComponent(JTable table, Object value,
289343
setForeground(textColor);
290344
setBackground(bgColor);
291345
}
292-
if (column == 0 || value == null) {
346+
if (column == DATA_COLUMN || value == null) {
293347
setText("");
294348
} else {
295349
setText(value.toString());

java/src/processing/mode/java/JavaEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public void rebuild() {
194194
@Override
195195
public EditorFooter createFooter() {
196196
EditorFooter footer = super.createFooter();
197-
addErrorTable();
197+
addErrorTable(footer);
198198
return footer;
199199
}
200200

java/src/processing/mode/java/pdex/ErrorCheckerService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ public void updateErrorTable() {
956956
// }
957957

958958
}
959+
// table.updateColumns();
959960

960961
// DefaultTableModel tm =
961962
// new DefaultTableModel(errorData, XQErrorTable.columnNames);

0 commit comments

Comments
 (0)