Skip to content

Commit

Permalink
NewProject Wizard remembers path
Browse files Browse the repository at this point in the history
  • Loading branch information
thorstenv committed Nov 21, 2013
1 parent 509f804 commit 2bf538a
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Wizards/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Manifest-Version: 1.0
OpenIDE-Module: jav.gui.wizard
OpenIDE-Module-Implementation-Version: 1
OpenIDE-Module-Implementation-Version: 2
OpenIDE-Module-Localizing-Bundle: jav/gui/wizard/Bundle.properties

19 changes: 10 additions & 9 deletions Wizards/src/jav/gui/wizard/newProject/NewProjectVisualPanel0.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public final class NewProjectVisualPanel0 extends JPanel implements DocumentList
public static final String PROP_NAME = "Proj_Name";

/** Creates new form NewProjectVisualPanel1 */
public NewProjectVisualPanel0() {
public NewProjectVisualPanel0(JFileChooser jfc) {
initComponents();
fileChooser = jfc;
jTextField1.setText("");
jTextField1.getDocument().addDocumentListener(this);

Expand All @@ -60,12 +60,11 @@ public NewProjectVisualPanel0() {
jButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser jfc = new JFileChooser();
// AbstractButton button = SwingUtils.getDescendantOfType(AbstractButton.class, jfc, "Icon", UIManager.getIcon("FileChooser.detailsViewIcon"));
// button.doClick();
jfc.setDialogTitle(java.util.ResourceBundle.getBundle("jav/gui/wizard/newProject/Bundle").getString("NewProjectVisualPanel0.path"));
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
jfc.setFileFilter(new FileFilter() {
fileChooser.setDialogTitle(java.util.ResourceBundle.getBundle("jav/gui/wizard/newProject/Bundle").getString("NewProjectVisualPanel0.path"));
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory();
Expand All @@ -77,10 +76,11 @@ public String getDescription() {
}
});

if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
try {
File file = jfc.getSelectedFile();
File file = fileChooser.getSelectedFile();
jTextField1.setText(file.getCanonicalPath());
fileChooser.setCurrentDirectory(file);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
Expand Down Expand Up @@ -203,7 +203,8 @@ private void initComponents() {
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration//GEN-END:variables

private JFileChooser fileChooser;

@Override
public void insertUpdate(DocumentEvent e) {
if( jTextField1.getDocument() == e.getDocument()) {
Expand Down
19 changes: 10 additions & 9 deletions Wizards/src/jav/gui/wizard/newProject/NewProjectVisualPanel1.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public final class NewProjectVisualPanel1 extends JPanel implements DocumentList
/**
* Creates new form NewProjectVisualPanel1
*/
public NewProjectVisualPanel1() {
public NewProjectVisualPanel1(JFileChooser jfc) {
initComponents();

fileChooser = jfc;
Object[] encodings = Charset.availableCharsets().keySet().toArray();

jComboBox2.setModel(new DefaultComboBoxModel(encodings));
Expand All @@ -75,12 +75,11 @@ public NewProjectVisualPanel1() {

@Override
public void actionPerformed(ActionEvent e) {
JFileChooser jfc = new JFileChooser();
// AbstractButton button = SwingUtils.getDescendantOfType(AbstractButton.class, jfc, "Icon", UIManager.getIcon("FileChooser.detailsViewIcon"));
// button.doClick();
jfc.setDialogTitle(java.util.ResourceBundle.getBundle("jav/gui/wizard/newProject/Bundle").getString("ocr_input_dir"));
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
jfc.setFileFilter(new FileFilter() {
fileChooser.setDialogTitle(java.util.ResourceBundle.getBundle("jav/gui/wizard/newProject/Bundle").getString("ocr_input_dir"));
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setFileFilter(new FileFilter() {

@Override
public boolean accept(File f) {
Expand All @@ -93,10 +92,11 @@ public String getDescription() {
}
});

if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
try {
File file = jfc.getSelectedFile();
File file = fileChooser.getSelectedFile();
jTextField1.setText(file.getCanonicalPath());
fileChooser.setCurrentDirectory(file.getParentFile());
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
Expand Down Expand Up @@ -213,7 +213,8 @@ private void initComponents() {
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables

private JFileChooser fileChooser;

@Override
public void insertUpdate(DocumentEvent e) {
if (jTextField1.getDocument() == e.getDocument()) {
Expand Down
18 changes: 10 additions & 8 deletions Wizards/src/jav/gui/wizard/newProject/NewProjectVisualPanel2.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ public final class NewProjectVisualPanel2 extends JPanel implements DocumentList
public static final String PROP_IMG_DIRNAME = "IMGDIRName";

/** Creates new form NewProjectVisualPanel1 */
public NewProjectVisualPanel2() {
public NewProjectVisualPanel2(JFileChooser jfc) {
initComponents();
fileChooser = jfc;
jTextField1.setText("");
jTextField1.getDocument().addDocumentListener(this);

jButton1.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
JFileChooser jfc = new JFileChooser();
// AbstractButton button = SwingUtils.getDescendantOfType(AbstractButton.class, jfc, "Icon", UIManager.getIcon("FileChooser.detailsViewIcon"));
// button.doClick();
jfc.setDialogTitle(java.util.ResourceBundle.getBundle("jav/gui/wizard/newProject/Bundle").getString("tif_img_dir"));
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
jfc.setFileFilter(new FileFilter() {
fileChooser.setDialogTitle(java.util.ResourceBundle.getBundle("jav/gui/wizard/newProject/Bundle").getString("tif_img_dir"));
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setFileFilter(new FileFilter() {

@Override
public boolean accept(File f) {
Expand All @@ -75,10 +75,11 @@ public String getDescription() {
}
});

if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
try {
File file = jfc.getSelectedFile();
File file = fileChooser.getSelectedFile();
jTextField1.setText(file.getCanonicalPath());
fileChooser.setCurrentDirectory(file.getParentFile());
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
Expand Down Expand Up @@ -160,4 +161,5 @@ private void initComponents() {
private javax.swing.JButton jButton1;
private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables
}
private JFileChooser fileChooser;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFileChooser;
import org.openide.WizardDescriptor;
import org.openide.util.NbBundle;

Expand Down Expand Up @@ -38,19 +39,19 @@
* @author thorsten ([email protected])
*/
public class NewProjectWizardDescriptor extends WizardDescriptor {

private NewProjectWizardPanel0 panel0 = new NewProjectWizardPanel0();
private NewProjectWizardPanel1 panel1 = new NewProjectWizardPanel1();
private NewProjectWizardPanel2 panel2 = new NewProjectWizardPanel2();
private JFileChooser jfc = new JFileChooser();
private NewProjectWizardPanel0 panel0 = new NewProjectWizardPanel0(jfc);
private NewProjectWizardPanel1 panel1 = new NewProjectWizardPanel1(jfc);
private NewProjectWizardPanel2 panel2 = new NewProjectWizardPanel2(jfc);
// private NewProjectWizardPanel3 panel3 = new NewProjectWizardPanel3();

public NewProjectWizardDescriptor() {
List<Panel<WizardDescriptor>> panels = new ArrayList<Panel<WizardDescriptor>>();
List<Panel<WizardDescriptor>> panels = new ArrayList<>();
panels.add(panel0);
panels.add(panel1);
panels.add(panel2);
// panels.add(panel3);
this.setPanelsAndSettings(new ArrayIterator<WizardDescriptor>(panels), this);
this.setPanelsAndSettings(new ArrayIterator<>(panels), this);

// {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
this.setTitleFormat(new MessageFormat("{0}"));
Expand All @@ -61,4 +62,4 @@ public NewProjectWizardDescriptor() {
putProperty("WizardPanel_contentNumbered", Boolean.TRUE);
putProperty("WizardPanel_contentData", new String[]{panel0.getName(), panel1.getName(), panel2.getName()}); //, panel3.getName()});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Iterator;
import java.util.ResourceBundle;
import java.util.Set;
import javax.swing.JFileChooser;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.openide.NotifyDescriptor;
Expand Down Expand Up @@ -54,11 +55,16 @@ public class NewProjectWizardPanel0 implements WizardDescriptor.Panel<WizardDesc
private boolean isValid = false;
private ResourceBundle bundle = NbBundle.getBundle(NewProjectWizardPanel0.class);
private String completeProjectPath;
private JFileChooser fileChooser;

public NewProjectWizardPanel0(JFileChooser jfc) {
fileChooser = jfc;
}

@Override
public NewProjectVisualPanel0 getComponent() {
if (view == null) {
view = new NewProjectVisualPanel0();
view = new NewProjectVisualPanel0(fileChooser);
view.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(0));
view.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
view.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
Expand Down Expand Up @@ -171,4 +177,4 @@ public void propertyChange(PropertyChangeEvent event) {
fireChangeEvent(this, oldState, isValid);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Iterator;
import java.util.ResourceBundle;
import java.util.Set;
import javax.swing.JFileChooser;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.openide.WizardDescriptor;
Expand Down Expand Up @@ -54,15 +55,21 @@ public class NewProjectWizardPanel1 implements WizardDescriptor.Panel<WizardDesc
private WizardDescriptor model = null;
private boolean isValid = false;
private ResourceBundle bundle = NbBundle.getBundle(NewProjectWizardPanel1.class);
private JFileChooser fileChooser;

public NewProjectWizardPanel1(JFileChooser jfc) {
fileChooser = jfc;
}


// Get the visual component for the panel. In this template, the component
// is kept separate. This can be more efficient: if the wizard is created
// but never displayed, or not all panels are displayed, it is better to
// create only those which really need to be visible.
@Override
public NewProjectVisualPanel1 getComponent() {
if (view == null) {
view = new NewProjectVisualPanel1();
view = new NewProjectVisualPanel1(fileChooser);
view.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(1));
view.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
view.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Iterator;
import java.util.ResourceBundle;
import java.util.Set;
import javax.swing.JFileChooser;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.openide.WizardDescriptor;
Expand Down Expand Up @@ -54,15 +55,21 @@ public class NewProjectWizardPanel2 implements WizardDescriptor.FinishablePanel<
private WizardDescriptor model = null;
private boolean isValid = false;
private ResourceBundle bundle = NbBundle.getBundle(NewProjectWizardPanel2.class);
private JFileChooser fileChooser;

public NewProjectWizardPanel2(JFileChooser jfc) {
fileChooser = jfc;
}


// Get the visual component for the panel. In this template, the component
// is kept separate. This can be more efficient: if the wizard is created
// but never displayed, or not all panels are displayed, it is better to
// create only those which really need to be visible.
@Override
public NewProjectVisualPanel2 getComponent() {
if (view == null) {
view = new NewProjectVisualPanel2();
view = new NewProjectVisualPanel2(fileChooser);
view.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(2));
view.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
view.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
Expand Down Expand Up @@ -159,4 +166,4 @@ public void propertyChange(PropertyChangeEvent event) {
fireChangeEvent(this, oldState, isValid);
}
}
}
}

0 comments on commit 2bf538a

Please sign in to comment.