001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc;
005:
006: import org.dijon.ButtonGroup;
007: import org.dijon.CheckBox;
008: import org.dijon.Component;
009: import org.dijon.Container;
010: import org.dijon.ContainerResource;
011: import org.dijon.Label;
012: import org.dijon.List;
013: import org.dijon.ListModel;
014: import org.dijon.RadioButton;
015:
016: import java.awt.Insets;
017: import java.awt.event.ActionEvent;
018: import java.awt.event.ActionListener;
019:
020: public class InstrumentTypePanel extends Container {
021: private Label m_messageLabel;
022: private ButtonGroup m_buttonGroup;
023: private RadioButton m_classButton;
024: private RadioButton m_packageButton;
025: private CheckBox m_restartToggle;
026: private String m_className;
027: private String m_packageName;
028: private Container m_super TypesPanel;
029: private List m_super TypesList;
030: private Container m_super TypesStandin;
031: private Container m_bootTypesPanel;
032: private List m_bootTypesList;
033: private Container m_bootTypesStandin;
034:
035: private static final String INCLUDE_ALL_PATTERN = "*..*";
036:
037: public InstrumentTypePanel(ContainerResource res) {
038: super (res);
039: }
040:
041: public void load(ContainerResource res) {
042: super .load(res);
043:
044: m_messageLabel = (Label) findComponent("MessageLabel");
045: m_classButton = (RadioButton) findComponent("ClassButton");
046: m_buttonGroup = (ButtonGroup) findComponent("ButtonGroup");
047: m_packageButton = (RadioButton) findComponent("PackageButton");
048: m_super TypesPanel = (Container) findComponent("SuperTypesPanel");
049: m_super TypesStandin = new Container();
050: m_super TypesList = (List) m_super TypesPanel
051: .findComponent("SuperTypesList");
052: m_bootTypesPanel = (Container) findComponent("BootTypesPanel");
053: m_bootTypesStandin = new Container();
054: m_bootTypesList = (List) m_bootTypesPanel
055: .findComponent("BootTypesList");
056: m_restartToggle = (CheckBox) findComponent("RestartToggle");
057:
058: m_buttonGroup.addActionListener(new ActionListener() {
059: public void actionPerformed(ActionEvent ae) {
060: if (m_super TypesPanel.getParent() != null) {
061: m_super TypesPanel.setEnabled(m_buttonGroup
062: .getSelectedIndex() != 2);
063: }
064: }
065: });
066:
067: int buttonCount = m_buttonGroup.getChildCount();
068: for (int i = 0; i < buttonCount; i++) {
069: Component comp = m_buttonGroup.getChildAt(i);
070: Insets margin = new Insets(0, 0, 0, 0);
071:
072: if (comp instanceof RadioButton) {
073: ((RadioButton) comp).setMargin(margin);
074: }
075: }
076: }
077:
078: public void setup(String msg, String className,
079: java.util.List bootTypes, java.util.List super Types) {
080: m_messageLabel.setText(msg);
081:
082: m_className = className;
083: m_packageName = className.substring(0, className
084: .lastIndexOf('.'));
085:
086: m_classButton.setText("Type '" + className + "'");
087: m_packageButton.setText("All types in package '"
088: + m_packageName + "'");
089: m_buttonGroup.setSelected("ClassButton");
090:
091: if (super Types.size() > 0) {
092: if (m_super TypesPanel.getParent() == null) {
093: replaceChild(m_super TypesStandin, m_super TypesPanel);
094: }
095: m_super TypesList.setModel(new ListModel(super Types));
096: } else if (m_super TypesPanel.getParent() != null) {
097: replaceChild(m_super TypesPanel, m_super TypesStandin);
098: }
099:
100: if (bootTypes.size() > 0) {
101: if (m_bootTypesPanel.getParent() == null) {
102: replaceChild(m_bootTypesStandin, m_bootTypesPanel);
103: }
104: m_bootTypesList.setModel(new ListModel(bootTypes));
105: } else if (m_bootTypesPanel.getParent() != null) {
106: replaceChild(m_bootTypesPanel, m_bootTypesStandin);
107: }
108:
109: m_restartToggle.setSelected(true);
110: }
111:
112: public boolean instrumentClass() {
113: return m_classButton.isSelected();
114: }
115:
116: public String getPattern() {
117: switch (m_buttonGroup.getSelectedIndex()) {
118: case 0:
119: return m_className;
120: case 1:
121: return m_packageName + ".*";
122: default:
123: return INCLUDE_ALL_PATTERN;
124: }
125: }
126:
127: public boolean includeAll() {
128: return getPattern().equals(INCLUDE_ALL_PATTERN);
129: }
130:
131: public boolean restartSystem() {
132: return m_restartToggle.isSelected();
133: }
134: }
|