< prev index next >

src/java.desktop/share/classes/javax/swing/text/html/IsindexView.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2000, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  71         JLabel label = new JLabel(prompt);
  72 
  73         textField = new JTextField();
  74         textField.addActionListener(this);
  75         panel.add(label, BorderLayout.WEST);
  76         panel.add(textField, BorderLayout.CENTER);
  77         panel.setAlignmentY(1.0f);
  78         panel.setOpaque(false);
  79         return panel;
  80     }
  81 
  82     /**
  83      * Responsible for processing the ActionEvent.
  84      * In this case this is hitting enter/return
  85      * in the text field.  This will construct the
  86      * URL from the base URL of the document.
  87      * To the URL is appended a '?' followed by the
  88      * contents of the JTextField.  The search
  89      * contents are URLEncoded.
  90      */

  91     public void actionPerformed(ActionEvent evt) {
  92 
  93         String data = textField.getText();
  94         if (data != null) {
  95             data = URLEncoder.encode(data);
  96         }
  97 
  98 
  99         AttributeSet attr = getElement().getAttributes();
 100         HTMLDocument hdoc = (HTMLDocument)getElement().getDocument();
 101 
 102         String action = (String) attr.getAttribute(HTML.Attribute.ACTION);
 103         if (action == null) {
 104             action = hdoc.getBase().toString();
 105         }
 106         try {
 107             URL url = new URL(action+"?"+data);
 108             JEditorPane pane = (JEditorPane)getContainer();
 109             pane.setPage(url);
 110         } catch (MalformedURLException e1) {
   1 /*
   2  * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  71         JLabel label = new JLabel(prompt);
  72 
  73         textField = new JTextField();
  74         textField.addActionListener(this);
  75         panel.add(label, BorderLayout.WEST);
  76         panel.add(textField, BorderLayout.CENTER);
  77         panel.setAlignmentY(1.0f);
  78         panel.setOpaque(false);
  79         return panel;
  80     }
  81 
  82     /**
  83      * Responsible for processing the ActionEvent.
  84      * In this case this is hitting enter/return
  85      * in the text field.  This will construct the
  86      * URL from the base URL of the document.
  87      * To the URL is appended a '?' followed by the
  88      * contents of the JTextField.  The search
  89      * contents are URLEncoded.
  90      */
  91     @SuppressWarnings("deprecation")
  92     public void actionPerformed(ActionEvent evt) {
  93 
  94         String data = textField.getText();
  95         if (data != null) {
  96             data = URLEncoder.encode(data);
  97         }
  98 
  99 
 100         AttributeSet attr = getElement().getAttributes();
 101         HTMLDocument hdoc = (HTMLDocument)getElement().getDocument();
 102 
 103         String action = (String) attr.getAttribute(HTML.Attribute.ACTION);
 104         if (action == null) {
 105             action = hdoc.getBase().toString();
 106         }
 107         try {
 108             URL url = new URL(action+"?"+data);
 109             JEditorPane pane = (JEditorPane)getContainer();
 110             pane.setPage(url);
 111         } catch (MalformedURLException e1) {
< prev index next >