//***************************************************************************** // ColorButtonPanel.java // // Summer 1999, 2000 // Geetika Tewari, Victoria Manfredi and Christie Rice // // //***************************************************************************** import java.awt.*; import java.awt.event.*; import java.lang.*; import java.io.*; import java.util.*; public class ColorButtonPanel extends Panel implements ActionListener { ColorFrame cf; // Parent ColorCanvas cc; // Components on ColorPanel Button saveButton; // int width, height; // Dimensions of panel GridBagLayout gridbag; // For layout GridBagConstraints constraints; // //******************************** // // constructor // //******************************** public ColorButtonPanel(ColorFrame cff) { super(); cf = cff; cc = new ColorCanvas(cf); saveButton = new Button("SAVE"); saveButton.addActionListener(this); // Make ColorButtonPanel panel take up half of the ColorFrame frame height = cf.getSize().height; width = cf.getSize().width/2; setSize(width, height); setBackground(Color.white); // Setup gridbag layout gridbag = new GridBagLayout(); constraints = new GridBagConstraints(); setLayout(gridbag); buildConstraints(constraints,0,0,3,1,100,100); gridbag.setConstraints(cc,constraints); add(cc); buildConstraints(constraints,1,1,1,1,100,100); gridbag.setConstraints(saveButton,constraints); add(saveButton); }// end constructor //**************************** // // buildConstraints // // // Needed for the gridbag // layout. //**************************** void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) { gbc.gridx = gx; gbc.gridy = gy; gbc.gridwidth = gw; gbc.gridheight = gh; gbc.weightx = wx; gbc.weighty = wy; }// end buildConstraints //******************************* // // actionPerformed // // Needed for the save button. //******************************* public void actionPerformed (ActionEvent e) { // Save the current color in the array of user-defined colors cf.UserColor[cf.userIndex] = cf.curc; // Call paint in ColorCanvas so that the cf.curc in Color Canvas is // updated => ColorCanvas changes => ColorCanvas observers are notified cf.cp.cbp.cc.repaint(); // The array of user-defined colors is a circular array. cf.userIndex = (cf.userIndex + 1) % Constants.NUM_USER_COL; }// end actionPerformed }// end class ColorButtonPanel