7

My goal is to write a Visual Studio plugin (a VSPackage) for my Java application. I was wondering if it was possible to view some JPanels inside a System.Windows.Forms instance, or rather as an Microsoft.VisualStudio.Editor.

I was thinking an applet but I'm pretty much stuck there...

Is streaming a Swing component as JPEG and displaying it in a Form an applicable idea?

EDIT:

I would really appreciate answers that are more then a "yes"/"no"/"why would you do this?". I made my mind about working this way, so I ask for:

  • A detailed solution for achieving my goal, OR,
  • Good insights/ideas of what my approach should be, OR,
  • A thorough explanation for why it is impossible to achieve.
  • Elist
    • 5,313
    • 3
    • 35
    • 73
    • 4
      This sounds like a difficult if not impossible pipe dream. Why mixing languages and their platforms in this way? What's the motivation behind this? You're far better off sticking with one platform here. What is your overall ultimate goal with this product? – Hovercraft Full Of Eels Jul 11 '13 at 15:29
    • The application is in Java, and has a complicated logic and UI, and I want to benefit some tools VS provides. After a long thinking process, my best solution is a VS plugin. If I will find no solution, I'll be forced to re implement a lot of code in C#, which I really want to avoid. – Elist Jul 11 '13 at 15:36
    • 2
      There are at least two "DIY IDE framework toolkits" for Java ([Eclipse RCP](http://wiki.eclipse.org/index.php/Rich_Client_Platform) and [Netbeans Platform](https://netbeans.org/features/platform/)) that may offer features similar to those of VS you're trying to integrate (but it might be helpful to add some info about what functionality you're after exactly), I think it might be a good idea to check these out. – fvu Jul 11 '13 at 15:51
    • Java can work fine with "complicated logic" and UI. I've been creating Java GUI's by hand for years and have also created C# GUI's as well. I much prefer making the Java GUI's. But having said that, if your program is geared only for Windows apps, then there's little that Java can do that C# can't. So I suggest you take your pick and create your GUI/program. – Hovercraft Full Of Eels Jul 11 '13 at 16:19
    • I'll be more informative (as much as I possibly can..): One feature in the Java application produces scripts for various testing frameworks, one of which is NUnit files. My goal is to integrate this feature into VS, so that the feature will become an editor of some kind and enables the user to create and run the test from within VS, with my application running behind the scenes. – Elist Jul 11 '13 at 16:28
    • 2
      Not sure about the complexity of UI stuff but a poor starting place might be http://improve.dk/compiling-java-in-visual-studio/ however your at real risk that the monster you've created will turn against you. I would head @hovercraft full of eels advice :-) – Kyle Jul 14 '13 at 09:37

    1 Answers1

    6

    ( ) Way of the warrior

    1. Load the JVM from your extension (use jvm.dll).
    2. Implement your own Applet Container. Something like this AppletViewer.
    3. Put the Applet Container inside your native form. This is hard, there are ways to get the Applet Container HWND (In Java Swing how do you get a Win32 window handle (hwnd) reference to a window?), but I am not sure a simple SetParent can do the trick.
    4. Load your Applet.

    ( ) Way of the master

    1. Use NPAPI/NPRuntime, like the browsers do.
    2. Load the npjp2.dll Java Plug-In.
    3. Load your applet.

    (X) The solution adopted was:

    1. Run the VS Plugin part written in Java (like an Applet) with JVM in another process (the standard for Java).
    2. Get the HWND using FindWindow (Win32 API).
    3. Use SetParent (Win32 API) and MoveWindow (Win32 API), to dock the window and resize it.

    I could name it the "the easiest way", but running Java in another process will give you more stability, so this is the "way that works". My only fear about using a window from another process, was the thread that process Windows messages in Java could interfere in Visual Studio. But from what I see, there is nothing to fear.

    :-)

    Community
    • 1
    • 1
    Marcos Zolnowski
    • 2,751
    • 1
    • 24
    • 29
    • Two interesting approaches, though I'm pretty sure I can get HWND even if the JVM is started outside the extension. I'll try to implement simple examples of both ways and let you know. Thanks! – Elist Jul 16 '13 at 19:27
    • Using a modified version of your "Warrior" way worked like charm. Actually there was no war at all... As I thought, with some help from [this guy](http://stackoverflow.com/questions/5836176/docking-window-inside-another-window) I was able to dock the window from a running java application on an **outside JVM** (got the HWND using FindWindow from user32.dll) into a .NET Form. – Elist Jul 18 '13 at 08:48
    • **Very good @Elist !** Many years ago, I played with SetParent, I knew it would work. Never thought that Java would let you do this so easily. And people telling you this was a "pipe dream", funny. – Marcos Zolnowski Jul 18 '13 at 17:50