//***************************************************************************** // ColorScrollTextPanel.java // // 15/3/00 // Geetika Tewari, Christie Rice & Victoria Manfredi // // //***************************************************************************** import java.awt.*; import java.awt.event.*; import java.lang.*; import java.io.*; import java.applet.*; import java.util.*; public class ColorScrollTextPanel extends Panel implements AdjustmentListener { ColorFrame cf; // Parent GridBagLayout gridbag; Label rgbLabel; // Scrollbar rgbScrollbar; // Components of the ScrollTextPanel panel TextField rgbTextField; // int whichSlider; ColorTextFieldHandler TFHandler; //******************************** // // constructor // //******************************** public ColorScrollTextPanel(ColorFrame cff, Label l, Scrollbar s, TextField t, Color bkgrndColor, int ws, ColorTextFieldHandler tfh) { super(); cf = cff; rgbLabel = l; rgbScrollbar = s; rgbTextField = t; whichSlider = ws; TFHandler = tfh; rgbScrollbar.addAdjustmentListener(this); // Begin GridBagLayout setup gridbag = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); setLayout(gridbag); buildConstraints(constraints, 0, 1, 1, 1, 20, 100); constraints.anchor = GridBagConstraints.EAST; gridbag.setConstraints(rgbLabel, constraints); add(rgbLabel); buildConstraints(constraints, 1, 1, 3, 1, 80, 100); constraints.fill = GridBagConstraints.HORIZONTAL; gridbag.setConstraints(rgbScrollbar, constraints); add(rgbScrollbar); buildConstraints(constraints, 4, 1, 1, 1, 20, 100); constraints.anchor = GridBagConstraints.WEST; constraints.fill = GridBagConstraints.NONE; gridbag.setConstraints(rgbTextField, constraints); rgbTextField.addTextListener(TFHandler); add(rgbTextField); setBackground(bkgrndColor); }// end constructor //******************************** // // buildConstraints // //******************************** public void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) { // Set up helper method for using a GridBagLayout gbc.gridx = gx; gbc.gridy = gy; gbc.gridwidth = gw; gbc.gridheight = gh; gbc.weightx = wx; gbc.weighty = wy; }// end buildConstraints //*********************************** // // adjustmentValueChanged // //*********************************** public void adjustmentValueChanged(AdjustmentEvent e) { // 0 = red, 1 = green, 2 = blue if (whichSlider == 0 ) { cf.r = e.getValue(); // initialize the red component of the // currently selected color // Set current color to the new color and repaint so that // observers of ColorCanvas know that the current color // has changed and so will change to show the new current color. cf.curc = new Color (cf.r, cf.g, cf.b); cf.cp.cbp.cc.repaint(); }// end if red else if (whichSlider == 1 ) { cf.g = e.getValue(); // initialize the green component of the // currently selected color // Set current color to the new color and repaint so that // observers of ColorCanvas know that the current color // has changed and so will change to show the new current color. cf.curc = new Color (cf.r, cf.g, cf.b); cf.cp.cbp.cc.repaint(); }// end if green else if (whichSlider == 2) { cf.b = e.getValue(); // initialize the blue component of the // currently selected color // Set current color to the new color and repaint so that // observers of ColorCanvas know that the current color // has changed and so will change to show the new current color. cf.curc = new Color (cf.r, cf.g, cf.b); cf.cp.cbp.cc.repaint(); }// end if blue }// end adjustmentValueChanged }// end ColorScrollTextPanel