public void read(StorableInput dr) throws IOException { super.read(dr); Connector start = (Connector) dr.readStorable(); if (start != null) { connectStart(start); } Connector end = (Connector) dr.readStorable(); if (end != null) { connectEnd(end); } if ((start != null) && (end != null)) { updateConnection(); } }
/** * Reads the attributes from a StorableInput. FigureAttributes store the following types directly: * Color, Boolean, String, Int. Other attribute types have to implement the Storable interface or * they have to be wrapped by an object that implements Storable. * * @see Storable * @see #write */ public void read(StorableInput dr) throws IOException { String s = dr.readString(); if (!s.toLowerCase().equals("attributes")) { throw new IOException("Attributes expected"); } fMap = new Hashtable(); int size = dr.readInt(); for (int i = 0; i < size; i++) { String key = dr.readString(); String valtype = dr.readString(); Object val = null; if (valtype.equals("Color")) { val = new Color(dr.readInt(), dr.readInt(), dr.readInt()); } else if (valtype.equals("Boolean")) { val = new Boolean(dr.readString()); } else if (valtype.equals("String")) { val = dr.readString(); } else if (valtype.equals("Int")) { val = new Integer(dr.readInt()); } else if (valtype.equals("Storable")) { val = dr.readStorable(); } else if (valtype.equals(Figure.POPUP_MENU)) { // read String but don't store it continue; } else if (valtype.equals("UNKNOWN")) { continue; } fMap.put(key, val); } }
/** * Restore a Drawing from a file with a given name. * * @param fileName of the file in which the Drawing has been saved * @return restored Drawing */ public Drawing restore(String fileName) throws IOException { if (!hasCorrectFileExtension(fileName)) { return null; } else { FileInputStream stream = new FileInputStream(fileName); StorableInput input = new StorableInput(stream); return (Drawing) input.readStorable(); } }
private void readFromStorableInput(String filename) { try { URL url = new URL(getCodeBase(), filename); InputStream stream = url.openStream(); StorableInput input = new StorableInput(stream); fDrawing.release(); fDrawing = (Drawing) input.readStorable(); view().setDrawing(fDrawing); } catch (IOException e) { initDrawing(); showStatus("Error:" + e); } }
/** Reads the contained figures from StorableInput. */ public void read(StorableInput dr) throws IOException { super.read(dr); int size = dr.readInt(); fFigures = new Vector(size); for (int i = 0; i < size; i++) add((Figure) dr.readStorable()); }
/** Reads the arrow tip from a StorableInput. */ public void read(StorableInput dr) throws IOException { super.read(dr); fLocator = (Locator) dr.readStorable(); }