mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
update AVR src
* java code not tested * Merge remote-tracking branch 'remotes/arduino/master' into esp8266 Conflicts: README.md app/src/processing/app/AbstractMonitor.java arduino-core/src/processing/app/Serial.java libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino libraries/WiFi/library.properties
This commit is contained in:
@ -6,7 +6,6 @@
|
||||
<classpathentry kind="lib" path="app/lib/antlr.jar"/>
|
||||
<classpathentry kind="lib" path="app/lib/apple.jar"/>
|
||||
<classpathentry kind="lib" path="app/lib/ecj.jar"/>
|
||||
<classpathentry kind="lib" path="app/lib/jna.jar"/>
|
||||
<classpathentry kind="lib" path="app/test-lib/junit-4.11.jar"/>
|
||||
<classpathentry kind="lib" path="app/test-lib/fest-assert-1.2.jar"/>
|
||||
<classpathentry kind="lib" path="app/test-lib/fest-reflect-1.2.jar"/>
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -13,7 +13,7 @@ hardware/arduino/bootloaders/caterina_LUFA/Caterina.lss
|
||||
hardware/arduino/bootloaders/caterina_LUFA/Caterina.elf
|
||||
hardware/arduino/bootloaders/caterina_LUFA/Caterina.eep
|
||||
hardware/arduino/bootloaders/caterina_LUFA/.dep/
|
||||
build/libastylej-*.zip
|
||||
build/*.zip
|
||||
build/windows/work/
|
||||
build/windows/*.zip
|
||||
build/windows/*.tgz
|
||||
|
@ -7,10 +7,19 @@ language. Arduino can be used to develop stand-alone interactive objects or
|
||||
can be connected to software on your computer (e.g. Flash, Processing, MaxMSP).
|
||||
The boards can be assembled by hand or purchased preassembled; the open-source
|
||||
IDE can be downloaded for free at http://arduino.cc/en/Main/Software
|
||||
* Arduino is an open-source physical computing platform based on a simple i/o
|
||||
board and a development environment that implements the Processing/Wiring
|
||||
language. Arduino can be used to develop stand-alone interactive objects or
|
||||
can be connected to software on your computer (e.g. Flash, Processing, MaxMSP).
|
||||
The boards can be assembled by hand or purchased preassembled; the open-source
|
||||
IDE can be downloaded for free at http://www.arduino.cc/en/Main/Software
|
||||
|
||||
* For more information, see the website at: http://www.arduino.cc/
|
||||
or the forums at: http://arduino.cc/forum/
|
||||
You can also follow Arduino on twitter at: https://twitter.com/arduino or like Arduino on Facebook at: https://www.facebook.com/official.arduino
|
||||
* For more information, see the website at: http://www.arduino.cc/
|
||||
or the forums at: http://www.arduino.cc/forum/
|
||||
You can also follow Arduino on twitter at: https://twitter.com/arduino or like Arduino on Facebook at: https://www.facebook.com/official.arduino
|
||||
|
||||
* To report a *bug* in the software or to request *a simple enhancement* go to:
|
||||
http://github.com/arduino/Arduino/issues
|
||||
@ -42,4 +51,3 @@ Arduino uses the [GNU avr-gcc toolchain](http://gcc.gnu.org/wiki/avr-gcc), [avrd
|
||||
[Processing](http://www.processing.org) and [Wiring](http://wiring.org.co).
|
||||
|
||||
Icon and about image designed by [ToDo](http://www.todo.to.it/)
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
<classpathentry kind="src" path="test"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="lib/antlr.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jna.jar"/>
|
||||
<classpathentry kind="lib" path="lib/ecj.jar"/>
|
||||
<classpathentry kind="lib" path="lib/apple.jar"/>
|
||||
<classpathentry kind="lib" path="lib/bcpg-jdk15on-152.jar"/>
|
||||
|
@ -14,7 +14,6 @@
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/serial"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/video"/>
|
||||
<classpathentry kind="lib" path="lib/antlr.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jna.jar"/>
|
||||
<classpathentry kind="lib" path="lib/ecj.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry excluding="processing/app/tools/format/|processing/app/macosx/" kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/dxf"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/net"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/opengl">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="opengl/library"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/pdf"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/serial"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/video"/>
|
||||
<classpathentry kind="lib" path="lib/antlr.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jna.jar"/>
|
||||
<classpathentry kind="lib" path="lib/ecj.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/fry/processing/build/windows/work/java/lib/tools.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
@ -73,7 +73,7 @@
|
||||
<echo message="override ${env.JAVA_HOME}/lib/tools.jar" />
|
||||
<fail />
|
||||
-->
|
||||
<javac source="1.6" target="1.6"
|
||||
<javac source="1.8" target="1.8"
|
||||
srcdir="src"
|
||||
destdir="bin"
|
||||
encoding="UTF-8"
|
||||
@ -85,7 +85,7 @@
|
||||
<target name="test" depends="compile" description="Runs the test">
|
||||
<mkdir dir="test-bin"/>
|
||||
|
||||
<javac source="1.6" target="1.6"
|
||||
<javac source="1.8" target="1.8"
|
||||
srcdir="test"
|
||||
destdir="test-bin"
|
||||
encoding="UTF-8"
|
||||
|
@ -1 +0,0 @@
|
||||
https://github.com/twall/jna/blob/master/LICENSE
|
BIN
app/lib/jna.jar
BIN
app/lib/jna.jar
Binary file not shown.
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/processing/src/processing/app/Base.java"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="1"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-6-openjdk-amd64" javaProject="processing" path="1" type="4"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/processing/lib/ecj.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/processing/lib/jna.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/processing/lib/jssc-2.6.0.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry path="3" projectName="processing-core" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento exportedEntriesOnly="false" project="processing"/> </runtimeClasspathEntry> "/>
|
||||
</listAttribute>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="processing.app.Base"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="processing"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Djava.library.path=lib/"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:processing}/../build/linux/work"/>
|
||||
</launchConfiguration>
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class LibraryByTypeComparator implements Comparator<ContributedLibrary> {
|
||||
|
||||
private final LibraryTypeComparator libraryTypeComparator;
|
||||
|
||||
public LibraryByTypeComparator() {
|
||||
this(new LibraryTypeComparator());
|
||||
}
|
||||
|
||||
public LibraryByTypeComparator(LibraryTypeComparator libraryTypeComparator) {
|
||||
this.libraryTypeComparator = libraryTypeComparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(ContributedLibrary o1, ContributedLibrary o2) {
|
||||
if (o1.getTypes() == null) {
|
||||
return 1;
|
||||
}
|
||||
if (o2.getTypes() == null) {
|
||||
return -1;
|
||||
}
|
||||
return libraryTypeComparator.compare(o1.getTypes().get(0), o2.getTypes().get(0));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class LibraryOfSameTypeComparator implements Comparator<ContributedLibrary> {
|
||||
|
||||
@Override
|
||||
public int compare(ContributedLibrary o1, ContributedLibrary o2) {
|
||||
if (o1.getTypes() == null) {
|
||||
return 1;
|
||||
}
|
||||
if (o2.getTypes() == null) {
|
||||
return -1;
|
||||
}
|
||||
if (!o1.getTypes().get(0).equals(o2.getTypes().get(0))) {
|
||||
return 0;
|
||||
}
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class LibraryTypeComparator implements Comparator<String> {
|
||||
|
||||
private final List<String> types;
|
||||
|
||||
public LibraryTypeComparator() {
|
||||
this("Arduino", "Recommended", "Contributed");
|
||||
}
|
||||
|
||||
public LibraryTypeComparator(String... types) {
|
||||
this.types = Arrays.asList(types);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
if (types.contains(o1) && types.contains(o2)) {
|
||||
return types.indexOf(o1) - types.indexOf(o2);
|
||||
} else if (types.contains(o1)) {
|
||||
return -1;
|
||||
} else if (types.contains(o2)) {
|
||||
return 1;
|
||||
}
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
|
||||
}
|
@ -26,15 +26,16 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries.ui;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContributionVersionComparator;
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
import cc.arduino.contributions.filters.BuiltInPredicate;
|
||||
import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.filters.OnlyUpstreamReleasePredicate;
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContributionVersionComparator;
|
||||
import cc.arduino.contributions.ui.InstallerTableCell;
|
||||
import cc.arduino.contributions.ui.listeners.DelegatingKeyListener;
|
||||
import cc.arduino.utils.ReverseComparator;
|
||||
|
@ -30,7 +30,6 @@
|
||||
package cc.arduino.contributions.libraries.ui;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.filters.CategoryPredicate;
|
||||
import cc.arduino.contributions.libraries.filters.TypePredicate;
|
||||
import cc.arduino.contributions.ui.DropdownItem;
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -26,16 +26,15 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries.ui;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
|
||||
import cc.arduino.contributions.VersionHelper;
|
||||
import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.LibrariesIndexer;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.ui.FilteredAbstractTableModel;
|
||||
import com.github.zafarkhaja.semver.Version;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
|
@ -26,30 +26,35 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries.ui;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.LibrariesIndexer;
|
||||
import cc.arduino.contributions.libraries.LibraryInstaller;
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.ui.InstallerJDialogUncaughtExceptionHandler;
|
||||
import cc.arduino.contributions.libraries.LibraryTypeComparator;
|
||||
import cc.arduino.contributions.ui.*;
|
||||
import cc.arduino.utils.Progress;
|
||||
import com.google.common.base.Predicate;
|
||||
import processing.app.Platform;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
||||
|
||||
private LibrariesIndexer indexer;
|
||||
private final JComboBox typeChooser;
|
||||
private final Platform platform;
|
||||
private LibrariesIndexer indexer;
|
||||
private Predicate<ContributedLibrary> typeFilter;
|
||||
|
||||
@Override
|
||||
@ -85,8 +90,9 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
||||
};
|
||||
}
|
||||
|
||||
public LibraryManagerUI(Frame parent) {
|
||||
public LibraryManagerUI(Frame parent, Platform platform) {
|
||||
super(parent, "Library Manager", Dialog.ModalityType.APPLICATION_MODAL, _("Unable to reach Arduino.cc due to possible network issues."));
|
||||
this.platform = platform;
|
||||
|
||||
filtersContainer.add(new JLabel(_("Topic")), 1);
|
||||
filtersContainer.remove(2);
|
||||
@ -160,7 +166,8 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
||||
typeChooser.removeAllItems();
|
||||
typeChooser.addItem(new DropdownAllItem());
|
||||
typeChooser.addItem(new DropdownInstalledLibraryItem(indexer.getIndex()));
|
||||
Collection<String> types = indexer.getIndex().getTypes();
|
||||
java.util.List<String> types = new LinkedList<String>(indexer.getIndex().getTypes());
|
||||
Collections.sort(types, new LibraryTypeComparator());
|
||||
for (String type : types) {
|
||||
typeChooser.addItem(new DropdownLibraryOfTypeItem(type));
|
||||
}
|
||||
@ -175,7 +182,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
||||
filterField.setEnabled(contribModel.getRowCount() > 0);
|
||||
|
||||
// Create LibrariesInstaller tied with the provided index
|
||||
installer = new LibraryInstaller(indexer) {
|
||||
installer = new LibraryInstaller(indexer, platform) {
|
||||
@Override
|
||||
public void onProgress(Progress progress) {
|
||||
setProgress(progress);
|
||||
|
@ -26,8 +26,10 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages.ui;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContributionVersionComparator;
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
import cc.arduino.contributions.filters.BuiltInPredicate;
|
||||
@ -35,7 +37,6 @@ import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
import cc.arduino.contributions.packages.ContributedBoard;
|
||||
import cc.arduino.contributions.packages.ContributedHelp;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.ui.InstallerTableCell;
|
||||
import cc.arduino.contributions.ui.listeners.DelegatingKeyListener;
|
||||
import cc.arduino.utils.ReverseComparator;
|
||||
|
@ -26,6 +26,7 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages.ui;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
|
||||
|
@ -26,15 +26,17 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages.ui;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.packages.ContributionInstaller;
|
||||
import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.ui.*;
|
||||
import cc.arduino.utils.Progress;
|
||||
import processing.app.I18n;
|
||||
import processing.app.Platform;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@ -47,7 +49,7 @@ import static processing.app.I18n._;
|
||||
@SuppressWarnings("serial")
|
||||
public class ContributionManagerUI extends InstallerJDialog {
|
||||
|
||||
// private ContributedPlatformTableCell cellEditor;
|
||||
private final Platform platform;
|
||||
|
||||
@Override
|
||||
protected FilteredAbstractTableModel createContribModel() {
|
||||
@ -82,8 +84,9 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
};
|
||||
}
|
||||
|
||||
public ContributionManagerUI(Frame parent) {
|
||||
public ContributionManagerUI(Frame parent, Platform platform) {
|
||||
super(parent, _("Boards Manager"), Dialog.ModalityType.APPLICATION_MODAL, _("Unable to reach Arduino.cc due to possible network issues."));
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
public void setIndexer(ContributionsIndexer indexer) {
|
||||
@ -113,7 +116,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
}
|
||||
|
||||
// Create ConstributionInstaller tied with the provided index
|
||||
installer = new ContributionInstaller(indexer) {
|
||||
installer = new ContributionInstaller(indexer, platform) {
|
||||
@Override
|
||||
public void onProgress(Progress progress) {
|
||||
setProgress(progress);
|
||||
|
@ -29,9 +29,8 @@
|
||||
|
||||
package cc.arduino.contributions.ui;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.filters.NoopPredicate;
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.ui.DropdownItem;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
@ -26,17 +26,15 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class FilterJTextField extends JTextField {
|
||||
|
@ -26,10 +26,11 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.ui;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
|
@ -26,9 +26,9 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.ui;
|
||||
|
||||
import cc.arduino.contributions.packages.ui.ContributionIndexTableModel;
|
||||
import cc.arduino.contributions.ui.listeners.AbstractKeyListener;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
@ -44,7 +44,6 @@ import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import static cc.arduino.contributions.packages.ui.ContributionIndexTableModel.DESCRIPTION_COL;
|
||||
import static processing.app.I18n._;
|
||||
@ -65,9 +64,11 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
||||
// Real contribution table
|
||||
protected JTable contribTable;
|
||||
// Model behind the table
|
||||
protected FilteredAbstractTableModel<T> contribModel;
|
||||
protected final FilteredAbstractTableModel<T> contribModel;
|
||||
private final JButton closeButton;
|
||||
private final JButton dismissErrorMessageButton;
|
||||
|
||||
abstract protected FilteredAbstractTableModel createContribModel();
|
||||
abstract protected FilteredAbstractTableModel<T> createContribModel();
|
||||
|
||||
abstract protected InstallerTableCell createCellRenderer();
|
||||
|
||||
@ -76,8 +77,8 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
||||
// Bottom:
|
||||
// - Progress bar
|
||||
protected final ProgressJProgressBar progressBar;
|
||||
protected final Box progressBox;
|
||||
protected final Box errorMessageBox;
|
||||
private final Box progressBox;
|
||||
private final Box errorMessageBox;
|
||||
private final JLabel errorMessage;
|
||||
|
||||
public InstallerJDialog(Frame parent, String title, ModalityType applicationModal, String noConnectionErrorMessage) {
|
||||
@ -184,11 +185,20 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
||||
progressBox.add(Box.createHorizontalStrut(5));
|
||||
progressBox.add(cancelButton);
|
||||
|
||||
JButton dismissErrorMessageButton = new JButton(_("OK"));
|
||||
dismissErrorMessageButton = new JButton(_("OK"));
|
||||
dismissErrorMessageButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
clearErrorMessage();
|
||||
setErrorMessageVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
closeButton = new JButton(_("Close"));
|
||||
closeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
InstallerJDialog.this.dispatchEvent(new WindowEvent(InstallerJDialog.this, WindowEvent.WINDOW_CLOSING));
|
||||
}
|
||||
});
|
||||
|
||||
@ -197,12 +207,13 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
||||
errorMessageBox.add(errorMessage);
|
||||
errorMessageBox.add(Box.createHorizontalGlue());
|
||||
errorMessageBox.add(dismissErrorMessageButton);
|
||||
errorMessageBox.add(closeButton);
|
||||
errorMessageBox.setVisible(false);
|
||||
}
|
||||
|
||||
{
|
||||
JPanel progressPanel = new JPanel();
|
||||
progressPanel.setBorder(new EmptyBorder(7, 7, 7, 7));
|
||||
progressPanel.setBorder(new EmptyBorder(7, 10, 7, 10));
|
||||
progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.Y_AXIS));
|
||||
progressPanel.add(progressBox);
|
||||
progressPanel.add(errorMessageBox);
|
||||
@ -236,12 +247,12 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
||||
|
||||
public void setErrorMessage(String message) {
|
||||
errorMessage.setText("<html><body>" + message + "</body></html>");
|
||||
errorMessageBox.setVisible(true);
|
||||
setErrorMessageVisible(true);
|
||||
}
|
||||
|
||||
public void clearErrorMessage() {
|
||||
errorMessage.setText("");
|
||||
errorMessageBox.setVisible(false);
|
||||
setErrorMessageVisible(false);
|
||||
}
|
||||
|
||||
public void setProgressVisible(boolean visible, String status) {
|
||||
@ -250,18 +261,25 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
||||
} else {
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
}
|
||||
errorMessageBox.setVisible(!visible);
|
||||
progressBox.setVisible(visible);
|
||||
|
||||
filterField.setEnabled(!visible);
|
||||
categoryChooser.setEnabled(!visible);
|
||||
contribTable.setEnabled(!visible);
|
||||
errorMessageBox.setVisible(false);
|
||||
if (contribTable.getCellEditor() != null) {
|
||||
((InstallerTableCell) contribTable.getCellEditor()).setEnabled(!visible);
|
||||
((InstallerTableCell) contribTable.getCellEditor()).setStatus(status);
|
||||
}
|
||||
}
|
||||
|
||||
private void setErrorMessageVisible(boolean visible) {
|
||||
errorMessage.setVisible(visible);
|
||||
dismissErrorMessageButton.setVisible(visible);
|
||||
closeButton.setVisible(!visible);
|
||||
errorMessageBox.setVisible(true);
|
||||
}
|
||||
|
||||
protected final ActionListener categoryChooserActionListener = new ActionListener() {
|
||||
|
||||
@Override
|
||||
|
@ -29,8 +29,6 @@
|
||||
|
||||
package cc.arduino.contributions.ui;
|
||||
|
||||
import cc.arduino.contributions.ui.InstallerJDialog;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
@ -26,6 +26,7 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.ui;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -26,12 +26,13 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.ui;
|
||||
|
||||
import javax.swing.JProgressBar;
|
||||
|
||||
import cc.arduino.utils.Progress;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ProgressJProgressBar extends JProgressBar {
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
package cc.arduino.packages.formatter;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.Editor;
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.syntax.SketchTextArea;
|
||||
@ -53,7 +54,7 @@ public class AStyle implements Tool {
|
||||
|
||||
public AStyle() {
|
||||
this.aStyleInterface = new AStyleInterface();
|
||||
File customFormatterConf = Base.getSettingsFile(FORMATTER_CONF);
|
||||
File customFormatterConf = BaseNoGui.getSettingsFile(FORMATTER_CONF);
|
||||
File defaultFormatterConf = new File(Base.getContentFile("lib"), FORMATTER_CONF);
|
||||
|
||||
File formatterConf;
|
||||
|
@ -90,7 +90,7 @@ public class SplashScreenHelper {
|
||||
}
|
||||
|
||||
private void printText(String str) {
|
||||
System.out.println(str);
|
||||
System.err.println(str);
|
||||
}
|
||||
|
||||
}
|
||||
|
196
app/src/cc/arduino/view/findreplace/FindReplace.form
Normal file
196
app/src/cc/arduino/view/findreplace/FindReplace.form
Normal file
@ -0,0 +1,196 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="2"/>
|
||||
<Property name="title" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Find")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="replaceLabel" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="findLabel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="findField" max="32767" attributes="0"/>
|
||||
<Component id="replaceField" max="32767" attributes="0"/>
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="searchAllFilesBox" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="wrapAroundBox" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="ignoreCaseBox" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<Component id="buttonsContainer" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="findLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="findField" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="replaceLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="replaceField" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="ignoreCaseBox" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="wrapAroundBox" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="searchAllFilesBox" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="buttonsContainer" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="findLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Find:")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="findField">
|
||||
<Properties>
|
||||
<Property name="columns" type="int" value="20"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="replaceLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Replace with:")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="replaceField">
|
||||
<Properties>
|
||||
<Property name="columns" type="int" value="20"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JCheckBox" name="ignoreCaseBox">
|
||||
<Properties>
|
||||
<Property name="selected" type="boolean" value="true"/>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Ignore Case")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JCheckBox" name="wrapAroundBox">
|
||||
<Properties>
|
||||
<Property name="selected" type="boolean" value="true"/>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Wrap Around")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JCheckBox" name="searchAllFilesBox">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Search all Sketch Tabs")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Container class="javax.swing.JPanel" name="buttonsContainer">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="findButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Find")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="findButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="previousButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Previous")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="previousButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="replaceFindButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Replace & Find")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="replaceFindButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="replaceButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Replace")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="replaceButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="replaceAllButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Replace All")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="replaceAllButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
460
app/src/cc/arduino/view/findreplace/FindReplace.java
Normal file
460
app/src/cc/arduino/view/findreplace/FindReplace.java
Normal file
@ -0,0 +1,460 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.view.findreplace;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.Editor;
|
||||
import processing.app.Sketch;
|
||||
import processing.app.helpers.OSUtils;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
public class FindReplace extends javax.swing.JFrame {
|
||||
|
||||
private static final String FIND_TEXT = "findText";
|
||||
private static final String REPLACE_TEXT = "replaceText";
|
||||
private static final String IGNORE_CASE = "ignoreCase";
|
||||
private static final String SEARCH_ALL_FILES = "searchAllFiles";
|
||||
private static final String WRAP_AROUND = "wrapAround";
|
||||
|
||||
private final Editor editor;
|
||||
|
||||
public FindReplace(Editor editor, Map<String, Object> state) {
|
||||
this.editor = editor;
|
||||
|
||||
initComponents();
|
||||
|
||||
if (OSUtils.isMacOS()) {
|
||||
buttonsContainer.removeAll();
|
||||
buttonsContainer.add(replaceAllButton);
|
||||
buttonsContainer.add(replaceButton);
|
||||
buttonsContainer.add(replaceFindButton);
|
||||
buttonsContainer.add(previousButton);
|
||||
buttonsContainer.add(findButton);
|
||||
}
|
||||
|
||||
getRootPane().setDefaultButton(findButton);
|
||||
|
||||
Base.registerWindowCloseKeys(getRootPane(), new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
Base.FIND_DIALOG_STATE = findDialogState();
|
||||
}
|
||||
});
|
||||
|
||||
Base.setIcon(this);
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowActivated(WindowEvent e) {
|
||||
findField.requestFocusInWindow();
|
||||
findField.selectAll();
|
||||
}
|
||||
});
|
||||
|
||||
restoreFindDialogState(state);
|
||||
}
|
||||
|
||||
private Map<String, Object> findDialogState() {
|
||||
Map<String, Object> state = new HashMap<String, Object>();
|
||||
state.put(FIND_TEXT, findField.getText());
|
||||
state.put(REPLACE_TEXT, replaceField.getText());
|
||||
state.put(IGNORE_CASE, ignoreCaseBox.isSelected());
|
||||
state.put(WRAP_AROUND, wrapAroundBox.isSelected());
|
||||
state.put(SEARCH_ALL_FILES, searchAllFilesBox.isSelected());
|
||||
return state;
|
||||
}
|
||||
|
||||
private void restoreFindDialogState(Map<String, Object> state) {
|
||||
if (state.containsKey(FIND_TEXT)) {
|
||||
findField.setText((String) state.get(FIND_TEXT));
|
||||
}
|
||||
if (state.containsKey(REPLACE_TEXT)) {
|
||||
replaceField.setText((String) state.get(REPLACE_TEXT));
|
||||
}
|
||||
if (state.containsKey(IGNORE_CASE)) {
|
||||
ignoreCaseBox.setSelected((Boolean) state.get(IGNORE_CASE));
|
||||
}
|
||||
if (state.containsKey(SEARCH_ALL_FILES)) {
|
||||
searchAllFilesBox.setSelected((Boolean) state.get(SEARCH_ALL_FILES));
|
||||
}
|
||||
if (state.containsKey(WRAP_AROUND)) {
|
||||
wrapAroundBox.setSelected((Boolean) state.get(WRAP_AROUND));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
javax.swing.JLabel findLabel = new javax.swing.JLabel();
|
||||
findField = new javax.swing.JTextField();
|
||||
javax.swing.JLabel replaceLabel = new javax.swing.JLabel();
|
||||
replaceField = new javax.swing.JTextField();
|
||||
ignoreCaseBox = new javax.swing.JCheckBox();
|
||||
wrapAroundBox = new javax.swing.JCheckBox();
|
||||
searchAllFilesBox = new javax.swing.JCheckBox();
|
||||
buttonsContainer = new javax.swing.JPanel();
|
||||
findButton = new javax.swing.JButton();
|
||||
previousButton = new javax.swing.JButton();
|
||||
replaceFindButton = new javax.swing.JButton();
|
||||
replaceButton = new javax.swing.JButton();
|
||||
replaceAllButton = new javax.swing.JButton();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setTitle(_("Find"));
|
||||
|
||||
findLabel.setText(_("Find:"));
|
||||
|
||||
findField.setColumns(20);
|
||||
|
||||
replaceLabel.setText(_("Replace with:"));
|
||||
|
||||
replaceField.setColumns(20);
|
||||
|
||||
ignoreCaseBox.setSelected(true);
|
||||
ignoreCaseBox.setText(_("Ignore Case"));
|
||||
|
||||
wrapAroundBox.setSelected(true);
|
||||
wrapAroundBox.setText(_("Wrap Around"));
|
||||
|
||||
searchAllFilesBox.setText(_("Search all Sketch Tabs"));
|
||||
|
||||
findButton.setText(_("Find"));
|
||||
findButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
findButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
buttonsContainer.add(findButton);
|
||||
|
||||
previousButton.setText(_("Previous"));
|
||||
previousButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
previousButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
buttonsContainer.add(previousButton);
|
||||
|
||||
replaceFindButton.setText(_("Replace & Find"));
|
||||
replaceFindButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
replaceFindButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
buttonsContainer.add(replaceFindButton);
|
||||
|
||||
replaceButton.setText(_("Replace"));
|
||||
replaceButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
replaceButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
buttonsContainer.add(replaceButton);
|
||||
|
||||
replaceAllButton.setText(_("Replace All"));
|
||||
replaceAllButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
replaceAllButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
buttonsContainer.add(replaceAllButton);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(replaceLabel)
|
||||
.addComponent(findLabel))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(findField)
|
||||
.addComponent(replaceField)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(searchAllFilesBox)
|
||||
.addComponent(wrapAroundBox)
|
||||
.addComponent(ignoreCaseBox))
|
||||
.addGap(0, 0, Short.MAX_VALUE))))
|
||||
.addComponent(buttonsContainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(findLabel)
|
||||
.addComponent(findField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(replaceLabel)
|
||||
.addComponent(replaceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(ignoreCaseBox)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(wrapAroundBox)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(searchAllFilesBox)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonsContainer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void findButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findButtonActionPerformed
|
||||
findNext();
|
||||
}//GEN-LAST:event_findButtonActionPerformed
|
||||
|
||||
private void previousButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_previousButtonActionPerformed
|
||||
findPrevious();
|
||||
}//GEN-LAST:event_previousButtonActionPerformed
|
||||
|
||||
private void replaceFindButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replaceFindButtonActionPerformed
|
||||
replaceAndFindNext();
|
||||
}//GEN-LAST:event_replaceFindButtonActionPerformed
|
||||
|
||||
private void replaceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replaceButtonActionPerformed
|
||||
replace();
|
||||
}//GEN-LAST:event_replaceButtonActionPerformed
|
||||
|
||||
private void replaceAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replaceAllButtonActionPerformed
|
||||
replaceAll();
|
||||
}//GEN-LAST:event_replaceAllButtonActionPerformed
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JPanel buttonsContainer;
|
||||
private javax.swing.JButton findButton;
|
||||
private javax.swing.JTextField findField;
|
||||
private javax.swing.JCheckBox ignoreCaseBox;
|
||||
private javax.swing.JButton previousButton;
|
||||
private javax.swing.JButton replaceAllButton;
|
||||
private javax.swing.JButton replaceButton;
|
||||
private javax.swing.JTextField replaceField;
|
||||
private javax.swing.JButton replaceFindButton;
|
||||
private javax.swing.JCheckBox searchAllFilesBox;
|
||||
private javax.swing.JCheckBox wrapAroundBox;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int originTab) {
|
||||
boolean wrapNeeded = false;
|
||||
String search = findField.getText();
|
||||
|
||||
if (search.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String text = editor.getText();
|
||||
|
||||
if (ignoreCaseBox.isSelected()) {
|
||||
search = search.toLowerCase();
|
||||
text = text.toLowerCase();
|
||||
}
|
||||
|
||||
int nextIndex;
|
||||
if (!backwards) {
|
||||
// int selectionStart = editor.textarea.getSelectionStart();
|
||||
int selectionEnd = editor.getSelectionStop();
|
||||
|
||||
nextIndex = text.indexOf(search, selectionEnd);
|
||||
if (wrap && nextIndex == -1) {
|
||||
// if wrapping, a second chance is ok, start from beginning
|
||||
wrapNeeded = true;
|
||||
}
|
||||
} else {
|
||||
// int selectionStart = editor.textarea.getSelectionStart();
|
||||
int selectionStart = editor.getSelectionStart() - 1;
|
||||
|
||||
if (selectionStart >= 0) {
|
||||
nextIndex = text.lastIndexOf(search, selectionStart);
|
||||
} else {
|
||||
nextIndex = -1;
|
||||
}
|
||||
if (wrap && nextIndex == -1) {
|
||||
// if wrapping, a second chance is ok, start from the end
|
||||
wrapNeeded = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (nextIndex == -1) {
|
||||
// Nothing found on this tab: Search other tabs if required
|
||||
if (searchTabs) {
|
||||
// editor.
|
||||
Sketch sketch = editor.getSketch();
|
||||
if (sketch.getCodeCount() > 1) {
|
||||
int realCurrentTab = sketch.getCodeIndex(sketch.getCurrentCode());
|
||||
|
||||
if (originTab != realCurrentTab) {
|
||||
if (originTab < 0) {
|
||||
originTab = realCurrentTab;
|
||||
}
|
||||
|
||||
if (!wrap) {
|
||||
if ((!backwards && realCurrentTab + 1 >= sketch.getCodeCount()) || (backwards && realCurrentTab - 1 < 0)) {
|
||||
return false; // Can't continue without wrap
|
||||
}
|
||||
}
|
||||
|
||||
if (backwards) {
|
||||
sketch.handlePrevCode();
|
||||
this.setVisible(true);
|
||||
int l = editor.getText().length() - 1;
|
||||
editor.setSelection(l, l);
|
||||
} else {
|
||||
sketch.handleNextCode();
|
||||
this.setVisible(true);
|
||||
editor.setSelection(0, 0);
|
||||
}
|
||||
|
||||
return find(wrap, backwards, true, originTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wrapNeeded) {
|
||||
nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (nextIndex != -1) {
|
||||
editor.setSelection(nextIndex, nextIndex + search.length());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the current selection with whatever's in the replacement text
|
||||
* field.
|
||||
*/
|
||||
private void replace() {
|
||||
if (findField.getText().length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int newpos = editor.getSelectionStart() - findField.getText().length();
|
||||
if (newpos < 0) {
|
||||
newpos = 0;
|
||||
}
|
||||
editor.setSelection(newpos, newpos);
|
||||
|
||||
boolean foundAtLeastOne = false;
|
||||
|
||||
if (find(false, false, searchAllFilesBox.isSelected(), -1)) {
|
||||
foundAtLeastOne = true;
|
||||
editor.setSelectedText(replaceField.getText());
|
||||
editor.getSketch().setModified(true); // TODO is this necessary?
|
||||
}
|
||||
|
||||
if (!foundAtLeastOne) {
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the current selection with whatever's in the replacement text
|
||||
* field, and then find the next match
|
||||
*/
|
||||
private void replaceAndFindNext() {
|
||||
replace();
|
||||
findNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace everything that matches by doing find and replace alternately until
|
||||
* nothing more found.
|
||||
*/
|
||||
private void replaceAll() {
|
||||
if (findField.getText().length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (searchAllFilesBox.isSelected()) {
|
||||
editor.getSketch().setCurrentCode(0); // select the first tab
|
||||
}
|
||||
|
||||
editor.setSelection(0, 0); // move to the beginning
|
||||
|
||||
boolean foundAtLeastOne = false;
|
||||
while (true) {
|
||||
if (find(false, false, searchAllFilesBox.isSelected(), -1)) {
|
||||
foundAtLeastOne = true;
|
||||
editor.setSelectedText(replaceField.getText());
|
||||
editor.getSketch().setModified(true); // TODO is this necessary?
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundAtLeastOne) {
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
}
|
||||
|
||||
public void findNext() {
|
||||
if (!find(wrapAroundBox.isSelected(), false, searchAllFilesBox.isSelected(), -1)) {
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
}
|
||||
|
||||
public void findPrevious() {
|
||||
if (!find(wrapAroundBox.isSelected(), true, searchAllFilesBox.isSelected(), -1)) {
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFindText(String text) {
|
||||
if (text == null) {
|
||||
return;
|
||||
}
|
||||
findField.setText(text);
|
||||
}
|
||||
}
|
@ -30,18 +30,21 @@
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace min="0" pref="332" max="32767" attributes="0"/>
|
||||
<Component id="jScrollPane1" alignment="0" pref="538" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
<Component id="ok" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="7" max="-2" attributes="0"/>
|
||||
<Component id="cancel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="jScrollPane1" alignment="0" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="unofficialListURLLabel" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
@ -55,11 +58,13 @@
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" pref="118" max="32767" attributes="0"/>
|
||||
<Component id="jScrollPane1" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="unofficialListURLLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="cancel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="ok" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="cancel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
@ -127,5 +132,20 @@
|
||||
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="unofficialListURLLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Click for a list of unofficial boards support URLs")" type="code"/>
|
||||
</Property>
|
||||
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
|
||||
<Color id="Cursore mano"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="unofficialListURLLabelMouseClicked"/>
|
||||
<EventHandler event="mouseExited" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="unofficialListURLLabelMouseExited"/>
|
||||
<EventHandler event="mouseEntered" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="unofficialListURLLabelMouseEntered"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -29,9 +29,7 @@
|
||||
|
||||
package cc.arduino.view.preferences;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import processing.app.Base;
|
||||
|
||||
@ -53,13 +51,7 @@ public class AdditionalBoardsManagerURLTextArea extends javax.swing.JDialog {
|
||||
initComponents();
|
||||
setLocationRelativeTo(parent);
|
||||
|
||||
Base.registerWindowCloseKeys(getRootPane(), new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cancelActionPerformed(e);
|
||||
}
|
||||
});
|
||||
|
||||
Base.registerWindowCloseKeys(getRootPane(), this::cancelActionPerformed);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,6 +67,7 @@ public class AdditionalBoardsManagerURLTextArea extends javax.swing.JDialog {
|
||||
javax.swing.JButton cancel = new javax.swing.JButton();
|
||||
javax.swing.JButton ok = new javax.swing.JButton();
|
||||
javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
|
||||
unofficialListURLLabel = new javax.swing.JLabel();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setTitle(_("Additional Boards Manager URLs"));
|
||||
@ -102,6 +95,22 @@ public class AdditionalBoardsManagerURLTextArea extends javax.swing.JDialog {
|
||||
|
||||
jLabel1.setText(_("Enter additional URLs, one for each row"));
|
||||
|
||||
unofficialListURLLabel.setText(_("Click for a list of unofficial boards support URLs"));
|
||||
unofficialListURLLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
|
||||
unofficialListURLLabel.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
||||
unofficialListURLLabelMouseClicked(evt);
|
||||
}
|
||||
|
||||
public void mouseExited(java.awt.event.MouseEvent evt) {
|
||||
unofficialListURLLabelMouseExited(evt);
|
||||
}
|
||||
|
||||
public void mouseEntered(java.awt.event.MouseEvent evt) {
|
||||
unofficialListURLLabelMouseEntered(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
@ -109,14 +118,16 @@ public class AdditionalBoardsManagerURLTextArea extends javax.swing.JDialog {
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(0, 332, Short.MAX_VALUE)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 538, Short.MAX_VALUE)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
.addComponent(ok)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGap(7, 7, 7)
|
||||
.addComponent(cancel))
|
||||
.addComponent(jScrollPane1)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jLabel1)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(unofficialListURLLabel)
|
||||
.addComponent(jLabel1))
|
||||
.addGap(0, 0, Short.MAX_VALUE)))
|
||||
.addContainerGap())
|
||||
);
|
||||
@ -126,11 +137,13 @@ public class AdditionalBoardsManagerURLTextArea extends javax.swing.JDialog {
|
||||
.addContainerGap()
|
||||
.addComponent(jLabel1)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
|
||||
.addComponent(jScrollPane1)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(unofficialListURLLabel)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(cancel)
|
||||
.addComponent(ok))
|
||||
.addComponent(ok)
|
||||
.addComponent(cancel))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
@ -147,6 +160,18 @@ public class AdditionalBoardsManagerURLTextArea extends javax.swing.JDialog {
|
||||
cancelActionPerformed(evt);
|
||||
}//GEN-LAST:event_okActionPerformed
|
||||
|
||||
private void unofficialListURLLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_unofficialListURLLabelMouseEntered
|
||||
unofficialListURLLabel.setForeground(new Color(0, 0, 140));
|
||||
}//GEN-LAST:event_unofficialListURLLabelMouseEntered
|
||||
|
||||
private void unofficialListURLLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_unofficialListURLLabelMouseExited
|
||||
unofficialListURLLabel.setForeground(new Color(76, 76, 76));
|
||||
}//GEN-LAST:event_unofficialListURLLabelMouseExited
|
||||
|
||||
private void unofficialListURLLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_unofficialListURLLabelMouseClicked
|
||||
Base.openURL("https://github.com/arduino/Arduino/wiki/Unofficial-list-of-3rd-party-boards-support-urls");
|
||||
}//GEN-LAST:event_unofficialListURLLabelMouseClicked
|
||||
|
||||
public void setText(String text) {
|
||||
Collection<String> urls = splitAndTrim(text, ",");
|
||||
additionalBoardsManagerURLs.setText(Joiner.on("\n").skipNulls().join(urls));
|
||||
@ -154,17 +179,7 @@ public class AdditionalBoardsManagerURLTextArea extends javax.swing.JDialog {
|
||||
|
||||
private Collection<String> splitAndTrim(String text, String separator) {
|
||||
Collection<String> urls = Arrays.asList(text.split(separator));
|
||||
return FluentIterable.from(urls).transform(new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String input) {
|
||||
return input.trim();
|
||||
}
|
||||
}).filter(new Predicate<String>() {
|
||||
@Override
|
||||
public boolean apply(String input) {
|
||||
return !input.isEmpty();
|
||||
}
|
||||
}).toList();
|
||||
return FluentIterable.from(urls).transform(String::trim).filter(url -> !url.isEmpty()).toList();
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
@ -174,6 +189,7 @@ public class AdditionalBoardsManagerURLTextArea extends javax.swing.JDialog {
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private final javax.swing.JTextArea additionalBoardsManagerURLs = new javax.swing.JTextArea();
|
||||
private javax.swing.JLabel unofficialListURLLabel;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
public void onOk(ActionListener listener) {
|
||||
|
@ -31,23 +31,32 @@
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="proxySettingsPanel" max="32767" attributes="0"/>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="sketchbookLocationField" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="browseButton" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="checkboxesContainer" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="okButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="cancelButton" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="additionalBoardsManagerLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="additionalBoardsManagerField" min="-2" pref="500" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="extendedAdditionalUrlFieldWindow" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="arduinoNotRunningLabel" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="sketchbookLocationLabel" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="comboWarningsLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="comboWarnings" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="morePreferencesLabel" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="showVerboseLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
@ -70,22 +79,12 @@
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<Component id="arduinoNotRunningLabel" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="morePreferencesLabel" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="preferencesFileLabel" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="okButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="cancelButton" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="additionalBoardsManagerLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="additionalBoardsManagerField" min="-2" pref="500" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="extendedAdditionalUrlFieldWindow" min="-2" pref="36" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
@ -126,14 +125,12 @@
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="checkboxesContainer" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="proxySettingsPanel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="103" alignment="0" groupAlignment="3" attributes="0">
|
||||
<Component id="additionalBoardsManagerLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="additionalBoardsManagerField" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="extendedAdditionalUrlFieldWindow" min="-2" pref="27" max="-2" attributes="0"/>
|
||||
<Component id="extendedAdditionalUrlFieldWindow" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="morePreferencesLabel" min="-2" max="-2" attributes="0"/>
|
||||
@ -146,7 +143,7 @@
|
||||
<Component id="cancelButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="okButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
@ -269,199 +266,6 @@
|
||||
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new JComboBox(warningItems)"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Container class="javax.swing.JPanel" name="proxySettingsPanel">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
|
||||
<TitledBorder title="<User Code>">
|
||||
<Connection PropertyName="titleX" code="_("Proxy Settings")" type="code"/>
|
||||
</TitledBorder>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="proxyHTTPSServerLabel" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="8" max="-2" attributes="0"/>
|
||||
<Component id="proxyHTTPServerLabel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Component id="proxyUserLabel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="proxyHTTPServer" max="32767" attributes="0"/>
|
||||
<Component id="proxyHTTPSServer" max="32767" attributes="0"/>
|
||||
<Component id="proxyUser" alignment="1" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="proxyHTTPSPortLabel" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="proxyPasswordLabel" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="proxyHTTPPortLabel" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="proxyHTTPSPort" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="proxyHTTPPort" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="proxyPassword" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="proxyHTTPServerLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="proxyHTTPServer" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="proxyHTTPSServerLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="proxyHTTPSServer" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="proxyUser" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="proxyUserLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="proxyHTTPPortLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="proxyHTTPPort" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="proxyHTTPSPort" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="proxyHTTPSPortLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="proxyPasswordLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="proxyPassword" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="proxyHTTPServerLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Server (HTTP):")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="proxyHTTPServer">
|
||||
<Properties>
|
||||
<Property name="columns" type="int" value="10"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="proxyHTTPPortLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Port (HTTP):")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="proxyHTTPPort">
|
||||
<Properties>
|
||||
<Property name="columns" type="int" value="10"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="proxyHTTPSServerLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Server (HTTPS):")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="proxyHTTPSServer">
|
||||
<Properties>
|
||||
<Property name="columns" type="int" value="10"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="proxyHTTPSPortLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Port (HTTPS):")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="proxyHTTPSPort">
|
||||
<Properties>
|
||||
<Property name="columns" type="int" value="10"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="proxyUserLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Username:")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="proxyUser">
|
||||
<Properties>
|
||||
<Property name="columns" type="int" value="10"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="proxyPasswordLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Password:")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JPasswordField" name="proxyPassword">
|
||||
<Properties>
|
||||
<Property name="columns" type="int" value="10"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Component class="javax.swing.JLabel" name="additionalBoardsManagerLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
@ -488,6 +292,9 @@
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="new ImageIcon(Base.getThemeImage("newwindow.gif", this))" type="code"/>
|
||||
</Property>
|
||||
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
|
||||
<Insets value="[1, 1, 1, 1]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="extendedAdditionalUrlFieldWindowActionPerformed"/>
|
||||
@ -516,6 +323,9 @@
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="PreferencesData.getPreferencesFile().getAbsolutePath()" type="code"/>
|
||||
</Property>
|
||||
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
|
||||
<Color id="Cursore mano"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="mousePressed" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="preferencesFileLabelMousePressed"/>
|
||||
@ -617,13 +427,6 @@
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JCheckBox" name="autoAssociateBox">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="_("Automatically associate .ino files with Arduino")" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JCheckBox" name="saveVerifyUploadBox">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
|
@ -30,19 +30,17 @@
|
||||
package cc.arduino.view.preferences;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.Editor;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.PreferencesData;
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.helpers.OSUtils;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@ -191,17 +189,7 @@ public class Preferences extends javax.swing.JDialog {
|
||||
|
||||
initComponents();
|
||||
|
||||
Base.registerWindowCloseKeys(getRootPane(), new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cancelButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
|
||||
if (!OSUtils.isWindows() || base.getPortableFolder() != null) {
|
||||
autoAssociateBox.setEnabled(false);
|
||||
autoAssociateBox.getParent().remove(autoAssociateBox);
|
||||
}
|
||||
Base.registerWindowCloseKeys(getRootPane(), this::cancelButtonActionPerformed);
|
||||
|
||||
showPrerefencesData();
|
||||
}
|
||||
@ -228,19 +216,6 @@ public class Preferences extends javax.swing.JDialog {
|
||||
verboseUploadBox = new javax.swing.JCheckBox();
|
||||
javax.swing.JLabel comboWarningsLabel = new javax.swing.JLabel();
|
||||
comboWarnings = new JComboBox(warningItems);
|
||||
javax.swing.JPanel proxySettingsPanel = new javax.swing.JPanel();
|
||||
javax.swing.JLabel proxyHTTPServerLabel = new javax.swing.JLabel();
|
||||
proxyHTTPServer = new javax.swing.JTextField();
|
||||
javax.swing.JLabel proxyHTTPPortLabel = new javax.swing.JLabel();
|
||||
proxyHTTPPort = new javax.swing.JTextField();
|
||||
javax.swing.JLabel proxyHTTPSServerLabel = new javax.swing.JLabel();
|
||||
proxyHTTPSServer = new javax.swing.JTextField();
|
||||
javax.swing.JLabel proxyHTTPSPortLabel = new javax.swing.JLabel();
|
||||
proxyHTTPSPort = new javax.swing.JTextField();
|
||||
javax.swing.JLabel proxyUserLabel = new javax.swing.JLabel();
|
||||
proxyUser = new javax.swing.JTextField();
|
||||
javax.swing.JLabel proxyPasswordLabel = new javax.swing.JLabel();
|
||||
proxyPassword = new javax.swing.JPasswordField();
|
||||
javax.swing.JLabel additionalBoardsManagerLabel = new javax.swing.JLabel();
|
||||
additionalBoardsManagerField = new javax.swing.JTextField();
|
||||
javax.swing.JButton extendedAdditionalUrlFieldWindow = new javax.swing.JButton();
|
||||
@ -256,7 +231,6 @@ public class Preferences extends javax.swing.JDialog {
|
||||
externalEditorBox = new javax.swing.JCheckBox();
|
||||
checkUpdatesBox = new javax.swing.JCheckBox();
|
||||
updateExtensionBox = new javax.swing.JCheckBox();
|
||||
autoAssociateBox = new javax.swing.JCheckBox();
|
||||
saveVerifyUploadBox = new javax.swing.JCheckBox();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
@ -291,99 +265,13 @@ public class Preferences extends javax.swing.JDialog {
|
||||
|
||||
comboWarningsLabel.setText(_("Compiler warnings: "));
|
||||
|
||||
proxySettingsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(_("Proxy Settings")));
|
||||
|
||||
proxyHTTPServerLabel.setText(_("Server (HTTP):"));
|
||||
|
||||
proxyHTTPServer.setColumns(10);
|
||||
|
||||
proxyHTTPPortLabel.setText(_("Port (HTTP):"));
|
||||
|
||||
proxyHTTPPort.setColumns(10);
|
||||
|
||||
proxyHTTPSServerLabel.setText(_("Server (HTTPS):"));
|
||||
|
||||
proxyHTTPSServer.setColumns(10);
|
||||
|
||||
proxyHTTPSPortLabel.setText(_("Port (HTTPS):"));
|
||||
|
||||
proxyHTTPSPort.setColumns(10);
|
||||
|
||||
proxyUserLabel.setText(_("Username:"));
|
||||
|
||||
proxyUser.setColumns(10);
|
||||
|
||||
proxyPasswordLabel.setText(_("Password:"));
|
||||
|
||||
proxyPassword.setColumns(10);
|
||||
|
||||
javax.swing.GroupLayout proxySettingsPanelLayout = new javax.swing.GroupLayout(proxySettingsPanel);
|
||||
proxySettingsPanel.setLayout(proxySettingsPanelLayout);
|
||||
proxySettingsPanelLayout.setHorizontalGroup(
|
||||
proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(proxySettingsPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addGroup(proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(proxyHTTPSServerLabel)
|
||||
.addGroup(proxySettingsPanelLayout.createSequentialGroup()
|
||||
.addGap(8, 8, 8)
|
||||
.addComponent(proxyHTTPServerLabel)))
|
||||
.addComponent(proxyUserLabel))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(proxyHTTPServer)
|
||||
.addComponent(proxyHTTPSServer)
|
||||
.addComponent(proxyUser, javax.swing.GroupLayout.Alignment.TRAILING))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addGroup(proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(proxyHTTPSPortLabel)
|
||||
.addComponent(proxyPasswordLabel, javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(proxyHTTPPortLabel, javax.swing.GroupLayout.Alignment.TRAILING))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(proxyHTTPSPort, javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(proxyHTTPPort, javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(proxyPassword, javax.swing.GroupLayout.Alignment.LEADING))
|
||||
.addContainerGap())
|
||||
);
|
||||
proxySettingsPanelLayout.setVerticalGroup(
|
||||
proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(proxySettingsPanelLayout.createSequentialGroup()
|
||||
.addGroup(proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(proxySettingsPanelLayout.createSequentialGroup()
|
||||
.addGroup(proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(proxyHTTPServerLabel)
|
||||
.addComponent(proxyHTTPServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(proxyHTTPSServerLabel)
|
||||
.addComponent(proxyHTTPSServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(proxyUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(proxyUserLabel)))
|
||||
.addGroup(proxySettingsPanelLayout.createSequentialGroup()
|
||||
.addGroup(proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(proxyHTTPPortLabel)
|
||||
.addComponent(proxyHTTPPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(proxyHTTPSPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(proxyHTTPSPortLabel))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(proxySettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(proxyPasswordLabel)
|
||||
.addComponent(proxyPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
additionalBoardsManagerLabel.setText(_("Additional Boards Manager URLs: "));
|
||||
additionalBoardsManagerLabel.setToolTipText(_("Enter a comma separated list of urls"));
|
||||
|
||||
additionalBoardsManagerField.setToolTipText(_("Enter a comma separated list of urls"));
|
||||
|
||||
extendedAdditionalUrlFieldWindow.setIcon(new ImageIcon(Base.getThemeImage("newwindow.gif", this)));
|
||||
extendedAdditionalUrlFieldWindow.setMargin(new java.awt.Insets(1, 1, 1, 1));
|
||||
extendedAdditionalUrlFieldWindow.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
extendedAdditionalUrlFieldWindowActionPerformed(evt);
|
||||
@ -394,6 +282,7 @@ public class Preferences extends javax.swing.JDialog {
|
||||
morePreferencesLabel.setText(_("More preferences can be edited directly in the file"));
|
||||
|
||||
preferencesFileLabel.setText(PreferencesData.getPreferencesFile().getAbsolutePath());
|
||||
preferencesFileLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
|
||||
preferencesFileLabel.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mousePressed(java.awt.event.MouseEvent evt) {
|
||||
preferencesFileLabelMousePressed(evt);
|
||||
@ -445,9 +334,6 @@ public class Preferences extends javax.swing.JDialog {
|
||||
updateExtensionBox.setText(_("Update sketch files to new extension on save (.pde -> .ino)"));
|
||||
checkboxesContainer.add(updateExtensionBox);
|
||||
|
||||
autoAssociateBox.setText(_("Automatically associate .ino files with Arduino"));
|
||||
checkboxesContainer.add(autoAssociateBox);
|
||||
|
||||
saveVerifyUploadBox.setText(_("Save when verifying or uploading"));
|
||||
checkboxesContainer.add(saveVerifyUploadBox);
|
||||
|
||||
@ -458,21 +344,28 @@ public class Preferences extends javax.swing.JDialog {
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(proxySettingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(sketchbookLocationField)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(browseButton))
|
||||
.addComponent(checkboxesContainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(okButton)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(cancelButton))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(additionalBoardsManagerLabel)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(additionalBoardsManagerField, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(extendedAdditionalUrlFieldWindow))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(arduinoNotRunningLabel)
|
||||
.addComponent(sketchbookLocationLabel)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(comboWarningsLabel)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(comboWarnings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(morePreferencesLabel)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(showVerboseLabel)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
@ -490,18 +383,10 @@ public class Preferences extends javax.swing.JDialog {
|
||||
.addComponent(comboLanguage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(requiresRestartLabel))))
|
||||
.addComponent(arduinoNotRunningLabel)
|
||||
.addComponent(morePreferencesLabel)
|
||||
.addComponent(preferencesFileLabel))
|
||||
.addGap(0, 0, Short.MAX_VALUE))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(okButton)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(cancelButton))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(additionalBoardsManagerLabel)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(additionalBoardsManagerField, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(extendedAdditionalUrlFieldWindow, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addGap(0, 0, Short.MAX_VALUE)))
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
@ -534,13 +419,11 @@ public class Preferences extends javax.swing.JDialog {
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(checkboxesContainer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(proxySettingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(additionalBoardsManagerLabel)
|
||||
.addComponent(additionalBoardsManagerField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(extendedAdditionalUrlFieldWindow, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(extendedAdditionalUrlFieldWindow))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(morePreferencesLabel)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
@ -551,7 +434,7 @@ public class Preferences extends javax.swing.JDialog {
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(cancelButton)
|
||||
.addComponent(okButton))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
@ -562,10 +445,10 @@ public class Preferences extends javax.swing.JDialog {
|
||||
File file = Base.selectFolder(_("Select new sketchbook location"), dflt, this);
|
||||
if (file != null) {
|
||||
String path = file.getAbsolutePath();
|
||||
if (Base.getPortableFolder() != null) {
|
||||
path = FileUtils.relativePath(Base.getPortableFolder().toString(), path);
|
||||
if (BaseNoGui.getPortableFolder() != null) {
|
||||
path = FileUtils.relativePath(BaseNoGui.getPortableFolder().toString(), path);
|
||||
if (path == null) {
|
||||
path = Base.getPortableSketchbookFolder();
|
||||
path = BaseNoGui.getPortableSketchbookFolder();
|
||||
}
|
||||
}
|
||||
sketchbookLocationField.setText(path);
|
||||
@ -575,12 +458,7 @@ public class Preferences extends javax.swing.JDialog {
|
||||
private void extendedAdditionalUrlFieldWindowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_extendedAdditionalUrlFieldWindowActionPerformed
|
||||
final AdditionalBoardsManagerURLTextArea additionalBoardsManagerURLTextArea = new AdditionalBoardsManagerURLTextArea(this);
|
||||
additionalBoardsManagerURLTextArea.setText(additionalBoardsManagerField.getText());
|
||||
additionalBoardsManagerURLTextArea.onOk(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
additionalBoardsManagerField.setText(additionalBoardsManagerURLTextArea.getText());
|
||||
}
|
||||
});
|
||||
additionalBoardsManagerURLTextArea.onOk(e -> additionalBoardsManagerField.setText(additionalBoardsManagerURLTextArea.getText()));
|
||||
additionalBoardsManagerURLTextArea.setVisible(true);
|
||||
}//GEN-LAST:event_extendedAdditionalUrlFieldWindowActionPerformed
|
||||
|
||||
@ -593,7 +471,7 @@ public class Preferences extends javax.swing.JDialog {
|
||||
}//GEN-LAST:event_preferencesFileLabelMousePressed
|
||||
|
||||
private void preferencesFileLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_preferencesFileLabelMouseExited
|
||||
preferencesFileLabel.setForeground(Color.BLACK);
|
||||
preferencesFileLabel.setForeground(new Color(76, 76, 76));
|
||||
}//GEN-LAST:event_preferencesFileLabelMouseExited
|
||||
|
||||
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
|
||||
@ -601,16 +479,19 @@ public class Preferences extends javax.swing.JDialog {
|
||||
}//GEN-LAST:event_cancelButtonActionPerformed
|
||||
|
||||
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
|
||||
savePreferencesData();
|
||||
for (Editor editor : base.getEditors()) {
|
||||
editor.applyPreferences();
|
||||
java.util.List<String> errors = validateData();
|
||||
if (!errors.isEmpty()) {
|
||||
Base.showWarning(_("Error"), errors.get(0), null);
|
||||
return;
|
||||
}
|
||||
|
||||
savePreferencesData();
|
||||
base.getEditors().forEach(processing.app.Editor::applyPreferences);
|
||||
cancelButtonActionPerformed(evt);
|
||||
}//GEN-LAST:event_okButtonActionPerformed
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JTextField additionalBoardsManagerField;
|
||||
private javax.swing.JCheckBox autoAssociateBox;
|
||||
private javax.swing.JCheckBox checkUpdatesBox;
|
||||
private javax.swing.JComboBox comboLanguage;
|
||||
private javax.swing.JComboBox comboWarnings;
|
||||
@ -619,12 +500,6 @@ public class Preferences extends javax.swing.JDialog {
|
||||
private javax.swing.JCheckBox externalEditorBox;
|
||||
private javax.swing.JTextField fontSizeField;
|
||||
private javax.swing.JLabel preferencesFileLabel;
|
||||
private javax.swing.JTextField proxyHTTPPort;
|
||||
private javax.swing.JTextField proxyHTTPSPort;
|
||||
private javax.swing.JTextField proxyHTTPSServer;
|
||||
private javax.swing.JTextField proxyHTTPServer;
|
||||
private javax.swing.JPasswordField proxyPassword;
|
||||
private javax.swing.JTextField proxyUser;
|
||||
private javax.swing.JCheckBox saveVerifyUploadBox;
|
||||
private javax.swing.JTextField sketchbookLocationField;
|
||||
private javax.swing.JCheckBox updateExtensionBox;
|
||||
@ -633,14 +508,22 @@ public class Preferences extends javax.swing.JDialog {
|
||||
private javax.swing.JCheckBox verifyUploadBox;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
private java.util.List<String> validateData() {
|
||||
java.util.List<String> errors = new LinkedList<>();
|
||||
if (FileUtils.isSubDirectory(new File(sketchbookLocationField.getText()), new File(PreferencesData.get("runtime.ide.path")))) {
|
||||
errors.add(_("The specified sketchbook folder contains your copy of the IDE.\nPlease choose a different folder for your sketchbook."));
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
private void savePreferencesData() {
|
||||
String oldPath = PreferencesData.get("sketchbook.path");
|
||||
String newPath = sketchbookLocationField.getText();
|
||||
if (newPath.isEmpty()) {
|
||||
if (base.getPortableFolder() == null) {
|
||||
if (BaseNoGui.getPortableFolder() == null) {
|
||||
newPath = base.getDefaultSketchbookFolderOrPromptForIt().toString();
|
||||
} else {
|
||||
newPath = base.getPortableSketchbookFolder();
|
||||
newPath = BaseNoGui.getPortableSketchbookFolder();
|
||||
}
|
||||
}
|
||||
if (!newPath.equals(oldPath)) {
|
||||
@ -683,27 +566,8 @@ public class Preferences extends javax.swing.JDialog {
|
||||
|
||||
PreferencesData.setBoolean("editor.update_extension", updateExtensionBox.isSelected());
|
||||
|
||||
if (autoAssociateBox != null) {
|
||||
PreferencesData.setBoolean("platform.auto_file_type_associations", autoAssociateBox.isSelected());
|
||||
}
|
||||
|
||||
PreferencesData.setBoolean("editor.save_on_verify", saveVerifyUploadBox.isSelected());
|
||||
|
||||
PreferencesData.set("proxy.http.server", proxyHTTPServer.getText());
|
||||
try {
|
||||
PreferencesData.set("proxy.http.port", Integer.valueOf(proxyHTTPPort.getText()).toString());
|
||||
} catch (NumberFormatException e) {
|
||||
PreferencesData.remove("proxy.http.port");
|
||||
}
|
||||
PreferencesData.set("proxy.https.server", proxyHTTPSServer.getText());
|
||||
try {
|
||||
PreferencesData.set("proxy.https.port", Integer.valueOf(proxyHTTPSPort.getText()).toString());
|
||||
} catch (NumberFormatException e) {
|
||||
PreferencesData.remove("proxy.https.port");
|
||||
}
|
||||
PreferencesData.set("proxy.user", proxyUser.getText());
|
||||
PreferencesData.set("proxy.password", new String(proxyPassword.getPassword()));
|
||||
|
||||
PreferencesData.set("boardsmanager.additional.urls", additionalBoardsManagerField.getText().replace("\r\n", "\n").replace("\r", "\n").replace("\n", ","));
|
||||
|
||||
//editor.applyPreferences();
|
||||
@ -744,27 +608,8 @@ public class Preferences extends javax.swing.JDialog {
|
||||
|
||||
updateExtensionBox.setSelected(PreferencesData.get("editor.update_extension") == null || PreferencesData.getBoolean("editor.update_extension"));
|
||||
|
||||
if (autoAssociateBox != null) {
|
||||
autoAssociateBox.setSelected(PreferencesData.getBoolean("platform.auto_file_type_associations"));
|
||||
}
|
||||
|
||||
saveVerifyUploadBox.setSelected(PreferencesData.getBoolean("editor.save_on_verify"));
|
||||
|
||||
proxyHTTPServer.setText(PreferencesData.get("proxy.http.server"));
|
||||
try {
|
||||
proxyHTTPPort.setText(Integer.toString(PreferencesData.getInteger("proxy.http.port", 8080)));
|
||||
} catch (NumberFormatException e) {
|
||||
proxyHTTPPort.setText("");
|
||||
}
|
||||
proxyHTTPSServer.setText(PreferencesData.get("proxy.https.server"));
|
||||
try {
|
||||
proxyHTTPSPort.setText(Integer.toString(PreferencesData.getInteger("proxy.https.port", 8443)));
|
||||
} catch (NumberFormatException e) {
|
||||
proxyHTTPSPort.setText("");
|
||||
}
|
||||
proxyUser.setText(PreferencesData.get("proxy.user"));
|
||||
proxyPassword.setText(PreferencesData.get("proxy.password"));
|
||||
|
||||
additionalBoardsManagerField.setText(PreferencesData.get("boardsmanager.additional.urls"));
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import javax.swing.Timer;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
|
||||
import cc.arduino.packages.BoardPort;
|
||||
import processing.app.debug.TextAreaFIFO;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
@ -44,16 +45,22 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
protected JCheckBox autoscrollBox;
|
||||
protected JComboBox lineEndings;
|
||||
protected JComboBox serialRates;
|
||||
private boolean monitorEnabled;
|
||||
private boolean closed;
|
||||
|
||||
private Timer updateTimer;
|
||||
private StringBuffer updateBuffer;
|
||||
|
||||
public AbstractMonitor(String title) {
|
||||
super(title);
|
||||
private BoardPort boardPort;
|
||||
|
||||
public AbstractMonitor(BoardPort boardPort) {
|
||||
super(boardPort.getLabel());
|
||||
this.boardPort = boardPort;
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent event) {
|
||||
try {
|
||||
closed = true;
|
||||
close();
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
@ -133,10 +140,7 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
}
|
||||
lineEndings.setMaximumSize(lineEndings.getMinimumSize());
|
||||
|
||||
String[] serialRateStrings = {
|
||||
"300", "1200", "2400", "4800", "9600",
|
||||
"19200", "38400", "57600", "74880", "115200"
|
||||
};
|
||||
String[] serialRateStrings = {"300", "1200", "2400", "4800", "9600", "19200", "38400", "57600", "74880", "115200", "230400", "250000"};
|
||||
|
||||
serialRates = new JComboBox();
|
||||
for (String rate : serialRateStrings) {
|
||||
@ -177,6 +181,43 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
updateBuffer = new StringBuffer(1048576);
|
||||
updateTimer = new Timer(33, this); // redraw serial monitor at 30 Hz
|
||||
updateTimer.start();
|
||||
|
||||
monitorEnabled = true;
|
||||
closed = false;
|
||||
}
|
||||
|
||||
public void enableWindow(boolean enable) {
|
||||
textArea.setEnabled(enable);
|
||||
scrollPane.setEnabled(enable);
|
||||
textField.setEnabled(enable);
|
||||
sendButton.setEnabled(enable);
|
||||
autoscrollBox.setEnabled(enable);
|
||||
lineEndings.setEnabled(enable);
|
||||
serialRates.setEnabled(enable);
|
||||
|
||||
monitorEnabled = enable;
|
||||
}
|
||||
|
||||
// Puts the window in suspend state, closing the serial port
|
||||
// to allow other entity (the programmer) to use it
|
||||
public void suspend() throws Exception {
|
||||
enableWindow(false);
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
public void resume(BoardPort boardPort) throws Exception {
|
||||
setBoardPort(boardPort);
|
||||
|
||||
// Enable the window
|
||||
enableWindow(true);
|
||||
|
||||
// If the window is visible, try to open the serial port
|
||||
if (!isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
open();
|
||||
}
|
||||
|
||||
public void onSerialRateChange(ActionListener listener) {
|
||||
@ -224,9 +265,26 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract void open() throws Exception;
|
||||
public boolean isClosed() {
|
||||
return closed;
|
||||
}
|
||||
|
||||
public abstract void close() throws Exception;
|
||||
public void open() throws Exception {
|
||||
closed = false;
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
closed = true;
|
||||
}
|
||||
|
||||
public BoardPort getBoardPort() {
|
||||
return boardPort;
|
||||
}
|
||||
|
||||
public void setBoardPort(BoardPort boardPort) {
|
||||
setTitle(boardPort.getLabel());
|
||||
this.boardPort = boardPort;
|
||||
}
|
||||
|
||||
public synchronized void addToUpdateBuffer(char buff[], int n) {
|
||||
updateBuffer.append(buff, 0, n);
|
||||
@ -239,8 +297,12 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final String s = consumeUpdateBuffer();
|
||||
if (s.length() > 0) {
|
||||
String s = consumeUpdateBuffer();
|
||||
|
||||
if (s.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//System.out.println("gui append " + s.length());
|
||||
if (autoscrollBox.isSelected()) {
|
||||
textArea.appendTrim(s);
|
||||
@ -249,6 +311,5 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
textArea.appendNoTrim(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,9 +25,7 @@ package processing.app;
|
||||
import cc.arduino.contributions.BuiltInCoreIsNewerCheck;
|
||||
import cc.arduino.contributions.DownloadableContributionVersionComparator;
|
||||
import cc.arduino.contributions.VersionHelper;
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.LibrariesIndexer;
|
||||
import cc.arduino.contributions.libraries.LibraryInstaller;
|
||||
import cc.arduino.contributions.libraries.*;
|
||||
import cc.arduino.contributions.libraries.ui.LibraryManagerUI;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.packages.ContributionInstaller;
|
||||
@ -41,6 +39,7 @@ import cc.arduino.view.Event;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import processing.app.debug.TargetBoard;
|
||||
import processing.app.debug.TargetPackage;
|
||||
@ -87,10 +86,13 @@ public class Base {
|
||||
}
|
||||
};
|
||||
|
||||
private static final int RECENT_SKETCHES_MAX_SIZE = 5;
|
||||
|
||||
private static boolean commandLine;
|
||||
public static volatile Base INSTANCE;
|
||||
|
||||
public static SplashScreenHelper splashScreenHelper = new SplashScreenHelper(SplashScreen.getSplashScreen());
|
||||
public static Map<String, Object> FIND_DIALOG_STATE = new HashMap<String, Object>();
|
||||
|
||||
// set to true after the first time the menu is built.
|
||||
// so that the errors while building don't show up again.
|
||||
@ -118,10 +120,12 @@ public class Base {
|
||||
private volatile Action openBoardsManager;
|
||||
|
||||
private final PdeKeywords pdeKeywords;
|
||||
private final List<JMenuItem> recentSketchesMenuItems;
|
||||
|
||||
static public void main(String args[]) throws Exception {
|
||||
System.setProperty("awt.useSystemAAFontSettings", "on");
|
||||
System.setProperty("swing.aatext", "true");
|
||||
System.setProperty("java.net.useSystemProxies", "true");
|
||||
|
||||
splashScreenHelper.splashText(_("Loading configuration..."));
|
||||
|
||||
@ -144,9 +148,9 @@ public class Base {
|
||||
|
||||
initLogger();
|
||||
|
||||
BaseNoGui.notifier = new GUIUserNotifier();
|
||||
BaseNoGui.initPlatform();
|
||||
|
||||
initPlatform();
|
||||
BaseNoGui.getPlatform().init();
|
||||
|
||||
BaseNoGui.initPortableFolder();
|
||||
|
||||
@ -205,7 +209,7 @@ public class Base {
|
||||
|
||||
// Set the look and feel before opening the window
|
||||
try {
|
||||
getPlatform().setLookAndFeel();
|
||||
BaseNoGui.getPlatform().setLookAndFeel();
|
||||
} catch (Exception e) {
|
||||
String mess = e.getMessage();
|
||||
if (mess.indexOf("ch.randelshofer.quaqua.QuaquaLookAndFeel") == -1) {
|
||||
@ -216,7 +220,7 @@ public class Base {
|
||||
}
|
||||
|
||||
// Create a location for untitled sketches
|
||||
untitledFolder = createTempFolder("untitled");
|
||||
untitledFolder = BaseNoGui.createTempFolder("untitled");
|
||||
DeleteFilesOnShutdown.add(untitledFolder);
|
||||
|
||||
INSTANCE = new Base(args);
|
||||
@ -260,23 +264,6 @@ public class Base {
|
||||
return commandLine;
|
||||
}
|
||||
|
||||
|
||||
static protected void initPlatform() {
|
||||
BaseNoGui.initPlatform();
|
||||
}
|
||||
|
||||
|
||||
static protected void initRequirements() {
|
||||
try {
|
||||
Class.forName("com.sun.jdi.VirtualMachine");
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
showError(_("Please install JDK 1.5 or later"),
|
||||
_("Arduino requires a full JDK (not just a JRE)\n" +
|
||||
"to run. Please install JDK 1.5 or later.\n" +
|
||||
"More information can be found in the reference."), cnfe);
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a File object for the given pathname. If the pathname
|
||||
// is not absolute, it is interpreted relative to the current
|
||||
// directory when starting the IDE (which is not the same as the
|
||||
@ -286,7 +273,13 @@ public class Base {
|
||||
}
|
||||
|
||||
public Base(String[] args) throws Exception {
|
||||
getPlatform().init();
|
||||
BaseNoGui.notifier = new GUIUserNotifier(this);
|
||||
this.recentSketchesMenuItems = new LinkedList<JMenuItem>();
|
||||
|
||||
CommandlineParser parser = new CommandlineParser(args);
|
||||
parser.parseArgumentsPhase1();
|
||||
|
||||
BaseNoGui.checkInstallationFolder();
|
||||
|
||||
String sketchbookPath = BaseNoGui.getSketchbookPath();
|
||||
|
||||
@ -313,7 +306,7 @@ public class Base {
|
||||
this.pdeKeywords = new PdeKeywords();
|
||||
this.pdeKeywords.reload();
|
||||
|
||||
CommandlineParser parser = CommandlineParser.newCommandlineParser(args);
|
||||
parser.parseArgumentsPhase2();
|
||||
|
||||
for (String path : parser.getFilenames()) {
|
||||
// Correctly resolve relative paths
|
||||
@ -334,7 +327,7 @@ public class Base {
|
||||
boolean showEditor = parser.isGuiMode();
|
||||
if (!parser.isForceSavePrefs())
|
||||
PreferencesData.setDoSave(showEditor);
|
||||
if (handleOpen(file, nextEditorLocation(), showEditor) == null) {
|
||||
if (handleOpen(file, nextEditorLocation(), showEditor, false) == null) {
|
||||
String mess = I18n.format(_("Failed to open sketch: \"{0}\""), path);
|
||||
// Open failure is fatal in upload/verify mode
|
||||
if (parser.isVerifyOrUploadMode())
|
||||
@ -350,8 +343,8 @@ public class Base {
|
||||
PreferencesData.save();
|
||||
|
||||
if (parser.isInstallBoard()) {
|
||||
ContributionsIndexer indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
|
||||
ContributionInstaller installer = new ContributionInstaller(indexer) {
|
||||
ContributionsIndexer indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform());
|
||||
ContributionInstaller installer = new ContributionInstaller(indexer, BaseNoGui.getPlatform()) {
|
||||
private String lastStatus = "";
|
||||
|
||||
@Override
|
||||
@ -365,7 +358,7 @@ public class Base {
|
||||
List<String> downloadedPackageIndexFiles = installer.updateIndex();
|
||||
installer.deleteUnknownFiles(downloadedPackageIndexFiles);
|
||||
indexer.parseIndex();
|
||||
indexer.syncWithFilesystem(getHardwareFolder());
|
||||
indexer.syncWithFilesystem(BaseNoGui.getHardwareFolder());
|
||||
|
||||
String[] boardToInstallParts = parser.getBoardToInstall().split(":");
|
||||
|
||||
@ -397,8 +390,8 @@ public class Base {
|
||||
System.exit(0);
|
||||
|
||||
} else if (parser.isInstallLibrary()) {
|
||||
LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder());
|
||||
LibraryInstaller installer = new LibraryInstaller(indexer) {
|
||||
LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform()));
|
||||
LibraryInstaller installer = new LibraryInstaller(indexer, BaseNoGui.getPlatform()) {
|
||||
private String lastStatus = "";
|
||||
|
||||
@Override
|
||||
@ -495,13 +488,7 @@ public class Base {
|
||||
// Do nothing (intended for only changing preferences)
|
||||
System.exit(0);
|
||||
} else if (parser.isGetPrefMode()) {
|
||||
String value = PreferencesData.get(parser.getGetPref(), null);
|
||||
if (value != null) {
|
||||
System.out.println(value);
|
||||
System.exit(0);
|
||||
} else {
|
||||
System.exit(4);
|
||||
}
|
||||
BaseNoGui.dumpPrefs(parser);
|
||||
}
|
||||
}
|
||||
|
||||
@ -550,8 +537,11 @@ public class Base {
|
||||
// Save the sketch path and window placement for each open sketch
|
||||
int count = PreferencesData.getInteger("last.sketch.count");
|
||||
int opened = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
String path = PreferencesData.get("last.sketch" + i + ".path");
|
||||
if (path == null) {
|
||||
continue;
|
||||
}
|
||||
if (BaseNoGui.getPortableFolder() != null) {
|
||||
File absolute = new File(BaseNoGui.getPortableFolder(), path);
|
||||
try {
|
||||
@ -568,7 +558,7 @@ public class Base {
|
||||
location = nextEditorLocation();
|
||||
}
|
||||
// If file did not exist, null will be returned for the Editor
|
||||
if (handleOpen(new File(path), location, true) != null) {
|
||||
if (handleOpen(new File(path), location, true, false, false) != null) {
|
||||
opened++;
|
||||
}
|
||||
}
|
||||
@ -589,20 +579,22 @@ public class Base {
|
||||
String untitledPath = untitledFolder.getAbsolutePath();
|
||||
|
||||
// Save the sketch path and window placement for each open sketch
|
||||
LinkedList<Editor> reverseEditors = new LinkedList<Editor>(editors);
|
||||
Collections.reverse(reverseEditors);
|
||||
int index = 0;
|
||||
for (Editor editor : editors) {
|
||||
for (Editor editor : reverseEditors) {
|
||||
String path = editor.getSketch().getMainFilePath();
|
||||
// In case of a crash, save untitled sketches if they contain changes.
|
||||
// (Added this for release 0158, may not be a good idea.)
|
||||
if (path.startsWith(untitledPath) &&
|
||||
!editor.getSketch().isModified()) {
|
||||
if (path.startsWith(untitledPath) && !editor.getSketch().isModified()) {
|
||||
continue;
|
||||
}
|
||||
if (BaseNoGui.getPortableFolder() != null) {
|
||||
path = FileUtils.relativePath(BaseNoGui.getPortableFolder().toString(), path);
|
||||
if (path == null)
|
||||
if (path == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
PreferencesData.set("last.sketch" + index + ".path", path);
|
||||
|
||||
int[] location = editor.getPlacement();
|
||||
@ -613,44 +605,23 @@ public class Base {
|
||||
PreferencesData.setInteger("last.sketch.count", index);
|
||||
}
|
||||
|
||||
|
||||
// If a sketch is untitled on quit, may need to store the new name
|
||||
// rather than the location from the temp folder.
|
||||
protected void storeSketchPath(Editor editor, int index) {
|
||||
String path = editor.getSketch().getMainFilePath();
|
||||
String untitledPath = untitledFolder.getAbsolutePath();
|
||||
if (path.startsWith(untitledPath)) {
|
||||
path = "";
|
||||
} else if (BaseNoGui.getPortableFolder() != null) {
|
||||
path = FileUtils.relativePath(BaseNoGui.getPortableFolder().toString(), path);
|
||||
if (path == null)
|
||||
path = "";
|
||||
}
|
||||
PreferencesData.set("last.sketch" + index + ".path", path);
|
||||
protected void storeRecentSketches(Sketch sketch) {
|
||||
if (sketch.isUntitled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> sketches = new LinkedHashSet<String>();
|
||||
sketches.add(sketch.getMainFilePath());
|
||||
sketches.addAll(PreferencesData.getCollection("recent.sketches"));
|
||||
|
||||
/*
|
||||
public void storeSketch(Editor editor) {
|
||||
int index = -1;
|
||||
for (int i = 0; i < editorCount; i++) {
|
||||
if (editors[i] == editor) {
|
||||
index = i;
|
||||
break;
|
||||
PreferencesData.setCollection("recent.sketches", sketches);
|
||||
}
|
||||
}
|
||||
if (index == -1) {
|
||||
System.err.println("Problem storing sketch " + editor.sketch.name);
|
||||
} else {
|
||||
String path = editor.sketch.getMainFilePath();
|
||||
Preferences.set("last.sketch" + index + ".path", path);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// .................................................................
|
||||
|
||||
protected void removeRecentSketchPath(String path) {
|
||||
Collection<String> sketches = new LinkedList<String>(PreferencesData.getCollection("recent.sketches"));
|
||||
sketches.remove(path);
|
||||
PreferencesData.setCollection("recent.sketches", sketches);
|
||||
}
|
||||
|
||||
// Because of variations in native windowing systems, no guarantees about
|
||||
// changes to the focused and active Windows can be made. Developers must
|
||||
@ -658,6 +629,14 @@ public class Base {
|
||||
// Window receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED event.
|
||||
protected void handleActivated(Editor whichEditor) {
|
||||
activeEditor = whichEditor;
|
||||
activeEditor.rebuildRecentSketchesMenu();
|
||||
if (PreferencesData.getBoolean("editor.external")) {
|
||||
try {
|
||||
activeEditor.getSketch().load(true);
|
||||
} catch (IOException e) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
|
||||
// set the current window to be the console that's getting output
|
||||
EditorConsoleStream.setCurrent(activeEditor.console);
|
||||
@ -732,7 +711,7 @@ public class Base {
|
||||
|
||||
// In 0126, untitled sketches will begin in the temp folder,
|
||||
// and then moved to a new location because Save will default to Save As.
|
||||
File sketchbookDir = getSketchbookFolder();
|
||||
File sketchbookDir = BaseNoGui.getSketchbookFolder();
|
||||
File newbieParentDir = untitledFolder;
|
||||
|
||||
// Use a generic name like sketch_031008a, the date plus a char
|
||||
@ -786,8 +765,7 @@ public class Base {
|
||||
try {
|
||||
File file = createNewUntitled();
|
||||
if (file != null) {
|
||||
Editor editor = handleOpen(file);
|
||||
editor.untitled = true;
|
||||
Editor editor = handleOpen(file, true);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
@ -857,7 +835,7 @@ public class Base {
|
||||
public void handleOpenPrompt() throws Exception {
|
||||
// get the frontmost window frame for placing file dialog
|
||||
FileDialog fd = new FileDialog(activeEditor, _("Open an Arduino sketch..."), FileDialog.LOAD);
|
||||
File lastFolder = new File(PreferencesData.get("last.folder", getSketchbookFolder().getAbsolutePath()));
|
||||
File lastFolder = new File(PreferencesData.get("last.folder", BaseNoGui.getSketchbookFolder().getAbsolutePath()));
|
||||
if (lastFolder.exists() && lastFolder.isFile()) {
|
||||
lastFolder = lastFolder.getParentFile();
|
||||
}
|
||||
@ -895,86 +873,99 @@ public class Base {
|
||||
* @throws Exception
|
||||
*/
|
||||
public Editor handleOpen(File file) throws Exception {
|
||||
return handleOpen(file, nextEditorLocation(), true);
|
||||
return handleOpen(file, false);
|
||||
}
|
||||
|
||||
public Editor handleOpen(File file, boolean untitled) throws Exception {
|
||||
return handleOpen(file, nextEditorLocation(), true, untitled);
|
||||
}
|
||||
|
||||
protected Editor handleOpen(File file, int[] location, boolean showEditor) throws Exception {
|
||||
// System.err.println("entering handleOpen " + path);
|
||||
protected Editor handleOpen(File file, int[] location, boolean showEditor, boolean untitled) throws Exception {
|
||||
return handleOpen(file, location, showEditor, true, untitled);
|
||||
}
|
||||
|
||||
protected Editor handleOpen(File file, int[] location, boolean showEditor, boolean storeOpenedSketches, boolean untitled) throws Exception {
|
||||
if (!file.exists()) return null;
|
||||
|
||||
// System.err.println(" editors: " + editors);
|
||||
// Cycle through open windows to make sure that it's not already open.
|
||||
String path = file.getAbsolutePath();
|
||||
for (Editor editor : editors) {
|
||||
if (editor.getSketch().getMainFilePath().equals(path)) {
|
||||
editor.toFront();
|
||||
// System.err.println(" handleOpen: already opened");
|
||||
return editor;
|
||||
}
|
||||
}
|
||||
|
||||
// If the active editor window is an untitled, and un-modified document,
|
||||
// just replace it with the file that's being opened.
|
||||
// if (activeEditor != null) {
|
||||
// Sketch activeSketch = activeEditor.sketch;
|
||||
// if (activeSketch.isUntitled() && !activeSketch.isModified()) {
|
||||
// // if it's an untitled, unmodified document, it can be replaced.
|
||||
// // except in cases where a second blank window is being opened.
|
||||
// if (!path.startsWith(untitledFolder.getAbsolutePath())) {
|
||||
// activeEditor.handleOpenUnchecked(path, 0, 0, 0, 0);
|
||||
// return activeEditor;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.err.println(" creating new editor");
|
||||
Editor editor = new Editor(this, file, location);
|
||||
// Editor editor = null;
|
||||
// try {
|
||||
// editor = new Editor(this, path, location);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// System.err.flush();
|
||||
// System.out.flush();
|
||||
// System.exit(1);
|
||||
// }
|
||||
// System.err.println(" done creating new editor");
|
||||
// EditorConsole.systemErr.println(" done creating new editor");
|
||||
final Editor editor = new Editor(this, file, location, BaseNoGui.getPlatform());
|
||||
|
||||
// Make sure that the sketch actually loaded
|
||||
if (editor.getSketch() == null) {
|
||||
// System.err.println("sketch was null, getting out of handleOpen");
|
||||
return null; // Just walk away quietly
|
||||
}
|
||||
|
||||
// if (editors == null) {
|
||||
// editors = new Editor[5];
|
||||
// }
|
||||
// if (editorCount == editors.length) {
|
||||
// editors = (Editor[]) PApplet.expand(editors);
|
||||
// }
|
||||
// editors[editorCount++] = editor;
|
||||
editor.untitled = untitled;
|
||||
|
||||
editors.add(editor);
|
||||
|
||||
// if (markedForClose != null) {
|
||||
// Point p = markedForClose.getLocation();
|
||||
// handleClose(markedForClose, false);
|
||||
// // open the new window in
|
||||
// editor.setLocation(p);
|
||||
// }
|
||||
if (storeOpenedSketches) {
|
||||
// Store information on who's open and running
|
||||
// (in case there's a crash or something that can't be recovered)
|
||||
storeSketches();
|
||||
storeRecentSketches(editor.getSketch());
|
||||
rebuildRecentSketchesMenuItems();
|
||||
PreferencesData.save();
|
||||
}
|
||||
|
||||
// now that we're ready, show the window
|
||||
// (don't do earlier, cuz we might move it based on a window being closed)
|
||||
if (showEditor)
|
||||
if (showEditor) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
editor.setVisible(true);
|
||||
|
||||
// System.err.println("exiting handleOpen");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
protected void rebuildRecentSketchesMenuItems() {
|
||||
Set<File> recentSketches = new LinkedHashSet<File>() {
|
||||
|
||||
@Override
|
||||
public boolean add(File file) {
|
||||
if (size() >= RECENT_SKETCHES_MAX_SIZE) {
|
||||
return false;
|
||||
}
|
||||
return super.add(file);
|
||||
}
|
||||
};
|
||||
|
||||
for (String path : PreferencesData.getCollection("recent.sketches")) {
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
recentSketches.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
recentSketchesMenuItems.clear();
|
||||
for (final File recentSketch : recentSketches) {
|
||||
JMenuItem recentSketchMenuItem = new JMenuItem(recentSketch.getParentFile().getName());
|
||||
recentSketchMenuItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
handleOpen(recentSketch);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
recentSketchesMenuItems.add(recentSketchMenuItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close a sketch as specified by its editor window.
|
||||
@ -993,35 +984,6 @@ public class Base {
|
||||
editor.internalCloseRunner();
|
||||
|
||||
if (editors.size() == 1) {
|
||||
// For 0158, when closing the last window /and/ it was already an
|
||||
// untitled sketch, just give up and let the user quit.
|
||||
// if (Preferences.getBoolean("sketchbook.closing_last_window_quits") ||
|
||||
// (editor.untitled && !editor.getSketch().isModified())) {
|
||||
if (OSUtils.isMacOS()) {
|
||||
Object[] options = {"OK", "Cancel"};
|
||||
String prompt =
|
||||
_("<html> " +
|
||||
"<head> <style type=\"text/css\">" +
|
||||
"b { font: 13pt \"Lucida Grande\" }" +
|
||||
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px }" +
|
||||
"</style> </head>" +
|
||||
"<b>Are you sure you want to Quit?</b>" +
|
||||
"<p>Closing the last open sketch will quit Arduino.");
|
||||
|
||||
int result = JOptionPane.showOptionDialog(editor,
|
||||
prompt,
|
||||
_("Quit"),
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]);
|
||||
if (result == JOptionPane.NO_OPTION ||
|
||||
result == JOptionPane.CLOSED_OPTION) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// This will store the sketch count as zero
|
||||
editors.remove(editor);
|
||||
try {
|
||||
@ -1030,6 +992,7 @@ public class Base {
|
||||
//ignore
|
||||
}
|
||||
storeSketches();
|
||||
rebuildRecentSketchesMenuItems();
|
||||
|
||||
// Save out the current prefs state
|
||||
PreferencesData.save();
|
||||
@ -1098,14 +1061,8 @@ public class Base {
|
||||
* @return false if canceled along the way
|
||||
*/
|
||||
protected boolean handleQuitEach() {
|
||||
int index = 0;
|
||||
for (Editor editor : editors) {
|
||||
if (editor.checkModified()) {
|
||||
// Update to the new/final sketch path for this fella
|
||||
storeSketchPath(editor, index);
|
||||
index++;
|
||||
|
||||
} else {
|
||||
if (!editor.checkModified()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1155,7 +1112,7 @@ public class Base {
|
||||
|
||||
// Add a list of all sketches and subfolders
|
||||
try {
|
||||
boolean sketches = addSketches(menu, getSketchbookFolder(), true);
|
||||
boolean sketches = addSketches(menu, BaseNoGui.getSketchbookFolder(), true);
|
||||
if (sketches) menu.addSeparator();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -1176,7 +1133,7 @@ public class Base {
|
||||
//new Exception().printStackTrace();
|
||||
try {
|
||||
menu.removeAll();
|
||||
addSketches(menu, getSketchbookFolder(), false);
|
||||
addSketches(menu, BaseNoGui.getSketchbookFolder(), false);
|
||||
//addSketches(menu, getSketchbookFolder());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -1195,6 +1152,13 @@ public class Base {
|
||||
return new LibraryList(libs);
|
||||
}
|
||||
|
||||
private List<ContributedLibrary> getSortedLibraries() {
|
||||
List<ContributedLibrary> installedLibraries = new LinkedList<ContributedLibrary>(BaseNoGui.librariesIndexer.getInstalledLibraries());
|
||||
Collections.sort(installedLibraries, new LibraryByTypeComparator());
|
||||
Collections.sort(installedLibraries, new LibraryOfSameTypeComparator());
|
||||
return installedLibraries;
|
||||
}
|
||||
|
||||
public void rebuildImportMenu(JMenu importMenu) {
|
||||
if (importMenu == null)
|
||||
return;
|
||||
@ -1222,36 +1186,38 @@ public class Base {
|
||||
importMenu.addSeparator();
|
||||
|
||||
// Split between user supplied libraries and IDE libraries
|
||||
TargetPlatform targetPlatform = getTargetPlatform();
|
||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
||||
|
||||
if (targetPlatform != null) {
|
||||
LibraryList ideLibs = getIDELibs();
|
||||
LibraryList userLibs = getUserLibs();
|
||||
try {
|
||||
// Find the current target. Get the platform, and then select the
|
||||
// correct name and core path.
|
||||
String platformNameLabel;
|
||||
platformNameLabel = StringUtils.capitalize(targetPlatform.getContainerPackage().getId()) + "/" + StringUtils.capitalize(targetPlatform.getId());
|
||||
platformNameLabel = I18n.format(_("{0} libraries"), platformNameLabel);
|
||||
JMenuItem platformItem = new JMenuItem(_(platformNameLabel));
|
||||
platformItem.setEnabled(false);
|
||||
importMenu.add(platformItem);
|
||||
|
||||
if (ideLibs.size() > 0) {
|
||||
addLibraries(importMenu, ideLibs);
|
||||
}
|
||||
|
||||
if (userLibs.size() > 0) {
|
||||
if (ideLibs.size() > 0) {
|
||||
List<ContributedLibrary> libs = getSortedLibraries();
|
||||
String lastLibType = null;
|
||||
for (ContributedLibrary lib : libs) {
|
||||
if (lastLibType == null || !lastLibType.equals(lib.getTypes().get(0))) {
|
||||
if (lastLibType != null) {
|
||||
importMenu.addSeparator();
|
||||
}
|
||||
JMenuItem contributedLibraryItem = new JMenuItem(_("Contributed libraries"));
|
||||
contributedLibraryItem.setEnabled(false);
|
||||
importMenu.add(contributedLibraryItem);
|
||||
addLibraries(importMenu, userLibs);
|
||||
lastLibType = lib.getTypes().get(0);
|
||||
JMenuItem platformItem = new JMenuItem(I18n.format(_("{0} libraries"), lastLibType));
|
||||
platformItem.setEnabled(false);
|
||||
importMenu.add(platformItem);
|
||||
}
|
||||
|
||||
AbstractAction action = new AbstractAction(lib.getName()) {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
UserLibrary l = (UserLibrary) getValue("library");
|
||||
try {
|
||||
activeEditor.getSketch().importLibrary(l);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", l.getSrcFolder()), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
action.putValue("library", lib);
|
||||
|
||||
// Add new element at the bottom
|
||||
JMenuItem item = new JMenuItem(action);
|
||||
item.putClientProperty("library", lib);
|
||||
importMenu.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1288,13 +1254,14 @@ public class Base {
|
||||
BaseNoGui.onBoardOrPortChange();
|
||||
|
||||
// Update editors status bar
|
||||
for (Editor editor : editors)
|
||||
for (Editor editor : editors) {
|
||||
editor.onBoardOrPortChange();
|
||||
}
|
||||
}
|
||||
|
||||
private void openManageLibrariesDialog() {
|
||||
@SuppressWarnings("serial")
|
||||
LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor) {
|
||||
LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor, BaseNoGui.getPlatform()) {
|
||||
@Override
|
||||
protected void onIndexesUpdated() throws Exception {
|
||||
BaseNoGui.initPackages();
|
||||
@ -1317,7 +1284,7 @@ public class Base {
|
||||
private void openInstallBoardDialog(final String filterText) throws Exception {
|
||||
// Create dialog for contribution manager
|
||||
@SuppressWarnings("serial")
|
||||
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) {
|
||||
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor, BaseNoGui.getPlatform()) {
|
||||
@Override
|
||||
protected void onIndexesUpdated() throws Exception {
|
||||
BaseNoGui.initPackages();
|
||||
@ -1447,7 +1414,7 @@ public class Base {
|
||||
@SuppressWarnings("serial")
|
||||
Action action = new AbstractAction(board.getName()) {
|
||||
public void actionPerformed(ActionEvent actionevent) {
|
||||
selectBoard((TargetBoard) getValue("b"));
|
||||
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
|
||||
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
|
||||
|
||||
onBoardOrPortChange();
|
||||
@ -1570,15 +1537,6 @@ public class Base {
|
||||
throw new IllegalStateException("Menu has no enabled items");
|
||||
}
|
||||
|
||||
|
||||
private void selectBoard(TargetBoard targetBoard) {
|
||||
BaseNoGui.selectBoard(targetBoard);
|
||||
}
|
||||
|
||||
public static void selectSerialPort(String port) {
|
||||
BaseNoGui.selectSerialPort(port);
|
||||
}
|
||||
|
||||
public void rebuildProgrammerMenu(JMenu menu) {
|
||||
menu.removeAll();
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
@ -1767,14 +1725,6 @@ public class Base {
|
||||
return list;
|
||||
}
|
||||
|
||||
protected void loadHardware(File folder) {
|
||||
BaseNoGui.loadHardware(folder);
|
||||
}
|
||||
|
||||
|
||||
// .................................................................
|
||||
|
||||
|
||||
/**
|
||||
* Show the About box.
|
||||
*/
|
||||
@ -1816,217 +1766,22 @@ public class Base {
|
||||
if (activeEditor != null) {
|
||||
dialog.setLocationRelativeTo(activeEditor);
|
||||
}
|
||||
dialog.pack();
|
||||
dialog.setMinimumSize(dialog.getSize());
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
// ...................................................................
|
||||
|
||||
|
||||
/**
|
||||
* Get list of platform constants.
|
||||
*/
|
||||
// static public int[] getPlatforms() {
|
||||
// return platforms;
|
||||
// }
|
||||
|
||||
|
||||
// static public int getPlatform() {
|
||||
// String osname = System.getProperty("os.name");
|
||||
//
|
||||
// if (osname.indexOf("Mac") != -1) {
|
||||
// return PConstants.MACOSX;
|
||||
//
|
||||
// } else if (osname.indexOf("Windows") != -1) {
|
||||
// return PConstants.WINDOWS;
|
||||
//
|
||||
// } else if (osname.equals("Linux")) { // true for the ibm vm
|
||||
// return PConstants.LINUX;
|
||||
//
|
||||
// } else {
|
||||
// return PConstants.OTHER;
|
||||
// }
|
||||
// }
|
||||
static public Platform getPlatform() {
|
||||
return BaseNoGui.getPlatform();
|
||||
}
|
||||
|
||||
|
||||
static public String getPlatformName() {
|
||||
String osname = System.getProperty("os.name");
|
||||
|
||||
if (osname.indexOf("Mac") != -1) {
|
||||
return "macosx";
|
||||
|
||||
} else if (osname.indexOf("Windows") != -1) {
|
||||
return "windows";
|
||||
|
||||
} else if (osname.equals("Linux")) { // true for the ibm vm
|
||||
return "linux";
|
||||
|
||||
} else {
|
||||
return "other";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// .................................................................
|
||||
|
||||
|
||||
static public File getSettingsFolder() {
|
||||
return BaseNoGui.getSettingsFolder();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convenience method to get a File object for the specified filename inside
|
||||
* the settings folder.
|
||||
* For now, only used by Preferences to get the preferences.txt file.
|
||||
*
|
||||
* @param filename A file inside the settings folder.
|
||||
* @return filename wrapped as a File object inside the settings folder
|
||||
*/
|
||||
static public File getSettingsFile(String filename) {
|
||||
return BaseNoGui.getSettingsFile(filename);
|
||||
}
|
||||
|
||||
|
||||
static public File getBuildFolder() {
|
||||
return BaseNoGui.getBuildFolder();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the path to the platform's temporary folder, by creating
|
||||
* a temporary temporary file and getting its parent folder.
|
||||
* <br/>
|
||||
* Modified for revision 0094 to actually make the folder randomized
|
||||
* to avoid conflicts in multi-user environments. (Bug 177)
|
||||
*/
|
||||
static public File createTempFolder(String name) {
|
||||
return BaseNoGui.createTempFolder(name);
|
||||
}
|
||||
|
||||
|
||||
// XXX: Remove this method and make librariesIndexer non-static
|
||||
static public LibraryList getLibraries() {
|
||||
return BaseNoGui.librariesIndexer.getInstalledLibraries();
|
||||
}
|
||||
|
||||
|
||||
static public String getExamplesPath() {
|
||||
return BaseNoGui.getExamplesPath();
|
||||
}
|
||||
|
||||
|
||||
static public List<File> getLibrariesPath() {
|
||||
return BaseNoGui.getLibrariesPath();
|
||||
}
|
||||
|
||||
|
||||
static public File getToolsFolder() {
|
||||
return BaseNoGui.getToolsFolder();
|
||||
}
|
||||
|
||||
|
||||
static public String getToolsPath() {
|
||||
return BaseNoGui.getToolsPath();
|
||||
}
|
||||
|
||||
|
||||
static public File getHardwareFolder() {
|
||||
return BaseNoGui.getHardwareFolder();
|
||||
}
|
||||
|
||||
//Get the core libraries
|
||||
static public File getCoreLibraries(String path) {
|
||||
return getContentFile(path);
|
||||
}
|
||||
|
||||
static public String getHardwarePath() {
|
||||
return BaseNoGui.getHardwarePath();
|
||||
}
|
||||
|
||||
|
||||
static public String getAvrBasePath() {
|
||||
return BaseNoGui.getAvrBasePath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specific TargetPackage
|
||||
*
|
||||
* @param packageName
|
||||
* @return
|
||||
*/
|
||||
static public TargetPackage getTargetPackage(String packageName) {
|
||||
return BaseNoGui.getTargetPackage(packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently selected TargetPlatform.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
static public TargetPlatform getTargetPlatform() {
|
||||
return BaseNoGui.getTargetPlatform();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specific TargetPlatform searching Package/Platform
|
||||
*
|
||||
* @param packageName
|
||||
* @param platformName
|
||||
* @return
|
||||
*/
|
||||
static public TargetPlatform getTargetPlatform(String packageName,
|
||||
String platformName) {
|
||||
return BaseNoGui.getTargetPlatform(packageName, platformName);
|
||||
}
|
||||
|
||||
static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) {
|
||||
return BaseNoGui.getCurrentTargetPlatformFromPackage(pack);
|
||||
}
|
||||
|
||||
static public PreferencesMap getBoardPreferences() {
|
||||
return BaseNoGui.getBoardPreferences();
|
||||
}
|
||||
|
||||
public List<JMenu> getBoardsCustomMenus() {
|
||||
return boardsCustomMenus;
|
||||
}
|
||||
|
||||
static public File getPortableFolder() {
|
||||
return BaseNoGui.getPortableFolder();
|
||||
}
|
||||
|
||||
|
||||
static public String getPortableSketchbookFolder() {
|
||||
return BaseNoGui.getPortableSketchbookFolder();
|
||||
}
|
||||
|
||||
|
||||
static public File getSketchbookFolder() {
|
||||
return BaseNoGui.getSketchbookFolder();
|
||||
}
|
||||
|
||||
|
||||
static public File getSketchbookLibrariesFolder() {
|
||||
return BaseNoGui.getSketchbookLibrariesFolder();
|
||||
}
|
||||
|
||||
|
||||
static public String getSketchbookLibrariesPath() {
|
||||
return getSketchbookLibrariesFolder().getAbsolutePath();
|
||||
return BaseNoGui.getSketchbookLibrariesFolder().getAbsolutePath();
|
||||
}
|
||||
|
||||
|
||||
static public File getSketchbookHardwareFolder() {
|
||||
return BaseNoGui.getSketchbookHardwareFolder();
|
||||
}
|
||||
|
||||
|
||||
public File getDefaultSketchbookFolderOrPromptForIt() {
|
||||
|
||||
File sketchbookFolder = BaseNoGui.getDefaultSketchbookFolder();
|
||||
@ -2084,7 +1839,7 @@ public class Base {
|
||||
*/
|
||||
static public void openURL(String url) {
|
||||
try {
|
||||
getPlatform().openURL(url);
|
||||
BaseNoGui.getPlatform().openURL(url);
|
||||
|
||||
} catch (Exception e) {
|
||||
showWarning(_("Problem Opening URL"),
|
||||
@ -2510,9 +2265,7 @@ public class Base {
|
||||
}
|
||||
return buffer;
|
||||
} finally {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
IOUtils.closeQuietly(input);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2560,12 +2313,8 @@ public class Base {
|
||||
}
|
||||
to.flush();
|
||||
} finally {
|
||||
if (from != null) {
|
||||
from.close(); // ??
|
||||
}
|
||||
if (to != null) {
|
||||
to.close(); // ??
|
||||
}
|
||||
IOUtils.closeQuietly(from);
|
||||
IOUtils.closeQuietly(to);
|
||||
}
|
||||
|
||||
targetFile.setLastModified(sourceFile.lastModified());
|
||||
@ -2597,12 +2346,15 @@ public class Base {
|
||||
File targetDir) throws IOException {
|
||||
targetDir.mkdirs();
|
||||
String files[] = sourceDir.list();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files == null) {
|
||||
throw new IOException("Unable to list files from " + sourceDir);
|
||||
}
|
||||
for (String file : files) {
|
||||
// Ignore dot files (.DS_Store), dot folders (.svn) while copying
|
||||
if (files[i].charAt(0) == '.') continue;
|
||||
if (file.charAt(0) == '.') continue;
|
||||
//if (files[i].equals(".") || files[i].equals("..")) continue;
|
||||
File source = new File(sourceDir, files[i]);
|
||||
File target = new File(targetDir, files[i]);
|
||||
File source = new File(sourceDir, file);
|
||||
File target = new File(targetDir, file);
|
||||
if (source.isDirectory()) {
|
||||
//target.mkdirs();
|
||||
copyDir(source, target);
|
||||
@ -2736,8 +2488,17 @@ public class Base {
|
||||
}
|
||||
}
|
||||
|
||||
// is there a valid library?
|
||||
File libFolder = sourceFile;
|
||||
if (FileUtils.isSubDirectory(new File(PreferencesData.get("sketchbook.path")), libFolder)) {
|
||||
activeEditor.statusError(_("A subfolder of your sketchbook is not a valid library"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (FileUtils.isSubDirectory(libFolder, new File(PreferencesData.get("sketchbook.path")))) {
|
||||
activeEditor.statusError(_("You can't import a folder that contains your sketchbook"));
|
||||
return;
|
||||
}
|
||||
|
||||
String libName = libFolder.getName();
|
||||
if (!BaseNoGui.isSanitaryName(libName)) {
|
||||
String mess = I18n.format(_("The library \"{0}\" cannot be used.\n"
|
||||
@ -2748,8 +2509,19 @@ public class Base {
|
||||
return;
|
||||
}
|
||||
|
||||
String[] headers;
|
||||
if (new File(libFolder, "library.properties").exists()) {
|
||||
headers = BaseNoGui.headerListFromIncludePath(UserLibrary.create(libFolder).getSrcFolder());
|
||||
} else {
|
||||
headers = BaseNoGui.headerListFromIncludePath(libFolder);
|
||||
}
|
||||
if (headers.length == 0) {
|
||||
activeEditor.statusError(_("Specified folder/zip file does not contain a valid library"));
|
||||
return;
|
||||
}
|
||||
|
||||
// copy folder
|
||||
File destinationFolder = new File(getSketchbookLibrariesFolder(), sourceFile.getName());
|
||||
File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder(), sourceFile.getName());
|
||||
if (!destinationFolder.mkdir()) {
|
||||
activeEditor.statusError(I18n.format(_("A library named {0} already exists"), sourceFile.getName()));
|
||||
return;
|
||||
@ -2761,6 +2533,8 @@ public class Base {
|
||||
return;
|
||||
}
|
||||
activeEditor.statusNotice(_("Library added to your libraries. Check \"Include library\" menu"));
|
||||
} catch (IOException e) {
|
||||
// FIXME error when importing. ignoring :(
|
||||
} finally {
|
||||
// delete zip created temp folder, if exists
|
||||
FileUtils.recursiveDelete(tmpFolder);
|
||||
@ -2790,4 +2564,8 @@ public class Base {
|
||||
public PdeKeywords getPdeKeywords() {
|
||||
return pdeKeywords;
|
||||
}
|
||||
|
||||
public List<JMenuItem> getRecentSketchesMenuItems() {
|
||||
return recentSketchesMenuItems;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,7 @@
|
||||
package processing.app;
|
||||
|
||||
import cc.arduino.files.DeleteFilesOnShutdown;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@ -34,7 +35,7 @@ class EditorConsoleStream extends OutputStream {
|
||||
// sister IDEs) might collide with the file causing permissions problems.
|
||||
// The files and folders are not deleted on exit because they may be
|
||||
// needed for debugging or bug reporting.
|
||||
tempFolder = Base.createTempFolder("console");
|
||||
tempFolder = BaseNoGui.createTempFolder("console");
|
||||
DeleteFilesOnShutdown.add(tempFolder);
|
||||
try {
|
||||
String outFileName = PreferencesData.get("console.output.file");
|
||||
@ -82,17 +83,13 @@ class EditorConsoleStream extends OutputStream {
|
||||
System.setErr(systemErr);
|
||||
|
||||
// close the PrintStream
|
||||
consoleOut.close();
|
||||
consoleErr.close();
|
||||
IOUtils.closeQuietly(consoleOut);
|
||||
IOUtils.closeQuietly(consoleErr);
|
||||
|
||||
// also have to close the original FileOutputStream
|
||||
// otherwise it won't be shut down completely
|
||||
try {
|
||||
stdoutFile.close();
|
||||
stderrFile.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
IOUtils.closeQuietly(stdoutFile);
|
||||
IOUtils.closeQuietly(stderrFile);
|
||||
|
||||
outFile.delete();
|
||||
errFile.delete();
|
||||
|
@ -91,7 +91,7 @@ public class EditorLineStatus extends JComponent {
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
if (name == "" && serialport == "") {
|
||||
PreferencesMap boardPreferences = Base.getBoardPreferences();
|
||||
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
|
||||
if (boardPreferences != null)
|
||||
setBoardName(boardPreferences.get("name"));
|
||||
else
|
||||
|
@ -1,7 +1,7 @@
|
||||
package processing.app;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
|
||||
@ -17,12 +17,9 @@ public class EditorListener implements KeyListener {
|
||||
}
|
||||
|
||||
/** ctrl-alt on windows and linux, cmd-alt on mac os x */
|
||||
static final int CTRL_ALT = ActionEvent.ALT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
|
||||
|
||||
static final int CTRL_SHIFT = ActionEvent.SHIFT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
|
||||
|
||||
static final int CTRL = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
|
||||
|
||||
private static final int CTRL = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
|
||||
private static final int CTRL_ALT = InputEvent.ALT_MASK | CTRL;
|
||||
private static final int CTRL_SHIFT = InputEvent.SHIFT_MASK | CTRL;
|
||||
|
||||
public void keyTyped(KeyEvent event) {
|
||||
char c = event.getKeyChar();
|
||||
@ -53,8 +50,7 @@ public class EditorListener implements KeyListener {
|
||||
|
||||
// Navigation..
|
||||
// FIXME: not working on LINUX !!!
|
||||
if (((event.getModifiers() & CTRL_SHIFT) == CTRL_SHIFT)) {
|
||||
if(code == KeyEvent.VK_TAB)
|
||||
if ((event.getModifiers() & CTRL_SHIFT) == CTRL_SHIFT && code == KeyEvent.VK_TAB) {
|
||||
sketch.handlePrevCode();
|
||||
}
|
||||
|
||||
|
@ -465,7 +465,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String message = "";
|
||||
message += _("Arduino: ") + BaseNoGui.VERSION_NAME_LONG + " (" + System.getProperty("os.name") + "), ";
|
||||
message += _("Board: ") + "\"" + Base.getBoardPreferences().get("name") + "\"\n\n";
|
||||
message += _("Board: ") + "\"" + BaseNoGui.getBoardPreferences().get("name") + "\"\n\n";
|
||||
message += editor.console.consoleTextPane.getText().trim();
|
||||
if ((PreferencesData.getBoolean("build.verbose")) == false) {
|
||||
message += "\n\n";
|
||||
|
@ -43,7 +43,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
|
||||
|
||||
/** Titles for each button when the shift key is pressed. */
|
||||
static final String titleShift[] = {
|
||||
_("Verify"), _("Upload Using Programmer"), _("New"), _("Open in Another Window"), _("Save"), _("Serial Monitor")
|
||||
_("Verify"), _("Upload Using Programmer"), _("New"), _("Open in Another Window"), _("Save As..."), _("Serial Monitor")
|
||||
};
|
||||
|
||||
static final int BUTTON_COUNT = title.length;
|
||||
@ -342,7 +342,11 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
|
||||
break;
|
||||
|
||||
case SAVE:
|
||||
if (e.isShiftDown()) {
|
||||
editor.handleSaveAs();
|
||||
} else {
|
||||
editor.handleSave(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case EXPORT:
|
||||
|
@ -1,462 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004-08 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
import processing.app.helpers.OSUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Find & Replace window for the Processing editor.
|
||||
* <p/>
|
||||
* One major annoyance in this is that the window is re-created each time
|
||||
* that "Find" is called. This is because Mac OS X has a strange focus
|
||||
* issue with windows that are re-shown with setVisible() or show().
|
||||
* requestFocusInWindow() properly sets the focus to the find field,
|
||||
* however, just a short moment later, the focus is set to null. Even
|
||||
* trying to catch this scenario and request it again doesn't seem to work.
|
||||
* Most likely this is some annoyance buried deep in one of Apple's docs,
|
||||
* or in the doc for the focus stuff (I tend to think the former because
|
||||
* Windows doesn't seem to be quite so beligerent). Filed as
|
||||
* <A HREF="http://dev.processing.org/bugs/show_bug.cgi?id=244"> Bug 244</A>
|
||||
* should anyone have clues about how to fix.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class FindReplace extends JFrame implements ActionListener {
|
||||
|
||||
private Editor editor;
|
||||
|
||||
private JTextField findField;
|
||||
private JTextField replaceField;
|
||||
private static String findString;
|
||||
private static String replaceString;
|
||||
|
||||
private JButton replaceButton;
|
||||
private JButton replaceAllButton;
|
||||
private JButton replaceFindButton;
|
||||
private JButton previousButton;
|
||||
private JButton findButton;
|
||||
|
||||
private JCheckBox ignoreCaseBox;
|
||||
private static boolean ignoreCase = true;
|
||||
|
||||
private JCheckBox wrapAroundBox;
|
||||
private static boolean wrapAround = true;
|
||||
|
||||
private JCheckBox searchAllFilesBox;
|
||||
private static boolean searchAllFiles = false;
|
||||
|
||||
public FindReplace(Editor editor) {
|
||||
super(_("Find"));
|
||||
this.editor = editor;
|
||||
|
||||
JPanel contentPanel = new JPanel();
|
||||
Border padding = BorderFactory.createEmptyBorder(10, 10, 10, 10);
|
||||
contentPanel.setBorder(padding);
|
||||
setContentPane(contentPanel);
|
||||
|
||||
JLabel findLabel = new JLabel(_("Find:"));
|
||||
findField = new JTextField(20);
|
||||
JLabel replaceLabel = new JLabel(_("Replace with:"));
|
||||
replaceField = new JTextField(20);
|
||||
|
||||
// Fill the findString with selected text if no previous value
|
||||
if (editor.getSelectedText() != null
|
||||
&& editor.getSelectedText().length() > 0)
|
||||
findString = editor.getSelectedText();
|
||||
|
||||
if (findString != null)
|
||||
findField.setText(findString);
|
||||
if (replaceString != null)
|
||||
replaceField.setText(replaceString);
|
||||
|
||||
ignoreCaseBox = new JCheckBox(_("Ignore Case"));
|
||||
ignoreCaseBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ignoreCase = ignoreCaseBox.isSelected();
|
||||
}
|
||||
});
|
||||
ignoreCaseBox.setSelected(ignoreCase);
|
||||
|
||||
wrapAroundBox = new JCheckBox(_("Wrap Around"));
|
||||
wrapAroundBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
wrapAround = wrapAroundBox.isSelected();
|
||||
}
|
||||
});
|
||||
wrapAroundBox.setSelected(wrapAround);
|
||||
|
||||
searchAllFilesBox = new JCheckBox(_("Search all Sketch Tabs"));
|
||||
searchAllFilesBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
searchAllFiles = searchAllFilesBox.isSelected();
|
||||
}
|
||||
});
|
||||
searchAllFilesBox.setSelected(searchAllFiles);
|
||||
|
||||
JPanel checkboxPanel = new JPanel();
|
||||
checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.PAGE_AXIS));
|
||||
checkboxPanel.add(ignoreCaseBox);
|
||||
checkboxPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
checkboxPanel.add(wrapAroundBox);
|
||||
checkboxPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
checkboxPanel.add(searchAllFilesBox);
|
||||
|
||||
replaceAllButton = new JButton(_("Replace All"));
|
||||
replaceAllButton.addActionListener(this);
|
||||
replaceButton = new JButton(_("Replace"));
|
||||
replaceButton.addActionListener(this);
|
||||
replaceFindButton = new JButton(_("Replace & Find"));
|
||||
replaceFindButton.addActionListener(this);
|
||||
previousButton = new JButton(_("Previous"));
|
||||
previousButton.addActionListener(this);
|
||||
findButton = new JButton(_("Find"));
|
||||
findButton.addActionListener(this);
|
||||
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
|
||||
|
||||
// ordering of buttons is different on mac versus pc
|
||||
if (OSUtils.isMacOS()) {
|
||||
buttonPanel.add(replaceAllButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(replaceButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(replaceFindButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(previousButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(findButton);
|
||||
|
||||
} else {
|
||||
buttonPanel.add(findButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(previousButton); // is this the right position for
|
||||
// non-Mac?
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(replaceFindButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(replaceButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(8, 0)));
|
||||
buttonPanel.add(replaceAllButton);
|
||||
}
|
||||
|
||||
// to fix ugliness.. normally macosx java 1.3 puts an
|
||||
// ugly white border around this object, so turn it off.
|
||||
if (OSUtils.isMacOS()) {
|
||||
buttonPanel.setBorder(null);
|
||||
}
|
||||
|
||||
// Put all components onto the dialog window
|
||||
GridBagLayout searchLayout = new GridBagLayout();
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
Container pane = getContentPane();
|
||||
pane.setLayout(searchLayout);
|
||||
|
||||
gbc.insets = new Insets(4, 4, 4, 4);
|
||||
gbc.gridx = 0;
|
||||
gbc.weightx = 0.0;
|
||||
gbc.weighty = 0.0;
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.anchor = GridBagConstraints.LINE_END;
|
||||
pane.add(findLabel, gbc);
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 1.0;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.anchor = GridBagConstraints.LINE_START;
|
||||
pane.add(findField, gbc);
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 1;
|
||||
gbc.weightx = 0.0;
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.anchor = GridBagConstraints.LINE_END;
|
||||
pane.add(replaceLabel, gbc);
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 1.0;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.anchor = GridBagConstraints.LINE_START;
|
||||
pane.add(replaceField, gbc);
|
||||
gbc.gridx = 1;
|
||||
gbc.gridy = 2;
|
||||
gbc.weighty = 0.0;
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
pane.add(checkboxPanel, gbc);
|
||||
gbc.anchor = GridBagConstraints.CENTER;
|
||||
gbc.gridwidth = 2;
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 3;
|
||||
gbc.insets = new Insets(12, 4, 4, 4);
|
||||
pane.add(buttonPanel, gbc);
|
||||
|
||||
pack();
|
||||
setResizable(false);
|
||||
// centers the dialog on thew screen
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
// make the find button the blinky default
|
||||
getRootPane().setDefaultButton(findButton);
|
||||
|
||||
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
handleClose();
|
||||
}
|
||||
});
|
||||
Base.registerWindowCloseKeys(getRootPane(), new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
// hide();
|
||||
handleClose();
|
||||
}
|
||||
});
|
||||
Base.setIcon(this);
|
||||
|
||||
// hack to to get first field to focus properly on osx
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowActivated(WindowEvent e) {
|
||||
// System.out.println("activating");
|
||||
/* boolean ok = */findField.requestFocusInWindow();
|
||||
// System.out.println("got " + ok);
|
||||
findField.selectAll();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleClose() {
|
||||
// System.out.println("handling close now");
|
||||
findString = findField.getText();
|
||||
replaceString = replaceField.getText();
|
||||
|
||||
// this object should eventually become dereferenced
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
/*
|
||||
public void show() {
|
||||
findField.requestFocusInWindow();
|
||||
super.show();
|
||||
//findField.selectAll();
|
||||
//findField.requestFocus();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Object source = e.getSource();
|
||||
|
||||
if (source == findButton) {
|
||||
findNext();
|
||||
|
||||
} else if (source == previousButton) {
|
||||
findPrevious();
|
||||
|
||||
} else if (source == replaceFindButton) {
|
||||
replaceAndFindNext();
|
||||
|
||||
} else if (source == replaceButton) {
|
||||
replace();
|
||||
|
||||
} else if (source == replaceAllButton) {
|
||||
replaceAll();
|
||||
}
|
||||
}
|
||||
|
||||
// look for the next instance of the find string to be found
|
||||
// once found, select it (and go to that line)
|
||||
|
||||
private boolean find(boolean wrap, boolean backwards, boolean searchTabs,
|
||||
int originTab) {
|
||||
// System.out.println("Find: " + originTab);
|
||||
boolean wrapNeeded = false;
|
||||
String search = findField.getText();
|
||||
// System.out.println("finding for " + search + " " + findString);
|
||||
// this will catch "find next" being called when no search yet
|
||||
if (search.length() == 0)
|
||||
return false;
|
||||
|
||||
String text = editor.getText();
|
||||
|
||||
if (ignoreCase) {
|
||||
search = search.toLowerCase();
|
||||
text = text.toLowerCase();
|
||||
}
|
||||
|
||||
int nextIndex;
|
||||
if (!backwards) {
|
||||
// int selectionStart = editor.textarea.getSelectionStart();
|
||||
int selectionEnd = editor.getSelectionStop();
|
||||
|
||||
nextIndex = text.indexOf(search, selectionEnd);
|
||||
if (wrap && nextIndex == -1) {
|
||||
// if wrapping, a second chance is ok, start from beginning
|
||||
wrapNeeded = true;
|
||||
}
|
||||
} else {
|
||||
// int selectionStart = editor.textarea.getSelectionStart();
|
||||
int selectionStart = editor.getSelectionStart() - 1;
|
||||
|
||||
if (selectionStart >= 0) {
|
||||
nextIndex = text.lastIndexOf(search, selectionStart);
|
||||
} else {
|
||||
nextIndex = -1;
|
||||
}
|
||||
if (wrap && nextIndex == -1) {
|
||||
// if wrapping, a second chance is ok, start from the end
|
||||
wrapNeeded = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (nextIndex == -1) {
|
||||
// Nothing found on this tab: Search other tabs if required
|
||||
if (searchTabs) {
|
||||
// editor.
|
||||
Sketch sketch = editor.getSketch();
|
||||
if (sketch.getCodeCount() > 1) {
|
||||
int realCurrentTab = sketch.getCodeIndex(sketch.getCurrentCode());
|
||||
|
||||
if (originTab != realCurrentTab) {
|
||||
if (originTab < 0)
|
||||
originTab = realCurrentTab;
|
||||
|
||||
if (!wrap)
|
||||
if ((!backwards && realCurrentTab + 1 >= sketch.getCodeCount())
|
||||
|| (backwards && realCurrentTab - 1 < 0))
|
||||
return false; // Can't continue without wrap
|
||||
|
||||
if (backwards) {
|
||||
sketch.handlePrevCode();
|
||||
this.setVisible(true);
|
||||
int l = editor.getText().length() - 1;
|
||||
editor.setSelection(l, l);
|
||||
} else {
|
||||
sketch.handleNextCode();
|
||||
this.setVisible(true);
|
||||
editor.setSelection(0, 0);
|
||||
}
|
||||
|
||||
return find(wrap, backwards, searchTabs, originTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wrapNeeded)
|
||||
nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search,
|
||||
0);
|
||||
}
|
||||
|
||||
if (nextIndex != -1) {
|
||||
editor.setSelection(nextIndex, nextIndex + search.length());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the current selection with whatever's in the replacement text
|
||||
* field.
|
||||
*/
|
||||
public void replace() {
|
||||
if (findField.getText().length() == 0)
|
||||
return;
|
||||
|
||||
int newpos = editor.getSelectionStart() - findField.getText().length();
|
||||
if (newpos < 0)
|
||||
newpos = 0;
|
||||
editor.setSelection(newpos, newpos);
|
||||
|
||||
boolean foundAtLeastOne = false;
|
||||
|
||||
if (find(false, false, searchAllFiles, -1)) {
|
||||
foundAtLeastOne = true;
|
||||
editor.setSelectedText(replaceField.getText());
|
||||
editor.getSketch().setModified(true); // TODO is this necessary?
|
||||
}
|
||||
|
||||
if (!foundAtLeastOne) {
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the current selection with whatever's in the replacement text
|
||||
* field, and then find the next match
|
||||
*/
|
||||
public void replaceAndFindNext() {
|
||||
replace();
|
||||
findNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace everything that matches by doing find and replace alternately until
|
||||
* nothing more found.
|
||||
*/
|
||||
public void replaceAll() {
|
||||
if (findField.getText().length() == 0)
|
||||
return;
|
||||
// move to the beginning
|
||||
editor.setSelection(0, 0);
|
||||
|
||||
boolean foundAtLeastOne = false;
|
||||
while (true) {
|
||||
if (find(false, false, searchAllFiles, -1)) {
|
||||
foundAtLeastOne = true;
|
||||
editor.setSelectedText(replaceField.getText());
|
||||
editor.getSketch().setModified(true); // TODO is this necessary?
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundAtLeastOne) {
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFindText(String text) {
|
||||
if (text == null) {
|
||||
return;
|
||||
}
|
||||
findField.setText(text);
|
||||
findString = text;
|
||||
}
|
||||
|
||||
public void findNext() {
|
||||
if (!find(wrapAround, false, searchAllFiles, -1)) {
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
}
|
||||
|
||||
public void findPrevious() {
|
||||
if (!find(wrapAround, true, searchAllFiles, -1)) {
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -26,18 +26,13 @@ public class NetworkMonitor extends AbstractMonitor implements MessageConsumer {
|
||||
|
||||
private static final int MAX_CONNECTION_ATTEMPTS = 5;
|
||||
|
||||
private final BoardPort port;
|
||||
private final String ipAddress;
|
||||
|
||||
private MessageSiphon inputConsumer;
|
||||
private Session session;
|
||||
private Channel channel;
|
||||
private int connectionAttempts;
|
||||
|
||||
public NetworkMonitor(BoardPort port) {
|
||||
super(port.getLabel());
|
||||
this.port = port;
|
||||
this.ipAddress = port.getAddress();
|
||||
super(port);
|
||||
|
||||
onSendCommand(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
@ -61,16 +56,17 @@ public class NetworkMonitor extends AbstractMonitor implements MessageConsumer {
|
||||
|
||||
@Override
|
||||
public String getAuthorizationKey() {
|
||||
return "runtime.pwd." + ipAddress;
|
||||
return "runtime.pwd." + getBoardPort().getAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() throws Exception {
|
||||
super.open();
|
||||
this.connectionAttempts = 0;
|
||||
|
||||
JSch jSch = new JSch();
|
||||
SSHClientSetupChainRing sshClientSetupChain = new SSHConfigFileSetup(new SSHPwdSetup());
|
||||
session = sshClientSetupChain.setup(port, jSch);
|
||||
session = sshClientSetupChain.setup(getBoardPort(), jSch);
|
||||
|
||||
session.setUserInfo(new NoInteractionUserInfo(PreferencesData.get(getAuthorizationKey())));
|
||||
session.connect(30000);
|
||||
@ -156,6 +152,8 @@ public class NetworkMonitor extends AbstractMonitor implements MessageConsumer {
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
super.close();
|
||||
|
||||
if (channel != null) {
|
||||
inputConsumer.stop();
|
||||
channel.disconnect();
|
||||
|
@ -84,13 +84,6 @@ public class Preferences {
|
||||
|
||||
static final int GUI_SMALL = 6;
|
||||
|
||||
static protected void init(File file) {
|
||||
PreferencesData.init(file);
|
||||
|
||||
// other things that have to be set explicitly for the defaults
|
||||
PreferencesHelper.putColor(PreferencesData.prefs, "run.window.bgcolor", SystemColor.control);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected static void save() {
|
||||
PreferencesData.save();
|
||||
|
@ -30,14 +30,11 @@ import static processing.app.I18n._;
|
||||
@SuppressWarnings("serial")
|
||||
public class SerialMonitor extends AbstractMonitor {
|
||||
|
||||
private final String port;
|
||||
private Serial serial;
|
||||
private int serialRate;
|
||||
|
||||
public SerialMonitor(BoardPort port) {
|
||||
super(port.getLabel());
|
||||
|
||||
this.port = port.getAddress();
|
||||
super(port);
|
||||
|
||||
serialRate = PreferencesData.getInteger("serial.debug_rate");
|
||||
serialRates.setSelectedItem(serialRate + " " + _("baud"));
|
||||
@ -89,9 +86,11 @@ public class SerialMonitor extends AbstractMonitor {
|
||||
}
|
||||
|
||||
public void open() throws Exception {
|
||||
super.open();
|
||||
|
||||
if (serial != null) return;
|
||||
|
||||
serial = new Serial(port, serialRate) {
|
||||
serial = new Serial(getBoardPort().getAddress(), serialRate) {
|
||||
@Override
|
||||
protected void message(char buff[], int n) {
|
||||
addToUpdateBuffer(buff, n);
|
||||
@ -100,6 +99,7 @@ public class SerialMonitor extends AbstractMonitor {
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
super.close();
|
||||
if (serial != null) {
|
||||
int[] location = getPlacement();
|
||||
String locationStr = PApplet.join(PApplet.str(location), ",");
|
||||
|
@ -49,7 +49,7 @@ import java.util.List;
|
||||
public class Sketch {
|
||||
static private File tempBuildFolder;
|
||||
|
||||
private Editor editor;
|
||||
private final Editor editor;
|
||||
|
||||
/** true if any of the files have been modified. */
|
||||
private boolean modified;
|
||||
@ -57,10 +57,7 @@ public class Sketch {
|
||||
private SketchCodeDocument current;
|
||||
private int currentIndex;
|
||||
|
||||
private SketchData data;
|
||||
|
||||
/** Class name for the PApplet, as determined by the preprocessor. */
|
||||
private String appletClassName;
|
||||
private final SketchData data;
|
||||
|
||||
/**
|
||||
* path is location of the main .pde file, because this is also
|
||||
@ -86,7 +83,7 @@ public class Sketch {
|
||||
"the application to complete the repair.", null);
|
||||
}
|
||||
*/
|
||||
tempBuildFolder = Base.getBuildFolder();
|
||||
tempBuildFolder = BaseNoGui.getBuildFolder();
|
||||
//Base.addBuildFolderToClassPath();
|
||||
|
||||
load();
|
||||
@ -108,6 +105,10 @@ public class Sketch {
|
||||
* in which case the load happens each time "run" is hit.
|
||||
*/
|
||||
protected void load() throws IOException {
|
||||
load(false);
|
||||
}
|
||||
|
||||
protected void load(boolean forceUpdate) throws IOException {
|
||||
data.load();
|
||||
|
||||
for (SketchCode code : data.getCodes()) {
|
||||
@ -117,12 +118,12 @@ public class Sketch {
|
||||
|
||||
// set the main file to be the current tab
|
||||
if (editor != null) {
|
||||
setCurrentCode(0);
|
||||
setCurrentCode(currentIndex, forceUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boolean renamingCode;
|
||||
private boolean renamingCode;
|
||||
|
||||
/**
|
||||
* Handler for the New Code menu option.
|
||||
@ -444,7 +445,7 @@ public class Sketch {
|
||||
Object[] options = { _("OK"), _("Cancel") };
|
||||
String prompt = (currentIndex == 0) ?
|
||||
_("Are you sure you want to delete this sketch?") :
|
||||
I18n.format(_("Are you sure you want to delete \"{0}\"?"), current.getCode().getPrettyName());
|
||||
I18n.format(_("Are you sure you want to delete \"{0}\"?"), current.getCode().getFileNameWithExtensionIfNotIno());
|
||||
int result = JOptionPane.showOptionDialog(editor,
|
||||
prompt,
|
||||
_("Delete"),
|
||||
@ -519,7 +520,7 @@ public class Sketch {
|
||||
}
|
||||
|
||||
|
||||
protected void calcModified() {
|
||||
private void calcModified() {
|
||||
modified = false;
|
||||
for (SketchCode code : data.getCodes()) {
|
||||
if (code.isModified()) {
|
||||
@ -611,7 +612,7 @@ public class Sketch {
|
||||
}
|
||||
|
||||
|
||||
protected boolean renameCodeToInoExtension(File pdeFile) {
|
||||
private boolean renameCodeToInoExtension(File pdeFile) {
|
||||
for (SketchCode c : data.getCodes()) {
|
||||
if (!c.getFile().equals(pdeFile))
|
||||
continue;
|
||||
@ -636,14 +637,11 @@ public class Sketch {
|
||||
* because they can cause trouble.
|
||||
*/
|
||||
protected boolean saveAs() throws IOException {
|
||||
String newParentDir = null;
|
||||
String newName = null;
|
||||
|
||||
// get new name for folder
|
||||
FileDialog fd = new FileDialog(editor, _("Save sketch folder as..."), FileDialog.SAVE);
|
||||
if (isReadOnly() || isUntitled()) {
|
||||
// default to the sketchbook folder
|
||||
fd.setDirectory(Base.getSketchbookFolder().getAbsolutePath());
|
||||
fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath());
|
||||
} else {
|
||||
// default to the parent folder of where this was
|
||||
// on macs a .getParentFile() method is required
|
||||
@ -654,8 +652,8 @@ public class Sketch {
|
||||
fd.setFile(oldName);
|
||||
|
||||
fd.setVisible(true);
|
||||
newParentDir = fd.getDirectory();
|
||||
newName = fd.getFile();
|
||||
String newParentDir = fd.getDirectory();
|
||||
String newName = fd.getFile();
|
||||
|
||||
// user canceled selection
|
||||
if (newName == null) return false;
|
||||
@ -836,7 +834,7 @@ public class Sketch {
|
||||
destFile = new File(data.getCodeFolder(), filename);
|
||||
|
||||
} else {
|
||||
for (String extension : data.getExtensions()) {
|
||||
for (String extension : SketchData.EXTENSIONS) {
|
||||
String lower = filename.toLowerCase();
|
||||
if (lower.endsWith("." + extension)) {
|
||||
destFile = new File(data.getFolder(), filename);
|
||||
@ -956,10 +954,10 @@ public class Sketch {
|
||||
// could also scan the text in the file to see if each import
|
||||
// statement is already in there, but if the user has the import
|
||||
// commented out, then this will be a problem.
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (String aList : list) {
|
||||
buffer.append("#include <");
|
||||
buffer.append(list[i]);
|
||||
buffer.append(aList);
|
||||
buffer.append(">\n");
|
||||
}
|
||||
buffer.append('\n');
|
||||
@ -979,8 +977,12 @@ public class Sketch {
|
||||
* </OL>
|
||||
*/
|
||||
public void setCurrentCode(int which) {
|
||||
setCurrentCode(which, false);
|
||||
}
|
||||
|
||||
public void setCurrentCode(int which, boolean forceUpdate) {
|
||||
// if current is null, then this is the first setCurrent(0)
|
||||
if ((currentIndex == which) && (current != null)) {
|
||||
if (!forceUpdate && (currentIndex == which) && (current != null)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1065,69 +1067,14 @@ public class Sketch {
|
||||
//handleOpen(sketch);
|
||||
//history.lastRecorded = historySaved;
|
||||
|
||||
// set current to null so that the tab gets updated
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=515
|
||||
current = null;
|
||||
// nuke previous files and settings, just get things loaded
|
||||
load();
|
||||
load(true);
|
||||
}
|
||||
|
||||
// // handle preprocessing the main file's code
|
||||
// return build(tempBuildFolder.getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Map an error from a set of processed .java files back to its location
|
||||
* in the actual sketch.
|
||||
* @param message The error message.
|
||||
* @param filename The .java file where the exception was found.
|
||||
* @param line Line number of the .java file for the exception (1-indexed)
|
||||
* @return A RunnerException to be sent to the editor, or null if it wasn't
|
||||
* possible to place the exception to the sketch code.
|
||||
*/
|
||||
// public RunnerException placeExceptionAlt(String message,
|
||||
// String filename, int line) {
|
||||
// String appletJavaFile = appletClassName + ".java";
|
||||
// SketchCode errorCode = null;
|
||||
// if (filename.equals(appletJavaFile)) {
|
||||
// for (SketchCode code : getCode()) {
|
||||
// if (code.isExtension("ino")) {
|
||||
// if (line >= code.getPreprocOffset()) {
|
||||
// errorCode = code;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// for (SketchCode code : getCode()) {
|
||||
// if (code.isExtension("java")) {
|
||||
// if (filename.equals(code.getFileName())) {
|
||||
// errorCode = code;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// int codeIndex = getCodeIndex(errorCode);
|
||||
//
|
||||
// if (codeIndex != -1) {
|
||||
// //System.out.println("got line num " + lineNumber);
|
||||
// // in case this was a tab that got embedded into the main .java
|
||||
// line -= getCode(codeIndex).getPreprocOffset();
|
||||
//
|
||||
// // lineNumber is 1-indexed, but editor wants zero-indexed
|
||||
// line--;
|
||||
//
|
||||
// // getMessage() will be what's shown in the editor
|
||||
// RunnerException exception =
|
||||
// new RunnerException(message, codeIndex, line, -1);
|
||||
// exception.hideStackTrace();
|
||||
// return exception;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Run the build inside the temporary build folder.
|
||||
* @return null if compilation failed, main class name if not
|
||||
@ -1235,29 +1182,6 @@ public class Sketch {
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
public boolean exportApplicationPrompt() throws IOException, RunnerException {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Export to application via GUI.
|
||||
*/
|
||||
protected boolean exportApplication() throws IOException, RunnerException {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Export to application without GUI.
|
||||
*/
|
||||
public boolean exportApplication(String destPath,
|
||||
int exportPlatform) throws IOException, RunnerException {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make sure the sketch hasn't been moved or deleted by some
|
||||
* nefarious user. If they did, try to re-create it and save.
|
||||
@ -1297,11 +1221,11 @@ public class Sketch {
|
||||
*/
|
||||
public boolean isReadOnly() {
|
||||
String apath = data.getFolder().getAbsolutePath();
|
||||
for (File folder : Base.getLibrariesPath()) {
|
||||
for (File folder : BaseNoGui.getLibrariesPath()) {
|
||||
if (apath.startsWith(folder.getAbsolutePath()))
|
||||
return true;
|
||||
}
|
||||
if (apath.startsWith(Base.getExamplesPath()) ||
|
||||
if (apath.startsWith(BaseNoGui.getExamplesPath()) ||
|
||||
apath.startsWith(Base.getSketchbookLibrariesPath())) {
|
||||
return true;
|
||||
}
|
||||
@ -1345,7 +1269,7 @@ public class Sketch {
|
||||
* extensions.
|
||||
*/
|
||||
public boolean validExtension(String what) {
|
||||
return data.getExtensions().contains(what);
|
||||
return SketchData.EXTENSIONS.contains(what);
|
||||
}
|
||||
|
||||
|
||||
@ -1356,7 +1280,7 @@ public class Sketch {
|
||||
return data.getDefaultExtension();
|
||||
}
|
||||
|
||||
static private List<String> hiddenExtensions = Arrays.asList("ino", "pde");
|
||||
static private final List<String> hiddenExtensions = Arrays.asList("ino", "pde");
|
||||
|
||||
public List<String> getHiddenExtensions() {
|
||||
return hiddenExtensions;
|
||||
@ -1452,11 +1376,6 @@ public class Sketch {
|
||||
}
|
||||
|
||||
|
||||
public String getAppletClassName2() {
|
||||
return appletClassName;
|
||||
}
|
||||
|
||||
|
||||
// .................................................................
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
package processing.app;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
import javax.swing.*;
|
||||
@ -133,9 +134,7 @@ public class UpdateCheck implements Runnable {
|
||||
reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
return Integer.parseInt(reader.readLine());
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import processing.app.Base;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.awt.Frame;
|
||||
@ -8,6 +10,12 @@ import javax.swing.JOptionPane;
|
||||
|
||||
public class GUIUserNotifier extends UserNotifier {
|
||||
|
||||
private final Base base;
|
||||
|
||||
public GUIUserNotifier(Base base) {
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an error message that's actually fatal to the program.
|
||||
* This is an error that can't be recovered. Use showWarning()
|
||||
@ -16,7 +24,7 @@ public class GUIUserNotifier extends UserNotifier {
|
||||
public void showError(String title, String message, Throwable e, int exit_code) {
|
||||
if (title == null) title = _("Error");
|
||||
|
||||
JOptionPane.showMessageDialog(new Frame(), message, title,
|
||||
JOptionPane.showMessageDialog(base.getActiveEditor(), message, title,
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
if (e != null) e.printStackTrace();
|
||||
@ -30,7 +38,7 @@ public class GUIUserNotifier extends UserNotifier {
|
||||
public void showMessage(String title, String message) {
|
||||
if (title == null) title = _("Message");
|
||||
|
||||
JOptionPane.showMessageDialog(new Frame(), message, title,
|
||||
JOptionPane.showMessageDialog(base.getActiveEditor(), message, title,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
@ -40,7 +48,7 @@ public class GUIUserNotifier extends UserNotifier {
|
||||
public void showWarning(String title, String message, Exception e) {
|
||||
if (title == null) title = _("Warning");
|
||||
|
||||
JOptionPane.showMessageDialog(new Frame(), message, title,
|
||||
JOptionPane.showMessageDialog(base.getActiveEditor(), message, title,
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
|
||||
if (e != null) e.printStackTrace();
|
||||
|
@ -83,7 +83,7 @@ public class ThinkDifferent {
|
||||
@Override
|
||||
public void handleQuitRequestWith(AppEvent.QuitEvent quitEvent, QuitResponse quitResponse) {
|
||||
if (waitForBase()) {
|
||||
if (Base.INSTANCE.handleClose(Base.INSTANCE.getActiveEditor())) {
|
||||
if (Base.INSTANCE.handleQuit()) {
|
||||
quitResponse.performQuit();
|
||||
} else {
|
||||
quitResponse.cancelQuit();
|
||||
@ -107,7 +107,7 @@ public class ThinkDifferent {
|
||||
|
||||
private static void sleep(int millis) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(millis);
|
||||
} catch (InterruptedException e) {
|
||||
//ignore
|
||||
}
|
||||
|
23
app/src/processing/app/syntax/MyConfigurableCaret.java
Normal file
23
app/src/processing/app/syntax/MyConfigurableCaret.java
Normal file
@ -0,0 +1,23 @@
|
||||
package processing.app.syntax;
|
||||
|
||||
import org.fife.ui.rtextarea.ConfigurableCaret;
|
||||
import processing.app.helpers.OSUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class MyConfigurableCaret extends ConfigurableCaret {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.isConsumed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!OSUtils.isLinux() && SwingUtilities.isMiddleMouseButton(e)) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.mouseClicked(e);
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
package processing.app.syntax;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.fife.ui.rsyntaxtextarea.TokenMap;
|
||||
import org.fife.ui.rsyntaxtextarea.TokenTypes;
|
||||
import processing.app.Base;
|
||||
@ -126,9 +127,7 @@ public class PdeKeywords {
|
||||
|
||||
fillMissingTokenType();
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
package processing.app.syntax;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.fife.ui.rsyntaxtextarea.*;
|
||||
import org.fife.ui.rsyntaxtextarea.Theme;
|
||||
import org.fife.ui.rsyntaxtextarea.Token;
|
||||
@ -85,7 +86,7 @@ public class SketchTextArea extends RSyntaxTextArea {
|
||||
installFeatures();
|
||||
}
|
||||
|
||||
protected void installFeatures() throws IOException {
|
||||
private void installFeatures() throws IOException {
|
||||
setTheme(PreferencesData.get("editor.syntax_theme", "default"));
|
||||
|
||||
setLinkGenerator(new DocLinkGenerator(pdeKeywords));
|
||||
@ -95,16 +96,14 @@ public class SketchTextArea extends RSyntaxTextArea {
|
||||
setSyntaxEditingStyle(SYNTAX_STYLE_CPLUSPLUS);
|
||||
}
|
||||
|
||||
public void setTheme(String name) throws IOException {
|
||||
private void setTheme(String name) throws IOException {
|
||||
FileInputStream defaultXmlInputStream = null;
|
||||
try {
|
||||
defaultXmlInputStream = new FileInputStream(new File(BaseNoGui.getContentFile("lib"), "theme/syntax/" + name + ".xml"));
|
||||
Theme theme = Theme.load(defaultXmlInputStream);
|
||||
theme.apply(this);
|
||||
} finally {
|
||||
if (defaultXmlInputStream != null) {
|
||||
defaultXmlInputStream.close();
|
||||
}
|
||||
IOUtils.closeQuietly(defaultXmlInputStream);
|
||||
}
|
||||
|
||||
setForeground(processing.app.Theme.getColor("editor.fgcolor"));
|
||||
@ -127,6 +126,7 @@ public class SketchTextArea extends RSyntaxTextArea {
|
||||
setSyntaxTheme(TokenTypes.COMMENT_EOL, "comment1");
|
||||
setSyntaxTheme(TokenTypes.COMMENT_KEYWORD, "comment1");
|
||||
setSyntaxTheme(TokenTypes.COMMENT_MARKUP, "comment1");
|
||||
setSyntaxTheme(TokenTypes.LITERAL_BOOLEAN, "literal_boolean");
|
||||
setSyntaxTheme(TokenTypes.LITERAL_CHAR, "literal_char");
|
||||
setSyntaxTheme(TokenTypes.LITERAL_STRING_DOUBLE_QUOTE, "literal_string_double_quote");
|
||||
}
|
||||
@ -143,7 +143,7 @@ public class SketchTextArea extends RSyntaxTextArea {
|
||||
|
||||
// Removing the default focus traversal keys
|
||||
// This is because the DefaultKeyboardFocusManager handles the keypress and consumes the event
|
||||
protected void fixControlTab() {
|
||||
private void fixControlTab() {
|
||||
removeCTRLTabFromFocusTraversal();
|
||||
|
||||
removeCTRLSHIFTTabFromFocusTraversal();
|
||||
@ -151,23 +151,18 @@ public class SketchTextArea extends RSyntaxTextArea {
|
||||
|
||||
private void removeCTRLSHIFTTabFromFocusTraversal() {
|
||||
KeyStroke ctrlShiftTab = KeyStroke.getKeyStroke("ctrl shift TAB");
|
||||
Set<AWTKeyStroke> backwardKeys = new HashSet<AWTKeyStroke>(this.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
|
||||
Set<AWTKeyStroke> backwardKeys = new HashSet<>(this.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
|
||||
backwardKeys.remove(ctrlShiftTab);
|
||||
}
|
||||
|
||||
private void removeCTRLTabFromFocusTraversal() {
|
||||
KeyStroke ctrlTab = KeyStroke.getKeyStroke("ctrl TAB");
|
||||
Set<AWTKeyStroke> forwardKeys = new HashSet<AWTKeyStroke>(this.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
|
||||
Set<AWTKeyStroke> forwardKeys = new HashSet<>(this.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
|
||||
forwardKeys.remove(ctrlTab);
|
||||
this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardKeys);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void select(int selectionStart, int selectionEnd) {
|
||||
super.select(selectionStart, selectionEnd);
|
||||
}
|
||||
|
||||
public boolean isSelectionActive() {
|
||||
return this.getSelectedText() != null;
|
||||
}
|
||||
@ -221,17 +216,6 @@ public class SketchTextArea extends RSyntaxTextArea {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JPopupMenu createPopupMenu() {
|
||||
JPopupMenu menu = super.createPopupMenu();
|
||||
return menu;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configurePopupMenu(JPopupMenu popupMenu) {
|
||||
super.configurePopupMenu(popupMenu);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RTAMouseListener createMouseListener() {
|
||||
return new SketchTextAreaMouseListener(this);
|
||||
@ -242,7 +226,7 @@ public class SketchTextArea extends RSyntaxTextArea {
|
||||
int offset = getLineStartOffset(line);
|
||||
int end = getLineEndOffset(line);
|
||||
getDocument().getText(offset, end - offset, segment);
|
||||
} catch (BadLocationException e) {
|
||||
} catch (BadLocationException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -271,16 +255,16 @@ public class SketchTextArea extends RSyntaxTextArea {
|
||||
|
||||
@Override
|
||||
public LinkGeneratorResult isLinkAtOffset(RSyntaxTextArea textArea, final int offs) {
|
||||
Token token = textArea.modelToToken(offs);
|
||||
if (token == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Token token = textArea.modelToToken(offs);
|
||||
String reference = pdeKeywords.getReference(token.getLexeme());
|
||||
|
||||
final String reference = pdeKeywords.getReference(token.getLexeme());
|
||||
if (reference != null || (token.getType() == TokenTypes.DATA_TYPE || token.getType() == TokenTypes.VARIABLE || token.getType() == TokenTypes.FUNCTION)) {
|
||||
|
||||
// LOG.fine("reference: " + reference + ", match: " + (token.getType() == TokenTypes.DATA_TYPE || token.getType() == TokenTypes.VARIABLE || token.getType() == TokenTypes.FUNCTION));
|
||||
|
||||
if (token != null && (reference != null || (token.getType() == TokenTypes.DATA_TYPE || token.getType() == TokenTypes.VARIABLE || token.getType() == TokenTypes.FUNCTION))) {
|
||||
|
||||
LinkGeneratorResult generatorResult = new LinkGeneratorResult() {
|
||||
return new LinkGeneratorResult() {
|
||||
|
||||
@Override
|
||||
public int getSourceOffset() {
|
||||
@ -297,8 +281,6 @@ public class SketchTextArea extends RSyntaxTextArea {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return generatorResult;
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -316,7 +298,7 @@ public class SketchTextArea extends RSyntaxTextArea {
|
||||
private boolean isScanningForLinks;
|
||||
private int hoveredOverLinkOffset = -1;
|
||||
|
||||
protected SketchTextAreaMouseListener(RTextArea textArea) {
|
||||
SketchTextAreaMouseListener(RTextArea textArea) {
|
||||
super(textArea);
|
||||
insets = new Insets(0, 0, 0, 0);
|
||||
}
|
||||
@ -458,7 +440,7 @@ public class SketchTextArea extends RSyntaxTextArea {
|
||||
if (isScanningForLinks) {
|
||||
Cursor c = getCursor();
|
||||
isScanningForLinks = false;
|
||||
if (c != null && c.getType() == Cursor.HAND_CURSOR) {
|
||||
if (c.getType() == Cursor.HAND_CURSOR) {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
||||
repaint(); // TODO: Repaint just the affected line.
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package processing.app.syntax;
|
||||
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaDefaultInputMap;
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaEditorKit;
|
||||
import org.fife.ui.rtextarea.RTextArea;
|
||||
import org.fife.ui.rtextarea.RTextAreaEditorKit;
|
||||
import processing.app.PreferencesData;
|
||||
@ -15,6 +16,7 @@ public class SketchTextAreaDefaultInputMap extends RSyntaxTextAreaDefaultInputMa
|
||||
public SketchTextAreaDefaultInputMap() {
|
||||
int defaultModifier = getDefaultModifier();
|
||||
int alt = InputEvent.ALT_MASK;
|
||||
int shift = InputEvent.SHIFT_MASK;
|
||||
boolean isOSX = RTextArea.isOSX();
|
||||
int moveByWordMod = isOSX ? alt : defaultModifier;
|
||||
|
||||
@ -37,7 +39,24 @@ public class SketchTextAreaDefaultInputMap extends RSyntaxTextAreaDefaultInputMa
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, defaultModifier), DefaultEditorKit.beginAction);
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, defaultModifier), DefaultEditorKit.endAction);
|
||||
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, defaultModifier | shift), DefaultEditorKit.selectionBeginLineAction);
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, defaultModifier | shift), DefaultEditorKit.selectionEndLineAction);
|
||||
|
||||
remove(KeyStroke.getKeyStroke(KeyEvent.VK_J, defaultModifier));
|
||||
}
|
||||
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_OPEN_BRACKET, defaultModifier), DefaultEditorKit.insertTabAction);
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_CLOSE_BRACKET, defaultModifier), RSyntaxTextAreaEditorKit.rstaDecreaseIndentAction);
|
||||
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, defaultModifier | shift), DefaultEditorKit.selectionBeginAction);
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, defaultModifier | shift), DefaultEditorKit.selectionEndAction);
|
||||
}
|
||||
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_DIVIDE, defaultModifier), RSyntaxTextAreaEditorKit.rstaToggleCommentAction);
|
||||
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT, 0), DefaultEditorKit.backwardAction);
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT, 0), DefaultEditorKit.forwardAction);
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_DOWN, 0), DefaultEditorKit.downAction);
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_UP, 0), DefaultEditorKit.upAction);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package processing.app.syntax;
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaUI;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.Caret;
|
||||
import javax.swing.text.EditorKit;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
@ -18,4 +19,11 @@ public class SketchTextAreaUI extends RSyntaxTextAreaUI {
|
||||
public EditorKit getEditorKit(JTextComponent tc) {
|
||||
return defaultKit;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Caret createCaret() {
|
||||
Caret caret = new MyConfigurableCaret();
|
||||
caret.setBlinkRate(500);
|
||||
return caret;
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,6 @@ package processing.app.syntax;
|
||||
|
||||
import org.fife.ui.rsyntaxtextarea.modes.CPlusPlusTokenMaker;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Controls the syntax highlighting of {@link SketchTextArea} based on the {@link PdeKeywords}
|
||||
*
|
||||
@ -51,6 +49,11 @@ public class SketchTokenMaker extends CPlusPlusTokenMaker {
|
||||
|
||||
@Override
|
||||
public void addToken(char[] array, int start, int end, int tokenType, int startOffset, boolean hyperlink) {
|
||||
if (start > end) {
|
||||
super.addToken(array, start, end, tokenType, startOffset, hyperlink);
|
||||
return;
|
||||
}
|
||||
|
||||
// This assumes all of your extra tokens would normally be scanned as IDENTIFIER.
|
||||
int newType = pdeKeywords.getTokenType(array, start, end);
|
||||
if (newType > -1) {
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
package processing.app.tools;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.Base;
|
||||
import processing.app.Editor;
|
||||
import processing.app.Sketch;
|
||||
@ -124,22 +125,21 @@ public class Archiver implements Tool {
|
||||
if (filename != null) {
|
||||
newbie = new File(directory, filename);
|
||||
|
||||
ZipOutputStream zos = null;
|
||||
try {
|
||||
//System.out.println(newbie);
|
||||
FileOutputStream zipOutputFile = new FileOutputStream(newbie);
|
||||
ZipOutputStream zos = new ZipOutputStream(zipOutputFile);
|
||||
zos = new ZipOutputStream(new FileOutputStream(newbie));
|
||||
|
||||
// recursively fill the zip file
|
||||
buildZip(location, name, zos);
|
||||
|
||||
// close up the jar file
|
||||
zos.flush();
|
||||
zos.close();
|
||||
|
||||
editor.statusNotice("Created archive " + newbie.getName() + ".");
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(zos);
|
||||
}
|
||||
} else {
|
||||
editor.statusNotice(_("Archive sketch canceled."));
|
||||
@ -150,6 +150,9 @@ public class Archiver implements Tool {
|
||||
public void buildZip(File dir, String sofar,
|
||||
ZipOutputStream zos) throws IOException {
|
||||
String files[] = dir.list();
|
||||
if (files == null) {
|
||||
throw new IOException("Unable to list files from " + dir);
|
||||
}
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].equals(".") ||
|
||||
files[i].equals("..")) continue;
|
||||
|
@ -1,950 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Original Copyright (c) 1997, 1998 Van Di-Han HO. All Rights Reserved.
|
||||
Updates Copyright (c) 2001 Jason Pell.
|
||||
Further updates Copyright (c) 2003 Martin Gomez, Ateneo de Manila University
|
||||
Bug fixes Copyright (c) 2005-09 Ben Fry and Casey Reas
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 2.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.app.tools;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.app.legacy.PApplet;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
|
||||
/**
|
||||
* Handler for dealing with auto format.
|
||||
* Contributed by Martin Gomez, additional bug fixes by Ben Fry.
|
||||
*
|
||||
* After some further digging, this code in fact appears to be a modified
|
||||
* version of Jason Pell's GPLed "Java Beautifier" class found here:
|
||||
* http://www.geocities.com/jasonpell/programs.html
|
||||
* Which is itself based on code from Van Di-Han Ho:
|
||||
* http://www.geocities.com/~starkville/vancbj_idx.html
|
||||
* [Ben Fry, August 2009]
|
||||
*/
|
||||
public class AutoFormat implements Tool {
|
||||
Editor editor;
|
||||
|
||||
static final int BLOCK_MAXLEN = 1024;
|
||||
|
||||
StringBuffer strOut;
|
||||
int indentValue;
|
||||
String indentChar;
|
||||
int EOF;
|
||||
CharArrayReader reader;
|
||||
int readCount, indexBlock, lineLength, lineNumber;
|
||||
char chars[];
|
||||
String strBlock;
|
||||
int s_level[];
|
||||
int c_level;
|
||||
int sp_flg[][];
|
||||
int s_ind[][];
|
||||
int s_if_lev[];
|
||||
int s_if_flg[];
|
||||
int if_lev, if_flg, level;
|
||||
int ind[];
|
||||
int e_flg, paren;
|
||||
static int p_flg[];
|
||||
char l_char, p_char;
|
||||
int a_flg, q_flg, ct;
|
||||
int s_tabs[][];
|
||||
String w_if_, w_else, w_for, w_ds, w_case, w_cpp_comment, w_jdoc;
|
||||
int jdoc, j;
|
||||
char string[];
|
||||
char cc;
|
||||
int s_flg;
|
||||
int peek;
|
||||
char peekc;
|
||||
int tabs;
|
||||
char last_char;
|
||||
char c;
|
||||
|
||||
String line_feed;
|
||||
|
||||
|
||||
public void init(Editor editor) {
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
|
||||
public String getMenuTitle() {
|
||||
return _("Auto Format");
|
||||
}
|
||||
|
||||
public void comment() throws IOException {
|
||||
int save_s_flg;
|
||||
save_s_flg = s_flg;
|
||||
|
||||
int done = 0;
|
||||
c = string[j++] = getchr(); // extra char
|
||||
while (done == 0) {
|
||||
c = string[j++] = getchr();
|
||||
while ((c != '/') && (j < string.length) && EOF == 0) {
|
||||
if(c == '\n' || c == '\r') {
|
||||
lineNumber++;
|
||||
putcoms();
|
||||
s_flg = 1;
|
||||
}
|
||||
c = string[j++] = getchr();
|
||||
}
|
||||
//String tmpstr = new String(string);
|
||||
if (j>1 && string[j-2] == '*') {
|
||||
done = 1;
|
||||
jdoc = 0;
|
||||
} else if (EOF != 0) {
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
|
||||
putcoms();
|
||||
s_flg = save_s_flg;
|
||||
jdoc = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public char get_string() throws IOException {
|
||||
char ch;
|
||||
ch = '*';
|
||||
while (true) {
|
||||
switch (ch) {
|
||||
default:
|
||||
ch = string[j++] = getchr();
|
||||
if (ch == '\\') {
|
||||
string[j++] = getchr();
|
||||
break;
|
||||
}
|
||||
if (ch == '\'' || ch == '"') {
|
||||
cc = string[j++] = getchr();
|
||||
while (cc != ch && EOF == 0) {
|
||||
if (cc == '\\') string[j++] = getchr();
|
||||
cc = string[j++] = getchr();
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (ch == '\n' || ch == '\r') {
|
||||
indent_puts();
|
||||
a_flg = 1;
|
||||
break;
|
||||
} else {
|
||||
return(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void indent_puts() {
|
||||
string[j] = '\0';
|
||||
if (j > 0) {
|
||||
if (s_flg != 0) {
|
||||
if((tabs > 0) && (string[0] != '{') && (a_flg == 1)) {
|
||||
tabs++;
|
||||
}
|
||||
p_tabs();
|
||||
s_flg = 0;
|
||||
if ((tabs > 0) && (string[0] != '{') && (a_flg == 1)) {
|
||||
tabs--;
|
||||
}
|
||||
a_flg = 0;
|
||||
}
|
||||
String j_string = new String(string);
|
||||
strOut.append(j_string.substring(0,j));
|
||||
for (int i=0; i<j; i++) string[i] = '\0';
|
||||
j = 0;
|
||||
|
||||
} else {
|
||||
if (s_flg != 0) {
|
||||
s_flg = 0;
|
||||
a_flg = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//public void fprintf(int outfil, String out_string) {
|
||||
public void fprintf(String out_string) {
|
||||
//int out_len = out_string.length();
|
||||
//String j_string = new String(string);
|
||||
strOut.append(out_string);
|
||||
}
|
||||
|
||||
|
||||
public int grabLines() {
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
|
||||
/* special edition of put string for comment processing */
|
||||
public void putcoms()
|
||||
{
|
||||
int i = 0;
|
||||
int sav_s_flg = s_flg;
|
||||
if(j > 0)
|
||||
{
|
||||
if(s_flg != 0)
|
||||
{
|
||||
p_tabs();
|
||||
s_flg = 0;
|
||||
}
|
||||
string[j] = '\0';
|
||||
i = 0;
|
||||
while (string[i] == ' ' && EOF == 0) i++;
|
||||
if (lookup_com(w_jdoc) == 1) jdoc = 1;
|
||||
String strBuffer = new String(string,0,j);
|
||||
if (string[i] == '/' && string[i+1]=='*')
|
||||
{
|
||||
if ((last_char != ';') && (sav_s_flg==1) )
|
||||
{
|
||||
//fprintf(outfil, strBuffer.substring(i,j));
|
||||
fprintf(strBuffer.substring(i,j));
|
||||
}
|
||||
else
|
||||
{
|
||||
//fprintf(outfil, strBuffer);
|
||||
fprintf(strBuffer);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[i]=='*' || jdoc == 0)
|
||||
//fprintf (outfil, " "+strBuffer.substring(i,j));
|
||||
fprintf (" "+strBuffer.substring(i,j));
|
||||
else
|
||||
//fprintf (outfil, " * "+strBuffer.substring(i,j));
|
||||
fprintf (" * "+strBuffer.substring(i,j));
|
||||
}
|
||||
j = 0;
|
||||
string[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void cpp_comment() throws IOException
|
||||
{
|
||||
c = getchr();
|
||||
while(c != '\n' && c != '\r' && EOF == 0)
|
||||
{
|
||||
string[j++] = c;
|
||||
c = getchr();
|
||||
}
|
||||
lineNumber++;
|
||||
indent_puts();
|
||||
s_flg = 1;
|
||||
}
|
||||
|
||||
|
||||
/* expand indentValue into tabs and spaces */
|
||||
public void p_tabs()
|
||||
{
|
||||
int i,k;
|
||||
|
||||
if (tabs<0) tabs = 0;
|
||||
if (tabs==0) return;
|
||||
i = tabs * indentValue; // calc number of spaces
|
||||
//j = i/8; /* calc number of tab chars */
|
||||
|
||||
for (k=0; k < i; k++) {
|
||||
strOut.append(indentChar);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public char getchr() throws IOException
|
||||
{
|
||||
if((peek < 0) && (last_char != ' ') && (last_char != '\t'))
|
||||
{
|
||||
if((last_char != '\n') && (last_char != '\r'))
|
||||
p_char = last_char;
|
||||
}
|
||||
if(peek > 0) /* char was read previously */
|
||||
{
|
||||
last_char = peekc;
|
||||
peek = -1;
|
||||
}
|
||||
else /* read next char in string */
|
||||
{
|
||||
indexBlock++;
|
||||
if (indexBlock >= lineLength)
|
||||
{
|
||||
for (int ib=0; ib<readCount; ib++) chars[ib] = '\0';
|
||||
|
||||
lineLength = readCount = 0;
|
||||
reader.mark(1);
|
||||
if (reader.read() != -1)
|
||||
{
|
||||
reader.reset(); // back to the mark
|
||||
readCount = reader.read(chars);
|
||||
lineLength = readCount;
|
||||
strBlock = new String(chars);
|
||||
indexBlock = 0;
|
||||
last_char = strBlock.charAt(indexBlock);
|
||||
peek = -1;
|
||||
peekc = '`';
|
||||
}
|
||||
else
|
||||
{
|
||||
EOF = 1;
|
||||
peekc = '\0';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
last_char = strBlock.charAt(indexBlock);
|
||||
}
|
||||
}
|
||||
peek = -1;
|
||||
if (last_char == '\r')
|
||||
{
|
||||
last_char = getchr();
|
||||
}
|
||||
|
||||
return last_char;
|
||||
}
|
||||
|
||||
/* else processing */
|
||||
public void gotelse()
|
||||
{
|
||||
tabs = s_tabs[c_level][if_lev];
|
||||
p_flg[level] = sp_flg[c_level][if_lev];
|
||||
ind[level] = s_ind[c_level][if_lev];
|
||||
if_flg = 1;
|
||||
}
|
||||
|
||||
/* read to new_line */
|
||||
public int getnl() throws IOException
|
||||
{
|
||||
int save_s_flg;
|
||||
save_s_flg = tabs;
|
||||
peekc = getchr();
|
||||
//while ((peekc == '\t' || peekc == ' ') &&
|
||||
// (j < string.length)) {
|
||||
while ((peekc == '\t' || peekc == ' ') && EOF == 0) {
|
||||
string[j++] = peekc;
|
||||
peek = -1;
|
||||
peekc = '`';
|
||||
peekc = getchr();
|
||||
peek = 1;
|
||||
}
|
||||
peek = 1;
|
||||
|
||||
if (peekc == '/')
|
||||
{
|
||||
peek = -1;
|
||||
peekc = '`';
|
||||
peekc = getchr();
|
||||
if (peekc == '*')
|
||||
{
|
||||
string[j++] = '/';
|
||||
string[j++] = '*';
|
||||
peek = -1;
|
||||
peekc = '`';
|
||||
comment();
|
||||
}
|
||||
else if (peekc == '/')
|
||||
{
|
||||
string[j++] = '/';
|
||||
string[j++] = '/';
|
||||
peek = -1;
|
||||
peekc = '`';
|
||||
cpp_comment();
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
string[j++] = '/';
|
||||
peek = 1;
|
||||
}
|
||||
}
|
||||
peekc = getchr();
|
||||
if(peekc == '\n')
|
||||
{
|
||||
lineNumber++;
|
||||
peek = -1;
|
||||
peekc = '`';
|
||||
tabs = save_s_flg;
|
||||
return(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
peek = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int lookup (String keyword)
|
||||
{
|
||||
char r;
|
||||
int l,kk; //,k,i;
|
||||
String j_string = new String(string);
|
||||
|
||||
if (j<1) return (0);
|
||||
kk=0;
|
||||
while(string[kk] == ' ' && EOF == 0)kk++;
|
||||
l=0;
|
||||
l = j_string.indexOf(keyword);
|
||||
if (l<0 || l!=kk)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
r = string[kk+keyword.length()];
|
||||
if(r >= 'a' && r <= 'z') return(0);
|
||||
if(r >= 'A' && r <= 'Z') return(0);
|
||||
if(r >= '0' && r <= '9') return(0);
|
||||
if(r == '_' || r == '&') return(0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
public int lookup_com (String keyword)
|
||||
{
|
||||
//char r;
|
||||
int l,kk; //,k,i;
|
||||
String j_string = new String(string);
|
||||
|
||||
if (j<1) return (0);
|
||||
kk=0;
|
||||
while(string[kk] == ' ' && EOF == 0) kk++;
|
||||
l=0;
|
||||
l = j_string.indexOf(keyword);
|
||||
if (l<0 || l!=kk)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
StringBuffer onechar;
|
||||
|
||||
// Adding an additional newline as a hack around other errors
|
||||
String originalText = editor.getText() + "\n";
|
||||
strOut = new StringBuffer();
|
||||
indentValue = PreferencesData.getInteger("editor.tabs.size");
|
||||
indentChar = new String(" ");
|
||||
|
||||
lineNumber = 0;
|
||||
c_level = if_lev = level = e_flg = paren = 0;
|
||||
a_flg = q_flg = j = tabs = 0;
|
||||
if_flg = peek = -1;
|
||||
peekc = '`';
|
||||
s_flg = 1;
|
||||
jdoc = 0;
|
||||
|
||||
s_level = new int[10];
|
||||
sp_flg = new int[20][10];
|
||||
s_ind = new int[20][10];
|
||||
s_if_lev = new int[10];
|
||||
s_if_flg = new int[10];
|
||||
ind = new int[10];
|
||||
p_flg = new int[10];
|
||||
s_tabs = new int[20][10];
|
||||
|
||||
w_else = new String ("else");
|
||||
w_if_ = new String ("if");
|
||||
w_for = new String ("for");
|
||||
w_ds = new String ("default");
|
||||
w_case = new String ("case");
|
||||
w_cpp_comment = new String ("//");
|
||||
w_jdoc = new String ("/**");
|
||||
line_feed = new String ("\n");
|
||||
|
||||
// read as long as there is something to read
|
||||
EOF = 0; // = 1 set in getchr when EOF
|
||||
|
||||
chars = new char[BLOCK_MAXLEN];
|
||||
string = new char[BLOCK_MAXLEN];
|
||||
try { // the whole process
|
||||
// open for input
|
||||
reader = new CharArrayReader(originalText.toCharArray());
|
||||
|
||||
// add buffering to that InputStream
|
||||
// bin = new BufferedInputStream(in);
|
||||
|
||||
for (int ib = 0; ib < BLOCK_MAXLEN; ib++) chars[ib] = '\0';
|
||||
|
||||
lineLength = readCount = 0;
|
||||
// read up a block - remember how many bytes read
|
||||
readCount = reader.read(chars);
|
||||
strBlock = new String(chars);
|
||||
|
||||
lineLength = readCount;
|
||||
lineNumber = 1;
|
||||
indexBlock = -1;
|
||||
j = 0;
|
||||
while (EOF == 0)
|
||||
{
|
||||
c = getchr();
|
||||
switch(c)
|
||||
{
|
||||
default:
|
||||
string[j++] = c;
|
||||
if(c != ',')
|
||||
{
|
||||
l_char = c;
|
||||
}
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
case '\t':
|
||||
if(lookup(w_else) == 1)
|
||||
{
|
||||
gotelse();
|
||||
if(s_flg == 0 || j > 0)string[j++] = c;
|
||||
indent_puts();
|
||||
s_flg = 0;
|
||||
break;
|
||||
}
|
||||
if(s_flg == 0 || j > 0)string[j++] = c;
|
||||
break;
|
||||
|
||||
case '\r': // <CR> for MS Windows 95
|
||||
case '\n':
|
||||
lineNumber++;
|
||||
if (EOF==1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
//String j_string = new String(string);
|
||||
|
||||
e_flg = lookup(w_else);
|
||||
if(e_flg == 1) gotelse();
|
||||
if (lookup_com(w_cpp_comment) == 1)
|
||||
{
|
||||
if (string[j] == '\n')
|
||||
{
|
||||
string[j] = '\0';
|
||||
j--;
|
||||
}
|
||||
}
|
||||
|
||||
indent_puts();
|
||||
//fprintf(outfil, line_feed);
|
||||
fprintf(line_feed);
|
||||
s_flg = 1;
|
||||
if(e_flg == 1)
|
||||
{
|
||||
p_flg[level]++;
|
||||
tabs++;
|
||||
}
|
||||
else
|
||||
if(p_char == l_char)
|
||||
{
|
||||
a_flg = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case '{':
|
||||
if(lookup(w_else) == 1)gotelse();
|
||||
if (s_if_lev.length == c_level) {
|
||||
s_if_lev = PApplet.expand(s_if_lev);
|
||||
s_if_flg = PApplet.expand(s_if_flg);
|
||||
}
|
||||
s_if_lev[c_level] = if_lev;
|
||||
s_if_flg[c_level] = if_flg;
|
||||
if_lev = if_flg = 0;
|
||||
c_level++;
|
||||
if(s_flg == 1 && p_flg[level] != 0)
|
||||
{
|
||||
p_flg[level]--;
|
||||
tabs--;
|
||||
}
|
||||
string[j++] = c;
|
||||
indent_puts();
|
||||
getnl() ;
|
||||
indent_puts();
|
||||
//fprintf(outfil,"\n");
|
||||
fprintf("\n");
|
||||
tabs++;
|
||||
s_flg = 1;
|
||||
if(p_flg[level] > 0)
|
||||
{
|
||||
ind[level] = 1;
|
||||
level++;
|
||||
s_level[level] = c_level;
|
||||
}
|
||||
break;
|
||||
|
||||
case '}':
|
||||
c_level--;
|
||||
if (c_level < 0)
|
||||
{
|
||||
EOF = 1;
|
||||
//System.out.println("eof b");
|
||||
string[j++] = c;
|
||||
indent_puts();
|
||||
break;
|
||||
}
|
||||
if ((if_lev = s_if_lev[c_level]-1) < 0)
|
||||
if_lev = 0;
|
||||
if_flg = s_if_flg[c_level];
|
||||
indent_puts();
|
||||
tabs--;
|
||||
p_tabs();
|
||||
peekc = getchr();
|
||||
if( peekc == ';')
|
||||
{
|
||||
onechar = new StringBuffer();
|
||||
onechar.append(c); // the }
|
||||
onechar.append(';');
|
||||
//fprintf(outfil, onechar.toString());
|
||||
fprintf(onechar.toString());
|
||||
peek = -1;
|
||||
peekc = '`';
|
||||
}
|
||||
else
|
||||
{
|
||||
onechar = new StringBuffer();
|
||||
onechar.append(c);
|
||||
//fprintf(outfil, onechar.toString());
|
||||
fprintf(onechar.toString());
|
||||
peek = 1;
|
||||
}
|
||||
getnl();
|
||||
indent_puts();
|
||||
//fprintf(outfil,"\n");
|
||||
fprintf("\n");
|
||||
s_flg = 1;
|
||||
if(c_level < s_level[level])
|
||||
if(level > 0) level--;
|
||||
if(ind[level] != 0)
|
||||
{
|
||||
tabs -= p_flg[level];
|
||||
p_flg[level] = 0;
|
||||
ind[level] = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case '"':
|
||||
case '\'':
|
||||
string[j++] = c;
|
||||
cc = getchr();
|
||||
while(cc != c && EOF == 0)
|
||||
{
|
||||
// max. length of line should be 256
|
||||
string[j++] = cc;
|
||||
|
||||
if(cc == '\\')
|
||||
{
|
||||
cc = string[j++] = getchr();
|
||||
}
|
||||
if(cc == '\n')
|
||||
{
|
||||
lineNumber++;
|
||||
indent_puts();
|
||||
s_flg = 1;
|
||||
}
|
||||
cc = getchr();
|
||||
|
||||
}
|
||||
string[j++] = cc;
|
||||
if(getnl() == 1)
|
||||
{
|
||||
l_char = cc;
|
||||
peek = 1;
|
||||
peekc = '\n';
|
||||
}
|
||||
break;
|
||||
|
||||
case ';':
|
||||
string[j++] = c;
|
||||
indent_puts();
|
||||
if(p_flg[level] > 0 && ind[level] == 0)
|
||||
{
|
||||
tabs -= p_flg[level];
|
||||
p_flg[level] = 0;
|
||||
}
|
||||
getnl();
|
||||
indent_puts();
|
||||
//fprintf(outfil,"\n");
|
||||
fprintf("\n");
|
||||
s_flg = 1;
|
||||
if(if_lev > 0)
|
||||
if(if_flg == 1)
|
||||
{
|
||||
if_lev--;
|
||||
if_flg = 0;
|
||||
}
|
||||
else if_lev = 0;
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
string[j++] = c;
|
||||
string[j++] = getchr();
|
||||
break;
|
||||
|
||||
case '?':
|
||||
q_flg = 1;
|
||||
string[j++] = c;
|
||||
break;
|
||||
|
||||
case ':':
|
||||
string[j++] = c;
|
||||
peekc = getchr();
|
||||
if(peekc == ':')
|
||||
{
|
||||
indent_puts();
|
||||
//fprintf (outfil,":");
|
||||
fprintf(":");
|
||||
peek = -1;
|
||||
peekc = '`';
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
//int double_colon = 0;
|
||||
peek = 1;
|
||||
}
|
||||
|
||||
if(q_flg == 1)
|
||||
{
|
||||
q_flg = 0;
|
||||
break;
|
||||
}
|
||||
if(lookup(w_ds) == 0 && lookup(w_case) == 0)
|
||||
{
|
||||
s_flg = 0;
|
||||
indent_puts();
|
||||
}
|
||||
else
|
||||
{
|
||||
tabs--;
|
||||
indent_puts();
|
||||
tabs++;
|
||||
}
|
||||
peekc = getchr();
|
||||
if(peekc == ';')
|
||||
{
|
||||
fprintf(";");
|
||||
peek = -1;
|
||||
peekc = '`';
|
||||
}
|
||||
else
|
||||
{
|
||||
peek = 1;
|
||||
}
|
||||
getnl();
|
||||
indent_puts();
|
||||
fprintf("\n");
|
||||
s_flg = 1;
|
||||
break;
|
||||
|
||||
case '/':
|
||||
string[j++] = c;
|
||||
peekc = getchr();
|
||||
|
||||
if(peekc == '/')
|
||||
{
|
||||
string[j++] = peekc;
|
||||
peekc = '`';
|
||||
peek = -1;
|
||||
cpp_comment();
|
||||
//fprintf(outfil,"\n");
|
||||
fprintf("\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
peek = 1;
|
||||
}
|
||||
|
||||
if(peekc != '*') {
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j > 0) string[j--] = '\0';
|
||||
if (j > 0) indent_puts();
|
||||
string[j++] = '/';
|
||||
string[j++] = '*';
|
||||
peek = -1;
|
||||
peekc = '`';
|
||||
comment();
|
||||
break;
|
||||
}
|
||||
|
||||
case '#':
|
||||
string[j++] = c;
|
||||
cc = getchr();
|
||||
while(cc != '\n' && EOF == 0)
|
||||
{
|
||||
string[j++] = cc;
|
||||
cc = getchr();
|
||||
}
|
||||
string[j++] = cc;
|
||||
s_flg = 0;
|
||||
indent_puts();
|
||||
s_flg = 1;
|
||||
break;
|
||||
|
||||
case ')':
|
||||
paren--;
|
||||
if (paren < 0)
|
||||
{
|
||||
EOF = 1;
|
||||
//System.out.println("eof c");
|
||||
}
|
||||
string[j++] = c;
|
||||
indent_puts();
|
||||
if(getnl() == 1)
|
||||
{
|
||||
peekc = '\n';
|
||||
peek = 1;
|
||||
if(paren != 0)
|
||||
{
|
||||
a_flg = 1;
|
||||
}
|
||||
else if(tabs > 0)
|
||||
{
|
||||
p_flg[level]++;
|
||||
tabs++;
|
||||
ind[level] = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case '(':
|
||||
string[j++] = c;
|
||||
paren++;
|
||||
if ((lookup(w_for) == 1))
|
||||
{
|
||||
c = get_string();
|
||||
while(c != ';' && EOF == 0) c = get_string();
|
||||
ct=0;
|
||||
int for_done = 0;
|
||||
while (for_done == 0 && EOF == 0)
|
||||
{
|
||||
c = get_string();
|
||||
while(c != ')' && EOF == 0)
|
||||
{
|
||||
if(c == '(') ct++;
|
||||
c = get_string();
|
||||
}
|
||||
if(ct != 0)
|
||||
{
|
||||
ct--;
|
||||
}
|
||||
else for_done = 1;
|
||||
} // endwhile for_done
|
||||
paren--;
|
||||
if (paren < 0)
|
||||
{
|
||||
EOF = 1;
|
||||
//System.out.println("eof d");
|
||||
}
|
||||
indent_puts();
|
||||
if(getnl() == 1)
|
||||
{
|
||||
peekc = '\n';
|
||||
peek = 1;
|
||||
p_flg[level]++;
|
||||
tabs++;
|
||||
ind[level] = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(lookup(w_if_) == 1)
|
||||
{
|
||||
indent_puts();
|
||||
s_tabs[c_level][if_lev] = tabs;
|
||||
sp_flg[c_level][if_lev] = p_flg[level];
|
||||
s_ind[c_level][if_lev] = ind[level];
|
||||
if_lev++;
|
||||
if_flg = 1;
|
||||
}
|
||||
} // end switch
|
||||
|
||||
//System.out.println("string len is " + string.length);
|
||||
//if (EOF == 1) System.out.println(string);
|
||||
//String j_string = new String(string);
|
||||
|
||||
} // end while not EOF
|
||||
|
||||
/*
|
||||
int bad;
|
||||
while ((bad = bin.read()) != -1) {
|
||||
System.out.print((char) bad);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
char bad;
|
||||
//while ((bad = getchr()) != 0) {
|
||||
while (true) {
|
||||
getchr();
|
||||
if (peek != -1) {
|
||||
System.out.print(last_char);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// save current (rough) selection point
|
||||
int selectionEnd = editor.getSelectionStop();
|
||||
|
||||
// make sure the caret would be past the end of the text
|
||||
if (strOut.length() < selectionEnd - 1) {
|
||||
selectionEnd = strOut.length() - 1;
|
||||
}
|
||||
|
||||
reader.close(); // close buff
|
||||
|
||||
String formattedText = strOut.toString();
|
||||
if (formattedText.equals(originalText)) {
|
||||
editor.statusNotice(_("No changes necessary for Auto Format."));
|
||||
|
||||
} else if (paren != 0) {
|
||||
// warn user if there are too many parens in either direction
|
||||
if (paren < 0) {
|
||||
editor.statusError(
|
||||
_("Auto Format Canceled: Too many right parentheses."));
|
||||
} else {
|
||||
editor.statusError(
|
||||
_("Auto Format Canceled: Too many left parentheses."));
|
||||
}
|
||||
|
||||
} else if (c_level != 0) { // check braces only if parens are ok
|
||||
if (c_level < 0) {
|
||||
editor.statusError(
|
||||
_("Auto Format Canceled: Too many right curly braces."));
|
||||
} else {
|
||||
editor.statusError(
|
||||
_("Auto Format Canceled: Too many left curly braces."));
|
||||
}
|
||||
|
||||
} else {
|
||||
// replace with new bootiful text
|
||||
// selectionEnd hopefully at least in the neighborhood
|
||||
editor.setText(formattedText);
|
||||
editor.setSelection(selectionEnd, selectionEnd);
|
||||
editor.getSketch().setModified(true);
|
||||
// mark as finished
|
||||
editor.statusNotice(_("Auto Format finished."));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
editor.statusError(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -29,6 +29,7 @@ import java.io.IOException;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.*;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@ -83,16 +84,19 @@ public class FixEncoding implements Tool {
|
||||
|
||||
protected String loadWithLocalEncoding(File file) throws IOException {
|
||||
// FileReader uses the default encoding, which is what we want.
|
||||
FileReader fr = new FileReader(file);
|
||||
BufferedReader reader = new BufferedReader(fr);
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(file));
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String line = null;
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
buffer.append(line);
|
||||
buffer.append('\n');
|
||||
}
|
||||
reader.close();
|
||||
return buffer.toString();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,43 +3,31 @@
|
||||
*/
|
||||
package processing.app.tools;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
|
||||
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.ButtonUI;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
* <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>
|
||||
* <p/>
|
||||
*
|
||||
* @version 1.5.0 04/05/12
|
||||
* @author Darryl
|
||||
* @version 1.5.0 04/05/12
|
||||
*/
|
||||
public class MenuScroller {
|
||||
|
||||
//private JMenu menu;
|
||||
private JPopupMenu menu;
|
||||
private Component[] menuItems;
|
||||
private MenuScrollItem upItem;
|
||||
@ -53,25 +41,6 @@ public class MenuScroller {
|
||||
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.
|
||||
@ -159,9 +128,9 @@ public class MenuScroller {
|
||||
* @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
|
||||
* @return the MenuScroller
|
||||
* @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) {
|
||||
@ -180,9 +149,9 @@ public class MenuScroller {
|
||||
* @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
|
||||
* @return the MenuScroller
|
||||
* @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) {
|
||||
@ -198,7 +167,7 @@ public class MenuScroller {
|
||||
* @param menu the menu
|
||||
*/
|
||||
public MenuScroller(JMenu menu) {
|
||||
this(menu, -1);
|
||||
this(menu, 15);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -209,7 +178,7 @@ public class MenuScroller {
|
||||
* @param menu the popup menu
|
||||
*/
|
||||
public MenuScroller(JPopupMenu menu) {
|
||||
this(menu, -1);
|
||||
this(menu, 15);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -302,11 +271,10 @@ public class MenuScroller {
|
||||
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
|
||||
int autoSizeScrollCount = getMaximumDrawableMenuItems();
|
||||
if (autoSizeScrollCount > scrollCount) {
|
||||
scrollCount = autoSizeScrollCount;
|
||||
}
|
||||
|
||||
if (scrollCount <= 0 || interval <= 0) {
|
||||
throw new IllegalArgumentException("scrollCount and interval must be greater than 0");
|
||||
@ -427,8 +395,7 @@ public class MenuScroller {
|
||||
if (item == null) {
|
||||
keepVisibleIndex = -1;
|
||||
} else {
|
||||
int index = menu.getComponentIndex(item);
|
||||
keepVisibleIndex = index;
|
||||
keepVisibleIndex = menu.getComponentIndex(item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -460,27 +427,19 @@ public class MenuScroller {
|
||||
* 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.
|
||||
* @throws Throwable if an error occurs.
|
||||
* @see MenuScroller#dispose()
|
||||
*/
|
||||
@Override
|
||||
public void finalize() throws Throwable {
|
||||
super.finalize();
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void refreshMenu() {
|
||||
if (menuItems == null || menuItems.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int newFirstIndex = Math.max(topFixedCount, firstIndex);
|
||||
newFirstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, newFirstIndex);
|
||||
|
||||
if (newFirstIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
firstIndex = newFirstIndex;
|
||||
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);
|
||||
@ -489,9 +448,9 @@ public class MenuScroller {
|
||||
for (int i = 0; i < topFixedCount; i++) {
|
||||
menu.add(menuItems[i]);
|
||||
}
|
||||
/*if (topFixedCount > 0) {
|
||||
if (topFixedCount > 0) {
|
||||
menu.addSeparator();
|
||||
}*/
|
||||
}
|
||||
|
||||
menu.add(upItem);
|
||||
for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
|
||||
@ -499,9 +458,9 @@ public class MenuScroller {
|
||||
}
|
||||
menu.add(downItem);
|
||||
|
||||
/*if (bottomFixedCount > 0) {
|
||||
if (bottomFixedCount > 0) {
|
||||
menu.addSeparator();
|
||||
}*/
|
||||
}
|
||||
for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
|
||||
menu.add(menuItems[i]);
|
||||
}
|
||||
@ -510,6 +469,22 @@ public class MenuScroller {
|
||||
parent.revalidate();
|
||||
parent.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private int getMaximumDrawableMenuItems() {
|
||||
JMenuItem test = new JMenuItem("test");
|
||||
double itemHeight = test.getUI().getPreferredSize(test).getHeight();
|
||||
|
||||
JMenuItem arrowMenuItem = new JMenuItem(MenuIcon.UP);
|
||||
double arrowMenuItemHeight = arrowMenuItem.getUI().getPreferredSize(arrowMenuItem).getHeight();
|
||||
|
||||
double menuBorderHeight = 8.0; // kludge - how to detect this?
|
||||
double screenHeight = java.awt.Toolkit.getDefaultToolkit().getScreenSize().getHeight();
|
||||
|
||||
int maxItems = (int) ((screenHeight - arrowMenuItemHeight * 2 - menuBorderHeight) / itemHeight);
|
||||
maxItems -= maxItems / 4;
|
||||
return maxItems;
|
||||
}
|
||||
|
||||
private class MouseScrollListener implements MouseWheelListener {
|
||||
public void mouseWheelMoved(MouseWheelEvent mwe) {
|
||||
@ -538,25 +513,6 @@ public class MenuScroller {
|
||||
|
||||
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
|
||||
@ -577,7 +533,6 @@ public class MenuScroller {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private class MenuScrollTimer extends Timer {
|
||||
|
||||
public MenuScrollTimer(final int increment, int interval) {
|
||||
@ -592,11 +547,10 @@ public class MenuScroller {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private class MenuScrollItem extends JMenuItem
|
||||
implements ChangeListener {
|
||||
|
||||
private MenuScrollTimer timer;
|
||||
private final MenuScrollTimer timer;
|
||||
|
||||
public MenuScrollItem(MenuIcon icon, int increment) {
|
||||
setIcon(icon);
|
||||
@ -620,7 +574,7 @@ public class MenuScroller {
|
||||
}
|
||||
}
|
||||
|
||||
private static enum MenuIcon implements Icon {
|
||||
private enum MenuIcon implements Icon {
|
||||
|
||||
UP(9, 1, 9),
|
||||
DOWN(1, 9, 1);
|
||||
|
@ -10,6 +10,7 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipException;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
public class ZipDeflater {
|
||||
@ -54,12 +55,8 @@ public class ZipDeflater {
|
||||
fos.write(buffer, 0, len);
|
||||
}
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
if (zipInputStream != null) {
|
||||
zipInputStream.close();
|
||||
}
|
||||
IOUtils.closeQuietly(fos);
|
||||
IOUtils.closeQuietly(zipInputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.contributions.libraries.LibrariesIndex;
|
||||
import cc.arduino.utils.MultiStepProgress;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class GzippedJsonDownloaderTest {
|
||||
|
||||
private File tempFolder;
|
||||
private File tempFile;
|
||||
private DownloadableContributionsDownloader downloader;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
tempFolder = FileUtils.createTempFolder();
|
||||
tempFile = File.createTempFile("test", ".json");
|
||||
downloader = new DownloadableContributionsDownloader(tempFolder);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
FileUtils.recursiveDelete(tempFolder);
|
||||
FileUtils.recursiveDelete(tempFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonDownload() throws Exception {
|
||||
new GZippedJsonDownloader(downloader, new URL("http://downloads.arduino.cc/libraries/library_index.json"), new URL("http://downloads.arduino.cc/libraries/library_index.json.gz")).download(tempFile, new MultiStepProgress(1), "");
|
||||
|
||||
InputStream indexIn = new FileInputStream(tempFile);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(new MrBeanModule());
|
||||
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||
mapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true);
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
LibrariesIndex librariesIndex = mapper.readValue(indexIn, LibrariesIndex.class);
|
||||
|
||||
assertTrue(librariesIndex != null);
|
||||
}
|
||||
}
|
53
app/test/cc/arduino/contributions/JsonDownloaderTest.java
Normal file
53
app/test/cc/arduino/contributions/JsonDownloaderTest.java
Normal file
@ -0,0 +1,53 @@
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.contributions.libraries.LibrariesIndex;
|
||||
import cc.arduino.utils.MultiStepProgress;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class JsonDownloaderTest {
|
||||
|
||||
private File tempFolder;
|
||||
private File tempFile;
|
||||
private DownloadableContributionsDownloader downloader;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
tempFolder = FileUtils.createTempFolder();
|
||||
tempFile = File.createTempFile("test", ".json");
|
||||
downloader = new DownloadableContributionsDownloader(tempFolder);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
FileUtils.recursiveDelete(tempFolder);
|
||||
FileUtils.recursiveDelete(tempFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonDownload() throws Exception {
|
||||
new JsonDownloader(downloader, new URL("http://downloads.arduino.cc/libraries/library_index.json")).download(tempFile, new MultiStepProgress(1), "");
|
||||
|
||||
InputStream indexIn = new FileInputStream(tempFile);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(new MrBeanModule());
|
||||
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||
mapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true);
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
LibrariesIndex librariesIndex = mapper.readValue(indexIn, LibrariesIndex.class);
|
||||
|
||||
assertTrue(librariesIndex != null);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package cc.arduino.contributions.libraries;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class LibraryOfTypeComparatorTest {
|
||||
|
||||
@Test
|
||||
public void testSort() throws Exception {
|
||||
List<String> strings = Arrays.asList("Arduino", "Contributed", "Recommended", "Recommended", "Other", "1yetanother", "Arduino", "Recommended", "Contributed", "Recommended");
|
||||
Collections.sort(strings, new LibraryTypeComparator());
|
||||
assertEquals(Arrays.asList("Arduino", "Arduino", "Recommended", "Recommended", "Recommended", "Recommended", "Contributed", "Contributed", "1yetanother", "Other"), strings);
|
||||
}
|
||||
}
|
@ -50,12 +50,13 @@ public abstract class AbstractGUITest {
|
||||
|
||||
FailOnThreadViolationRepaintManager.install();
|
||||
|
||||
Base.initPlatform();
|
||||
Preferences.init(null);
|
||||
BaseNoGui.initPlatform();
|
||||
BaseNoGui.getPlatform().init();
|
||||
PreferencesData.init(null);
|
||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
||||
Theme.init();
|
||||
Base.getPlatform().setLookAndFeel();
|
||||
Base.untitledFolder = Base.createTempFolder("untitled");
|
||||
BaseNoGui.getPlatform().setLookAndFeel();
|
||||
Base.untitledFolder = BaseNoGui.createTempFolder("untitled");
|
||||
DeleteFilesOnShutdown.add(Base.untitledFolder);
|
||||
|
||||
window = GuiActionRunner.execute(new GuiQuery<ArduinoFrameFixture>() {
|
||||
|
@ -37,14 +37,14 @@ public abstract class AbstractWithPreferencesTest {
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(DeleteFilesOnShutdown.INSTANCE));
|
||||
Base.initPlatform();
|
||||
Base.getPlatform().init();
|
||||
Preferences.init(null);
|
||||
BaseNoGui.initPlatform();
|
||||
BaseNoGui.getPlatform().init();
|
||||
PreferencesData.init(null);
|
||||
Theme.init();
|
||||
|
||||
BaseNoGui.initPackages();
|
||||
|
||||
Base.untitledFolder = Base.createTempFolder("untitled");
|
||||
Base.untitledFolder = BaseNoGui.createTempFolder("untitled");
|
||||
DeleteFilesOnShutdown.add(Base.untitledFolder);
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
package processing.app;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -63,9 +64,7 @@ public class I18NTest {
|
||||
is = new FileInputStream(file);
|
||||
properties.load(is);
|
||||
} finally {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
@ -74,5 +74,9 @@ public class SystemProfilerParserTest {
|
||||
assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem24131"));
|
||||
assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbserial-DN0031EV"));
|
||||
assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbserial-DN0031EV"));
|
||||
|
||||
output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output8.txt"));
|
||||
|
||||
assertEquals("0X03EB_0X2157", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd132"));
|
||||
}
|
||||
}
|
||||
|
96
app/test/processing/app/macosx/system_profiler_output8.txt
Normal file
96
app/test/processing/app/macosx/system_profiler_output8.txt
Normal file
@ -0,0 +1,96 @@
|
||||
USB:
|
||||
|
||||
USB Hi-Speed Bus:
|
||||
|
||||
Host Controller Location: Built-in USB
|
||||
Host Controller Driver: AppleUSBEHCI
|
||||
PCI Device ID: 0x1c2d
|
||||
PCI Revision ID: 0x0005
|
||||
PCI Vendor ID: 0x8086
|
||||
Bus Number: 0xfa
|
||||
|
||||
Hub:
|
||||
|
||||
Product ID: 0x2513
|
||||
Vendor ID: 0x0424 (SMSC)
|
||||
Version: b.b3
|
||||
Speed: Up to 480 Mb/sec
|
||||
Location ID: 0xfa100000 / 2
|
||||
Current Available (mA): 500
|
||||
Current Required (mA): 2
|
||||
|
||||
Arduino Leonardo:
|
||||
|
||||
Product ID: 0x8036
|
||||
Vendor ID: 0x2341
|
||||
Version: 1.00
|
||||
Speed: Up to 12 Mb/sec
|
||||
Manufacturer: Arduino LLC
|
||||
Location ID: 0xfa120000 / 5
|
||||
Current Available (mA): 500
|
||||
Current Required (mA): 500
|
||||
|
||||
BRCM20702 Hub:
|
||||
|
||||
Product ID: 0x4500
|
||||
Vendor ID: 0x0a5c (Broadcom Corp.)
|
||||
Version: 1.00
|
||||
Speed: Up to 12 Mb/sec
|
||||
Manufacturer: Apple Inc.
|
||||
Location ID: 0xfa110000 / 3
|
||||
Current Available (mA): 500
|
||||
Current Required (mA): 94
|
||||
|
||||
Bluetooth USB Host Controller:
|
||||
|
||||
Product ID: 0x8281
|
||||
Vendor ID: 0x05ac (Apple Inc.)
|
||||
Version: 1.25
|
||||
Speed: Up to 12 Mb/sec
|
||||
Manufacturer: Apple Inc.
|
||||
Location ID: 0xfa113000 / 4
|
||||
Current Available (mA): 500
|
||||
Current Required (mA): 0
|
||||
|
||||
USB Hi-Speed Bus:
|
||||
|
||||
Host Controller Location: Built-in USB
|
||||
Host Controller Driver: AppleUSBEHCI
|
||||
PCI Device ID: 0x1c26
|
||||
PCI Revision ID: 0x0005
|
||||
PCI Vendor ID: 0x8086
|
||||
Bus Number: 0xfd
|
||||
|
||||
Hub:
|
||||
|
||||
Product ID: 0x2513
|
||||
Vendor ID: 0x0424 (SMSC)
|
||||
Version: b.b3
|
||||
Speed: Up to 480 Mb/sec
|
||||
Location ID: 0xfd100000 / 2
|
||||
Current Available (mA): 500
|
||||
Current Required (mA): 2
|
||||
|
||||
EDBG CMSIS-DAP:
|
||||
|
||||
Product ID: 0x2157
|
||||
Vendor ID: 0x03eb (Atmel Corporation)
|
||||
Version: 1.01
|
||||
Serial Number: 00000000AZE000000310
|
||||
Speed: Up to 480 Mb/sec
|
||||
Manufacturer: Atmel Corp.
|
||||
Location ID: 0xfd130000 / 4
|
||||
Current Available (mA): 500
|
||||
Current Required (mA): 500
|
||||
|
||||
IR Receiver:
|
||||
|
||||
Product ID: 0x8242
|
||||
Vendor ID: 0x05ac (Apple Inc.)
|
||||
Version: 0.16
|
||||
Speed: Up to 1.5 Mb/sec
|
||||
Manufacturer: Apple Computer, Inc.
|
||||
Location ID: 0xfd110000 / 3
|
||||
Current Available (mA): 500
|
||||
Current Required (mA): 100
|
||||
|
42
app/test/processing/app/windows/RegQueryParserTest.java
Normal file
42
app/test/processing/app/windows/RegQueryParserTest.java
Normal file
@ -0,0 +1,42 @@
|
||||
package processing.app.windows;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class RegQueryParserTest {
|
||||
|
||||
@Test
|
||||
public void testRegQueryParser() throws Exception {
|
||||
String output = "! REG.EXE VERSION 3.0\n" +
|
||||
"\n" +
|
||||
"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\n" +
|
||||
"\n" +
|
||||
" Local AppData REG_SZ C:\\Documents and Settings\\username\\My Documents";
|
||||
|
||||
String folderPath = new RegQueryParser(output).getValueOfKey();
|
||||
assertEquals("C:\\Documents and Settings\\username\\My Documents", folderPath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegQueryParser2() throws Exception {
|
||||
String output = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\n" +
|
||||
" Local AppData REG_SZ C:\\Users\\username\\AppData\\Local";
|
||||
|
||||
String folderPath = new RegQueryParser(output).getValueOfKey();
|
||||
assertEquals("C:\\Users\\username\\AppData\\Local", folderPath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegQueryParserXP() throws Exception {
|
||||
String output = "! REG.EXE VERSION 3.0\n" +
|
||||
"\n" +
|
||||
"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\n" +
|
||||
"\n" +
|
||||
"\tLocal AppData REG_SZ C:\\Documents and Settings\\username\\My Documents";
|
||||
|
||||
String folderPath = new RegQueryParser(output).getValueOfKey();
|
||||
assertEquals("C:\\Documents and Settings\\username\\My Documents", folderPath);
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,6 @@
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="lib/jna.jar"/>
|
||||
<classpathentry kind="lib" path="lib/apple.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-logging-1.0.4.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jmdns-3.4.1.jar"/>
|
||||
|
@ -31,8 +31,8 @@
|
||||
<property environment="env" />
|
||||
<property name="java_home" value="${env.JAVA_HOME}" />
|
||||
|
||||
<javac source="1.6"
|
||||
target="1.6"
|
||||
<javac source="1.8"
|
||||
target="1.8"
|
||||
encoding="UTF-8"
|
||||
includeAntRuntime="false"
|
||||
srcdir="src"
|
||||
|
@ -1 +0,0 @@
|
||||
https://github.com/twall/jna/blob/master/LICENSE
|
Binary file not shown.
107
arduino-core/src/cc/arduino/MyStreamPumper.java
Normal file
107
arduino-core/src/cc/arduino/MyStreamPumper.java
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino;
|
||||
|
||||
import processing.app.debug.MessageConsumer;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* A version of StreamPumper from commons-exec that write to a MessageConsumer
|
||||
*/
|
||||
public class MyStreamPumper implements Runnable {
|
||||
|
||||
/**
|
||||
* the input stream to pump from
|
||||
*/
|
||||
private final BufferedReader reader;
|
||||
|
||||
/**
|
||||
* the output stream to pmp into
|
||||
*/
|
||||
private final MessageConsumer messageConsumer;
|
||||
|
||||
/**
|
||||
* was the end of the stream reached
|
||||
*/
|
||||
private boolean finished;
|
||||
|
||||
public MyStreamPumper(final InputStream is, final MessageConsumer messageConsumer) {
|
||||
this.reader = new BufferedReader(new InputStreamReader(is));
|
||||
this.messageConsumer = messageConsumer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies data from the input stream to the output stream. Terminates as
|
||||
* soon as the input stream is closed or an error occurs.
|
||||
*/
|
||||
public void run() {
|
||||
synchronized (this) {
|
||||
// Just in case this object is reused in the future
|
||||
finished = false;
|
||||
}
|
||||
|
||||
try {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
messageConsumer.message(line + "\n");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// nothing to do - happens quite often with watchdog
|
||||
} finally {
|
||||
synchronized (this) {
|
||||
finished = true;
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the end of the stream has been reached.
|
||||
*
|
||||
* @return true is the stream has been exhausted.
|
||||
*/
|
||||
public synchronized boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method blocks until the stream pumper finishes.
|
||||
*
|
||||
* @see #isFinished()
|
||||
*/
|
||||
public synchronized void waitFor() throws InterruptedException {
|
||||
while (!isFinished()) {
|
||||
wait();
|
||||
}
|
||||
}
|
||||
}
|
@ -26,9 +26,9 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import cc.arduino.contributions.VersionHelper;
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import com.github.zafarkhaja.semver.Version;
|
||||
|
||||
import java.io.File;
|
@ -29,8 +29,6 @@
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class DownloadableContributionBuiltInAtTheBottomComparator implements Comparator<DownloadableContribution> {
|
||||
|
@ -29,8 +29,6 @@
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class DownloadableContributionVersionComparator implements Comparator<DownloadableContribution> {
|
||||
|
@ -26,7 +26,8 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.utils.FileHash;
|
||||
import cc.arduino.utils.Progress;
|
@ -77,12 +77,8 @@ public class GPGDetachedSignatureVerifier {
|
||||
|
||||
return pgpSignature.verify();
|
||||
} finally {
|
||||
if (signatureInputStream != null) {
|
||||
signatureInputStream.close();
|
||||
}
|
||||
if (signedFileInputStream != null) {
|
||||
signedFileInputStream.close();
|
||||
}
|
||||
IOUtils.closeQuietly(signatureInputStream);
|
||||
IOUtils.closeQuietly(signedFileInputStream);
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,9 +88,7 @@ public class GPGDetachedSignatureVerifier {
|
||||
keyIn = new BufferedInputStream(new FileInputStream(file));
|
||||
return readPublicKey(keyIn, keyId);
|
||||
} finally {
|
||||
if (keyIn != null) {
|
||||
keyIn.close();
|
||||
}
|
||||
IOUtils.closeQuietly(keyIn);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.utils.Progress;
|
||||
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
|
||||
import org.apache.commons.compress.compressors.gzip.GzipUtils;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
|
||||
public class GZippedJsonDownloader {
|
||||
|
||||
private final DownloadableContributionsDownloader downloader;
|
||||
private final URL url;
|
||||
private final URL gzippedUrl;
|
||||
|
||||
public GZippedJsonDownloader(DownloadableContributionsDownloader downloader, URL url, URL gzippedUrl) {
|
||||
this.downloader = downloader;
|
||||
this.url = url;
|
||||
this.gzippedUrl = gzippedUrl;
|
||||
}
|
||||
|
||||
public void download(File tmpFile, Progress progress, String statusText) throws Exception {
|
||||
try {
|
||||
new JsonDownloader(downloader, gzippedUrl).download(tmpFile, progress, statusText);
|
||||
File gzipTmpFile = new File(tmpFile.getParentFile(), GzipUtils.getCompressedFilename(tmpFile.getName()));
|
||||
tmpFile.renameTo(gzipTmpFile);
|
||||
decompress(gzipTmpFile, tmpFile);
|
||||
} catch (Exception e) {
|
||||
new JsonDownloader(downloader, url).download(tmpFile, progress, statusText);
|
||||
}
|
||||
}
|
||||
|
||||
private void decompress(File gzipTmpFile, File tmpFile) throws IOException {
|
||||
OutputStream os = null;
|
||||
GzipCompressorInputStream gzipIs = null;
|
||||
try {
|
||||
os = new FileOutputStream(tmpFile);
|
||||
gzipIs = new GzipCompressorInputStream(new FileInputStream(gzipTmpFile));
|
||||
final byte[] buffer = new byte[4096];
|
||||
int n = 0;
|
||||
while (-1 != (n = gzipIs.read(buffer))) {
|
||||
os.write(buffer, 0, n);
|
||||
}
|
||||
} finally {
|
||||
IOUtils.closeQuietly(os);
|
||||
IOUtils.closeQuietly(gzipIs);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.utils.Progress;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
public class JsonDownloader {
|
||||
|
||||
private final DownloadableContributionsDownloader downloader;
|
||||
private final URL url;
|
||||
|
||||
public JsonDownloader(DownloadableContributionsDownloader downloader, URL url) {
|
||||
this.downloader = downloader;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public void download(File tmpFile, Progress progress, String statusText) throws Exception {
|
||||
try {
|
||||
downloader.download(url, tmpFile, progress, statusText);
|
||||
} catch (InterruptedException e) {
|
||||
// Download interrupted... just exit
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import processing.app.I18n;
|
||||
|
@ -26,6 +26,7 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import com.github.zafarkhaja.semver.Version;
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
package cc.arduino.contributions.filters;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
public class BuiltInPredicate implements Predicate<DownloadableContribution> {
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
package cc.arduino.contributions.filters;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
public class DownloadableContributionWithVersionPredicate implements Predicate<DownloadableContribution> {
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
package cc.arduino.contributions.filters;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
public class InstalledPredicate implements Predicate<DownloadableContribution> {
|
||||
|
@ -26,9 +26,10 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import processing.app.I18n;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
@ -26,6 +26,7 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries;
|
||||
|
||||
public abstract class ContributedLibraryReference {
|
||||
|
@ -26,11 +26,19 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries;
|
||||
|
||||
import cc.arduino.contributions.libraries.filters.LibraryInstalledInsideCore;
|
||||
import cc.arduino.contributions.libraries.filters.TypePredicate;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.helpers.FileUtils;
|
||||
@ -43,6 +51,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@ -50,6 +59,7 @@ import static processing.app.I18n._;
|
||||
|
||||
public class LibrariesIndexer {
|
||||
|
||||
private final ContributionsIndexer contributionsIndexer;
|
||||
private LibrariesIndex index;
|
||||
private final LibraryList installedLibraries = new LibraryList();
|
||||
private final LibraryList installedLibrariesWithDuplicates = new LibraryList();
|
||||
@ -58,10 +68,12 @@ public class LibrariesIndexer {
|
||||
private final File stagingFolder;
|
||||
private File sketchbookLibrariesFolder;
|
||||
|
||||
public LibrariesIndexer(File preferencesFolder) {
|
||||
indexFile = new File(preferencesFolder, "library_index.json");
|
||||
stagingFolder = new File(preferencesFolder, "staging" + File.separator +
|
||||
"libraries");
|
||||
private final List<String> badLibNotified = new ArrayList<String>();
|
||||
|
||||
public LibrariesIndexer(File preferencesFolder, ContributionsIndexer contributionsIndexer) {
|
||||
this.contributionsIndexer = contributionsIndexer;
|
||||
this.indexFile = new File(preferencesFolder, "library_index.json");
|
||||
this.stagingFolder = new File(new File(preferencesFolder, "staging"), "libraries");
|
||||
}
|
||||
|
||||
public void parseIndex() throws IOException {
|
||||
@ -86,9 +98,7 @@ public class LibrariesIndexer {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (indexIn != null) {
|
||||
indexIn.close();
|
||||
}
|
||||
IOUtils.closeQuietly(indexIn);
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,14 +111,25 @@ public class LibrariesIndexer {
|
||||
// Clear all installed flags
|
||||
installedLibraries.clear();
|
||||
installedLibrariesWithDuplicates.clear();
|
||||
for (ContributedLibrary lib : index.getLibraries())
|
||||
for (ContributedLibrary lib : index.getLibraries()) {
|
||||
lib.setInstalled(false);
|
||||
}
|
||||
|
||||
// Rescan libraries
|
||||
for (File folder : librariesFolders)
|
||||
for (File folder : librariesFolders) {
|
||||
scanInstalledLibraries(folder, folder.equals(sketchbookLibrariesFolder));
|
||||
}
|
||||
|
||||
FluentIterable.from(installedLibraries).filter(new TypePredicate("Contributed")).filter(new LibraryInstalledInsideCore(contributionsIndexer)).transform(new Function<UserLibrary, Object>() {
|
||||
@Override
|
||||
public Object apply(UserLibrary userLibrary) {
|
||||
ContributedPlatform platform = contributionsIndexer.getPlatformByFolder(userLibrary.getInstalledFolder());
|
||||
userLibrary.setTypes(Arrays.asList(platform.getCategory()));
|
||||
return userLibrary;
|
||||
}
|
||||
}).toList();
|
||||
}
|
||||
|
||||
private void scanInstalledLibraries(File folder, boolean isSketchbook) {
|
||||
File list[] = folder.listFiles(OnlyDirs.ONLY_DIRS);
|
||||
// if a bad folder or something like that, this might come back null
|
||||
@ -117,11 +138,18 @@ public class LibrariesIndexer {
|
||||
|
||||
for (File subfolder : list) {
|
||||
if (!BaseNoGui.isSanitaryName(subfolder.getName())) {
|
||||
|
||||
// Detect whether the current folder name has already had a notification.
|
||||
if(!badLibNotified.contains(subfolder.getName())) {
|
||||
|
||||
badLibNotified.add(subfolder.getName());
|
||||
|
||||
String mess = I18n.format(_("The library \"{0}\" cannot be used.\n"
|
||||
+ "Library names must contain only basic letters and numbers.\n"
|
||||
+ "(ASCII only and no spaces, and it cannot start with a number)"),
|
||||
subfolder.getName());
|
||||
BaseNoGui.showMessage(_("Ignoring bad library name"), mess);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -26,14 +26,16 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContributionsDownloader;
|
||||
import cc.arduino.contributions.DownloadableContributionsDownloader;
|
||||
import cc.arduino.contributions.GZippedJsonDownloader;
|
||||
import cc.arduino.utils.ArchiveExtractor;
|
||||
import cc.arduino.utils.MultiStepProgress;
|
||||
import cc.arduino.utils.Progress;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.Platform;
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
@ -45,6 +47,7 @@ import static processing.app.I18n._;
|
||||
public class LibraryInstaller {
|
||||
|
||||
private static final String LIBRARY_INDEX_URL;
|
||||
private static final String LIBRARY_INDEX_URL_GZ;
|
||||
|
||||
static {
|
||||
String externalLibraryIndexUrl = System.getProperty("LIBRARY_INDEX_URL");
|
||||
@ -53,14 +56,17 @@ public class LibraryInstaller {
|
||||
} else {
|
||||
LIBRARY_INDEX_URL = "http://downloads.arduino.cc/libraries/library_index.json";
|
||||
}
|
||||
LIBRARY_INDEX_URL_GZ = "http://downloads.arduino.cc/libraries/library_index.json.gz";
|
||||
}
|
||||
|
||||
private final LibrariesIndexer indexer;
|
||||
private final DownloadableContributionsDownloader downloader;
|
||||
private final Platform platform;
|
||||
|
||||
public LibraryInstaller(LibrariesIndexer _indexer) {
|
||||
indexer = _indexer;
|
||||
File stagingFolder = _indexer.getStagingFolder();
|
||||
public LibraryInstaller(LibrariesIndexer indexer, Platform platform) {
|
||||
this.indexer = indexer;
|
||||
this.platform = platform;
|
||||
File stagingFolder = indexer.getStagingFolder();
|
||||
downloader = new DownloadableContributionsDownloader(stagingFolder) {
|
||||
@Override
|
||||
protected void onProgress(Progress progress) {
|
||||
@ -77,8 +83,8 @@ public class LibraryInstaller {
|
||||
File outputFile = indexer.getIndexFile();
|
||||
File tmpFile = new File(outputFile.getAbsolutePath() + ".tmp");
|
||||
try {
|
||||
downloader.download(url, tmpFile, progress,
|
||||
_("Downloading libraries index..."));
|
||||
GZippedJsonDownloader gZippedJsonDownloader = new GZippedJsonDownloader(downloader, new URL(LIBRARY_INDEX_URL), new URL(LIBRARY_INDEX_URL_GZ));
|
||||
gZippedJsonDownloader.download(tmpFile, progress, _("Downloading libraries index..."));
|
||||
} catch (InterruptedException e) {
|
||||
// Download interrupted... just exit
|
||||
return;
|
||||
@ -91,8 +97,7 @@ public class LibraryInstaller {
|
||||
if (outputFile.exists())
|
||||
outputFile.delete();
|
||||
if (!tmpFile.renameTo(outputFile))
|
||||
throw new Exception(
|
||||
_("An error occurred while updating libraries index!"));
|
||||
throw new Exception(_("An error occurred while updating libraries index!"));
|
||||
|
||||
// Step 2: Rescan index
|
||||
rescanLibraryIndex(progress);
|
||||
@ -124,7 +129,7 @@ public class LibraryInstaller {
|
||||
File libsFolder = indexer.getSketchbookLibrariesFolder();
|
||||
File tmpFolder = FileUtils.createTempFolderIn(libsFolder);
|
||||
try {
|
||||
new ArchiveExtractor(BaseNoGui.getPlatform()).extract(lib.getDownloadedFile(), tmpFolder, 1);
|
||||
new ArchiveExtractor(platform).extract(lib.getDownloadedFile(), tmpFolder, 1);
|
||||
} catch (Exception e) {
|
||||
if (tmpFolder.exists())
|
||||
FileUtils.recursiveDelete(tmpFolder);
|
||||
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries.filters;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
public class LibraryInstalledInsideCore implements Predicate<ContributedLibrary> {
|
||||
|
||||
private final ContributionsIndexer indexer;
|
||||
|
||||
public LibraryInstalledInsideCore(ContributionsIndexer indexer) {
|
||||
this.indexer = indexer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedLibrary contributedLibrary) {
|
||||
return indexer.isFolderInsidePlatform(contributedLibrary.getInstalledFolder());
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -26,6 +26,7 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
public interface ContributedBoard {
|
||||
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
public abstract class ContributedHelp {
|
||||
|
@ -26,9 +26,8 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -26,8 +26,11 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
@ -26,15 +26,16 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
|
||||
public class ContributedTargetPackage implements TargetPackage {
|
||||
|
||||
private final String id;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user