/* Copyright F. P. Marin ( Wed Jun 04 16:18:46 1997 ) E-mail: felix@bloch.ciens.ucv.ve Permission to use, copy, modify and distribute this software and its documentation for NON-COMERCIAL purposes and without fee is hereby granted provided that this copyright notice appears in all copies. F. P. Marin makes no representations or warranties about the suitability of the software, either express or implied, including but no limited to the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. F. P. Marin shall not be liable for any damage suffered by license as a result of using, modifying or distributing this software or its derivatives. HTML code is: */ import java.awt.*; public class HtmlColor extends java.applet.Applet { Color bgColor=Color.black,textColor=Color.black; Color linkColor=Color.black,vlinkColor=Color.black; Color alinkColor=Color.black; Font fnt=new Font("Courier",Font.BOLD,48); FontMetrics fm=getFontMetrics(fnt); int xt,yt,xl,yl,xv,yv,xa,ya,h; NorthPanel np=new NorthPanel(this); SouthPanel sp=new SouthPanel(this); String s[]={"Text","Link","Vlink","Alink"}; public void init() { setBackground(Color.white); setLayout(new BorderLayout()); add("North",np); add("South",sp); xt=(size().width - fm.stringWidth(s[0]))/2; xl=(size().width - fm.stringWidth(s[1]))/2; xv=(size().width - fm.stringWidth(s[2]))/2; xa=(size().width - fm.stringWidth(s[3]))/2; h=fm.getHeight(); yt=(size().height - 4*h)/2 + h; yl=yt + h; yv=yl + h; ya=yv + h; repaint(); } public Insets insets() { return new Insets(0,0,0,0); } public void update(OneColor OC) { if ( OC==np.oc[0] ) bgColor=np.oc[0].c; else if ( OC==np.oc[1] ) textColor=np.oc[1].c; else if ( OC==sp.oc[0] ) linkColor=sp.oc[0].c; else if ( OC==sp.oc[1] ) vlinkColor=sp.oc[1].c; else alinkColor=sp.oc[2].c; repaint(); } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { g.setColor(bgColor); g.fillRect(0,0,size().width,size().height); g.setFont(fnt); g.setColor(textColor); g.drawString(s[0],xt,yt); g.setColor(linkColor); g.drawString(s[1],xl,yl); g.setColor(vlinkColor); g.drawString(s[2],xv,yv); g.setColor(alinkColor); g.drawString(s[3],xa,ya); } } class OneColor extends Panel { Color c; HtmlColor mother; Slider s[]=new Slider[3]; OneColor(String name,HtmlColor mother) { super(); this.mother=mother; setLayout(new GridLayout(4,1)); setFont(new Font("TimesRoman",Font.BOLD + Font.ITALIC,18)); add(new Label(name,Label.CENTER)); add(s[0]=new Slider("Red",this)); add(s[1]=new Slider("Green",this)); add(s[2]=new Slider("Blue",this)); c=new Color(s[0].val,s[1].val,s[2].val); } void update() { c=new Color(s[0].val,s[1].val,s[2].val); mother.update(this); } } class NorthPanel extends Panel { HtmlColor mother; OneColor oc[]=new OneColor[2]; NorthPanel(HtmlColor mother) { super(); this.mother=mother; setLayout(new GridLayout(1,2)); add(oc[0]=new OneColor("Bgcolor ",this.mother)); add(oc[1]=new OneColor("Text ",this.mother)); mother.bgColor=oc[0].c; mother.textColor=oc[1].c; } } class Slider extends Panel { double slope; int sbmin,val; Label l=new Label("0"); OneColor mother; Scrollbar sb=new Scrollbar(Scrollbar.HORIZONTAL,0,5,0,255); Slider(String color,OneColor mother) { super(); this.mother=mother; setLayout(new GridLayout(1,3)); if ( color.equals("Red") ) setForeground(Color.red.brighter()); else if ( color.equals("Green") ) setForeground(Color.green.brighter()); else setForeground(Color.blue.brighter()); setFont(new Font("Helvetica",Font.BOLD,14)); add(new Label(color + " ",Label.RIGHT)); add(sb); add(l); sbmin=sb.getMinimum(); slope=255.0/(sb.getMaximum() - sbmin); val=((int)(256.0*Math.random()))%256; sb.setValue(val); l.setText(" " + String.valueOf(val)); } public boolean handleEvent(Event e) { val=(int)(slope*(sb.getValue() - sbmin) + 0.5); if ( val<0 ) val=0; else if ( val>255 ) val=255; l.setText(" " + String.valueOf(val)); mother.update(); return true; } } class SouthPanel extends Panel { HtmlColor mother; OneColor oc[]=new OneColor[3]; SouthPanel(HtmlColor mother) { super(); this.mother=mother; setLayout(new GridLayout(1,3)); add(oc[0]=new OneColor("Link",this.mother)); add(oc[1]=new OneColor("Vlink",this.mother)); add(oc[2]=new OneColor("Alink",this.mother)); mother.linkColor=oc[0].c; mother.vlinkColor=oc[1].c; mother.alinkColor=oc[2].c; } }