/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2011 Neil C Smith. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 3 for more details. * * You should have received a copy of the GNU General Public License version 3 * along with this work; if not, see http://www.gnu.org/licenses/ * * * Please visit http://neilcsmith.net if you need additional information or * have any questions. */ package net.neilcsmith.praxis.live.project.wizard; import java.io.File; import javax.swing.JPanel; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.netbeans.spi.project.ui.support.ProjectChooser; import org.openide.filesystems.FileChooserBuilder; final class PraxisProjectVisualPanel1 extends JPanel implements DocumentListener { private PraxisProjectWizardPanel1 wizardPanel; private FileChooserBuilder fileChooser; private File location; PraxisProjectVisualPanel1(PraxisProjectWizardPanel1 wizardPanel) { this.wizardPanel = wizardPanel; initComponents(); fileChooser = new FileChooserBuilder(PraxisProjectWizardIterator.class) .setDirectoriesOnly(true) .setApproveText("Select") .setDefaultWorkingDirectory(ProjectChooser.getProjectsFolder()) .forceUseOfDefaultWorkingDirectory(true) .setFileHiding(true); location = fileChooser.createFileChooser().getCurrentDirectory(); locationField.setText(location.toString()); projectField.setText(location.toString()); nameField.getDocument().addDocumentListener(this); } @Override public String getName() { return "Project Location"; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { nameField = new javax.swing.JTextField(); nameLabel = new javax.swing.JLabel(); locationField = new javax.swing.JTextField(); locationLabel = new javax.swing.JLabel(); browseButton = new javax.swing.JButton(); projectField = new javax.swing.JTextField(); folderLabel = new javax.swing.JLabel(); org.openide.awt.Mnemonics.setLocalizedText(nameLabel, org.openide.util.NbBundle.getMessage(PraxisProjectVisualPanel1.class, "PraxisProjectVisualPanel1.nameLabel.text")); // NOI18N locationField.setEditable(false); org.openide.awt.Mnemonics.setLocalizedText(locationLabel, org.openide.util.NbBundle.getMessage(PraxisProjectVisualPanel1.class, "PraxisProjectVisualPanel1.locationLabel.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(PraxisProjectVisualPanel1.class, "PraxisProjectVisualPanel1.browseButton.text")); // NOI18N browseButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { browseButtonActionPerformed(evt); } }); projectField.setEditable(false); org.openide.awt.Mnemonics.setLocalizedText(folderLabel, org.openide.util.NbBundle.getMessage(PraxisProjectVisualPanel1.class, "PraxisProjectVisualPanel1.folderLabel.text")); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(25, 25, 25) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(folderLabel) .addComponent(locationLabel) .addComponent(nameLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(projectField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(locationField, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(browseButton)) .addComponent(nameField, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(nameLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(locationField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(browseButton) .addComponent(locationLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(projectField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(folderLabel)) .addContainerGap(193, Short.MAX_VALUE)) ); }// </editor-fold>//GEN-END:initComponents private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed File loc = fileChooser.showOpenDialog(); if (loc != null) { location = loc; locationField.setText(location.toString()) ; update(); } }//GEN-LAST:event_browseButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton browseButton; private javax.swing.JLabel folderLabel; private javax.swing.JTextField locationField; private javax.swing.JLabel locationLabel; private javax.swing.JTextField nameField; private javax.swing.JLabel nameLabel; private javax.swing.JTextField projectField; // End of variables declaration//GEN-END:variables File getProjectLocation() { return location; } String getProjectName() { return nameField.getText(); } @Override public void insertUpdate(DocumentEvent e) { update(); } @Override public void removeUpdate(DocumentEvent e) { update(); } @Override public void changedUpdate(DocumentEvent e) { update(); } private void update() { projectField.setText(locationField.getText() + "/" + nameField.getText()); wizardPanel.validate(); } }