Back to index

wims  3.65+svn20090927
ColorEditor.java
Go to the documentation of this file.
00001 package rene.dialogs;
00002 
00003 import java.awt.Color;
00004 import java.awt.Frame;
00005 import java.awt.GridLayout;
00006 import java.awt.Label;
00007 import java.awt.Panel;
00008 import java.awt.Scrollbar;
00009 import java.awt.event.AdjustmentEvent;
00010 import java.awt.event.AdjustmentListener;
00011 import java.awt.event.FocusEvent;
00012 import java.awt.event.FocusListener;
00013 
00014 import rene.gui.ButtonAction;
00015 import rene.gui.CloseDialog;
00016 import rene.gui.DoActionListener;
00017 import rene.gui.Global;
00018 import rene.gui.IntField;
00019 import rene.gui.MyLabel;
00020 import rene.gui.MyPanel;
00021 import rene.gui.Panel3D;
00022 
00023 class ColorScrollbar extends Panel 
00024     implements AdjustmentListener, DoActionListener, FocusListener
00025 {      public int Value;
00026        ColorEditor CE;
00027        Scrollbar SB;
00028        IntField L;
00029        public ColorScrollbar (ColorEditor ce, String s, int value)
00030        {      CE=ce;
00031               setLayout(new GridLayout(1,0));
00032               Value=value;
00033               Panel p=new MyPanel();
00034               p.setLayout(new GridLayout(1,0));
00035               p.add(new MyLabel(s));
00036               p.add(L=new IntField(this,"L",Value,4));
00037               add(p);
00038               add(SB=new Scrollbar(Scrollbar.HORIZONTAL,value,40,0,295));
00039               SB.addAdjustmentListener(this);
00040               L.addFocusListener(this);
00041        }
00042        public void focusLost (FocusEvent e)
00043        {      doAction("L");
00044        }
00045        public void focusGained (FocusEvent e)
00046        {      doAction("L");
00047        }
00048        public void doAction (String o)
00049        {      if ("L".equals(o))
00050               {      Value=L.value(0,255);
00051                      SB.setValue(Value);
00052                      CE.setcolor();
00053               }
00054        }
00055        public void itemAction (String o, boolean flag) {}
00056        public void adjustmentValueChanged (AdjustmentEvent e)
00057        {      Value=SB.getValue();
00058               L.set(Value);
00059               SB.setValue(Value);
00060               CE.setcolor();
00061        }
00062        public int value () { return L.value(0,255); }
00063 }
00064 
00071 public class ColorEditor extends CloseDialog
00072 {      ColorScrollbar Red, Green, Blue;
00073        Label RedLabel,GreenLabel,BlueLabel;
00074        Color C;
00075        Panel CP;
00076        String Name;
00077        public ColorEditor (Frame F, String s, Color c)
00078        {      super(F,Global.name("coloreditor.title"),true);
00079               Name=s;
00080               C=Global.getParameter(s,c);
00081               if (C==null) C=new Color(255,255,255);
00082               Panel p=new MyPanel();
00083               p.setLayout(new GridLayout(0,1));
00084               p.add(Red=new ColorScrollbar(this,
00085                      Global.name("coloreditor.red"),C.getRed()));
00086               p.add(Green=new ColorScrollbar(this,
00087                      Global.name("coloreditor.green"),C.getGreen()));
00088               p.add(Blue=new ColorScrollbar(this,
00089                      Global.name("coloreditor.blue"),C.getBlue()));
00090               add("Center",new Panel3D(p));
00091               Panel pb=new MyPanel();
00092               pb.add(new ButtonAction(this,Global.name("OK"),"OK"));
00093               pb.add(new ButtonAction(this,Global.name("abort"),"Close"));
00094               add("South",new Panel3D(pb));
00095               CP=new MyPanel();
00096               CP.add(new MyLabel(Global.name("coloreditor.color")));
00097               CP.setBackground(C);
00098               add("North",new Panel3D(CP));
00099               pack();
00100        }
00101        public void doAction (String o)
00102        {      if ("Close".equals(o))
00103               {      doclose();
00104               }
00105               else if ("OK".equals(o))
00106               {      setcolor();
00107                      Global.setParameter(Name,C);
00108                      doclose();
00109               }
00110        }
00111        public void setcolor ()
00112        {      C=new Color(Red.value(),Green.value(),Blue.value());
00113               CP.setBackground(C);
00114               CP.repaint();
00115        }
00116 }