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