@@ -24,58 +24,47 @@ public static class AppFrame extends ApplicationTemplate.AppFrame
2424 {
2525 public AppFrame ()
2626 {
27- // Create an object to generate random attributes.
28- final RandomShapeAttributes randomAttrs = new RandomShapeAttributes ();
27+ ShapefileLayerFactory factory = new ShapefileLayerFactory ();
2928
30- // Spawn a thread to load the shapefile.
31- Thread t = new Thread (new Runnable ()
29+ // Specify an attribute delegate to assign random attributes to each shapefile record.
30+ final RandomShapeAttributes randomAttrs = new RandomShapeAttributes ();
31+ factory .setAttributeDelegate (new ShapefileRenderable .AttributeDelegate ()
3232 {
3333 @ Override
34- public void run ()
34+ public void assignAttributes (ShapefileRecord shapefileRecord ,
35+ ShapefileRenderable .Record renderableRecord )
3536 {
36- ShapefileLayerFactory factory = new ShapefileLayerFactory ();
37+ renderableRecord .setAttributes (randomAttrs .nextAttributes ().asShapeAttributes ());
38+ }
39+ });
3740
38- // Specify an attribute delegate to assign attributes for each shapefile record.
39- factory .setAttributeDelegate (new ShapefileRenderable .AttributeDelegate ()
41+ // Load the shapefile. Define the completion callback.
42+ factory .createFromShapefileSource ("testData/shapefiles/TM_WORLD_BORDERS-0.3.shp" ,
43+ new ShapefileLayerFactory .CompletionCallback ()
44+ {
45+ @ Override
46+ public void completion (Object result )
4047 {
41- @ Override
42- public void assignAttributes (ShapefileRecord shapefileRecord ,
43- ShapefileRenderable .Record renderableRecord )
44- {
45- renderableRecord .setAttributes (randomAttrs .nextAttributes ().asShapeAttributes ());
46- }
47- });
48+ final Layer layer = (Layer ) result ; // the result is the layer the factory created
49+ layer .setName (WWIO .getFilename (layer .getName ()));
4850
49- // Load the shapefile. Define the completion callback.
50- factory .createFromShapefileSource ("testData/shapefiles/TM_WORLD_BORDERS-0.3.shp" ,
51- new ShapefileLayerFactory .CompletionCallback ()
51+ // Add the layer to the World Window's layer list on the Event Dispatch Thread.
52+ SwingUtilities .invokeLater (new Runnable ()
5253 {
5354 @ Override
54- public void completion ( Object result )
55+ public void run ( )
5556 {
56- final Layer layer = (Layer ) result ; // the result is the layer the factory created
57- layer .setName (WWIO .getFilename (layer .getName ()));
58-
59- // Add the layer to the World Window's layer list on the Event Dispatch Thread.
60- SwingUtilities .invokeLater (new Runnable ()
61- {
62- @ Override
63- public void run ()
64- {
65- AppFrame .this .getWwd ().getModel ().getLayers ().add (layer );
66- }
67- });
68- }
69-
70- @ Override
71- public void exception (Exception e )
72- {
73- Logging .logger ().log (java .util .logging .Level .SEVERE , e .getMessage (), e );
57+ AppFrame .this .getWwd ().getModel ().getLayers ().add (layer );
7458 }
7559 });
76- }
77- });
78- t .start ();
60+ }
61+
62+ @ Override
63+ public void exception (Exception e )
64+ {
65+ Logging .logger ().log (java .util .logging .Level .SEVERE , e .getMessage (), e );
66+ }
67+ });
7968 }
8069 }
8170
0 commit comments