⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsxmlreadwrite.java

📁 用JAVA编写的绘图程序 功能简介: 支持存储
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package drawsmart.itsv.tool;

import drawsmart.itsv.framework.JDSXMLReadWriteface;
import java.io.File;
import drawsmart.itsv.framework.JDSComponentface;
import drawsmart.itsv.framework.JDSLineface;
import drawsmart.itsv.framework.JDSDesktopface;
import org.jdom.*;
import java.io.*;
import drawsmart.itsv.tool.GetResource;
import drawsmart.itsv.swing.*;
import java.awt.Rectangle;
import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.util.Iterator;
import drawsmart.itsv.model.SetupDataModel;
import java.util.Vector;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class DSXMLReadWrite
    implements JDSXMLReadWriteface {

  //换行符
  String newline = System.getProperty("line.separator");

  //生成XML文档
  String encoding = GetResource.getXMLResource("encoding");

  public DSXMLReadWrite() {
  }

  /**
   *
   * @param filepath File
   * @param jDSComponentfaces JDSComponentface[]
   * @param jDSLinefaces JDSLineface[]
   * @todo Implement this drawsmart.itsv.framework.JDSXMLReadWriteface method
   */
  public void insertElement(File filepath, JDSDesktopface jDSDesktopface) {
    JDSComponentface[] jDSComponentfaces=jDSDesktopface.getJDSAllComponent();
    JDSLineface[] jDSLinefaces=jDSDesktopface.getJDSAllLineface();
    HashMap hashMap=jDSDesktopface.getHashMap();

    FileInputStream fileInputStream = null;
    FileOutputStream fileOutputStream = null;
    try {
      org.jdom.input.SAXBuilder sb = new org.jdom.input.SAXBuilder();
      //创建文档
      fileInputStream = new FileInputStream(filepath);
      Document doc = sb.build(fileInputStream);
      //获得这个文档得跟元素
      Element el = doc.getRootElement();
      for (int i = 0; i < jDSComponentfaces.length; i++) {
        Element jDSComponentface = new Element("JDSComponentface");

        String tag = "";

        String textinfo = "";

        String sID="";

        Color fillColor = null;

        Color frameColor = null;

        if (jDSComponentfaces[i] instanceof DSExtendRectangleSpace) {
          tag = "RectangleSpace";
        }
        else if (jDSComponentfaces[i] instanceof DSExtendElipse) {
          tag = "Elipse";
        }
        else if (jDSComponentfaces[i] instanceof DSExtendRectangleDiamond) {
          tag = "Diamond";
        }
        else if (jDSComponentfaces[i] instanceof DSExtendRectangleStar) {
          tag = "Star";
        }

        textinfo = jDSComponentfaces[i].getTextInfo();

        fillColor = jDSComponentfaces[i].getFillColor();
        int fillColor_RGB = fillColor.getRGB();

        frameColor = jDSComponentfaces[i].getFrameColor();
        int frameColor_RGB = frameColor.getRGB();

        sID=jDSComponentfaces[i].getComponentID();

        Rectangle rectangle = jDSComponentfaces[i].getRectSize();
        int x = (int) rectangle.getX();
        int y = (int) rectangle.getY();
        int w = (int) rectangle.getWidth();
        int h = (int) rectangle.getHeight();
        jDSComponentface.setAttribute("x", "" + x);
        jDSComponentface.setAttribute("y", "" + y);
        jDSComponentface.setAttribute("w", "" + w);
        jDSComponentface.setAttribute("h", "" + h);

        jDSComponentface.setAttribute("style", tag);
        jDSComponentface.setAttribute("textinfo", textinfo);
        jDSComponentface.setAttribute("fillcolor", "" + fillColor_RGB);
        jDSComponentface.setAttribute("framecolor", "" + frameColor_RGB);
        //写入唯一标示符
        jDSComponentface.setAttribute("ID", sID);


        el.addContent("    ");
        el.addContent(jDSComponentface);
        el.addContent(newline);
      }
      //写入所有的直线
      for (int i = 0; i < jDSLinefaces.length; i++) {
        JDSLineface jDSLinefaceComponent = jDSLinefaces[i];
        JDSComponentface jDSComponentfaceEnd = jDSLinefaceComponent.
            getJDSComponentEnd();
        JDSComponentface jDSComponentfaceStart = jDSLinefaceComponent.
            getJDSComponentStart();

        String sID_s = jDSComponentfaceStart.getComponentID();
        String sID_e = jDSComponentfaceEnd.getComponentID();
        //写入所有的属性值
        Element jDSLineface = new Element("JDSLineface");

        jDSLineface.setAttribute("start",sID_s);
        jDSLineface.setAttribute("end",sID_e);

        el.addContent("    ");
        el.addContent(jDSLineface);
        el.addContent(newline);

      }
      //写入环节配置
      //测试
      Set set = hashMap.keySet();
      Iterator iterator = set.iterator();
      while (iterator.hasNext()) {
        String str1 = iterator.next().toString();
        //System.out.println(str1);
        SetupDataModel setupDataModel=(SetupDataModel)hashMap.get(str1);
        //描述
        String str2=setupDataModel.getDescribe();
        if(str2.indexOf(newline)>-1)
          str2=str2.replaceAll(newline,"@");
        else
          str2=str2.replaceAll("\n","@");
        //开始时间
        String str3=setupDataModel.getStartdate();
        //结束时间
        String str4=setupDataModel.getEnddate();
        //责任人
        Vector vector=setupDataModel.getVector();
        String strVec="";
        for(int v=0;v<vector.size();v++)
        {
          strVec=strVec+vector.get(v).toString()+"@";
        }
        if(strVec.length()>1)
          strVec=strVec.substring(0,strVec.length()-1);
        strVec=strVec.trim();

        Element tacheData = new Element("TacheData");
        tacheData.setAttribute("ID",str1);
        tacheData.setAttribute("Describe",str2);
        tacheData.setAttribute("Startdate",str3);
        tacheData.setAttribute("Enddate",str4);
        tacheData.setAttribute("Principal",strVec);

        el.addContent("    ");
        el.addContent(tacheData);
        el.addContent(newline);
      }
    //hashMap.get

      //写入文件
      org.jdom.output.XMLOutputter xml = new org.jdom.output.XMLOutputter("", false,
          encoding);
      fileOutputStream = new FileOutputStream(filepath);
      xml.output(doc, fileOutputStream);
    }
    catch (Exception e) {
      System.out.println(e);
    }
    if (fileInputStream != null) {
      try {
        fileInputStream.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (fileOutputStream != null) {
      try {
        fileOutputStream.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }

  }

  /**
   *
   * @param file File
   * @param jDSExtendDesktopface JDSExtendDesktopface
   * @todo Implement this drawsmart.itsv.framework.JDSXMLReadWriteface method
   */
  public void openElement(File file, JDSDesktopface jDSDesktopface) {
    HashMap hashMap=new HashMap();
    FileInputStream fileInputStream = null;
    try {
      org.jdom.input.SAXBuilder sb = new org.jdom.input.SAXBuilder();
      //创建文档
      fileInputStream = new FileInputStream(file);
      Document doc = sb.build(fileInputStream);
      //获得这个文档得跟元素
      Element el = doc.getRootElement();
      java.util.List list = el.getChildren();
      for (int i = 0; i < list.size(); i++) {
        Element jds = (Element) list.get(i);
        if (jds.getName().trim().equals("JDSComponentface")) {
          JDSComponentface jDSComponentface = null;
          //jds.getAttribute("x");
          int x = Integer.parseInt(jds.getAttribute("x").getValue());
          int y = Integer.parseInt(jds.getAttribute("y").getValue());
          int w = Integer.parseInt(jds.getAttribute("w").getValue());
          int h = Integer.parseInt(jds.getAttribute("h").getValue());

          String tag = jds.getAttribute("style").getValue();
          String textinfo = jds.getAttribute("textinfo").getValue();
          String sfillcolor = jds.getAttribute("fillcolor").getValue();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -