I already have a Java application with Swing GUI which reads a bunch of XML files and makes some graphs based on the information found in those XML files.
Now I was asked to turn that application into an Eclipse Plugin so the application can be launched from inside the Eclipse IDE. On top of that I have to make my application to sometimes open an XML file which contains the data that the user clicks.
Now, after a fast walk through a tutorial about how to make an Eclipse Plugin, it does not seem that I will be able to use Swing components inside a Plugin Project. I have seen that there are other tools and frameworks for making GUI for a plugin.
I need a suggestion for how can I turn my Swing application into an Eclipse plugin, the easiest possible. Even with some frameworks for Swing I had a hard time to make a treelayout graph. I imagine that should be even harder to implement into Eclipse plugin if Swing components do not work over there.
Here it is how my application looks like right now, based on Swing components:
If you don't want to rewrite the whole application, you may want to check possibilities of using SWT_AWT bridge, which allows to integrate Swing applications into SWT world. It is pretty easy, but you may want to check some articles as well.
I used it to integrate some Swing-based print preview functionality into existing Eclipse-RCP application. Worked well, though it still has its own underwater rocks.
You can use Swing components inside a Eclipse plugin.
For demonstaration I took the Swing components from https://code.google.com/p/treelayout/ and put them into an Eclipse view:
The important file looks like this:
package createaview.views;
import org.abego.treelayout.demo.swing.SwingDemo;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
public class TreeView extends ViewPart {
public static final String ID = "createaview.views.SampleView";
private TableViewer viewer;
class ViewContentProvider implements IStructuredContentProvider {
public void inputChanged(Viewer v, Object oldInput, Object newInput) {}
public void dispose() {}
public Object[] getElements(Object parent) {
return new String[] {"One", "Two", "Three"};
}
}
class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
public String getColumnText(Object obj, int index) {
return getText(obj);
}
public Image getColumnImage(Object obj, int index) {
return getImage(obj);
}
public Image getImage(Object obj) {
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
}
}
class NameSorter extends ViewerSorter {
}
public TreeView() {}
public void createPartControl(Composite parent) {
Composite composite = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
java.awt.Frame frame = SWT_AWT.new_Frame(composite);
frame.add(SwingDemo.getPanel());
}
public void setFocus() {
viewer.getControl().setFocus();
}
}
and if you pass me an email address I'll bundle up the demo project I did and send them to you (actually, it should probably be that if this is looking like the right answer, I'll put the projects in a zip file somewhere around here for the community to have a look at)
Related
I setup my eclipse for PROCESSING perfectely..
I am using Eclipse Oxygen and installed PROCESSING 3.3.6
i am trying to run processing program in eclipse and there is no option is run as Applet
My code is below :
package processing01;
import processing.core.PApplet;
public class Processing01 extends PApplet{
public static void main(String[] args) {
PApplet.main("Processing01");
}
public void settings(){
size(300,300);
}
public void setup(){
fill(120,50,240);
}
public void draw(){
ellipse(width/2,height/2,second(),second());
}
}
Processing 3 no longer supports running as an applet. From the Processing 3 change list:
Applet is gone — Java's java.awt.Applet is no longer the base class used by PApplet, so any sketches that make use of Applet-specific methods (or assume that a PApplet is a Java AWT Component object) will need to be rewritten.
The PApplet class no longer extends the Applet class, which means you can't treat Processing sketches as a component anymore, and you can't run them as an applet. You can only run them as an application.
Applets are dead, and shouldn't be used anyway.
Because having package the code would be
//replace
PApplet.main("Processing01");
//with
PApplet.main("processing01.Processing01");
When I try to run my java code for processing it shows an error "selection does not contain applet". This is how I am supposed to run my code.
Here is my code:
package proccesing;
import processing.core.*;
public class proccesing extends PApplet {
public void setup() {
background(100,100);
}
public void draw() {
line(0,0,0,100);
}
}
As of Processing 3, PApplet no longer extends Applet. In other words, you can't deploy as an applet anymore.
You could try using the Applet exporting tool, but you're much better off using Processing.js to deploy as JavaScript. Applets are pretty much dead and shouldn't really be used anymore.
Newbie at netbeans-platform.
How can I save my state from one execution to the next.
The netbeans platform elegantly remembers the state and position of all my windows. How can I add to that state some of my own data? Very much like Netbeans saves what projects are open and reopens them when it starts up, along with their state.
Ass suggested here I added the following to my TopComponent but it doesn't work. getPersistenceType is called but neither writeExternal n'or readExternal are called.
#Override
public int getPersistenceType() {
return TopComponent.PERSISTENCE_ALWAYS;
}
#Override
public void writeExternal(ObjectOutput oo) throws IOException {
super.writeExternal(oo);
}
#Override
public void readExternal(ObjectInput oi) throws IOException, ClassNotFoundException {
super.readExternal(oi);
}
Comments here suggest tapping into readProperties and writeProperties but that doesn't feel right to me. I am not wanting to store Properties, I want to store State.
Some years ago I blogged about this, using the Session Storage feature of the Swing Application Framework in a NetBeans Platform application:
http://puces-blog.blogspot.ch/2009/04/netbeans-platform-meets-swing.html
The following 3 classes should provide the integration into the NetBeans Platform:
ModuleApplicationContext.java
ModuleLocalStorage.java
Modules.java
The referenced XProperties and JXTable you only need if you want support for SwingX classes such as JXTable.
To use this feature in your own module you need to initialize the context in your ModuleInstall class:
public class Installer extends ModuleInstall {
private static ModuleApplicationContext applicationContext;
#Override
public void restored() {
applicationContext = new ModuleApplicationContext(Modules.getModuleInfo(
Installer.class));
}
public static ModuleApplicationContext getApplicationContext() {
return applicationContext;
}
}
For a given contentPane you can then store the GUI session state using:
Installer.getApplicationContext().getSessionStorage().save(
getContentPanel(), SESSION_STORAGE_XML);
and restore the state using:
Installer.getApplicationContext().getSessionStorage().
restore(getContentPanel(), SESSION_STORAGE_XML);
Note: you need to set the component names of the relevant components
You can find the complete sample here: http://sourceforge.net/p/puces-samples/code/HEAD/tree/tags/sessionstate-1.0/
Also note however that development of the Swing Application Framework (JSR-296) has been withdrawn.
There is a fork called Better Swing Application Framework, but I haven't used it yet.
I also had some problems with this but finally I could fix it.
Annotate Your topcomponent class with #TopComponent.Description and set the right persistence type inside the annotation.
Your topcomponent class has to be serializable so,
every fields inside the topcompent have to be serializable or transient.
You can implement Your custom serialization with readExtern/writeExternal but it is not necessary, You can remove them.
If it still does not work check the log after You closed Your netbeans app and You will see why the platform could not serialize Your topComponent.
I need to import the project as mentioned in this link.
I am not using git, hence I have downloaded the project zip folder and extracted. Could you please let me know how to import this LibGdx sample project ?
This project is about 3 years ago, perhaps the APIs libgdx not be supported 100% by the cycle of listener aplication, or the project will not be prepared to be exported, and is a simple guide. I do not know the truth but looking at the repo what comes to mind is the following.
I think the easiest wayIt would create a new project, libgdx.
Copy, android asset data folder in to the new project android asset, and the Main folder, extract all files and copy to the core of the new project. change name package com.matsemann.libgdxloadingscreen; for you packege name and change other posible error in the files.
Take the class SomeCoolGame in "SomeCoolGame.java":
package com.matsemann.libgdxloadingscreen;
//
public class SomeCoolGame extends Game {
/**
* Holds all our assets
*/
public AssetManager manager = new AssetManager();
#Override
public void create() {
setScreen(new LoadingScreen(this));
}
}
as an entry point and adapt more or less something, eh not test but it's just so you can see the idea
package your.name.package;
//
public class MyGdxGame extends ApplicationAdapter {
/**
* Holds all our assets
*/
public AssetManager manager = new AssetManager();
#Override
public void create() {
setScreen(new LoadingScreen(this));
}
}
and work starting from there.
I've implemented my own widget (extending Canvas), that has as distinct characteristic the fact that it's all black.
When adding my canvas to a Shell in design-mode in WindowBuilder, it looks just like a regular canvas, although when in execution-mode everything shows up just alright.
Is there anything I'm missing, or is this an inherent limitation on the part of WindowBuilder?
Here's the code I'm using, just in case:
public class MyCanvas extends Canvas {
public MyCanvas(Composite parent, int style) {
super(parent, style);
setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
addPaintListener(new PaintListenerEx());
}
private class PaintListenerEx implements PaintListener {
#Override
public void paintControl(PaintEvent e) {
e.gc.fillRectangle(MyCanvas.this.getBounds());
e.gc.dispose();
}
}
}
I believe that WindowBuilder is not calling the constructor you are trying to use to initilize your Canvas. WindowBuilder uses some known entry points per framework (like SWT) but sometimes it fails to find one even if you are using the right signature.
If you want to specify an entry point for WindowBuilder you can use this:
/**
* #wbp.parser.entryPoint
*/
to make WindowBuilder start from there but it is not guaranteed to work.
There's also the case where you need to specify the default constructor of a specific graphic element.
/**
* #wbp.parser.constructor
*/
In my particular case entryPoint didn't work and this was the solution.