private void addCreationButtonsTo(JToolBar tb, final DrawingEditor editor) { // AttributeKeys for the entitie sets HashMap<AttributeKey, Object> attributes; ResourceBundleUtil drawLabels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); ButtonFactory.addSelectionToolTo( tb, editor, ButtonFactory.createDrawingActions(editor), createSelectionActions(editor)); tb.addSeparator(); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.FILL_COLOR, Color.white); attributes.put(AttributeKeys.STROKE_COLOR, Color.black); ButtonFactory.addToolTo( tb, editor, new CreationTool(new SVGRectFigure(), attributes), "edit.createRectangle", drawLabels); ButtonFactory.addToolTo( tb, editor, new CreationTool(new SVGEllipseFigure(), attributes), "edit.createEllipse", drawLabels); ButtonFactory.addToolTo( tb, editor, new PathTool(new SVGPathFigure(), new SVGBezierFigure(true), attributes), "edit.createPolygon", drawLabels); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.FILL_COLOR, null); attributes.put(AttributeKeys.STROKE_COLOR, Color.black); ButtonFactory.addToolTo( tb, editor, new CreationTool(new SVGPathFigure(), attributes), "edit.createLine", drawLabels); ButtonFactory.addToolTo( tb, editor, new PathTool(new SVGPathFigure(), new SVGBezierFigure(false), attributes), "edit.createScribble", drawLabels); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.FILL_COLOR, Color.black); attributes.put(AttributeKeys.STROKE_COLOR, null); ButtonFactory.addToolTo( tb, editor, new CreationTool(new SVGTextFigure(), attributes), "edit.createText", drawLabels); TextAreaCreationTool tat = new TextAreaCreationTool(new SVGTextAreaFigure(), attributes); tat.setRubberbandColor(Color.BLACK); ButtonFactory.addToolTo(tb, editor, tat, "edit.createTextArea", drawLabels); }
public static Map<String, String> getStyles(String str) throws IOException { HashMap<String, String> styles = new HashMap<String, String>(); if (str == null) return styles; StreamTokenizer tt = new StreamTokenizer(new StringReader(str)); tt.resetSyntax(); tt.wordChars('!', '9'); tt.wordChars('<', '~'); tt.wordChars(128 + 32, 255); tt.whitespaceChars(0, ' '); while (tt.nextToken() != StreamTokenizer.TT_EOF) { if (tt.ttype != ';') { String key, value; if (tt.ttype != StreamTokenizer.TT_WORD) { throw new IOException( "Key token expected in " + str + " " + Integer.toHexString(tt.ttype)); } key = tt.sval; if (tt.nextToken() != ':') { throw new IOException("Colon expected after " + key + " in " + str); } if (tt.nextToken() != StreamTokenizer.TT_WORD) { throw new IOException( "Value token expected after " + key + " in " + str + " " + tt.ttype); } value = tt.sval; while (tt.nextToken() == StreamTokenizer.TT_WORD) { value += ' ' + tt.sval; } tt.pushBack(); styles.put(key, value); } } return styles; }