Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions jme3-templates/src/com/jme3/gde/templates/FileUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.jme3.gde.templates;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.Exceptions;
import org.openide.xml.XMLUtil;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
*
* @author rickard
*/
public class FileUtils {

public static void unZipFile(InputStream source, FileObject projectRoot) throws IOException {
try (source) {
ZipInputStream str = new ZipInputStream(source);
ZipEntry entry;
while ((entry = str.getNextEntry()) != null) {
if (entry.isDirectory()) {
FileUtil.createFolder(projectRoot, entry.getName());
} else {
FileObject fo = FileUtil.createData(projectRoot, entry.getName());
if ("nbproject/project.xml".equals(entry.getName())) {
// Special handling for setting name of Ant-based projects; customize as needed:
filterProjectXML(fo, str, projectRoot.getName());
} else {
writeFile(str, fo);
}
}
}
}
}

private static void writeFile(ZipInputStream str, FileObject fo) throws IOException {
try (OutputStream out = fo.getOutputStream()) {
FileUtil.copy(str, out);
}
}

private static void filterProjectXML(FileObject fo, ZipInputStream str, String name) throws IOException {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileUtil.copy(str, baos);
Document doc = XMLUtil.parse(new InputSource(new ByteArrayInputStream(baos.toByteArray())), false, false, null, null);
NodeList nl = doc.getDocumentElement().getElementsByTagName("name");
if (nl != null) {
for (int i = 0; i < nl.getLength(); i++) {
Element el = (Element) nl.item(i);
if (el.getParentNode() != null && "data".equals(el.getParentNode().getNodeName())) {
NodeList nl2 = el.getChildNodes();
if (nl2.getLength() > 0) {
nl2.item(0).setNodeValue(name);
}
break;
}
}
}
try (OutputStream out = fo.getOutputStream()) {
XMLUtil.write(doc, out, "UTF-8");
}
} catch (IOException | DOMException | SAXException ex) {
Exceptions.printStackTrace(ex);
writeFile(str, fo);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2010 jMonkeyEngine
* Copyright (c) 2009-2025 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -31,20 +31,15 @@
*/
package com.jme3.gde.templates.basic;

import com.jme3.gde.templates.FileUtils;
import java.awt.Component;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.MessageFormat;
import java.util.Enumeration;
import java.util.LinkedHashSet;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.JComponent;
import javax.swing.event.ChangeListener;
import org.netbeans.api.project.ProjectManager;
Expand All @@ -53,13 +48,7 @@
import org.openide.WizardDescriptor;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.openide.xml.XMLUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

@SuppressWarnings({"unchecked", "rawtypes"})
public class BasicGameWizardIterator implements WizardDescriptor./*Progress*/InstantiatingIterator {
Expand Down Expand Up @@ -94,7 +83,7 @@ private String[] createSteps() {

FileObject template = Templates.getTemplate(wiz);
FileObject dir = FileUtil.toFileObject(dirF);
unZipFile(template.getInputStream(), dir);
FileUtils.unZipFile(template.getInputStream(), dir);

// Always open top dir as a project:
resultSet.add(dir);
Expand Down Expand Up @@ -130,9 +119,7 @@ public void initialize(WizardDescriptor wiz) {
// chooser to appear in the list of steps.
steps[i] = c.getName();
}
if (c instanceof JComponent) { // assume Swing components
JComponent jc = (JComponent) c;
// Step #.
if (c instanceof JComponent jc) {
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i);
// Step name (actually the whole list for reference).
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps);
Expand Down Expand Up @@ -194,57 +181,4 @@ public final void addChangeListener(ChangeListener l) {
public final void removeChangeListener(ChangeListener l) {
}

private static void unZipFile(InputStream source, FileObject projectRoot) throws IOException {
try (source) {
ZipInputStream str = new ZipInputStream(source);
ZipEntry entry;
while ((entry = str.getNextEntry()) != null) {
if (entry.isDirectory()) {
FileUtil.createFolder(projectRoot, entry.getName());
} else {
FileObject fo = FileUtil.createData(projectRoot, entry.getName());
if ("nbproject/project.xml".equals(entry.getName())) {
// Special handling for setting name of Ant-based projects; customize as needed:
filterProjectXML(fo, str, projectRoot.getName());
} else {
writeFile(str, fo);
}
}
}
}
}

private static void writeFile(ZipInputStream str, FileObject fo) throws IOException {
try (OutputStream out = fo.getOutputStream()) {
FileUtil.copy(str, out);
}
}

private static void filterProjectXML(FileObject fo, ZipInputStream str, String name) throws IOException {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileUtil.copy(str, baos);
Document doc = XMLUtil.parse(new InputSource(new ByteArrayInputStream(baos.toByteArray())), false, false, null, null);
NodeList nl = doc.getDocumentElement().getElementsByTagName("name");
if (nl != null) {
for (int i = 0; i < nl.getLength(); i++) {
Element el = (Element) nl.item(i);
if (el.getParentNode() != null && "data".equals(el.getParentNode().getNodeName())) {
NodeList nl2 = el.getChildNodes();
if (nl2.getLength() > 0) {
nl2.item(0).setNodeValue(name);
}
break;
}
}
}
try (OutputStream out = fo.getOutputStream()) {
XMLUtil.write(doc, out, "UTF-8");
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
writeFile(str, fo);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.jme3.gde.templates.downloadedproject;


/**
*
* @author rickard
*/
public class Config {

private static final String PROJECT_NAME = "JaimesAscent";
private static final String GITHUB_REF = "JaimesAscent-1.1.1/";
private static final String ZIP_NAME = "JaimesAscent.zip";
private static final String GITHUB_PATH = "https://github.com/neph1/JaimesAscent/archive/refs/tags/v1.1.1.zip";



public String getProjectName() {
return PROJECT_NAME;
}

public String getGithubRef() {
return GITHUB_REF;
}

public String getZipName() {
return ZIP_NAME;
}

public String getGithubPath() {
return GITHUB_PATH;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<ComponentRef name="projectNameTextField"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/templates/monkeyzone/Bundle.properties" key="JaimesAscentPanelVisual.projectNameLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
<ResourceString bundle="com/jme3/gde/templates/monkeyzone/Bundle.properties" key="ExampleProjectPanelVisual.projectNameLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<AuxValues>
Expand All @@ -81,7 +81,7 @@
<ComponentRef name="projectLocationTextField"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/templates/monkeyzone/Bundle.properties" key="JaimesAscentPanelVisual.projectLocationLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
<ResourceString bundle="com/jme3/gde/templates/monkeyzone/Bundle.properties" key="ExampleProjectPanelVisual.projectLocationLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<AuxValues>
Expand All @@ -93,10 +93,10 @@
<Component class="javax.swing.JButton" name="browseButton">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/templates/monkeyzone/Bundle.properties" key="JaimesAscentPanelVisual.browseButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
<ResourceString bundle="com/jme3/gde/templates/monkeyzone/Bundle.properties" key="ExampleProjectPanelVisual.browseButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="actionCommand" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/templates/monkeyzone/Bundle.properties" key="JaimesAscentPanelVisual.browseButton.actionCommand" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
<ResourceString bundle="com/jme3/gde/templates/monkeyzone/Bundle.properties" key="ExampleProjectPanelVisual.browseButton.actionCommand" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
Expand All @@ -109,7 +109,7 @@
<ComponentRef name="createdFolderTextField"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/templates/monkeyzone/Bundle.properties" key="JaimesAscentPanelVisual.createdFolderLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
<ResourceString bundle="com/jme3/gde/templates/monkeyzone/Bundle.properties" key="ExampleProjectPanelVisual.createdFolderLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.gde.templates.jaimesascent;
package com.jme3.gde.templates.downloadedproject;

import java.io.File;
import javax.swing.JFileChooser;
Expand All @@ -42,14 +42,15 @@
import org.openide.WizardValidationException;
import org.openide.filesystems.FileUtil;

public class JaimesAscentPanelVisual extends JPanel implements DocumentListener {
public class ExampleProjectPanelVisual extends JPanel implements DocumentListener {

public static final String PROP_PROJECT_NAME = "projectName";
static final String PROJECT_NAME = "JaimesAscent";
private final JaimesAscentWizardPanel panel;
private final ExampleProjectWizardPanel panel;
private final Config config;

public JaimesAscentPanelVisual(JaimesAscentWizardPanel panel) {
public ExampleProjectPanelVisual(ExampleProjectWizardPanel panel, Config config) {
initComponents();
this.config = config;
this.panel = panel;
// Register listener on the textFields to make the automatic updates
projectNameTextField.getDocument().addDocumentListener(this);
Expand Down Expand Up @@ -77,21 +78,21 @@ private void initComponents() {
createdFolderTextField = new javax.swing.JTextField();

projectNameLabel.setLabelFor(projectNameTextField);
org.openide.awt.Mnemonics.setLocalizedText(projectNameLabel, org.openide.util.NbBundle.getMessage(JaimesAscentPanelVisual.class, "JaimesAscentPanelVisual.projectNameLabel.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(projectNameLabel, org.openide.util.NbBundle.getMessage(ExampleProjectPanelVisual.class, "ExampleProjectPanelVisual.projectNameLabel.text")); // NOI18N

projectLocationLabel.setLabelFor(projectLocationTextField);
org.openide.awt.Mnemonics.setLocalizedText(projectLocationLabel, org.openide.util.NbBundle.getMessage(JaimesAscentPanelVisual.class, "JaimesAscentPanelVisual.projectLocationLabel.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(projectLocationLabel, org.openide.util.NbBundle.getMessage(ExampleProjectPanelVisual.class, "ExampleProjectPanelVisual.projectLocationLabel.text")); // NOI18N

org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(JaimesAscentPanelVisual.class, "JaimesAscentPanelVisual.browseButton.text")); // NOI18N
browseButton.setActionCommand(org.openide.util.NbBundle.getMessage(JaimesAscentPanelVisual.class, "JaimesAscentPanelVisual.browseButton.actionCommand")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(ExampleProjectPanelVisual.class, "ExampleProjectPanelVisual.browseButton.text")); // NOI18N
browseButton.setActionCommand(org.openide.util.NbBundle.getMessage(ExampleProjectPanelVisual.class, "ExampleProjectPanelVisual.browseButton.actionCommand")); // NOI18N
browseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
browseButtonActionPerformed(evt);
}
});

createdFolderLabel.setLabelFor(createdFolderTextField);
org.openide.awt.Mnemonics.setLocalizedText(createdFolderLabel, org.openide.util.NbBundle.getMessage(JaimesAscentPanelVisual.class, "JaimesAscentPanelVisual.createdFolderLabel.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(createdFolderLabel, org.openide.util.NbBundle.getMessage(ExampleProjectPanelVisual.class, "ExampleProjectPanelVisual.createdFolderLabel.text")); // NOI18N

createdFolderTextField.setEditable(false);

Expand Down Expand Up @@ -235,7 +236,7 @@ void read(WizardDescriptor settings) {

String projectName = (String) settings.getProperty("name");
if (projectName == null) {
projectName = PROJECT_NAME;
projectName = config.getProjectName();
}
this.projectNameTextField.setText(projectName);
this.projectNameTextField.selectAll();
Expand Down
Loading
Loading