//mainFrame.java // generates a frame to cover the screen for the text. //Title: General Classes //Version: 0.1 //Author: John Krantz //Company: Hanover College //Description: Some general classes to control the look and feel //of the book package. package util; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; // Gabor Imports import gui.*; import output.*; /** * Contructs a screen size frame with the defaults already inplace * base upon JFrame. * @author John Krantz * @version 0.1 */ public class ParameterFrame extends MainFrame { static final long serialVersionUID = 0; public final static Dimension SCREENSIZE = Toolkit.getDefaultToolkit().getScreenSize(); // contaner to hold panel private Container c = this.getContentPane(); //Panel object to hold parameters to be set private JPanel titlePanel = new JPanel(new BorderLayout()); private JPanel holdPanel = new JPanel(); // title object private JLabel titleLabel = new JLabel("Title"); // parameter object private JLabel paramLabel [] = new JLabel[3]; private JTextField param [] = new JTextField[3]; // done button public JButton applyButton = new JButton("Apply"); public JButton doneButton = new JButton("Done"); // menu objects private Analyze control; Menus menu; ParameterFrame pf; // add a title to the same frame as above. public ParameterFrame(String title, String [] paramNames, String [] paramDefaults, Analyze ga){ Font titleFont = new Font("SansSerif",Font.BOLD,18); Font labelFont = new Font("SansSerif",Font.PLAIN,12); titleLabel.setFont(titleFont); titleLabel.setText(title); // set up the menus control = ga; menu = new Menus(this,control,false); // parameters to determine the size of the window int h = 0; int w = 0; FontMetrics fm = titleLabel.getFontMetrics(titleFont); h = fm.getHeight(); w = fm.stringWidth(titleLabel.getText()); fm = titleLabel.getFontMetrics(labelFont); this.getContentPane().setBackground(Color.black); this.setForeground(Color.white); this.setTitle(titleLabel.getText()); // set primary layout c.add(titlePanel,BorderLayout.NORTH); titlePanel.add(titleLabel,BorderLayout.CENTER); c.add(holdPanel,BorderLayout.CENTER); // set up the parameters objects paramLabel = new JLabel[paramNames.length]; param = new JTextField[paramNames.length]; holdPanel.setLayout(new GridLayout(param.length,2)); // add the parameter objects for (int i = 0; i < param.length; i ++){ paramLabel[i] = new JLabel(" "+paramNames[i]+" : "); param[i] = new JTextField(paramDefaults[i]); param[i].setEditable(true); holdPanel.add(paramLabel[i]); holdPanel.add(param[i]); h += fm.getHeight(); if (fm.stringWidth(paramLabel[i].getText())+ fm.stringWidth(param[i].getText()) > w){ w = fm.stringWidth(paramLabel[i].getText())+ fm.stringWidth(param[i].getText()); } } // add the done button JPanel donePanel = new JPanel(new FlowLayout()); donePanel.add(applyButton); donePanel.add(doneButton); c.add(donePanel, BorderLayout.SOUTH); h += fm.getHeight(); this.setSize(new Dimension(w*17/10,h*20/10)); pf = this; setupListeners(); } private void setupListeners(){ // read the thresholds setting panel's apply button applyButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ control.showPlot(); } });// and thresholds apply button // read the thresholds setting panel's done button doneButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ pf.setVisible(false); control.showPlot(); } });// end threshold done button } // set methods public void setParamValues(String [] paramDefaults){ for (int i = 0; i < param.length; i ++){ param[i].setText(paramDefaults[i]); } } // get methods public String [] getParameters(){ String [] out = new String[param.length]; for (int i = 0; i < param.length; i ++){ out[i] = param[i].getText(); } return out; } public int getFrameHeight(){ return getHeight();} public int getFrameWidth(){ return getWidth();} }