mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
fixed save and save as to update the title bar
This commit is contained in:
+5
-3
@@ -243,9 +243,11 @@ public class MainFrame extends JFrame implements IView {
|
|||||||
@Override
|
@Override
|
||||||
public void processMessage(EventType eventType, Object... params) {
|
public void processMessage(EventType eventType, Object... params) {
|
||||||
if (eventType == EventType.FILE_STATUS_CHANGED) {
|
if (eventType == EventType.FILE_STATUS_CHANGED) {
|
||||||
String fileName = plugInPort.getCurrentFileName() == null ? "Untitled" : plugInPort
|
String fileName = (String) params[0];
|
||||||
.getCurrentFileName();
|
if (fileName == null) {
|
||||||
String modified = plugInPort.isProjectModified() ? " (modified)" : "";
|
fileName = "Untitled";
|
||||||
|
}
|
||||||
|
String modified = (Boolean) params[1] ? " (modified)" : "";
|
||||||
setTitle(String.format("DIYLC %s alpha - %s %s", plugInPort.getCurrentVersionNumber(),
|
setTitle(String.format("DIYLC %s alpha - %s %s", plugInPort.getCurrentVersionNumber(),
|
||||||
fileName, modified));
|
fileName, modified));
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-37
@@ -2,15 +2,11 @@ package org.diylc.plugins.file;
|
|||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.diylc.common.EventType;
|
import org.diylc.common.EventType;
|
||||||
import org.diylc.common.IPlugIn;
|
import org.diylc.common.IPlugIn;
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
@@ -19,8 +15,6 @@ import org.diylc.images.IconLoader;
|
|||||||
|
|
||||||
import com.diyfever.gui.IDrawingProvider;
|
import com.diyfever.gui.IDrawingProvider;
|
||||||
import com.diyfever.gui.export.DrawingExporter;
|
import com.diyfever.gui.export.DrawingExporter;
|
||||||
import com.thoughtworks.xstream.XStream;
|
|
||||||
import com.thoughtworks.xstream.io.xml.DomDriver;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entry point class for File management utilities.
|
* Entry point class for File management utilities.
|
||||||
@@ -29,8 +23,6 @@ import com.thoughtworks.xstream.io.xml.DomDriver;
|
|||||||
*/
|
*/
|
||||||
public class FileManager implements IPlugIn {
|
public class FileManager implements IPlugIn {
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(FileManager.class);
|
|
||||||
|
|
||||||
private static final String FILE_TITLE = "File";
|
private static final String FILE_TITLE = "File";
|
||||||
private static final String TRACE_MASK_TITLE = "Trace Mask";
|
private static final String TRACE_MASK_TITLE = "Trace Mask";
|
||||||
|
|
||||||
@@ -38,8 +30,6 @@ public class FileManager implements IPlugIn {
|
|||||||
private ProjectDrawingProvider drawingProvider;
|
private ProjectDrawingProvider drawingProvider;
|
||||||
private TraceMaskDrawingProvider traceMaskDrawingProvider;
|
private TraceMaskDrawingProvider traceMaskDrawingProvider;
|
||||||
|
|
||||||
private XStream xStream = new XStream(new DomDriver());
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(IPlugInPort plugInPort) {
|
public void connect(IPlugInPort plugInPort) {
|
||||||
this.plugInPort = plugInPort;
|
this.plugInPort = plugInPort;
|
||||||
@@ -119,22 +109,15 @@ public class FileManager implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.DIY.getFilter(),
|
if (plugInPort.getCurrentFileName() == null) {
|
||||||
null, FileFilterEnum.DIY.getExtensions()[0], new ProjectPreview());
|
File file = DialogFactory.getInstance().showSaveDialog(
|
||||||
|
FileFilterEnum.DIY.getFilter(), null,
|
||||||
|
FileFilterEnum.DIY.getExtensions()[0], new ProjectPreview());
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
LOG.info("Saving project to file.");
|
plugInPort.saveProjectToFile(file.getAbsolutePath());
|
||||||
FileOutputStream fos;
|
|
||||||
try {
|
|
||||||
fos = new FileOutputStream(file);
|
|
||||||
xStream.toXML(plugInPort.getCurrentProject(), fos);
|
|
||||||
fos.close();
|
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
ex.printStackTrace();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
plugInPort.saveProjectToFile(plugInPort.getCurrentFileName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,19 +137,7 @@ public class FileManager implements IPlugIn {
|
|||||||
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.DIY.getFilter(),
|
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.DIY.getFilter(),
|
||||||
null, FileFilterEnum.DIY.getExtensions()[0], new ProjectPreview());
|
null, FileFilterEnum.DIY.getExtensions()[0], new ProjectPreview());
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
LOG.info("Saving project to file.");
|
plugInPort.saveProjectToFile(file.getAbsolutePath());
|
||||||
FileOutputStream fos;
|
|
||||||
try {
|
|
||||||
fos = new FileOutputStream(file);
|
|
||||||
xStream.toXML(plugInPort.getCurrentProject(), fos);
|
|
||||||
fos.close();
|
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
ex.printStackTrace();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user