clean up error/warning handling, differentiate errors/warnings in list (fixes #3406)

This commit is contained in:
Ben Fry
2015-09-24 05:11:04 -04:00
parent 4ea4d58b56
commit 209ea9000a
9 changed files with 179 additions and 295 deletions
+6 -6
View File
@@ -2779,12 +2779,12 @@ public abstract class Editor extends JFrame implements RunnerListener {
}
/**
* Returns the current mode of the editor status bar: NOTICE, ERR or EDIT.
*/
public int getStatusMode() {
return status.mode;
}
// /**
// * Returns the current mode of the editor status bar: NOTICE, ERR or EDIT.
// */
// public int getStatusMode() {
// return status.mode;
// }
/**
+32 -211
View File
@@ -47,9 +47,11 @@ public class EditorStatus extends BasicSplitPaneDivider { //JPanel {
Color[] bgcolor;
Color[] fgcolor;
static public final int NOTICE = 0;
static public final int ERR = 1;
static public final int EDIT = 2;
@SuppressWarnings("hiding")
static public final int ERROR = 1;
static public final int COMPILER_ERROR = 1; // temporary
static public final int WARNING = 2;
static public final int NOTICE = 0;
static final int YES = 1;
static final int NO = 2;
@@ -139,50 +141,45 @@ public class EditorStatus extends BasicSplitPaneDivider { //JPanel {
}
public void notice(String message) {
mode = NOTICE;
public void message(String message, int mode) {
this.message = message;
this.mode = mode;
url = findURL(message);
repaint();
}
public void unnotice(String unmessage) {
if (message.equals(unmessage)) empty();
public void notice(String message) {
message(message, NOTICE);
// mode = NOTICE;
// this.message = message;
// url = findURL(message);
// repaint();
}
// public void unnotice(String unmessage) {
// if (message.equals(unmessage)) empty();
// }
public void warning(String message) {
message(message, WARNING);
// this.message = message;
// mode = WARNING;
// url = findURL(message);
// repaint();
}
public void error(String message) {
mode = ERR;
this.message = message;
url = findURL(message);
repaint();
}
// public void edit(String message, String dflt) {
// mode = EDIT;
message(message, ERROR);
// this.message = message;
//
// response = 0;
// okButton.setVisible(true);
// cancelButton.setVisible(true);
// editField.setVisible(true);
// editField.setText(dflt);
// editField.selectAll();
// editField.requestFocusInWindow();
//
// mode = ERROR;
// url = findURL(message);
// repaint();
// }
// public void unedit() {
// okButton.setVisible(false);
// cancelButton.setVisible(false);
// editField.setVisible(false);
// editor.textarea.requestFocusInWindow();
// empty();
// }
}
public void startIndeterminate() {
@@ -268,164 +265,6 @@ public class EditorStatus extends BasicSplitPaneDivider { //JPanel {
}
/*
protected void setup() {
if (okButton == null) {
cancelButton = new JButton(Preferences.PROMPT_CANCEL);
okButton = new JButton(Preferences.PROMPT_OK);
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (mode == EDIT) {
unedit();
//editor.toolbar.clear();
}
}
});
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// answering to rename/new code question
if (mode == EDIT) { // this if() isn't (shouldn't be?) necessary
String answer = editField.getText();
editor.getSketch().nameCode(answer);
unedit();
}
}
});
// !@#(* aqua ui #($*(( that turtle-neck wearing #(** (#$@)(
// os9 seems to work if bg of component is set, but x still a bastard
if (Base.isMacOS()) {
//yesButton.setBackground(bgcolor[EDIT]);
//noButton.setBackground(bgcolor[EDIT]);
cancelButton.setBackground(bgcolor[EDIT]);
okButton.setBackground(bgcolor[EDIT]);
}
setLayout(null);
add(cancelButton);
add(okButton);
cancelButton.setVisible(false);
okButton.setVisible(false);
editField = new JTextField();
// disabling, was not in use
//editField.addActionListener(this);
//if (Base.platform != Base.MACOSX) {
editField.addKeyListener(new KeyAdapter() {
// Grab ESC with keyPressed, because it's not making it to keyTyped
public void keyPressed(KeyEvent event) {
if (event.getKeyChar() == KeyEvent.VK_ESCAPE) {
unedit();
//editor.toolbar.clear();
event.consume();
}
}
// use keyTyped to catch when the feller is actually
// added to the text field. with keyTyped, as opposed to
// keyPressed, the keyCode will be zero, even if it's
// enter or backspace or whatever, so the keychar should
// be used instead. grr.
public void keyTyped(KeyEvent event) {
//System.out.println("got event " + event);
int c = event.getKeyChar();
if (c == KeyEvent.VK_ENTER) { // accept the input
String answer = editField.getText();
editor.getSketch().nameCode(answer);
unedit();
event.consume();
// easier to test the affirmative case than the negative
} else if ((c == KeyEvent.VK_BACK_SPACE) ||
(c == KeyEvent.VK_DELETE) ||
(c == KeyEvent.VK_RIGHT) ||
(c == KeyEvent.VK_LEFT) ||
(c == KeyEvent.VK_UP) ||
(c == KeyEvent.VK_DOWN) ||
(c == KeyEvent.VK_HOME) ||
(c == KeyEvent.VK_END) ||
(c == KeyEvent.VK_SHIFT)) {
// these events are ignored
// } else if (c == KeyEvent.VK_ESCAPE) {
// unedit();
// editor.toolbar.clear();
// event.consume();
} else if (c == KeyEvent.VK_SPACE) {
String t = editField.getText();
int start = editField.getSelectionStart();
int end = editField.getSelectionEnd();
editField.setText(t.substring(0, start) + "_" +
t.substring(end));
editField.setCaretPosition(start+1);
event.consume();
} else if ((c == '_') || (c == '.') || // allow .pde and .java
((c >= 'A') && (c <= 'Z')) ||
((c >= 'a') && (c <= 'z'))) {
// these are ok, allow them through
} else if ((c >= '0') && (c <= '9')) {
// getCaretPosition == 0 means that it's the first char
// and the field is empty.
// getSelectionStart means that it *will be* the first
// char, because the selection is about to be replaced
// with whatever is typed.
if ((editField.getCaretPosition() == 0) ||
(editField.getSelectionStart() == 0)) {
// number not allowed as first digit
//System.out.println("bad number bad");
event.consume();
}
} else {
event.consume();
//System.out.println("code is " + code + " char = " + c);
}
//System.out.println("code is " + code + " char = " + c);
}
});
add(editField);
editField.setVisible(false);
}
}
private void setButtonBounds() {
int top = (sizeH - BUTTON_HEIGHT) / 2;
int eachButton = Preferences.GUI_SMALL + Preferences.BUTTON_WIDTH;
int cancelLeft = sizeW - eachButton;
int noLeft = cancelLeft - eachButton;
int yesLeft = noLeft - eachButton;
//yesButton.setLocation(yesLeft, top);
//noButton.setLocation(noLeft, top);
cancelButton.setLocation(cancelLeft, top);
okButton.setLocation(noLeft, top);
//yesButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
//noButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
cancelButton.setSize(Preferences.BUTTON_WIDTH, BUTTON_HEIGHT);
okButton.setSize(Preferences.BUTTON_WIDTH, BUTTON_HEIGHT);
// edit field height is awkward, and very different between mac and pc,
// so use at least the preferred height for now.
int editWidth = 2*Preferences.BUTTON_WIDTH;
int editHeight = editField.getPreferredSize().height;
int editTop = (1 + sizeH - editHeight) / 2; // add 1 for ceil
editField.setBounds(yesLeft - Preferences.BUTTON_WIDTH, editTop,
editWidth, editHeight);
}
*/
public Dimension getPreferredSize() {
return getMinimumSize();
}
@@ -439,22 +278,4 @@ public class EditorStatus extends BasicSplitPaneDivider { //JPanel {
public Dimension getMaximumSize() {
return new Dimension(super.getMaximumSize().width, HIGH);
}
/*
public void actionPerformed(ActionEvent e) {
if (e.getSource() == cancelButton) {
if (mode == EDIT) unedit();
//editor.toolbar.clear();
} else if (e.getSource() == okButton) {
// answering to rename/new code question
if (mode == EDIT) { // this if() isn't (shouldn't be?) necessary
String answer = editField.getText();
editor.getSketch().nameCode(answer);
unedit();
}
}
}
*/
}
+50 -6
View File
@@ -29,6 +29,7 @@ import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.ToolTipManager;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
@@ -36,7 +37,6 @@ import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import processing.app.Language;
import processing.app.Messages;
import processing.app.Mode;
import processing.app.ui.Editor;
@@ -44,6 +44,11 @@ import processing.app.ui.Editor;
public class ErrorTable extends JTable {
Editor editor;
public interface Entry {
public boolean isError();
public boolean isWarning();
}
static final String[] columnNames = {
"", // the blank column used for spacing
Language.text("editor.footer.errors.problem"),
@@ -109,8 +114,8 @@ public class ErrorTable extends JTable {
editor.errorTableDoubleClick(data);
}
// editor.getErrorChecker().scrollToErrorLine(row);
} catch (Exception e1) {
Messages.log("Exception XQErrorTable mouseReleased " + e);
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
@@ -185,7 +190,7 @@ public class ErrorTable extends JTable {
}
public void addRow(Object data, String message, String filename, String line) {
public void addRow(Entry data, String message, String filename, String line) {
DefaultTableModel dtm = (DefaultTableModel) getModel();
dtm.addRow(new Object[] { data, message, filename, line });
}
@@ -318,6 +323,12 @@ public class ErrorTable extends JTable {
Color bgColor;
Color textColorSelected;
Color bgColorSelected;
Color bgColorError;
Color bgColorWarning;
// int indicatorSize;
Color errorIndicatorColor;
Color warningIndicatorColor;
public GradyRowRenderer(Mode mode) {
setFont(mode.getFont("errors.row.font"));
@@ -327,6 +338,13 @@ public class ErrorTable extends JTable {
bgColor = mode.getColor("errors.row.bgcolor");
textColorSelected = mode.getColor("errors.selection.fgcolor");
bgColorSelected = mode.getColor("errors.selection.bgcolor");
bgColorError = mode.getColor("errors.selection.error.bgcolor");
bgColorWarning = mode.getColor("errors.selection.warning.bgcolor");
// indicatorSize = mode.getInteger("errors.indicator.size");
errorIndicatorColor = mode.getColor("errors.indicator.error.color");
warningIndicatorColor = mode.getColor("errors.indicator.warning.color");
setOpaque(true);
}
@@ -335,19 +353,45 @@ public class ErrorTable extends JTable {
boolean selected,
boolean focused,
int row, int column) {
Entry entry = (Entry) table.getValueAt(row, DATA_COLUMN);
if (selected) {
setForeground(textColorSelected);
setBackground(bgColorSelected);
if (entry.isError()) {
setBackground(bgColorError);
} else if (entry.isWarning()) {
setBackground(bgColorWarning);
} else {
setBackground(bgColorSelected);
}
} else {
setForeground(textColor);
setBackground(bgColor);
}
if (column == DATA_COLUMN || value == null) {
if (column == DATA_COLUMN) {
setText("\u2022");
setHorizontalAlignment(SwingConstants.CENTER);
if (entry.isError()) {
setForeground(errorIndicatorColor);
} else if (entry.isWarning()) {
setForeground(warningIndicatorColor);
} else {
setText(""); // no dot
}
} else if (value == null) {
setText("");
} else {
setHorizontalAlignment(SwingConstants.LEFT);
setText(value.toString());
}
return this;
}
// Component dot = new JComponent() {
// @Override
// public void paintComponent(Graphics g) {
//
// }
// };
}
}