package genegui; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import javax.swing.*; import affectors.*; import main.*; /** AffectorViewPanel.java Displays information about an An Affector Template and allows some values to be modified. @author WJS */ public class AffectorViewPanel extends JPanel implements GuiInterface { /** The MainGui object that this belongs to */ private MainGui TheMainGui; /** The AFfector Template */ private AffectorTemplate TheTemplate; public AffectorViewPanel(AffectorTemplate affectorTemplate, MainGui theMainGui) { TheTemplate = affectorTemplate; TheMainGui = theMainGui; setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); setBackground(Color.lightGray); // Show the name of the Affector String nameString = TheTemplate.getAffectorName(); nameString = nameString.substring(nameString.indexOf("affector.")+11); JLabel name = new JLabel(nameString); name.setFont(new Font("Helvetica",Font.BOLD,16)); name.setOpaque(false); JPanel namePanel = new JPanel(); namePanel.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.black)); namePanel.setLayout(new BoxLayout(namePanel,BoxLayout.X_AXIS)); namePanel.add(name); JPanel filler = new JPanel(); filler.setOpaque(false); namePanel.add(filler); namePanel.setBackground(Color.white); add(namePanel); // Create all the sub-panels, one for each parameter AffectorViewSubPanel subPanel; int parameterNumber; Enumeration e = TheTemplate.getAffectorParameters(); while (e.hasMoreElements()) { parameterNumber = ((Integer)e.nextElement()).intValue(); subPanel = new AffectorViewSubPanel(parameterNumber); add(subPanel); } // Add the set button that applies all changes JPanel p = new JPanel(); p.setBackground(Color.lightGray); p.setLayout(new BorderLayout()); JButton setButton = new JButton("Apply Changes"); setButton.setOpaque(false); setButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setValues(); } }); p.add(setButton,BorderLayout.CENTER); add(p); } /** Reads the parameter values from the JTextFields and applys them to the Network. @author WJS */ private void setValues() { Component c[] = getComponents(); for (int i=0;i