1 7 package javax.swing.text.html; 8 9 import java.awt.*; 10 import java.awt.event.*; 11 import java.net.URLEncoder ; 12 import java.net.MalformedURLException ; 13 import java.io.IOException ; 14 import java.net.URL ; 15 import javax.swing.text.*; 16 import javax.swing.*; 17 18 19 26 27 class IsindexView extends ComponentView implements ActionListener { 28 29 JTextField textField; 30 31 34 public IsindexView(Element elem) { 35 super(elem); 36 } 37 38 44 public Component createComponent() { 45 AttributeSet attr = getElement().getAttributes(); 46 47 JPanel panel = new JPanel(new BorderLayout()); 48 panel.setBackground(null); 49 50 String prompt = (String )attr.getAttribute(HTML.Attribute.PROMPT); 51 if (prompt == null) { 52 prompt = UIManager.getString("IsindexView.prompt"); 53 } 54 JLabel label = new JLabel(prompt); 55 56 textField = new JTextField(); 57 textField.addActionListener(this); 58 panel.add(label, BorderLayout.WEST); 59 panel.add(textField, BorderLayout.CENTER); 60 panel.setAlignmentY(1.0f); 61 panel.setOpaque(false); 62 return panel; 63 } 64 65 74 public void actionPerformed(ActionEvent evt) { 75 76 String data = textField.getText(); 77 if (data != null) { 78 data = URLEncoder.encode(data); 79 } 80 81 82 AttributeSet attr = getElement().getAttributes(); 83 HTMLDocument hdoc = (HTMLDocument )getElement().getDocument(); 84 85 String action = (String ) attr.getAttribute(HTML.Attribute.ACTION); 86 if (action == null) { 87 action = hdoc.getBase().toString(); 88 } 89 try { 90 URL url = new URL (action+"?"+data); 91 JEditorPane pane = (JEditorPane)getContainer(); 92 pane.setPage(url); 93 } catch (MalformedURLException e1) { 94 } catch (IOException e2) { 95 } 96 } 97 } 98 | Popular Tags |