Back to index

wims  3.65+svn20090927
Lister.java
Go to the documentation of this file.
00001 /*
00002  * Created on 14.01.2006
00003  *
00004  * This is a display for lists of items, stored in rene.lister.Element.
00005  * The display has two optional scrollbars and a ListerPanel.
00006  */
00007 package rene.lister;
00008 
00009 import java.awt.*;
00010 import java.awt.event.*;
00011 import java.io.PrintWriter;
00012 
00013 import rene.gui.*;
00014 
00015 public class Lister 
00016        extends Panel implements AdjustmentListener
00017 {      public ListerPanel L;
00018        Scrollbar Vertical,Horizontal;
00019        
00025        public Lister (boolean vs, boolean hs)
00026        {      L=new ListerPanel(this);
00027               setLayout(new BorderLayout());
00028               add("Center",L);
00029               if (vs)
00030               {      add("East",Vertical=new Scrollbar(Scrollbar.VERTICAL,0,100,0,1100));
00031                      Vertical.addAdjustmentListener(this);
00032               }
00033               if (hs)
00034               {      add("South",Horizontal=new Scrollbar(Scrollbar.HORIZONTAL,0,100,0,1100));
00035                      Horizontal.addAdjustmentListener(this);
00036               }
00037        }
00038        public Lister ()
00039        {      this(true,true);
00040        }
00041        
00049        public void setScrollbars (double vp, double vs, double hp, double hs)
00050        {      if (Vertical!=null)
00051               {      int size=(int)(vs*1000);
00052                      int max=1000+size;
00053                      int pos=(int)(vp*1000);
00054                      Vertical.setValues(pos,size,0,max);
00055               }
00056        }
00057        
00061        public void adjustmentValueChanged (AdjustmentEvent e) 
00062        {      if (Vertical!=null && e.getSource()==Vertical)
00063               {      switch (e.getAdjustmentType())
00064                      {      case AdjustmentEvent.UNIT_INCREMENT :
00065                                    L.up(1); break;
00066                             case AdjustmentEvent.UNIT_DECREMENT :
00067                                    L.down(1); break;
00068                             case AdjustmentEvent.BLOCK_INCREMENT :
00069                                    L.pageUp(); break;
00070                             case AdjustmentEvent.BLOCK_DECREMENT :
00071                                    L.pageDown(); break;
00072                             default :
00073                                    int size=Vertical.getVisibleAmount();
00074                                    int max=Vertical.getMaximum();
00075                                    int pos=Vertical.getValue();
00076                                    L.setVerticalPos((double)(pos)/(max-size));
00077                      }
00078               }
00079               else if (Horizontal!=null && e.getSource()==Horizontal)
00080               {      int pos=Horizontal.getValue();
00081                      switch (e.getAdjustmentType())
00082                      {      case AdjustmentEvent.UNIT_INCREMENT :
00083                                    pos+=10; break;
00084                             case AdjustmentEvent.UNIT_DECREMENT :
00085                                    pos-=10; break;
00086                             case AdjustmentEvent.BLOCK_INCREMENT :
00087                                    pos+=50; break;
00088                             case AdjustmentEvent.BLOCK_DECREMENT :
00089                                    pos-=50; break;
00090                      }
00091                      L.setHorizontalPos((double)(pos)/1000);
00092                      Horizontal.setValue(pos);
00093               }
00094        }
00095        
00100        public ListerPanel getLister ()
00101        {      return L;
00102        }
00103        
00104        public void addActionListener (ActionListener al)
00105        {      L.addActionListener(al);
00106        }
00107        
00108        public void updateDisplay ()
00109        {      L.repaint();
00110        }
00111        
00112        public void removeActionListener (ActionListener al)
00113        {      L.removeActionListener(al);
00114        }
00115        
00116        public void clear ()
00117        {      L.clear();
00118        }
00119        
00120        public void addElement (Element el)
00121        {      L.add(el);
00122        }
00123        
00128        public int getSelectedIndex ()
00129        {      if (L.Selected.size()>0) 
00130                      return ((Integer)L.Selected.elementAt(0)).intValue();
00131               else
00132                      return -1;
00133        }
00134        
00135        public String getSelectedItem ()
00136        {      int n=getSelectedIndex();
00137               if (n<0) return null;
00138               return L.getElementAt(n).getElementString();
00139        }
00140        
00145        public int[] getSelectedIndices ()
00146        {      int k[]=new int[L.Selected.size()];
00147               for (int i=0; i<k.length; i++)
00148                      k[i]=((Integer)L.Selected.elementAt(i)).intValue();
00149               return k;
00150        }
00151        
00155        public void showLast ()
00156        {      L.showLast();
00157        }
00158 
00166        public void setMode (boolean multiple, 
00167                      boolean easymultiple, 
00168                      boolean singleclick,
00169                      boolean rightmouse)
00170        {      L.MultipleSelection=multiple;
00171               L.EasyMultipleSelection=easymultiple;
00172               L.ReportSingleClick=singleclick;
00173               L.RightMouseClick=rightmouse;
00174        }
00175        
00180        public void save (PrintWriter o)
00181        {      L.save(o);
00182        }
00183        
00184        public void select (int sel)
00185        {      
00186        }
00187        
00193        public void addElement (String name, Color col)
00194        {      addElement(new StringElement(name,col));
00195        }
00196        public void addElement (String name)
00197        {      addElement(new StringElement(name));
00198        }
00199        
00200        public static void main (String args[])
00201        {      CloseFrame F=new CloseFrame("Test");
00202               F.setSize(300,400);
00203               F.setLocation(200,200);
00204               F.setLayout(new BorderLayout());
00205               Lister L=new Lister(true,true);
00206               F.add("Center",L);
00207               for (int i=0; i<1000; i++)
00208               {      L.getLister().add(
00209                             new StringElement(
00210                                           "-------------- This is line number: "+i,
00211                                           new Color(0,0,i%256)));
00212               }      
00213               F.setVisible(true);
00214        }
00215 
00216        public void setState (int s)
00217        {      L.setState(s);
00218        }
00219 
00220        public void setListingBackground (Color c)
00221        {      L.setListingBackground(c);
00222        }
00223 }