mirror of
https://github.com/processing/processing4.git
synced 2026-01-30 03:41:15 +01:00
fix up the error table a little more
This commit is contained in:
@@ -29,13 +29,11 @@ import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.ToolTipManager;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.JTableHeader;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
import javax.swing.table.TableModel;
|
||||
import javax.swing.table.TableColumn;
|
||||
|
||||
import processing.app.Language;
|
||||
import processing.app.Messages;
|
||||
@@ -53,10 +51,16 @@ public class ErrorTable extends JTable {
|
||||
Language.text("editor.footer.errors.line")
|
||||
};
|
||||
|
||||
int[] columnWidths = { Editor.LEFT_GUTTER, 400, 100, 50 };
|
||||
//int[] columnWidths = { Editor.LEFT_GUTTER, 400, 100, 50 };
|
||||
//static final int[] DEFAULT_WIDTHS = { Editor.LEFT_GUTTER, 400, 100, 50 };
|
||||
|
||||
/** Is the column being resized? */
|
||||
private boolean columnResizing = false;
|
||||
static final int DATA_COLUMN = 0;
|
||||
static final int PROBLEM_COLUMN = 1;
|
||||
static final int TAB_COLUMN = 2;
|
||||
static final int LINE_COLUMN = 3;
|
||||
|
||||
// /** Is the column being resized? */
|
||||
// private boolean columnResizing = false;
|
||||
|
||||
Font headerFont;
|
||||
Color headerColor;
|
||||
@@ -79,22 +83,25 @@ public class ErrorTable extends JTable {
|
||||
//setShowGrid(false);
|
||||
setIntercellSpacing(new Dimension(0, 0));
|
||||
|
||||
// this did nothing, no columns existed yet
|
||||
/*
|
||||
TableColumnModel columnModel = getColumnModel();
|
||||
for (int i = 0; i < columnModel.getColumnCount(); i++) {
|
||||
columnModel.getColumn(i).setPreferredWidth(columnWidths[i]);
|
||||
//System.out.println("class is " + columnModel.getColumn(i).getClass());
|
||||
}
|
||||
*/
|
||||
// DefaultTableModel tm = new DefaultTableModel(columnNames, 0);
|
||||
// be specific about the width of the first column
|
||||
TableColumn emptyColumn = columnModel.getColumn(0);
|
||||
emptyColumn.setMaxWidth(Editor.LEFT_GUTTER);
|
||||
emptyColumn.setMinWidth(Editor.LEFT_GUTTER);
|
||||
|
||||
columnModel.getColumn(PROBLEM_COLUMN).setPreferredWidth(400);
|
||||
columnModel.getColumn(TAB_COLUMN).setPreferredWidth(100);
|
||||
columnModel.getColumn(LINE_COLUMN).setPreferredWidth(50);
|
||||
// // the other columns are just a preference
|
||||
// for (int i = 1; i < columnModel.getColumnCount(); i++) {
|
||||
// columnModel.getColumn(i).setPreferredWidth(columnWidths[i]);
|
||||
// }
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
synchronized public void mouseClicked(MouseEvent e) {
|
||||
try {
|
||||
int row = ((ErrorTable) e.getSource()).getSelectedRow();
|
||||
Object data = getModel().getValueAt(row, 0);
|
||||
Object data = getModel().getValueAt(row, DATA_COLUMN);
|
||||
int clickCount = e.getClickCount();
|
||||
if (clickCount == 1) {
|
||||
editor.errorTableClick(data);
|
||||
@@ -142,7 +149,9 @@ public class ErrorTable extends JTable {
|
||||
*/
|
||||
|
||||
header.setReorderingAllowed(false);
|
||||
// header.setResizingAllowed(false);
|
||||
|
||||
/*
|
||||
// Handles the resizing of columns. When mouse press is detected on
|
||||
// table header, Stop updating the table, store new values of column
|
||||
// widths, and resume updating. Updating is disabled as long as
|
||||
@@ -164,6 +173,7 @@ public class ErrorTable extends JTable {
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
ToolTipManager.sharedInstance().registerComponent(this);
|
||||
}
|
||||
@@ -181,16 +191,59 @@ public class ErrorTable extends JTable {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void updateColumns() {
|
||||
// figure out the column widths
|
||||
TableColumnModel columnModel = getColumnModel();
|
||||
int tabWidth = getMaxColumnWidth(this, TAB_COLUMN);
|
||||
int lineWidth = getMaxColumnWidth(this, LINE_COLUMN);
|
||||
int problemWidth = getWidth() - Editor.LEFT_GUTTER - tabWidth - lineWidth;
|
||||
|
||||
columnModel.getColumn(DATA_COLUMN).setMaxWidth(Editor.LEFT_GUTTER);
|
||||
columnModel.getColumn(TAB_COLUMN).setMaxWidth(tabWidth);
|
||||
columnModel.getColumn(LINE_COLUMN).setMaxWidth(lineWidth);
|
||||
columnModel.getColumn(PROBLEM_COLUMN).setMaxWidth(problemWidth);
|
||||
|
||||
// System.out.println(tabWidth + " " + lineWidth + " " + problemWidth);
|
||||
|
||||
// for (int i = 0; i < columnModel.getColumnCount(); i++) {
|
||||
// columnModel.getColumn(i).setPreferredWidth(columnWidths[i]);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
static private int getMaxColumnWidth(JTable table, int col) {
|
||||
TableCellRenderer renderer =
|
||||
table.getTableHeader().getDefaultRenderer();
|
||||
Component comp =
|
||||
renderer.getTableCellRendererComponent(table, columnNames[col],
|
||||
false, false, 0, col);
|
||||
int maxWidth = comp.getPreferredSize().width;
|
||||
|
||||
// TableColumn column = table.getColumnModel().getColumn(col);
|
||||
// renderer = column.getCellRenderer();
|
||||
renderer = table.getDefaultRenderer(Object.class);
|
||||
// System.out.println("renderer is " + renderer);
|
||||
|
||||
for (int row = 0; row < table.getModel().getRowCount(); row++) {
|
||||
Object value = table.getModel().getValueAt(row, col);
|
||||
comp = renderer.getTableCellRendererComponent(table, value,
|
||||
false, false, row, col);
|
||||
double valueWidth = comp.getPreferredSize().getWidth();
|
||||
maxWidth = (int) Math.max(maxWidth, valueWidth);
|
||||
}
|
||||
return maxWidth;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int rowIndex, int colIndex) {
|
||||
return false; // Disallow the editing of any cell
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates table contents with new data
|
||||
* @return boolean - If table data was updated
|
||||
*/
|
||||
/*
|
||||
synchronized public boolean updateTable(final TableModel tableModel) {
|
||||
if (!isVisible()) return false;
|
||||
|
||||
@@ -229,6 +282,7 @@ public class ErrorTable extends JTable {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
@@ -289,7 +343,7 @@ public class ErrorTable extends JTable {
|
||||
setForeground(textColor);
|
||||
setBackground(bgColor);
|
||||
}
|
||||
if (column == 0 || value == null) {
|
||||
if (column == DATA_COLUMN || value == null) {
|
||||
setText("");
|
||||
} else {
|
||||
setText(value.toString());
|
||||
|
||||
@@ -194,7 +194,7 @@ public class JavaEditor extends Editor {
|
||||
@Override
|
||||
public EditorFooter createFooter() {
|
||||
EditorFooter footer = super.createFooter();
|
||||
addErrorTable();
|
||||
addErrorTable(footer);
|
||||
return footer;
|
||||
}
|
||||
|
||||
|
||||
@@ -956,6 +956,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
// }
|
||||
|
||||
}
|
||||
// table.updateColumns();
|
||||
|
||||
// DefaultTableModel tm =
|
||||
// new DefaultTableModel(errorData, XQErrorTable.columnNames);
|
||||
|
||||
Reference in New Issue
Block a user