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-2006 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:
042: package org.netbeans.modules.project.ant;
043:
044: import java.awt.BorderLayout;
045: import java.io.File;
046: import java.io.IOException;
047:
048: /**
049: * Wrapper around FileChooserAccessory to let user decide how to reference file.
050: */
051: public class RelativizeFilePathCustomizer extends javax.swing.JPanel {
052:
053: private File fileToRelativize;
054: private File baseFolder;
055: private File sharedLibrariesFolder;
056: private boolean copyAllowed;
057: private FileChooserAccessory fileChooserAccessory;
058:
059: /** Creates new form RelativizeFilePathCustomizer */
060: public RelativizeFilePathCustomizer(File fileToRelativize,
061: File baseFolder, File sharedLibrariesFolder,
062: boolean copyAllowed) {
063: this .fileToRelativize = fileToRelativize;
064: this .baseFolder = baseFolder;
065: this .sharedLibrariesFolder = sharedLibrariesFolder;
066: this .copyAllowed = copyAllowed;
067: initComponents();
068: fileChooserAccessory = new FileChooserAccessory(baseFolder,
069: sharedLibrariesFolder, copyAllowed, fileToRelativize);
070: jPanel1.setLayout(new BorderLayout());
071: jPanel1.add(fileChooserAccessory);
072: }
073:
074: public String getFile() throws IOException {
075: fileChooserAccessory.copyFilesIfNecessary();
076: if (fileChooserAccessory.isRelative()) {
077: return fileChooserAccessory.getFiles()[0];
078: } else {
079: return fileToRelativize.getAbsolutePath();
080: }
081: }
082:
083: /** This method is called from within the constructor to
084: * initialize the form.
085: * WARNING: Do NOT modify this code. The content of this method is
086: * always regenerated by the Form Editor.
087: */
088: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
089: private void initComponents() {
090:
091: jLabel1 = new javax.swing.JLabel();
092: jPanel1 = new javax.swing.JPanel();
093:
094: jLabel1.setText(java.text.MessageFormat.format(
095: org.openide.util.NbBundle.getMessage(
096: RelativizeFilePathCustomizer.class,
097: "RelativizeFilePathCustomizer.jLabel1.text"),
098: new Object[] { fileToRelativize.getName() })); // NOI18N
099:
100: org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(
101: jPanel1);
102: jPanel1.setLayout(jPanel1Layout);
103: jPanel1Layout.setHorizontalGroup(jPanel1Layout
104: .createParallelGroup(
105: org.jdesktop.layout.GroupLayout.LEADING).add(0,
106: 380, Short.MAX_VALUE));
107: jPanel1Layout.setVerticalGroup(jPanel1Layout
108: .createParallelGroup(
109: org.jdesktop.layout.GroupLayout.LEADING).add(0,
110: 258, Short.MAX_VALUE));
111:
112: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
113: this );
114: this .setLayout(layout);
115: layout
116: .setHorizontalGroup(layout
117: .createParallelGroup(
118: org.jdesktop.layout.GroupLayout.LEADING)
119: .add(
120: layout
121: .createSequentialGroup()
122: .addContainerGap()
123: .add(
124: layout
125: .createParallelGroup(
126: org.jdesktop.layout.GroupLayout.LEADING)
127: .add(
128: jPanel1,
129: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
130: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
131: Short.MAX_VALUE)
132: .add(jLabel1))
133: .addContainerGap()));
134: layout.setVerticalGroup(layout.createParallelGroup(
135: org.jdesktop.layout.GroupLayout.LEADING).add(
136: layout.createSequentialGroup().addContainerGap().add(
137: jLabel1).addPreferredGap(
138: org.jdesktop.layout.LayoutStyle.RELATED).add(
139: jPanel1,
140: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
141: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
142: Short.MAX_VALUE).addContainerGap()));
143: }// </editor-fold>//GEN-END:initComponents
144:
145: // Variables declaration - do not modify//GEN-BEGIN:variables
146: private javax.swing.JLabel jLabel1;
147: private javax.swing.JPanel jPanel1;
148: // End of variables declaration//GEN-END:variables
149:
150: }
|