Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Java Swing MVC Best Practices (Read 8391 times)
alukes
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 61
Joined: Jul 1st, 2011
Java Swing MVC Best Practices
Sep 2nd, 2013 at 12:23am
Print Post  
I have looked and can't seem to find a best practices example of JSP and web page code for MVC. Could you point me in the right direction? Thanks
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Java Swing MVC Best Practices
Reply #1 - Sep 2nd, 2013 at 9:34am
Print Post  
If you are asking in general, here are some articles and examples.

Java Swing:
http://www.oracle.com/technetwork/articles/javase/index-142890.html
http://accu.org/index.php/journals/1524

JSP:
http://www.oracle.com/technetwork/articles/javase/servlets-jsp-140445.html
http://www.datadisk.co.uk/html_docs/jsp/jsp_mvc_tutorial.htm

As for the diagramming API specifically, you could keep your model classes separate from it and work with Diagram and DiagramView classes only as part of your views, or you could integrate your models with the Diagram and DiagramItem classes by deriving from them. E.g. you could do the latter if your application model is already related to graphs or drawings, or otherwise keep it separate if you are using the diagrams only for some specific visualization of the model.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
alukes
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 61
Joined: Jul 1st, 2011
Re: Java Swing MVC Best Practices
Reply #2 - Sep 2nd, 2013 at 2:12pm
Print Post  
Thanks for the links. They look helpful. I was wondering if I can use the examples given in ASP.NET MVC or if there are differences between ASP.NET MVC and JDiagram?  Thanks
  
Back to top
 
IP Logged
 
alukes
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 61
Joined: Jul 1st, 2011
Re: Java Swing MVC Best Practices
Reply #3 - Sep 3rd, 2013 at 3:37am
Print Post  
Looks like ASP>NET MVC is quite different. What do I need to do to get a diagram view that references the diagram in the managed bean? Thanks


managed Bean

package com.mycompany.mavenflowchartdb;

import javax.ejb.Stateful;
import com.mindfusion.diagramming.*;

/*
@Stateful
public class DiagramBean {
private Diagram flowChart;

public DiagramBean()
{
  flowChart = new Diagram();
}

public Diagram getFlowChart() {
        return flowChart;
    }

    public void setFlowChart(Diagram flowChart) {
        this.flowChart = flowChart;
    }



JSP

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <applet id="fcapplet" code="com.mindfusion.diagramming.class"
archive="JDiagram.jar" width="640" height="480" mayscript>
</applet>
        <script>
function load()
{
     var applet = document.getElementById("fcapplet");
     fc = applet.getDiagram();
   
}   
</script>
    </head>
    <body>
       
    </body>
</html>
  
Back to top
 
IP Logged
 
alukes
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 61
Joined: Jul 1st, 2011
Re: Java Swing MVC Best Practices
Reply #4 - Sep 3rd, 2013 at 4:42am
Print Post  
Also could you provide an example of what is needed to run the diagram and diagram view not using the applet class on a client machine. I am thinking I just need methods to send and receive the file in the managed bean.

On the client machine JSP I would need the applet to reference the com.fusion.diagramming class, and then how would I create a diagram, diagram view and load from the managed bean?

I am new to this so I am sure my questions are basic, but I haven't found any clear examples yet.

Thanks
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Java Swing MVC Best Practices
Reply #5 - Sep 3rd, 2013 at 8:17am
Print Post  
Quote:
Also could you provide an example of what is needed to run the diagram and diagram view not using the applet class on a client machine. I am thinking I just need methods to send and receive the file in the managed bean.


JDiagram is mostly a component for desktop applications, and the DiagramView class is a Java Swing component that lets you edit diagrams interactively in Swing applications. We don't provide any built-in JSP integration at this time, and if you don't want your web page to load an applet, you won't be using the DiagramView class either, but only Diagram and DiagramItem-derived objects. E.g. you can build the diagram model with them from JSP or servlet code, and then generate bitmaps with associated HTML image maps representing the diagram. You can find an example showing how to use JDiagram both as an applet and as a server-side image generator in the Samples/JspSample folder; copy it to a Tomcat apps folder to run it.

If you need to implement user interaction with the diagram in a web page, you will have to load the JDiagram's applet, or possibly use our JavaScript library for HTML5 Canvas on the client side. Another option is to create a Java Web Start desktop application that communicates with your server via web services.

Quote:
On the client machine JSP I would need the applet to reference the com.fusion.diagramming class, and then how would I create a diagram, diagram view and load from the managed bean?


You won't be using DiagramView on the server side as it's a Swing UI component. In the JSP code you can populate a Diagram with objects representing your data, and call Diagram.saveToString to get the encoded diagram in format that you can send to the client side applet. DiagramApplet will automatically load that string if you set it as the value of the DiagramData applet parameter. This is shown in the JspSample sample project.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
alukes
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 61
Joined: Jul 1st, 2011
Re: Java Swing MVC Best Practices
Reply #6 - Sep 3rd, 2013 at 11:00am
Print Post  
Thanks somehow I missed the JSP example. I will check that out and look into your other suggestions.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint