Back to index

wims  3.65+svn20090927
SelectDialog.java
Go to the documentation of this file.
00001 /*
00002  * Created on 26.10.2005
00003  *
00004  */
00005 package rene.zirkel.dialogs;
00006 
00007 import java.awt.*;
00008 import java.awt.event.*;
00009 
00010 import rene.gui.*;
00011 import rene.util.*;
00012 import rene.lister.*;
00013 import rene.zirkel.Zirkel;
00014 import rene.zirkel.objects.*;
00015 
00021 public class SelectDialog extends HelpCloseDialog implements ActionListener
00022 {      MyVector V;
00023        ConstructionObject O=null;
00024        Lister L;
00025        
00029        public SelectDialog (Frame f, MyVector v)
00030        {      super(f,Zirkel.name("select.title","Select Object"),true);
00031               V=v;
00032               add("Center",L=new Lister());
00033               L.setMode(false,false,false,false);
00034               for (int i=0; i<v.size(); i++)
00035               {      ConstructionObject o=(ConstructionObject)v.elementAt(i);
00036                      if (o instanceof PointObject)
00037                             L.addElement(o.getName(),Color.black);
00038                      else if (o instanceof PrimitiveLineObject)
00039                             L.addElement(o.getName(),Color.red.darker());
00040                      else if (o instanceof PrimitiveCircleObject)
00041                             L.addElement(o.getName(),Color.blue.darker());                 
00042                      else L.addElement(o.getName(),Color.green.darker());
00043               }
00044               L.select(0);
00045               L.addActionListener(this);
00046               L.updateDisplay();
00047               Panel p=new MyPanel();
00048               p.add(new ButtonAction(this,Zirkel.name("select.ok"),"OK"));
00049               p.add(new ButtonAction(this,Zirkel.name("select.cancel"),"Close"));
00050               addHelp(p,"mouse");
00051               add("South",new Panel3D(p));
00052               pack();
00053               center(f);
00054               setVisible(true);
00055        }
00056        
00057        public void actionPerformed (ActionEvent e)
00058        {      if (e.getSource()==L) // List double clicked!
00059               {      doAction("OK");
00060               }
00061               else super.actionPerformed(e);
00062        }
00063        
00064        public void doAction (String o)
00065        {      Aborted=true;
00066               if (o.equals("OK"))
00067               {      int i=L.getSelectedIndex();
00068                      if (i>=0) O=(ConstructionObject)V.elementAt(i);
00069                      Aborted=false;
00070                      doclose();
00071               }
00072               else super.doAction(o);
00073        }
00074        
00075        public ConstructionObject getObject ()
00076        {      return O;
00077        }
00078 }
00079 
00080