package edu.calpoly.cpe205.fetter; import javax.swing.*; import java.util.*; import java.io.*; import java.lang.reflect.*; import java.lang.*; import java.awt.*; import javax.swing.event.*; import java.awt.event.*; /** * This class represents the JTabbedPane used in the Fields and Methods panel * that hold rows of Field or Method information. This class is responsible * for adding the rows to the appropriate visibility tab */ // Author: Brian Laird // Version History // Nov 18, 2000 - added algorithm pseudocode // Nov 29, 2000 - (Michael Hebron) corrected pseudocode for constructor, // optimized pseudocode for addRow, implemented // constructor, addRow // Nov 29, 2000 - (Mike Power) added addTitles method // Nov 30, 2000 - (Michael Hebron) changed class description, added // javadocs for addTitles // Jan 17, 2001 - (Wes Strickland) checked for Stage One Release. No changes, already // fully implemented. // Feb 10, 2001 - (Jonathon Lee) - updated to coding standards public class VisibilityTabbedPane extends JTabbedPane { /** * Constructs a VisibilityTabbedPane. *

* Pre-conditions: visibility is either Modifier.public, Modifier.private, * Modifier.protected, Modifier.packaged * Post-conditions: constructs a VisibilityTabbedPane */ public VisibilityTabbedPane() { JScrollPane publicSP = new JScrollPane(); // pane for public items JScrollPane protectedSP = new JScrollPane(); // pane for protected items JScrollPane privateSP = new JScrollPane(); // pane for private items JScrollPane packageSP = new JScrollPane(); // pane for packaged local items // SET publicPanel to NEW JPanel // SET privatePanel to NEW JPanel // SET protectedPanel to NEW JPanel // SET packagedPanel to NEW JPanel publicPanel = new JPanel(); privatePanel = new JPanel(); protectedPanel = new JPanel(); packagedPanel = new JPanel(); publicPanel.setLayout(new GridBagLayout()); privatePanel.setLayout(new GridBagLayout()); protectedPanel.setLayout(new GridBagLayout()); packagedPanel.setLayout(new GridBagLayout()); addTitles(publicPanel); addTitles(privatePanel); addTitles(protectedPanel); addTitles(packagedPanel); publicSP.setViewportView(publicPanel); protectedSP.setViewportView(protectedPanel); privateSP.setViewportView(privatePanel); packageSP.setViewportView(packagedPanel); add("public", publicSP); add("protected", protectedSP); add("private", privateSP); add("package local", packageSP); } /** * Adds column headers to the panel pane *

* Pre-conditions: pane must be empty
* Post-condtions: pane contains "Modifiers", "Type", * "Name", "Values" column headers * @param pane the panel to add column headers to */ protected void addTitles(JPanel pane) { pane.setBorder(BorderFactory.createEtchedBorder()); GridBagConstraints cns = new GridBagConstraints(); // constraints for the panel cns.gridx = 0; cns.gridy = GridBagConstraints.RELATIVE; cns.fill = GridBagConstraints.HORIZONTAL; cns.anchor = GridBagConstraints.NORTH; pane.add(new JLabel("Modifiers"), cns); cns.gridx++; pane.add(new JLabel("Type"), cns); cns.gridx++; pane.add(new JLabel("Name"), cns); cns.gridx++; cns.weightx = 1; pane.add(new JLabel("Values"), cns); } /** * Adds a row to either "public", "private", or "protected" tabs. *

* Pre-conditions: none * Post-conditions: row has been added to "public", "private", or "protected" tabs * @param visibility one of three int values: Modifier.public, Modifier.protected, or Modifier.private * @param row the new row that is to be added */ public void addRow(int visibility, RowAbstract row) { // DECLARE targetPanel as JPanel // CONSTRUCT rowPanel as NEW JPanel // CONSTRUCT c as NEW GridBagConstraints ParameterObjectComboBox[] pcb; // combo box for a row JLabel typeLabel; // type of parameter JPanel targetPanel; // public/private/protected JPanel mdf; // modifier panel JPanel rowPanel = new JPanel(); // panel to hold each row rowPanel.setLayout(new BoxLayout(rowPanel, BoxLayout.X_AXIS)); GridBagConstraints c = new GridBagConstraints(); // IF visibility = Modifier.PUBLIC // SET targetPanel to publicPanel // ELSEIF visibility = Modifier.PROTECTED // SET targetPanel to protectedPanel // ELSEIF visibility = Modifier.PRIVATE // SET targetPanel to privatePanel // ELSE // SET targetPanel to packagedPanel /* determine where to put the panel */ if (visibility == Modifier.PUBLIC) { targetPanel = publicPanel; } else if (visibility == Modifier.PROTECTED) { targetPanel = protectedPanel; } else if (visibility == Modifier.PRIVATE) { targetPanel = privatePanel; } else { targetPanel = packagedPanel; } c.gridx = 0; c.gridy = GridBagConstraints.RELATIVE; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.NORTH; // CALL getModifierPanel of row returns mdf // CALL add of targetPanel with mdf // CALL getType of row returns typeLabel // CALL add of targetPanel with typeLabel // CALL add of targetPanel with row // CALL getComboBoxes of row returns pcb[] // CALL getLength of Array with pcb[] returns length // FOR index = 1 to length // CALL add of rowPanel with pcb[index] // ENDFOR // CALL add of targetPanel with rowPanel mdf = row.getModifierPanel(); targetPanel.add(mdf, c); c.gridx++; typeLabel = row.getType(); targetPanel.add(typeLabel, c); c.gridx++; targetPanel.add(row.getNameButton(), c); c.gridx++; c.weightx = 1; pcb = row.getComboBoxes(); int length = Array.getLength(pcb); // number of combo boxes /* for each combo box */ for (int index = 0; index < length; index++) { rowPanel.add(pcb[index]); } targetPanel.add(rowPanel, c); } /** * A JPanel that stores public data */ protected JPanel publicPanel; /** * A JPanel that stores private data */ protected JPanel privatePanel; /** * A JPanel that stores protected data */ protected JPanel protectedPanel; /** * A JPanel that stores packaged data */ protected JPanel packagedPanel; /** @link dependency */ /*#RowAbstract lnkFieldRow;*/ }