1 19 20 package org.gjt.sp.jedit.gui; 21 22 import javax.swing.border.*; 23 import javax.swing.*; 24 import java.awt.event.*; 25 import java.awt.*; 26 import org.gjt.sp.jedit.*; 27 28 public class AddAbbrevDialog extends JDialog 29 { 30 public AddAbbrevDialog(View view, String abbrev) 31 { 32 super(view,jEdit.getProperty("add-abbrev.title"),true); 33 34 this.view = view; 35 36 JPanel content = new JPanel(new BorderLayout()); 37 content.setBorder(new EmptyBorder(12,12,12,12)); 38 setContentPane(content); 39 40 editor = new AbbrevEditor(); 41 editor.setAbbrev(abbrev); 42 editor.setBorder(new EmptyBorder(6,0,12,0)); 43 content.add(BorderLayout.CENTER,editor); 44 45 Box box = new Box(BoxLayout.X_AXIS); 46 box.add(Box.createGlue()); 47 global = new JButton(jEdit.getProperty("add-abbrev.global")); 48 global.addActionListener(new ActionHandler()); 49 box.add(global); 50 box.add(Box.createHorizontalStrut(6)); 51 modeSpecific = new JButton(jEdit.getProperty("add-abbrev.mode")); 52 modeSpecific.addActionListener(new ActionHandler()); 53 box.add(modeSpecific); 54 box.add(Box.createHorizontalStrut(6)); 55 cancel = new JButton(jEdit.getProperty("common.cancel")); 56 cancel.addActionListener(new ActionHandler()); 57 box.add(cancel); 58 box.add(Box.createGlue()); 59 content.add(BorderLayout.SOUTH,box); 60 61 KeyListener listener = new KeyHandler(); 62 addKeyListener(listener); 63 editor.getBeforeCaretTextArea().addKeyListener(listener); 64 editor.getAfterCaretTextArea().addKeyListener(listener); 65 66 setDefaultCloseOperation(DISPOSE_ON_CLOSE); 67 68 if(abbrev == null) 69 GUIUtilities.requestFocus(this,editor.getAbbrevField()); 70 else 71 GUIUtilities.requestFocus(this,editor.getBeforeCaretTextArea()); 72 73 pack(); 74 setLocationRelativeTo(view); 75 setVisible(true); 76 } 77 78 private View view; 80 private AbbrevEditor editor; 81 private JButton global; 82 private JButton modeSpecific; 83 private JButton cancel; 84 85 class ActionHandler implements ActionListener 86 { 87 public void actionPerformed(ActionEvent evt) 88 { 89 Object source = evt.getSource(); 90 if(source == global) 91 { 92 String _abbrev = editor.getAbbrev(); 93 if(_abbrev == null || _abbrev.length() == 0) 94 { 95 getToolkit().beep(); 96 return; 97 } 98 Abbrevs.addGlobalAbbrev(_abbrev,editor.getExpansion()); 99 Abbrevs.expandAbbrev(view,false); 100 } 101 else if(source == modeSpecific) 102 { 103 String _abbrev = editor.getAbbrev(); 104 if(_abbrev == null || _abbrev.length() == 0) 105 { 106 getToolkit().beep(); 107 return; 108 } 109 Abbrevs.addModeAbbrev(view.getBuffer().getMode().getName(), 110 _abbrev,editor.getExpansion()); 111 Abbrevs.expandAbbrev(view,false); 112 } 113 114 dispose(); 115 } 116 } 117 118 class KeyHandler extends KeyAdapter 119 { 120 public void keyPressed(KeyEvent evt) 121 { 122 if(evt.getKeyCode() == KeyEvent.VK_ESCAPE) 123 dispose(); 124 } 125 } 126 } 127 | Popular Tags |