author | prr |
Tue, 16 Dec 2014 09:58:02 -0800 | |
changeset 28236 | 610561ed1847 |
parent 28231 | b608ffcaed74 |
parent 28059 | e576535359cc |
permissions | -rw-r--r-- |
2 | 1 |
/* |
28231
b608ffcaed74
8066621: Suppress deprecation warnings in java.desktop module
darcy
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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 |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package javax.swing.text.html; |
|
26 |
||
27 |
import java.awt.*; |
|
28 |
import java.awt.event.*; |
|
29 |
import java.net.URLEncoder; |
|
30 |
import java.net.MalformedURLException; |
|
31 |
import java.io.IOException; |
|
32 |
import java.net.URL; |
|
33 |
import javax.swing.text.*; |
|
34 |
import javax.swing.*; |
|
35 |
||
36 |
||
37 |
/** |
|
38 |
* A view that supports the <ISINDEX< tag. This is implemented |
|
39 |
* as a JPanel that contains |
|
40 |
* |
|
41 |
* @author Sunita Mani |
|
42 |
*/ |
|
43 |
||
44 |
class IsindexView extends ComponentView implements ActionListener { |
|
45 |
||
46 |
JTextField textField; |
|
47 |
||
48 |
/** |
|
49 |
* Creates an IsindexView |
|
50 |
*/ |
|
51 |
public IsindexView(Element elem) { |
|
52 |
super(elem); |
|
53 |
} |
|
54 |
||
55 |
/** |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
25859
diff
changeset
|
56 |
* Creates the components necessary to implement |
2 | 57 |
* this view. The component returned is a <code>JPanel</code>, |
58 |
* that contains the PROMPT to the left and <code>JTextField</code> |
|
59 |
* to the right. |
|
60 |
*/ |
|
61 |
public Component createComponent() { |
|
62 |
AttributeSet attr = getElement().getAttributes(); |
|
63 |
||
64 |
JPanel panel = new JPanel(new BorderLayout()); |
|
65 |
panel.setBackground(null); |
|
66 |
||
67 |
String prompt = (String)attr.getAttribute(HTML.Attribute.PROMPT); |
|
68 |
if (prompt == null) { |
|
69 |
prompt = UIManager.getString("IsindexView.prompt"); |
|
70 |
} |
|
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 |
*/ |
|
28231
b608ffcaed74
8066621: Suppress deprecation warnings in java.desktop module
darcy
parents:
25859
diff
changeset
|
91 |
@SuppressWarnings("deprecation") |
2 | 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) { |
|
112 |
} catch (IOException e2) { |
|
113 |
} |
|
114 |
} |
|
115 |
} |