1 21 package proguard.gui; 22 23 import proguard.*; 24 import proguard.classfile.util.ClassUtil; 25 26 import java.awt.Component ; 27 import java.awt.event.*; 28 import java.util.*; 29 30 import javax.swing.*; 31 32 33 39 class ClassSpecificationsPanel extends ListPanel 40 { 41 protected ClassSpecificationDialog classSpecificationDialog; 42 43 44 public ClassSpecificationsPanel(JFrame owner, boolean fullKeepOptions) 45 { 46 super(); 47 48 list.setCellRenderer(new MyListCellRenderer()); 49 50 classSpecificationDialog = new ClassSpecificationDialog(owner, fullKeepOptions); 51 52 addAddButton(); 53 addEditButton(); 54 addRemoveButton(); 55 addUpButton(); 56 addDownButton(); 57 58 enableSelectionButtons(); 59 } 60 61 62 protected void addAddButton() 63 { 64 JButton addButton = new JButton(GUIResources.getMessage("add")); 65 addButton.addActionListener(new ActionListener() 66 { 67 public void actionPerformed(ActionEvent e) 68 { 69 setClassSpecification(createClassSpecification()); 70 int returnValue = classSpecificationDialog.showDialog(); 71 if (returnValue == ClassSpecificationDialog.APPROVE_OPTION) 72 { 73 addElement(getClassSpecification()); 75 } 76 } 77 }); 78 79 addButton(addButton); 80 } 81 82 83 protected void addEditButton() 84 { 85 JButton editButton = new JButton(GUIResources.getMessage("edit")); 86 editButton.addActionListener(new ActionListener() 87 { 88 public void actionPerformed(ActionEvent e) 89 { 90 ClassSpecification selectedClassSpecification = 91 (ClassSpecification)list.getSelectedValue(); 92 93 setClassSpecification(selectedClassSpecification); 94 int returnValue = classSpecificationDialog.showDialog(); 95 if (returnValue == ClassSpecificationDialog.APPROVE_OPTION) 96 { 97 setElementAt(getClassSpecification(), 99 list.getSelectedIndex()); 100 } 101 } 102 }); 103 104 addButton(editButton); 105 } 106 107 108 protected ClassSpecification createClassSpecification() 109 { 110 return new ClassSpecification(); 111 } 112 113 114 protected void setClassSpecification(ClassSpecification classSpecification) 115 { 116 classSpecificationDialog.setClassSpecification(classSpecification); 117 } 118 119 120 protected ClassSpecification getClassSpecification() 121 { 122 return classSpecificationDialog.getClassSpecification(); 123 } 124 125 126 129 public void setClassSpecifications(List classSpecifications) 130 { 131 listModel.clear(); 132 133 if (classSpecifications != null) 134 { 135 for (int index = 0; index < classSpecifications.size(); index++) 136 { 137 listModel.addElement(classSpecifications.get(index)); 138 } 139 } 140 141 enableSelectionButtons(); 144 } 145 146 147 150 public List getClassSpecifications() 151 { 152 int size = listModel.size(); 153 if (size == 0) 154 { 155 return null; 156 } 157 158 List classSpecifications = new ArrayList(size); 159 for (int index = 0; index < size; index++) 160 { 161 classSpecifications.add(listModel.get(index)); 162 } 163 164 return classSpecifications; 165 } 166 167 168 171 private static class MyListCellRenderer implements ListCellRenderer 172 { 173 JLabel label = new JLabel(); 174 175 176 178 public Component getListCellRendererComponent(JList list, 179 Object value, 180 int index, 181 boolean isSelected, 182 boolean cellHasFocus) 183 { 184 ClassSpecification classSpecification = (ClassSpecification)value; 185 186 String comments = classSpecification.comments; 187 188 label.setText(comments != null ? comments.trim() : 189 classSpecification.className != null ? (GUIResources.getMessage("class") + ' ' + ClassUtil.externalClassName(classSpecification.className)) : 190 classSpecification.extendsClassName != null ? (GUIResources.getMessage("extensionsOf") + ' ' + ClassUtil.externalClassName(classSpecification.extendsClassName)) : 191 (GUIResources.getMessage("specificationNumber") + index)); 192 193 if (isSelected) 194 { 195 label.setBackground(list.getSelectionBackground()); 196 label.setForeground(list.getSelectionForeground()); 197 } 198 else 199 { 200 label.setBackground(list.getBackground()); 201 label.setForeground(list.getForeground()); 202 } 203 204 label.setOpaque(true); 205 206 return label; 207 } 208 } 209 } 210 | Popular Tags |