mirror of https://github.com/noisymime/Arduino.git
Code cleanup
This commit is contained in:
parent
43743bb1a3
commit
fc8d903c7d
|
@ -22,47 +22,60 @@
|
||||||
|
|
||||||
package processing.app;
|
package processing.app;
|
||||||
|
|
||||||
|
import cc.arduino.packages.BoardPort;
|
||||||
import cc.arduino.packages.MonitorFactory;
|
import cc.arduino.packages.MonitorFactory;
|
||||||
|
import cc.arduino.packages.Uploader;
|
||||||
|
import cc.arduino.packages.uploaders.SerialUploader;
|
||||||
import cc.arduino.view.StubMenuListener;
|
import cc.arduino.view.StubMenuListener;
|
||||||
import cc.arduino.view.findreplace.FindReplace;
|
import cc.arduino.view.findreplace.FindReplace;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.jcraft.jsch.JSchException;
|
import com.jcraft.jsch.JSchException;
|
||||||
import jssc.SerialPortException;
|
import jssc.SerialPortException;
|
||||||
import processing.app.debug.*;
|
|
||||||
import processing.app.forms.PasswordAuthorizationDialog;
|
|
||||||
import processing.app.helpers.OSUtils;
|
|
||||||
import processing.app.helpers.PreferencesMapException;
|
|
||||||
import processing.app.legacy.PApplet;
|
|
||||||
import processing.app.syntax.*;
|
|
||||||
import processing.app.tools.*;
|
|
||||||
import static processing.app.I18n._;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.datatransfer.*;
|
|
||||||
import java.awt.event.*;
|
|
||||||
import java.awt.print.*;
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.zip.*;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import javax.swing.border.MatteBorder;
|
|
||||||
import javax.swing.event.*;
|
|
||||||
import javax.swing.text.*;
|
|
||||||
import javax.swing.undo.*;
|
|
||||||
|
|
||||||
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
|
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
|
||||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaEditorKit;
|
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaEditorKit;
|
||||||
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
|
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
|
||||||
import org.fife.ui.rtextarea.Gutter;
|
import org.fife.ui.rtextarea.Gutter;
|
||||||
import org.fife.ui.rtextarea.RTextScrollPane;
|
import org.fife.ui.rtextarea.RTextScrollPane;
|
||||||
|
import processing.app.debug.RunnerException;
|
||||||
|
import processing.app.debug.RunnerListener;
|
||||||
|
import processing.app.forms.PasswordAuthorizationDialog;
|
||||||
|
import processing.app.helpers.OSUtils;
|
||||||
|
import processing.app.helpers.PreferencesMapException;
|
||||||
|
import processing.app.legacy.PApplet;
|
||||||
|
import processing.app.syntax.ArduinoTokenMakerFactory;
|
||||||
|
import processing.app.syntax.SketchTextArea;
|
||||||
|
import processing.app.tools.DiscourseFormat;
|
||||||
|
import processing.app.tools.MenuScroller;
|
||||||
|
import processing.app.tools.Tool;
|
||||||
|
|
||||||
import cc.arduino.packages.BoardPort;
|
import javax.swing.*;
|
||||||
import cc.arduino.packages.Uploader;
|
import javax.swing.border.MatteBorder;
|
||||||
import cc.arduino.packages.uploaders.SerialUploader;
|
import javax.swing.event.*;
|
||||||
|
import javax.swing.text.BadLocationException;
|
||||||
|
import javax.swing.text.PlainDocument;
|
||||||
|
import javax.swing.undo.CannotRedoException;
|
||||||
|
import javax.swing.undo.CannotUndoException;
|
||||||
|
import javax.swing.undo.UndoManager;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.datatransfer.DataFlavor;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
import java.awt.event.*;
|
||||||
|
import java.awt.print.PageFormat;
|
||||||
|
import java.awt.print.PrinterException;
|
||||||
|
import java.awt.print.PrinterJob;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.ConnectException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
|
import static processing.app.I18n._;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main editor panel for the Processing Development Environment.
|
* Main editor panel for the Processing Development Environment.
|
||||||
|
@ -1937,7 +1950,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||||
if (shouldSavePredicate.apply(sketch)) {
|
if (shouldSavePredicate.apply(sketch)) {
|
||||||
handleSave(true);
|
handleSave(true);
|
||||||
}
|
}
|
||||||
toolbar.activate(EditorToolbar.RUN);
|
toolbar.activateRun();
|
||||||
status.progress(_("Compiling sketch..."));
|
status.progress(_("Compiling sketch..."));
|
||||||
|
|
||||||
// do this to advance/clear the terminal window / dos prompt / etc
|
// do this to advance/clear the terminal window / dos prompt / etc
|
||||||
|
@ -1988,7 +2001,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
status.unprogress();
|
status.unprogress();
|
||||||
toolbar.deactivate(EditorToolbar.RUN);
|
toolbar.deactivateRun();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2008,7 +2021,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||||
|
|
||||||
internalCloseRunner();
|
internalCloseRunner();
|
||||||
|
|
||||||
toolbar.deactivate(EditorToolbar.RUN);
|
toolbar.deactivateRun();
|
||||||
// toolbar.deactivate(EditorToolbar.STOP);
|
// toolbar.deactivate(EditorToolbar.STOP);
|
||||||
|
|
||||||
// focus the PDE again after quitting presentation mode [toxi 030903]
|
// focus the PDE again after quitting presentation mode [toxi 030903]
|
||||||
|
@ -2272,7 +2285,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||||
|
|
||||||
|
|
||||||
private boolean handleSave2() {
|
private boolean handleSave2() {
|
||||||
toolbar.activate(EditorToolbar.SAVE);
|
toolbar.activateSave();
|
||||||
statusNotice(_("Saving..."));
|
statusNotice(_("Saving..."));
|
||||||
boolean saved = false;
|
boolean saved = false;
|
||||||
try {
|
try {
|
||||||
|
@ -2306,7 +2319,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||||
// this is used when another operation calls a save
|
// this is used when another operation calls a save
|
||||||
}
|
}
|
||||||
//toolbar.clear();
|
//toolbar.clear();
|
||||||
toolbar.deactivate(EditorToolbar.SAVE);
|
toolbar.deactivateSave();
|
||||||
return saved;
|
return saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2315,7 +2328,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||||
//stopRunner(); // formerly from 0135
|
//stopRunner(); // formerly from 0135
|
||||||
handleStop();
|
handleStop();
|
||||||
|
|
||||||
toolbar.activate(EditorToolbar.SAVE);
|
toolbar.activateSave();
|
||||||
|
|
||||||
//SwingUtilities.invokeLater(new Runnable() {
|
//SwingUtilities.invokeLater(new Runnable() {
|
||||||
//public void run() {
|
//public void run() {
|
||||||
|
@ -2339,7 +2352,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
// make sure the toolbar button deactivates
|
// make sure the toolbar button deactivates
|
||||||
toolbar.deactivate(EditorToolbar.SAVE);
|
toolbar.deactivateSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -2393,7 +2406,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||||
handleSave(true);
|
handleSave(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toolbar.activate(EditorToolbar.EXPORT);
|
toolbar.activateExport();
|
||||||
console.clear();
|
console.clear();
|
||||||
status.progress(_("Uploading to I/O Board..."));
|
status.progress(_("Uploading to I/O Board..."));
|
||||||
|
|
||||||
|
@ -2440,7 +2453,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||||
status.unprogress();
|
status.unprogress();
|
||||||
uploading = false;
|
uploading = false;
|
||||||
//toolbar.clear();
|
//toolbar.clear();
|
||||||
toolbar.deactivate(EditorToolbar.EXPORT);
|
toolbar.deactivateExport();
|
||||||
|
|
||||||
resumeOrCloseSerialMonitor();
|
resumeOrCloseSerialMonitor();
|
||||||
resumeOrCloseSerialPlotter();
|
resumeOrCloseSerialPlotter();
|
||||||
|
@ -2535,7 +2548,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||||
status.unprogress();
|
status.unprogress();
|
||||||
uploading = false;
|
uploading = false;
|
||||||
//toolbar.clear();
|
//toolbar.clear();
|
||||||
toolbar.deactivate(EditorToolbar.EXPORT);
|
toolbar.deactivateExport();
|
||||||
|
|
||||||
resumeOrCloseSerialMonitor();
|
resumeOrCloseSerialMonitor();
|
||||||
resumeOrCloseSerialPlotter();
|
resumeOrCloseSerialPlotter();
|
||||||
|
@ -2815,7 +2828,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||||
System.err.println(what);
|
System.err.println(what);
|
||||||
status.error(what);
|
status.error(what);
|
||||||
//new Exception("deactivating RUN").printStackTrace();
|
//new Exception("deactivating RUN").printStackTrace();
|
||||||
toolbar.deactivate(EditorToolbar.RUN);
|
toolbar.deactivateRun();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,65 +38,80 @@ import static processing.app.I18n._;
|
||||||
*/
|
*/
|
||||||
public class EditorToolbar extends JComponent implements MouseInputListener, KeyListener {
|
public class EditorToolbar extends JComponent implements MouseInputListener, KeyListener {
|
||||||
|
|
||||||
/** Rollover titles for each button. */
|
/**
|
||||||
static final String title[] = {
|
* Rollover titles for each button.
|
||||||
|
*/
|
||||||
|
private static final String[] title = {
|
||||||
_("Verify"), _("Upload"), _("New"), _("Open"), _("Save"), _("Serial Monitor")
|
_("Verify"), _("Upload"), _("New"), _("Open"), _("Save"), _("Serial Monitor")
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Titles for each button when the shift key is pressed. */
|
/**
|
||||||
static final String titleShift[] = {
|
* Titles for each button when the shift key is pressed.
|
||||||
|
*/
|
||||||
|
private static final String[] titleShift = {
|
||||||
_("Verify"), _("Upload Using Programmer"), _("New"), _("Open"), _("Save As..."), _("Serial Monitor")
|
_("Verify"), _("Upload Using Programmer"), _("New"), _("Open"), _("Save As..."), _("Serial Monitor")
|
||||||
};
|
};
|
||||||
|
|
||||||
static final int BUTTON_COUNT = title.length;
|
private static final int BUTTON_COUNT = title.length;
|
||||||
/** Width of each toolbar button. */
|
/**
|
||||||
static final int BUTTON_WIDTH = 27;
|
* Width of each toolbar button.
|
||||||
/** Height of each toolbar button. */
|
*/
|
||||||
static final int BUTTON_HEIGHT = 32;
|
private static final int BUTTON_WIDTH = 27;
|
||||||
/** The amount of space between groups of buttons on the toolbar. */
|
/**
|
||||||
static final int BUTTON_GAP = 5;
|
* Height of each toolbar button.
|
||||||
/** Size of the button image being chopped up. */
|
*/
|
||||||
static final int BUTTON_IMAGE_SIZE = 33;
|
private static final int BUTTON_HEIGHT = 32;
|
||||||
|
/**
|
||||||
|
* The amount of space between groups of buttons on the toolbar.
|
||||||
|
*/
|
||||||
|
private static final int BUTTON_GAP = 5;
|
||||||
|
/**
|
||||||
|
* Size of the button image being chopped up.
|
||||||
|
*/
|
||||||
|
private static final int BUTTON_IMAGE_SIZE = 33;
|
||||||
|
|
||||||
|
|
||||||
static final int RUN = 0;
|
private static final int RUN = 0;
|
||||||
static final int EXPORT = 1;
|
private static final int EXPORT = 1;
|
||||||
|
|
||||||
static final int NEW = 2;
|
private static final int NEW = 2;
|
||||||
static final int OPEN = 3;
|
private static final int OPEN = 3;
|
||||||
static final int SAVE = 4;
|
private static final int SAVE = 4;
|
||||||
|
|
||||||
static final int SERIAL = 5;
|
private static final int SERIAL = 5;
|
||||||
|
|
||||||
static final int INACTIVE = 0;
|
private static final int INACTIVE = 0;
|
||||||
static final int ROLLOVER = 1;
|
private static final int ROLLOVER = 1;
|
||||||
static final int ACTIVE = 2;
|
private static final int ACTIVE = 2;
|
||||||
|
|
||||||
Editor editor;
|
private final Editor editor;
|
||||||
|
|
||||||
Image offscreen;
|
private Image offscreen;
|
||||||
int width, height;
|
private int width;
|
||||||
|
private int height;
|
||||||
|
|
||||||
Color bgcolor;
|
private final Color bgcolor;
|
||||||
|
|
||||||
static Image[][] buttonImages;
|
private static Image[][] buttonImages;
|
||||||
int currentRollover;
|
private int currentRollover;
|
||||||
|
|
||||||
JPopupMenu popup;
|
private JPopupMenu popup;
|
||||||
JMenu menu;
|
private final JMenu menu;
|
||||||
|
|
||||||
int buttonCount;
|
private int buttonCount;
|
||||||
int[] state = new int[BUTTON_COUNT];
|
private int[] state = new int[BUTTON_COUNT];
|
||||||
Image[] stateImage;
|
private Image[] stateImage;
|
||||||
int which[]; // mapping indices to implementation
|
private final int[] which; // mapping indices to implementation
|
||||||
|
|
||||||
int x1[], x2[];
|
private int[] x1;
|
||||||
int y1, y2;
|
private int[] x2;
|
||||||
|
private int y1;
|
||||||
|
private int y2;
|
||||||
|
|
||||||
Font statusFont;
|
private final Font statusFont;
|
||||||
Color statusColor;
|
private final Color statusColor;
|
||||||
|
|
||||||
boolean shiftPressed;
|
private boolean shiftPressed;
|
||||||
|
|
||||||
public EditorToolbar(Editor editor, JMenu menu) {
|
public EditorToolbar(Editor editor, JMenu menu) {
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
|
@ -123,7 +138,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
|
||||||
addMouseMotionListener(this);
|
addMouseMotionListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadButtons() {
|
private void loadButtons() {
|
||||||
Image allButtons = Base.getThemeImage("buttons.gif", this);
|
Image allButtons = Base.getThemeImage("buttons.gif", this);
|
||||||
buttonImages = new Image[BUTTON_COUNT][3];
|
buttonImages = new Image[BUTTON_COUNT][3];
|
||||||
|
|
||||||
|
@ -236,10 +251,11 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void mouseDragged(MouseEvent e) { }
|
public void mouseDragged(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void handleMouse(MouseEvent e) {
|
private void handleMouse(MouseEvent e) {
|
||||||
int x = e.getX();
|
int x = e.getX();
|
||||||
int y = e.getY();
|
int y = e.getY();
|
||||||
|
|
||||||
|
@ -304,8 +320,6 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
|
||||||
handleMouse(e);
|
handleMouse(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wasDown = -1;
|
|
||||||
|
|
||||||
|
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
|
|
||||||
|
@ -362,31 +376,55 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void mouseClicked(MouseEvent e) { }
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void mouseReleased(MouseEvent e) { }
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a particular button to be active.
|
* Set a particular button to be active.
|
||||||
*/
|
*/
|
||||||
public void activate(int what) {
|
private void activate(int what) {
|
||||||
if (buttonImages != null) {
|
if (buttonImages != null) {
|
||||||
setState(what, ACTIVE, true);
|
setState(what, ACTIVE, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void activateRun() {
|
||||||
|
activate(RUN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void activateSave() {
|
||||||
|
activate(SAVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void activateExport() {
|
||||||
|
activate(EXPORT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a particular button to be active.
|
* Set a particular button to be active.
|
||||||
*/
|
*/
|
||||||
public void deactivate(int what) {
|
private void deactivate(int what) {
|
||||||
if (buttonImages != null) {
|
if (buttonImages != null) {
|
||||||
setState(what, INACTIVE, true);
|
setState(what, INACTIVE, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deactivateRun() {
|
||||||
|
deactivate(RUN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deactivateSave() {
|
||||||
|
deactivate(SAVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deactivateExport() {
|
||||||
|
deactivate(EXPORT);
|
||||||
|
}
|
||||||
|
|
||||||
public Dimension getPreferredSize() {
|
public Dimension getPreferredSize() {
|
||||||
return getMinimumSize();
|
return getMinimumSize();
|
||||||
|
@ -419,5 +457,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void keyTyped(KeyEvent e) { }
|
public void keyTyped(KeyEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue