Comments on: JGraph and BDE https://undocumentedmatlab.com/blog_old/jgraph-and-bde Charting Matlab's unsupported hidden underbelly Thu, 02 May 2024 08:00:01 +0000 hourly 1 https://wordpress.org/?v=4.4.1 By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/jgraph-and-bde#comment-352287 Thu, 02 Jul 2015 12:42:48 +0000 https://undocumentedmatlab.com/?p=2063#comment-352287 @Sam – thanks for confirming that BDE does indeed stand for Block Diagram Editor as I’ve speculated. As I noted in the main text, MathWorks removed BDE from the core Matlab in R2009b, and it’s not available to the general Matlab user since then. Only users of R2009a and earlier can use it. When I wrote the article in late 2010 (for publication in Jan 2011), R2009a was still widely used. But I believe that it is not very relevant nowadays.

]]>
By: Sam Robertshttps://undocumentedmatlab.com/blog_old/jgraph-and-bde#comment-352285 Thu, 02 Jul 2015 12:32:55 +0000 https://undocumentedmatlab.com/?p=2063#comment-352285 Yair – just in case you’re still interested (I appreciate that this is a very old post I’m replying to), BDE is short for block diagram editor. It’s part of SimBiology (MathWorks’ product for modelling, simulation and analysis of biological systems, such as pharmacokinetics and systems biology), and is used to graphically lay out components of biological models. If you take a look at the marketing pages on MathWorks website for SimBiology, you’ll see plenty of screenshots that show the component in action.

It’s a MathWorks-authored component, although it may (I’m not sure) be a wrapper around a third-party component. I’m not sure why it’s included as part of MATLAB rather than just SimBiology – perhaps there’s an idea that it might get reused across other products as well.

If anyone is thinking of using it, I would not rely on it to have a stable interface or behaviour across versions: MathWorks may well modify it based on requirements for SimBiology – which, as a leaf product, has much more scope to change rapidly than core MATLAB.

]]>
By: Scott Kochhttps://undocumentedmatlab.com/blog_old/jgraph-and-bde#comment-326984 Wed, 25 Jun 2014 18:38:50 +0000 https://undocumentedmatlab.com/?p=2063#comment-326984 Thanks for the post Markus. Here’s how I implemented your suggestion for anyone interested (Daniel).

Overload the mxGraph class. Create a file, mymxGraph.java with the following code:

import java.awt.datatransfer.DataFlavor;
import com.mxgraph.view.mxGraph;
import com.mxgraph.swing.util.mxGraphTransferable;
 
// Modified mxGraph to fix dragging
public class mymxGraph extends mxGraph {
  static {
    try {
      //Set enableImageSupport to false if using Mac otherwise data translation error happens.
      com.mxgraph.swing.util.mxGraphTransferable.enableImageSupport = false;
      //Following code is suggested in:
      //https://github.com/jgraph/jgraphx/blob/master/src/com/mxgraph/swing/util/mxGraphTransferable.java
      mxGraphTransferable.dataFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + 
      "; class=com.mxgraph.swing.util.mxGraphTransferable", null, 
      new com.mxgraph.swing.util.mxGraphTransferable(null, null).getClass().getClassLoader()); 
    } catch (ClassNotFoundException e) {
      System.err.println("Caught Class Not Found Exception: " + e.getMessage());;
    }
  }
}

Next, compile the class (at Matlab command line). Note that I have the jgraphx.jar in the same folder as mymxGraph.java created above which is also my Current Folder in Matlab:

% Compile the java file being sure to include jgraphx.jar
system('javac mymxGraph.java -classpath jgraphx.jar')
% Create a jar
system('jar cf mymxGraph.jar mymxGraph.class')
% Add both mymxGraph and jgraphx to java path
javaaddpath('mymxGraph.jar');
javaaddpath('jgraphx.jar')
 
% Replace com.mxgraph.view.mxGraph with the new mymxGraph
graph = mymxGraph;
 
%Run the rest of the code above and cells should now be draggable.

I’m a java amateur so if anyone has improvements to suggest please post them.

Thanks

]]>
By: Markus Behlehttps://undocumentedmatlab.com/blog_old/jgraph-and-bde#comment-288622 Fri, 25 Oct 2013 13:58:13 +0000 https://undocumentedmatlab.com/?p=2063#comment-288622 @Daniel

You don’t need to patch jgraphx’ sources.
From your code I see that you use jgraphx directly on Matlab’s command line (or in a .m file).
I wrote a Java program (where I put my code snippet in right at the beginning), compiled and packed it into a jar. From Matlab’s command line, I use that jar as a kind of library.

]]>
By: Daniel Malmquisthttps://undocumentedmatlab.com/blog_old/jgraph-and-bde#comment-280717 Thu, 10 Oct 2013 12:46:48 +0000 https://undocumentedmatlab.com/?p=2063#comment-280717 Hi!

I’ve been trying to get this working.

Do i need to put this code in my own program or in the jgraphx sources and rebuild it?

I’ve tried running it from my program with no success. I use jgraphx directly from matlab so i rewrote the code snippet for matlab:

%Fix for movable vertices
tempobj = javaObject('com.mxgraph.swing.util.mxGraphTransferable',[], []);
mxGraphTransferable.dataFlavor = javaObject('java.awt.datatransfer.DataFlavor', ...
   [char(java.awt.datatransfer.DataFlavor.javaJVMLocalObjectMimeType)'; class = com.mxgraph.swing.util.mxGraphTransferable'], ...
   [], tempobj.getClass().getClassLoader())

What am I doing wrong?

Regards

]]>
By: Markus Behlehttps://undocumentedmatlab.com/blog_old/jgraph-and-bde#comment-223621 Thu, 11 Jul 2013 08:58:18 +0000 https://undocumentedmatlab.com/?p=2063#comment-223621 mxGraph/JGraph – Get Drag & Drop (moving vertices), Cut & Paste working

People complained about not being able to move vertices if they start a java application built with mxGraph/JGraph. I experienced the same problem and investigated it. Here’s my solution how to get it working.
This article refers to Matlab R2013a and mxGraph 2.1.0.0 but it should also work with older versions of both.

Both Drag & Drop (which is needed for moving vertices around) and Cut & Paste rely on the mxGraphTransferHandler working correctly. The mxGraphTransferHandler in fact uses its own implementation of Transferable (java.awt.datatransfer.Transferable) called mxGraphTransferable. Have a look at the source code in jgraphx/src/com/mxgraph/swing/util/mxGraphTransferable.java. At the very end you’ll see a static initializer whose job is to construct a suitable DataFlavor (java.awt.datatransfer.DataFlavor). And here is the problem! If you start your mxGraph application from Java’s VM everything works fine. But if you start it from within Matlab’s JVM it cannot find the class com.mxgraph.swing.util.mxGraphTransferable and you’ll get a ClassNotFoundException. As you can see in the code this one is caught but nothing happens (// do nothing). So you do not notice that the Class Loader has a problem and keep wondering why moving vertices does not work (as me).

Now here comes the solution. By the way, I found it in the source code jgraphx/src/com/mxgraph/swing/util/mxGraphTransferable.java at the very top. There it says “Serialized Data Flavor. Use the following code to switch to local reference flavor: …”. In fact this did not work for me. “If you get a class not found exception, try the following instead: …” Et voila! Just insert their code

mxGraphTransferable.dataFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType
+ "; class=com.mxgraph.swing.util.mxGraphTransferable", null,
new com.mxgraph.swing.util.mxGraphTransferable(null, null).getClass().getClassLoader());

at the beginning of your java code and moving vertices, Drag & Drop and Cut & Paste works!

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/jgraph-and-bde#comment-60715 Mon, 31 Oct 2011 22:04:17 +0000 https://undocumentedmatlab.com/?p=2063#comment-60715 @Akli – try to follow the code in the following File Exchange submission: http://www.mathworks.com/matlabcentral/fileexchange/27074

]]>
By: Akli Benalihttps://undocumentedmatlab.com/blog_old/jgraph-and-bde#comment-60197 Mon, 24 Oct 2011 18:25:00 +0000 https://undocumentedmatlab.com/?p=2063#comment-60197 Yes, I added the jar files in \lib and the build.xml using the javaaddpath.

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/jgraph-and-bde#comment-60080 Sat, 22 Oct 2011 16:09:18 +0000 https://undocumentedmatlab.com/?p=2063#comment-60080 @Akli – did you remember to use javaaddpath for your JGraphT jar file(s)?

]]>
By: Akli Benalihttps://undocumentedmatlab.com/blog_old/jgraph-and-bde#comment-60019 Fri, 21 Oct 2011 21:30:59 +0000 https://undocumentedmatlab.com/?p=2063#comment-60019 About JgraphT and the submission link mentioned above: I tried to follow the instructions in the link and I can’t use the JgraphT in Matlab. When I do ‘which org.matjgraph.MaximalCliques.getMaximalCliques’ it retrives “not found”. First I thought the problem was in the paths to add because the “build” path does not exist. I changed it to match the build.xml file and all the jar files in the \lib\ path and still it does not work.

Does anyone know what can be the problem?

Cheers

(Version R2008a, Windows Vista)

]]>
By: Sven Körnerhttps://undocumentedmatlab.com/blog_old/jgraph-and-bde#comment-34007 Thu, 17 Feb 2011 20:13:10 +0000 https://undocumentedmatlab.com/?p=2063#comment-34007 @Fab: There is a way, you can move the vertex (works in 2010a, maybe also in 2008a). The trick is, when you have selected the vertex as shown in the figure after the codesnippet (green dotted border with marker and the double-cross appears) then press the left mouse button (hold on), press the right mouse button (hold on) and with both mouse buttons down move the mouse to the new place for the vertex. Then release the right mouse button first – vertex moves. It is difficult, but with a little training …

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/jgraph-and-bde#comment-32739 Wed, 09 Feb 2011 17:40:37 +0000 https://undocumentedmatlab.com/?p=2063#comment-32739 @Fab – well, while you cannot simply drag the vortexes, you can indeed move them by dragging opposite edges. For example, to move left, first enlarge the vortex leftward by dragging the left-side resize handle, then reduce the size leftward by dragging the right-side resize handle; the end result is that the vortex moved left. Ugly, but it works…

]]>
By: Fabhttps://undocumentedmatlab.com/blog_old/jgraph-and-bde#comment-32702 Wed, 09 Feb 2011 12:09:06 +0000 https://undocumentedmatlab.com/?p=2063#comment-32702 “JGraph example within a Matlab figure (the graph is fully interactive)”
Well I still can’t move the vorteces, same problem as Scott mentioned in his comment. Any solution to that?
(Version R2008a)

]]>