1 26 27 package org.objectweb.util.browser.plugin.java.reflect; 28 29 import java.awt.event.ItemEvent ; 30 import java.awt.event.ItemListener ; 31 32 import javax.swing.BorderFactory ; 33 import javax.swing.Box ; 34 import javax.swing.BoxLayout ; 35 import javax.swing.JCheckBox ; 36 import javax.swing.JPanel ; 37 38 import org.objectweb.util.browser.gui.api.ValidateReport; 39 import org.objectweb.util.browser.gui.lib.AbstractElementBox; 40 import org.objectweb.util.browser.gui.lib.DefaultValidateReport; 41 42 50 public class ClassVisibilityBox 51 extends AbstractElementBox { 52 53 59 protected ClassVisibilityConfig oldConfig_, newConfig_; 60 61 62 68 71 public ClassVisibilityBox() { 72 this(null); 73 } 74 75 public ClassVisibilityBox(ClassVisibilityConfig config) { 76 super(true); 77 78 if(config!=null) 79 oldConfig_ = config; 80 else 81 oldConfig_ = new ClassVisibilityConfig(); 82 newConfig_ = (ClassVisibilityConfig)oldConfig_.clone(); 83 84 Box mainBox = Box.createVerticalBox(); 85 86 Box treeInheritanceBox = Box.createHorizontalBox(); 87 treeInheritanceBox.add(Box.createHorizontalGlue()); 88 JPanel treeInheritancePanel = createHorizontalPanel("Tree Inheritance"); 89 treeInheritancePanel.add(createCheckBox("Tree inheritance", ClassVisibilityConfig.TREE_INHERITANCE)); 90 treeInheritancePanel.add(createCheckBox("Flat view", ClassVisibilityConfig.FLAT_VIEW)); 91 treeInheritanceBox.add(treeInheritancePanel); 92 treeInheritanceBox.add(Box.createHorizontalGlue()); 93 94 mainBox.add(treeInheritanceBox); 95 96 mainBox.add(Box.createVerticalStrut(10)); 97 98 Box classVisibilityBox = Box.createHorizontalBox(); 99 100 classVisibilityBox.add(Box.createHorizontalGlue()); 101 102 JPanel attributesPanel = createVerticalPanel("Attributes"); 103 attributesPanel.add(createCheckBox("public", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.PUBLIC)); 104 attributesPanel.add(createCheckBox("protected", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.PROTECTED)); 105 attributesPanel.add(createCheckBox("private", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.PRIVATE)); 106 attributesPanel.add(createCheckBox("package", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.PACKAGE)); 107 attributesPanel.add(createCheckBox("static", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.STATIC)); 108 attributesPanel.add(createCheckBox("final", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.FINAL)); 109 attributesPanel.add(createCheckBox("display the type", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.TYPE)); 110 attributesPanel.add(createCheckBox("display declaring class", ClassVisibilityConfig.ATTRIBUTE + "." + ClassVisibilityConfig.DECLARING_CLASS)); 111 classVisibilityBox.add(attributesPanel); 112 113 classVisibilityBox.add(Box.createHorizontalStrut(10)); 114 115 JPanel methodsPanel = createVerticalPanel("Methods"); 116 methodsPanel.add(createCheckBox("public", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.PUBLIC)); 117 methodsPanel.add(createCheckBox("protected", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.PROTECTED)); 118 methodsPanel.add(createCheckBox("private", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.PRIVATE)); 119 methodsPanel.add(createCheckBox("package", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.PACKAGE)); 120 methodsPanel.add(createCheckBox("static", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.STATIC)); 121 methodsPanel.add(createCheckBox("final", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.FINAL)); 122 methodsPanel.add(createCheckBox("abstract", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.ABSTRACT)); 123 methodsPanel.add(createCheckBox("display the params", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.PARAMS)); 124 methodsPanel.add(createCheckBox("display the return type", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.RETURN_TYPE)); 125 methodsPanel.add(createCheckBox("display declaring class", ClassVisibilityConfig.METHOD + "." + ClassVisibilityConfig.DECLARING_CLASS)); 126 classVisibilityBox.add(methodsPanel); 127 128 classVisibilityBox.add(Box.createHorizontalStrut(10)); 129 130 JPanel innerClassPanel = createVerticalPanel("Inner Classes"); 131 innerClassPanel.add(createCheckBox("public", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.PUBLIC)); 132 innerClassPanel.add(createCheckBox("protected", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.PROTECTED)); 133 innerClassPanel.add(createCheckBox("private", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.PRIVATE)); 134 innerClassPanel.add(createCheckBox("package", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.PACKAGE)); 135 innerClassPanel.add(createCheckBox("static", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.STATIC)); 136 innerClassPanel.add(createCheckBox("final", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.FINAL)); 137 innerClassPanel.add(createCheckBox("abstract", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.ABSTRACT)); 138 innerClassPanel.add(createCheckBox("display declaring class", ClassVisibilityConfig.INNER_CLASS + "." + ClassVisibilityConfig.DECLARING_CLASS)); 139 classVisibilityBox.add(innerClassPanel); 140 141 classVisibilityBox.add(Box.createHorizontalGlue()); 142 143 mainBox.add(classVisibilityBox); 144 145 add(mainBox); 146 } 147 148 154 protected JPanel createVerticalPanel(String title){ 155 JPanel panel = new JPanel (); 156 panel.setBorder(BorderFactory.createTitledBorder(title)); 157 panel.setLayout(new BoxLayout (panel, BoxLayout.Y_AXIS)); 158 panel.setAlignmentY(TOP_ALIGNMENT); 159 panel.setAlignmentX(LEFT_ALIGNMENT); 160 return panel; 161 } 162 163 protected JPanel createHorizontalPanel(String title){ 164 JPanel panel = new JPanel (); 165 panel.setBorder(BorderFactory.createTitledBorder(title)); 166 panel.setLayout(new BoxLayout (panel, BoxLayout.X_AXIS)); 167 panel.setAlignmentY(TOP_ALIGNMENT); 168 panel.setAlignmentX(LEFT_ALIGNMENT); 169 return panel; 170 } 171 172 protected JCheckBox createCheckBox(String label, String name){ 173 JCheckBox checkBox = new JCheckBox (label); 174 checkBox.setSelected(newConfig_.get(name)); 175 checkBox.addItemListener(new ChangeState(name, checkBox)); 176 return checkBox; 177 } 178 179 185 public ValidateReport validateBox() { 186 return new DefaultValidateReport(); 187 } 188 189 195 public ClassVisibilityConfig getConfig(){ 196 return newConfig_; 197 } 198 199 205 private final class ChangeState 206 implements ItemListener { 207 208 protected String state_; 209 protected JCheckBox checkBox_; 210 211 public ChangeState(String state, JCheckBox checkBox){ 212 state_ = state; 213 checkBox_ = checkBox; 214 } 215 216 public void itemStateChanged(ItemEvent e) { 217 newConfig_.put(state_, checkBox_.isSelected()); 218 } 219 220 } 221 222 } 223 224 | Popular Tags |