Permalink
Browse files

Replace old RXTXcomm with jSSC

Remove old RXTXcomm and add support for jSSC library
  • Loading branch information...
1 parent d0976f6 commit 00b0dcfce5c353bd53b8c7e4f5f68589c2a82979 @dbarragan dbarragan committed Aug 7, 2014
@@ -27,6 +27,7 @@
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
+import java.net.*;
import javax.swing.*;
@@ -42,8 +43,8 @@
* files and images, etc) that comes from that.
*/
public class Base {
- public static final int REVISION = 100;
- static String VERSION_NAME = "0100";
+ public static final int REVISION = 101;
+ static String VERSION_NAME = "0101";
/** Set true if this a proper release rather than a numbered revision. */
static public boolean RELEASE = false;
/** True if heavy debugging error/log messages are enabled */
@@ -2259,8 +2260,62 @@ static public int showYesNoQuestion(Frame editor, String title,
}
}
+ static public String urlDecode(String str) {
+ try {
+ return URLDecoder.decode(str, "UTF-8");
+ } catch (UnsupportedEncodingException e) { // safe per the JDK source
+ return null;
+ }
+ }
+ /**
+ * Adjacent the executable on Windows and Linux,
+ * or inside Contents/Resources/Java on Mac OS X.
+ */
+ static protected File wiringRoot;
+
+
static public File getContentFile(String name) {
+ if (wiringRoot == null) {
+ // Get the path to the .jar file that contains Base.class
+ String path = Base.class.getProtectionDomain().getCodeSource().getLocation().getPath();
+ // Path may have URL encoding, so remove it
+ String decodedPath = urlDecode(path);
+
+ if (decodedPath.contains("/app/bin")) {
+ if (Base.isMacOS()) {
+ wiringRoot =
+ new File(path, "../../build/macosx/work/Processing.app/Contents/Java");
+ } else if (Base.isWindows()) {
+ wiringRoot = new File(path, "../../build/windows/work");
+ } else if (Base.isLinux()) {
+ wiringRoot = new File(path, "../../build/linux/work");
+ }
+ } else {
+ // The .jar file will be in the lib folder
+ File jarFolder = new File(decodedPath).getParentFile();
+ if (jarFolder.getName().equals("lib")) {
+ // The main Processing installation directory.
+ // This works for Windows, Linux, and Apple's Java 6 on OS X.
+ wiringRoot = jarFolder.getParentFile();
+ } else if (Base.isMacOS()) {
+ // This works for Java 7 on OS X. The 'lib' folder is not part of the
+ // classpath on OS X, and adding it creates more problems than it's
+ // worth.
+ wiringRoot = jarFolder;
+
+ }
+ if (wiringRoot == null || !wiringRoot.exists()) {
+ // Try working directory instead (user.dir, different from user.home)
+ System.err.println("Could not find lib folder via " +
+ jarFolder.getAbsolutePath() +
+ ", switching to user.dir");
+ wiringRoot = new File(System.getProperty("user.dir"));
+ }
+ }
+ }
+
+ /*
String path = System.getProperty("user.dir");
// Get a path to somewhere inside the .app folder
@@ -2271,7 +2326,8 @@ static public File getContentFile(String name) {
}
}
File working = new File(path);
- return new File(working, name);
+ */
+ return new File(wiringRoot, name);
}
@@ -2305,6 +2361,17 @@ static public Image getLibImage(String name, Component who) {
* Return an InputStream for a file inside the Processing lib folder.
*/
static public InputStream getLibStream(String filename) throws IOException {
+ /*
+ Properties p = System.getProperties();
+ Enumeration keys = p.keys();
+ String res = new String();
+ while (keys.hasMoreElements()) {
+ String key = (String)keys.nextElement();
+ String value = (String)p.get(key);
+ res += key + ": " + value+ "\n";
+ }
+ showMessage("HERE ", getContentFile("lib").getAbsolutePath() +"XXX"+ System.getProperty("os.name")+"XXX"+res);
+ */
return new FileInputStream(new File(getContentFile("lib"), filename));
}
@@ -43,7 +43,7 @@
import javax.swing.undo.*;
import java.util.regex.*;
-import gnu.io.*;
+import jssc.*;
/**
* Main editor panel for the Processing Development Environment.
@@ -868,7 +868,20 @@ protected void populateSerialMenu() {
try
{
- for (Enumeration enumeration = CommPortIdentifier.getPortIdentifiers(); enumeration.hasMoreElements();)
+ Vector<String> ports = new Vector<String>(Arrays.asList(SerialPortList.getPortNames()));
+ Enumeration<?> portList = ports.elements();
+
+ while (portList.hasMoreElements()) {
+ String portId =
+ (String) portList.nextElement();
+ rbMenuItem = new JCheckBoxMenuItem(portId, portId.equals(Preferences.get("serial.port")));
+ rbMenuItem.addActionListener(serialMenuListener);
+ //serialGroup.add(rbMenuItem);
+ serialMenu.add(rbMenuItem);
+ empty = false;
+ }
+
+ /*for (Enumeration enumeration = CommPortIdentifier.getPortIdentifiers(); enumeration.hasMoreElements();)
{
CommPortIdentifier commportidentifier = (CommPortIdentifier)enumeration.nextElement();
//System.out.println("Found communication port: " + commportidentifier);
@@ -882,7 +895,7 @@ protected void populateSerialMenu() {
serialMenu.add(rbMenuItem);
empty = false;
}
- }
+ }*/
if (!empty) {
//System.out.println("enabling the serialMenu");
serialMenu.setEnabled(true);
@@ -924,21 +937,21 @@ protected JMenu buildSerialMenu() {
// environment variable will hose things.
try {
//System.out.println("building port list");
- for( Enumeration portList = CommPortIdentifier.getPortIdentifiers(); portList.hasMoreElements();)
+ Vector<String> ports = new Vector<String>(Arrays.asList(SerialPortList.getPortNames()));
+ Enumeration<?> portList = ports.elements();
+
+ while( portList.hasMoreElements())
{
- CommPortIdentifier portId =
- (CommPortIdentifier) portList.nextElement();
+ String portId = (String) portList.nextElement();
//System.out.println(portId);
- if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
//if (portId.getName().equals(port)) {
- String name = portId.getName();
+ String name = portId;
JCheckBoxMenuItem mi =
new JCheckBoxMenuItem(name, name.equals(defaultName));
mi.addActionListener(listener);
//mi.addItemListener(listener);
serialMenu.add(mi);
- }
}
} catch (UnsatisfiedLinkError e) {
e.printStackTrace();
Oops, something went wrong.

0 comments on commit 00b0dcf

Please sign in to comment.