1 19 20 package org.netbeans.editor.ext; 21 22 import java.awt.event.*; 23 import java.util.ResourceBundle ; 24 import javax.swing.JPanel ; 25 import javax.swing.DefaultComboBoxModel ; 26 import javax.swing.JTextField ; 27 import javax.swing.JComponent ; 28 import java.util.List ; 29 import java.util.ArrayList ; 30 import java.util.Vector ; 31 32 import org.netbeans.editor.EditorState; 33 import org.openide.util.NbBundle; 34 35 44 public class GotoDialogPanel extends JPanel implements FocusListener { 45 46 static final long serialVersionUID =-8686958102543713464L; 47 private static final String HISTORY_KEY = "GotoDialogPanel.history-goto-line"; private static final int MAX_ITEMS = 20; 49 50 51 private boolean dontFire = false; 52 private KeyEventBlocker blocker; 53 private final ResourceBundle bundle = NbBundle.getBundle(org.netbeans.editor.BaseKit.class); 54 55 56 public GotoDialogPanel() { 57 initComponents (); 58 getAccessibleContext().setAccessibleName(bundle.getString("goto-title")); getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_goto")); gotoCombo.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_goto-line")); List history = (List )EditorState.get( HISTORY_KEY ); 62 if( history == null ) history = new ArrayList (); 63 updateCombo( history ); 64 } 65 66 69 protected void updateCombo( List content ) { 70 dontFire = true; 71 gotoCombo.setModel( new DefaultComboBoxModel ( content.toArray() ) ); 72 dontFire = false; 73 } 74 75 private void initComponents() { 77 java.awt.GridBagConstraints gridBagConstraints; 78 79 gotoLabel = new javax.swing.JLabel (); 80 gotoCombo = new javax.swing.JComboBox (); 81 82 setLayout(new java.awt.GridBagLayout ()); 83 84 gotoLabel.setLabelFor(gotoCombo); 85 gotoLabel.setText(bundle.getString("goto-line")); 86 gotoLabel.setDisplayedMnemonic(bundle.getString("goto-line-mnemonic").charAt(0)); 87 gridBagConstraints = new java.awt.GridBagConstraints (); 88 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 89 gridBagConstraints.weighty = 1.0; 90 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 91 add(gotoLabel, gridBagConstraints); 92 93 gotoCombo.setEditable(true); 94 gridBagConstraints = new java.awt.GridBagConstraints (); 95 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 96 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 97 gridBagConstraints.weightx = 1.0; 98 gridBagConstraints.weighty = 1.0; 99 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 10); 100 add(gotoCombo, gridBagConstraints); 101 102 } 104 105 106 protected javax.swing.JComboBox gotoCombo; 108 protected javax.swing.JLabel gotoLabel; 109 111 112 113 public String getValue() { 114 return (String )gotoCombo.getEditor().getItem(); 115 } 116 117 120 public void updateHistory() { 121 List history = (List )EditorState.get( HISTORY_KEY ); 122 if( history == null ) history = new ArrayList (); 123 124 Object value = getValue(); 125 126 if( history.contains( value ) ) { 127 history.remove( value ); 129 history.add( 0, value ); 130 } else { 131 if( history.size() >= MAX_ITEMS ) 133 history = history.subList(0, MAX_ITEMS-1); 134 history.add( 0, getValue() ); 136 } 137 EditorState.put( HISTORY_KEY, history ); 138 139 updateCombo( history ); 140 } 141 142 145 public void popupNotify(KeyEventBlocker blocker) { 146 this.blocker = blocker; 147 gotoCombo.getEditor().getEditorComponent().addFocusListener(this); 148 gotoCombo.getEditor().selectAll(); 149 gotoCombo.getEditor().getEditorComponent().requestFocus(); 150 } 151 152 public javax.swing.JComboBox getGotoCombo() 153 { 154 return gotoCombo; 155 } 156 157 public void focusGained(FocusEvent e) { 158 if (blocker != null) 159 blocker.stopBlocking(); 160 ((JComponent )e.getSource()).removeFocusListener(this); 161 } 162 163 public void focusLost(FocusEvent e) { 164 } 165 } 166 | Popular Tags |