Source Code Cross Referenced for TransformPanel.java in  » IDE-Netbeans » xml » org » netbeans » modules » xsl » ui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » xml » org.netbeans.modules.xsl.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:        package org.netbeans.modules.xsl.ui;
0042:
0043:        import java.io.File;
0044:        import java.io.IOException;
0045:        import java.net.URL;
0046:        import java.net.MalformedURLException;
0047:        import java.awt.*;
0048:        import javax.swing.*;
0049:        import java.util.Vector;
0050:
0051:        import javax.xml.transform.*;
0052:
0053:        import org.openide.loaders.DataObject;
0054:        import org.openide.filesystems.*;
0055:        import org.openide.DialogDisplayer;
0056:        import org.openide.NotifyDescriptor;
0057:
0058:        import org.netbeans.api.xml.cookies.TransformableCookie;
0059:
0060:        import org.netbeans.modules.xsl.settings.TransformHistory;
0061:        import org.netbeans.modules.xsl.utils.TransformUtil;
0062:        import org.openide.util.NbBundle;
0063:
0064:        /**
0065:         *
0066:         * @author  Libor Kramolis
0067:         * @version 0.1
0068:         */
0069:        public final class TransformPanel extends javax.swing.JPanel {
0070:            /** Serial Version UID */
0071:            private static final long serialVersionUID = -3449709794133206327L;
0072:
0073:            public static final String DATA_XML_MODIFIED = "DATA_XML_MODIFIED";
0074:            public static final String DATA_XSL_MODIFIED = "DATA_XSL_MODIFIED";
0075:            public static final String DATA_OUTPUT_MODIFIED = "DATA_OUTPUT_MODIFIED";
0076:            public static final String DATA_PROCESS_MODIFIED = "DATA_PROCESS_MODIFIED";
0077:            public static final String DATA_OVERWRITE_MODIFIED = "DATA_OVERWRITE_MODIFIED";
0078:
0079:            private URL baseURL;
0080:            private Data data;
0081:            private boolean initialized = false;
0082:
0083:            private DataObject xmlDataObject;
0084:            private String xml_stylesheet; // <?xsl-stylesheet ...
0085:            private DataObject xslDataObject;
0086:            private TransformHistory xmlHistory;
0087:            private TransformHistory xslHistory;
0088:
0089:            private boolean userSetOutput = false;
0090:            private boolean userSetProcess = false;
0091:            private String lastOutputFileExt = TransformUtil.DEFAULT_OUTPUT_EXT;
0092:            private Object lastXSLObject = new Object();
0093:
0094:            /** Hide transformation components if true. */
0095:            private boolean suppressXSL;
0096:
0097:            /** Names of output actions. */
0098:            private static final String[] SHOW_NAMES = new String[] {
0099:                    NbBundle.getMessage(TransformPanel.class,
0100:                            "NAME_process_output_do_nothing"), // TransformHistory.DO_NOTHING
0101:                    NbBundle.getMessage(TransformPanel.class,
0102:                            "NAME_process_output_apply_default_action"), // TransformHistory.APPLY_DEFAULT_ACTION
0103:                    NbBundle.getMessage(TransformPanel.class,
0104:                            "NAME_process_output_open_in_browser"), // TransformHistory.OPEN_IN_BROWSER
0105:            };
0106:
0107:            private static final Object JUST_PREVIEW = new Preview();
0108:
0109:            /** Creates new form TransformPanel */
0110:            public TransformPanel(DataObject xml, String xml_ss,
0111:                    DataObject xsl, boolean suppressXSL)
0112:                    throws MalformedURLException, FileStateInvalidException {
0113:                initComponents();
0114:
0115:                init(xml, xml_ss, xsl, suppressXSL);
0116:                initAccessibility();
0117:            }
0118:
0119:            /** Creates new form TransformPanel */
0120:            public TransformPanel(DataObject xml, String xml_ss, DataObject xsl)
0121:                    throws MalformedURLException, FileStateInvalidException {
0122:                this (xml, xml_ss, xsl, false);
0123:            }
0124:
0125:            private void init(DataObject xml, String xml_ss, DataObject xsl,
0126:                    boolean supXSL) throws MalformedURLException,
0127:                    FileStateInvalidException {
0128:                data = new Data();
0129:                xmlDataObject = xml;
0130:                xml_stylesheet = xml_ss;
0131:                xslDataObject = xsl;
0132:                suppressXSL = supXSL;
0133:
0134:                if (xmlDataObject != null) {
0135:                    setInput(TransformUtil.getURLName(xmlDataObject
0136:                            .getPrimaryFile()));
0137:                    FileObject xmlFileObject = xmlDataObject.getPrimaryFile();
0138:                    xmlHistory = (TransformHistory) xmlFileObject
0139:                            .getAttribute(TransformHistory.TRANSFORM_HISTORY_ATTRIBUTE);
0140:                    if (xmlHistory != null) {
0141:                        setXSL(xmlHistory.getLastXSL());
0142:                    }
0143:                    if ((data.xsl == null) && (xml_stylesheet != null)) {
0144:                        setXSL(xml_stylesheet);
0145:                    }
0146:                    try {
0147:                        baseURL = xmlFileObject.getParent().getURL();
0148:                    } catch (FileStateInvalidException exc) {
0149:                        // ignore it
0150:                    }
0151:                }
0152:                if (xslDataObject != null) {
0153:                    setXSL(TransformUtil.getURLName(xslDataObject
0154:                            .getPrimaryFile()));
0155:                    FileObject xslFileObject = xslDataObject.getPrimaryFile();
0156:                    xslHistory = (TransformHistory) xslFileObject
0157:                            .getAttribute(TransformHistory.TRANSFORM_HISTORY_ATTRIBUTE);
0158:                    if ((data.xml == null) && (xslHistory != null)) {
0159:                        setInput(xslHistory.getLastXML());
0160:                    }
0161:                    if (baseURL == null) {
0162:                        try {
0163:                            baseURL = xslFileObject.getParent().getURL();
0164:                        } catch (FileStateInvalidException exc) {
0165:                            // ignore it
0166:                        }
0167:                    }
0168:                }
0169:
0170:                if ((xmlHistory != null) || (xslHistory != null)) {
0171:                    if (xmlHistory != null) {
0172:                        setOutput(xmlHistory.getLastXSLOutput());
0173:                    }
0174:                    if ((data.output == null || (data.output instanceof  String && ""
0175:                            .equals(data.output)))
0176:                            && (xslHistory != null)) {
0177:                        setOutput(xslHistory.getLastXMLOutput());
0178:                    }
0179:                    if (data.output == null) {
0180:                        setOutput(JUST_PREVIEW);
0181:                    }
0182:                }
0183:
0184:                if (xmlHistory != null) {
0185:                    setOverwriteOutput(xmlHistory.isOverwriteOutput());
0186:                    setProcessOutput(new Integer(xmlHistory.getProcessOutput()));
0187:                } else if (xslHistory != null) {
0188:                    setOverwriteOutput(xslHistory.isOverwriteOutput());
0189:                    setProcessOutput(new Integer(xslHistory.getProcessOutput()));
0190:                }
0191:
0192:                ownInitComponents();
0193:            }
0194:
0195:            private void ownInitComponents() {
0196:                // XML Input
0197:                updateXMLComboBoxModel(null);
0198:                // XSL Transformation
0199:                updateXSLComboBoxModel(null);
0200:
0201:                updateComponents();
0202:
0203:                setCaretPosition(inputComboBox);
0204:                setCaretPosition(transformComboBox);
0205:                setCaretPosition(outputComboBox);
0206:            }
0207:
0208:            private void setCaretPosition(JComboBox comboBox) {
0209:                ComboBoxEditor cbEditor = comboBox.getEditor();
0210:                final Component editorComponent = cbEditor.getEditorComponent();
0211:
0212:                //        if ( Util.THIS.isLoggable() ) /* then */ {
0213:                //            Util.THIS.debug("TransformPanel.setCaretPosition: " + comboBox);
0214:                //            Util.THIS.debug("    editorComponent = " + editorComponent);
0215:                //        }
0216:
0217:                if (editorComponent instanceof  JTextField) {
0218:                    SwingUtilities.invokeLater(new Runnable() {
0219:                        public void run() {
0220:                            JTextField textField = (JTextField) editorComponent;
0221:                            int length = textField.getText().length();
0222:                            textField.setCaretPosition(length);
0223:
0224:                            //                    if ( Util.THIS.isLoggable() ) /* then */ {
0225:                            //                        Util.THIS.debug("    text[" + length + "]='" + textField.getText() + "' - " + textField.getCaretPosition());
0226:                            //                    }
0227:                        }
0228:                    });
0229:                }
0230:            }
0231:
0232:            private void updateXMLComboBoxModel(Object prefItem) {
0233:                Object[] history = null;
0234:                if ((xmlDataObject == null) && (xslHistory != null)) {
0235:                    history = xslHistory.getXMLs();
0236:                }
0237:
0238:                Vector cbModel = new Vector();
0239:
0240:                // Preferred Item
0241:                if (prefItem != null) {
0242:                    cbModel.add(prefItem);
0243:                }
0244:                // History
0245:                if (history != null) {
0246:                    for (int i = 0; i < history.length; i++) {
0247:                        cbModel.add(history[i]);
0248:                    }
0249:                }
0250:
0251:                inputComboBox.setModel(new DefaultComboBoxModel(cbModel));
0252:            }
0253:
0254:            private void updateXSLComboBoxModel(Object prefItem) {
0255:                Object[] history = null;
0256:                if ((xslDataObject == null) && (xmlHistory != null)) {
0257:                    history = xmlHistory.getXSLs();
0258:                }
0259:
0260:                Vector cbModel = new Vector();
0261:
0262:                // Preferred Item
0263:                if (prefItem != null) {
0264:                    cbModel.add(prefItem);
0265:                }
0266:                // <?xsl-stylesheet ...
0267:                if (xml_stylesheet != null) {
0268:                    cbModel.add(xml_stylesheet);
0269:                }
0270:                // History
0271:                if (history != null) {
0272:                    for (int i = 0; i < history.length; i++) {
0273:                        if ((history[i] != null)
0274:                                && (history[i].equals(xml_stylesheet) == false)) { // do not duplicate xml_stylesheet item
0275:                            cbModel.add(history[i]);
0276:                        }
0277:                    }
0278:                }
0279:
0280:                transformComboBox.setModel(new DefaultComboBoxModel(cbModel));
0281:            }
0282:
0283:            private boolean isInitialized() {
0284:                synchronized (data) {
0285:                    return initialized;
0286:                }
0287:            }
0288:
0289:            private void setInitialized(boolean init) {
0290:                synchronized (data) {
0291:                    initialized = init;
0292:                }
0293:            }
0294:
0295:            private static String guessFileName(String xml) {
0296:                String fileName = null;
0297:
0298:                int slashIndex = xml.lastIndexOf('/');
0299:                if (slashIndex != -1) {
0300:                    fileName = xml.substring(slashIndex + 1);
0301:                } else {
0302:                    fileName = xml;
0303:                }
0304:
0305:                return fileName;
0306:            }
0307:
0308:            private String guessOutputFileExt() {
0309:                String ext = lastOutputFileExt;
0310:                String xslObject = getXSL();
0311:
0312:                if (xslObject != lastXSLObject) {
0313:                    try {
0314:                        Source xslSource;
0315:                        xslSource = TransformUtil.createSource(baseURL,
0316:                                xslObject);
0317:                        ext = TransformUtil.guessOutputExt(xslSource);
0318:
0319:                        // cache last values
0320:                        lastXSLObject = xslObject;
0321:                        lastOutputFileExt = ext;
0322:                    } catch (Exception exc) {
0323:                        // ignore it
0324:
0325:                        //if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("[TransformPanel] Cannot guess extension!", exc);
0326:                    }
0327:                }
0328:
0329:                //if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("[TransformPanel] I guess output has '" + ext + "' extension.");
0330:
0331:                return ext;
0332:            }
0333:
0334:            private Object guessOutputFile() {
0335:                Object output = data.output;
0336:
0337:                if (output == null || "".equals(output)
0338:                        || JUST_PREVIEW.equals(output)) {
0339:                    String origName = guessFileName(data.xml);
0340:                    String origExt = "";
0341:                    int dotIndex = origName.lastIndexOf('.');
0342:                    if (dotIndex != -1) {
0343:                        origExt = origName.substring(dotIndex + 1);
0344:                        origName = origName.substring(0, dotIndex);
0345:                    }
0346:
0347:                    String ext = guessOutputFileExt();
0348:                    String plusName = "";
0349:                    if (ext.equals(origExt)) {
0350:                        plusName = NbBundle.getMessage(TransformPanel.class,
0351:                                "NAME_plusNameIfSameName");
0352:                    }
0353:
0354:                    output = origName + plusName + "." + ext; // NOI18N
0355:                }
0356:
0357:                return output;
0358:            }
0359:
0360:            private void initOutputComboBox(Object defaultOutput) {
0361:                outputComboBox.setModel(new DefaultComboBoxModel(new Object[] {
0362:                        defaultOutput, JUST_PREVIEW }));
0363:            }
0364:
0365:            private void updateComponents() {
0366:                setInitialized(false);
0367:
0368:                // XML Input
0369:                boolean notXML = (xmlDataObject == null);
0370:                if (data.xml != null) {
0371:                    inputComboBox.setSelectedItem(data.xml);
0372:                    inputComboBox.setEditable(data.xml instanceof  String);
0373:                }
0374:                inputComboBox.setEnabled(notXML);
0375:                browseInputButton.setEnabled(notXML);
0376:
0377:                // XSL Transformation
0378:                if (suppressXSL) {
0379:                    transformLabel.setVisible(false);
0380:                    transformComboBox.setVisible(false);
0381:                    browseXSLTButton.setVisible(false);
0382:                } else {
0383:                    transformLabel.setVisible(true);
0384:                    transformComboBox.setVisible(true);
0385:                    browseXSLTButton.setVisible(true);
0386:
0387:                    boolean notXSL = (xslDataObject == null);
0388:                    transformComboBox.setEnabled(notXSL);
0389:                    browseXSLTButton.setEnabled(notXSL);
0390:                    if (data.xsl != null) {
0391:                        transformComboBox.setSelectedItem(data.xsl);
0392:                        transformComboBox
0393:                                .setEditable(data.xsl instanceof  String);
0394:                    }
0395:                }
0396:
0397:                // test if XML and also XSL
0398:                boolean canOutput = true;
0399:                if ((data.xml == null) || (data.xsl == null)
0400:                        || (data.xml.length() == 0) || (data.xsl.length() == 0)) {
0401:                    canOutput = false;
0402:                }
0403:
0404:                // Output
0405:                outputComboBox.setEnabled(canOutput);
0406:                if (canOutput) {
0407:                    Object output = guessOutputFile();
0408:                    initOutputComboBox(output);
0409:
0410:                    outputComboBox.setSelectedItem(data.output != null ? output
0411:                            : JUST_PREVIEW);
0412:                    outputComboBox.setEditable(data.output != null);
0413:                }
0414:
0415:                // Overwrite Output
0416:                if (data.overwrite != null) {
0417:                    overwriteCheckBox
0418:                            .setSelected(data.overwrite.booleanValue());
0419:                }
0420:                overwriteCheckBox.setEnabled(canOutput && data.output != null);
0421:
0422:                // Process Output
0423:                if (data.process != null) {
0424:                    showComboBox.setSelectedIndex(data.process.intValue());
0425:                } else {
0426:                    String ext = guessOutputFileExt().toLowerCase();
0427:                    if (ext.equals("html") || ext.equals("htm")) { // NOI18N
0428:                        showComboBox
0429:                                .setSelectedIndex(TransformHistory.OPEN_IN_BROWSER);
0430:                    } else {
0431:                        showComboBox
0432:                                .setSelectedIndex(TransformHistory.APPLY_DEFAULT_ACTION);
0433:                    }
0434:                }
0435:                showComboBox.setEnabled(canOutput && data.output != null);
0436:
0437:                setInitialized(true);
0438:            }
0439:
0440:            public Data getData() {
0441:                return new Data(getInput(), getXSL(), getOutput(),
0442:                        isOverwriteOutput(), getProcessOutput());
0443:            }
0444:
0445:            public void setData(Data data) {
0446:                this .data = data;
0447:                updateComponents();
0448:            }
0449:
0450:            /**
0451:             * @return selected XML input.
0452:             */
0453:            private String getInput() {
0454:                return (String) inputComboBox.getSelectedItem();
0455:            }
0456:
0457:            /**
0458:             * @return selected XSLT script.
0459:             */
0460:            private String getXSL() {
0461:                return (String) transformComboBox.getSelectedItem();
0462:            }
0463:
0464:            /**
0465:             * @return selected output.
0466:             */
0467:            private String getOutput() {
0468:                Object output = outputComboBox.getSelectedItem();
0469:
0470:                if (JUST_PREVIEW.equals(output)) {
0471:                    return null;
0472:                }
0473:                return (String) output;
0474:            }
0475:
0476:            /**
0477:             * @return selected overwrite output option.
0478:             */
0479:            private boolean isOverwriteOutput() {
0480:                return overwriteCheckBox.isSelected();
0481:            }
0482:
0483:            /**
0484:             * @return selected process output option.
0485:             */
0486:            private int getProcessOutput() {
0487:                return showComboBox.getSelectedIndex();
0488:            }
0489:
0490:            /**
0491:             * Compute preffered dimension for combo with
0492:             * particulal number of columns
0493:             */
0494:            private Dimension comboSize(int columns) {
0495:                JTextField template = new JTextField();
0496:                template.setColumns(columns);
0497:                return template.getPreferredSize();
0498:            }
0499:
0500:            /** This method is called from within the constructor to
0501:             * initialize the form.
0502:             * WARNING: Do NOT modify this code. The content of this method is
0503:             * always regenerated by the Form Editor.
0504:             */
0505:            // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
0506:            private void initComponents() {
0507:                java.awt.GridBagConstraints gridBagConstraints;
0508:
0509:                inputLabel = new javax.swing.JLabel();
0510:                inputLabel.setDisplayedMnemonic(NbBundle.getMessage(
0511:                        TransformPanel.class, "LBL_XML_input_mnemonic").charAt(
0512:                        0));
0513:                inputComboBox = new javax.swing.JComboBox();
0514:                browseInputButton = new javax.swing.JButton();
0515:                transformLabel = new javax.swing.JLabel();
0516:                transformLabel.setDisplayedMnemonic(NbBundle.getMessage(
0517:                        TransformPanel.class, "LBL_XSL_transform_mnemonic")
0518:                        .charAt(0));
0519:                transformComboBox = new javax.swing.JComboBox();
0520:                browseXSLTButton = new javax.swing.JButton();
0521:                outputLabel = new javax.swing.JLabel();
0522:                outputLabel.setDisplayedMnemonic(NbBundle.getMessage(
0523:                        TransformPanel.class, "LBL_trans_output_mnemonic")
0524:                        .charAt(0));
0525:                outputComboBox = new javax.swing.JComboBox();
0526:                overwriteCheckBox = new javax.swing.JCheckBox();
0527:                overwriteCheckBox.setMnemonic(NbBundle.getMessage(
0528:                        TransformPanel.class, "LBL_over_write_mnemonic")
0529:                        .charAt(0));
0530:                showLabel = new javax.swing.JLabel();
0531:                showLabel.setDisplayedMnemonic(NbBundle.getMessage(
0532:                        TransformPanel.class, "LBL_show_output_mnemonic")
0533:                        .charAt(0));
0534:                showComboBox = new javax.swing.JComboBox();
0535:
0536:                setLayout(new java.awt.GridBagLayout());
0537:
0538:                inputLabel.setLabelFor(inputComboBox);
0539:                inputLabel.setText(NbBundle.getMessage(TransformPanel.class,
0540:                        "LBL_XML_input")); // NOI18N
0541:                gridBagConstraints = new java.awt.GridBagConstraints();
0542:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0543:                gridBagConstraints.insets = new java.awt.Insets(6, 12, 0, 0);
0544:                add(inputLabel, gridBagConstraints);
0545:
0546:                inputComboBox.setEditable(true);
0547:                inputComboBox.setPreferredSize(comboSize(40));
0548:                inputComboBox
0549:                        .addActionListener(new java.awt.event.ActionListener() {
0550:                            public void actionPerformed(
0551:                                    java.awt.event.ActionEvent evt) {
0552:                                inputComboBoxActionPerformed(evt);
0553:                            }
0554:                        });
0555:                gridBagConstraints = new java.awt.GridBagConstraints();
0556:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0557:                gridBagConstraints.weightx = 1.0;
0558:                gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
0559:                add(inputComboBox, gridBagConstraints);
0560:
0561:                browseInputButton.setMnemonic(NbBundle.getMessage(
0562:                        TransformPanel.class, "LBL_browse_file_mnemonic")
0563:                        .charAt(0));
0564:                browseInputButton.setText(NbBundle.getMessage(
0565:                        TransformPanel.class, "LBL_browse_file")); // NOI18N
0566:                browseInputButton
0567:                        .addActionListener(new java.awt.event.ActionListener() {
0568:                            public void actionPerformed(
0569:                                    java.awt.event.ActionEvent evt) {
0570:                                browseInputButtonActionPerformed(evt);
0571:                            }
0572:                        });
0573:                gridBagConstraints = new java.awt.GridBagConstraints();
0574:                gridBagConstraints.insets = new java.awt.Insets(12, 5, 0, 11);
0575:                add(browseInputButton, gridBagConstraints);
0576:
0577:                transformLabel.setLabelFor(transformComboBox);
0578:                transformLabel.setText(NbBundle.getMessage(
0579:                        TransformPanel.class, "LBL_XSL_transform")); // NOI18N
0580:                gridBagConstraints = new java.awt.GridBagConstraints();
0581:                gridBagConstraints.gridx = 0;
0582:                gridBagConstraints.gridy = 1;
0583:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0584:                gridBagConstraints.insets = new java.awt.Insets(6, 12, 0, 0);
0585:                add(transformLabel, gridBagConstraints);
0586:
0587:                transformComboBox.setEditable(true);
0588:                transformComboBox.setPreferredSize(comboSize(40));
0589:                transformComboBox
0590:                        .addActionListener(new java.awt.event.ActionListener() {
0591:                            public void actionPerformed(
0592:                                    java.awt.event.ActionEvent evt) {
0593:                                transformComboBoxActionPerformed(evt);
0594:                            }
0595:                        });
0596:                gridBagConstraints = new java.awt.GridBagConstraints();
0597:                gridBagConstraints.gridx = 1;
0598:                gridBagConstraints.gridy = 1;
0599:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0600:                gridBagConstraints.weightx = 1.0;
0601:                gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0);
0602:                add(transformComboBox, gridBagConstraints);
0603:
0604:                browseXSLTButton.setMnemonic(NbBundle.getMessage(
0605:                        TransformPanel.class, "LBL_browse_xslt_mnemonic")
0606:                        .charAt(0));
0607:                browseXSLTButton.setText(NbBundle.getMessage(
0608:                        TransformPanel.class, "LBL_browse_xslt")); // NOI18N
0609:                browseXSLTButton
0610:                        .addActionListener(new java.awt.event.ActionListener() {
0611:                            public void actionPerformed(
0612:                                    java.awt.event.ActionEvent evt) {
0613:                                browseXSLTButtonActionPerformed(evt);
0614:                            }
0615:                        });
0616:                gridBagConstraints = new java.awt.GridBagConstraints();
0617:                gridBagConstraints.gridx = 2;
0618:                gridBagConstraints.gridy = 1;
0619:                gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 11);
0620:                add(browseXSLTButton, gridBagConstraints);
0621:
0622:                outputLabel.setLabelFor(outputComboBox);
0623:                outputLabel.setText(NbBundle.getMessage(TransformPanel.class,
0624:                        "LBL_trans_output")); // NOI18N
0625:                gridBagConstraints = new java.awt.GridBagConstraints();
0626:                gridBagConstraints.gridx = 0;
0627:                gridBagConstraints.gridy = 2;
0628:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0629:                gridBagConstraints.insets = new java.awt.Insets(6, 12, 0, 0);
0630:                add(outputLabel, gridBagConstraints);
0631:
0632:                outputComboBox.setEditable(true);
0633:                outputComboBox.setPreferredSize(comboSize(40));
0634:                outputComboBox
0635:                        .addActionListener(new java.awt.event.ActionListener() {
0636:                            public void actionPerformed(
0637:                                    java.awt.event.ActionEvent evt) {
0638:                                outputComboBoxActionPerformed(evt);
0639:                            }
0640:                        });
0641:                gridBagConstraints = new java.awt.GridBagConstraints();
0642:                gridBagConstraints.gridx = 1;
0643:                gridBagConstraints.gridy = 2;
0644:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0645:                gridBagConstraints.weightx = 1.0;
0646:                gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0);
0647:                add(outputComboBox, gridBagConstraints);
0648:
0649:                overwriteCheckBox.setSelected(true);
0650:                overwriteCheckBox.setText(NbBundle.getMessage(
0651:                        TransformPanel.class, "LBL_over_write")); // NOI18N
0652:                overwriteCheckBox
0653:                        .addActionListener(new java.awt.event.ActionListener() {
0654:                            public void actionPerformed(
0655:                                    java.awt.event.ActionEvent evt) {
0656:                                overwriteCheckBoxActionPerformed(evt);
0657:                            }
0658:                        });
0659:                gridBagConstraints = new java.awt.GridBagConstraints();
0660:                gridBagConstraints.gridx = 1;
0661:                gridBagConstraints.gridy = 4;
0662:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0663:                gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0);
0664:                add(overwriteCheckBox, gridBagConstraints);
0665:
0666:                showLabel.setText(NbBundle.getMessage(TransformPanel.class,
0667:                        "LBL_show_output")); // NOI18N
0668:                gridBagConstraints = new java.awt.GridBagConstraints();
0669:                gridBagConstraints.gridx = 0;
0670:                gridBagConstraints.gridy = 5;
0671:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0672:                gridBagConstraints.insets = new java.awt.Insets(6, 12, 6, 0);
0673:                add(showLabel, gridBagConstraints);
0674:
0675:                showComboBox.setModel(new javax.swing.DefaultComboBoxModel(
0676:                        SHOW_NAMES));
0677:                showComboBox
0678:                        .addActionListener(new java.awt.event.ActionListener() {
0679:                            public void actionPerformed(
0680:                                    java.awt.event.ActionEvent evt) {
0681:                                showComboBoxActionPerformed(evt);
0682:                            }
0683:                        });
0684:                gridBagConstraints = new java.awt.GridBagConstraints();
0685:                gridBagConstraints.gridx = 1;
0686:                gridBagConstraints.gridy = 5;
0687:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0688:                gridBagConstraints.weightx = 1.0;
0689:                gridBagConstraints.insets = new java.awt.Insets(11, 12, 6, 0);
0690:                add(showComboBox, gridBagConstraints);
0691:            }// </editor-fold>//GEN-END:initComponents
0692:
0693:            /** Initialize accesibility
0694:             */
0695:            private void initAccessibility() {
0696:                this .getAccessibleContext().setAccessibleDescription(
0697:                        NbBundle.getMessage(TransformPanel.class,
0698:                                "ACSD_TransformPanel"));
0699:
0700:                overwriteCheckBox.getAccessibleContext()
0701:                        .setAccessibleDescription(
0702:                                NbBundle.getMessage(TransformPanel.class,
0703:                                        "ACSD_overwriteCheckBox"));
0704:                outputComboBox.getAccessibleContext().setAccessibleDescription(
0705:                        NbBundle.getMessage(TransformPanel.class,
0706:                                "ACSD_outputComboBox"));
0707:                inputComboBox.getAccessibleContext().setAccessibleDescription(
0708:                        NbBundle.getMessage(TransformPanel.class,
0709:                                "ACSD_inputComboBox"));
0710:                browseXSLTButton.getAccessibleContext()
0711:                        .setAccessibleDescription(
0712:                                NbBundle.getMessage(TransformPanel.class,
0713:                                        "ACSD_browseXSLTButton"));
0714:                showComboBox.getAccessibleContext().setAccessibleDescription(
0715:                        NbBundle.getMessage(TransformPanel.class,
0716:                                "ACSD_showComboBox"));
0717:                browseInputButton.getAccessibleContext()
0718:                        .setAccessibleDescription(
0719:                                NbBundle.getMessage(TransformPanel.class,
0720:                                        "ACSD_browseInputButton"));
0721:                transformComboBox.getAccessibleContext()
0722:                        .setAccessibleDescription(
0723:                                NbBundle.getMessage(TransformPanel.class,
0724:                                        "ACSD_transformComboBox"));
0725:            }
0726:
0727:            private void browseXSLTButtonActionPerformed(
0728:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseXSLTButtonActionPerformed
0729:
0730:                try {
0731:                    File selectedFile = getFileFromChooser(getXSL());
0732:                    if (selectedFile == null)
0733:                        return;
0734:                    FileObject fo = FileUtil.toFileObject(selectedFile);
0735:                    DataObject dObj = fo == null ? null : DataObject.find(fo);
0736:                    if (dObj == null
0737:                            || !TransformUtil.isXSLTransformation(dObj)) {
0738:                        NotifyDescriptor desc = new NotifyDescriptor.Message(
0739:                                NbBundle.getMessage(TransformPanel.class,
0740:                                        "MSG_notXslFile", //NOI18N
0741:                                        selectedFile.getName()),
0742:                                NotifyDescriptor.ERROR_MESSAGE);
0743:                        DialogDisplayer.getDefault().notify(desc);
0744:                        return;
0745:                    }
0746:                    setXSL(TransformUtil.getURLName(fo));
0747:
0748:                    if ((userSetOutput == false) && (xmlHistory != null)) {
0749:                        setOutput(xmlHistory.getXSLOutput(data.xsl));
0750:                    }
0751:                    if (userSetProcess == false) {
0752:                        setProcessOutput(null);
0753:                    }
0754:                    updateXSLComboBoxModel(data.xsl);
0755:
0756:                    updateComponents();
0757:
0758:                    setCaretPosition(transformComboBox);
0759:
0760:                } catch (IOException exc) { // TransformUtil.getURLName (...)
0761:                    // ignore it
0762:                    //Util.THIS.debug(exc);
0763:                } finally {
0764:                    //Util.icons = null;
0765:                }
0766:            }//GEN-LAST:event_browseXSLTButtonActionPerformed
0767:
0768:            private void browseInputButtonActionPerformed(
0769:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseInputButtonActionPerformed
0770:
0771:                try {
0772:                    File selectedFile = getFileFromChooser(getInput());
0773:                    if (selectedFile == null)
0774:                        return;
0775:                    FileObject fo = FileUtil.toFileObject(selectedFile);
0776:                    DataObject dObj = fo == null ? null : DataObject.find(fo);
0777:                    if (dObj == null
0778:                            || dObj.getCookie(TransformableCookie.class) == null) {
0779:                        NotifyDescriptor desc = new NotifyDescriptor.Message(
0780:                                NbBundle.getMessage(TransformPanel.class,
0781:                                        "MSG_notXmlFile", //NOI18N
0782:                                        selectedFile.getName()),
0783:                                NotifyDescriptor.ERROR_MESSAGE);
0784:                        DialogDisplayer.getDefault().notify(desc);
0785:                        return;
0786:                    }
0787:                    setInput(TransformUtil.getURLName(fo));
0788:
0789:                    if ((userSetOutput == false) && (xslHistory != null)) {
0790:                        setOutput(xslHistory.getXMLOutput(data.xml));
0791:                    }
0792:                    if (userSetProcess == false) {
0793:                        setProcessOutput(null);
0794:                    }
0795:                    updateXMLComboBoxModel(data.xml);
0796:
0797:                    updateComponents();
0798:
0799:                    setCaretPosition(inputComboBox);
0800:
0801:                } catch (IOException exc) { // TransformUtil.getURLName (...)
0802:                    // ignore it
0803:                    //Util.THIS.debug(exc);
0804:                } finally {
0805:                    //Util.icons = null;
0806:                }
0807:            }//GEN-LAST:event_browseInputButtonActionPerformed
0808:
0809:            public void setInput(String input) {
0810:                if (data == null) {
0811:                    return;
0812:                }
0813:                String oldInput = data.getInput();
0814:                data.setInput(input);
0815:                firePropertyChange(DATA_XML_MODIFIED, oldInput, input);
0816:            }
0817:
0818:            public void setXSL(String xslValue) {
0819:                if (data == null) {
0820:                    return;
0821:                }
0822:                String oldXSL = data.getXSL();
0823:                data.setXSL(xslValue);
0824:                firePropertyChange(DATA_XSL_MODIFIED, oldXSL, xslValue);
0825:            }
0826:
0827:            public void setOutput(Object outputValue) {
0828:                if (data == null) {
0829:                    return;
0830:                }
0831:                Object oldOutput = data.getOutput();
0832:                data.setOutput(outputValue);
0833:                firePropertyChange(DATA_OUTPUT_MODIFIED, oldOutput, outputValue);
0834:            }
0835:
0836:            public void setOverwriteOutput(Boolean overwriteObject) {
0837:                if (data == null || overwriteObject == null) {
0838:                    return;
0839:                }
0840:                setOverwriteOutput(overwriteObject.booleanValue());
0841:            }
0842:
0843:            public void setOverwriteOutput(boolean overwriteValue) {
0844:                if (data == null) {
0845:                    return;
0846:                }
0847:                boolean oldOverwrite = data.isOverwriteOutput();
0848:                data.setOverwriteOutput(overwriteValue);
0849:                firePropertyChange(DATA_OVERWRITE_MODIFIED, oldOverwrite,
0850:                        overwriteValue);
0851:            }
0852:
0853:            public void setProcessOutput(Integer processObject) {
0854:                if (data == null || processObject == null) {
0855:                    return;
0856:                }
0857:                setProcessOutput(processObject.intValue());
0858:            }
0859:
0860:            public void setProcessOutput(int processValue) {
0861:                if (data == null) {
0862:                    return;
0863:                }
0864:                int oldProcess = data.getProcessOutput();
0865:                data.setProcessOutput(processValue);
0866:                firePropertyChange(DATA_PROCESS_MODIFIED, oldProcess,
0867:                        processValue);
0868:            }
0869:
0870:            private void showComboBoxActionPerformed(
0871:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showComboBoxActionPerformed
0872:                // Add your handling code here:
0873:                if (isInitialized()) {
0874:                    setProcessOutput(new Integer(showComboBox
0875:                            .getSelectedIndex()));
0876:                    userSetProcess = true;
0877:                    updateComponents();
0878:                }
0879:            }//GEN-LAST:event_showComboBoxActionPerformed
0880:
0881:            private void overwriteCheckBoxActionPerformed(
0882:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_overwriteCheckBoxActionPerformed
0883:                // Add your handling code here:
0884:                if (isInitialized()) {
0885:                    setOverwriteOutput(overwriteCheckBox.isSelected());
0886:                    updateComponents();
0887:                }
0888:            }//GEN-LAST:event_overwriteCheckBoxActionPerformed
0889:
0890:            private void transformComboBoxActionPerformed(
0891:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_transformComboBoxActionPerformed
0892:                // Add your handling code here:
0893:                if (isInitialized()) {
0894:                    String item = (String) transformComboBox.getSelectedItem();
0895:
0896:                    //            if ( Util.THIS.isLoggable() ) /* then */ {
0897:                    //                Util.THIS.debug("TransformPanel.transformComboBoxActionPerformed: getSelectedItem = " + item);
0898:                    //            }
0899:
0900:                    if (item == null) {
0901:                        return;
0902:                    }
0903:
0904:                    setXSL(item.trim());
0905:
0906:                    if ((userSetOutput == false) && (xmlHistory != null)) {
0907:                        setOutput(xmlHistory.getXSLOutput(data.xsl));
0908:                    }
0909:                    if (userSetProcess == false) {
0910:                        setProcessOutput(null);
0911:                    }
0912:
0913:                    updateComponents();
0914:
0915:                    //             setCaretPosition (transformComboBox);
0916:                }
0917:            }//GEN-LAST:event_transformComboBoxActionPerformed
0918:
0919:            private void inputComboBoxActionPerformed(
0920:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputComboBoxActionPerformed
0921:                // Add your handling code here:
0922:                if (isInitialized()) {
0923:                    String item = (String) inputComboBox.getSelectedItem();
0924:
0925:                    //            if ( Util.THIS.isLoggable() ) /* then */ {
0926:                    //                Util.THIS.debug("TransformPanel.inputComboBoxActionPerformed: getSelectedItem = " + item);
0927:                    //            }
0928:
0929:                    if (item == null) {
0930:                        return;
0931:                    }
0932:
0933:                    setInput(item.trim());
0934:
0935:                    if ((userSetOutput == false) && (xslHistory != null)) {
0936:                        setOutput(xslHistory.getXMLOutput(data.xml));
0937:                    }
0938:                    if (userSetProcess == false) {
0939:                        setProcessOutput(null);
0940:                    }
0941:
0942:                    updateComponents();
0943:
0944:                    //             setCaretPosition (inputComboBox);
0945:                }
0946:            }//GEN-LAST:event_inputComboBoxActionPerformed
0947:
0948:            private void outputComboBoxActionPerformed(
0949:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_outputComboBoxActionPerformed
0950:                // Add your handling code here:
0951:                if (isInitialized()) {
0952:                    Object item = outputComboBox.getSelectedItem();
0953:                    if (item instanceof  String) {
0954:                        String str = ((String) item).trim();
0955:                        if (str.length() == 0) {
0956:                            str = null;
0957:                        }
0958:                        item = str;
0959:                    }
0960:                    setOutput(item);
0961:
0962:                    userSetOutput = true;
0963:                    updateComponents();
0964:
0965:                    //             setCaretPosition (outputComboBox);
0966:                }
0967:            }//GEN-LAST:event_outputComboBoxActionPerformed
0968:
0969:            // Variables declaration - do not modify//GEN-BEGIN:variables
0970:            private javax.swing.JButton browseInputButton;
0971:            private javax.swing.JButton browseXSLTButton;
0972:            private javax.swing.JComboBox inputComboBox;
0973:            private javax.swing.JLabel inputLabel;
0974:            private javax.swing.JComboBox outputComboBox;
0975:            private javax.swing.JLabel outputLabel;
0976:            private javax.swing.JCheckBox overwriteCheckBox;
0977:            private javax.swing.JComboBox showComboBox;
0978:            private javax.swing.JLabel showLabel;
0979:            private javax.swing.JComboBox transformComboBox;
0980:            private javax.swing.JLabel transformLabel;
0981:
0982:            // End of variables declaration//GEN-END:variables
0983:
0984:            //
0985:            // class Data
0986:            //
0987:
0988:            public static final class Data {
0989:                private String xml;
0990:                private String xsl;
0991:                private Object output;
0992:                private Boolean overwrite;
0993:                private Integer process;
0994:
0995:                public Data() {
0996:                    this .xml = null;
0997:                    this .xsl = null;
0998:                    this .output = "";
0999:                    this .overwrite = null;
1000:                    this .process = null;
1001:                }
1002:
1003:                public Data(String xml, String xsl, Object output,
1004:                        boolean overwrite, int process) {
1005:                    this .xml = xml;
1006:                    this .xsl = xsl;
1007:                    this .output = output;
1008:                    this .overwrite = overwrite ? Boolean.TRUE : Boolean.FALSE;
1009:                    this .process = process == -1 ? null : new Integer(process);
1010:                }
1011:
1012:                /**
1013:                 * @return selected XML input.
1014:                 */
1015:                public String getInput() {
1016:                    return xml;
1017:                }
1018:
1019:                /**
1020:                 * @return selected XSLT script.
1021:                 */
1022:                public String getXSL() {
1023:                    return xsl;
1024:                }
1025:
1026:                /**
1027:                 * @return selected output.
1028:                 */
1029:                public Object getOutput() {
1030:                    return output;
1031:                }
1032:
1033:                /**
1034:                 * @return selected overwrite output option.
1035:                 */
1036:                public boolean isOverwriteOutput() {
1037:                    if (overwrite == null) {
1038:                        return false;
1039:                    }
1040:                    return overwrite.booleanValue();
1041:                }
1042:
1043:                /**
1044:                 * @return selected process output option.
1045:                 */
1046:                public int getProcessOutput() {
1047:                    if (process == null) {
1048:                        return 0;
1049:                    }
1050:                    return process.intValue();
1051:                }
1052:
1053:                public void setInput(String input) {
1054:                    xml = input;
1055:                }
1056:
1057:                public void setXSL(String xslValue) {
1058:                    xsl = xslValue;
1059:                }
1060:
1061:                public void setOutput(Object outputValue) {
1062:                    if (JUST_PREVIEW.equals(outputValue)) {
1063:                        output = null;
1064:                    } else {
1065:                        output = outputValue;
1066:                    }
1067:                }
1068:
1069:                public void setOverwriteOutput(boolean overwriteValue) {
1070:                    overwrite = overwriteValue ? Boolean.TRUE : Boolean.FALSE;
1071:                }
1072:
1073:                public void setProcessOutput(Integer processObject) {
1074:                    process = processObject;
1075:                }
1076:
1077:                public void setProcessOutput(int processValue) {
1078:                    setProcessOutput(new Integer(processValue));
1079:                }
1080:
1081:                public String toString() {
1082:                    StringBuffer sb = new StringBuffer(super .toString());
1083:
1084:                    sb.append("[input='").append(xml).append("'; ");
1085:                    sb.append("xsl='").append(xsl).append("'; ");
1086:                    sb.append("output='").append(output).append("'; ");
1087:                    sb.append("overwrite='").append(overwrite).append("'; ");
1088:                    sb.append("process='").append(process).append("]");
1089:
1090:                    return sb.toString();
1091:                }
1092:
1093:            } // class Data
1094:
1095:            //
1096:            // class Preview
1097:            //
1098:
1099:            private static class Preview {
1100:                public String toString() {
1101:                    return NbBundle.getMessage(TransformPanel.class,
1102:                            "NAME_output_just_preview");
1103:                }
1104:            } // class Preview
1105:
1106:            /** Open the file chooser and return the file.
1107:             *@param oldUrl url where to start browsing
1108:             */
1109:            private File getFileFromChooser(String oldUrl) {
1110:                javax.swing.JFileChooser chooser = new javax.swing.JFileChooser();
1111:                if (oldUrl != null) {
1112:                    try {
1113:                        File file = null;
1114:                        java.net.URI url = new java.net.URI(oldUrl);
1115:                        if (url != null) {
1116:                            file = new File(url);
1117:                        }
1118:                        if (file != null) {
1119:                            File parentDir = file.getParentFile();
1120:                            if (parentDir != null && parentDir.exists())
1121:                                chooser.setCurrentDirectory(parentDir);
1122:                        }
1123:                    } catch (java.net.URISyntaxException ex) {
1124:                    } catch (java.lang.IllegalArgumentException x) {
1125:                    }
1126:                }
1127:                File selectedFile = null;
1128:                if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
1129:                    selectedFile = chooser.getSelectedFile();
1130:                }
1131:                return selectedFile;
1132:            }
1133:
1134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.