001 package swingui;
002
003 import java.awt.Dimension;
004 import java.awt.GridLayout;
005
006 import javax.swing.JPanel;
007 import javax.swing.JTabbedPane;
008
009 import components.Absorber;
010 import components.Ball;
011 import components.GameObject;
012
013 /** The DetailPanel is a mutable class that displays detailed information about
014 * a particular object, when it is selected in build mode.
015 * <p>
016 * DetailPanel contains several panes that can represent different types of information
017 * about an object. Depending on the type of object passed into update(),
018 * DetailPanel will use different panes -- i.e. only Absorbers will display the AbsorberPanel,
019 * which contains information about whether a ball is held inside the Absorber.
020 *
021 * @author ruthdhan
022 *
023 */
024 public class DetailPanel extends JPanel {
025 //fields
026 private MainGUI gui;
027
028 //the panels
029 private OrientationPanel orientPanel;
030 private TriggerPanel triggerPanel;
031 private DelayPanel delayPanel;
032 private TargetPanel targetPanel;
033 private VelocityPanel velocityPanel;
034 private AbsorberPanel absorberPanel;
035
036 //the pane
037 private JTabbedPane tabbedPane;
038 private int tab; //which tab is selected
039
040 //selected
041 private GameObject selected;
042
043 public DetailPanel(MainGUI gui) {
044 super();
045 this.gui = gui;
046
047 // THE PANELS
048 orientPanel = new OrientationPanel();
049 triggerPanel = new TriggerPanel();
050 delayPanel = new DelayPanel();
051 targetPanel = new TargetPanel(gui);
052 velocityPanel = new VelocityPanel();
053 absorberPanel = new AbsorberPanel();
054
055 //the tabbed pane
056 tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
057 tabbedPane.setPreferredSize(new Dimension(225, 300));
058 tab = 0;
059
060 ///////////////////////////////
061 //putting everything together//
062 ///////////////////////////////
063 this.add(tabbedPane);
064 this.setVisible(true);
065 }
066
067 /** update the detail panel UI with information about obj
068 * @requires obj != null
069 */
070 public void update(GameObject obj) {
071 selected = obj;
072 //System.err.println("entered update with obj="+obj);
073
074 //if ball, show velocity section
075 if (selected instanceof Ball) {
076 this.setLayout(new GridLayout(1, 1));
077 velocityPanel.setObject(obj);
078 tabbedPane.add(velocityPanel);
079 } else {
080 this.setLayout(new GridLayout(1, 4));
081
082 //absorbers don't have o-panel
083 if (selected instanceof Absorber) {
084 absorberPanel.setObject(obj);
085 tabbedPane.add(absorberPanel);
086 } else {
087 orientPanel.setObject(obj);
088 tabbedPane.add(orientPanel);
089 }
090
091 //trigger/delay/target for all gizmos
092 triggerPanel.setObject(obj);
093 delayPanel.setObject(obj);
094 targetPanel.setObject(obj);
095 tabbedPane.add(triggerPanel);
096 tabbedPane.add(delayPanel);
097 tabbedPane.add(targetPanel);
098 }
099 try {
100 tabbedPane.setSelectedIndex(tab);
101 } catch (IndexOutOfBoundsException e) {
102 tabbedPane.setSelectedIndex(0);
103 }
104 this.add(tabbedPane);
105
106 //check:
107 System.err.println("count="+this.getComponentCount()+ ", comp="+this.getComponents());
108
109 //repaint
110 this.setVisible(true);
111 this.repaint();
112 }
113
114
115 /** clear the detail panel (i.e. in play mode) **/
116 public void clear() {
117 //System.out.println("clear detail panel");
118 this.removeAll();
119 tab = tabbedPane.getSelectedIndex();
120 tabbedPane.removeAll();
121 this.repaint();
122 }
123 }