1 19 20 package org.netbeans.modules.scripting.php.dbginterface.ui; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Dimension ; 24 import java.awt.FontMetrics ; 25 import java.util.ResourceBundle ; 26 import javax.swing.JComponent ; 27 import javax.swing.JEditorPane ; 28 import javax.swing.JLabel ; 29 import javax.swing.JPanel ; 30 import javax.swing.JScrollPane ; 31 import javax.swing.border.CompoundBorder ; 32 import javax.swing.border.EmptyBorder ; 33 import javax.swing.text.EditorKit ; 34 import org.openide.awt.Mnemonics; 35 import org.openide.util.NbBundle; 36 37 38 46 public class WatchPanel { 47 48 private JPanel panel; 49 private JEditorPane editorPane; 50 private String expression; 51 52 public WatchPanel(String expression) { 53 this.expression = expression; 54 } 55 56 public static void setupContext(JEditorPane editorPane) { 57 } 89 90 public JComponent getPanel() { 91 if (panel != null) return panel; 92 93 panel = new JPanel (); 94 ResourceBundle bundle = NbBundle.getBundle(WatchPanel.class); 95 96 panel.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_WatchPanel")); JLabel textLabel = new JLabel (); 98 Mnemonics.setLocalizedText(textLabel, bundle.getString ("CTL_Watch_Name")); 100 editorPane = new JEditorPane ("text/javascript", expression); EditorKit kit = editorPane.getEditorKit(); 102 if(kit == null || kit.getClass().getSimpleName().contains("PlainEditorKit")) { editorPane.setContentType("text/x-javascript"); } 105 editorPane.setKeymap(new FilteredKeymap(editorPane.getKeymap())); 106 107 setupContext(editorPane); 108 109 JScrollPane sp = new JScrollPane (editorPane, JScrollPane.VERTICAL_SCROLLBAR_NEVER, 110 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 111 112 textLabel.setBorder (new EmptyBorder (0, 0, 5, 0)); 113 panel.setLayout (new BorderLayout ()); 114 panel.setBorder (new EmptyBorder (11, 12, 1, 11)); 115 panel.add (BorderLayout.NORTH, textLabel); 116 panel.add (BorderLayout.CENTER, sp); 117 118 FontMetrics fm = editorPane.getFontMetrics(editorPane.getFont()); 119 int size = 2*fm.getLeading() + fm.getMaxAscent() + fm.getMaxDescent() + 4; 120 121 editorPane.setPreferredSize(new Dimension (30*size, (int) (1*size))); 122 123 editorPane.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_CTL_Watch_Name")); editorPane.setBorder ( 125 new CompoundBorder (editorPane.getBorder (), 126 new EmptyBorder (2, 0, 2, 0)) 127 ); 128 editorPane.setText (expression); 129 editorPane.selectAll (); 130 131 textLabel.setLabelFor (editorPane); 132 editorPane.requestFocus (); 133 134 return panel; 135 } 136 137 public String getExpression() { 138 return editorPane.getText().trim(); 139 } 140 } 141 | Popular Tags |