mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-22 08:22:04 +03:00
Merge branch 'ide-1.5.x' into lib-1.5
This commit is contained in:
@ -50,9 +50,9 @@ import static processing.app.I18n._;
|
||||
* files and images, etc) that comes from that.
|
||||
*/
|
||||
public class Base {
|
||||
public static final int REVISION = 151;
|
||||
public static final int REVISION = 152;
|
||||
/** This might be replaced by main() if there's a lib/version.txt file. */
|
||||
static String VERSION_NAME = "0151";
|
||||
static String VERSION_NAME = "0152";
|
||||
/** Set true if this a proper release rather than a numbered revision. */
|
||||
static public boolean RELEASE = false;
|
||||
|
||||
@ -111,8 +111,21 @@ public class Base {
|
||||
List<Editor> editors = Collections.synchronizedList(new ArrayList<Editor>());
|
||||
Editor activeEditor;
|
||||
|
||||
static File portableFolder = null;
|
||||
static final String portableSketchbookFolder = "sketchbook";
|
||||
|
||||
|
||||
static public void main(String args[]) throws Exception {
|
||||
initPlatform();
|
||||
|
||||
// Portable folder
|
||||
portableFolder = getContentFile("portable");
|
||||
if (!portableFolder.exists())
|
||||
portableFolder = null;
|
||||
|
||||
// run static initialization that grabs all the prefs
|
||||
Preferences.init(null);
|
||||
|
||||
try {
|
||||
File versionFile = getContentFile("lib/version.txt");
|
||||
if (versionFile.exists()) {
|
||||
@ -151,8 +164,6 @@ public class Base {
|
||||
}
|
||||
*/
|
||||
|
||||
initPlatform();
|
||||
|
||||
// // Set the look and feel before opening the window
|
||||
// try {
|
||||
// platform.setLookAndFeel();
|
||||
@ -172,12 +183,6 @@ public class Base {
|
||||
// Make sure a full JDK is installed
|
||||
//initRequirements();
|
||||
|
||||
// run static initialization that grabs all the prefs
|
||||
Preferences.init(null);
|
||||
|
||||
// load the I18n module for internationalization
|
||||
I18n.init(Preferences.get("editor.languages.current"));
|
||||
|
||||
// setup the theme coloring fun
|
||||
Theme.init();
|
||||
|
||||
@ -252,14 +257,18 @@ public class Base {
|
||||
// If a value is at least set, first check to see if the folder exists.
|
||||
// If it doesn't, warn the user that the sketchbook folder is being reset.
|
||||
if (sketchbookPath != null) {
|
||||
File skechbookFolder = new File(sketchbookPath);
|
||||
if (!skechbookFolder.exists()) {
|
||||
File sketchbookFolder;
|
||||
if (portableFolder != null)
|
||||
sketchbookFolder = new File(portableFolder, sketchbookPath);
|
||||
else
|
||||
sketchbookFolder = new File(sketchbookPath);
|
||||
if (!sketchbookFolder.exists()) {
|
||||
Base.showWarning(_("Sketchbook folder disappeared"),
|
||||
_("The sketchbook folder no longer exists.\n" +
|
||||
"Arduino will switch to the default sketchbook\n" +
|
||||
"location, and create a new sketchbook folder if\n" +
|
||||
"necessary. Arduino will then stop talking about\n" +
|
||||
"himself in the third person."), null);
|
||||
_("The sketchbook folder no longer exists.\n" +
|
||||
"Arduino will switch to the default sketchbook\n" +
|
||||
"location, and create a new sketchbook folder if\n" +
|
||||
"necessary. Arduino will then stop talking about\n" +
|
||||
"himself in the third person."), null);
|
||||
sketchbookPath = null;
|
||||
}
|
||||
}
|
||||
@ -267,7 +276,10 @@ public class Base {
|
||||
// If no path is set, get the default sketchbook folder for this platform
|
||||
if (sketchbookPath == null) {
|
||||
File defaultFolder = getDefaultSketchbookFolder();
|
||||
Preferences.set("sketchbook.path", defaultFolder.getAbsolutePath());
|
||||
if (portableFolder != null)
|
||||
Preferences.set("sketchbook.path", portableSketchbookFolder);
|
||||
else
|
||||
Preferences.set("sketchbook.path", defaultFolder.getAbsolutePath());
|
||||
if (!defaultFolder.exists()) {
|
||||
defaultFolder.mkdirs();
|
||||
}
|
||||
@ -281,6 +293,8 @@ public class Base {
|
||||
|
||||
boolean opened = false;
|
||||
boolean doUpload = false;
|
||||
boolean doVerify = false;
|
||||
boolean doVerbose = false;
|
||||
String selectBoard = null;
|
||||
String selectPort = null;
|
||||
// Check if any files were passed in on the command line
|
||||
@ -289,6 +303,14 @@ public class Base {
|
||||
doUpload = true;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--verify")) {
|
||||
doVerify = true;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--verbose") || args[i].equals("-v")) {
|
||||
doVerbose = true;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--board")) {
|
||||
i++;
|
||||
if (i < args.length)
|
||||
@ -319,16 +341,42 @@ public class Base {
|
||||
}
|
||||
}
|
||||
|
||||
if (doUpload) {
|
||||
if (!opened)
|
||||
throw new Exception(_("Can't open source sketch!"));
|
||||
Thread.sleep(2000);
|
||||
if (doUpload || doVerify) {
|
||||
if (!opened) {
|
||||
System.out.println(_("Can't open source sketch!"));
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
// Set verbosity for command line build
|
||||
Preferences.set("build.verbose", "" + doVerbose);
|
||||
Preferences.set("upload.verbose", "" + doVerbose);
|
||||
|
||||
Editor editor = editors.get(0);
|
||||
if (selectPort != null)
|
||||
editor.selectSerialPort(selectPort);
|
||||
|
||||
// Wait until editor is initialized
|
||||
while (!editor.status.isInitialized())
|
||||
Thread.sleep(10);
|
||||
|
||||
// Do board selection if requested
|
||||
if (selectBoard != null)
|
||||
selectBoard(selectBoard, editor);
|
||||
editor.exportHandler.run();
|
||||
|
||||
if (doUpload) {
|
||||
// Build and upload
|
||||
if (selectPort != null)
|
||||
editor.selectSerialPort(selectPort);
|
||||
editor.exportHandler.run();
|
||||
} else {
|
||||
// Build only
|
||||
editor.runHandler.run();
|
||||
}
|
||||
|
||||
// Error during build or upload
|
||||
int res = editor.status.mode;
|
||||
if (res == EditorStatus.ERR)
|
||||
System.exit(1);
|
||||
|
||||
// No errors exit gracefully
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@ -389,6 +437,14 @@ public class Base {
|
||||
int opened = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
String path = Preferences.get("last.sketch" + i + ".path");
|
||||
if (portableFolder != null) {
|
||||
File absolute = new File(portableFolder, path);
|
||||
try {
|
||||
path = absolute.getCanonicalPath();
|
||||
} catch (IOException e) {
|
||||
// path unchanged.
|
||||
}
|
||||
}
|
||||
int[] location;
|
||||
if (windowPositionValid) {
|
||||
String locationStr = Preferences.get("last.sketch" + i + ".location");
|
||||
@ -427,6 +483,11 @@ public class Base {
|
||||
!editor.getSketch().isModified()) {
|
||||
continue;
|
||||
}
|
||||
if (portableFolder != null) {
|
||||
path = FileUtils.relativePath(portableFolder.toString(), path);
|
||||
if (path == null)
|
||||
continue;
|
||||
}
|
||||
Preferences.set("last.sketch" + index + ".path", path);
|
||||
|
||||
int[] location = editor.getPlacement();
|
||||
@ -445,6 +506,11 @@ public class Base {
|
||||
String untitledPath = untitledFolder.getAbsolutePath();
|
||||
if (path.startsWith(untitledPath)) {
|
||||
path = "";
|
||||
} else
|
||||
if (portableFolder != null) {
|
||||
path = FileUtils.relativePath(portableFolder.toString(), path);
|
||||
if (path == null)
|
||||
path = "";
|
||||
}
|
||||
Preferences.set("last.sketch" + index + ".path", path);
|
||||
}
|
||||
@ -973,6 +1039,8 @@ public class Base {
|
||||
}
|
||||
|
||||
public Map<String, File> getIDELibs() {
|
||||
if (libraries == null)
|
||||
return new HashMap<String, File>();
|
||||
Map<String, File> ideLibs = new HashMap<String, File>(libraries);
|
||||
for (String lib : libraries.keySet()) {
|
||||
if (FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
|
||||
@ -982,6 +1050,8 @@ public class Base {
|
||||
}
|
||||
|
||||
public Map<String, File> getUserLibs() {
|
||||
if (libraries == null)
|
||||
return new HashMap<String, File>();
|
||||
Map<String, File> userLibs = new HashMap<String, File>(libraries);
|
||||
for (String lib : libraries.keySet()) {
|
||||
if (!FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
|
||||
@ -1005,34 +1075,37 @@ public class Base {
|
||||
importMenu.add(addLibraryMenuItem);
|
||||
|
||||
// Split between user supplied libraries and IDE libraries
|
||||
Map<String, File> ideLibs = getIDELibs();
|
||||
Map<String, File> userLibs = getUserLibs();
|
||||
try {
|
||||
// Find the current target. Get the platform, and then select the
|
||||
// correct name and core path.
|
||||
PreferencesMap prefs = getTargetPlatform().getPreferences();
|
||||
String targetname = prefs.get("name");
|
||||
TargetPlatform targetPlatform = getTargetPlatform();
|
||||
if (targetPlatform != null) {
|
||||
Map<String, File> ideLibs = getIDELibs();
|
||||
Map<String, File> userLibs = getUserLibs();
|
||||
try {
|
||||
// Find the current target. Get the platform, and then select the
|
||||
// correct name and core path.
|
||||
PreferencesMap prefs = targetPlatform.getPreferences();
|
||||
String targetname = prefs.get("name");
|
||||
|
||||
if (false) {
|
||||
// Hack to extract these words by gettext tool.
|
||||
// These phrases are actually defined in the "platform.txt".
|
||||
String notused = _("Arduino AVR Boards");
|
||||
notused = _("Arduino ARM (32-bits) Boards");
|
||||
}
|
||||
if (false) {
|
||||
// Hack to extract these words by gettext tool.
|
||||
// These phrases are actually defined in the "platform.txt".
|
||||
String notused = _("Arduino AVR Boards");
|
||||
notused = _("Arduino ARM (32-bits) Boards");
|
||||
}
|
||||
|
||||
JMenuItem platformItem = new JMenuItem(_(targetname));
|
||||
platformItem.setEnabled(false);
|
||||
importMenu.add(platformItem);
|
||||
if (ideLibs.size()>0) {
|
||||
importMenu.addSeparator();
|
||||
addLibraries(importMenu, ideLibs);
|
||||
JMenuItem platformItem = new JMenuItem(_(targetname));
|
||||
platformItem.setEnabled(false);
|
||||
importMenu.add(platformItem);
|
||||
if (ideLibs.size() > 0) {
|
||||
importMenu.addSeparator();
|
||||
addLibraries(importMenu, ideLibs);
|
||||
}
|
||||
if (userLibs.size() > 0) {
|
||||
importMenu.addSeparator();
|
||||
addLibraries(importMenu, userLibs);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (userLibs.size()>0) {
|
||||
importMenu.addSeparator();
|
||||
addLibraries(importMenu, userLibs);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1135,11 +1208,15 @@ public class Base {
|
||||
}
|
||||
|
||||
public void onBoardOrPortChange() {
|
||||
TargetPlatform targetPlatform = getTargetPlatform();
|
||||
if (targetPlatform == null)
|
||||
return;
|
||||
|
||||
// Calculate paths for libraries and examples
|
||||
examplesFolder = getContentFile("examples");
|
||||
toolsFolder = getContentFile("tools");
|
||||
|
||||
File platformFolder = getTargetPlatform().getFolder();
|
||||
File platformFolder = targetPlatform.getFolder();
|
||||
librariesFolders = new ArrayList<File>();
|
||||
librariesFolders.add(getContentFile("libraries"));
|
||||
librariesFolders.add(new File(platformFolder, "libraries"));
|
||||
@ -1153,9 +1230,14 @@ public class Base {
|
||||
// Populate importToLibraryTable
|
||||
importToLibraryTable = new HashMap<String, File>();
|
||||
for (File subfolder : libraries.values()) {
|
||||
String packages[] = headerListFromIncludePath(subfolder);
|
||||
for (String pkg : packages)
|
||||
importToLibraryTable.put(pkg, subfolder);
|
||||
try {
|
||||
String packages[] = headerListFromIncludePath(subfolder);
|
||||
for (String pkg : packages) {
|
||||
importToLibraryTable.put(pkg, subfolder);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", subfolder), e);
|
||||
}
|
||||
}
|
||||
|
||||
// Update editors status bar
|
||||
@ -1403,6 +1485,9 @@ public class Base {
|
||||
*/
|
||||
protected boolean addSketches(JMenu menu, File folder,
|
||||
final boolean replaceExisting) throws IOException {
|
||||
if (folder == null)
|
||||
return false;
|
||||
|
||||
// skip .DS_Store files, etc (this shouldn't actually be necessary)
|
||||
if (!folder.isDirectory()) return false;
|
||||
|
||||
@ -1501,8 +1586,13 @@ public class Base {
|
||||
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
ActionListener listener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
activeEditor.getSketch().importLibrary(e.getActionCommand());
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
String jarPath = event.getActionCommand();
|
||||
try {
|
||||
activeEditor.getSketch().importLibrary(jarPath);
|
||||
} catch (IOException e) {
|
||||
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", jarPath), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -1524,8 +1614,12 @@ public class Base {
|
||||
* the header files in its sub-folders, as those should be included from
|
||||
* within the header files at the top-level).
|
||||
*/
|
||||
static public String[] headerListFromIncludePath(File path) {
|
||||
return path.list(new OnlyFilesWithExtension(".h"));
|
||||
static public String[] headerListFromIncludePath(File path) throws IOException {
|
||||
String[] list = path.list(new OnlyFilesWithExtension(".h"));
|
||||
if (list == null) {
|
||||
throw new IOException();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected void loadHardware(File folder) {
|
||||
@ -1698,6 +1792,9 @@ public class Base {
|
||||
|
||||
|
||||
static public File getSettingsFolder() {
|
||||
if (portableFolder != null)
|
||||
return portableFolder;
|
||||
|
||||
File settingsFolder = null;
|
||||
|
||||
String preferencesPath = Preferences.get("settings.path");
|
||||
@ -1717,8 +1814,8 @@ public class Base {
|
||||
if (!settingsFolder.exists()) {
|
||||
if (!settingsFolder.mkdirs()) {
|
||||
showError(_("Settings issues"),
|
||||
_("Arduino cannot run because it could not\n" +
|
||||
"create a folder to store your settings."), null);
|
||||
_("Arduino cannot run because it could not\n" +
|
||||
"create a folder to store your settings."), null);
|
||||
}
|
||||
}
|
||||
return settingsFolder;
|
||||
@ -1849,7 +1946,10 @@ public class Base {
|
||||
*/
|
||||
static public TargetPlatform getTargetPlatform(String packageName,
|
||||
String platformName) {
|
||||
return packages.get(packageName).get(platformName);
|
||||
TargetPackage p = packages.get(packageName);
|
||||
if (p == null)
|
||||
return null;
|
||||
return p.get(platformName);
|
||||
}
|
||||
|
||||
static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) {
|
||||
@ -1874,7 +1974,19 @@ public class Base {
|
||||
return boardPreferences;
|
||||
}
|
||||
|
||||
static public File getPortableFolder() {
|
||||
return portableFolder;
|
||||
}
|
||||
|
||||
|
||||
static public String getPortableSketchbookFolder() {
|
||||
return portableSketchbookFolder;
|
||||
}
|
||||
|
||||
|
||||
static public File getSketchbookFolder() {
|
||||
if (portableFolder != null)
|
||||
return new File(portableFolder, Preferences.get("sketchbook.path"));
|
||||
return new File(Preferences.get("sketchbook.path"));
|
||||
}
|
||||
|
||||
@ -1907,6 +2019,9 @@ public class Base {
|
||||
|
||||
|
||||
protected File getDefaultSketchbookFolder() {
|
||||
if (portableFolder != null)
|
||||
return new File(portableFolder, portableSketchbookFolder);
|
||||
|
||||
File sketchbookFolder = null;
|
||||
try {
|
||||
sketchbookFolder = platform.getDefaultSketchbookFolder();
|
||||
|
@ -508,12 +508,14 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
if (sketchbookMenu == null) {
|
||||
sketchbookMenu = new JMenu(_("Sketchbook"));
|
||||
MenuScroller.setScrollerFor(sketchbookMenu);
|
||||
base.rebuildSketchbookMenu(sketchbookMenu);
|
||||
}
|
||||
fileMenu.add(sketchbookMenu);
|
||||
|
||||
if (examplesMenu == null) {
|
||||
examplesMenu = new JMenu(_("Examples"));
|
||||
MenuScroller.setScrollerFor(examplesMenu);
|
||||
base.rebuildExamplesMenu(examplesMenu);
|
||||
}
|
||||
fileMenu.add(examplesMenu);
|
||||
@ -727,7 +729,10 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
|
||||
protected void addTools(JMenu menu, File sourceFolder) {
|
||||
HashMap<String, JMenuItem> toolItems = new HashMap<String, JMenuItem>();
|
||||
if (sourceFolder == null)
|
||||
return;
|
||||
|
||||
Map<String, JMenuItem> toolItems = new HashMap<String, JMenuItem>();
|
||||
|
||||
File[] folders = sourceFolder.listFiles(new FileFilter() {
|
||||
public boolean accept(File folder) {
|
||||
@ -956,6 +961,9 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
serialMonitor.closeSerialPort();
|
||||
serialMonitor.setVisible(false);
|
||||
serialMonitor = new SerialMonitor(Preferences.get("serial.port"));
|
||||
|
||||
onBoardOrPortChange();
|
||||
|
||||
//System.out.println("set to " + get("serial.port"));
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
import processing.app.tools.MenuScroller;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.awt.*;
|
||||
@ -238,6 +239,7 @@ public class EditorHeader extends JComponent {
|
||||
|
||||
} else {
|
||||
menu = new JMenu();
|
||||
MenuScroller.setScrollerFor(menu);
|
||||
popup = menu.getPopupMenu();
|
||||
add(popup);
|
||||
popup.setLightWeightPopupEnabled(true);
|
||||
|
@ -72,6 +72,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
|
||||
//Thread promptThread;
|
||||
int response;
|
||||
|
||||
boolean initialized = false;
|
||||
|
||||
public EditorStatus(Editor editor) {
|
||||
this.editor = editor;
|
||||
@ -237,7 +238,10 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
|
||||
|
||||
public void paintComponent(Graphics screen) {
|
||||
//if (screen == null) return;
|
||||
if (okButton == null) setup();
|
||||
if (!initialized) {
|
||||
setup();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
//System.out.println("status.paintComponent");
|
||||
|
||||
@ -290,8 +294,8 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
|
||||
|
||||
protected void setup() {
|
||||
if (okButton == null) {
|
||||
cancelButton = new JButton(Preferences.PROMPT_CANCEL);
|
||||
okButton = new JButton(Preferences.PROMPT_OK);
|
||||
cancelButton = new JButton(I18n.PROMPT_CANCEL);
|
||||
okButton = new JButton(I18n.PROMPT_OK);
|
||||
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@ -500,4 +504,8 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
return initialized;
|
||||
}
|
||||
}
|
||||
|
@ -19,15 +19,29 @@ import java.text.MessageFormat;
|
||||
|
||||
public class I18n {
|
||||
// start using current locale but still allow using the dropdown list later
|
||||
private static ResourceBundle i18n = ResourceBundle.getBundle("processing.app.Resources");
|
||||
public static Locale locale;
|
||||
private static ResourceBundle i18n;
|
||||
|
||||
// prompt text stuff
|
||||
|
||||
static String PROMPT_YES;
|
||||
static String PROMPT_NO;
|
||||
static String PROMPT_CANCEL;
|
||||
static String PROMPT_OK;
|
||||
static String PROMPT_BROWSE;
|
||||
|
||||
static protected void init (String language) {
|
||||
// there might be a null pointer exception ... most likely will never happen but the jvm gets mad
|
||||
try {
|
||||
if (language == null || language.trim().length() == 0) locale = Locale.getDefault();
|
||||
else locale = new Locale(language);
|
||||
i18n = ResourceBundle.getBundle("processing.app.Resources", locale);
|
||||
if (language != null && language.trim().length() > 0) {
|
||||
Locale.setDefault(new Locale(language));
|
||||
}
|
||||
i18n = ResourceBundle.getBundle("processing.app.Resources", Locale.getDefault());
|
||||
|
||||
PROMPT_YES = _("Yes");
|
||||
PROMPT_NO = _("No");
|
||||
PROMPT_CANCEL = _("Cancel");
|
||||
PROMPT_OK = _("OK");
|
||||
PROMPT_BROWSE = _("Browse");
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import javax.swing.UIManager;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import processing.core.PConstants;
|
||||
|
||||
|
||||
/**
|
||||
@ -159,6 +160,10 @@ public class Platform {
|
||||
return clib.unsetenv(variable);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return PConstants.platformNames[PConstants.OTHER];
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
@ -23,16 +23,18 @@
|
||||
|
||||
package processing.app;
|
||||
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.syntax.SyntaxStyle;
|
||||
import processing.core.PApplet;
|
||||
import processing.core.PConstants;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.syntax.*;
|
||||
import processing.core.*;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
||||
@ -71,20 +73,14 @@ public class Preferences {
|
||||
|
||||
static final String PREFS_FILE = "preferences.txt";
|
||||
|
||||
|
||||
// prompt text stuff
|
||||
|
||||
static final String PROMPT_YES = _("Yes");
|
||||
static final String PROMPT_NO = _("No");
|
||||
static final String PROMPT_CANCEL = _("Cancel");
|
||||
static final String PROMPT_OK = _("OK");
|
||||
static final String PROMPT_BROWSE = _("Browse");
|
||||
|
||||
String[] languages = {
|
||||
_("System Default"),
|
||||
"العربية" + " (" + _("Arabic") + ")",
|
||||
"Aragonés" + " (" + _("Aragonese") + ")",
|
||||
"български" + " (" + _("Bulgarian") + ")",
|
||||
"Català" + " (" + _("Catalan") + ")",
|
||||
"Hrvatski" + " (" + _("Croatian") + ")",
|
||||
"český" + " (" + _("Czech") + ")",
|
||||
"简体中文" + " (" + _("Chinese Simplified") + ")",
|
||||
"繁體中文" + " (" + _("Chinese Traditional") + ")",
|
||||
"Dansk" + " (" + _("Danish") + ")",
|
||||
@ -93,7 +89,10 @@ public class Preferences {
|
||||
"Eesti" + " (" + _("Estonian") + ")",
|
||||
"Pilipino" + " (" + _("Filipino") + ")",
|
||||
"Français" + " (" + _("French") + ")",
|
||||
"Canadienne-français" + " (" + _("Canadian French") + ")",
|
||||
"Galego" + " (" + _("Galician") + ")",
|
||||
"საქართველოს" + " (" + _("Georgian") + ")",
|
||||
"עברית" + " (" + _("Hebrew") + ")",
|
||||
"Deutsch" + " (" + _("German") + ")",
|
||||
"ελληνικά" + " (" + _("Greek") + ")",
|
||||
"Magyar" + " (" + _("Hindi") + ")",
|
||||
@ -104,8 +103,9 @@ public class Preferences {
|
||||
"한국어" + " (" + _("Korean") + ")",
|
||||
"Latviešu" + " (" + _("Latvian") + ")",
|
||||
"Lietuvių Kalba" + " (" + _("Lithuaninan") + ")",
|
||||
"मराठी" + " (" + _("Marathi") + ")",
|
||||
"मराठी" + " (" + _("Marathi") + ")",
|
||||
"Norsk" + " (" + _("Norwegian") + ")",
|
||||
"Norsk bokmål" + " (" + _("Norwegian Bokmål") + ")",
|
||||
"فارسی" + " (" + _("Persian") + ")",
|
||||
"Język Polski" + " (" + _("Polish") + ")",
|
||||
"Português" + " (" + _("Portuguese") + " - Brazil)",
|
||||
@ -113,12 +113,18 @@ public class Preferences {
|
||||
"Română" + " (" + _("Romanian") + ")",
|
||||
"Русский" + " (" + _("Russian") + ")",
|
||||
"Español" + " (" + _("Spanish") + ")",
|
||||
"தமிழ்" + " (" + _("Tamil") + ")"};
|
||||
"தமிழ்" + " (" + _("Tamil") + ")",
|
||||
"Türk" + " (" + _("Turkish") + ")",
|
||||
"Український" + " (" + _("Ukrainian") + ")"
|
||||
};
|
||||
String[] languagesISO = {
|
||||
"",
|
||||
"ar",
|
||||
"an",
|
||||
"bg",
|
||||
"ca",
|
||||
"hr_hr",
|
||||
"cs_cz",
|
||||
"zh_cn",
|
||||
"zh_tw",
|
||||
"da",
|
||||
@ -127,7 +133,10 @@ public class Preferences {
|
||||
"et",
|
||||
"tl",
|
||||
"fr",
|
||||
"fr_ca",
|
||||
"gl",
|
||||
"ka_ge",
|
||||
"he",
|
||||
"de",
|
||||
"el",
|
||||
"hi",
|
||||
@ -140,6 +149,7 @@ public class Preferences {
|
||||
"lt",
|
||||
"mr",
|
||||
"no_nb",
|
||||
"nb_no",
|
||||
"fa",
|
||||
"pl",
|
||||
"pt_br",
|
||||
@ -147,7 +157,10 @@ public class Preferences {
|
||||
"ro",
|
||||
"ru",
|
||||
"es",
|
||||
"ta"};
|
||||
"ta",
|
||||
"tr",
|
||||
"uk"
|
||||
};
|
||||
|
||||
/**
|
||||
* Standardized width for buttons. Mac OS X 10.3 wants 70 as its default,
|
||||
@ -221,14 +234,13 @@ public class Preferences {
|
||||
}
|
||||
|
||||
// set some runtime constants (not saved on preferences file)
|
||||
table.put("runtime.os", PConstants.platformNames[PApplet.platform]);
|
||||
File hardwareFolder = Base.getHardwareFolder();
|
||||
table.put("runtime.hardware.path", hardwareFolder.getAbsolutePath());
|
||||
table.put("runtime.ide.path", hardwareFolder.getParentFile().getAbsolutePath());
|
||||
table.put("runtime.ide.version", "" + Base.REVISION);
|
||||
|
||||
// check for platform-specific properties in the defaults
|
||||
String platformExt = "." + PConstants.platformNames[PApplet.platform];
|
||||
String platformExt = "." + Base.platform.getName();
|
||||
int platformExtLength = platformExt.length();
|
||||
Enumeration e = table.keys();
|
||||
while (e.hasMoreElements()) {
|
||||
@ -244,9 +256,6 @@ public class Preferences {
|
||||
// clone the hash table
|
||||
defaults = (Hashtable) table.clone();
|
||||
|
||||
// other things that have to be set explicitly for the defaults
|
||||
setColor("run.window.bgcolor", SystemColor.control);
|
||||
|
||||
// Load a prefs file if specified on the command line
|
||||
if (commandLinePrefs != null) {
|
||||
try {
|
||||
@ -283,7 +292,16 @@ public class Preferences {
|
||||
), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// load the I18n module for internationalization
|
||||
I18n.init(Preferences.get("editor.languages.current"));
|
||||
|
||||
// set some other runtime constants (not saved on preferences file)
|
||||
table.put("runtime.os", PConstants.platformNames[PApplet.platform]);
|
||||
|
||||
// other things that have to be set explicitly for the defaults
|
||||
setColor("run.window.bgcolor", SystemColor.control);
|
||||
}
|
||||
|
||||
|
||||
@ -322,14 +340,21 @@ public class Preferences {
|
||||
pain.add(sketchbookLocationField);
|
||||
d = sketchbookLocationField.getPreferredSize();
|
||||
|
||||
button = new JButton(PROMPT_BROWSE);
|
||||
button = new JButton(I18n.PROMPT_BROWSE);
|
||||
button.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
File dflt = new File(sketchbookLocationField.getText());
|
||||
File file =
|
||||
Base.selectFolder(_("Select new sketchbook location"), dflt, dialog);
|
||||
Base.selectFolder(_("Select new sketchbook location"), dflt, dialog);
|
||||
if (file != null) {
|
||||
sketchbookLocationField.setText(file.getAbsolutePath());
|
||||
String path = file.getAbsolutePath();
|
||||
if (Base.getPortableFolder() != null) {
|
||||
path = FileUtils.relativePath(Base.getPortableFolder().toString(), path);
|
||||
if (path == null) {
|
||||
path = Base.getPortableSketchbookFolder();
|
||||
}
|
||||
}
|
||||
sketchbookLocationField.setText(path);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -442,6 +467,10 @@ public class Preferences {
|
||||
autoAssociateBox.setBounds(left, top, d.width + 10, d.height);
|
||||
right = Math.max(right, left + d.width);
|
||||
top += d.height + GUI_BETWEEN;
|
||||
|
||||
// If using portable mode, it's bad manner to change PC setting.
|
||||
if (Base.getPortableFolder() != null)
|
||||
autoAssociateBox.setEnabled(false);
|
||||
}
|
||||
|
||||
// More preferences are in the ...
|
||||
@ -460,7 +489,7 @@ public class Preferences {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
Base.openFolder(Base.getSettingsFolder());
|
||||
}
|
||||
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
clickable.setForeground(new Color(0, 0, 140));
|
||||
}
|
||||
@ -486,7 +515,7 @@ public class Preferences {
|
||||
|
||||
// [ OK ] [ Cancel ] maybe these should be next to the message?
|
||||
|
||||
button = new JButton(PROMPT_OK);
|
||||
button = new JButton(I18n.PROMPT_OK);
|
||||
button.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
applyFrame();
|
||||
@ -501,7 +530,7 @@ public class Preferences {
|
||||
button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
h += BUTTON_WIDTH + GUI_SMALL;
|
||||
|
||||
button = new JButton(PROMPT_CANCEL);
|
||||
button = new JButton(I18n.PROMPT_CANCEL);
|
||||
button.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
disposeFrame();
|
||||
@ -594,6 +623,12 @@ public class Preferences {
|
||||
// if the sketchbook path has changed, rebuild the menus
|
||||
String oldPath = get("sketchbook.path");
|
||||
String newPath = sketchbookLocationField.getText();
|
||||
if (newPath.isEmpty()) {
|
||||
if (Base.getPortableFolder() == null)
|
||||
newPath = editor.base.getDefaultSketchbookFolder().toString();
|
||||
else
|
||||
newPath = Base.getPortableSketchbookFolder();
|
||||
}
|
||||
if (!newPath.equals(oldPath)) {
|
||||
editor.base.rebuildSketchbookMenus();
|
||||
set("sketchbook.path", newPath);
|
||||
@ -682,8 +717,8 @@ public class Preferences {
|
||||
load(input, table);
|
||||
}
|
||||
|
||||
static public void load(InputStream input, Map table) throws IOException {
|
||||
String[] lines = PApplet.loadStrings(input); // Reads as UTF-8
|
||||
static public void load(InputStream input, Map table) throws IOException {
|
||||
String[] lines = loadStrings(input); // Reads as UTF-8
|
||||
for (String line : lines) {
|
||||
if ((line.length() == 0) ||
|
||||
(line.charAt(0) == '#')) continue;
|
||||
@ -698,6 +733,41 @@ public class Preferences {
|
||||
}
|
||||
}
|
||||
|
||||
static public String[] loadStrings(InputStream input) {
|
||||
try {
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new InputStreamReader(input, "UTF-8"));
|
||||
|
||||
String lines[] = new String[100];
|
||||
int lineCount = 0;
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (lineCount == lines.length) {
|
||||
String temp[] = new String[lineCount << 1];
|
||||
System.arraycopy(lines, 0, temp, 0, lineCount);
|
||||
lines = temp;
|
||||
}
|
||||
lines[lineCount++] = line;
|
||||
}
|
||||
reader.close();
|
||||
|
||||
if (lineCount == lines.length) {
|
||||
return lines;
|
||||
}
|
||||
|
||||
// resize array to appropriate amount for these lines
|
||||
String output[] = new String[lineCount];
|
||||
System.arraycopy(lines, 0, output, 0, lineCount);
|
||||
return output;
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
//throw new RuntimeException("Error inside loadStrings()");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// .................................................................
|
||||
|
||||
@ -712,9 +782,9 @@ public class Preferences {
|
||||
// Fix for 0163 to properly use Unicode when writing preferences.txt
|
||||
PrintWriter writer = PApplet.createWriter(preferencesFile);
|
||||
|
||||
Enumeration e = table.keys(); //properties.propertyNames();
|
||||
while (e.hasMoreElements()) {
|
||||
String key = (String) e.nextElement();
|
||||
String[] keys = (String[])table.keySet().toArray(new String[0]);
|
||||
Arrays.sort(keys);
|
||||
for (String key: keys) {
|
||||
if (key.startsWith("runtime."))
|
||||
continue;
|
||||
writer.println(key + "=" + ((String) table.get(key)));
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1579
app/src/processing/app/Resources_bg.po
Normal file
1579
app/src/processing/app/Resources_bg.po
Normal file
File diff suppressed because it is too large
Load Diff
1080
app/src/processing/app/Resources_bg.properties
Normal file
1080
app/src/processing/app/Resources_bg.properties
Normal file
File diff suppressed because it is too large
Load Diff
1581
app/src/processing/app/Resources_cs_cz.po
Normal file
1581
app/src/processing/app/Resources_cs_cz.po
Normal file
File diff suppressed because it is too large
Load Diff
1082
app/src/processing/app/Resources_cs_cz.properties
Normal file
1082
app/src/processing/app/Resources_cs_cz.properties
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1579
app/src/processing/app/Resources_fr_ca.po
Normal file
1579
app/src/processing/app/Resources_fr_ca.po
Normal file
File diff suppressed because it is too large
Load Diff
1080
app/src/processing/app/Resources_fr_ca.properties
Normal file
1080
app/src/processing/app/Resources_fr_ca.properties
Normal file
File diff suppressed because it is too large
Load Diff
1579
app/src/processing/app/Resources_hr_hr.po
Normal file
1579
app/src/processing/app/Resources_hr_hr.po
Normal file
File diff suppressed because it is too large
Load Diff
1080
app/src/processing/app/Resources_hr_hr.properties
Normal file
1080
app/src/processing/app/Resources_hr_hr.properties
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1580
app/src/processing/app/Resources_iw.po
Normal file
1580
app/src/processing/app/Resources_iw.po
Normal file
File diff suppressed because it is too large
Load Diff
1081
app/src/processing/app/Resources_iw.properties
Normal file
1081
app/src/processing/app/Resources_iw.properties
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1579
app/src/processing/app/Resources_ka_ge.po
Normal file
1579
app/src/processing/app/Resources_ka_ge.po
Normal file
File diff suppressed because it is too large
Load Diff
1080
app/src/processing/app/Resources_ka_ge.properties
Normal file
1080
app/src/processing/app/Resources_ka_ge.properties
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1579
app/src/processing/app/Resources_nb_no.po
Normal file
1579
app/src/processing/app/Resources_nb_no.po
Normal file
File diff suppressed because it is too large
Load Diff
1080
app/src/processing/app/Resources_nb_no.properties
Normal file
1080
app/src/processing/app/Resources_nb_no.properties
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1582
app/src/processing/app/Resources_tr.po
Normal file
1582
app/src/processing/app/Resources_tr.po
Normal file
File diff suppressed because it is too large
Load Diff
1083
app/src/processing/app/Resources_tr.properties
Normal file
1083
app/src/processing/app/Resources_tr.properties
Normal file
File diff suppressed because it is too large
Load Diff
1578
app/src/processing/app/Resources_uk.po
Normal file
1578
app/src/processing/app/Resources_uk.po
Normal file
File diff suppressed because it is too large
Load Diff
1079
app/src/processing/app/Resources_uk.properties
Normal file
1079
app/src/processing/app/Resources_uk.properties
Normal file
File diff suppressed because it is too large
Load Diff
@ -612,7 +612,7 @@ public class Sketch {
|
||||
|
||||
} else {
|
||||
// delete the file
|
||||
if (!current.deleteFile()) {
|
||||
if (!current.deleteFile(tempBuildFolder)) {
|
||||
Base.showMessage(_("Couldn't do it"),
|
||||
I18n.format(_("Could not delete \"{0}\"."), current.getFileName()));
|
||||
return;
|
||||
@ -826,7 +826,7 @@ public class Sketch {
|
||||
FileDialog.SAVE);
|
||||
if (isReadOnly() || isUntitled()) {
|
||||
// default to the sketchbook folder
|
||||
fd.setDirectory(Preferences.get("sketchbook.path"));
|
||||
fd.setDirectory(Base.getSketchbookFolder().getAbsolutePath());
|
||||
} else {
|
||||
// default to the parent folder of where this was
|
||||
fd.setDirectory(folder.getParent());
|
||||
@ -1124,7 +1124,7 @@ public class Sketch {
|
||||
* Add import statements to the current tab for all of packages inside
|
||||
* the specified jar file.
|
||||
*/
|
||||
public void importLibrary(String jarPath) {
|
||||
public void importLibrary(String jarPath) throws IOException {
|
||||
// make sure the user didn't hide the sketch folder
|
||||
ensureExistence();
|
||||
|
||||
@ -1339,7 +1339,6 @@ public class Sketch {
|
||||
// make sure the user didn't hide the sketch folder
|
||||
ensureExistence();
|
||||
|
||||
String[] codeFolderPackages = null;
|
||||
classPath = buildPath;
|
||||
|
||||
// // figure out the contents of the code folder to see if there
|
||||
@ -1381,12 +1380,8 @@ public class Sketch {
|
||||
// Note that the headerOffset isn't applied until compile and run, because
|
||||
// it only applies to the code after it's been written to the .java file.
|
||||
int headerOffset = 0;
|
||||
//PdePreprocessor preprocessor = new PdePreprocessor();
|
||||
try {
|
||||
headerOffset = preprocessor.writePrefix(bigCode.toString(),
|
||||
buildPath,
|
||||
name,
|
||||
codeFolderPackages);
|
||||
headerOffset = preprocessor.writePrefix(bigCode.toString());
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
fnfe.printStackTrace();
|
||||
String msg = _("Build folder disappeared or could not be written");
|
||||
@ -1399,24 +1394,14 @@ public class Sketch {
|
||||
String primaryClassName = null;
|
||||
|
||||
try {
|
||||
// if (i != 0) preproc will fail if a pde file is not
|
||||
// java mode, since that's required
|
||||
String className = preprocessor.write();
|
||||
|
||||
if (className == null) {
|
||||
throw new RunnerException(_("Could not find main class"));
|
||||
// this situation might be perfectly fine,
|
||||
// (i.e. if the file is empty)
|
||||
//System.out.println("No class found in " + code[i].name);
|
||||
//System.out.println("(any code in that file will be ignored)");
|
||||
//System.out.println();
|
||||
|
||||
// } else {
|
||||
// code[0].setPreprocName(className + ".java");
|
||||
}
|
||||
|
||||
// Output file
|
||||
File streamFile = new File(buildPath, name + ".cpp");
|
||||
FileOutputStream outputStream = new FileOutputStream(streamFile);
|
||||
preprocessor.write(outputStream);
|
||||
outputStream.close();
|
||||
|
||||
// store this for the compiler and the runtime
|
||||
primaryClassName = className + ".cpp";
|
||||
primaryClassName = name + ".cpp";
|
||||
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
fnfe.printStackTrace();
|
||||
@ -1630,7 +1615,7 @@ public class Sketch {
|
||||
editor.status.progressUpdate(percent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void size(PreferencesMap prefs) throws RunnerException {
|
||||
long size = 0;
|
||||
String maxsizeString = prefs.get("upload.maximum_size");
|
||||
@ -1641,8 +1626,8 @@ public class Sketch {
|
||||
try {
|
||||
size = sizer.computeSize();
|
||||
System.out.println(I18n
|
||||
.format(_("Binary sketch size: {0} bytes (of a {1} byte maximum)"),
|
||||
size, maxsize));
|
||||
.format(_("Binary sketch size: {0} bytes (of a {1} byte maximum) - {2}% used"),
|
||||
size, maxsize, size * 100 / maxsize));
|
||||
} catch (RunnerException e) {
|
||||
System.err.println(I18n.format(_("Couldn't determine program size: {0}"),
|
||||
e.getMessage()));
|
||||
@ -1668,58 +1653,7 @@ public class Sketch {
|
||||
return success ? suggestedClassName : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all commented portions of a given String as spaces.
|
||||
* Utility function used here and in the preprocessor.
|
||||
*/
|
||||
static public String scrubComments(String what) {
|
||||
char p[] = what.toCharArray();
|
||||
|
||||
int index = 0;
|
||||
while (index < p.length) {
|
||||
// for any double slash comments, ignore until the end of the line
|
||||
if ((p[index] == '/') &&
|
||||
(index < p.length - 1) &&
|
||||
(p[index+1] == '/')) {
|
||||
p[index++] = ' ';
|
||||
p[index++] = ' ';
|
||||
while ((index < p.length) &&
|
||||
(p[index] != '\n')) {
|
||||
p[index++] = ' ';
|
||||
}
|
||||
|
||||
// check to see if this is the start of a new multiline comment.
|
||||
// if it is, then make sure it's actually terminated somewhere.
|
||||
} else if ((p[index] == '/') &&
|
||||
(index < p.length - 1) &&
|
||||
(p[index+1] == '*')) {
|
||||
p[index++] = ' ';
|
||||
p[index++] = ' ';
|
||||
boolean endOfRainbow = false;
|
||||
while (index < p.length - 1) {
|
||||
if ((p[index] == '*') && (p[index+1] == '/')) {
|
||||
p[index++] = ' ';
|
||||
p[index++] = ' ';
|
||||
endOfRainbow = true;
|
||||
break;
|
||||
|
||||
} else {
|
||||
// continue blanking this area
|
||||
p[index++] = ' ';
|
||||
}
|
||||
}
|
||||
if (!endOfRainbow) {
|
||||
throw new RuntimeException(_("Missing the */ from the end of a " +
|
||||
"/* comment */"));
|
||||
}
|
||||
} else { // any old character, move along
|
||||
index++;
|
||||
}
|
||||
}
|
||||
return new String(p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean exportApplicationPrompt() throws IOException, RunnerException {
|
||||
return false;
|
||||
}
|
||||
|
@ -107,8 +107,21 @@ public class SketchCode {
|
||||
}
|
||||
|
||||
|
||||
protected boolean deleteFile() {
|
||||
return file.delete();
|
||||
protected boolean deleteFile(File tempBuildFolder) {
|
||||
if (!file.delete()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
File[] compiledFiles = tempBuildFolder.listFiles(new FileFilter() {
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.getName().startsWith(getFileName());
|
||||
}
|
||||
});
|
||||
for (File compiledFile : compiledFiles) {
|
||||
compiledFile.delete();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,7 +41,6 @@ public class TargetPlatform {
|
||||
private MapWithSubkeys customMenus;
|
||||
|
||||
public TargetPlatform(String _name, File _folder) {
|
||||
System.out.println("TargetPlatform: constructor start, name: " + _name);
|
||||
name = _name;
|
||||
folder = _folder;
|
||||
boards = new HashMap<String, PreferencesMap>();
|
||||
|
@ -90,4 +90,68 @@ public class FileUtils {
|
||||
return tmpFolder;
|
||||
}
|
||||
|
||||
//
|
||||
// Compute relative path to "target" from a directory "origin".
|
||||
//
|
||||
// If "origin" is not absolute, it is relative from the current directory.
|
||||
// If "target" is not absolute, it is relative from "origin".
|
||||
//
|
||||
// by Shigeru KANEMOTO at SWITCHSCIENCE.
|
||||
//
|
||||
public static String relativePath(String origin, String target) {
|
||||
try {
|
||||
origin = (new File(origin)).getCanonicalPath();
|
||||
File targetFile = new File(target);
|
||||
if (targetFile.isAbsolute())
|
||||
target = targetFile.getCanonicalPath();
|
||||
else
|
||||
target = (new File(origin, target)).getCanonicalPath();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (origin.equals(target)) {
|
||||
// origin and target is identical.
|
||||
return ".";
|
||||
}
|
||||
|
||||
if (origin.equals(File.separator)) {
|
||||
// origin is root.
|
||||
return "." + target;
|
||||
}
|
||||
|
||||
String prefix = "";
|
||||
String root = File.separator;
|
||||
|
||||
if (System.getProperty("os.name").indexOf("Windows") != -1) {
|
||||
if (origin.startsWith("\\\\") || target.startsWith("\\\\")) {
|
||||
// Windows UNC path not supported.
|
||||
return null;
|
||||
}
|
||||
|
||||
char originLetter = origin.charAt(0);
|
||||
char targetLetter = target.charAt(0);
|
||||
if (Character.isLetter(originLetter) && Character.isLetter(targetLetter)) {
|
||||
// Windows only
|
||||
if (originLetter != targetLetter) {
|
||||
// Drive letters differ
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
prefix = "" + originLetter + ':';
|
||||
root = prefix + File.separator;
|
||||
}
|
||||
|
||||
String relative = "";
|
||||
while (!target.startsWith(origin + File.separator)) {
|
||||
origin = (new File(origin)).getParent();
|
||||
if (origin.equals(root))
|
||||
origin = prefix;
|
||||
relative += "..";
|
||||
relative += File.separator;
|
||||
}
|
||||
|
||||
return relative + target.substring(origin.length() + 1);
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import java.io.File;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import processing.app.Preferences;
|
||||
import processing.core.PConstants;
|
||||
|
||||
|
||||
/**
|
||||
@ -52,6 +53,12 @@ public class Platform extends processing.app.Platform {
|
||||
}
|
||||
|
||||
|
||||
public File getDefaultSketchbookFolder() throws Exception {
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
return new File(home, "Arduino");
|
||||
}
|
||||
|
||||
|
||||
public void openURL(String url) throws Exception {
|
||||
if (openFolderAvailable()) {
|
||||
String launcher = Preferences.get("launcher");
|
||||
@ -112,4 +119,9 @@ public class Platform extends processing.app.Platform {
|
||||
file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return PConstants.platformNames[PConstants.LINUX];
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import com.apple.eio.FileManager;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.core.PApplet;
|
||||
import processing.core.PConstants;
|
||||
|
||||
|
||||
/**
|
||||
@ -195,4 +196,10 @@ public class Platform extends processing.app.Platform {
|
||||
protected String getDocumentsFolder() throws FileNotFoundException {
|
||||
return FileManager.findFolder(kUserDomain, kDocumentsFolderType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return PConstants.platformNames[PConstants.MACOSX];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
package processing.app.preproc;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import processing.app.*;
|
||||
import processing.core.*;
|
||||
|
||||
@ -61,38 +62,22 @@ public class PdePreprocessor {
|
||||
// than the others, since the imports are auto-generated.
|
||||
List<String> codeFolderImports;
|
||||
|
||||
String indent;
|
||||
|
||||
PrintStream stream;
|
||||
String program;
|
||||
String buildPath;
|
||||
// starts as sketch name, ends as main class name
|
||||
String name;
|
||||
|
||||
|
||||
/**
|
||||
* Setup a new preprocessor.
|
||||
*/
|
||||
public PdePreprocessor() {
|
||||
int tabSize = Preferences.getInteger("editor.tabs.size");
|
||||
char[] indentChars = new char[tabSize];
|
||||
Arrays.fill(indentChars, ' ');
|
||||
indent = new String(indentChars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes out the head of the c++ code generated for a sketch.
|
||||
* Called from processing.app.Sketch.
|
||||
* @param program the concatenated code from all tabs containing pde-files
|
||||
* @param buildPath the path into which the processed pde-code is to be written
|
||||
* @param name the name of the sketch
|
||||
* @param codeFolderPackages unused param (leftover from processing)
|
||||
*/
|
||||
public int writePrefix(String program, String buildPath,
|
||||
String sketchName, String codeFolderPackages[]) throws FileNotFoundException {
|
||||
this.buildPath = buildPath;
|
||||
this.name = sketchName;
|
||||
|
||||
public int writePrefix(String program)
|
||||
throws FileNotFoundException {
|
||||
// if the program ends with no CR or LF an OutOfMemoryError will happen.
|
||||
// not gonna track down the bug now, so here's a hack for it:
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=5
|
||||
@ -102,7 +87,7 @@ public class PdePreprocessor {
|
||||
// an OutOfMemoryError or NullPointerException will happen.
|
||||
// again, not gonna bother tracking this down, but here's a hack.
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=16
|
||||
Sketch.scrubComments(program);
|
||||
scrubComments(program);
|
||||
// If there are errors, an exception is thrown and this fxn exits.
|
||||
|
||||
if (Preferences.getBoolean("preproc.substitute_unicode")) {
|
||||
@ -134,10 +119,6 @@ public class PdePreprocessor {
|
||||
// do this after the program gets re-combobulated
|
||||
this.program = program;
|
||||
|
||||
// output the code
|
||||
File streamFile = new File(buildPath, name + ".cpp");
|
||||
stream = new PrintStream(new FileOutputStream(streamFile));
|
||||
|
||||
return headerCount + prototypeCount;
|
||||
}
|
||||
|
||||
@ -181,17 +162,16 @@ public class PdePreprocessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* preprocesses a pde file and writes out a java file
|
||||
* @return the classname of the exported Java
|
||||
* preprocesses a pde file and writes out a cpp file into the specified
|
||||
* OutputStream
|
||||
*
|
||||
* @param output
|
||||
* @throws Exception
|
||||
*/
|
||||
//public String write(String program, String buildPath, String name,
|
||||
// String extraImports[]) throws java.lang.Exception {
|
||||
public String write() throws java.lang.Exception {
|
||||
public void write(OutputStream output) throws Exception {
|
||||
PrintStream stream = new PrintStream(output);
|
||||
writeProgram(stream, program, prototypes);
|
||||
writeFooter(stream);
|
||||
stream.close();
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
// Write the pde program to the cpp file
|
||||
@ -344,4 +324,56 @@ public class PdePreprocessor {
|
||||
|
||||
return functionMatches;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replace all commented portions of a given String as spaces.
|
||||
* Utility function used here and in the preprocessor.
|
||||
*/
|
||||
static public String scrubComments(String what) {
|
||||
char p[] = what.toCharArray();
|
||||
|
||||
int index = 0;
|
||||
while (index < p.length) {
|
||||
// for any double slash comments, ignore until the end of the line
|
||||
if ((p[index] == '/') &&
|
||||
(index < p.length - 1) &&
|
||||
(p[index+1] == '/')) {
|
||||
p[index++] = ' ';
|
||||
p[index++] = ' ';
|
||||
while ((index < p.length) &&
|
||||
(p[index] != '\n')) {
|
||||
p[index++] = ' ';
|
||||
}
|
||||
|
||||
// check to see if this is the start of a new multiline comment.
|
||||
// if it is, then make sure it's actually terminated somewhere.
|
||||
} else if ((p[index] == '/') &&
|
||||
(index < p.length - 1) &&
|
||||
(p[index+1] == '*')) {
|
||||
p[index++] = ' ';
|
||||
p[index++] = ' ';
|
||||
boolean endOfRainbow = false;
|
||||
while (index < p.length - 1) {
|
||||
if ((p[index] == '*') && (p[index+1] == '/')) {
|
||||
p[index++] = ' ';
|
||||
p[index++] = ' ';
|
||||
endOfRainbow = true;
|
||||
break;
|
||||
|
||||
} else {
|
||||
// continue blanking this area
|
||||
p[index++] = ' ';
|
||||
}
|
||||
}
|
||||
if (!endOfRainbow) {
|
||||
throw new RuntimeException(_("Missing the */ from the end of a " +
|
||||
"/* comment */"));
|
||||
}
|
||||
} else { // any old character, move along
|
||||
index++;
|
||||
}
|
||||
}
|
||||
return new String(p);
|
||||
}
|
||||
}
|
||||
|
633
app/src/processing/app/tools/MenuScroller.java
Normal file
633
app/src/processing/app/tools/MenuScroller.java
Normal file
@ -0,0 +1,633 @@
|
||||
/**
|
||||
* @(#)MenuScroller.java 1.5.0 04/02/12
|
||||
*/
|
||||
package processing.app.tools;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.MenuSelectionManager;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
/**
|
||||
* A class that provides scrolling capabilities to a long menu dropdown or
|
||||
* popup menu. A number of items can optionally be frozen at the top and/or
|
||||
* bottom of the menu.
|
||||
* <P>
|
||||
* <B>Implementation note:</B> The default number of items to display
|
||||
* at a time is 15, and the default scrolling interval is 125 milliseconds.
|
||||
* <P>
|
||||
*
|
||||
* @version 1.5.0 04/05/12
|
||||
* @author Darryl
|
||||
*/
|
||||
public class MenuScroller {
|
||||
|
||||
//private JMenu menu;
|
||||
private JPopupMenu menu;
|
||||
private Component[] menuItems;
|
||||
private MenuScrollItem upItem;
|
||||
private MenuScrollItem downItem;
|
||||
private final MenuScrollListener menuListener = new MenuScrollListener();
|
||||
private int scrollCount;
|
||||
private int interval;
|
||||
private int topFixedCount;
|
||||
private int bottomFixedCount;
|
||||
private int firstIndex = 0;
|
||||
private int keepVisibleIndex = -1;
|
||||
|
||||
private static int getMaximumItems(JPopupMenu menu) {
|
||||
JMenuItem test = new JMenuItem("test");
|
||||
ButtonUI ui = test.getUI();
|
||||
Dimension d = ui.getPreferredSize(test);
|
||||
double item_height = d.getHeight();
|
||||
//System.out.println("JMenuItem Height " + item_height);
|
||||
JMenuItem up = new JMenuItem(MenuIcon.UP);
|
||||
ui = up.getUI();
|
||||
d = ui.getPreferredSize(up);
|
||||
double icon_height = d.getHeight();
|
||||
//System.out.println("icon item height " + icon_height);
|
||||
double menu_border_height = 8.0; // kludge - how to detect this?
|
||||
double screen_height = java.awt.Toolkit.getDefaultToolkit().getScreenSize().getHeight();
|
||||
//System.out.println("screen height " + screen_height);
|
||||
int n = (int)((screen_height - icon_height * 2 - menu_border_height) / item_height);
|
||||
//System.out.println("max items " + n);
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a menu to be scrolled with the default number of items to
|
||||
* display at a time and the default scrolling interval.
|
||||
*
|
||||
* @param menu the menu
|
||||
* @return the MenuScroller
|
||||
*/
|
||||
public static MenuScroller setScrollerFor(JMenu menu) {
|
||||
return new MenuScroller(menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a popup menu to be scrolled with the default number of items to
|
||||
* display at a time and the default scrolling interval.
|
||||
*
|
||||
* @param menu the popup menu
|
||||
* @return the MenuScroller
|
||||
*/
|
||||
public static MenuScroller setScrollerFor(JPopupMenu menu) {
|
||||
return new MenuScroller(menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a menu to be scrolled with the default number of items to
|
||||
* display at a time and the specified scrolling interval.
|
||||
*
|
||||
* @param menu the menu
|
||||
* @param scrollCount the number of items to display at a time
|
||||
* @return the MenuScroller
|
||||
* @throws IllegalArgumentException if scrollCount is 0 or negative
|
||||
*/
|
||||
public static MenuScroller setScrollerFor(JMenu menu, int scrollCount) {
|
||||
return new MenuScroller(menu, scrollCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a popup menu to be scrolled with the default number of items to
|
||||
* display at a time and the specified scrolling interval.
|
||||
*
|
||||
* @param menu the popup menu
|
||||
* @param scrollCount the number of items to display at a time
|
||||
* @return the MenuScroller
|
||||
* @throws IllegalArgumentException if scrollCount is 0 or negative
|
||||
*/
|
||||
public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount) {
|
||||
return new MenuScroller(menu, scrollCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a menu to be scrolled, with the specified number of items to
|
||||
* display at a time and the specified scrolling interval.
|
||||
*
|
||||
* @param menu the menu
|
||||
* @param scrollCount the number of items to be displayed at a time
|
||||
* @param interval the scroll interval, in milliseconds
|
||||
* @return the MenuScroller
|
||||
* @throws IllegalArgumentException if scrollCount or interval is 0 or negative
|
||||
*/
|
||||
public static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval) {
|
||||
return new MenuScroller(menu, scrollCount, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a popup menu to be scrolled, with the specified number of items to
|
||||
* display at a time and the specified scrolling interval.
|
||||
*
|
||||
* @param menu the popup menu
|
||||
* @param scrollCount the number of items to be displayed at a time
|
||||
* @param interval the scroll interval, in milliseconds
|
||||
* @return the MenuScroller
|
||||
* @throws IllegalArgumentException if scrollCount or interval is 0 or negative
|
||||
*/
|
||||
public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval) {
|
||||
return new MenuScroller(menu, scrollCount, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a menu to be scrolled, with the specified number of items
|
||||
* to display in the scrolling region, the specified scrolling interval,
|
||||
* and the specified numbers of items fixed at the top and bottom of the
|
||||
* menu.
|
||||
*
|
||||
* @param menu the menu
|
||||
* @param scrollCount the number of items to display in the scrolling portion
|
||||
* @param interval the scroll interval, in milliseconds
|
||||
* @param topFixedCount the number of items to fix at the top. May be 0.
|
||||
* @param bottomFixedCount the number of items to fix at the bottom. May be 0
|
||||
* @throws IllegalArgumentException if scrollCount or interval is 0 or
|
||||
* negative or if topFixedCount or bottomFixedCount is negative
|
||||
* @return the MenuScroller
|
||||
*/
|
||||
public static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval,
|
||||
int topFixedCount, int bottomFixedCount) {
|
||||
return new MenuScroller(menu, scrollCount, interval,
|
||||
topFixedCount, bottomFixedCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a popup menu to be scrolled, with the specified number of items
|
||||
* to display in the scrolling region, the specified scrolling interval,
|
||||
* and the specified numbers of items fixed at the top and bottom of the
|
||||
* popup menu.
|
||||
*
|
||||
* @param menu the popup menu
|
||||
* @param scrollCount the number of items to display in the scrolling portion
|
||||
* @param interval the scroll interval, in milliseconds
|
||||
* @param topFixedCount the number of items to fix at the top. May be 0
|
||||
* @param bottomFixedCount the number of items to fix at the bottom. May be 0
|
||||
* @throws IllegalArgumentException if scrollCount or interval is 0 or
|
||||
* negative or if topFixedCount or bottomFixedCount is negative
|
||||
* @return the MenuScroller
|
||||
*/
|
||||
public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval,
|
||||
int topFixedCount, int bottomFixedCount) {
|
||||
return new MenuScroller(menu, scrollCount, interval,
|
||||
topFixedCount, bottomFixedCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>MenuScroller</code> that scrolls a menu with the
|
||||
* default number of items to display at a time, and default scrolling
|
||||
* interval.
|
||||
*
|
||||
* @param menu the menu
|
||||
*/
|
||||
public MenuScroller(JMenu menu) {
|
||||
this(menu, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
|
||||
* default number of items to display at a time, and default scrolling
|
||||
* interval.
|
||||
*
|
||||
* @param menu the popup menu
|
||||
*/
|
||||
public MenuScroller(JPopupMenu menu) {
|
||||
this(menu, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>MenuScroller</code> that scrolls a menu with the
|
||||
* specified number of items to display at a time, and default scrolling
|
||||
* interval.
|
||||
*
|
||||
* @param menu the menu
|
||||
* @param scrollCount the number of items to display at a time
|
||||
* @throws IllegalArgumentException if scrollCount is 0 or negative
|
||||
*/
|
||||
public MenuScroller(JMenu menu, int scrollCount) {
|
||||
this(menu, scrollCount, 150);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
|
||||
* specified number of items to display at a time, and default scrolling
|
||||
* interval.
|
||||
*
|
||||
* @param menu the popup menu
|
||||
* @param scrollCount the number of items to display at a time
|
||||
* @throws IllegalArgumentException if scrollCount is 0 or negative
|
||||
*/
|
||||
public MenuScroller(JPopupMenu menu, int scrollCount) {
|
||||
this(menu, scrollCount, 150);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>MenuScroller</code> that scrolls a menu with the
|
||||
* specified number of items to display at a time, and specified scrolling
|
||||
* interval.
|
||||
*
|
||||
* @param menu the menu
|
||||
* @param scrollCount the number of items to display at a time
|
||||
* @param interval the scroll interval, in milliseconds
|
||||
* @throws IllegalArgumentException if scrollCount or interval is 0 or negative
|
||||
*/
|
||||
public MenuScroller(JMenu menu, int scrollCount, int interval) {
|
||||
this(menu, scrollCount, interval, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
|
||||
* specified number of items to display at a time, and specified scrolling
|
||||
* interval.
|
||||
*
|
||||
* @param menu the popup menu
|
||||
* @param scrollCount the number of items to display at a time
|
||||
* @param interval the scroll interval, in milliseconds
|
||||
* @throws IllegalArgumentException if scrollCount or interval is 0 or negative
|
||||
*/
|
||||
public MenuScroller(JPopupMenu menu, int scrollCount, int interval) {
|
||||
this(menu, scrollCount, interval, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>MenuScroller</code> that scrolls a menu with the
|
||||
* specified number of items to display in the scrolling region, the
|
||||
* specified scrolling interval, and the specified numbers of items fixed at
|
||||
* the top and bottom of the menu.
|
||||
*
|
||||
* @param menu the menu
|
||||
* @param scrollCount the number of items to display in the scrolling portion
|
||||
* @param interval the scroll interval, in milliseconds
|
||||
* @param topFixedCount the number of items to fix at the top. May be 0
|
||||
* @param bottomFixedCount the number of items to fix at the bottom. May be 0
|
||||
* @throws IllegalArgumentException if scrollCount or interval is 0 or
|
||||
* negative or if topFixedCount or bottomFixedCount is negative
|
||||
*/
|
||||
public MenuScroller(JMenu menu, int scrollCount, int interval,
|
||||
int topFixedCount, int bottomFixedCount) {
|
||||
this(menu.getPopupMenu(), scrollCount, interval, topFixedCount, bottomFixedCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
|
||||
* specified number of items to display in the scrolling region, the
|
||||
* specified scrolling interval, and the specified numbers of items fixed at
|
||||
* the top and bottom of the popup menu.
|
||||
*
|
||||
* @param menu the popup menu
|
||||
* @param scrollCount the number of items to display in the scrolling portion
|
||||
* @param interval the scroll interval, in milliseconds
|
||||
* @param topFixedCount the number of items to fix at the top. May be 0
|
||||
* @param bottomFixedCount the number of items to fix at the bottom. May be 0
|
||||
* @throws IllegalArgumentException if scrollCount or interval is 0 or
|
||||
* negative or if topFixedCount or bottomFixedCount is negative
|
||||
*/
|
||||
public MenuScroller(JPopupMenu menu, int scrollCount, int interval,
|
||||
int topFixedCount, int bottomFixedCount) {
|
||||
|
||||
if(scrollCount == -1)
|
||||
scrollCount = getMaximumItems(menu)-topFixedCount-bottomFixedCount; // Autosize
|
||||
|
||||
if(interval == -1)
|
||||
interval = 150; // Default value
|
||||
|
||||
if (scrollCount <= 0 || interval <= 0) {
|
||||
throw new IllegalArgumentException("scrollCount and interval must be greater than 0");
|
||||
}
|
||||
if (topFixedCount < 0 || bottomFixedCount < 0) {
|
||||
throw new IllegalArgumentException("topFixedCount and bottomFixedCount cannot be negative");
|
||||
}
|
||||
|
||||
upItem = new MenuScrollItem(MenuIcon.UP, -1);
|
||||
downItem = new MenuScrollItem(MenuIcon.DOWN, +1);
|
||||
setScrollCount(scrollCount);
|
||||
setInterval(interval);
|
||||
setTopFixedCount(topFixedCount);
|
||||
setBottomFixedCount(bottomFixedCount);
|
||||
|
||||
this.menu = menu;
|
||||
menu.addPopupMenuListener(menuListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the scroll interval in milliseconds
|
||||
*
|
||||
* @return the scroll interval in milliseconds
|
||||
*/
|
||||
public int getInterval() {
|
||||
return interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the scroll interval in milliseconds
|
||||
*
|
||||
* @param interval the scroll interval in milliseconds
|
||||
* @throws IllegalArgumentException if interval is 0 or negative
|
||||
*/
|
||||
public void setInterval(int interval) {
|
||||
if (interval <= 0) {
|
||||
throw new IllegalArgumentException("interval must be greater than 0");
|
||||
}
|
||||
upItem.setInterval(interval);
|
||||
downItem.setInterval(interval);
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of items in the scrolling portion of the menu.
|
||||
*
|
||||
* @return the number of items to display at a time
|
||||
*/
|
||||
public int getscrollCount() {
|
||||
return scrollCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of items in the scrolling portion of the menu.
|
||||
*
|
||||
* @param scrollCount the number of items to display at a time
|
||||
* @throws IllegalArgumentException if scrollCount is 0 or negative
|
||||
*/
|
||||
public void setScrollCount(int scrollCount) {
|
||||
if (scrollCount <= 0) {
|
||||
throw new IllegalArgumentException("scrollCount must be greater than 0");
|
||||
}
|
||||
this.scrollCount = scrollCount;
|
||||
MenuSelectionManager.defaultManager().clearSelectedPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of items fixed at the top of the menu or popup menu.
|
||||
*
|
||||
* @return the number of items
|
||||
*/
|
||||
public int getTopFixedCount() {
|
||||
return topFixedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of items to fix at the top of the menu or popup menu.
|
||||
*
|
||||
* @param topFixedCount the number of items
|
||||
*/
|
||||
public void setTopFixedCount(int topFixedCount) {
|
||||
if (firstIndex <= topFixedCount) {
|
||||
firstIndex = topFixedCount;
|
||||
} else {
|
||||
firstIndex += (topFixedCount - this.topFixedCount);
|
||||
}
|
||||
this.topFixedCount = topFixedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of items fixed at the bottom of the menu or popup menu.
|
||||
*
|
||||
* @return the number of items
|
||||
*/
|
||||
public int getBottomFixedCount() {
|
||||
return bottomFixedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of items to fix at the bottom of the menu or popup menu.
|
||||
*
|
||||
* @param bottomFixedCount the number of items
|
||||
*/
|
||||
public void setBottomFixedCount(int bottomFixedCount) {
|
||||
this.bottomFixedCount = bottomFixedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls the specified item into view each time the menu is opened. Call this method with
|
||||
* <code>null</code> to restore the default behavior, which is to show the menu as it last
|
||||
* appeared.
|
||||
*
|
||||
* @param item the item to keep visible
|
||||
* @see #keepVisible(int)
|
||||
*/
|
||||
public void keepVisible(JMenuItem item) {
|
||||
if (item == null) {
|
||||
keepVisibleIndex = -1;
|
||||
} else {
|
||||
int index = menu.getComponentIndex(item);
|
||||
keepVisibleIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls the item at the specified index into view each time the menu is opened. Call this
|
||||
* method with <code>-1</code> to restore the default behavior, which is to show the menu as
|
||||
* it last appeared.
|
||||
*
|
||||
* @param index the index of the item to keep visible
|
||||
* @see #keepVisible(javax.swing.JMenuItem)
|
||||
*/
|
||||
public void keepVisible(int index) {
|
||||
keepVisibleIndex = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes this MenuScroller from the associated menu and restores the
|
||||
* default behavior of the menu.
|
||||
*/
|
||||
public void dispose() {
|
||||
if (menu != null) {
|
||||
menu.removePopupMenuListener(menuListener);
|
||||
menu = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the <code>dispose</code> method of this MenuScroller is
|
||||
* called when there are no more refrences to it.
|
||||
*
|
||||
* @exception Throwable if an error occurs.
|
||||
* @see MenuScroller#dispose()
|
||||
*/
|
||||
@Override
|
||||
public void finalize() throws Throwable {
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void refreshMenu() {
|
||||
if (menuItems != null && menuItems.length > 0) {
|
||||
firstIndex = Math.max(topFixedCount, firstIndex);
|
||||
firstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, firstIndex);
|
||||
|
||||
upItem.setEnabled(firstIndex > topFixedCount);
|
||||
downItem.setEnabled(firstIndex + scrollCount < menuItems.length - bottomFixedCount);
|
||||
|
||||
menu.removeAll();
|
||||
for (int i = 0; i < topFixedCount; i++) {
|
||||
menu.add(menuItems[i]);
|
||||
}
|
||||
/*if (topFixedCount > 0) {
|
||||
menu.addSeparator();
|
||||
}*/
|
||||
|
||||
menu.add(upItem);
|
||||
for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
|
||||
menu.add(menuItems[i]);
|
||||
}
|
||||
menu.add(downItem);
|
||||
|
||||
/*if (bottomFixedCount > 0) {
|
||||
menu.addSeparator();
|
||||
}*/
|
||||
for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
|
||||
menu.add(menuItems[i]);
|
||||
}
|
||||
|
||||
JComponent parent = (JComponent) upItem.getParent();
|
||||
parent.revalidate();
|
||||
parent.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private class MenuScrollListener implements PopupMenuListener {
|
||||
|
||||
@Override
|
||||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
||||
setMenuItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
|
||||
restoreMenuItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void popupMenuCanceled(PopupMenuEvent e) {
|
||||
restoreMenuItems();
|
||||
}
|
||||
|
||||
private void setMenuItems() {
|
||||
menuItems = menu.getComponents();
|
||||
|
||||
// Hack for auto detect the topFixed total
|
||||
/*int topFixedCountPrev = topFixedCount;
|
||||
for(int i=menuItems.length-1;i>0;i--)
|
||||
{
|
||||
if(menuItems[i].getClass().getName().endsWith("Separator"))
|
||||
{
|
||||
System.out.println(i);
|
||||
setTopFixedCount(i+1);
|
||||
|
||||
if(topFixedCount!=topFixedCountPrev)
|
||||
{
|
||||
scrollCount = getMaximumItems()-topFixedCount;
|
||||
System.out.println(getMaximumItems()-topFixedCount);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
|
||||
if (keepVisibleIndex >= topFixedCount
|
||||
&& keepVisibleIndex <= menuItems.length - bottomFixedCount
|
||||
&& (keepVisibleIndex > firstIndex + scrollCount
|
||||
|| keepVisibleIndex < firstIndex)) {
|
||||
firstIndex = Math.min(firstIndex, keepVisibleIndex);
|
||||
firstIndex = Math.max(firstIndex, keepVisibleIndex - scrollCount + 1);
|
||||
}
|
||||
if (menuItems.length > topFixedCount + scrollCount + bottomFixedCount) {
|
||||
refreshMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreMenuItems() {
|
||||
menu.removeAll();
|
||||
for (Component component : menuItems) {
|
||||
menu.add(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class MenuScrollTimer extends Timer {
|
||||
|
||||
public MenuScrollTimer(final int increment, int interval) {
|
||||
super(interval, new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
firstIndex += increment;
|
||||
refreshMenu();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private class MenuScrollItem extends JMenuItem
|
||||
implements ChangeListener {
|
||||
|
||||
private MenuScrollTimer timer;
|
||||
|
||||
public MenuScrollItem(MenuIcon icon, int increment) {
|
||||
setIcon(icon);
|
||||
setDisabledIcon(icon);
|
||||
timer = new MenuScrollTimer(increment, interval);
|
||||
addChangeListener(this);
|
||||
}
|
||||
|
||||
public void setInterval(int interval) {
|
||||
timer.setDelay(interval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (isArmed() && !timer.isRunning()) {
|
||||
timer.start();
|
||||
}
|
||||
if (!isArmed() && timer.isRunning()) {
|
||||
timer.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static enum MenuIcon implements Icon {
|
||||
|
||||
UP(9, 1, 9),
|
||||
DOWN(1, 9, 1);
|
||||
final int[] xPoints = {1, 5, 9};
|
||||
final int[] yPoints;
|
||||
|
||||
MenuIcon(int... yPoints) {
|
||||
this.yPoints = yPoints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
Dimension size = c.getSize();
|
||||
Graphics g2 = g.create(size.width / 2 - 5, size.height / 2 - 5, 10, 10);
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.drawPolygon(xPoints, yPoints, 3);
|
||||
if (c.isEnabled()) {
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.fillPolygon(xPoints, yPoints, 3);
|
||||
}
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconWidth() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconHeight() {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@ import processing.app.Base;
|
||||
import processing.app.Preferences;
|
||||
import processing.app.windows.Registry.REGISTRY_ROOT_KEY;
|
||||
import processing.core.PApplet;
|
||||
import processing.core.PConstants;
|
||||
|
||||
|
||||
// http://developer.apple.com/documentation/QuickTime/Conceptual/QT7Win_Update_Guide/Chapter03/chapter_3_section_1.html
|
||||
@ -302,4 +303,10 @@ public class Platform extends processing.app.Platform {
|
||||
//return 0;
|
||||
return clib._putenv(variable + "=");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return PConstants.platformNames[PConstants.WINDOWS];
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user