//***************************************************************************** // ColorFrame.java // 3/11/00 // Popupframe that contains the three canvases. // // Geetika Tewari, Victoria Manfredi and Christie Rice // //***************************************************************************** import java.awt.*; import java.awt.event.*; import java.applet.*; import java.awt.Frame.*; import java.util.*; import java.io.*; public class ColorFrame extends Frame { //************************************************************************** //************************************************************************** // Model //************************************************************************** //************************************************************************** Color StaticColor[]; // Color matrix array (static). Color UserColor[]; // Array of colors that user has created (not static). Color RBColor[]; // Array of colors (one color for each Radio Button). int CurRButton; // Index of the currently selected radio button. int userIndex; // Index in UserColor array to put the next color // the user wants saved. Color curc; // Currently selected color. int r, g, b; // Red, green, and blue values of the current color. // The UserColor array works just like the StaticColor array except that the // user can change the colors in the UserColor array. Therefore, when // different color boxes are clicked in either array, curc, the color for // the currently selected radio button, the scrollbars and the textfields all // change to show the same current color. When curc in the model is changed, // by using one of the controllers, the view is changed as follows: the color // used for the currently selected radio button changes, as do the scroll bars // and textboxes. At all times, the scroll bars, the curc variable in the // ColorFrame class, the currently selected radio button and the textfields // display the same color. When the RBColor array changes, the view will also // change to show the new color for the radio button that was updated. When // CurRButton in the model changes, this changes which index colors will be // stored in the RBColor array. Also, when CurRButton changes, the curc in // ColorFrame current changes to reflect the color of the currently // selected radio button. // //************************************************************************** //************************************************************************** //************************************************************************** // View //************************************************************************** //************************************************************************** ColorPanel cp; ColorRadioButtonPanel rbp; // The 2 panels that ColorFrame contains // The view is the two panels displayed on the ColorFrame and the panels, // canvases, radiobuttons, textfields, and scrollbars placed on these // panels. //************************************************************************** //************************************************************************** //************************************************************************** // Controller //************************************************************************** //************************************************************************** // // The following are controllers as each can be used to change the current // color: // // -The ColorCanvas on the ColorButtonPanel on the ColorPanel: by clicking // on different colors on the ColorCanvas the current color is changed. // -The scroll bars on the ColorScrollTextPanels on the ColorRGBPanel on the // ColorPanel. // -The radio buttons on ColorRadioCanvasPanels on the ColorRadioButtonPanel. // -The text fields on the ColorScrollTextPanels on the ColorRGBPanel on the // ColorPanel. // // //************************************************************************** //**************************** // // constructor // //**************************** ColorFrame(String title) { super(title); // Arrange the main/parent attibute frame on the screen setVisible(true); setBounds(80,300,400,250); //x, y, width, height // Construct the arrays and variables making up the model StaticColor = new Color[Constants.NUM_STAT_COL]; UserColor = new Color[Constants.NUM_USER_COL]; userIndex = 0; RBColor = new Color [Constants.NUM_RADIO_BUT]; // Initialize StaticColor array StaticColor[0] = StaticColor[0].getHSBColor((float) 1.0, (float) 1.0, (float) 1.0); StaticColor[1] = StaticColor[1].getHSBColor((float) 0.9, (float) 1.0, (float) 1.0); StaticColor[2] = StaticColor[2].getHSBColor((float) 0.8, (float) 1.0, (float) 1.0); StaticColor[3] = StaticColor[3].getHSBColor((float) 0.7, (float) 1.0, (float) 1.0); StaticColor[4] = StaticColor[4].getHSBColor((float) 0.6, (float) 1.0, (float) 1.0); StaticColor[5] = StaticColor[5].getHSBColor((float) 0.5, (float) 1.0, (float) 1.0); StaticColor[6] = StaticColor[6].getHSBColor((float) 0.4, (float) 1.0, (float) 1.0); StaticColor[7] = StaticColor[7].getHSBColor((float) 0.3, (float) 1.0, (float) 1.0); StaticColor[8] = StaticColor[8].getHSBColor((float) 0.2, (float) 1.0, (float) 1.0); StaticColor[9] = StaticColor[9].getHSBColor((float) 0.1, (float) 1.0, (float) 1.0); // Initialize UserColor array UserColor[0] = UserColor[0].getHSBColor((float) 1.0, (float) 1.0, (float) 1.0); UserColor[1] = UserColor[1].getHSBColor((float) 0.9, (float) 1.0, (float) 1.0); UserColor[2] = UserColor[2].getHSBColor((float) 0.8, (float) 1.0, (float) 1.0); UserColor[3] = UserColor[3].getHSBColor((float) 0.7, (float) 1.0, (float) 1.0); UserColor[4] = UserColor[4].getHSBColor((float) 0.6, (float) 1.0, (float) 1.0); UserColor[5] = UserColor[5].getHSBColor((float) 0.5, (float) 1.0, (float) 1.0); UserColor[6] = UserColor[6].getHSBColor((float) 0.4, (float) 1.0, (float) 1.0); UserColor[7] = UserColor[7].getHSBColor((float) 0.3, (float) 1.0, (float) 1.0); UserColor[8] = UserColor[8].getHSBColor((float) 0.2, (float) 1.0, (float) 1.0); UserColor[9] = UserColor[9].getHSBColor((float) 0.1, (float) 1.0, (float) 1.0); // Intialize RBColor array RBColor[Constants.PTFILL] = new Color(255,0,0); RBColor[Constants.PTCON] = new Color(255,0,153); RBColor[Constants.BACKGRND] = new Color(204,0,255); RBColor[Constants.GRID] = new Color(50,0,255); RBColor[Constants.AXIS] = new Color(0,101,255); RBColor[Constants.PARABOLA] = new Color(50,255,0); r = 255; g = 100; b = 100; // Current color of the current color square curc = new Color(r, g, b); cp = new ColorPanel(this); rbp= new ColorRadioButtonPanel(this); setBackground(Color.black); // To get the line dividing rbp and cp setLayout(new GridLayout(1, 2, 1, 1)); add(rbp); add(cp); addWindowListener(new ColorCloseWindow()); }// end constructor }//end of class ColorFrame