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

📄 graphtoxgmmlsaxhandler.java

📁 OpenJGraph是一个开源的Java库
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
         */        public void endSerializeEdge( Edge edge ) throws Exception {            this.commonHandler.endSerializeEdge( edge );        }        /**         * Calls <tt>CommonHandler.endSerialize()</tt>         */        public void endSerialize() throws Exception {            this.commonHandler.endSerialize();        }    }    /**     * Inner class delegate of <tt>GraphToXGMMLSAXHandler</tt> for     * serializing <tt>VisualGraph</tt> objects and not <tt>Graph</tt> objects.     *     * @author  Jesus M. Salvo Jr.     */    class VisualGraphHandler extends GraphToXGMMLSAXHandler {        private VisualGraph     vGraph;        private CommonHandler   commonHandler;        private GraphHandler    graphHandler;        public VisualGraphHandler( GraphToXMLEventGenerator eventGenerator,                XMLSerializer serializer, CommonHandler commonHandler ) {            super( eventGenerator, serializer );            this.commonHandler = commonHandler;            this.graphHandler = new GraphHandler( eventGenerator, serializer, this.commonHandler );        }        /**         * Empty method implementation         */        public void startSerialize( Graph graph ) throws Exception {}        /**         * Serializes the <tt>&lt;graph&gt;</tt> element, including setting the         * <tt>Graphic</tt> attribute to <tt>1</tt>.         */        public void startSerialize( VisualGraph vGraph ) throws Exception {            this.vGraph = vGraph;            this.commonHandler.startSerialize( vGraph.getGraph() );            // Serialize the beginning tag of the graph element            AttributesImpl attrs = new AttributesImpl();            // Add the Graphic attribute            attrs.addAttribute( "",                XGMML.GRAPHIC_ATTRIBUTE_LITERAL, XGMML.GRAPHIC_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.BOOLEAN_TYPE_STRINGPOOL_INDEX ),                this.commonHandler.sPool.toString( this.commonHandler.ONE_LITERAL_STRINGPOOL_INDEX ));            // Add the Vendor attribute            attrs.addAttribute( "",                XGMML.VENDOR_ATTRIBUTE_LITERAL, XGMML.VENDOR_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                this.commonHandler.sPool.toString( this.commonHandler.OPENJGRAPH_LITERAL_STRINGPOOL_INDEX ));            // Add the directed attribute            attrs.addAttribute( "",                XGMML.DIRECTED_ATTRIBUTE_LITERAL, XGMML.DIRECTED_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.BOOLEAN_TYPE_STRINGPOOL_INDEX ),                vGraph.getGraph() instanceof DirectedGraph ?                    this.commonHandler.sPool.toString( this.commonHandler.ONE_LITERAL_STRINGPOOL_INDEX ) :                    this.commonHandler.sPool.toString( this.commonHandler.ZERO_LITERAL_STRINGPOOL_INDEX ));            this.commonHandler.getReaderAdapter().startElement( "",                XGMML.GRAPH_ELEMENT_LITERAL, XGMML.GRAPH_ELEMENT_LITERAL, attrs );            // Serialize the att element for other meta information about the graph            this.commonHandler.serializeOtherGraphMetaInformation();            // =============NOTE: Need to also serialize vertexPainterFactory,            // ============= EdgePainterFactory, and componentEditorFactory            // Serialize the layoutmanager            attrs.clear();            // Add the name attribute            attrs.addAttribute( "",                XGMML.NAME_ATTRIBUTE_LITERAL, XGMML.NAME_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                "layoutManager" );            // Add the type attribute            attrs.addAttribute( "",                XGMML.TYPE_ATTRIBUTE_LITERAL, XGMML.TYPE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                "string" );            // Add the type attribute            attrs.addAttribute( "",                XGMML.VALUE_ATTRIBUTE_LITERAL, XGMML.VALUE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                this.vGraph.getGraphLayoutManager().getClass().getName() );            this.commonHandler.getReaderAdapter().startElement( "",                XGMML.ATT_ELEMENT_LITERAL, XGMML.ATT_ELEMENT_LITERAL, attrs );            this.commonHandler.getReaderAdapter().endElement( "",                XGMML.ATT_ELEMENT_LITERAL, XGMML.ATT_ELEMENT_LITERAL);        }        /**         * Serializes the <tt>&lt;node&gt;</tt> element, including the         * &ltgraphics&gt; element that describes the visual properties of the         * <tt>VisualVertex</tt> as allowed by XGMML.         * <p>         * The corresponding <tt>VisualVertex</tt> of the specified <tt>Vertex</tt>         * is obtained via tt>VisualGraph.getVisualVertex()</tt>.         */        public void serializeVertex( Vertex vertex ) throws Exception {            XMLReaderAdapter    readerAdapter = this.commonHandler.getReaderAdapter();            AttributesImpl  attrs = new AttributesImpl();            this.graphHandler.serializeVertex( vertex );            VisualVertex vVertex = this.vGraph.getVisualVertex( vertex );            java.awt.geom.Rectangle2D bounds = vVertex.getBounds2D();            attrs.addAttribute( "",                XGMML.WIDTH_ATTRIBUTE_LITERAL, XGMML.WIDTH_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                Double.toString(bounds.getWidth()) );            attrs.addAttribute( "",                XGMML.HEIGHT_ATTRIBUTE_LITERAL, XGMML.HEIGHT_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                Double.toString(bounds.getHeight()) );            attrs.addAttribute( "",                XGMML.FONT_ATTRIBUTE_LITERAL, XGMML.FONT_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                vVertex.getFont().getName() );            attrs.addAttribute( "",                XGMML.VISIBLE_ATTRIBUTE_LITERAL, XGMML.VISIBLE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                "true" );            attrs.addAttribute( "",                XGMML.FILL_ATTRIBUTE_LITERAL, XGMML.FILL_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                Integer.toHexString( vVertex.getFillcolor().getRGB()) );            attrs.addAttribute( "",                XGMML.OUTLINE_ATTRIBUTE_LITERAL, XGMML.OUTLINE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                Integer.toHexString( vVertex.getOutlinecolor().getRGB()) );            readerAdapter.startElement( "",                XGMML.GRAPHICS_ELEMENT_LITERAL, XGMML.GRAPHICS_ELEMENT_LITERAL, attrs );            attrs.clear();            attrs.addAttribute( "",                XGMML.X_ATTRIBUTE_LITERAL, XGMML.X_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                Double.toString(bounds.getCenterX()) );            attrs.addAttribute( "",                XGMML.Y_ATTRIBUTE_LITERAL, XGMML.Y_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                Double.toString(bounds.getCenterY()) );            readerAdapter.startElement( "",                XGMML.CENTER_ELEMENT_LITERAL, XGMML.CENTER_ELEMENT_LITERAL, attrs );            readerAdapter.endElement( "",                XGMML.CENTER_ELEMENT_LITERAL, XGMML.CENTER_ELEMENT_LITERAL );            attrs.clear();            attrs.addAttribute( "",                XGMML.NAME_ATTRIBUTE_LITERAL, XGMML.NAME_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                "className" );            attrs.addAttribute( "",                XGMML.TYPE_ATTRIBUTE_LITERAL, XGMML.TYPE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ));            attrs.addAttribute( "",                XGMML.VALUE_ATTRIBUTE_LITERAL, XGMML.VALUE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                vVertex.getClass().getName() );            readerAdapter.startElement( "",                XGMML.ATT_ELEMENT_LITERAL, XGMML.ATT_ELEMENT_LITERAL, attrs );            readerAdapter.endElement( "",                XGMML.ATT_ELEMENT_LITERAL, XGMML.ATT_ELEMENT_LITERAL );            attrs.clear();            attrs.addAttribute( "",                XGMML.NAME_ATTRIBUTE_LITERAL, XGMML.NAME_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                "painter" );            attrs.addAttribute( "",                XGMML.TYPE_ATTRIBUTE_LITERAL, XGMML.TYPE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ));            attrs.addAttribute( "",                XGMML.VALUE_ATTRIBUTE_LITERAL, XGMML.VALUE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                vVertex.getPainter().getClass().getName());            readerAdapter.startElement( "",                XGMML.ATT_ELEMENT_LITERAL, XGMML.ATT_ELEMENT_LITERAL, attrs );            readerAdapter.endElement( "",                XGMML.ATT_ELEMENT_LITERAL, XGMML.ATT_ELEMENT_LITERAL );            readerAdapter.endElement( "",                XGMML.GRAPHIC_ATTRIBUTE_LITERAL, XGMML.GRAPHIC_ATTRIBUTE_LITERAL);        }        /**         * Calls <tt>CommonHandler.endSerializeVertex()</tt>         */        public void endSerializeVertex( Vertex vertex ) throws Exception {            this.commonHandler.endSerializeVertex( vertex );        }        /**         * Serializes the <tt>&lt;edge&gt;</tt> element, including the         * &ltgraphics&gt; element that describes the visual properties of the         * <tt>VisualEdge</tt> as allowed by XGMML.         * <p>         * The corresponding <tt>VisualEdge</tt> of the specified <tt>Edge</tt>         * is obtained via tt>VisualGraph.getVisualEdge()</tt>.         */        public void serializeEdge( Edge edge ) throws Exception {            XMLReaderAdapter    readerAdapter = this.commonHandler.getReaderAdapter();            AttributesImpl      attrs = new AttributesImpl();            this.graphHandler.serializeEdge( edge );            VisualEdge vEdge = this.vGraph.getVisualEdge( edge );            attrs.addAttribute( "",                XGMML.FONT_ATTRIBUTE_LITERAL, XGMML.FONT_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                vEdge.getFont().getName() );            attrs.addAttribute( "",                XGMML.VISIBLE_ATTRIBUTE_LITERAL, XGMML.VISIBLE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                "true" );            attrs.addAttribute( "",                XGMML.FILL_ATTRIBUTE_LITERAL, XGMML.FILL_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                Integer.toHexString( vEdge.getFillcolor().getRGB()) );            attrs.addAttribute( "",                XGMML.OUTLINE_ATTRIBUTE_LITERAL, XGMML.OUTLINE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                Integer.toHexString( vEdge.getOutlinecolor().getRGB()) );            readerAdapter.startElement( "",                XGMML.GRAPHICS_ELEMENT_LITERAL, XGMML.GRAPHICS_ELEMENT_LITERAL, attrs );            readerAdapter.startElement( "",                XGMML.LINE_ELEMENT_LITERAL, XGMML.LINE_ELEMENT_LITERAL,                new AttributesImpl());            double edgeSegment[] = new double[6];            java.awt.geom.PathIterator pathIterator =                vEdge.getGeneralPath().getPathIterator( null );            while( !pathIterator.isDone() ) {                int segmentType = pathIterator.currentSegment( edgeSegment );                if( segmentType != java.awt.geom.PathIterator.SEG_CLOSE ) {                    attrs.clear();                    attrs.addAttribute( "",                        XGMML.X_ATTRIBUTE_LITERAL, XGMML.X_ATTRIBUTE_LITERAL,                        this.commonHandler.sPool.toString( this.commonHandler.DOUBLE_TYPE_STRINGPOOL_INDEX ),                        Double.toString( edgeSegment[0] ));                    attrs.addAttribute( "",                        XGMML.Y_ATTRIBUTE_LITERAL, XGMML.Y_ATTRIBUTE_LITERAL,                        this.commonHandler.sPool.toString( this.commonHandler.DOUBLE_TYPE_STRINGPOOL_INDEX ),                        Double.toString( edgeSegment[1] ));                    readerAdapter.startElement( "",                        XGMML.POINT_ELEMENT_LITERAL, XGMML.POINT_ELEMENT_LITERAL,                        attrs );                    readerAdapter.endElement( "",                        XGMML.POINT_ELEMENT_LITERAL, XGMML.POINT_ELEMENT_LITERAL );                }                pathIterator.next();            }            readerAdapter.endElement( "",                XGMML.LINE_ELEMENT_LITERAL, XGMML.LINE_ELEMENT_LITERAL );            attrs.clear();            attrs.addAttribute( "",                XGMML.NAME_ATTRIBUTE_LITERAL, XGMML.NAME_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                "className" );            attrs.addAttribute( "",                XGMML.TYPE_ATTRIBUTE_LITERAL, XGMML.TYPE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ));            attrs.addAttribute( "",                XGMML.VALUE_ATTRIBUTE_LITERAL, XGMML.VALUE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                vEdge.getClass().getName() );            readerAdapter.startElement( "",                XGMML.ATT_ELEMENT_LITERAL, XGMML.ATT_ELEMENT_LITERAL, attrs );            readerAdapter.endElement( "",                XGMML.ATT_ELEMENT_LITERAL, XGMML.ATT_ELEMENT_LITERAL );            attrs.clear();            attrs.addAttribute( "",                XGMML.NAME_ATTRIBUTE_LITERAL, XGMML.NAME_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                "painter" );            attrs.addAttribute( "",                XGMML.TYPE_ATTRIBUTE_LITERAL, XGMML.TYPE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ));            attrs.addAttribute( "",                XGMML.VALUE_ATTRIBUTE_LITERAL, XGMML.VALUE_ATTRIBUTE_LITERAL,                this.commonHandler.sPool.toString( this.commonHandler.STRING_TYPE_STRINGPOOL_INDEX ),                vEdge.getPainter().getClass().getName());            readerAdapter.startElement( "",                XGMML.ATT_ELEMENT_LITERAL, XGMML.ATT_ELEMENT_LITERAL, attrs );            readerAdapter.endElement( "",                XGMML.ATT_ELEMENT_LITERAL, XGMML.ATT_ELEMENT_LITERAL );            readerAdapter.endElement( "",                XGMML.GRAPHIC_ATTRIBUTE_LITERAL, XGMML.GRAPHIC_ATTRIBUTE_LITERAL );        }        /**         * Calls <tt>CommonHandler.endSerializeEdge()</tt>         */        public void endSerializeEdge( Edge edge ) throws Exception {            this.commonHandler.endSerializeEdge( edge );        }        /**         * Calls <tt>CommonHandler.endSerialize</tt>         */        public void endSerialize() throws Exception {            this.commonHandler.endSerialize();        }    }}

⌨️ 快捷键说明

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