Use Processing PDE files within Java? - java

I have a working Java code that I would like to visualize using processing. I also found the tutorial on how to include processing within eclipse and am also already able to create a canvas, etc.
What I want to do now is to actually do the visualization. I found a nice project that is exactly what I need. However, the author provides PDE files.
How can I include PDE files in my java project? Is that even possible?

The PDE files that are available in that project are simply text files. You can either use them in your code directly, or better yet, try to understand what they're doing and adapt the code to your own purposes.
But to answer your question, you don't include PDE files in a Java project. You included the Processing library jars on your classpath, which give you access to things like the PApplet class. Then you can include a PApplet (which is just like a Processing sketch, in fact a Processing sketch is a PApplet) in your Java application and pass it whatever information you want.
More info here: http://processing.org/tutorials/eclipse/

Related

set data folder location for PApplet triggered through runSketch

I'm running a Processing sketch (a PApplet subclass, created by exporting from a Processing sketch) from Clojure. The basic process is
export sketch
locate jar files in exported application
install these jar files into local maven repo
load the libs in clojure using lein
The code is in this GH repo, including (reasonably) minimal instructions for how to get set up and reproduce the problem.
Loading basic sketches works, but when I create a sketch which calls e.g. loadImage() to load an image from my data folder, the sketch can't find it.
I know this is convoluted way to do this - this is partially a learning exercise for me and partially the fact that I'm a lisp guy but not a JVM guy.
Is there any way to dynamically tell the PApplet subclass where its data folder is? Or am I stuck putting absolute paths everywhere?
EDIT: Ugh, what a mess. It looks like the problem is that I'm actually wrapping each PApplet subclass in a clojure proxy (so that I can intercept certain methods and make the various sketches play nice together) but the way Processing finds the data path involves looking at the ProtectionDomain to find the root source path, so this won't work as I'm currentyly trying it. Back to the drawing board...
So you're using maven to link to jars you've exported from Processing, and those jars can't find the sketch directory?
If I were you, I would look int two places:
The Processing JavaDoc contains a detailed reference on every variable and function in Processing. Particularly check out the PApplet class and check out the following:
ARGS_SKETCH_FOLDER
selectInput()
selectOutput()
sketchFile()
sketchOutputPath() and sketchOutputStream()
sketchPath()
I would bet that by either setting the first variable or by overriding some of those functions, you can have Processing look wherever you want.
If you need more detail, the Processing source will tell you exactly how Processing uses all of the above.

Pure java alternative to GIMP with *live* plugin development?

Basically, I want to combine the Eclipse compiler+Java source editor with a nice Java GUI for image editing/processing in order to allow code-based image processing plugin development directly inside the image processing app.
What's the easiest solution for doing that? Start off with Eclipse and build an image processing tool out of it? Or just use parts of Eclipse (editor+compiler)? Are there any example projects doing something similar?
Marvin Framework provides feature extensibility through plug-in interface. Basically, it allow you to implement an image processing algorithm as a Java class that can be loaded dynamically on your application.
Regarding your idea, consider a Java application combining an image editing software and a source code editor. After writing the image processing algorithm, the user clicks on "Execute". The application:
saves the source code as .java file.
call the Java compiter to generate the .class
Load the new class dynamically into the application through Java Reflection
It is basically what MarvinEditor does to let developers to add new plug-ins to the application. Take a look at Marvin Prototyping Environment. It's similar to your idea.

C++ or Java Library for automated code editing?

I am writing/planning to write a program that takes in a java file (or multiple java files), and edits and adds functions/classes/variables and then outputs a new java file (or multiple files).
Is there a C++ or Java library that
Can recognize and output names of classes/functions within a text file
Can recognize and output the names of the input arguments for said classes/functions
Can allow me to insert code at specific lines or within specific functions
Can search for a given variable name/value
Maintains original file formatting
I would prefer not having to manually code something to do the above, so any help would be appreciated.
Thank you in advance!
EDIT: I currently use Eclipse, and am unsure of how to proceed. So to further explain my question:
In eclipse, if I write a program that opens another .java file, How would I go about 'asking' eclipse to output, say, all the class names of the .java file I just opened?
Also I will explain the 'purpose' of this project to further clarify. I want to write a program that can take in any java file, and turn it into a class that can implemented remotely via RMI. To do this I will need to add an execute() function, have the file implement Task and Serializable and add a few variables, etc... Based on my knowledge, doing this in Eclipse would require manual editing of the program, but I would like to completely automate this process.
Thank you, again.
Much of what you need can be found in a modern IDE; and some very good IDEs are open source (eclipse and Intellij IDEA Community Edition for Java). You might look there to see if there are modules that suite your needs.
Looks like you are talking of a tool like eclipse. You might not be looking for a full fledged IDE, but the requirements that you have mentioned are fulfilled by any basic IDE.
If you wish to make one of your own, you can do that using eclipse rich client platform.
All that you would need from Java is the reflection API.

Applet to Capture Images from a WebCam

I'm trying to create an Applet that will capture images from my Webcam.
I saw an sample in this thread but the imports don't work in my class. They weren't recognized.
I'm a newbie with Java, so, what i'm doing wrong ?
You must include the required external libraries (.jar) in your project in order for the compiler to find its imports.
In the answer you refer to, JavaCV is the API of choice, and also in the answer is a tutorial on configuring JavaCV for use.
In Webcam Capture project source code you can find webcam applet example and the working demo available here. This example does not require any additional JARs since it's shaded while the build. Shading is a process which packs all classes, from all dependent JARs, together, in only one file, referred then as shaded JAR. If you share all JARs you don;t have to build classpath since all imports are packed together.
From the code perspective there is no difference from using webcam API provided within Webcam Capture project in JFrame or JApplet. It contains WebcamPanel class which can be easily used to display image from camera in real time. For more details please check other examples.
The one important think you have to do, is to sigh your applet. This is required operation if you like to access host hardware. Without signing you would have to specify set of appropriate permissions, but I never did this, since, from my perspective JAR shading and signing with Maven a way easier.

Analyse SWF-Files with Java

I stumbled upon the need to find out (inside Java code) which files are dynamically loaded by an SWF-file. Is there any possibility to get a list of paths of every object referenced inside?
I tried out some libraries without proper documentation and gave up. Although I ran out of Google Search Phrases... ;)
Maybe there is an external tool which can be accessed by Java via command line?
Ggreat thanks in advance
Maybe you can get to the information you need using the dump tool which is part of Apparat.
I use actionscript more than Java, so I also recommend having a look at AS3SWF which is a great library you could use to load and analyze the swf you need. Think of it as decompiling at runtime.
Either way, the SWF Format Specifications will come in handy.
I'm not sure there's something that does exactly what you want, but I imagine you could collect all the strings (DefineText tags), loop through them and run an URL RegEx against them.
I think even if you could analyze a SWF file, you can't be sure to get this information. I have Flex Project (finally a swf file) which dynamically loads some modules, but the names (URLs) of the available modules are requested from the server. So there is no chance to retrieve this information from the main swf file.

Categories

Resources