import java.awt.*; import javax.swing.*; import java.util.Random; import java.awt.event.*; import javax.swing.event.*; public class MainApplet10 extends JApplet implements ChangeListener, ActionListener, Runnable { Display drawingSurface; static Image OSI; // The off-screen image Graphics g, OSGR; // The on Screen Image static final int MAX_DISTANCE = 3; static int steps = 2; static int total = 0; static int distance = 0; static int color = 0; static int distanceV = 0; static int distanceH = 0; static int width=0; static int height=0; static int option=0; static int zoomFactor=1; static double[] weightV = {1,1,-1.0,-1.0}; static double[] weightH = {1,1,-1.0,-1.0}; static int [][] caGrid; static String nbhdType; Thread animator; //--------------------------------------------------------------------------------------- // // Private Variables for the GUI // //--------------------------------------------------------------------------------------- private JPanel display; private JSlider h1, h2, h3, h4, v1, v2, v3, v4; private JLabel h1Label, h2Label, h3Label, h4Label; private JLabel v1Label, v2Label, v3Label, v4Label; private JLabel ipLabel; private JLabel nbhdLabel; private JLabel type1Label; private JLabel type2Label; private JLabel type3Label; private JLabel type4Label; private JLabel type5Label; private JComboBox ipComboBox; private JRadioButton type1RadioButton; private JRadioButton type2RadioButton; private JRadioButton type3RadioButton; private JRadioButton type4RadioButton; private JRadioButton type5RadioButton; private JLabel lwLabel; private JLabel onLabel; private JLabel offLabel; private JRadioButton onRadioButton; private JRadioButton offRadioButton; private GridBagConstraints constraints; private JLabel blankLabel1, blankLabel2, blankLabel3, blankLabel4; private static JLabel nbhdIconLabel; private JPanel controls; private static JPanel nbhdIcon; // The image for the selected nbhd type private JPanel nbhdPanel; // The grid bag with all the nbhd controls private Image image; // Image for the neighborhood Icon private String[] patterns; // The list of prebuilt patterns for the ComboBox private JButton primaryColorBtn, secondaryColorBtn; private static Color primaryColor, secondaryColor; private static JLabel primaryColorLabel, secondaryColorLabel; //--------------------------------------------------------------------------------------- class Display extends JPanel { // This nested class defines a JPanel that is used // for displaying the content of the applet. An // object of this class is used as the content pane // of the applet. public void draw() { repaint(); } public void paintComponent(Graphics g) { super.paintComponent(g); width = getSize().width; // Get this component's width. height = getSize().height; // Get this component's height. OSI = createImage(width, height); OSGR = OSI.getGraphics(); OSGR.setColor(getBackground()); OSGR.fillRect(0, 0, width, height); if (option==0) initialize(g,OSGR); else { if (option==1) create(g,OSGR); } } // end paintComponent() } // end nested class Display //--------------------------------------------------------------------------------------- public void init() { nbhdType = new String("Type1"); // Initial Nbhd type is Type-1 Container contentPane = getContentPane(); GridBagLayout layout = new GridBagLayout(); contentPane.setLayout(layout); nbhdPanel = new JPanel(); GridBagLayout layout2 = new GridBagLayout(); nbhdPanel.setLayout(layout2); nbhdPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Neighborhood Parameters"), BorderFactory.createEmptyBorder(2,2,2,2))); ActionListener listener = new UIAction(); // // Create Instance Variables for the User Interface // drawingSurface = new Display(); ipLabel = new JLabel ("Interesting Rules :"); nbhdLabel = new JLabel ("Neighborhood :"); blankLabel1 = new JLabel (" "); blankLabel2 = new JLabel (" "); blankLabel3 = new JLabel (" "); blankLabel4 = new JLabel (" "); type1Label = new JLabel ("Type 1 : "); type2Label = new JLabel ("Type 2 : "); type3Label = new JLabel ("Type 3 : "); type4Label = new JLabel ("Type 4 : "); type5Label = new JLabel ("Type 5 : "); lwLabel = new JLabel ("Lock Weights:"); patterns = new String[] {"Maze", "Squiggles", "Blobs", "Zebra - Vertical", "Wiggles", "Zebra - Horizontal", "Zebra - Vertical2", "Squiggles2"}; ipComboBox = new JComboBox(patterns); ipComboBox.addActionListener(listener); type1RadioButton = new JRadioButton(); type2RadioButton = new JRadioButton(); type3RadioButton = new JRadioButton(); type4RadioButton = new JRadioButton(); type5RadioButton = new JRadioButton(); type1RadioButton.setActionCommand("Type1"); type2RadioButton.setActionCommand("Type2"); type3RadioButton.setActionCommand("Type3"); type4RadioButton.setActionCommand("Type4"); type5RadioButton.setActionCommand("Type5"); type1RadioButton.setSelected(true); primaryColorBtn = new JButton("Set Primary Color"); secondaryColorBtn = new JButton("Set Secondary Color"); primaryColorLabel = new JLabel("xxxxxx"); secondaryColorLabel = new JLabel("xxxxxx"); primaryColor = Color.black; secondaryColor = Color.white; ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(type1RadioButton); buttonGroup.add(type2RadioButton); buttonGroup.add(type3RadioButton); buttonGroup.add(type4RadioButton); buttonGroup.add(type5RadioButton); h1 = new JSlider(JSlider.HORIZONTAL,-20,20,0); h2 = new JSlider(JSlider.HORIZONTAL,-20,20,0); h3 = new JSlider(JSlider.HORIZONTAL,-20,20,0); h4 = new JSlider(JSlider.HORIZONTAL,-20,20,0); v1 = new JSlider(JSlider.HORIZONTAL,-20,20,0); v2 = new JSlider(JSlider.HORIZONTAL,-20,20,0); v3 = new JSlider(JSlider.HORIZONTAL,-20,20,0); v4 = new JSlider(JSlider.HORIZONTAL,-20,20,0); h1Label = new JLabel("H1"); h2Label = new JLabel("H2"); h3Label = new JLabel("H3"); h4Label = new JLabel("H4"); v1Label = new JLabel("V1"); v2Label = new JLabel("V2"); v3Label = new JLabel("V3"); v4Label = new JLabel("V4"); controls = new JPanel(); nbhdIcon = new JPanel(); nbhdIcon.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Neighborhood"), BorderFactory.createEmptyBorder(5,5,5,5))); // // Set the constraints and add user interface elements // to the Window // constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH; constraints.anchor = GridBagConstraints.CENTER; add(drawingSurface, 0, 0, 2, 10, 100, 100); constraints.fill = GridBagConstraints.HORIZONTAL; JButton resetBtn = new JButton("Reseed"); resetBtn.addActionListener(this); add(resetBtn, 0, 10, 2, 1, 100, 100); JButton startBtn = new JButton("Run"); startBtn.addActionListener(this); add(startBtn, 0, 11, 2, 1, 100, 100); constraints.fill = GridBagConstraints.HORIZONTAL; add(h1, 0, 12, 1, 1, 100, 100); add(h2, 0, 13, 1, 1, 100, 100); add(h3, 0, 14, 1, 1, 100, 100); add(h4, 0, 15, 1, 1, 100, 100); h1Label.setForeground(Color.red); h2Label.setForeground(Color.yellow); h3Label.setForeground(Color.blue); h4Label.setForeground(Color.green); v1Label.setForeground(Color.red); v2Label.setForeground(Color.yellow); v3Label.setForeground(Color.blue); v4Label.setForeground(Color.green); constraints.fill = GridBagConstraints.BOTH; add(h1Label, 1, 12, 1, 1, 100, 100); add(h2Label, 1, 13, 1, 1, 100, 100); add(h3Label, 1, 14, 1, 1, 100, 100); add(h4Label, 1, 15, 1, 1, 100, 100); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.WEST; addp(nbhdPanel, ipLabel, 0, 0, 2, 1, 100, 100); constraints.anchor = GridBagConstraints.WEST; addp(nbhdPanel, ipComboBox, 2, 0, 1, 1, 100, 100); constraints.anchor = GridBagConstraints.WEST; addp(nbhdPanel, nbhdLabel, 0, 1, 2, 1, 100, 100); constraints.anchor = GridBagConstraints.EAST; addp(nbhdPanel, type1Label, 0, 2, 1, 1, 100, 100); addp(nbhdPanel, type2Label, 0, 3, 1, 1, 100, 100); addp(nbhdPanel, type3Label, 0, 4, 1, 1, 100, 100); addp(nbhdPanel, type4Label, 0, 5, 1, 1, 100, 100); addp(nbhdPanel, type5Label, 0, 6, 1, 1, 100, 100); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.WEST; addp(nbhdPanel, type1RadioButton, 1, 2, 1, 1, 100, 100); addp(nbhdPanel, type2RadioButton, 1, 3, 1, 1, 100, 100); addp(nbhdPanel, type3RadioButton, 1, 4, 1, 1, 100, 100); addp(nbhdPanel, type4RadioButton, 1, 5, 1, 1, 100, 100); addp(nbhdPanel, type5RadioButton, 1, 6, 1, 1, 100, 100); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.anchor = GridBagConstraints.CENTER; addp(nbhdPanel, primaryColorBtn, 0, 8, 2, 1, 100, 100); addp(nbhdPanel, secondaryColorBtn, 0, 9, 2, 1, 100, 100); primaryColorLabel.setBackground(primaryColor); secondaryColorLabel.setBackground(secondaryColor); primaryColorLabel.setForeground(primaryColor); secondaryColorLabel.setForeground(secondaryColor); primaryColorLabel.setOpaque(true); secondaryColorLabel.setOpaque(true); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.WEST; addp(nbhdPanel, primaryColorLabel, 2, 8, 1, 1, 100, 100); addp(nbhdPanel, secondaryColorLabel, 2, 9, 1, 1, 100, 100); image = getImage (getCodeBase (), "images/type1.GIF"); ImageIcon icon = new ImageIcon(image); // Create label for displaying the NBHD. nbhdIconLabel = new JLabel(); nbhdIconLabel.setHorizontalAlignment(JLabel.CENTER); nbhdIconLabel.setVerticalAlignment(JLabel.CENTER); nbhdIconLabel.setVerticalTextPosition(JLabel.CENTER); nbhdIconLabel.setHorizontalTextPosition(JLabel.CENTER); nbhdIconLabel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(0,1,0,1))); nbhdIconLabel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(0,0,1,0), nbhdIconLabel.getBorder())); // Display the first image. nbhdIconLabel.setIcon(icon); nbhdIconLabel.setText(""); nbhdIcon.add(nbhdIconLabel); constraints.fill = GridBagConstraints.BOTH; constraints.anchor = GridBagConstraints.CENTER; addp(nbhdPanel, nbhdIcon, 2, 2, 1, 5, 100, 100); constraints.fill = GridBagConstraints.BOTH; constraints.anchor = GridBagConstraints.CENTER; add(nbhdPanel, 2, 0, 3, 10, 100, 100); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.anchor = GridBagConstraints.CENTER; add(v1, 2, 12, 2, 1, 100, 100); add(v2, 2, 13, 2, 1, 100, 100); add(v3, 2, 14, 2, 1, 100, 100); add(v4, 2, 15, 2, 1, 100, 100); constraints.fill = GridBagConstraints.BOTH; add(v1Label, 4, 12, 1, 1, 100, 100); add(v2Label, 4, 13, 1, 1, 100, 100); add(v3Label, 4, 14, 1, 1, 100, 100); add(v4Label, 4, 15, 1, 1, 100, 100); h1.addChangeListener(this); h2.addChangeListener(this); h3.addChangeListener(this); h4.addChangeListener(this); v1.addChangeListener(this); v2.addChangeListener(this); v3.addChangeListener(this); v4.addChangeListener(this); type1RadioButton.addActionListener(listener); type2RadioButton.addActionListener(listener); type3RadioButton.addActionListener(listener); type4RadioButton.addActionListener(listener); type5RadioButton.addActionListener(listener); PrimaryColorListener primaryColorListener = new PrimaryColorListener(); SecondaryColorListener secondaryColorListener = new SecondaryColorListener(); primaryColorBtn.addActionListener(primaryColorListener); secondaryColorBtn.addActionListener(secondaryColorListener); h1.setValue(20); h2.setValue(20); h3.setValue(-20); h4.setValue(-20); v1.setValue(20); v2.setValue(20); v3.setValue(-20); v4.setValue(-20); //--------------------------------------------------------------------------------------- width = getSize().width; // Get this component's width. height = getSize().height; // Get this component's height. caGrid=new int[width][height]; } // end init() //--------------------------------------------------------------------------------------- public void start () { animator = new Thread(this); animator.start(); } //--------------------------------------------------------------------------------------- public void run() { while (Thread.currentThread() == animator) { repaint(); try { Thread.sleep(5); } catch (InterruptedException e) { break; } } } //--------------------------------------------------------------------------------------- public static void initialize(Graphics g, Graphics OSGR) { Random generator = new Random(); // Initialize the Grid to random numbers for (int i=0; i<=height; i++) { for (int j=0; j<=width; j++) { caGrid [i][j] = generator.nextInt(2); if (caGrid[i][j] == 1) OSGR.setColor(primaryColor); else OSGR.setColor(secondaryColor); OSGR.drawLine(i,j,i,j); } } g.drawImage(OSI, 0, 0, null); // Copy OSI onto the screen } //--------------------------------------------------------------------------------------- public static void create(Graphics g, Graphics OSGR) { int minwidth = 0; // minimum index for elements int minheight = 0; int maxwidth = width; int maxheight = height; // maximum index for elements int sx1,sx2,sy1,sy2,dx1,dy1,dx2,dy2; for (int stepCount=1; stepCount < steps; stepCount++) { for (int i=0; i <= height; i++) { for (int j=0; j <= width; j++) { total = 0; for (int x= i-MAX_DISTANCE; x <= i+MAX_DISTANCE; x++) { for (int y= j-MAX_DISTANCE; y <= j+MAX_DISTANCE; y++) { if ( (x) >= minwidth && (x) <= maxwidth && (y) >= minheight && (y) <= maxheight ) { distanceH = Math.abs(x-i); distanceV = Math.abs(y-j); color = caGrid[x][y]; if (distanceV <= MAX_DISTANCE && distanceH <= MAX_DISTANCE) total += (weightV[distanceV] + weightH[distanceH])/2 * color; } } } if (total > 0) { caGrid[i][j]=1; OSGR.setColor(primaryColor); } else { caGrid[i][j]=0; OSGR.setColor(secondaryColor); } OSGR.drawLine(i,j,i,j); } } g.drawImage(OSI,0,0,null); } } //--------------------------------------------------------------------------------------- public void actionPerformed(ActionEvent evt) { String command = evt.getActionCommand(); // The "action command" associated with the event // is the text on the button that was clicked. if (command.equals("Run")) { option=1; drawingSurface.draw(); } else { option=0; drawingSurface.draw(); } } // end actionPerformed() //--------------------------------------------------------------------------------------- public void stateChanged(ChangeEvent evt) { if (nbhdType.equals("Type1")) { weightH[0] = h1.getValue()/10.0; weightH[1] = h2.getValue()/10.0; weightH[2] = h3.getValue()/10.0; weightH[3] = h4.getValue()/10.0; h1Label.setText(" H1 = " + weightH[0]); h2Label.setText(" H2 = " + weightH[1]); h3Label.setText(" H3 = " + weightH[2]); h4Label.setText(" H4 = " + weightH[3]); weightV[0] = v1.getValue()/10.0; weightV[1] = v2.getValue()/10.0; weightV[2] = v3.getValue()/10.0; weightV[3] = v4.getValue()/10.0; v1Label.setText(" V1 = " + weightV[0]); v2Label.setText(" V2 = " + weightV[1]); v3Label.setText(" V3 = " + weightV[2]); v4Label.setText(" V4 = " + weightV[3]); } if (nbhdType.equals("Type2")) { weightH[0] = h1.getValue()/10.0; weightH[1] = h1.getValue()/10.0; weightH[2] = h3.getValue()/10.0; weightH[3] = h3.getValue()/10.0; h2.setValue(h1.getValue()); h4.setValue(h3.getValue()); h1Label.setText(" H1 = " + weightH[0]); h2Label.setText(" H2 = " + weightH[1]); h3Label.setText(" H3 = " + weightH[2]); h4Label.setText(" H4 = " + weightH[3]); weightV[0] = v1.getValue()/10.0; weightV[1] = v1.getValue()/10.0; weightV[2] = v3.getValue()/10.0; weightV[3] = v3.getValue()/10.0; v2.setValue(v1.getValue()); v4.setValue(v3.getValue()); v1Label.setText(" V1 = " + weightV[0]); v2Label.setText(" V2 = " + weightV[1]); v3Label.setText(" V3 = " + weightV[2]); v4Label.setText(" V4 = " + weightV[3]); } if (nbhdType.equals("Type3")) { weightH[0] = h1.getValue()/10.0; weightH[1] = h2.getValue()/10.0; weightH[2] = h2.getValue()/10.0; weightH[3] = h4.getValue()/10.0; h3.setValue(h2.getValue()); h1Label.setText(" H1 = " + weightH[0]); h2Label.setText(" H2 = " + weightH[1]); h3Label.setText(" H3 = " + weightH[2]); h4Label.setText(" H4 = " + weightH[3]); weightV[0] = v1.getValue()/10.0; weightV[1] = v2.getValue()/10.0; weightV[2] = v2.getValue()/10.0; weightV[3] = v4.getValue()/10.0; v3.setValue(v2.getValue()); v1Label.setText(" V1 = " + weightV[0]); v2Label.setText(" V2 = " + weightV[1]); v3Label.setText(" V3 = " + weightV[2]); v4Label.setText(" V4 = " + weightV[3]); } if (nbhdType.equals("Type4")) { weightH[0] = h1.getValue()/10.0; weightH[1] = h1.getValue()/10.0; weightH[2] = h2.getValue()/10.0; weightH[3] = h3.getValue()/10.0; h2.setValue(h1.getValue()); h1Label.setText(" H1 = " + weightH[0]); h2Label.setText(" H2 = " + weightH[1]); h3Label.setText(" H3 = " + weightH[2]); h4Label.setText(" H4 = " + weightH[3]); weightV[0] = v1.getValue()/10.0; weightV[1] = v1.getValue()/10.0; weightV[2] = v2.getValue()/10.0; weightV[3] = v3.getValue()/10.0; v2.setValue(v1.getValue()); v1Label.setText(" V1 = " + weightV[0]); v2Label.setText(" V2 = " + weightV[1]); v3Label.setText(" V3 = " + weightV[2]); v4Label.setText(" V4 = " + weightV[3]); } if (nbhdType.equals("Type5")) { weightH[0] = h1.getValue()/10.0; weightH[1] = h2.getValue()/10.0; weightH[2] = 0.0; weightH[3] = 0.0; h1Label.setText(" H1 = " + weightH[0]); h2Label.setText(" H2 = " + weightH[1]); h3Label.setText(" H3 = " + weightH[2]); h4Label.setText(" H4 = " + weightH[3]); weightV[0] = v1.getValue()/10.0; weightV[1] = v2.getValue()/10.0; weightV[2] = 0.0; weightV[3] = 0.0; v1Label.setText(" V1 = " + weightV[0]); v2Label.setText(" V2 = " + weightV[1]); v3Label.setText(" V3 = " + weightV[2]); v4Label.setText(" V4 = " + weightV[3]); } } //--------------------------------------------------------------------------------------- public void add(Component c, int x, int y, int w, int h, int wx, int wy) { constraints.gridx = x; constraints.gridy = y; constraints.gridwidth = w; constraints.gridheight = h; constraints.weightx = wx; constraints.weighty = wy; getContentPane().add(c, constraints); } //--------------------------------------------------------------------------------------- public void addp(JPanel cont, Component c, int x, int y, int w, int h, int wx, int wy) { constraints.gridx = x; constraints.gridy = y; constraints.gridwidth = w; constraints.gridheight = h; constraints.weightx = wx; constraints.weighty = wy; cont.add(c, constraints); } //--------------------------------------------------------------------------------------- public void setInterestingPatterns(String selectedItem) { System.out.println("SelectedItem" + ipComboBox.getSelectedItem()); if ("Maze".equals(ipComboBox.getSelectedItem())) { weightH[0] = 1.0; weightH[1] = 1.0; weightH[2] = -1.0; weightH[3] = -1.0; weightV[0] = 1.0; weightV[1] = 1.0; weightV[2] = -1.0; weightV[3] = -1.0; h1.setValue(20); h2.setValue(20); h3.setValue(-20); h4.setValue(-20); v1.setValue(20); v2.setValue(20); v3.setValue(-20); v4.setValue(-20); } if ("Squiggles".equals(ipComboBox.getSelectedItem())) { weightH[0] = 1.0; weightH[1] = -1.0; weightH[2] = 1.0; weightH[3] = -1.0; weightV[0] = 1.0; weightV[1] = 0.0; weightV[2] = 0.0; weightV[3] = -1.0; h1.setValue(20); h2.setValue(-20); h3.setValue(20); h4.setValue(-20); v1.setValue(20); v2.setValue(0); v3.setValue(0); v4.setValue(-20); } if ("Blobs".equals(ipComboBox.getSelectedItem())) { weightH[0] = 1.0; weightH[1] = -1.0; weightH[2] = 1.0; weightH[3] = -1.0; weightV[0] = 1.0; weightV[1] = -1.0; weightV[2] = 1.0; weightV[3] = -1.0; h1.setValue(20); h2.setValue(-20); h3.setValue(20); h4.setValue(-20); v1.setValue(20); v2.setValue(-20); v3.setValue(20); v4.setValue(-20); } if ("Zebra - Vertical".equals(ipComboBox.getSelectedItem())) { weightH[0] = 1.0; weightH[1] = 1.0; weightH[2] = 1.0; weightH[3] = -1.0; weightV[0] = -1.0; weightV[1] = -1.0; weightV[2] = -1.0; weightV[3] = 1.0; h1.setValue(20); h2.setValue(20); h3.setValue(20); h4.setValue(-20); v1.setValue(-20); v2.setValue(-20); v3.setValue(-20); v4.setValue(20); } if ("Wiggles".equals(ipComboBox.getSelectedItem())) { weightH[0] = 1.0; weightH[1] = -1.0; weightH[2] = -1.0; weightH[3] = 1.0; weightV[0] = -1.0; weightV[1] = 1.0; weightV[2] = 1.0; weightV[3] = -1.0; h1.setValue(20); h2.setValue(-20); h3.setValue(-20); h4.setValue(20); v1.setValue(-20); v2.setValue(20); v3.setValue(20); v4.setValue(-20); } if ("Zebra - Horizontal".equals(ipComboBox.getSelectedItem())) { weightH[0] = -1.0; weightH[1] = -1.0; weightH[2] = 1.0; weightH[3] = 1.0; weightV[0] = 1.0; weightV[1] = 1.0; weightV[2] = -1.0; weightV[3] = -1.0; h1.setValue(-20); h2.setValue(-20); h3.setValue(20); h4.setValue(20); v1.setValue(20); v2.setValue(20); v3.setValue(-20); v4.setValue(-20); } if ("Zebra - Vertical2".equals(ipComboBox.getSelectedItem())) { weightH[0] = 1.0; weightH[1] = 1.0; weightH[2] = -1.0; weightH[3] = -1.0; weightV[0] = -1.0; weightV[1] = -1.0; weightV[2] = 1.0; weightV[3] = 1.0; h1.setValue(20); h2.setValue(20); h3.setValue(-20); h4.setValue(-20); v1.setValue(-20); v2.setValue(-20); v3.setValue(20); v4.setValue(20); } if ("Squiggles2".equals(ipComboBox.getSelectedItem())) { weightH[0] = 1.0; weightH[1] = -1.0; weightH[2] = -1.0; weightH[3] = 1.0; weightV[0] = 1.0; weightV[1] = -1.0; weightV[2] = -1.0; weightV[3] = 1.0; h1.setValue(20); h2.setValue(-20); h3.setValue(-20); h4.setValue(20); v1.setValue(20); v2.setValue(-20); v3.setValue(-20); v4.setValue(20); } } //--------------------------------------------------------------------------------------- public void setNbhdType1() { nbhdType = "Type1"; image = getImage (getCodeBase (), "images/type1.GIF"); ImageIcon icon = new ImageIcon(image); nbhdIconLabel.setHorizontalAlignment(JLabel.CENTER); nbhdIconLabel.setVerticalAlignment(JLabel.CENTER); nbhdIconLabel.setVerticalTextPosition(JLabel.CENTER); nbhdIconLabel.setHorizontalTextPosition(JLabel.CENTER); nbhdIconLabel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(0,1,0,1))); nbhdIconLabel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(0,0,1,0), nbhdIconLabel.getBorder())); // Display the 2nd image. nbhdIconLabel.setIcon(icon); nbhdIconLabel.setText(""); h1Label.setForeground(Color.red); h2Label.setForeground(Color.yellow); h3Label.setForeground(Color.blue); h4Label.setForeground(Color.green); v1Label.setForeground(Color.red); v2Label.setForeground(Color.yellow); v3Label.setForeground(Color.blue); v4Label.setForeground(Color.green); System.out.println("Setting type 1"); } //--------------------------------------------------------------------------------------- public void setNbhdType2() { nbhdType = "Type2"; image = getImage (getCodeBase (), "images/type2.GIF"); ImageIcon icon = new ImageIcon(image); nbhdIconLabel.setHorizontalAlignment(JLabel.CENTER); nbhdIconLabel.setVerticalAlignment(JLabel.CENTER); nbhdIconLabel.setVerticalTextPosition(JLabel.CENTER); nbhdIconLabel.setHorizontalTextPosition(JLabel.CENTER); nbhdIconLabel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(0,1,0,1))); nbhdIconLabel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(0,0,1,0), nbhdIconLabel.getBorder())); // Display the 2nd image. nbhdIconLabel.setIcon(icon); nbhdIconLabel.setText(""); h1Label.setForeground(Color.red); h2Label.setForeground(Color.red); h3Label.setForeground(Color.yellow); h4Label.setForeground(Color.yellow); v1Label.setForeground(Color.red); v2Label.setForeground(Color.red); v3Label.setForeground(Color.yellow); v4Label.setForeground(Color.yellow); System.out.println("Setting type 2"); } //--------------------------------------------------------------------------------------- public void setNbhdType3() { nbhdType = "Type3"; image = getImage (getCodeBase (), "images/type3.GIF"); ImageIcon icon = new ImageIcon(image); nbhdIconLabel.setHorizontalAlignment(JLabel.CENTER); nbhdIconLabel.setVerticalAlignment(JLabel.CENTER); nbhdIconLabel.setVerticalTextPosition(JLabel.CENTER); nbhdIconLabel.setHorizontalTextPosition(JLabel.CENTER); nbhdIconLabel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(0,1,0,1))); nbhdIconLabel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(0,0,1,0), nbhdIconLabel.getBorder())); // Display the 2nd image. nbhdIconLabel.setIcon(icon); nbhdIconLabel.setText(""); h1Label.setForeground(Color.red); h2Label.setForeground(Color.yellow); h3Label.setForeground(Color.yellow); h4Label.setForeground(Color.blue); v1Label.setForeground(Color.red); v2Label.setForeground(Color.yellow); v3Label.setForeground(Color.yellow); v4Label.setForeground(Color.blue); System.out.println("Setting type 3"); } //--------------------------------------------------------------------------------------- public void setNbhdType4() { nbhdType = "Type4"; image = getImage (getCodeBase (), "images/type4.GIF"); ImageIcon icon = new ImageIcon(image); nbhdIconLabel.setHorizontalAlignment(JLabel.CENTER); nbhdIconLabel.setVerticalAlignment(JLabel.CENTER); nbhdIconLabel.setVerticalTextPosition(JLabel.CENTER); nbhdIconLabel.setHorizontalTextPosition(JLabel.CENTER); nbhdIconLabel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(0,1,0,1))); nbhdIconLabel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(0,0,1,0), nbhdIconLabel.getBorder())); // Display the 2nd image. nbhdIconLabel.setIcon(icon); nbhdIconLabel.setText(""); h1Label.setForeground(Color.red); h2Label.setForeground(Color.red); h3Label.setForeground(Color.yellow); h4Label.setForeground(Color.blue); v1Label.setForeground(Color.red); v2Label.setForeground(Color.red); v3Label.setForeground(Color.yellow); v4Label.setForeground(Color.blue); System.out.println("Setting type 4"); } //--------------------------------------------------------------------------------------- public void setNbhdType5() { nbhdType = "Type5"; image = getImage (getCodeBase (), "images/type5.GIF"); ImageIcon icon = new ImageIcon(image); nbhdIconLabel.setHorizontalAlignment(JLabel.CENTER); nbhdIconLabel.setVerticalAlignment(JLabel.CENTER); nbhdIconLabel.setVerticalTextPosition(JLabel.CENTER); nbhdIconLabel.setHorizontalTextPosition(JLabel.CENTER); nbhdIconLabel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(0,1,0,1))); nbhdIconLabel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(0,0,1,0), nbhdIconLabel.getBorder())); // Display the 2nd image. nbhdIconLabel.setIcon(icon); nbhdIconLabel.setText(""); h1Label.setForeground(Color.red); h2Label.setForeground(Color.yellow); h3Label.setForeground(Color.gray); h4Label.setForeground(Color.gray); v1Label.setForeground(Color.red); v2Label.setForeground(Color.yellow); v3Label.setForeground(Color.gray); v4Label.setForeground(Color.gray); System.out.println("Setting type 5"); } //--------------------------------------------------------------------------------------- private class UIAction implements ActionListener { public void actionPerformed(ActionEvent event) { System.out.println(event.getActionCommand()); if ("comboBoxChanged".equals(event.getActionCommand())) { setInterestingPatterns((String)ipComboBox.getSelectedItem()); } if ("Type1".equals(event.getActionCommand())) { ipComboBox.setEnabled(true); h1.setEnabled(true); h2.setEnabled(true); h3.setEnabled(true); h4.setEnabled(true); v1.setEnabled(true); v2.setEnabled(true); v3.setEnabled(true); v4.setEnabled(true); setNbhdType1(); } if ("Type2".equals(event.getActionCommand())) { ipComboBox.setEnabled(false); h1.setEnabled(true); h2.setEnabled(false); h3.setEnabled(true); h4.setEnabled(false); v1.setEnabled(true); v2.setEnabled(false); v3.setEnabled(true); v4.setEnabled(false); setNbhdType2(); } if ("Type3".equals(event.getActionCommand())) { ipComboBox.setEnabled(false); h1.setEnabled(true); h2.setEnabled(true); h3.setEnabled(false); h4.setEnabled(true); v1.setEnabled(true); v2.setEnabled(true); v3.setEnabled(false); v4.setEnabled(true); setNbhdType3(); } if ("Type4".equals(event.getActionCommand())) { ipComboBox.setEnabled(false); h1.setEnabled(true); h2.setEnabled(false); h3.setEnabled(true); h4.setEnabled(true); v1.setEnabled(true); v2.setEnabled(false); v3.setEnabled(true); v4.setEnabled(true); setNbhdType4(); } if ("Type5".equals(event.getActionCommand())) { ipComboBox.setEnabled(false); h1.setEnabled(true); h2.setEnabled(true); h3.setEnabled(false); h4.setEnabled(false); v1.setEnabled(true); v2.setEnabled(true); v3.setEnabled(false); v4.setEnabled(false); setNbhdType5(); } } } //--------------------------------------------------------------------------------------- private class PrimaryColorListener implements ActionListener { public void actionPerformed(ActionEvent event) { primaryColor = JColorChooser.showDialog(nbhdPanel, "Set Primary Color", Color.red); System.out.println(primaryColor); primaryColorLabel.setForeground(primaryColor); primaryColorLabel.setBackground(primaryColor); } } private class SecondaryColorListener implements ActionListener { public void actionPerformed(ActionEvent event) { secondaryColor = JColorChooser.showDialog(nbhdPanel, "Set Secondary", Color.orange); System.out.println(secondaryColor); secondaryColorLabel.setForeground(secondaryColor); secondaryColorLabel.setBackground(secondaryColor); } } }