001    // GraphLab Project: http://graphlab.sharif.edu
002    // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
003    // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
004    package graphlab.graph.old;
005    
006    import graphlab.platform.lang.FromStringProvider;
007    import graphlab.platform.StaticUtils;
008    
009    import java.awt.*;
010    import static java.awt.BasicStroke.CAP_BUTT;
011    import static java.awt.BasicStroke.JOIN_MITER;
012    import java.io.Serializable;
013    import java.util.Vector;
014    
015    /**
016     * User: root
017     */
018    public class GStroke implements Serializable, FromStringProvider<GStroke> {
019        static {
020            StaticUtils.setFromStringProvider(GStroke.class.getName(), new GStroke());
021        }
022    
023        /**
024         *
025         */
026        private static final long serialVersionUID = 1699990527314740484L;
027        static Vector<GStroke> strokes = new Vector<GStroke>();
028        public static GStroke empty = new GStroke("Empty", 0, new float[]{0, 100000000f});
029        public static GStroke simple = new GStroke("simple", 1, new float[]{1, 0});
030        public static GStroke solid = new GStroke("solid", new float[]{1, 0});
031        public static GStroke strong = new GStroke("strong", 4, new float[]{1, 0});
032        public static GStroke dashed = new GStroke("dashed", new float[]{6, 2});
033        public static GStroke dotted = new GStroke("dotted", new float[]{2, 4});
034        public static GStroke dashed_dotted = new GStroke("dashed-dotted", new float[]{6, 2, 2, 6});
035        public static GStroke dashed_dotted_dotted = new GStroke("dashed-dotted-dotted", new float[]{6, 2, 2, 6, 2, 6});
036        public static GStroke dashed_dashed_dotted = new GStroke("dashed-dashed-dotted", new float[]{6, 2, 6, 2, 2, 4});
037    
038        public String name;
039        public BasicStroke stroke;
040        int w = 2;
041        public static final String STROKE = "stroke";
042    
043        public GStroke(String name, float[] dashInfo) {
044            init(name, w, dashInfo);
045        }
046    
047        public GStroke(String name, int w, float[] dashInfo) {
048            init(name, w, dashInfo);
049        }
050    
051        private void init(String name, int w, float[] dashInfo) {
052            this.name = name;
053            this.stroke = new BasicStroke(w, CAP_BUTT, JOIN_MITER, 1, dashInfo, 2);
054            if (name.equals("solid") || name.equals("simple"))
055                stroke = new BasicStroke(w);
056            strokes.add(this);
057        }
058    
059        public GStroke() {
060        }
061    
062    //    Edge e;
063    
064    //    public void handleEdge(Edge e) {
065    //        this.e = e;
066    //        stroke = solid.stroke;
067    //        e.model.getAttributes().put(STROKE, solid);
068    //        e.model.addAttributeListener(this, new String[]{STROKE});
069    //        e.view.addPostPaintHandler(this);
070    //    }
071    
072        /**
073         * just changes the stroke of the graphics if nesecary
074         */
075    //    public void paint(Graphics g, Component unused) {
076    //        Graphics2D gg = ((Graphics2D) g);
077    //        if (!gg.getStroke().equals(stroke))
078    //            gg.setStroke(stroke);
079    //    }
080    
081    //    public void attributeUpdated(String name, Object oldVal, Object newVal) {
082    //        if (name.equals(STROKE)) {
083    //        stroke = ((GStroke) newVal).stroke;
084    //            Graphics g=e.view.getGraphics();
085    //            ((Graphics2D) g).setStroke(stroke);
086    //            e.view.repaint();
087    //        }
088    //    }
089        public GStroke fromString(String data) {
090            for (GStroke _ : strokes)
091                if (_.name.equals(data)) {
092    //                System.out.println(data+":"+_.name);
093                    return _;
094                }
095            return null;
096        }
097    
098        public String toString() {
099            return name;
100        }
101    }