You can now directly edit shader node's code inside the shader node editor and benefit from a live reload feature of the shader.
parent
a047376d70
commit
576e18b376
@ -0,0 +1,5 @@ |
||||
ShaderEditPanel.closeButton.text= |
||||
ShaderEditPanel.shaderEditorPane.text= |
||||
ShaderEditPanel.closeButton.toolTipText=Close this panel |
||||
ShaderEditPanel.jToggleButton1.text=jToggleButton1 |
||||
ShaderEditPanel.headerText.text=jLabel1 |
@ -0,0 +1,162 @@ |
||||
<?xml version="1.0" encoding="UTF-8" ?> |
||||
|
||||
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> |
||||
<NonVisualComponents> |
||||
<Component class="javax.swing.ButtonGroup" name="buttonGroup1"> |
||||
</Component> |
||||
</NonVisualComponents> |
||||
<AuxValues> |
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/> |
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> |
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> |
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/> |
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/> |
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> |
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> |
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> |
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> |
||||
</AuxValues> |
||||
|
||||
<Layout> |
||||
<DimensionLayout dim="0"> |
||||
<Group type="103" groupAlignment="0" attributes="0"> |
||||
<Component id="header" alignment="0" max="32767" attributes="0"/> |
||||
<Component id="jScrollPane1" alignment="0" pref="645" max="32767" attributes="0"/> |
||||
<Group type="102" alignment="1" attributes="0"> |
||||
<Component id="buttonPanel" max="32767" attributes="0"/> |
||||
<EmptySpace max="-2" attributes="0"/> |
||||
</Group> |
||||
</Group> |
||||
</DimensionLayout> |
||||
<DimensionLayout dim="1"> |
||||
<Group type="103" groupAlignment="0" attributes="0"> |
||||
<Group type="102" alignment="1" attributes="0"> |
||||
<Component id="header" min="-2" max="-2" attributes="0"/> |
||||
<EmptySpace max="-2" attributes="0"/> |
||||
<Component id="buttonPanel" min="-2" pref="21" max="-2" attributes="0"/> |
||||
<EmptySpace max="-2" attributes="0"/> |
||||
<Component id="jScrollPane1" pref="492" max="32767" attributes="0"/> |
||||
</Group> |
||||
</Group> |
||||
</DimensionLayout> |
||||
</Layout> |
||||
<SubComponents> |
||||
<Container class="javax.swing.JScrollPane" name="jScrollPane1"> |
||||
<Properties> |
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> |
||||
<Dimension value="[0, 0]"/> |
||||
</Property> |
||||
</Properties> |
||||
<AuxValues> |
||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> |
||||
</AuxValues> |
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> |
||||
<SubComponents> |
||||
<Component class="javax.swing.JEditorPane" name="shaderEditorPane"> |
||||
<Properties> |
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> |
||||
<Border info="null"/> |
||||
</Property> |
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> |
||||
<ResourceString bundle="com/jme3/gde/materialdefinition/editor/Bundle.properties" key="ShaderEditPanel.shaderEditorPane.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> |
||||
</Property> |
||||
</Properties> |
||||
</Component> |
||||
</SubComponents> |
||||
</Container> |
||||
<Container class="javax.swing.JPanel" name="header"> |
||||
<Properties> |
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> |
||||
<Color blue="d1" green="b4" id="Active Caption" palette="2" red="99" type="palette"/> |
||||
</Property> |
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> |
||||
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo"> |
||||
<EtchetBorder/> |
||||
</Border> |
||||
</Property> |
||||
</Properties> |
||||
|
||||
<Layout> |
||||
<DimensionLayout dim="0"> |
||||
<Group type="103" groupAlignment="0" attributes="0"> |
||||
<Group type="102" alignment="0" attributes="0"> |
||||
<Component id="headerText" max="32767" attributes="0"/> |
||||
<EmptySpace max="-2" attributes="0"/> |
||||
<Component id="closeButton" min="-2" max="-2" attributes="0"/> |
||||
</Group> |
||||
</Group> |
||||
</DimensionLayout> |
||||
<DimensionLayout dim="1"> |
||||
<Group type="103" groupAlignment="0" attributes="0"> |
||||
<Group type="103" alignment="0" groupAlignment="3" attributes="0"> |
||||
<Component id="headerText" alignment="3" min="-2" pref="19" max="-2" attributes="0"/> |
||||
<Component id="closeButton" alignment="3" min="-2" pref="19" max="-2" attributes="0"/> |
||||
</Group> |
||||
</Group> |
||||
</DimensionLayout> |
||||
</Layout> |
||||
<SubComponents> |
||||
<Component class="javax.swing.JLabel" name="headerText"> |
||||
<Properties> |
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> |
||||
<Font name="Tahoma" size="11" style="1"/> |
||||
</Property> |
||||
<Property name="horizontalAlignment" type="int" value="0"/> |
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"> |
||||
<Image iconType="3" name="/com/jme3/gde/materialdefinition/icons/fragment.png"/> |
||||
</Property> |
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> |
||||
<ResourceString bundle="com/jme3/gde/materialdefinition/editor/Bundle.properties" key="ShaderEditPanel.headerText.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> |
||||
</Property> |
||||
</Properties> |
||||
</Component> |
||||
<Component class="javax.swing.JButton" name="closeButton"> |
||||
<Properties> |
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> |
||||
<Color blue="d1" green="b4" id="Active Caption" palette="2" red="99" type="palette"/> |
||||
</Property> |
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> |
||||
<Font name="Tahoma" size="8" style="1"/> |
||||
</Property> |
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"> |
||||
<Image iconType="3" name="/com/jme3/gde/materialdefinition/icons/out.png"/> |
||||
</Property> |
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> |
||||
<ResourceString bundle="com/jme3/gde/materialdefinition/editor/Bundle.properties" key="ShaderEditPanel.closeButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> |
||||
</Property> |
||||
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> |
||||
<ResourceString bundle="com/jme3/gde/materialdefinition/editor/Bundle.properties" key="ShaderEditPanel.closeButton.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> |
||||
</Property> |
||||
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor"> |
||||
<Insets value="[0, 0, 0, 0]"/> |
||||
</Property> |
||||
</Properties> |
||||
<Events> |
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="closeButtonActionPerformed"/> |
||||
</Events> |
||||
</Component> |
||||
</SubComponents> |
||||
</Container> |
||||
<Container class="javax.swing.JPanel" name="buttonPanel"> |
||||
<Properties> |
||||
<Property name="alignmentX" type="float" value="0.0"/> |
||||
<Property name="alignmentY" type="float" value="0.0"/> |
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> |
||||
<Dimension value="[73, 29]"/> |
||||
</Property> |
||||
</Properties> |
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/> |
||||
<SubComponents> |
||||
<Component class="javax.swing.JToggleButton" name="jToggleButton1"> |
||||
<Properties> |
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> |
||||
<ResourceString bundle="com/jme3/gde/materialdefinition/editor/Bundle.properties" key="ShaderEditPanel.jToggleButton1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> |
||||
</Property> |
||||
</Properties> |
||||
</Component> |
||||
</SubComponents> |
||||
</Container> |
||||
</SubComponents> |
||||
</Form> |
@ -0,0 +1,244 @@ |
||||
/* |
||||
* To change this license header, choose License Headers in Project Properties. |
||||
* To change this template file, choose Tools | Templates |
||||
* and open the template in the editor. |
||||
*/ |
||||
package com.jme3.gde.materialdefinition.editor; |
||||
|
||||
import com.jme3.gde.materialdefinition.icons.Icons; |
||||
import com.jme3.shader.Shader; |
||||
import java.awt.Component; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.KeyEvent; |
||||
import java.awt.event.KeyListener; |
||||
import java.beans.PropertyChangeEvent; |
||||
import java.beans.PropertyChangeListener; |
||||
import java.io.IOException; |
||||
import java.io.OutputStreamWriter; |
||||
import java.util.List; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.JToggleButton; |
||||
import javax.swing.text.EditorKit; |
||||
import org.openide.filesystems.FileObject; |
||||
import org.openide.loaders.DataObject; |
||||
import org.openide.loaders.DataObjectNotFoundException; |
||||
import org.openide.text.CloneableEditorSupport; |
||||
import org.openide.util.Exceptions; |
||||
|
||||
/** |
||||
* |
||||
* @author Nehon |
||||
*/ |
||||
public class ShaderEditPanel extends JPanel { |
||||
|
||||
private DataObject currentDataObject = null; |
||||
private MatDefEditorlElement parent = null; |
||||
|
||||
/** |
||||
* Creates new form ShaderEditPanel |
||||
*/ |
||||
public ShaderEditPanel() { |
||||
initComponents(); |
||||
String mime = "text/x-glsl"; |
||||
EditorKit ek = CloneableEditorSupport.getEditorKit(mime); |
||||
shaderEditorPane.setEditorKit(ek); |
||||
shaderEditorPane.setContentType(mime); |
||||
shaderEditorPane.addKeyListener(new KeyListener() { |
||||
|
||||
public void keyTyped(KeyEvent e) { |
||||
currentDataObject.setModified(true); |
||||
} |
||||
|
||||
public void keyPressed(KeyEvent e) { |
||||
if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { |
||||
saveCurrent(); |
||||
} |
||||
} |
||||
|
||||
public void keyReleased(KeyEvent e) { |
||||
} |
||||
}); |
||||
} |
||||
|
||||
public void setParent(MatDefEditorlElement parent) { |
||||
this.parent = parent; |
||||
} |
||||
|
||||
public void setFiles(String title, NodePanel.NodeType type, List<FileObject> fos) { |
||||
|
||||
headerText.setText(title); |
||||
headerText.setIcon(Icons.getIconForShaderType(type)); |
||||
boolean firstItem = true; |
||||
for (Component component : buttonPanel.getComponents()) { |
||||
buttonGroup1.remove((JToggleButton) component); |
||||
} |
||||
buttonPanel.removeAll(); |
||||
buttonPanel.repaint(); |
||||
|
||||
for (FileObject fo : fos) { |
||||
final Tab b = new Tab(); |
||||
b.setText(fo.getNameExt()); |
||||
buttonGroup1.add(b); |
||||
try { |
||||
b.dataObject = DataObject.find(fo); |
||||
b.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
saveCurrent(); |
||||
try { |
||||
shaderEditorPane.setText(b.dataObject.getPrimaryFile().asText()); |
||||
} catch (IOException ex) { |
||||
Exceptions.printStackTrace(ex); |
||||
} |
||||
currentDataObject = b.dataObject; |
||||
} |
||||
|
||||
}); |
||||
if (firstItem) { |
||||
shaderEditorPane.setText(fo.asText()); |
||||
currentDataObject = b.dataObject; |
||||
b.setSelected(true); |
||||
firstItem = false; |
||||
} |
||||
} catch (IOException ex) { |
||||
Exceptions.printStackTrace(ex); |
||||
} |
||||
|
||||
buttonPanel.add(b); |
||||
} |
||||
|
||||
} |
||||
|
||||
public void saveCurrent() { |
||||
if (currentDataObject != null && currentDataObject.isModified()) { |
||||
try { |
||||
OutputStreamWriter out = new OutputStreamWriter(currentDataObject.getPrimaryFile().getOutputStream()); |
||||
out.write(shaderEditorPane.getText(), 0, shaderEditorPane.getText().length()); |
||||
out.close(); |
||||
currentDataObject.setModified(false); |
||||
if(currentDataObject.getPrimaryFile().getExt().equalsIgnoreCase("j3sn")){ |
||||
parent.reload(); |
||||
} |
||||
parent.refresh(); |
||||
} catch (DataObjectNotFoundException ex) { |
||||
Exceptions.printStackTrace(ex); |
||||
} catch (IOException ex) { |
||||
Exceptions.printStackTrace(ex); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private class Tab extends JToggleButton { |
||||
|
||||
DataObject dataObject; |
||||
} |
||||
|
||||
/** |
||||
* 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. |
||||
*/ |
||||
@SuppressWarnings("unchecked") |
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() { |
||||
|
||||
buttonGroup1 = new javax.swing.ButtonGroup(); |
||||
jScrollPane1 = new javax.swing.JScrollPane(); |
||||
shaderEditorPane = new javax.swing.JEditorPane(); |
||||
header = new javax.swing.JPanel(); |
||||
headerText = new javax.swing.JLabel(); |
||||
closeButton = new javax.swing.JButton(); |
||||
buttonPanel = new javax.swing.JPanel(); |
||||
jToggleButton1 = new javax.swing.JToggleButton(); |
||||
|
||||
jScrollPane1.setMinimumSize(new java.awt.Dimension(0, 0)); |
||||
|
||||
shaderEditorPane.setBorder(null); |
||||
shaderEditorPane.setText(org.openide.util.NbBundle.getMessage(ShaderEditPanel.class, "ShaderEditPanel.shaderEditorPane.text")); // NOI18N
|
||||
jScrollPane1.setViewportView(shaderEditorPane); |
||||
|
||||
header.setBackground(java.awt.SystemColor.activeCaption); |
||||
header.setBorder(javax.swing.BorderFactory.createEtchedBorder()); |
||||
|
||||
headerText.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
|
||||
headerText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); |
||||
headerText.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jme3/gde/materialdefinition/icons/fragment.png"))); // NOI18N
|
||||
org.openide.awt.Mnemonics.setLocalizedText(headerText, org.openide.util.NbBundle.getMessage(ShaderEditPanel.class, "ShaderEditPanel.headerText.text")); // NOI18N
|
||||
|
||||
closeButton.setBackground(java.awt.SystemColor.activeCaption); |
||||
closeButton.setFont(new java.awt.Font("Tahoma", 1, 8)); // NOI18N
|
||||
closeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jme3/gde/materialdefinition/icons/out.png"))); // NOI18N
|
||||
org.openide.awt.Mnemonics.setLocalizedText(closeButton, org.openide.util.NbBundle.getMessage(ShaderEditPanel.class, "ShaderEditPanel.closeButton.text")); // NOI18N
|
||||
closeButton.setToolTipText(org.openide.util.NbBundle.getMessage(ShaderEditPanel.class, "ShaderEditPanel.closeButton.toolTipText")); // NOI18N
|
||||
closeButton.setMargin(new java.awt.Insets(0, 0, 0, 0)); |
||||
closeButton.addActionListener(new java.awt.event.ActionListener() { |
||||
public void actionPerformed(java.awt.event.ActionEvent evt) { |
||||
closeButtonActionPerformed(evt); |
||||
} |
||||
}); |
||||
|
||||
javax.swing.GroupLayout headerLayout = new javax.swing.GroupLayout(header); |
||||
header.setLayout(headerLayout); |
||||
headerLayout.setHorizontalGroup( |
||||
headerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
||||
.addGroup(headerLayout.createSequentialGroup() |
||||
.addComponent(headerText, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
||||
.addComponent(closeButton)) |
||||
); |
||||
headerLayout.setVerticalGroup( |
||||
headerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
||||
.addGroup(headerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
||||
.addComponent(headerText, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE) |
||||
.addComponent(closeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)) |
||||
); |
||||
|
||||
buttonPanel.setAlignmentX(0.0F); |
||||
buttonPanel.setAlignmentY(0.0F); |
||||
buttonPanel.setPreferredSize(new java.awt.Dimension(73, 29)); |
||||
buttonPanel.setLayout(new javax.swing.BoxLayout(buttonPanel, javax.swing.BoxLayout.LINE_AXIS)); |
||||
|
||||
org.openide.awt.Mnemonics.setLocalizedText(jToggleButton1, org.openide.util.NbBundle.getMessage(ShaderEditPanel.class, "ShaderEditPanel.jToggleButton1.text")); // NOI18N
|
||||
buttonPanel.add(jToggleButton1); |
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); |
||||
this.setLayout(layout); |
||||
layout.setHorizontalGroup( |
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
||||
.addComponent(header, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 645, Short.MAX_VALUE) |
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() |
||||
.addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
||||
.addContainerGap()) |
||||
); |
||||
layout.setVerticalGroup( |
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() |
||||
.addComponent(header, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) |
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
||||
.addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE) |
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE)) |
||||
); |
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
|
||||
setVisible(false); |
||||
|
||||
saveCurrent(); |
||||
|
||||
|
||||
}//GEN-LAST:event_closeButtonActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.ButtonGroup buttonGroup1; |
||||
private javax.swing.JPanel buttonPanel; |
||||
private javax.swing.JButton closeButton; |
||||
private javax.swing.JPanel header; |
||||
private javax.swing.JLabel headerText; |
||||
private javax.swing.JScrollPane jScrollPane1; |
||||
private javax.swing.JToggleButton jToggleButton1; |
||||
private javax.swing.JEditorPane shaderEditorPane; |
||||
// End of variables declaration//GEN-END:variables
|
||||
} |
After Width: | Height: | Size: 47 KiB |
Loading…
Reference in new issue