Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: gef/src/org/tigris/gef/base CmdSaveSVG.java

gef
Discussion topic

Back to topic list

CVS update: gef/src/org/tigris/gef/base CmdSaveSVG.java

Reply

Author toby
Full name Toby Baier
Date 2001-03-12 07:09:05 PST
Message User: toby
  Date: 01/03/12 07:09:04

  Modified: src/org/tigris/gef/base CmdSaveSVG.java
  Log:
  reverted CmdSaveSVG to use the SVGWriter, not the TEE.
  Obtained from:Toby
  Submitted by:Toby
  
  Revision Changes Path
  1.2 +27 -105 gef/src/org/tigris/g​ef/base/CmdSaveSVG.j​ava
  
  Index: CmdSaveSVG.java
  ====================​====================​====================​=======
  RCS file: /cvs/gef/src/org/tig​ris/gef/base/CmdSave​SVG.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CmdSaveSVG.java 2000/09/04 12:38:47 1.1
  +++ CmdSaveSVG.java 2001/03/12 15:09:04 1.2
  @@ -1,5 +1,3 @@
  -package org.tigris.gef.base;
  -
   // Copyright (c) 1996-99 The Regents of the University of California. All
   // Rights Reserved. Permission to use, copy, modify, and distribute this
   // software and its documentation without fee, and without a written
  @@ -23,116 +21,40 @@
   // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
   // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
   
  +// File: CmdSaveSVG.java
  +// Classes: CmdSaveSVG
   
  -// File: CmdSave.java
  -// Classes: CmdSave
  -// Original Author: jrobbins at ics dot uci dot edu
  -// $Id: CmdSaveSVG.java,v 1.1 2000/09/04 12:38:47 1sturm Exp $
  +package org.tigris.gef.base;
   
   import java.util.*;
  -import java.awt.*;
   import java.io.*;
  +import java.awt.Rectangle;
   
  -import org.tigris.gef.ocl.*;
  +import org.tigris.gef.persistence.*;
   
  -/** Cmd to save the current document to a binary file using Sun's
  - * ObjectSerialization library. The written file contains the Editor
  - * object and all objects reachable through instance variables of the
  - * Editor (e.g., the selections, the views, the contents of the
  - * views, the net-level description of the graph, etc.). UI objects
  - * such as Windows, Frames, Panels, and Images are not stored because
  - * I have marked those instance variables as transient in the source
  - * code. <p>
  - *
  - * One advantage of this approach to saving and loading is that
  - * developers using GEF can add subclasses (e.g., to NetNode) which
  - * introduce new instance variables, and those will be saved and
  - * loaded without the developers having to special load and save
  - * methods. However, make sure that you do not point to any AWT
  - * objects unless those instance variables are transient because those
  - * cannot be saved. <p>
  - *
  - * Needs-More-Work: the files produced by a save are not really good
  - * for anything other than reloading into this tool, or another Java
  - * program that uses ObjectSerialization. At this time GEF provides no
  - * support for saving or loading textual representations of documents
  - * that could be used in other tools.<p>
  - *
  - * @see CmdOpen */
  -
  -public class CmdSaveSVG extends Cmd implements FilenameFilter {
  -
  - protected static Hashtable _templates = new Hashtable();
  - protected static OCLExpander _expander = null;
  -
  - static {
  - _templates = TemplateReader.readF​ile("/org/tigris/gef​/xml/dtd/SVG.tee");
  - _expander = new OCLExpander(_templates);
  - }
   
  +public class CmdSaveSVG extends CmdSaveGraphics {
   
  - public CmdSaveSVG() { super("Save as SVG...", NO_ICON); }
  - /** Only allow the user to select files that match the fiven
  - * filename pattern. Needs-More-Work: this is not used yet. */
  - public CmdSaveSVG(String filterPattern) {
  - this();
  - setArg("filterPattern", filterPattern);
  - }
  - /** Only let the user select files that match the filter. This does
  - * not seem to be called under JDK 1.0.2 on solaris. I have not
  - * finished this method, it currently accepts all filenames. <p>
  - *
  - * Needs-More-Work: the source code for this method is duplicated in
  - * CmdOpen#accept. */
  - public boolean accept(File dir, String name) {
  - System.out.println("checking: "+ dir + " " + name);
  - if (containsArg("filterPattern")) {
  - // if pattern dosen't match, return false
  - return true;
  - }
  - return true; // no pattern was specified
  - }
  - public void doIt() {
  - //@@@ just for easy debugging
  - _templates = TemplateReader.readF​ile("/org/tigris/gef​/xml/dtd/SVG.tee");
  - _expander = new OCLExpander(_templates);
  -
  - try {
  - Editor ce = Globals.curEditor();
  - Diagram d = new Diagram("junk", ce.getGraphModel(),
  - (LayerPerspective) ce.getLayerManager()​.getActiveLayer());
  - FileDialog fd = new
  - FileDialog(ce.findFrame(), "Save Diagram in SVG format", FileDialog.SAVE);
  - fd.setFilenameFilter(this);
  - fd.setDirectory(Glob​als.getLastDirectory​());
  - fd.show();
  - String filename = fd.getFile(); // blocking
  - String path = fd.getDirectory(); // blocking
  - Globals.setLastDirectory(path);
  - if (filename != null) {
  - Globals.showStatus("Writing " + path + filename + "...");
  - FileWriter fw = new FileWriter(path + filename);
  - System.out.println("Cmd save in SVG...");
  - _expander.expand(fw, d, "", "");
  - System.out.println("save done");
  - Globals.showStatus("Wrote " + path + filename);
  - fw.close();
  - //ce.setTitle(filename);
  + public CmdSaveSVG() {
  + super("Save Scalable Vector Graphics...", NO_ICON);
  + }
  +
  + protected void saveGraphics(OutputStream s, Editor ce,
  + Rectangle drawingArea)
  + throws IOException {
  + System.out.println("Writing Scalable Vector Graphics...");
  + SVGWriter writer = null;
  + try {
  + writer = new SVGWriter(s);
  + } catch (Exception e) {
  + System.out.println("Whatever this exception may be..." +e);
  + e.printStackTrace();
  + }
  + if (writer != null) {
  + ce.print(writer);
  + writer.dispose();
  + System.out.println("Wrote Scalable Vector Graphics...");
         }
  - }
  - catch (FileNotFoundException ignore) {
  - System.out.println("got an FileNotFoundException");
  - }
  - // catch (java.lang.ClassMism​atchException ignore) {
  - // System.out.println("got an ClassMismatchException");
  - // }
  - catch (IOException ignore) {
  - System.out.println("got an IOException");
  - ignore.printStackTrace();
  -
  - }
  - }
  - public void undoIt() {
  - System.out.println("Undo does not make sense for CmdSave");
  - }
  + }
  +
   } /* end class CmdSaveSVG */

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: gef/src/org/tigris/gef/base CmdSaveSVG.java toby Toby Baier 2001-03-12 07:09:05 PST
Messages per page: