Source Code Cross Referenced for ScatterPlot.java in  » Database-Client » prefuse » prefuse » demos » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » prefuse » prefuse.demos 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package prefuse.demos;
002:
003:        import java.awt.BorderLayout;
004:        import java.awt.event.ActionEvent;
005:        import java.awt.event.ActionListener;
006:
007:        import javax.swing.BorderFactory;
008:        import javax.swing.Box;
009:        import javax.swing.BoxLayout;
010:        import javax.swing.JComboBox;
011:        import javax.swing.JFrame;
012:        import javax.swing.JLabel;
013:        import javax.swing.JToolBar;
014:
015:        import prefuse.Constants;
016:        import prefuse.Display;
017:        import prefuse.Visualization;
018:        import prefuse.action.ActionList;
019:        import prefuse.action.RepaintAction;
020:        import prefuse.action.assignment.ColorAction;
021:        import prefuse.action.assignment.DataShapeAction;
022:        import prefuse.action.layout.AxisLayout;
023:        import prefuse.controls.ToolTipControl;
024:        import prefuse.data.Table;
025:        import prefuse.data.io.DelimitedTextTableReader;
026:        import prefuse.render.DefaultRendererFactory;
027:        import prefuse.render.ShapeRenderer;
028:        import prefuse.util.ColorLib;
029:        import prefuse.visual.VisualItem;
030:        import prefuse.visual.expression.VisiblePredicate;
031:
032:        /**
033:         * A simple scatter plot visualization that allows visual encodings to
034:         * be changed at runtime.
035:         * 
036:         * @author <a href="http://jheer.org">jeffrey heer</a>
037:         */
038:        public class ScatterPlot extends Display {
039:
040:            private static final String group = "data";
041:
042:            private ShapeRenderer m_shapeR = new ShapeRenderer(2);
043:
044:            public ScatterPlot(Table t, String xfield, String yfield) {
045:                this (t, xfield, yfield, null);
046:            }
047:
048:            public ScatterPlot(Table t, String xfield, String yfield,
049:                    String sfield) {
050:                super (new Visualization());
051:
052:                // --------------------------------------------------------------------
053:                // STEP 1: setup the visualized data
054:
055:                m_vis.addTable(group, t);
056:
057:                DefaultRendererFactory rf = new DefaultRendererFactory(m_shapeR);
058:                m_vis.setRendererFactory(rf);
059:
060:                // --------------------------------------------------------------------
061:                // STEP 2: create actions to process the visual data
062:
063:                // set up the actions
064:                AxisLayout x_axis = new AxisLayout(group, xfield,
065:                        Constants.X_AXIS, VisiblePredicate.TRUE);
066:                m_vis.putAction("x", x_axis);
067:
068:                AxisLayout y_axis = new AxisLayout(group, yfield,
069:                        Constants.Y_AXIS, VisiblePredicate.TRUE);
070:                m_vis.putAction("y", y_axis);
071:
072:                ColorAction color = new ColorAction(group,
073:                        VisualItem.STROKECOLOR, ColorLib.rgb(100, 100, 255));
074:                m_vis.putAction("color", color);
075:
076:                DataShapeAction shape = new DataShapeAction(group, sfield);
077:                m_vis.putAction("shape", shape);
078:
079:                ActionList draw = new ActionList();
080:                draw.add(x_axis);
081:                draw.add(y_axis);
082:                if (sfield != null)
083:                    draw.add(shape);
084:                draw.add(color);
085:                draw.add(new RepaintAction());
086:                m_vis.putAction("draw", draw);
087:
088:                // --------------------------------------------------------------------
089:                // STEP 3: set up a display and ui components to show the visualization
090:
091:                setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
092:                setSize(700, 450);
093:                setHighQuality(true);
094:
095:                ToolTipControl ttc = new ToolTipControl(new String[] { xfield,
096:                        yfield });
097:                addControlListener(ttc);
098:
099:                // --------------------------------------------------------------------        
100:                // STEP 4: launching the visualization
101:
102:                m_vis.run("draw");
103:
104:            }
105:
106:            public int getPointSize() {
107:                return m_shapeR.getBaseSize();
108:            }
109:
110:            public void setPointSize(int size) {
111:                m_shapeR.setBaseSize(size);
112:                repaint();
113:            }
114:
115:            // ------------------------------------------------------------------------
116:
117:            public static void main(String[] argv) {
118:                String data = "/fisher.iris.txt";
119:                String xfield = "SepalLength";
120:                String yfield = "PetalLength";
121:                String sfield = "Species";
122:                if (argv.length >= 3) {
123:                    data = argv[0];
124:                    xfield = argv[1];
125:                    yfield = argv[2];
126:                    sfield = (argv.length > 3 ? argv[3] : null);
127:                }
128:
129:                final ScatterPlot sp = demo(data, xfield, yfield, sfield);
130:                JToolBar toolbar = getEncodingToolbar(sp, xfield, yfield,
131:                        sfield);
132:
133:                JFrame frame = new JFrame("p r e f u s e  |  s c a t t e r");
134:                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
135:                frame.getContentPane().add(toolbar, BorderLayout.NORTH);
136:                frame.getContentPane().add(sp, BorderLayout.CENTER);
137:                frame.pack();
138:                frame.setVisible(true);
139:            }
140:
141:            public static ScatterPlot demo(String data, String xfield,
142:                    String yfield) {
143:                return demo(data, xfield, yfield, null);
144:            }
145:
146:            public static ScatterPlot demo(String data, String xfield,
147:                    String yfield, String sfield) {
148:                Table table = null;
149:                try {
150:                    table = new DelimitedTextTableReader().readTable(data);
151:                } catch (Exception e) {
152:                    e.printStackTrace();
153:                    return null;
154:                }
155:                ScatterPlot scatter = new ScatterPlot(table, xfield, yfield,
156:                        sfield);
157:                scatter.setPointSize(10);
158:                return scatter;
159:            }
160:
161:            private static JToolBar getEncodingToolbar(final ScatterPlot sp,
162:                    final String xfield, final String yfield,
163:                    final String sfield) {
164:                int spacing = 10;
165:
166:                // create list of column names
167:                Table t = (Table) sp.getVisualization().getSourceData(group);
168:                String[] colnames = new String[t.getColumnCount()];
169:                for (int i = 0; i < colnames.length; ++i)
170:                    colnames[i] = t.getColumnName(i);
171:
172:                // create toolbar that allows visual mappings to be changed
173:                JToolBar toolbar = new JToolBar();
174:                toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
175:                toolbar.add(Box.createHorizontalStrut(spacing));
176:
177:                final JComboBox xcb = new JComboBox(colnames);
178:                xcb.setSelectedItem(xfield);
179:                xcb.addActionListener(new ActionListener() {
180:                    public void actionPerformed(ActionEvent e) {
181:                        Visualization vis = sp.getVisualization();
182:                        AxisLayout xaxis = (AxisLayout) vis.getAction("x");
183:                        xaxis.setDataField((String) xcb.getSelectedItem());
184:                        vis.run("draw");
185:                    }
186:                });
187:                toolbar.add(new JLabel("X: "));
188:                toolbar.add(xcb);
189:                toolbar.add(Box.createHorizontalStrut(2 * spacing));
190:
191:                final JComboBox ycb = new JComboBox(colnames);
192:                ycb.setSelectedItem(yfield);
193:                ycb.addActionListener(new ActionListener() {
194:                    public void actionPerformed(ActionEvent e) {
195:                        Visualization vis = sp.getVisualization();
196:                        AxisLayout yaxis = (AxisLayout) vis.getAction("y");
197:                        yaxis.setDataField((String) ycb.getSelectedItem());
198:                        vis.run("draw");
199:                    }
200:                });
201:                toolbar.add(new JLabel("Y: "));
202:                toolbar.add(ycb);
203:                toolbar.add(Box.createHorizontalStrut(2 * spacing));
204:
205:                final JComboBox scb = new JComboBox(colnames);
206:                scb.setSelectedItem(sfield);
207:                scb.addActionListener(new ActionListener() {
208:                    public void actionPerformed(ActionEvent e) {
209:                        Visualization vis = sp.getVisualization();
210:                        DataShapeAction s = (DataShapeAction) vis
211:                                .getAction("shape");
212:                        s.setDataField((String) scb.getSelectedItem());
213:                        vis.run("draw");
214:                    }
215:                });
216:                toolbar.add(new JLabel("Shape: "));
217:                toolbar.add(scb);
218:                toolbar.add(Box.createHorizontalStrut(spacing));
219:                toolbar.add(Box.createHorizontalGlue());
220:
221:                return toolbar;
222:            }
223:
224:        } // end of class ScatterPlot
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.