1 2 25 26 package org.aspectj.ajde.ui.swing; 27 28 import java.awt.*; 29 import java.awt.event.*; 30 import java.io.File ; 31 32 import javax.swing.*; 33 import javax.swing.event.*; 34 import java.util.*; 35 import org.aspectj.ajde.*; 36 import org.aspectj.asm.*; 37 import org.aspectj.asm.views.*; 38 import org.aspectj.ajde.ui.*; 39 import javax.swing.border.*; 40 41 public class SimpleStructureViewToolPanel extends JPanel { 42 43 private StructureView currentView; 44 private JButton separator_button = new JButton(); 45 private boolean hideNonAJEnabled = false; 46 private boolean hideAssociationsEnabled = false; 47 private boolean sortEnabled = false; 48 49 Border border1; 50 Border border2; 51 JButton structureView_button = new JButton(); 52 JPanel label_panel = new JPanel(); 53 JLabel currConfig_field = new JLabel(); 54 JPanel spacer_panel = new JPanel(); 55 JPanel jPanel2 = new JPanel(); 56 JButton forward_button = new JButton(); 57 JPanel navigation_panel = new JPanel(); 58 JButton back_button = new JButton(); 59 BorderLayout borderLayout1 = new BorderLayout(); 60 JPanel buttons_panel = new JPanel(); 61 BorderLayout borderLayout2 = new BorderLayout(); 62 BorderLayout borderLayout3 = new BorderLayout(); 63 BorderLayout borderLayout4 = new BorderLayout(); 64 65 public final StructureModelListener MODEL_LISTENER = new StructureModelListener() { 66 public void modelUpdated(StructureModel model) { 67 String path = Ajde.getDefault().getConfigurationManager().getActiveConfigFile(); 68 String fileName = "<no active config>"; 69 if (path != null) fileName = new File (path).getName(); 70 updateCurrConfigLabel(fileName); 71 } 72 }; 73 74 JButton hideNonAJ_button = new JButton(); 75 JPanel navigation_panel1 = new JPanel(); 76 JButton hideAssociations_button = new JButton(); 77 BorderLayout borderLayout5 = new BorderLayout(); 78 JButton sort_button = new JButton(); 79 80 public SimpleStructureViewToolPanel(StructureView currentView) { 81 this.currentView = currentView; 82 Ajde.getDefault().getStructureModelManager().addListener(MODEL_LISTENER); 83 try { 84 jbInit(); 85 } catch (Exception e) { 86 Ajde.getDefault().getErrorHandler().handleError("Could not initialize GUI.", e); 87 } 88 updateCurrConfigLabel("<no active config>"); 89 } 90 91 private void updateCurrConfigLabel(String text) { 92 currConfig_field.setText(" File View (" + text + ")"); 93 } 94 95 private void jbInit() throws Exception { 96 border1 = BorderFactory.createBevelBorder(BevelBorder.LOWERED,Color.white,Color.white,new Color(156, 156, 158),new Color(109, 109, 110)); 97 border2 = BorderFactory.createEmptyBorder(0,1,0,0); 98 99 100 101 separator_button.setPreferredSize(new Dimension(2, 16)); 102 separator_button.setMinimumSize(new Dimension(2, 16)); 103 separator_button.setEnabled(false); 104 separator_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); 105 separator_button.setMaximumSize(new Dimension(2, 16)); 106 107 108 structureView_button.addActionListener(new java.awt.event.ActionListener () { 109 public void actionPerformed(ActionEvent e) { 110 structureView_button_actionPerformed(e); 111 } 112 }); 113 structureView_button.setIcon(AjdeUIManager.getDefault().getIconRegistry().getStructureViewIcon()); 114 structureView_button.setBorder(border2); 115 structureView_button.setToolTipText("Navigate back"); 116 structureView_button.setPreferredSize(new Dimension(20, 20)); 117 structureView_button.setMinimumSize(new Dimension(20, 20)); 118 structureView_button.setMaximumSize(new Dimension(24, 20)); 119 currConfig_field.setBackground(SystemColor.control); 120 currConfig_field.setFont(new java.awt.Font ("SansSerif", 0, 11)); 121 currConfig_field.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); 122 currConfig_field.setText(" "); 124 125 forward_button.addActionListener(new java.awt.event.ActionListener () { 126 public void actionPerformed(ActionEvent e) { 127 forward_button_actionPerformed(e); 128 } 129 }); 130 forward_button.setIcon(AjdeUIManager.getDefault().getIconRegistry().getForwardIcon()); 131 forward_button.setToolTipText("Navigate forward"); 132 forward_button.setPreferredSize(new Dimension(20, 20)); 133 forward_button.setMinimumSize(new Dimension(20, 20)); 134 forward_button.setMaximumSize(new Dimension(24, 20)); 135 forward_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); 136 navigation_panel.setLayout(borderLayout1); 137 back_button.setMaximumSize(new Dimension(24, 20)); 138 back_button.setMinimumSize(new Dimension(20, 20)); 139 back_button.setPreferredSize(new Dimension(20, 20)); 140 back_button.setToolTipText("Navigate back"); 141 back_button.setIcon(AjdeUIManager.getDefault().getIconRegistry().getBackIcon()); 142 back_button.addActionListener(new java.awt.event.ActionListener () { 143 public void actionPerformed(ActionEvent e) { 144 back_button_actionPerformed(e); 145 } 146 }); 147 back_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); 148 this.setLayout(borderLayout2); 149 buttons_panel.setLayout(borderLayout3); 150 label_panel.setLayout(borderLayout4); 151 hideNonAJ_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); 152 hideNonAJ_button.setMaximumSize(new Dimension(24, 20)); 153 hideNonAJ_button.setMinimumSize(new Dimension(20, 20)); 154 hideNonAJ_button.setPreferredSize(new Dimension(20, 20)); 155 hideNonAJ_button.setToolTipText("Hide non-AspectJ members"); 156 hideNonAJ_button.setIcon(AjdeUIManager.getDefault().getIconRegistry().getHideNonAJIcon()); 157 hideNonAJ_button.addActionListener(new java.awt.event.ActionListener () { 158 public void actionPerformed(ActionEvent e) { 159 hideNonAJ_button_actionPerformed(e); 160 } 161 }); 162 navigation_panel1.setLayout(borderLayout5); 163 hideAssociations_button.setMaximumSize(new Dimension(24, 20)); 164 hideAssociations_button.setMinimumSize(new Dimension(20, 20)); 165 hideAssociations_button.setPreferredSize(new Dimension(20, 20)); 166 hideAssociations_button.setToolTipText("Hide associations"); 167 hideAssociations_button.setIcon(AjdeUIManager.getDefault().getIconRegistry().getHideAssociationsIcon()); 168 hideAssociations_button.addActionListener(new java.awt.event.ActionListener () { 169 public void actionPerformed(ActionEvent e) { 170 hideAssociations_button_actionPerformed(e); 171 } 172 }); 173 hideAssociations_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); 174 sort_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); 175 sort_button.addActionListener(new java.awt.event.ActionListener () { 176 public void actionPerformed(ActionEvent e) { 177 sort_button_actionPerformed(e); 178 } 179 }); 180 sort_button.setIcon(AjdeUIManager.getDefault().getIconRegistry().getOrderIcon()); 181 sort_button.setToolTipText("Sort member"); 182 sort_button.setPreferredSize(new Dimension(20, 20)); 183 sort_button.setMinimumSize(new Dimension(20, 20)); 184 sort_button.setMaximumSize(new Dimension(24, 20)); 185 label_panel.add(currConfig_field, BorderLayout.CENTER); 186 this.add(spacer_panel, BorderLayout.CENTER); 188 this.add(buttons_panel, BorderLayout.EAST); 189 buttons_panel.add(navigation_panel, BorderLayout.CENTER); 190 navigation_panel.add(back_button, BorderLayout.CENTER); 191 navigation_panel.add(forward_button, BorderLayout.EAST); 192 navigation_panel.add(jPanel2, BorderLayout.WEST); 193 buttons_panel.add(navigation_panel1, BorderLayout.WEST); 194 navigation_panel1.add(hideAssociations_button, BorderLayout.EAST); 195 navigation_panel1.add(hideNonAJ_button, BorderLayout.CENTER); 196 navigation_panel1.add(sort_button, BorderLayout.WEST); 197 this.add(label_panel, BorderLayout.WEST); 198 199 200 } 201 202 private void forward_button_actionPerformed(ActionEvent e) { 203 Ajde.getDefault().getStructureViewManager().fireNavigateForwardAction(currentView); 204 } 205 206 private void back_button_actionPerformed(ActionEvent e) { 207 Ajde.getDefault().getStructureViewManager().fireNavigateBackAction(currentView); 208 } 209 210 void structureView_button_actionPerformed(ActionEvent e) { 211 212 } 213 214 private void hideNonAJ_button_actionPerformed(ActionEvent e) { 215 if (hideNonAJEnabled) { 216 hideNonAJ_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); 217 hideNonAJEnabled = false; 218 currentView.getViewProperties().setFilteredMemberKinds(new ArrayList()); 219 } else { 220 hideNonAJ_button.setBorder(AjdeWidgetStyles.LOWERED_BEVEL_BORDER); 221 hideNonAJEnabled = true; 222 currentView.getViewProperties().setFilteredMemberKinds( 223 ProgramElementNode.Kind.getNonAJMemberKinds() 224 ); 225 } 226 Ajde.getDefault().getStructureViewManager().refreshView(currentView); 227 } 228 229 private void hideAssociations_button_actionPerformed(ActionEvent e) { 230 if (hideAssociationsEnabled) { 231 hideAssociations_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); 232 hideAssociationsEnabled = false; 233 currentView.getViewProperties().setRelations( 234 Ajde.getDefault().getStructureViewManager().getAvailableRelations() 235 ); 236 } else { 237 hideAssociations_button.setBorder(AjdeWidgetStyles.LOWERED_BEVEL_BORDER); 238 hideAssociationsEnabled = true; 239 currentView.getViewProperties().setRelations(new ArrayList()); 240 } 241 Ajde.getDefault().getStructureViewManager().refreshView(currentView); 242 } 243 244 private void sort_button_actionPerformed(ActionEvent e) { 245 if (sortEnabled) { 246 sort_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); 247 sortEnabled = false; 248 currentView.getViewProperties().setSorting( 249 StructureViewProperties.Sorting.DECLARATIONAL 250 ); 251 } else { 252 sort_button.setBorder(AjdeWidgetStyles.LOWERED_BEVEL_BORDER); 253 sortEnabled = true; 254 currentView.getViewProperties().setSorting( 255 StructureViewProperties.Sorting.ALPHABETICAL 256 ); 257 } 258 Ajde.getDefault().getStructureViewManager().refreshView(currentView); 259 } 260 } 261 | Popular Tags |