1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.telscenter.pas.steps.quickEditors.html;
24
25 import java.awt.BorderLayout;
26 import java.awt.event.ActionListener;
27 import java.awt.event.FocusEvent;
28 import java.awt.event.FocusListener;
29 import java.net.MalformedURLException;
30 import java.net.URL;
31
32 import javax.swing.Action;
33 import javax.swing.JButton;
34 import javax.swing.JComponent;
35 import javax.swing.JLabel;
36 import javax.swing.JPanel;
37 import javax.swing.JTextField;
38
39 import net.miginfocom.swing.MigLayout;
40
41 import org.apache.commons.lang.StringUtils;
42 import org.telscenter.pas.common.ui.panel.TextEditorPanel;
43 import org.telscenter.pas.steps.BrowseWebUI;
44 import org.telscenter.pas.steps.BrowseWeb.PopupPreviewAction;
45
46 /***
47 * Creates the Authoring Mode for the OutsideLink Step
48 *
49 * @author aperritano
50 *
51 */
52 public class OutsideLinkQuickEditorUI extends HtmlQuickEditorUI {
53
54 private static final int TEXT_BOX_LEN = 32;
55
56 private JButton browseButton;
57 private JTextField externalUrlText;
58 private JButton previewButton;
59
60
61 /***
62 * Creates the UI for the step specific authoring that is displayed
63 * on the bottom right main section of the authoring tool
64 */
65 protected void createUI() {
66 this.setOpaque(false);
67
68
69
70
71 MigLayout layout = new MigLayout("insets 8 2 4 2");
72
73 this.setLayout(layout);
74
75
76 this.add(createExternalLabelPanel());
77
78
79 this.add(createLocalTextPanel());
80
81
82 this.add(createPreviewButton(), "wrap");
83 }
84
85
86
87
88 /***
89 * @return the panel that contains the preview button
90 */
91 private JPanel createPreviewButton() {
92 JPanel previewButtonPanel = new JPanel(new BorderLayout(0,0));
93
94
95 PopupPreviewAction previewAction =
96 (PopupPreviewAction) browseWebBean.getPreviewAction(
97 false, externalUrlText);
98
99
100 previewAction.putValue(Action.NAME, "Preview Step");
101
102
103 previewButton = new JButton(previewAction);
104
105 previewButton.setOpaque(false);
106
107
108 previewButtonPanel.add(previewButton,BorderLayout.EAST);
109
110 return previewButtonPanel;
111 }
112
113
114
115
116 /***
117 * @return the component that contains the text label
118 */
119 private JComponent createExternalLabelPanel() {
120 JLabel local = new JLabel("Outside Link:");
121 return local;
122 }
123
124
125
126
127
128 private JComponent createLocalTextPanel() {
129
130 final JTextField outsideLinkUrlTextField = new JTextField(TEXT_BOX_LEN);
131
132 if( browseWebBean.getUrl() != null ) {
133
134 String url = browseWebBean.getUrl().toString();
135 outsideLinkUrlTextField.setText(url);
136 } else {
137
138 outsideLinkUrlTextField.setText("http://www.google.com/");
139 }
140
141
142 outsideLinkUrlTextField.setName("Url");
143
144 outsideLinkUrlTextField.addFocusListener(new FocusListener() {
145 public void focusGained(FocusEvent e) {
146
147 }
148
149 public void focusLost(FocusEvent e) {
150
151
152 try {
153 browseWebBean.setUrl(new URL(outsideLinkUrlTextField.getText()));
154 } catch (MalformedURLException e1) {
155
156
157 }
158 }
159 });
160
161 outsideLinkUrlTextField.requestFocus();
162
163
164
165 outsideLinkUrlTextField.setEditable(false);
166
167
168 outsideLinkUrlTextField.setBackground(this.getBackground());
169
170 TextEditorPanel panel = new TextEditorPanel(outsideLinkUrlTextField,null);
171
172
173
174 externalUrlText = outsideLinkUrlTextField;
175 return panel;
176 }
177
178
179
180
181 protected void applyUrl() {
182 if( externalUrlText.getText() != null && StringUtils.trimToNull(externalUrlText.getText()) != null ) {
183 try {
184 browseWebBean.setUrl(new URL(externalUrlText.getText()));
185 } catch (MalformedURLException e1) {
186
187
188 }
189 }
190 }
191
192 }