Subversion Repositories wimsdev

Rev

Blame | Last modification | View Log | RSS feed

  1. package rene.gui;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.io.*;
  6. import java.util.*;
  7.  
  8. class SaveColor extends Color
  9. {       public SaveColor (int red, int green, int blue)
  10.         {       super(red>0?red:0,green>0?green:0,blue>0?blue:0);
  11.         }
  12. }
  13.  
  14. /**
  15. These are the common things to Separators and Incons.
  16. */
  17.  
  18. interface IconBarElement
  19. {       public int width ();
  20.         public void setPosition (int x, int y);
  21.         public Point getPosition ();
  22.         public void setEnabled (boolean flag);
  23.         public String getName ();
  24. }
  25.  
  26. /**
  27. A simple separator between icons.
  28. */
  29.  
  30. class Separator extends Panel
  31.         implements IconBarElement
  32. {       final int Size=6;
  33.         public Separator (IconBar bar)
  34.         {       if (bar.Vertical)
  35.                         setSize(BasicIcon.Size,Size);
  36.                 else
  37.                         setSize(Size,BasicIcon.Size);  
  38.         }
  39.         public int width ()
  40.         {       return Size;
  41.         }
  42.         public void setPosition (int x, int y)
  43.         {       setLocation(x,y);
  44.         }
  45.         public Point getPosition () { return new Point(0,0); }
  46.         public void setEnabled (boolean flag) {}
  47.         public String getName () { return ""; }
  48.         public void paint (Graphics g)
  49.         {       g.setColor(getBackground());
  50.                 if (Global.getParameter("iconbar.showseparators",false))
  51.                         g.fill3DRect(1,1,getSize().width-1,getSize().height-1,false);
  52.                 else
  53.                         g.fillRect(1,1,getSize().width-1,getSize().height-1);
  54.         }
  55. }
  56.  
  57. /**
  58.  * @author Rene
  59.  * This is the most basic icon, handling mouse presses
  60.  * and display in activated, pressed, unset or disabled state.
  61.  */
  62. class BasicIcon extends Panel
  63.         implements MouseListener,IconBarElement,Runnable
  64. {       IconBar Bar;
  65.         String Name;
  66.         boolean Enabled; // Icon cannot be changed by user action.
  67.         boolean On; // On or off are the basic stated of icons.
  68.         boolean Focus=false;
  69.         public static int Size=22; // the size of icons
  70.         boolean MouseOver,MouseDown; // for display states during mouse action
  71.         boolean Unset; // Unknown State!
  72.  
  73.         public BasicIcon (IconBar bar, String name)
  74.         {       Bar=bar; Name=name; Enabled=true; On=false;
  75.                 addMouseListener(this);
  76.                 enableEvents(AWTEvent.KEY_EVENT_MASK);
  77.                 setSize(Size,Size);
  78.         }
  79.        
  80.         public void processKeyEvent (KeyEvent e)
  81.         {       Bar.getKey(e);
  82.         }
  83.  
  84.         /**
  85.         Paint a button with an image
  86.         */
  87.         public void paint (Graphics g)
  88.         {       if (MouseDown)
  89.                 {       g.setColor(getBackground());
  90.                         g.fill3DRect(0,0,Size,Size,false);
  91.                 }
  92.                 else
  93.                 {       if (MouseOver)
  94.                         {       if (On)
  95.                                 {       Color c=getBackground();
  96.                                         g.setColor(
  97.                                                 new SaveColor(c.getRed()-30,c.getGreen()-30,c.getBlue()));
  98.                                 }
  99.                                 else g.setColor(getBackground());
  100.                                 g.fill3DRect(0,0,Size,Size,true);
  101.                         }
  102.                         else
  103.                         {       if (On)
  104.                                 {       Color c=getBackground();
  105.                                         g.setColor(c);
  106.                                         g.fillRect(0,0,Size,Size);
  107.                                         g.setColor(
  108.                                                 new SaveColor(c.getRed()-100,c.getGreen()-100,c.getBlue()));
  109.                                         g.fillRect(3,3,Size-2,Size-2);
  110.                                         g.setColor(
  111.                                                 new SaveColor(c.getRed()-50,c.getGreen()-50,c.getBlue()));
  112.                                         g.fillRect(1,1,Size-2,Size-2);
  113.                                 }
  114.                                 else
  115.                                 {       g.setColor(getBackground());
  116.                                         g.fillRect(0,0,Size,Size);
  117.                                 }
  118.                         }
  119.                 }
  120.                 dopaint(g);    
  121.                 if (Unset)
  122.                 {       Color c=getBackground();
  123.                         g.setColor(
  124.                                 new SaveColor(c.getRed()-100,c.getGreen(),c.getBlue()));
  125.                         g.drawLine(0,0,Size,Size);
  126.                 }      
  127.                 if (Focus) showFocus(g);
  128.         }
  129.        
  130.         public void showFocus (Graphics g)
  131.         {       g.setColor(Color.white);
  132.                 g.drawRect(4,4,1,1);
  133.                 g.drawRect(Size-5,4,1,1);
  134.                 g.drawRect(4,Size-5,1,1);
  135.                 g.drawRect(Size-5,Size-5,1,1);
  136.         }
  137.        
  138.         public void dopaint (Graphics g)
  139.         {
  140.         }
  141.        
  142.         public void update (Graphics g)
  143.         {       paint(g);
  144.         }
  145.        
  146.         /**
  147.         * User pressed the mouse key over this button.
  148.         */
  149.         public void mousePressed (MouseEvent e)
  150.         {       if (!Enabled) return;
  151.                 MouseDown=true; repaint();
  152.         }
  153.  
  154.         /**
  155.         * User released the mouse key again.
  156.         */
  157.         public void mouseReleased (MouseEvent e)
  158.         {       if (!Enabled) return;
  159.                 MouseDown=false;
  160.                 Dimension d=getSize();
  161.                 if (e.getX()<0 || e.getX()>d.width ||
  162.                         e.getY()<0 || e.getY()>d.height)
  163.                 {       repaint(); return;
  164.                 }
  165.                 Unset=false;
  166.                 pressed(e); // call method for children to change states etc.
  167.                 repaint();
  168.                 T=null; // stop icon help thread
  169.                 // Notify Iconbar about activation:
  170.                 long time=System.currentTimeMillis();
  171.                 Bar.iconPressed(Name,e.isShiftDown(),e.isControlDown());
  172.                 // Necessary, since Java 1.4 does not report
  173.                 // MouseExited, if a modal dialog is active:
  174.                 time=System.currentTimeMillis()-time;
  175.                 if (MouseOver && time>1000)
  176.                 {       MouseOver=false;
  177.                         repaint();
  178.                 }
  179.         }
  180.        
  181.         /**
  182.          * Overwrite for children!
  183.          * @param e Mouse event for determining right button etc.
  184.          */
  185.         public void pressed (MouseEvent e)
  186.         {
  187.         }
  188.        
  189.         public void mouseClicked (MouseEvent e) {}
  190.        
  191.         Thread T;
  192.         boolean Control;
  193.        
  194.         /**
  195.         Start a thread, that waits for one second, then tells
  196.         the icon bar to display the proper help text.
  197.         */
  198.         public synchronized void mouseEntered (MouseEvent e)
  199.         {       if (T!=null) return;
  200.                 if (Enabled) MouseOver=true;
  201.                 repaint();
  202.                 if (!Global.getParameter("iconbar.showtips",true)) return;
  203.                 Control=e.isControlDown();
  204.                 T=new Thread(this);
  205.                 T.start();
  206.         }
  207.        
  208.         /**
  209.          * A thread to display an icon help.
  210.          */
  211.         public void run ()
  212.         {       try
  213.                 {       Thread.sleep(1000);
  214.                 }
  215.                 catch (Exception e) {}
  216.                 if (T!=null)
  217.                 {       synchronized(this)
  218.                         {       try
  219.                                 {       Point P=getLocationOnScreen();
  220.                                         String help=Global.name("iconhelp."+Name,"");
  221.                                         if (help.equals("") && Name.length()>1)
  222.                                         {       help=Global.name("iconhelp."+
  223.                                                         Name.substring(0,Name.length()-1)+"?","");
  224.                                         }
  225.                                         if (help.equals(""))
  226.                                                 help=Bar.getHelp(Name);
  227.                                         if (help.equals(""))
  228.                                                 help=Global.name("iconhelp.nohelp","No help available");
  229.                                         if (Control)
  230.                                         {       String hc=Global.name("iconhelp.control."+Name,"");
  231.                                                 if (!hc.equals("")) help=hc;
  232.                                         }
  233.                                         Bar.displayHelp(this,help);
  234.                                 }
  235.                                 catch (Exception e) {}
  236.                         }
  237.                         try
  238.                         {       Thread.sleep(5000);
  239.                         }
  240.                         catch (Exception e) {}
  241.                         if (T!=null) Bar.removeHelp();
  242.                         T=null;
  243.                 }
  244.         }
  245.  
  246.         /**
  247.         Tell the run method, that display is no longer necessary,
  248.         and remove the help text.
  249.         */
  250.         public synchronized void mouseExited (MouseEvent e)
  251.         {       T=null;
  252.                 MouseOver=false;
  253.                 repaint();
  254.                 Bar.removeHelp();
  255.         }
  256.        
  257.         // for the IconBarElement interface
  258.        
  259.         public int width ()
  260.         {       return Size;
  261.         }
  262.        
  263.         public void setPosition (int x, int y)
  264.         {       setLocation(x,y);
  265.         }
  266.        
  267.         public Point getPosition ()
  268.         {       return getLocationOnScreen();
  269.         }
  270.        
  271.         public void setEnabled (boolean flag)
  272.         {       if (Enabled==flag) return;
  273.                 Enabled=flag;
  274.                 repaint();
  275.         }
  276.        
  277.         public String getName ()
  278.         {       return Name;
  279.         }
  280.  
  281.         public boolean hasFocus () { return Focus; }
  282.         public void setFocus (boolean flag) { Focus=flag; repaint(); } 
  283.        
  284.         // needs to be removed:
  285.        
  286.         public boolean isSet ()
  287.         {       return !Unset;
  288.         }      
  289.         public void unset (boolean flag)
  290.         {       Unset=flag;
  291.         }
  292.         public void unset ()
  293.         {       unset(true);
  294.         }
  295. }
  296.  
  297. /**
  298.  * @author Rene
  299.  * A primitive icon that displays a GIF image.
  300.  */
  301. class IconWithGif extends BasicIcon
  302. {       Image I;
  303.         Color C;
  304.         int W,H,X,Y;
  305.        
  306.         /**
  307.         * Initialize the icon and load its image.
  308.         * By changing the global parameter "icontype", png can be used too.
  309.         */
  310.         public IconWithGif (IconBar bar, String file)
  311.         {       super(bar,file);
  312.                 String iconfile=getDisplay(file);
  313.                 if (!iconfile.equals("")) file=iconfile;
  314.                 try
  315.                 {       InputStream in=getClass().getResourceAsStream(
  316.                                 Bar.Resource+file+"."+Global.getParameter("icontype","gif"));
  317.                         int pos=0;
  318.                         int n=in.available();
  319.                         byte b[]=new byte[20000];
  320.                         while (n>0)
  321.                         {       int k=in.read(b,pos,n);
  322.                                 if (k<0) break;
  323.                                 pos+=k;
  324.                                 n=in.available();
  325.                         }
  326.                         in.close();
  327.                         I=Toolkit.getDefaultToolkit().createImage(b,0,pos);
  328.                         MediaTracker T=new MediaTracker(bar);
  329.                         T.addImage(I,0);
  330.                         T.waitForAll();
  331.                 }
  332.                 catch (Exception e)
  333.                 {       try
  334.                         {       I=getToolkit().getImage(file+"."+Global.getParameter("icontype","gif"));
  335.                                 MediaTracker mt=new MediaTracker(this);
  336.                                 mt.addImage(I,0);
  337.                                 mt.waitForID(0);
  338.                                 if (!(mt.checkID(0) && !mt.isErrorAny()))
  339.                                         throw new Exception("");
  340.                         }
  341.                         catch (Exception ex) { I=null; return;}
  342.                 }
  343.                 W=I.getWidth(this);
  344.                 H=I.getHeight(this);
  345.                 X=Size/2-W/2;
  346.                 Y=Size/2-H/2;
  347.         }
  348.        
  349.         public String getDisplay (String name)
  350.         {       if (!name.endsWith(")")) return "";
  351.                 int n=name.lastIndexOf('(');
  352.                 if (n<0) return "";
  353.                 return name.substring(n+1,name.length()-1);
  354.         }
  355.        
  356.         public IconWithGif (IconBar bar, String name, Color color)
  357.         {       super(bar,name);
  358.                 C=color;
  359.         }
  360.        
  361.         public void dopaint (Graphics g)       
  362.         {       if (I!=null)
  363.                 {       if (W>getSize().width) g.drawImage(I,1,1,Size-2,Size-2,this);
  364.                         else g.drawImage(I,X,Y,this);
  365.                 }
  366.                 else if (C!=null)
  367.                 {       g.setColor(C);
  368.                         g.fillRect(3,3,Size-6,Size-6);
  369.                 }
  370.                 else
  371.                 {       g.setFont(new Font("Courier",Font.BOLD,Size/3));
  372.                         FontMetrics fm=getFontMetrics(getFont());
  373.                         String s=getDisplay(Name);
  374.                         if (s.length()>3) s=s.substring(0,3);
  375.                         int w=fm.stringWidth(s);
  376.                         int h=fm.getHeight();
  377.                         g.setColor(this.getForeground());
  378.                         Graphics2D G=(Graphics2D)g;
  379.                         G.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
  380.                                         RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  381.                         G.drawString(s,Size/2-w/2,Size/2-h/2+fm.getAscent());
  382.                 }
  383.         }
  384.        
  385. }
  386.  
  387. /**
  388.  * @author Rene
  389.  * A primitive icon that displays one of several GIF images.
  390.  */
  391. class MultipleIcon extends BasicIcon
  392. {       int N;
  393.         Image I[];
  394.         int Selected;
  395.         int X[],Y[],W[],H[];
  396.        
  397.         public MultipleIcon (IconBar bar, String name, int number)
  398.         {       super(bar,name);
  399.                 N=number;
  400.                 I=new Image[N];
  401.                 X=new int[N];
  402.                 Y=new int[N];
  403.                 W=new int[N];
  404.                 H=new int[N];
  405.                 MediaTracker T=new MediaTracker(bar);
  406.                 try
  407.                 {       for (int i=0; i<N; i++)
  408.                         {       try
  409.                                 {       InputStream in=getClass().getResourceAsStream(
  410.                                                 Bar.Resource+name+i+"."+Global.getParameter("icontype","gif"));
  411.                                         int pos=0;
  412.                                         int n=in.available();
  413.                                         byte b[]=new byte[20000];
  414.                                         while (n>0)
  415.                                         {       int k=in.read(b,pos,n);
  416.                                                 if (k<0) break;
  417.                                                 pos+=k;
  418.                                                 n=in.available();
  419.                                         }
  420.                                         in.close();
  421.                                         I[i]=Toolkit.getDefaultToolkit().createImage(b,0,pos);
  422.                                         T.addImage(I[i],i);
  423.                                 }
  424.                                 catch (Exception e)
  425.                                 {       I[i]=null;
  426.                                 }
  427.                         }
  428.                         T.waitForAll();
  429.                         for (int i=0; i<N; i++)
  430.                         {       W[i]=I[i].getWidth(this);
  431.                                 H[i]=I[i].getHeight(this);
  432.                                 X[i]=Size/2-W[i]/2;
  433.                                 Y[i]=Size/2-H[i]/2;
  434.                         }
  435.                 }
  436.                 catch (Exception e)
  437.                 {       for (int i=0; i<N; i++) I[i]=null;
  438.                 }
  439.         }
  440.        
  441.         public MultipleIcon (IconBar bar, String name)
  442.         {       super(bar,name);
  443.                 Selected=0;
  444.         }
  445.  
  446.         /**
  447.         Paint a button with an image
  448.         */
  449.         public void dopaint (Graphics g)
  450.         {       if (I[Selected]!=null)
  451.                 {       if (W[Selected]>getSize().width) g.drawImage(I[Selected],1,1,Size-2,Size-2,this);
  452.                         else g.drawImage(I[Selected],X[Selected],Y[Selected],this);
  453.                 }
  454.         }
  455.        
  456.         /**
  457.          * Go up and down the pictures.
  458.          */
  459.         public void pressed (MouseEvent e)
  460.         {       if (e.isMetaDown())
  461.                 {       Selected--;
  462.                         if (Selected<0) Selected=N-1;
  463.                 }
  464.                 else
  465.                 {       Selected++;
  466.                         if (Selected>=N) Selected=0;
  467.                 }
  468.         }
  469.  
  470.         public void setSelected (int s)
  471.         {       if (Selected==s) return;
  472.                 Selected=s;
  473.                 repaint();
  474.         }
  475.        
  476.         public int getSelected ()
  477.         {       return Selected;
  478.         }
  479. }
  480.  
  481. /**
  482.  * @author Rene
  483.  * An MultipleIcon that can be enabled externally.
  484.  */
  485. class MultipleToggleIcon extends MultipleIcon
  486. {       public MultipleToggleIcon (IconBar bar, String name, int number)
  487.         {       super(bar,name,number);
  488.         }
  489.         public void setState (boolean flag)
  490.         {       On=flag;
  491.                 repaint();
  492.         }
  493. }
  494.  
  495. /**
  496.  * @author Rene
  497.  * A toggle icon for several colors.
  498.  */
  499. class ColorIcon extends MultipleIcon
  500. {       Color Colors[];
  501.         public ColorIcon (IconBar bar, String name, Color colors[])
  502.         {       super(bar,name);
  503.                 N=colors.length;
  504.                 Colors=colors;
  505.         }
  506.         public void dopaint (Graphics g)
  507.         {       g.setColor(Colors[Selected]);
  508.                 g.fill3DRect(5,5,Size-10,Size-10,true);
  509.         }      
  510. }
  511.  
  512. /**
  513.  * @author Rene
  514.  * A toggle icon for several strings.
  515.  */
  516. class MultipleStringIcon extends MultipleIcon
  517. {       String S[];
  518.        
  519.         public MultipleStringIcon (IconBar bar, String name, String s[])
  520.         {       super(bar,name);
  521.                 S=s;
  522.                 N=S.length;
  523.         }
  524.        
  525.         public void dopaint (Graphics g)
  526.         {       g.setColor(getForeground());
  527.                 Font font=new Font("Dialog",Font.PLAIN,Size*2/3);
  528.                 g.setFont(font);
  529.                 FontMetrics fm=getFontMetrics(font);
  530.                 int w=fm.stringWidth(S[Selected]);
  531.                 g.drawString(S[Selected],(Size-w)/2,Size-fm.getDescent());
  532.         }
  533.        
  534. }
  535.  
  536. /**
  537.  * Button to get all icons, when there is not too much space.
  538.  */
  539. class OverflowButton extends Panel
  540. {       IconBar IB;
  541.         boolean Left=true;
  542.        
  543.         public OverflowButton (IconBar ib, boolean left)
  544.         {       IB=ib; Left=left;
  545.                 addMouseListener(new MouseAdapter()
  546.                                 {       public void mouseClicked (MouseEvent e)
  547.                                         {       IB.setShifted(!Left);  
  548.                                         }
  549.                                 }
  550.                         );
  551.         }
  552.  
  553.         public void paint (Graphics g)
  554.         {       int size=BasicIcon.Size;
  555.                 g.setColor(getBackground());
  556.                 g.fill3DRect(0,0,10,size,true);
  557.                 g.setColor(getForeground());
  558.                 int x[]=new int[3],y[]=new int[3];
  559.                 if (Left)
  560.                 {       x[0]=2; x[1]=x[2]=8;
  561.                         y[0]=size/2; y[1]=y[0]-6; y[2]=y[0]+6;
  562.                 }
  563.                 else
  564.                 {       x[0]=8; x[1]=x[2]=2;
  565.                         y[0]=size/2; y[1]=y[0]-6; y[2]=y[0]+6;
  566.                 }
  567.                 g.fillPolygon(x,y,3);
  568.         }
  569. }
  570.  
  571. class PopupIcon extends BasicIcon
  572. {      
  573.         public PopupIcon (IconBar bar, String name[])
  574.         {       super(bar,name[0]);
  575.         }
  576. }
  577.  
  578.  
  579. /**
  580.  * @author Rene
  581.  * An action icon for one click.
  582.  */
  583. class ToggleIcon extends IconWithGif
  584. {       boolean State;
  585.         private IconGroup G;
  586.  
  587.         public ToggleIcon (IconBar bar, String file, IconGroup g)
  588.         {       super(bar,file);
  589.                 State=false; G=g;
  590.         }
  591.        
  592.         public ToggleIcon (IconBar bar, String file, Color c, IconGroup g)
  593.         {       super(bar,file,c);
  594.                 State=false; G=g;
  595.         }
  596.        
  597.         public ToggleIcon (IconBar bar, String file)
  598.         {       this(bar,file,null);
  599.         }
  600.        
  601.         public void pressed (MouseEvent e)
  602.         {       setState(!On);
  603.         }
  604.  
  605.         public boolean getState () { return State; }
  606.        
  607.         public void setState (boolean state)
  608.         {       if (G!=null) G.toggle(this);
  609.                 else
  610.                 {       if (On==state) { State=state; return; }
  611.                         On=State=state;
  612.                         repaint();
  613.                 }
  614.         }
  615.        
  616.         public void unselect ()
  617.         {       if (G!=null) G.unselect();
  618.         }
  619.        
  620.         public void setStateInGroup (boolean state)
  621.         {       if (On==state) { State=state; return; }
  622.                 On=State=state;
  623.                 repaint();
  624.         }
  625.        
  626.         public int countPeers ()
  627.         {       if (G==null) return 0;
  628.                 return G.getN();
  629.         }
  630.        
  631.         public void unset ()
  632.         {       if (G!=null) G.unset(true);
  633.                 else super.unset();
  634.         }      
  635.         public void dounset (boolean flag)
  636.         {       super.unset(flag);
  637.         }
  638.         public void set ()
  639.         {       if (G!=null) G.unset(false);
  640.                 else super.unset(false);
  641.         }      
  642.         public void doset ()
  643.         {       super.unset(false);
  644.         }
  645. }
  646.  
  647. /**
  648.  * @author Rene
  649.  * An icon to display on/off state.
  650.  */
  651. class OnOffIcon extends ToggleIcon
  652. {       static int LampSize=4;
  653.         public OnOffIcon (IconBar bar, String file)
  654.         {       super(bar,file,null);
  655.         }
  656.         public void pressed (MouseEvent e)
  657.         {       State=On=!On;
  658.         }
  659. }
  660.  
  661. /**
  662. This class can add several ToggleItems and will enable only one
  663. of them.
  664. */
  665.  
  666. class IconGroup
  667. {       String Files[],Breaks[];
  668.         IconBar Bar;
  669.         int N;
  670.         ToggleIcon Icons[];
  671.         public IconGroup (IconBar bar, String files[], String breaks[])
  672.         {       Files=files; Breaks=breaks; Bar=bar;
  673.                 init();
  674.         }
  675.         public IconGroup (IconBar bar, String files[])
  676.         {       this(bar,files,files);
  677.         }
  678.         public void init ()
  679.         {       N=0;
  680.                 for (int i=0; i<Files.length; i++)
  681.                         if (!Files[i].equals("")) N++;
  682.                 Icons=new ToggleIcon[N];
  683.                 int k=0;
  684.                 for (int i=0; i<Files.length; i++)
  685.                 {       if (!Files[i].equals(""))
  686.                         {       Icons[k++]=new ToggleIcon(Bar,Files[i],this);
  687.                         }
  688.                 }              
  689.         }
  690.         public IconGroup (IconBar bar, String name, int n)
  691.         {       Breaks=Files=new String[n];
  692.                 for (int i=0; i<n; i++)
  693.                 {       Files[i]=name+i;
  694.                 }
  695.                 Bar=bar;
  696.                 init();
  697.         }
  698.         public IconGroup (IconBar bar, String name, Color colors[])
  699.         {       N=colors.length;
  700.                 Breaks=Files=new String[N];
  701.                 for (int i=0; i<N; i++)
  702.                 {       Files[i]=name+i;
  703.                 }
  704.                 Bar=bar;
  705.                 Icons=new ToggleIcon[N];
  706.                 for (int i=0; i<N; i++)
  707.                 {       Icons[i]=new ToggleIcon(Bar,Files[i],colors[i],this);
  708.                 }              
  709.         }
  710.         public void addLeft ()
  711.         {       int i=0;
  712.                 for (int k=0; k<Files.length; k++)
  713.                         if (Files[k].equals("")) Bar.addSeparatorLeft();
  714.                         else
  715.                         {       if (Breaks[k].startsWith("!")) Bar.addSeparatorLeft();
  716.                                 Bar.addLeft(Icons[i++]);
  717.                         }
  718.         }
  719.         public void addRight ()
  720.         {       int i=0;
  721.                 for (int k=0; k<Files.length; k++)
  722.                         if (Files[k].equals("")) Bar.addSeparatorRight();
  723.                         else
  724.                         {       if (Breaks[k].startsWith("!")) Bar.addSeparatorRight();
  725.                                 Bar.addRight(Icons[i++]);
  726.                         }
  727.         }
  728.         public void toggle (ToggleIcon icon)
  729.         {       for (int i=0; i<N; i++)
  730.                 {       if (Icons[i]==icon) icon.setStateInGroup(true);
  731.                         else Icons[i].setStateInGroup(false);
  732.                 }
  733.         }
  734.         public void unselect ()
  735.         {       for (int i=0; i<N; i++)
  736.                 {       Icons[i].setStateInGroup(false);
  737.                 }
  738.         }
  739.         public int getN () { return N; }
  740.         public void unset (boolean flag)
  741.         {       for (int i=0; i<N; i++)
  742.                 {       Icons[i].dounset(flag);
  743.                 }
  744.         }
  745. }
  746.  
  747. /**
  748. An state display. Loads two images from a resource and display either
  749. of them, depending on the enabled state.
  750. */
  751.  
  752. class StateDisplay extends BasicIcon
  753. {       Image IOn,IOff;
  754.         int W,H,X,Y;
  755.        
  756.         /**
  757.         Initialize the icon and load its image.
  758.         */
  759.         public StateDisplay (IconBar bar, String file)
  760.         {       super(bar,file);
  761.                 try
  762.                 {       InputStream in=getClass().getResourceAsStream(
  763.                                 Bar.Resource+file+"on"+"."+Global.getParameter("icontype","gif"));
  764.                         int pos=0;
  765.                         int n=in.available();
  766.                         byte b[]=new byte[20000];
  767.                         while (n>0)
  768.                         {       int k=in.read(b,pos,n);
  769.                                 if (k<0) break;
  770.                                 pos+=k;
  771.                                 n=in.available();
  772.                         }
  773.                         in.close();
  774.                         IOn=Toolkit.getDefaultToolkit().createImage(b,0,pos);
  775.                         MediaTracker T=new MediaTracker(bar);
  776.                         T.addImage(IOn,0);
  777.                         in=getClass().getResourceAsStream(
  778.                                 Bar.Resource+file+"off"+"."+Global.getParameter("icontype","gif"));
  779.                         pos=0;
  780.                         n=in.available();
  781.                         byte b1[]=new byte[20000];
  782.                         while (n>0)
  783.                         {       int k=in.read(b1,pos,n);
  784.                                 if (k<0) break;
  785.                                 pos+=k;
  786.                                 n=in.available();
  787.                         }
  788.                         in.close();
  789.                         IOff=Toolkit.getDefaultToolkit().createImage(b1,0,pos);
  790.                         T.addImage(IOff,1);
  791.                         T.waitForAll();
  792.                         W=IOn.getWidth(this);
  793.                         H=IOn.getHeight(this);
  794.                         if (Bar.Vertical) X=Size/2-W/2;
  795.                         else X=0;
  796.                         Y=Size/2-H/2;
  797.                 }
  798.                 catch (Exception e)
  799.                 {       IOn=IOff=null;
  800.                 }
  801.         }
  802.        
  803.         /**
  804.         Paint a button with an image
  805.         */
  806.         public void paint (Graphics g)
  807.         {       if (Enabled && IOn!=null)
  808.                 {       if (W>getSize().width) g.drawImage(IOn,1,1,Size-2,Size-2,this);
  809.                         else g.drawImage(IOn,X,Y,this);
  810.                 }
  811.                 else if (!Enabled && IOff!=null)
  812.                 {       if (W>getSize().width) g.drawImage(IOff,1,1,Size-2,Size-2,this);
  813.                         else g.drawImage(IOff,X,Y,this);
  814.                 }
  815.         }
  816.        
  817.         public void mousePressed (MouseEvent e) {}
  818.         public void mouseReleased (MouseEvent e) { T=null; }
  819.         public void mouseClicked (MouseEvent e) {}     
  820. }
  821.  
  822. /**
  823. This panel displays icons and reacts on mouse actions.
  824. It can also interpret key strokes to traverse the icons.
  825. */
  826.  
  827. public class IconBar extends Panel
  828.         implements KeyListener, FocusListener, IconBarListener
  829. {       Vector Left=new Vector(),Right=new Vector();
  830.         int W;
  831.         Frame F;
  832.         public final int Offset=2;
  833.         public String Resource="/";
  834.         int Focus=0;
  835.         public boolean TraverseFocus=true;
  836.         public boolean UseSize=true;
  837.         public boolean Vertical=false;
  838.        
  839.         public IconBar (Frame f, boolean traversefocus)
  840.         {       F=f; TraverseFocus=traversefocus;
  841.                 if (Global.ControlBackground!=null)
  842.                         setBackground(Global.ControlBackground);
  843.                 else setBackground(SystemColor.menu);
  844.                 Resource=Global.getParameter("iconpath","");
  845.                 BasicIcon.Size=Global.getParameter("iconsize",20);
  846.                 setLayout(null);
  847.                 W=Offset*2;
  848.                 addKeyListener(this);
  849.                 if (TraverseFocus) addFocusListener(this);
  850.         }
  851.         public IconBar (Frame f)
  852.         {       this(f,true);
  853.         }      
  854.        
  855.         /**
  856.          * Do not know, if this is necessary. But sometimes the icons do not
  857.          * repaint after an update.
  858.          */
  859.         public void forceRepaint ()
  860.         {       super.repaint();
  861.                 Enumeration e=Left.elements();
  862.                 while (e.hasMoreElements())
  863.                 {       BasicIcon i=(BasicIcon)e.nextElement();
  864.                         i.repaint();
  865.                 }
  866.                 e=Right.elements();
  867.                 while (e.hasMoreElements())
  868.                 {       BasicIcon i=(BasicIcon)e.nextElement();
  869.                         i.repaint();
  870.                 }
  871.         }
  872.  
  873.         public void keyPressed (KeyEvent e) {}
  874.         public void keyReleased (KeyEvent e)
  875.         {       switch (e.getKeyCode())
  876.                 {       case KeyEvent.VK_RIGHT :
  877.                                 setFocus(Focus,false);
  878.                                 Focus++;
  879.                                 if (Focus>=Left.size()+Right.size()) Focus=0;
  880.                                 while (!(getIcon(Focus) instanceof BasicIcon))
  881.                                 {       Focus++;
  882.                                         if (Focus>=Left.size()+Right.size())
  883.                                         {       Focus=0; break;
  884.                                         }
  885.                                 }
  886.                                 setFocus(Focus,true);
  887.                                 break;
  888.                         case KeyEvent.VK_LEFT :
  889.                                 setFocus(Focus,false);
  890.                                 Focus--;
  891.                                 if (Focus<0) Focus=Left.size()+Right.size()-1;
  892.                                 while (!(getIcon(Focus) instanceof BasicIcon))
  893.                                 {       Focus--;
  894.                                         if (Focus<0)
  895.                                         {       Focus=Left.size()+Right.size()-1;
  896.                                                 break;
  897.                                         }
  898.                                 }
  899.                                 setFocus(Focus,true);
  900.                                 break;
  901.                         case KeyEvent.VK_SPACE :
  902.                                 try
  903.                                 {       BasicIcon icon=(BasicIcon)getIcon(Focus);
  904.                                         icon.mouseReleased(new MouseEvent(this,
  905.                                                 MouseEvent.MOUSE_RELEASED,0,0,0,0,1,false));
  906.                                 }
  907.                                 catch (Exception ex) {}
  908.                                 break;
  909.                 }
  910.         }
  911.         public void keyTyped (KeyEvent e) {}
  912.        
  913.         /*
  914.         public boolean isFocusTraversable ()
  915.         {       return TraverseFocus;
  916.         }
  917.         */
  918.        
  919.         public Object getIcon (int n)
  920.         {       if (n<Left.size()) return Left.elementAt(n);
  921.                 else return Right.elementAt(Right.size()-1-(n-Left.size()));
  922.         }
  923.        
  924.         public void focusGained (FocusEvent e)
  925.         {       if (TraverseFocus) setFocus(Focus,true);
  926.         }
  927.         public void focusLost (FocusEvent e)
  928.         {       if (TraverseFocus) setFocus(Focus,false);
  929.         }
  930.                
  931.         public void setFocus (int n, boolean flag)
  932.         {       if (!TraverseFocus) return;
  933.                 try
  934.                 {       if (n<Left.size())
  935.                         {       BasicIcon icon=(BasicIcon)Left.elementAt(n);
  936.                                 icon.setFocus(flag);
  937.                         }
  938.                         else
  939.                         {       BasicIcon icon=(BasicIcon)Right.elementAt(
  940.                                         Right.size()-1-(n-Left.size()));
  941.                                 icon.setFocus(flag);
  942.                         }
  943.                 }
  944.                 catch (Exception e) {}
  945.         }
  946.        
  947.         /**
  948.         Add an icon
  949.         */
  950.         public void addLeft (String name)
  951.         {       addLeft(new IconWithGif(this,name));
  952.         }
  953.         public void addLeft (BasicIcon i)
  954.         {       Left.addElement(i);
  955.                 add(i);
  956.                 W+=i.width()+Offset;
  957.         }
  958.  
  959.         /**
  960.         Add an icon at the right end
  961.         */
  962.         public void addRight (String name)
  963.         {       addRight(new IconWithGif(this,name));
  964.         }
  965.         public void addRight (BasicIcon i)
  966.         {       Right.addElement(i);
  967.                 add(i);
  968.                 W+=i.width()+Offset;
  969.         }
  970.  
  971.         /**
  972.         Add a toggle icon
  973.         */
  974.         public void addToggleLeft (String name)
  975.         {       addLeft(new ToggleIcon(this,name));
  976.         }
  977.         public void addToggleRight (String name)
  978.         {       addRight(new ToggleIcon(this,name));
  979.         }
  980.        
  981.         /**
  982.         Add a toggle icon
  983.         */
  984.         public void addOnOffLeft (String name)
  985.         {       addLeft(new OnOffIcon(this,name));
  986.         }
  987.         public void addOnOffRight (String name)
  988.         {       addRight(new OnOffIcon(this,name));
  989.         }
  990.        
  991.         /**
  992.         Add a complete groupe of toggle items.
  993.         */
  994.         public void addToggleGroupLeft (String names[], String breaks[])
  995.         {       IconGroup g=new IconGroup(this,names,breaks);
  996.                 g.addLeft();
  997.         }
  998.         public void addToggleGroupRight (String names[], String breaks[])
  999.         {       IconGroup g=new IconGroup(this,names,breaks);
  1000.                 g.addRight();
  1001.         }
  1002.         public void addToggleGroupLeft (String names[])
  1003.         {       addToggleGroupLeft(names,names);
  1004.         }
  1005.         public void addToggleGroupRight (String names[])
  1006.         {       addToggleGroupRight(names,names);
  1007.         }
  1008.         public void addToggleGroupLeft (String name, int n)
  1009.         {       IconGroup g=new IconGroup(this,name,n);
  1010.                 g.addLeft();
  1011.         }
  1012.         public void addToggleGroupRight (String name, int n)
  1013.         {       IconGroup g=new IconGroup(this,name,n);
  1014.                 g.addRight();
  1015.         }
  1016.         public void addToggleGroupLeft (String name, Color colors[])
  1017.         {       IconGroup g=new IconGroup(this,name,colors);
  1018.                 g.addLeft();
  1019.         }
  1020.         public void addToggleGroupRight (String name, Color colors[])
  1021.         {       IconGroup g=new IconGroup(this,name,colors);
  1022.                 g.addRight();
  1023.         }
  1024.  
  1025.         /**
  1026.         Add a separator
  1027.         */
  1028.         public void addSeparatorLeft ()
  1029.         {       if (Left.size()==0) return;
  1030.                 if (Left.lastElement() instanceof Separator) return;
  1031.                 Separator s=new Separator(this);
  1032.                 Left.addElement(s);
  1033.                 add(s);
  1034.                 W+=s.width()+Offset;
  1035.         }
  1036.         public void addSeparatorRight ()
  1037.         {       if (Right.size()==0) return;
  1038.                 if (Right.lastElement() instanceof Separator) return;
  1039.                 Separator s=new Separator(this);
  1040.                 Right.addElement(s);
  1041.                 add(s);
  1042.                 W+=s.width()+Offset;
  1043.         }
  1044.  
  1045.         /**
  1046.         Add a multiple icon (can toggle between the icons)
  1047.         */
  1048.         public void addMultipleIconLeft (String name, int number)
  1049.         {       addLeft(new MultipleIcon(this,name,number));
  1050.         }
  1051.         public void addMultipleIconRight (String name, int number)
  1052.         {       addRight(new MultipleIcon(this,name,number));
  1053.         }
  1054.        
  1055.         /**
  1056.         Add a multiple icon (can toggle between the icons)
  1057.         */
  1058.         public void addMultipleStringIconLeft (String name, String s[])
  1059.         {       addLeft(new MultipleStringIcon(this,name,s));
  1060.         }
  1061.         public void addMultipleStringIconRight (String name, String s[])
  1062.         {       addRight(new MultipleStringIcon(this,name,s));
  1063.         }
  1064.        
  1065.         /**
  1066.         Add a multiple icon (can toggle between the icons)
  1067.         */
  1068.         public void addMultipleToggleIconLeft (String name, int number)
  1069.         {       addLeft(new MultipleToggleIcon(this,name,number));
  1070.         }
  1071.         public void addMultipleToggleIconRight (String name, int number)
  1072.         {       addRight(new MultipleToggleIcon(this,name,number));
  1073.         }
  1074.        
  1075.         /**
  1076.         Add a multiple icon (can toggle between the colors)
  1077.         */
  1078.         public void addColorIconLeft (String name, Color colors[])
  1079.         {       addLeft(new ColorIcon(this,name,colors));
  1080.         }
  1081.         public void addColorIconRight (String name, Color colors[])
  1082.         {       addRight(new ColorIcon(this,name,colors));
  1083.         }
  1084.  
  1085.         /**
  1086.         Add a state display at the left end.
  1087.         */
  1088.         public void addStateLeft (String name)
  1089.         {       addLeft(new StateDisplay(this,name));
  1090.         }
  1091.         public void addStateRight (String name)
  1092.         {       addRight(new StateDisplay(this,name));
  1093.         }
  1094.        
  1095.         boolean Overflow=false,Shifted=false;
  1096.         OverflowButton OB;
  1097.         int OverflowX;
  1098.        
  1099.         /**
  1100.         Override the layout and arange the icons from the
  1101.         left and the right.
  1102.         */
  1103.         public void doLayout ()
  1104.         {       if (OB!=null)
  1105.                 {       remove(OB); OB=null;
  1106.                 }
  1107.                 if (Vertical)  
  1108.                 {       int x;
  1109.                         x=getSize().height;
  1110.                         for (int k=0; k<Right.size(); k++)
  1111.                         {       IconBarElement i=(IconBarElement)Right.elementAt(k);
  1112.                                 x-=i.width();
  1113.                                 i.setPosition(2,x);
  1114.                                 x-=Offset;
  1115.                         }
  1116.                         int xmax=x;
  1117.                         x=0;
  1118.                         for (int k=0; k<Left.size(); k++)
  1119.                         {       IconBarElement i=(IconBarElement)Left.elementAt(k);
  1120.                                 i.setPosition(2,x);
  1121.                                 x+=i.width();
  1122.                                 x+=Offset;
  1123.                                 if (x+IconWithGif.Size>xmax) x=-1000;
  1124.                         }
  1125.                 }
  1126.                 else
  1127.                 {       int x;
  1128.                         x=getSize().width;
  1129.                         for (int k=0; k<Right.size(); k++)
  1130.                         {       IconBarElement i=(IconBarElement)Right.elementAt(k);
  1131.                                 x-=i.width();
  1132.                                 i.setPosition(x,2);
  1133.                                 x-=Offset;
  1134.                         }
  1135.                         int xmax=x;
  1136.                         x=0;
  1137.                         for (int k=0; k<Left.size(); k++)
  1138.                         {       IconBarElement i=(IconBarElement)Left.elementAt(k);
  1139.                                 i.setPosition(x,2);
  1140.                                 x+=i.width();
  1141.                                 x+=Offset;
  1142.                                 if (x+IconWithGif.Size>xmax-10 && k<Left.size()-1)
  1143.                                 {       Overflow=true; OverflowX=x;
  1144.                                         OB=new OverflowButton(this,Shifted);
  1145.                                         add(OB);
  1146.                                         OB.setSize(10,BasicIcon.Size);
  1147.                                         OB.setLocation(xmax-10-Offset,2);
  1148.                                         if (!Shifted)
  1149.                                         {       x=-1000;       
  1150.                                         }
  1151.                                         else
  1152.                                         {       x=xmax-10-2*Offset;
  1153.                                                 for (int l=Left.size()-1; l>=0; l--)
  1154.                                                 {       i=(IconBarElement)Left.elementAt(l);
  1155.                                                         x-=i.width();
  1156.                                                         i.setPosition(x,2);
  1157.                                                         x-=Offset;
  1158.                                                         if (x-IconWithGif.Size<0) x-=1000;
  1159.                                                 }
  1160.                                                 break;
  1161.                                         }
  1162.                                 }
  1163.                         }
  1164.                 }
  1165.         }
  1166.        
  1167.         public void setShifted (boolean flag)
  1168.         {       Shifted=flag;
  1169.                 doLayout();
  1170.         }
  1171.        
  1172.         /**
  1173.         Override the preferred sizes.
  1174.         */
  1175.         public Dimension getPreferredSize ()
  1176.         {       if (Vertical)
  1177.                 {       if (!UseSize) return new Dimension(IconWithGif.Size+4,10);
  1178.                         return new Dimension(IconWithGif.Size+4,W+10);
  1179.                 }
  1180.                 else
  1181.                 {       if (!UseSize) return new Dimension(10,IconWithGif.Size+4);
  1182.                         return new Dimension(W+10,IconWithGif.Size+4);
  1183.                 }
  1184.         }
  1185.         public Dimension getMinimumSize ()
  1186.         {       return getPreferredSize();
  1187.         }
  1188.        
  1189.         // The IconBar can notify one IconBarListener on icon
  1190.         // clicks.
  1191.        
  1192.         IconBarListener L=null;
  1193.        
  1194.         public void setIconBarListener (IconBarListener l)
  1195.         {       L=l;
  1196.         }
  1197.        
  1198.         public void removeIconBarListener (IconBarListener l)
  1199.         {       L=null;
  1200.         }
  1201.        
  1202.         boolean Shift,Control;
  1203.        
  1204.         public void iconPressed (String name, boolean shift, boolean control)
  1205.         {       Shift=shift; Control=control;
  1206.                 removeHelp();
  1207.                 if (L!=null) L.iconPressed(name);
  1208.         }
  1209.        
  1210.         public boolean isShiftPressed () { return Shift; }
  1211.         public boolean isControlPressed () { return Control; }
  1212.         public void clearShiftControl () { Shift=Control=false; }
  1213.        
  1214.         // The tool tip help, initiated by the icons.
  1215.        
  1216.         Window WHelp=null;
  1217.        
  1218.         public synchronized void displayHelp (IconBarElement i, String text)
  1219.         {       if (F==null || WHelp!=null) return;
  1220.                 Point P=i.getPosition();
  1221.                 WHelp=new Window(F);
  1222.                 Panel p=new Panel();
  1223.                 StringTokenizer t=new StringTokenizer(text,"+");
  1224.                 p.setLayout(new GridLayout(0,1));
  1225.                 while (t.hasMoreTokens())
  1226.                 {       p.add(new MyLabel(t.nextToken()));
  1227.                 }
  1228.                 WHelp.add("Center",p);
  1229.                 WHelp.pack();
  1230.                 Dimension d=WHelp.getSize();
  1231.                 Dimension ds=getToolkit().getScreenSize();
  1232.                 int x=P.x,y=P.y+i.width()+10;
  1233.                 if (x+d.width>ds.width) x=ds.width-d.width;
  1234.                 if (y+d.height>ds.height) y=P.y-i.width()-d.height;
  1235.                 WHelp.setLocation(x,y);
  1236.                 WHelp.setBackground(new Color(255,255,220));
  1237.                 WHelp.setForeground(Color.black);
  1238.                 WHelp.setVisible(true);
  1239.         }
  1240.        
  1241.         public synchronized void removeHelp ()
  1242.         {       if (WHelp==null) return;
  1243.                 WHelp.setVisible(false);
  1244.                 WHelp.dispose();
  1245.                 WHelp=null;
  1246.         }
  1247.        
  1248.         private BasicIcon find (String name)
  1249.         {       int k;
  1250.                 for (k=0; k<Left.size(); k++)
  1251.                 {       try
  1252.                         {       BasicIcon i=(BasicIcon)Left.elementAt(k);
  1253.                                 if (i.getName().equals(name)) return i;
  1254.                         }
  1255.                         catch (Exception e) {}
  1256.                 }
  1257.                 for (k=0; k<Right.size(); k++)
  1258.                 {       try
  1259.                         {       BasicIcon i=(BasicIcon)Right.elementAt(k);
  1260.                                 if (i.getName().equals(name)) return i;
  1261.                         }
  1262.                         catch (Exception e) {}
  1263.                 }
  1264.                 return null;
  1265.         }
  1266.  
  1267.         /**
  1268.         Enable the tool with the specified name.
  1269.         */
  1270.         public void setEnabled (String name, boolean flag)
  1271.         {       BasicIcon icon=find(name);
  1272.                 if (icon==null) return;
  1273.                 icon.setEnabled(flag);
  1274.         }
  1275.  
  1276.         /**
  1277.         Select
  1278.         */
  1279.         public void toggle (String name)
  1280.         {       BasicIcon icon=find(name);
  1281.                 if (icon==null || !(icon instanceof ToggleIcon)) return;
  1282.                 ((ToggleIcon)icon).setState(true);
  1283.         }
  1284.        
  1285.         /**
  1286.         Have an Icon?
  1287.         */
  1288.         public boolean have (String name)
  1289.         {       return find(name)!=null;
  1290.         }
  1291.        
  1292.         /**
  1293.         Deselect all icons in the group of an icon
  1294.         */
  1295.         public void unselect (String name)
  1296.         {       BasicIcon icon=find(name);
  1297.                 if (icon==null || !(icon instanceof ToggleIcon)) return;
  1298.                 ((ToggleIcon)icon).unselect();
  1299.         }
  1300.        
  1301.         /**
  1302.         Toggle an item of an item group (known by name and number).
  1303.         */
  1304.         public void toggle (String name, int n)
  1305.         {       toggle(name+n);
  1306.         }
  1307.        
  1308.         /**
  1309.         Set the state of a single toggle icon.
  1310.         */
  1311.         public void setState (String name, boolean flag)
  1312.         {       BasicIcon icon=find(name);
  1313.                 if (icon!=null && (icon instanceof ToggleIcon))
  1314.                         ((ToggleIcon)icon).setState(flag);
  1315.                 if (icon!=null && (icon instanceof MultipleToggleIcon))
  1316.                         ((MultipleToggleIcon)icon).setState(flag);
  1317.         }
  1318.  
  1319.         /**
  1320.         Get the state of the specified toggle icon
  1321.         */
  1322.         public boolean getState (String name)
  1323.         {       BasicIcon icon=find(name);
  1324.                 if (icon==null || !(icon instanceof ToggleIcon)) return false;
  1325.                 return ((ToggleIcon)icon).getState();
  1326.         }
  1327.        
  1328.         /**
  1329.         Return the state of a toggle icon.
  1330.         */
  1331.         public int getToggleState (String name)
  1332.         {       BasicIcon icon=find(name+0);
  1333.                 if (icon==null || !(icon instanceof ToggleIcon)) return -1;
  1334.                 int n=((ToggleIcon)icon).countPeers();
  1335.                 for (int i=0; i<n; i++)
  1336.                 {       if (getState(name+i)) return i;
  1337.                 }
  1338.                 return -1;
  1339.         }
  1340.  
  1341.         /**
  1342.         Get the state of the specified multiple icon
  1343.         */
  1344.         public int getMultipleState (String name)
  1345.         {       int k;
  1346.                 for (k=0; k<Left.size(); k++)
  1347.                 {       IconBarElement i=(IconBarElement)Left.elementAt(k);
  1348.                         if (i.getName().equals(name) && i instanceof MultipleIcon)
  1349.                         {       return ((MultipleIcon)i).getSelected();
  1350.                         }
  1351.                 }
  1352.                 for (k=0; k<Right.size(); k++)
  1353.                 {       IconBarElement i=(IconBarElement)Right.elementAt(k);
  1354.                         if (i.getName().equals(name) && i instanceof MultipleIcon)
  1355.                         {       return ((MultipleIcon)i).getSelected();
  1356.                         }
  1357.                 }
  1358.                 return -1;
  1359.         }
  1360.  
  1361.         /**
  1362.         Set the state of the specified multiple icon
  1363.         */
  1364.         public void setMultipleState (String name, int state)
  1365.         {       int k;
  1366.                 for (k=0; k<Left.size(); k++)
  1367.                 {       IconBarElement i=(IconBarElement)Left.elementAt(k);
  1368.                         if (i.getName().equals(name) && i instanceof MultipleIcon)
  1369.                         {       ((MultipleIcon)i).setSelected(state);
  1370.                         }
  1371.                 }
  1372.                 for (k=0; k<Right.size(); k++)
  1373.                 {       IconBarElement i=(IconBarElement)Right.elementAt(k);
  1374.                         if (i.getName().equals(name) && i instanceof MultipleIcon)
  1375.                         {       ((MultipleIcon)i).setSelected(state);
  1376.                         }
  1377.                 }
  1378.         }
  1379.  
  1380.         /**
  1381.         See, if the specific icon has been set.
  1382.         */
  1383.         public boolean isSet (String name)
  1384.         {       BasicIcon icon=find(name);
  1385.                 if (icon==null) return false;
  1386.                 return icon.isSet();
  1387.         }
  1388.        
  1389.         /**
  1390.         Set the specific icon to unset.
  1391.         */
  1392.         public void unset (String name)
  1393.         {       BasicIcon icon=find(name);
  1394.                 if (icon!=null) icon.unset();
  1395.         }
  1396.        
  1397.         public void getKey (KeyEvent e)
  1398.         {       processKeyEvent(e);
  1399.         }
  1400.        
  1401.         public void setSize (int size)
  1402.         {       BasicIcon.Size=size;
  1403.         }
  1404.        
  1405.         public void removeAll ()
  1406.         {       Enumeration e=Left.elements();
  1407.                 while (e.hasMoreElements())
  1408.                 {       remove((BasicIcon)e.nextElement());
  1409.                 }
  1410.                 e=Right.elements();
  1411.                 while (e.hasMoreElements())
  1412.                 {       remove((BasicIcon)e.nextElement());
  1413.                 }
  1414.                 Left.removeAllElements();
  1415.                 Right.removeAllElements();
  1416.         }
  1417.        
  1418.         /**
  1419.          * Overwrite in children!
  1420.          * @param name
  1421.          * @return Help text
  1422.          */
  1423.         public String getHelp (String name)
  1424.         {       return "";
  1425.         }
  1426.        
  1427.         public static void main (String args[])
  1428.         {       CloseFrame f=new CloseFrame("Test");
  1429.                 IconBar IA=new IconBar(f);
  1430.                 IA.Vertical=true;
  1431.                 IA.setSize(30);
  1432.                 IA.Resource="/icons/";
  1433.                 IA.addLeft("back");
  1434.                 IA.addLeft("undo");
  1435.                 IA.addSeparatorLeft();
  1436.                 IA.addOnOffLeft("grid");
  1437.                 IA.addSeparatorLeft();
  1438.                 IA.addToggleLeft("delete");
  1439.                 IA.addSeparatorLeft();
  1440.                 String tg[]={"zoom","draw","","rename","edit"};
  1441.                 IA.addToggleGroupLeft(tg);
  1442.                 IA.addSeparatorLeft();
  1443.                 IA.addMultipleToggleIconLeft("macro",3);
  1444.                 IA.addSeparatorLeft();
  1445.                 String tga[]={"zoom","draw","rename","edit"};
  1446.                 IA.addLeft(new PopupIcon(IA,tga));
  1447.                 IA.addSeparatorLeft();
  1448.                 String st[]={"A","B","C","D"};
  1449.                 IA.addMultipleStringIconLeft("strings",st);
  1450.                 Color col[]={Color.BLACK,Color.RED,Color.GREEN};
  1451.                 IA.addStateLeft("needsave");
  1452.                 IA.addColorIconLeft("color",col);
  1453.                 f.add("Center",new IconBarPanel(
  1454.                         new Panel3D(IA),new Panel3D(new Panel())));
  1455.                 f.pack();      
  1456.                 f.center();
  1457.                 IA.setIconBarListener(IA);
  1458.                 f.setVisible(true);
  1459.         }
  1460.  
  1461.         public void iconPressed(String name)
  1462.         {       System.out.println(name);
  1463.         }
  1464.  
  1465. }
  1466.