private Text makeText(Element textNode, ClassGraphics graphics) { String str = textNode.getAttribute(ATR_STRING); String fontName = textNode.getAttribute(ATR_FONTNAME); int fontStyle = Integer.parseInt(textNode.getAttribute(ATR_FONTSTYLE)); int fontSize = Integer.parseInt(textNode.getAttribute(ATR_FONTSIZE)); Font font = new Font(fontName, fontStyle, fontSize); FixedCoords fc = getFixedCoords(textNode, graphics.getBoundWidth(), graphics.getBoundHeight(), null); Text newText = new Text(fc.x, fc.y, font, getColor(textNode), str, isShapeFixed(textNode)); newText.setFixedX(fc.fx); newText.setFixedY(fc.fy); return newText; }
private Element generateGraphicsNode(Document doc, ClassGraphics gr) { Element graphicsEl = doc.createElement(EL_GRAPHICS); Element bounds = doc.createElement(EL_BOUNDS); graphicsEl.appendChild(bounds); bounds.setAttribute(ATR_X, Integer.toString(gr.getBoundX())); bounds.setAttribute(ATR_Y, Integer.toString(gr.getBoundY())); bounds.setAttribute(ATR_WIDTH, Integer.toString(gr.getBoundWidth())); bounds.setAttribute(ATR_HEIGHT, Integer.toString(gr.getBoundHeight())); for (Shape shape : gr.getShapes()) { if (shape instanceof Rect) { Rect rect = (Rect) shape; Element rectEl = doc.createElement(EL_RECT); graphicsEl.appendChild(rectEl); rectEl.setAttribute(ATR_X, Integer.toString(rect.getX())); rectEl.setAttribute(ATR_Y, Integer.toString(rect.getY())); rectEl.setAttribute(ATR_WIDTH, Integer.toString(rect.getWidth())); rectEl.setAttribute(ATR_HEIGHT, Integer.toString(rect.getHeight())); rectEl.setAttribute(ATR_COLOUR, Integer.toString(rect.getColor().getRGB())); rectEl.setAttribute(ATR_FILLED, Boolean.toString(rect.isFilled())); rectEl.setAttribute(ATR_FIXED, Boolean.toString(rect.isFixed())); rectEl.setAttribute(ATR_STROKE, Float.toString(rect.getStroke().getLineWidth())); rectEl.setAttribute(ATR_LINETYPE, Float.toString(rect.getLineType())); rectEl.setAttribute(ATR_TRANSPARENCY, Integer.toString(rect.getTransparency())); } else if (shape instanceof Text) { Text text = (Text) shape; Element textEl = doc.createElement(EL_TEXT); textEl.setAttribute(ATR_STRING, text.getText()); textEl.setAttribute(ATR_X, Integer.toString(text.getX())); textEl.setAttribute(ATR_Y, Integer.toString(text.getY())); textEl.setAttribute(ATR_FONTNAME, text.getFont().getName()); textEl.setAttribute(ATR_FONTSIZE, Integer.toString(text.getFont().getSize())); textEl.setAttribute(ATR_FONTSTYLE, Integer.toString(text.getFont().getStyle())); textEl.setAttribute(ATR_TRANSPARENCY, Integer.toString(text.getTransparency())); textEl.setAttribute(ATR_COLOUR, Integer.toString(text.getColor().getRGB())); graphicsEl.appendChild(textEl); } // TODO handle the rest of shapes } return graphicsEl; }