473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Need a help in prefuse visulation graph save as jpeg file

Hi Frnd's,

m using prefuse visulation,it's have one display class and this class have one saveImage(outPutStream, String jpg,double size);. now graph is converting ia jpg image properly.now my problem is tht,If graph is to large if it going out of screen thn ,i m getting jpg image on screen disply graph,m not getting the image of tht graph which going out of screen. this is my code



This is my code



Expand|Select|Wrap|Line Numbers
  1.  import com.sun.corba.se.impl.orbutil.graph.Node;
  2. import java.awt.BorderLayout;
  3. import java.awt.Dimension;
  4. import java.awt.Point;
  5. import java.awt.dnd.DragSource;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.ItemEvent;
  9. import java.awt.event.MouseAdapter;
  10. import java.awt.event.MouseEvent;
  11. import java.awt.event.MouseListener;
  12. import java.awt.event.WindowAdapter;
  13. import java.awt.event.WindowEvent;
  14. import java.awt.event.WindowListener;
  15. import java.awt.image.BufferedImage;
  16. import java.io.File;
  17. import java.io.FileOutputStream;
  18. import java.io.IOException;
  19. import java.io.OutputStream;
  20. import java.util.Iterator;
  21. import javax.crypto.NullCipher;
  22. import javax.swing.JButton;
  23. import javax.swing.JFrame;
  24. import javax.swing.JOptionPane;
  25. import javax.swing.border.Border;
  26.  
  27. import prefuse.Constants;
  28. import prefuse.Display;
  29. import prefuse.Visualization;
  30. import prefuse.action.Action;
  31. import prefuse.action.ActionList;
  32. import prefuse.action.RepaintAction;
  33. import prefuse.action.assignment.ColorAction;
  34. import prefuse.action.assignment.DataColorAction;
  35. import prefuse.action.layout.graph.ForceDirectedLayout;
  36. import prefuse.activity.Activity;
  37. import prefuse.activity.ActivityAdapter;
  38. import prefuse.activity.ActivityListener;
  39. import prefuse.controls.DragControl;
  40. import prefuse.controls.PanControl;
  41. import prefuse.controls.ToolTipControl;
  42. import prefuse.controls.ZoomControl;
  43. import prefuse.controls.FocusControl;
  44. import prefuse.controls.DragControl;
  45. import prefuse.data.Graph;
  46. import prefuse.data.Table;
  47. import prefuse.data.Tuple;
  48. import prefuse.data.io.DataIOException;
  49. import prefuse.data.io.GraphMLReader;
  50. import prefuse.data.io.GraphWriter;
  51. import prefuse.data.tuple.TupleSet;
  52. import prefuse.render.DefaultRendererFactory;
  53. import prefuse.render.LabelRenderer;
  54. import prefuse.render.ShapeRenderer;
  55. import prefuse.util.ColorLib;
  56. import prefuse.util.force.DragForce;
  57. import prefuse.visual.NodeItem;
  58. import prefuse.visual.VisualItem;
  59. import javax.swing.*;
  60. import java.awt.Container;
  61. import java.io.FileInputStream;
  62. import java.awt.Canvas;
  63. import java.awt.event.WindowAdapter;
  64. import java.awt.event.WindowListener;
  65. import java.awt.Image;
  66. import java.util.Set;
  67. class DrawGrahp extends JFrame{
  68.  
  69. private FileOutputStream fileOutPutStream=null;
  70. private JButton button;
  71. private JFrame frame;
  72. private Visualization vis;
  73. private LabelRenderer r;
  74. private ActionList layout;
  75. private ActionList color;
  76. private Display d ;
  77. private int a,b;
  78. private Graph graph = null;
  79. private JPanel jpanel;
  80. public DrawGrahp(){
  81. jpanel=new JPanel();
  82.  
  83.  
  84. button=new JButton("Save");
  85. Container con= getContentPane();
  86. jpanel.setLayout(null);
  87. button.setBounds(200,300,70,40);
  88. con.setSize(500,600);
  89. jpanel.setSize(1000,800);
  90. final int l= jpanel.getHeight();
  91. final int m=jpanel.getWidth();
  92. Canvas canvas=new Canvas();
  93.  
  94. jpanel.add(button);
  95.  
  96. con.setVisible(true);
  97. jpanel.setDoubleBuffered(true);
  98. jpanel.setPreferredSize(new Dimension(500,600));
  99. Point location=new Point();
  100.  
  101.  
  102. System.out.println("Panel Size"+ jpanel.getSize());
  103. System.out.println("panel height----------"+jpanel.getHeight()+"Panel width-------------"+jpanel.getWidth());
  104. con.add(jpanel,BorderLayout.NORTH);
  105.  
  106.  
  107. try {
  108. graph = new GraphMLReader().readGraph("\\JavaApplicationSwing\\graph.xml");
  109. } catch (DataIOException e ) {
  110. e.printStackTrace();
  111. System.err.println("Error loading graph. Exiting...");
  112. System.exit(1);
  113. }
  114.  
  115.  
  116.  
  117.  
  118. // nodes and edges are accessible as "graph.nodes" and "graph.edges"
  119. vis = new Visualization();
  120. vis.add("graph", graph);
  121.  
  122. vis.setInteractive("graph.edges", null, false);
  123.  
  124. // -- 3. the renderers and renderer factory ---------------------------
  125.  
  126.  
  127. r = new LabelRenderer("name");
  128. r.setRoundedCorner(8, 8); // round the corners
  129. ShapeRenderer sh=new ShapeRenderer();
  130. sh.star(2,3,4);
  131. sh.setBaseSize(4);
  132.  
  133. // return our name label renderer as the default for all non-EdgeItems
  134. // includes straight line edges for EdgeItems by default
  135. vis.setRendererFactory(new DefaultRendererFactory(r));
  136. d = new Display(vis);
  137.  
  138. // -- 4. the processing actions ---------------------------------------
  139.  
  140.  
  141.  
  142. int[] palette = new int[] {
  143. ColorLib.rgb(255,180,180), ColorLib.rgb(190,190,255)
  144.  
  145. };
  146.  
  147. // map nominal data values to colors using our provided palette
  148. DataColorAction fill = new DataColorAction("graph.nodes", "gender",
  149. Constants.NOMINAL, VisualItem.FILLCOLOR, palette);
  150.  
  151.  
  152. ColorAction text = new ColorAction("graph.nodes",
  153. VisualItem.TEXTCOLOR, ColorLib.gray(0));
  154.  
  155. if(text.equals("sriniwas"))
  156. {
  157. new ColorAction("graph.nodes",VisualItem.TEXTCOLOR, ColorLib.green(240));
  158. }
  159. ColorAction edges = new ColorAction("graph.edges",
  160. VisualItem.STROKECOLOR, ColorLib.gray(200));
  161.  
  162.  
  163. color = new ActionList();
  164. color.add(fill);
  165.  
  166. color.add(text);
  167. color.add(edges);
  168. int aa;
  169. for(int i=0;i<color.size();i++){
  170.  
  171.  
  172. System.out.println("sdhfshdfhsf" +i);
  173. }
  174.  
  175. layout = new ActionList(Activity.INFINITY);
  176. layout.add(new ForceDirectedLayout("graph"));
  177. layout.add(new RepaintAction());
  178.  
  179.  
  180.  
  181.  
  182.  
  183. vis.putAction("color", color);
  184. vis.putAction("layout", layout);
  185.  
  186.  
  187. // -- 5. the display and interactive controls -------------------------
  188. d = new Display(vis);
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195. // d.setSize(1000, 600); // set display size
  196.  
  197.  
  198. d.addControlListener(new DragControl());
  199. d.addControlListener(new PanControl());
  200. d.addControlListener(new ZoomControl());
  201. d.addControlListener(new FrameFocusControl());
  202. // d.addControlListener(new ToolTipControl(){
  203.  
  204.  
  205. //d.addControlListener(new DragSource());
  206.  
  207.  
  208. // -- 6. launch the visualization -------------------------------------
  209.  
  210. jpanel.add(d);
  211. vis.run("color");
  212. vis.run("layout");
  213.  
  214.  
  215.  
  216.  
  217. button.addActionListener(new ActionListener(){
  218. public void actionPerformed(ActionEvent e){
  219. if(e.getSource()==button){
  220. try{
  221.  
  222.  
  223.  
  224.  
  225. jpanel.setSize(new Dimension(l*10,m*10));
  226. System.out.println("Panel Hieght"+jpanel.getHeight());
  227. System.out.println("Panel width"+jpanel.getWidth());
  228. Image img =d.getOffscreenBuffer();
  229. img.getSource();
  230. System.out.println("A fter increase Panel Size"+ jpanel.getSize());
  231. fileOutPutStream=new FileOutputStream("c:/sri/img.jpg");
  232. d.saveImage(fileOutPutStream,"jpg",2.6);
  233. fileOutPutStream.flush();
  234. fileOutPutStream.close();
  235.  
  236. System.out.println("------------------"+jpanel.getHeight());
  237. }catch(IOException ex){ex.printStackTrace();}
  238.  
  239. }
  240. }
  241. });
  242.  
  243. }
  244.  
  245.  
  246.  
  247. }
  248.  
  249.  
  250. public class DrawGrahpDemo{
  251. public static void main(String Arg[]){
  252.  
  253. DrawGrahp drawGraph=new DrawGrahp();
  254.  
  255. drawGraph.setVisible(true);
  256. drawGraph.setSize(500,600);
  257. drawGraph.setDefaultCloseOperation(JFrame.EXIT_ON_ CLOSE);
  258.  
  259. }
  260. }
  261.  
  262.  
it's very importtant for me, plz help me.
Jan 12 '08 #1
2 4113
RedSon
5,000 Expert 4TB
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Jan 14 '08 #2
final
1
[quote=sriniwas]Hi Frnd's,

m using prefuse visulation,it's have one display class and this class have one saveImage(outPutStream, String jpg,double size);. now graph is converting ia jpg image properly.now my problem is tht,If graph is to large if it going out of screen thn ,i m getting jpg image on screen disply graph,m not getting the image of tht graph which going out of screen. this is my code

Hello sriniwas,

I had the same problem and I solved it by creating a new temporary display where I scaled the visualization onto the size of the created display. After this I am able to save a complete image of the visualized graph. The other possibility is to scale your actual display onto the size of your visualization while saving an image and decreasing it after that.
If there are other possibilities I would be glad to read about.
Feb 29 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: jhon02148 | last post by:
hi this hw have four files: 1. for the main program 2. listp.cpp (the source file) 3. listp.h (the header file) 4. exception.h if there is anybody who could help me with this hw i really...
1
by: jhon02148 | last post by:
hi this hw have four files: 1. for the main program 2. listp.cpp (the source file) 3. listp.h (the header file) 4. exception.h hi iam done with my hw i still have to do one function which is...
11
by: Chapman | last post by:
Is it possible to plot the graph as an output of my program in C? It can be a simple graph as quadratic curves for example or a correlation between 2 variables only. Thanks
5
by: TheGanjaMan | last post by:
Hi everyone, I'm trying to write up a simple image stamper application that stamps the Exif date information from the jpegs that I've taken from my digital camera and saves the new file with the...
2
by: Jeff | last post by:
Hey asp.net 2.0 The code below saves the "helloworld.jpeg" file to: C:\Documents and Settings\Jeff\My Documents\Visual Studio 2005\WebSites\BN\webForms\Profile HttpPostedFile file =...
1
by: natttalia | last post by:
Hello, im having some problems with a bitmap, im hoping somebody can help me :( i'm gettin data through a stored procedure and want to draw a pie graph. the little problem is that i actually get...
1
by: blazingmavrick | last post by:
My problem consits of the following:- i am creating mulitple picturebox's, when the user double clicks on the picture box it opens the opendialog box to load a picture (jpeg only) into the picture...
0
by: phanibiddu | last post by:
How to draw on windows form and save it as Jpeg file I am trying with this code but not comming public Form3() { InitializeComponent(); //rnd = new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.