/* * GraphicEditExport.java * * Created on 24 czerwiec 2003, 01:48 */ package com.obrctm.openmap.editor; import java.io.*; import javax.swing.*; import java.util.*; import java.awt.*; import com.bbn.openmap.Environment; import com.bbn.openmap.omGraphics.*; /** * * @author kpiot */ public class GraphicEditImport { /** * The path where the files should be written. */ protected String fileName = "NoName"; /** Creates a new instance of GraphicEditImport */ public GraphicEditImport() { } public OMGraphicList importFromFile() { String lFilePath = getFilePathFromUser(); if (lFilePath == null) return null; fileName = lFilePath; return importFromFile(lFilePath); } public OMGraphicList importFromFile(String inputFileName) { try { ObjectInputStream in = new ObjectInputStream(new FileInputStream(inputFileName)); String opis = (String)in.readObject(); OMGraphicList list = (OMGraphicList)in.readObject(); Iterator ite = list.iterator(); while(ite.hasNext()) { BasicStroke lBasicStroke = new BasicStroke(in.readFloat(),in.readInt(),in.readInt(),in.readFloat(),(float[])in.readObject(),in.readFloat()); OMGraphic lOMGraphic = (OMGraphic)ite.next(); lOMGraphic.setStroke((Stroke)lBasicStroke); if (lOMGraphic instanceof OMRangeRings) { ((OMRangeRings)lOMGraphic).setNeedToRegenerate(true); // Działa poprawnie równiez bez jawnego przywrócenia poniższych parametrow, chociaż // w klasie com.bbn.openmap.omGraphic.DrawingAttributes pola: // protected Stroke stroke = null; // oraz // protected BasicStrokeEditor bse; // należy ustawić na transient !!!!! // protected transient Stroke stroke = null; // oraz // protected transient BasicStrokeEditor bse; // ((OMRangeRings)lOMGraphic).drawingAttributes.setStroke((Stroke)lBasicStroke); // ((OMRangeRings)lOMGraphic).drawingAttributes.getBasicStrokeEditor(); } } return(list); // list.generate(getProjection()); // setList(list); } catch (Exception e) { e.printStackTrace(); } return null; } /** * Fetches a file path from the user, via a JFileChooser. Returns * null if the user cancels. */ public String getFilePathFromUser() { String ret = null; try { //setup the file chooser File startingPoint = new File(Environment.get("lastchosendirectory", System.getProperty("user.home"))); JFileChooser chooser = new JFileChooser(startingPoint); chooser.setDialogTitle("Select GraphicEditorFile Set Name..."); int state = chooser.showSaveDialog(null); //only bother trying to read the file if there is one //for some reason, the APPROVE_OPTION said it was a //boolean during compile and didn't work in this next //statement if ((state != JFileChooser.CANCEL_OPTION) && (state != JFileChooser.ERROR_OPTION)) { ret = chooser.getSelectedFile().getCanonicalPath(); //store the selected file for later Environment.set("lastchosendirectory", ret); } else { // no need to try to continue if the user doesn't // actually pick a filename } } catch (IOException ioe) { StringBuffer sb = new StringBuffer("GraphicEditor Import Error:"); sb.append("\nProblem with open the graphiceditorfile get."); sb.append("\n" + ioe.toString()); JOptionPane.showMessageDialog(null, sb.toString(), "GraphicEditor Import from File", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } return ret; } }