Proper save handling for the shader editor.

experimental
Nehon 10 years ago
parent 3a61032575
commit 06e9618a4b
  1. 6
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ShaderEditPanel.form
  2. 30
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ShaderEditPanel.java

@ -67,9 +67,6 @@
</Container> </Container>
<Container class="javax.swing.JPanel" name="header"> <Container class="javax.swing.JPanel" name="header">
<Properties> <Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="66" green="66" id="TabbedPane.focus" palette="3" red="66" type="palette"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo"> <Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
<EtchetBorder/> <EtchetBorder/>
@ -99,9 +96,6 @@
<SubComponents> <SubComponents>
<Component class="javax.swing.JLabel" name="headerText"> <Component class="javax.swing.JLabel" name="headerText">
<Properties> <Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="66" green="66" id="TabbedPane.focus" palette="3" red="66" type="palette"/>
</Property>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="11" style="1"/> <Font name="Tahoma" size="11" style="1"/>
</Property> </Property>

@ -12,11 +12,12 @@ import java.awt.event.ActionListener;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.List; import java.util.List;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JToggleButton; import javax.swing.JToggleButton;
import javax.swing.text.EditorKit; import javax.swing.text.EditorKit;
import org.openide.cookies.EditorCookie;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject; import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject; import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException; import org.openide.loaders.DataObjectNotFoundException;
@ -41,21 +42,20 @@ public class ShaderEditPanel extends JPanel {
EditorKit ek = CloneableEditorSupport.getEditorKit(mime); EditorKit ek = CloneableEditorSupport.getEditorKit(mime);
shaderEditorPane.setEditorKit(ek); shaderEditorPane.setEditorKit(ek);
shaderEditorPane.setContentType(mime); shaderEditorPane.setContentType(mime);
shaderEditorPane.addKeyListener(new KeyListener() { shaderEditorPane.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {
currentDataObject.setModified(true);
} }
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
saveCurrent(); saveCurrent();
} }
} }
public void keyReleased(KeyEvent e) {
}
}); });
} }
@ -84,7 +84,7 @@ public class ShaderEditPanel extends JPanel {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
saveCurrent(); saveCurrent();
try { try {
shaderEditorPane.setText(b.dataObject.getPrimaryFile().asText()); shaderEditorPane.setDocument(b.dataObject.getLookup().lookup(EditorCookie.class).openDocument());
} catch (IOException ex) { } catch (IOException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
} }
@ -93,7 +93,7 @@ public class ShaderEditPanel extends JPanel {
}); });
if (firstItem) { if (firstItem) {
shaderEditorPane.setText(fo.asText()); shaderEditorPane.setDocument(b.dataObject.getLookup().lookup(EditorCookie.class).openDocument());
currentDataObject = b.dataObject; currentDataObject = b.dataObject;
b.setSelected(true); b.setSelected(true);
firstItem = false; firstItem = false;
@ -109,10 +109,10 @@ public class ShaderEditPanel extends JPanel {
public void saveCurrent() { public void saveCurrent() {
if (currentDataObject != null && currentDataObject.isModified()) { if (currentDataObject != null && currentDataObject.isModified()) {
FileLock lock = null;
try { try {
OutputStreamWriter out = new OutputStreamWriter(currentDataObject.getPrimaryFile().getOutputStream()); currentDataObject.getLookup().lookup(EditorCookie.class).saveDocument();
out.write(shaderEditorPane.getText(), 0, shaderEditorPane.getText().length());
out.close();
currentDataObject.setModified(false); currentDataObject.setModified(false);
if(currentDataObject.getPrimaryFile().getExt().equalsIgnoreCase("j3sn")){ if(currentDataObject.getPrimaryFile().getExt().equalsIgnoreCase("j3sn")){
parent.reload(); parent.reload();
@ -122,6 +122,10 @@ public class ShaderEditPanel extends JPanel {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
} catch (IOException ex) { } catch (IOException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
}finally{
if (lock!=null){
lock.releaseLock();
}
} }
} }
} }
@ -155,10 +159,8 @@ public class ShaderEditPanel extends JPanel {
shaderEditorPane.setText(org.openide.util.NbBundle.getMessage(ShaderEditPanel.class, "ShaderEditPanel.shaderEditorPane.text")); // NOI18N shaderEditorPane.setText(org.openide.util.NbBundle.getMessage(ShaderEditPanel.class, "ShaderEditPanel.shaderEditorPane.text")); // NOI18N
jScrollPane1.setViewportView(shaderEditorPane); jScrollPane1.setViewportView(shaderEditorPane);
header.setBackground(javax.swing.UIManager.getDefaults().getColor("TabbedPane.focus"));
header.setBorder(javax.swing.BorderFactory.createEtchedBorder()); header.setBorder(javax.swing.BorderFactory.createEtchedBorder());
headerText.setBackground(javax.swing.UIManager.getDefaults().getColor("TabbedPane.focus"));
headerText.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N headerText.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
headerText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); headerText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
headerText.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jme3/gde/materialdefinition/icons/fragment.png"))); // NOI18N headerText.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jme3/gde/materialdefinition/icons/fragment.png"))); // NOI18N

Loading…
Cancel
Save