1 19 package org.netbeans.modules.java.editor.overridden; 20 21 import java.awt.Component ; 22 import java.awt.Cursor ; 23 import java.awt.Toolkit ; 24 import java.awt.event.FocusEvent ; 25 import java.awt.event.FocusListener ; 26 import java.awt.event.KeyEvent ; 27 import java.awt.event.MouseEvent ; 28 import java.util.List ; 29 import javax.lang.model.element.Element; 30 import javax.lang.model.element.ExecutableElement; 31 import javax.swing.DefaultListCellRenderer ; 32 import javax.swing.DefaultListModel ; 33 import javax.swing.JList ; 34 import javax.swing.JPanel ; 35 import javax.swing.ListModel ; 36 import org.netbeans.api.java.source.JavaSource; 37 import org.netbeans.api.java.source.SourceUtils; 38 import org.netbeans.api.java.source.UiUtils; 39 import org.openide.filesystems.FileObject; 40 41 45 public class IsOverriddenPopup extends JPanel implements FocusListener { 46 47 private String caption; 48 private List <ElementDescription> declarations; 49 50 51 public IsOverriddenPopup(String caption, List <ElementDescription> declarations) { 52 this.caption = caption; 53 this.declarations = declarations; 54 55 initComponents(); 56 57 jList1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 58 59 addFocusListener(this); 60 } 61 62 67 private void initComponents() { 69 java.awt.GridBagConstraints gridBagConstraints; 70 71 jLabel1 = new javax.swing.JLabel (); 72 jScrollPane1 = new javax.swing.JScrollPane (); 73 jList1 = new javax.swing.JList (); 74 75 setFocusCycleRoot(true); 76 setLayout(new java.awt.GridBagLayout ()); 77 78 jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); 79 jLabel1.setText(caption 80 ); 81 jLabel1.setFocusable(false); 82 gridBagConstraints = new java.awt.GridBagConstraints (); 83 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 84 add(jLabel1, gridBagConstraints); 85 86 jList1.setModel(createListModel()); 87 jList1.setCellRenderer(new RendererImpl()); 88 jList1.setSelectedIndex(0); 89 jList1.setVisibleRowCount(declarations.size() 90 ); 91 jList1.addKeyListener(new java.awt.event.KeyAdapter () { 92 public void keyPressed(java.awt.event.KeyEvent evt) { 93 jList1KeyPressed(evt); 94 } 95 }); 96 jList1.addMouseListener(new java.awt.event.MouseAdapter () { 97 public void mouseClicked(java.awt.event.MouseEvent evt) { 98 jList1MouseClicked(evt); 99 } 100 }); 101 jScrollPane1.setViewportView(jList1); 102 103 gridBagConstraints = new java.awt.GridBagConstraints (); 104 gridBagConstraints.gridx = 0; 105 gridBagConstraints.gridy = 1; 106 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 107 gridBagConstraints.weightx = 1.0; 108 gridBagConstraints.weighty = 1.0; 109 add(jScrollPane1, gridBagConstraints); 110 } 112 private void jList1MouseClicked(java.awt.event.MouseEvent evt) { if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 1) { 115 openSelected(); 116 } 117 } 119 private void jList1KeyPressed(java.awt.event.KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_ENTER && evt.getModifiers() == 0) { 122 openSelected(); 123 } 124 } 126 127 private javax.swing.JLabel jLabel1; 129 private javax.swing.JList jList1; 130 private javax.swing.JScrollPane jScrollPane1; 131 133 private void openSelected() { 134 ElementDescription desc = (ElementDescription) jList1.getSelectedValue(); 135 136 if (desc != null) { 137 FileObject file = desc.getSourceFile(); 138 139 if (file != null) { 140 UiUtils.open(file, desc.getHandle()); 141 } else { 142 Toolkit.getDefaultToolkit().beep(); 143 } 144 } 145 146 PopupUtil.hidePopup(); 147 } 148 149 private ListModel createListModel() { 150 DefaultListModel dlm = new DefaultListModel (); 151 152 for (ElementDescription el: declarations) { 153 dlm.addElement(el); 154 } 155 156 return dlm; 157 } 158 159 private static class RendererImpl extends DefaultListCellRenderer { 160 public Component getListCellRendererComponent( 161 JList list, 162 Object value, 163 int index, 164 boolean isSelected, 165 boolean cellHasFocus) { 166 Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 167 168 if (value instanceof ElementDescription) { 169 ElementDescription desc = (ElementDescription) value; 170 171 setIcon(desc.getIcon()); 172 setText(desc.getDisplayName()); 173 } 174 175 return c; 176 } 177 } 178 179 public void focusGained(FocusEvent arg0) { 180 jList1.requestFocus(); 181 jList1.requestFocusInWindow(); 182 } 183 184 public void focusLost(FocusEvent arg0) { 185 } 186 187 } 188 | Popular Tags |