I have made a simple application that draws a map in a jframe. The problem is
that the map becomes blank when the frame is resized or minimized.  

The code: public void interFace(Geometry[] kartData) throws Exception
                        {
                                // feature attributes creation
                                AttributeType[] types = new
AttributeType[1];
                                types[0] =
                                       
AttributeTypeFactory.newAttributeType("centre", MultiLineString.class);

                                // feature type creation
                                FeatureType pointType =
                                       
FeatureTypeFactory.newFeatureType(types, "linefeature");

                                FeatureCollection aFeatureCollection =
                                        FeatureCollections.newCollection();
                               
                                for(int i = 0; i < kartData.length; i++)
                                {
                                aFeatureCollection.add(pointType.create(new
Object[]{(MultiLineString)kartData[i]}));
                                }


                                // Prepare styles
                                StyleBuilder sb = new StyleBuilder();

                                // Create line symbolizer
                                LineSymbolizer lineSymb =
                                        (LineSymbolizer)
sb.createLineSymbolizer(Color.RED, 1);

                                Style aStyle = sb.createStyle(lineSymb);

                                MapContext map = new DefaultMapContext();
                                map.addLayer(aFeatureCollection, aStyle);
                                renderer = new StreamingRenderer();
                                renderer.setContext(map);
                               
                               
                                double scaleX =
                                        p.getBounds().getWidth()
                                                /
aFeatureCollection.getBounds().getWidth();
                                double scaleY =
                                        p.getBounds().getHeight()
                                                /
aFeatureCollection.getBounds().getHeight();
                                double scale = scaleX < scaleY ? scaleX :
scaleY;
 
                               
                                transform = new AffineTransform();

                                transform.translate(0,
p.getBounds().getHeight());
                               
                                transform.scale(scale, -scale);

                                transform.translate(
                                       
-aFeatureCollection.getBounds().getMinX(),
                                       
-aFeatureCollection.getBounds().getMinY());
                                //
p.getGraphics().clearRect(0,0,(int)p.getBounds().getWidth(),(int)p.getBounds().getHeight());

                                //p.setBackground(Color.black);
                               
                                System.out.println(p.getGraphics());
                                System.out.println(p.getBounds());
                                System.out.println(transform);
                               
                                renderer.paint((Graphics2D) p.getGraphics(),
p.getBounds(),
                                                transform);
                               
                               

                                frame.addWindowListener(new WindowAdapter()
                                {
                                        public void
windowClosing(WindowEvent e) {
                                                e.getWindow().dispose();
                                        }
                                       
                                       
                                        public void windowActivated(
WindowEvent e )
                                        {  
                                                p.repaint();
                                        }
                                       
                                        public void windowClosed(
WindowEvent e )  
                                        {
                                                p.repaint();
                                        }
                                       
                                        public void windowDeactivated(
WindowEvent e )
                                        {
                                                p.repaint();
                                        }
                                       
                                        public void windowOpened(
WindowEvent e )
                                        {
                                                p.repaint();
                                        }
                                       
                                        public void windowIconfield(
WindowEvent e )
                                        {
                                                p.repaint();
                                        }
                                       
                                        public void windowIconified(
WindowEvent e )
                                        {
                                                p.repaint();
                                        }
                                       
                                        public void windowDeiconified(
WindowEvent e ) {
                                                p.repaint();
                                                }
                                        public void windowStateChanged(
WindowEvent e ) {
                                               
                                                p.repaint();
                                                }
                                       
                                               
                                });

What am i doing wrong??
-- 
View this message in context: 
http://www.nabble.com/-Newbie--Problem-with-rendering-update-tf2958951.html#a8277734
Sent from the geotools-gt2-users mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to