001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.faces.dt.std.table;
042:
043: import java.awt.BorderLayout;
044: import java.awt.Component;
045: import java.awt.Dimension;
046: import java.awt.FlowLayout;
047: import java.awt.Frame;
048: import java.awt.GridBagConstraints;
049: import java.awt.GridBagLayout;
050: import java.awt.GridLayout;
051: import java.awt.Insets;
052: import java.awt.SystemColor;
053: import java.awt.event.ActionEvent;
054: import java.awt.event.ActionListener;
055: import java.util.HashMap;
056: import java.util.Map;
057: import javax.swing.JButton;
058: import javax.swing.JCheckBox;
059: import javax.swing.JComboBox;
060: import javax.swing.JComponent;
061: import javax.swing.JDialog;
062: import javax.swing.JLabel;
063: import javax.swing.JPanel;
064: import javax.swing.JTextField;
065: import javax.swing.event.ChangeEvent;
066: import javax.swing.event.ChangeListener;
067: import javax.swing.event.DocumentEvent;
068: import javax.swing.event.DocumentListener;
069: import org.netbeans.modules.visualweb.faces.dt.util.ComponentBundle;
070: import org.netbeans.modules.visualweb.propertyeditors.StandardUrlPanel;
071:
072: public class HtmlDataTableCustomizerPagingPanel extends JPanel {
073:
074: private static final ComponentBundle bundle = ComponentBundle
075: .getBundle(HtmlDataTableCustomizerPagingPanel.class);
076: private static final int DEFAULT_PAGING_ROWS = 10;
077: private Map inputDependents = new HashMap();
078:
079: private JCheckBox chkEnablePaging = new JCheckBox();
080: private JTextField tfPageSize = new JTextField();
081: private JLabel lblPageSize = new JLabel();
082: private JLabel lblNav = new JLabel();
083: private JComboBox comboNav = new JComboBox();
084: private JCheckBox chkFirst = new JCheckBox();
085: private JCheckBox chkPrevious = new JCheckBox();
086: private JCheckBox chkNext = new JCheckBox();
087: private JCheckBox chkLast = new JCheckBox();
088: private JLabel lblLocation = new JLabel();
089: private JComboBox comboLocation = new JComboBox();
090: private JTextField tfFirst = new JTextField();
091: private JTextField tfPrevious = new JTextField();
092: private JTextField tfNext = new JTextField();
093: private JTextField tfLast = new JTextField();
094: private GridBagLayout gridBagLayout1 = new GridBagLayout();
095: private JPanel fillerPanel = new JPanel();
096: private HtmlDataTableState table;
097: private JButton btnBrowseFirst = new JButton();
098: private JButton btnBrowsePrevious = new JButton();
099: private JButton btnBrowseNext = new JButton();
100: private JButton btnBrowseLast = new JButton();
101: private JLabel lblAlign = new JLabel();
102: private JComboBox comboAlign = new JComboBox();
103: private String previousComboNavSelection;
104:
105: HtmlDataTableCustomizerPagingPanel() {
106: try {
107: jbInit();
108: } catch (Exception ex) {
109: ex.printStackTrace();
110: }
111: }
112:
113: void setTable(HtmlDataTableState table) {
114: this .table = table;
115: initState();
116: }
117:
118: private void jbInit() throws Exception {
119: ChangeListener chkListener = new ChangeListener() {
120: public void stateChanged(ChangeEvent e) {
121: chk_stateChanged(e);
122: }
123: };
124: ActionListener pagingActionListener = new ActionListener() {
125: public void actionPerformed(ActionEvent e) {
126: pagingPanelActionPerformed(e);
127: }
128: };
129: chkEnablePaging.addChangeListener(chkListener);
130: chkEnablePaging.setText(bundle.getMessage("enablePaging")); //NOI18N
131: lblPageSize.setText(bundle.getMessage("pageSize")); //NOI18N
132: //tfPageSize.setPreferredSize(new Dimension(100, 24));
133: tfPageSize.getDocument().addDocumentListener(
134: new DocumentListener() {
135: public void insertUpdate(DocumentEvent e) {
136: tfPageSize_changed(e);
137: }
138:
139: public void removeUpdate(DocumentEvent e) {
140: tfPageSize_changed(e);
141: }
142:
143: public void changedUpdate(DocumentEvent e) {
144: tfPageSize_changed(e);
145: }
146: });
147: lblNav.setText(bundle.getMessage("pageNavControls")); //NOI18N
148: comboNav.setMinimumSize(new Dimension(30, 24));
149: //comboNav.setPreferredSize(new Dimension(150, 24));
150: comboNav.addItem(HtmlDataTableState.BUTTON_TEXT);
151: comboNav.addItem(HtmlDataTableState.BUTTON_IMAGE);
152: comboNav.addItem(HtmlDataTableState.BUTTON_NONE);
153: comboNav.addActionListener(pagingActionListener);
154:
155: chkFirst.addChangeListener(chkListener);
156: chkFirst.setText(bundle.getMessage("firstPage")); //NOI18N
157: chkPrevious.addChangeListener(chkListener);
158: chkPrevious.setText(bundle.getMessage("prevPage")); //NOI18N
159: chkNext.addChangeListener(chkListener);
160: chkNext.setText(bundle.getMessage("nextPage")); //NOI18N
161: chkLast.addChangeListener(chkListener);
162: chkLast.setText(bundle.getMessage("lastPage")); //NOI18N
163:
164: tfFirst.setColumns(20);
165: tfPrevious.setColumns(20);
166: tfNext.setColumns(20);
167: tfLast.setColumns(20);
168:
169: lblLocation.setText(bundle.getMessage("position")); //NOI18N
170: comboLocation.setMinimumSize(new Dimension(30, 24));
171: //comboLocation.setPreferredSize(new Dimension(150, 24));
172: comboLocation.addItem(HtmlDataTableState.TOP);
173: comboLocation.addItem(HtmlDataTableState.BOTTOM);
174: comboLocation.addItem(HtmlDataTableState.TOP_AND_BOTTOM);
175:
176: lblAlign.setText(bundle.getMessage("align")); //NOI18N
177: comboAlign.setMinimumSize(new Dimension(30, 24));
178: //comboAlign.setPreferredSize(new Dimension(150, 24));
179: comboAlign.addItem(HtmlDataTableState.ALIGN_LEFT);
180: comboAlign.addItem(HtmlDataTableState.ALIGN_CENTER);
181: comboAlign.addItem(HtmlDataTableState.ALIGN_RIGHT);
182:
183: String browseText = bundle.getMessage("browseEllipse"); //NOI18N
184: btnBrowseFirst.setText(browseText);
185: btnBrowseFirst.addActionListener(pagingActionListener);
186: btnBrowsePrevious.setText(browseText);
187: btnBrowsePrevious.addActionListener(pagingActionListener);
188: btnBrowseNext.setText(browseText);
189: btnBrowseNext.addActionListener(pagingActionListener);
190: btnBrowseLast.setText(browseText);
191: btnBrowseLast.addActionListener(pagingActionListener);
192:
193: inputDependents.put(chkEnablePaging, new JComponent[] {
194: lblPageSize, tfPageSize, comboNav });
195: inputDependents.put(comboNav, new JComponent[] { chkFirst,
196: tfFirst, btnBrowseFirst, chkPrevious, tfPrevious,
197: btnBrowsePrevious, chkNext, tfNext, btnBrowseNext,
198: chkLast, tfLast, btnBrowseLast, lblLocation,
199: comboLocation, lblAlign, comboAlign });
200:
201: this .setLayout(gridBagLayout1);
202: this .add(chkEnablePaging, new GridBagConstraints(0, 0, 3, 1,
203: 0.0, 0.0, GridBagConstraints.WEST,
204: GridBagConstraints.NONE, new Insets(8, 8, 2, 8), 0, 0));
205:
206: this .add(lblPageSize, new GridBagConstraints(0, 1, 3, 1, 0.0,
207: 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
208: new Insets(2, 22, 4, 8), 0, 0));
209: this .add(tfPageSize, new GridBagConstraints(0, 2, 1, 1, 0.0,
210: 0.0, GridBagConstraints.WEST,
211: GridBagConstraints.HORIZONTAL, new Insets(0, 22, 8, 8),
212: 0, 0));
213:
214: this .add(lblNav, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
215: GridBagConstraints.WEST, GridBagConstraints.NONE,
216: new Insets(8, 22, 16, 4), 0, 0));
217: this .add(comboNav, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0,
218: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
219: new Insets(8, 4, 16, 4), 0, 0));
220:
221: this .add(chkFirst, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0,
222: GridBagConstraints.WEST, GridBagConstraints.NONE,
223: new Insets(0, 32, 8, 4), 0, 0));
224: this .add(tfFirst, new GridBagConstraints(1, 4, 1, 1, 1.0, 0.0,
225: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
226: new Insets(0, 4, 8, 4), 0, 0));
227: this .add(btnBrowseFirst, new GridBagConstraints(2, 4, 1, 1,
228: 0.0, 0.0, GridBagConstraints.WEST,
229: GridBagConstraints.NONE, new Insets(0, 4, 8, 8), 0, 0));
230:
231: this .add(chkPrevious, new GridBagConstraints(0, 5, 1, 1, 0.0,
232: 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
233: new Insets(0, 32, 8, 4), 0, 0));
234: this .add(tfPrevious, new GridBagConstraints(1, 5, 1, 1, 1.0,
235: 0.0, GridBagConstraints.WEST,
236: GridBagConstraints.HORIZONTAL, new Insets(0, 4, 8, 4),
237: 0, 0));
238: this .add(btnBrowsePrevious, new GridBagConstraints(2, 5, 1, 1,
239: 0.0, 0.0, GridBagConstraints.WEST,
240: GridBagConstraints.NONE, new Insets(0, 4, 8, 8), 0, 0));
241:
242: this .add(chkNext, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0,
243: GridBagConstraints.WEST, GridBagConstraints.NONE,
244: new Insets(0, 32, 8, 4), 0, 0));
245: this .add(tfNext, new GridBagConstraints(1, 6, 1, 1, 1.0, 0.0,
246: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
247: new Insets(0, 4, 8, 4), 0, 0));
248: this .add(btnBrowseNext, new GridBagConstraints(2, 6, 1, 1, 0.0,
249: 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
250: new Insets(0, 4, 8, 8), 0, 0));
251:
252: this .add(chkLast, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0,
253: GridBagConstraints.WEST, GridBagConstraints.NONE,
254: new Insets(0, 32, 8, 4), 0, 0));
255: this .add(tfLast, new GridBagConstraints(1, 7, 1, 1, 1.0, 0.0,
256: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
257: new Insets(0, 4, 8, 4), 0, 0));
258: this .add(btnBrowseLast, new GridBagConstraints(2, 7, 1, 1, 0.0,
259: 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
260: new Insets(0, 4, 8, 8), 0, 0));
261:
262: this .add(lblLocation, new GridBagConstraints(0, 8, 1, 1, 0.0,
263: 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
264: new Insets(0, 35, 8, 4), 0, 0));
265: this .add(comboLocation, new GridBagConstraints(1, 8, 1, 1, 1.0,
266: 0.0, GridBagConstraints.WEST,
267: GridBagConstraints.HORIZONTAL, new Insets(0, 4, 8, 4),
268: 0, 0));
269:
270: this .add(lblAlign, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0,
271: GridBagConstraints.WEST, GridBagConstraints.NONE,
272: new Insets(0, 35, 8, 4), 0, 0));
273: this .add(comboAlign, new GridBagConstraints(1, 9, 1, 1, 1.0,
274: 0.0, GridBagConstraints.WEST,
275: GridBagConstraints.HORIZONTAL, new Insets(0, 4, 8, 4),
276: 0, 0));
277:
278: this .add(fillerPanel, new GridBagConstraints(0, 10, 3, 1, 1.0,
279: 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH,
280: new Insets(0, 0, 0, 0), 0, 0));
281: }
282:
283: public void pagingPanelActionPerformed(ActionEvent e) {
284: if (e.getSource() == comboNav) {
285: String comboNavSelectedItem = (String) comboNav
286: .getSelectedItem();
287: boolean textOrImage = (HtmlDataTableState.BUTTON_TEXT
288: .equals(comboNavSelectedItem) || HtmlDataTableState.BUTTON_IMAGE
289: .equals(comboNavSelectedItem));
290: if (textOrImage && !chkFirst.isSelected()
291: && !chkPrevious.isSelected()
292: && !chkNext.isSelected() && !chkLast.isSelected()) {
293: chkFirst.setSelected(true);
294: chkPrevious.setSelected(true);
295: chkNext.setSelected(true);
296: chkLast.setSelected(true);
297: }
298:
299: //put existing text field content into HtmlDataTableState
300:
301: if (HtmlDataTableState.BUTTON_NONE
302: .equals(previousComboNavSelection)
303: || HtmlDataTableState.BUTTON_TEXT
304: .equals(previousComboNavSelection)) {
305: //save existing text in all text fields as button text
306: table.paging.firstButtonText = tfFirst.getText();
307: table.paging.previousButtonText = tfPrevious.getText();
308: table.paging.nextButtonText = tfNext.getText();
309: table.paging.lastButtonText = tfLast.getText();
310: } else if (HtmlDataTableState.BUTTON_IMAGE
311: .equals(previousComboNavSelection)) {
312: table.paging.firstButtonUrl = tfFirst.getText();
313: table.paging.previousButtonUrl = tfPrevious.getText();
314: table.paging.nextButtonUrl = tfNext.getText();
315: table.paging.lastButtonUrl = tfLast.getText();
316: }
317:
318: //modify text field contents
319:
320: if (HtmlDataTableState.BUTTON_IMAGE
321: .equals(comboNavSelectedItem)) {
322: tfFirst.setText(table.paging.firstButtonUrl);
323: tfPrevious.setText(table.paging.previousButtonUrl);
324: tfNext.setText(table.paging.nextButtonUrl);
325: tfLast.setText(table.paging.lastButtonUrl);
326: } else {
327: tfFirst.setText(table.paging.firstButtonText);
328: tfPrevious.setText(table.paging.previousButtonText);
329: tfNext.setText(table.paging.nextButtonText);
330: tfLast.setText(table.paging.lastButtonText);
331: }
332:
333: setDependentsEnabled(comboNav);
334:
335: previousComboNavSelection = comboNavSelectedItem;
336: } else {
337: JButton[] browseButtons = { btnBrowseFirst,
338: btnBrowsePrevious, btnBrowseNext, btnBrowseLast };
339: JTextField[] textFields = { tfFirst, tfPrevious, tfNext,
340: tfLast };
341: for (int i = 0; i < browseButtons.length; i++) {
342: if (e.getSource() == browseButtons[i]) {
343: StandardUrlPanel urlPanel = new StandardUrlPanel();
344: urlPanel.setDesignProperty(null);
345: urlPanel.setDesignContext(table.getTableBean()
346: .getDesignContext());
347: urlPanel.initialize();
348: URLDialog urlDialog = new URLDialog(
349: getParentFrame(this ), urlPanel);
350: urlDialog.show();
351: textFields[i].setText(urlDialog.getUrlString());
352: urlPanel = null;
353: urlDialog = null;
354: break;
355: }
356: }
357: }
358: }
359:
360: void initState() {
361: chkEnablePaging.setSelected(table.paging.rows > 0);
362: tfPageSize.setText(table.paging.rows > 0 ? String
363: .valueOf(table.paging.rows) : String
364: .valueOf(DEFAULT_PAGING_ROWS));
365:
366: comboNav.setSelectedItem(table.paging.navigation);
367: previousComboNavSelection = table.paging.navigation;
368:
369: chkFirst.setSelected(table.paging.firstButton);
370: tfFirst
371: .setText(HtmlDataTableState.BUTTON_IMAGE
372: .equals(table.paging.navigation) ? table.paging.firstButtonUrl
373: : table.paging.firstButtonText);
374: chkPrevious.setSelected(table.paging.previousButton);
375: tfPrevious
376: .setText(HtmlDataTableState.BUTTON_IMAGE
377: .equals(table.paging.navigation) ? table.paging.previousButtonUrl
378: : table.paging.previousButtonText);
379: chkNext.setSelected(table.paging.nextButton);
380: tfNext
381: .setText(HtmlDataTableState.BUTTON_IMAGE
382: .equals(table.paging.navigation) ? table.paging.nextButtonUrl
383: : table.paging.nextButtonText);
384: chkLast.setSelected(table.paging.lastButton);
385: tfLast
386: .setText(HtmlDataTableState.BUTTON_IMAGE
387: .equals(table.paging.navigation) ? table.paging.lastButtonUrl
388: : table.paging.lastButtonText);
389:
390: if (table.paging.navOnTop && table.paging.navOnBottom) {
391: comboLocation
392: .setSelectedItem(HtmlDataTableState.TOP_AND_BOTTOM);
393: } else if (table.paging.navOnTop) {
394: comboLocation.setSelectedItem(HtmlDataTableState.TOP);
395: } else if (table.paging.navOnBottom) {
396: comboLocation.setSelectedItem(HtmlDataTableState.BOTTOM);
397: }
398:
399: comboAlign.setSelectedItem(table.paging.align);
400:
401: setDependentsEnabled(chkEnablePaging);
402: }
403:
404: private int getPagingRows() {
405: int rows = 0;
406: if (chkEnablePaging.isSelected()) {
407: try {
408: rows = Integer.parseInt(tfPageSize.getText().trim());
409: } catch (Exception x) {
410: //let rows be 0
411: }
412: }
413: return rows;
414: }
415:
416: void saveState() {
417: table.paging.rows = getPagingRows();
418: String comboNavSelection = (String) comboNav.getSelectedItem();
419: table.paging.navigation = comboNavSelection;
420: String location = (String) comboLocation.getSelectedItem();
421: table.paging.navOnTop = location.equals(HtmlDataTableState.TOP)
422: || location.equals(HtmlDataTableState.TOP_AND_BOTTOM);
423: table.paging.navOnBottom = location
424: .equals(HtmlDataTableState.BOTTOM)
425: || location.equals(HtmlDataTableState.TOP_AND_BOTTOM);
426: table.paging.align = (String) comboAlign.getSelectedItem();
427: table.paging.firstButton = chkFirst.isSelected();
428: table.paging.previousButton = chkPrevious.isSelected();
429: table.paging.nextButton = chkNext.isSelected();
430: table.paging.lastButton = chkLast.isSelected();
431: if (HtmlDataTableState.BUTTON_NONE.equals(comboNavSelection)
432: || HtmlDataTableState.BUTTON_TEXT
433: .equals(comboNavSelection)) {
434: //save existing text in all text fields as button text
435: table.paging.firstButtonText = tfFirst.getText();
436: table.paging.previousButtonText = tfPrevious.getText();
437: table.paging.nextButtonText = tfNext.getText();
438: table.paging.lastButtonText = tfLast.getText();
439: } else if (HtmlDataTableState.BUTTON_IMAGE
440: .equals(comboNavSelection)) {
441: table.paging.firstButtonUrl = tfFirst.getText();
442: table.paging.previousButtonUrl = tfPrevious.getText();
443: table.paging.nextButtonUrl = tfNext.getText();
444: table.paging.lastButtonUrl = tfLast.getText();
445: }
446: }
447:
448: private void chk_stateChanged(ChangeEvent e) {
449: setDependentsEnabled((JComponent) e.getSource());
450: }
451:
452: private void tfPageSize_changed(DocumentEvent e) {
453: setDependentsEnabled(chkEnablePaging);
454: }
455:
456: private void setDependentsEnabled(JComponent source) {
457: JComponent[] dependents = (JComponent[]) inputDependents
458: .get(source);
459: if (dependents == null) {
460: return;
461: }
462: boolean on = false;
463: String selectedComboItem = null;
464: if (source instanceof JCheckBox) {
465: JCheckBox chkSource = (JCheckBox) source;
466: on = chkSource.isEnabled() && chkSource.isSelected();
467: } else if (source == comboNav) {
468: selectedComboItem = (String) comboNav.getSelectedItem();
469: on = comboNav.isEnabled()
470: && (HtmlDataTableState.BUTTON_TEXT
471: .equals(selectedComboItem) || HtmlDataTableState.BUTTON_IMAGE
472: .equals(selectedComboItem));
473: }
474: for (int i = 0; i < dependents.length; i++) {
475: boolean localOn = on;
476: if (source == chkEnablePaging
477: && dependents[i] != lblPageSize
478: && dependents[i] != tfPageSize) {
479: localOn = localOn && getPagingRows() > 0;
480: }
481: if (source == comboNav
482: && (dependents[i].equals(btnBrowseFirst)
483: || dependents[i].equals(btnBrowsePrevious)
484: || dependents[i].equals(btnBrowseNext) || dependents[i]
485: .equals(btnBrowseLast))) {
486: localOn = localOn
487: && HtmlDataTableState.BUTTON_IMAGE
488: .equals(selectedComboItem);
489: }
490: dependents[i].setEnabled(localOn);
491: if (dependents[i] instanceof JTextField) {
492: dependents[i].setBackground(localOn ? SystemColor.text
493: : SystemColor.control);
494: }
495: setDependentsEnabled(dependents[i]);
496: }
497: }
498:
499: private Frame getParentFrame(Component c) {
500: while (true) {
501: if (c == null) {
502: return null;
503: }
504: if (c instanceof Frame) {
505: return (Frame) c;
506: }
507: c = c.getParent();
508: }
509: }
510:
511: private class URLDialog extends JDialog {
512: private JButton btnOk, btnCancel;
513: private StandardUrlPanel urlPanel;
514: private String urlString;
515:
516: public URLDialog(Frame parent, StandardUrlPanel urlPanel) {
517: super (parent, bundle.getMessage("urlDlgTitle"), true); //NOI18N
518: this .urlPanel = urlPanel;
519: ActionListener dialogActionListener = new ActionListener() {
520: public void actionPerformed(ActionEvent e) {
521: dialogActionPerformed(e);
522: }
523: };
524: JPanel buttonPanelParent = new JPanel();
525: ((FlowLayout) buttonPanelParent.getLayout())
526: .setAlignment(FlowLayout.RIGHT);
527: JPanel buttonPanel = new JPanel(new GridLayout(1, 2, 5, 5));
528: buttonPanelParent.add(buttonPanel);
529: btnOk = new JButton(bundle.getMessage("okCaps")); //NOI18N
530: btnCancel = new JButton(bundle.getMessage("cancel")); //NOI18N
531: btnOk.addActionListener(dialogActionListener);
532: btnCancel.addActionListener(dialogActionListener);
533: buttonPanel.add(btnOk);
534: buttonPanel.add(btnCancel);
535: getContentPane().add(urlPanel);
536: getContentPane().add(buttonPanelParent, BorderLayout.SOUTH);
537: pack();
538: setResizable(true);
539: setLocationRelativeTo(parent);
540: }
541:
542: public void dialogActionPerformed(ActionEvent e) {
543: if (e.getSource() == btnOk) {
544: Object urlObj = this .urlPanel.getPropertyValue();
545: if (urlObj == null) {
546: this .urlString = null;
547: }
548: if (urlObj instanceof String) {
549: this .urlString = (String) urlObj;
550: } else {
551: this .urlString = urlObj.toString();
552: }
553: dispose();
554: } else if (e.getSource() == btnCancel) {
555: dispose();
556: }
557: }
558:
559: public String getUrlString() {
560: return this.urlString;
561: }
562: }
563: }
|