use of java.awt.FileDialog in project megameklab by MegaMek.
the class MenuBarCreator method jMenuSaveAsEntity_actionPerformed.
public void jMenuSaveAsEntity_actionPerformed(ActionEvent event) {
if (UnitUtil.validateUnit(parentFrame.getEntity()).length() > 0) {
JOptionPane.showMessageDialog(parentFrame, "Warning: Saving an invalid unit, it might load incorrectly!");
}
UnitUtil.compactCriticals(parentFrame.getEntity());
FileDialog fDialog = new FileDialog(parentFrame, "Save As", FileDialog.SAVE);
String filePathName = CConfig.getParam(CConfig.CONFIG_SAVE_LOC);
fDialog.setDirectory(filePathName);
fDialog.setFile(parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel() + (parentFrame.getEntity() instanceof Mech ? ".mtf" : ".blk"));
fDialog.setLocationRelativeTo(parentFrame);
fDialog.setVisible(true);
if (fDialog.getFile() != null) {
filePathName = fDialog.getDirectory() + fDialog.getFile();
CConfig.setParam(CConfig.CONFIG_SAVE_LOC, fDialog.getDirectory());
} else {
return;
}
try {
if (parentFrame.getEntity() instanceof Mech) {
FileOutputStream out = new FileOutputStream(filePathName);
PrintStream p = new PrintStream(out);
p.println(((Mech) parentFrame.getEntity()).getMtf());
p.close();
out.close();
} else {
BLKFile.encode(filePathName, parentFrame.getEntity());
}
CConfig.updateSaveFiles(filePathName);
} catch (Exception ex) {
ex.printStackTrace();
}
JOptionPane.showMessageDialog(parentFrame, parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel() + " saved to " + filePathName);
}
use of java.awt.FileDialog in project megameklab by MegaMek.
the class StatusBar method getFluffImage.
private void getFluffImage() {
// copied from structureTab
FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD);
fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar);
fDialog.setLocationRelativeTo(this);
fDialog.setVisible(true);
if (fDialog.getFile() != null) {
String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath();
relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir").toString()).getAbsolutePath().length() + 1);
getSmallCraft().getFluff().setMMLImagePath(relativeFilePath);
}
refresh.refreshPreview();
return;
}
use of java.awt.FileDialog in project megameklab by MegaMek.
the class StatusBar method getFluffImage.
private void getFluffImage() {
// copied from structureTab
FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD);
fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar);
/*
//This does not seem to be working
if (getMech().getFluff().getMMLImagePath().trim().length() > 0) {
String fullPath = new File(getMech().getFluff().getMMLImagePath()).getAbsolutePath();
String imageName = fullPath.substring(fullPath.lastIndexOf(File.separatorChar) + 1);
fullPath = fullPath.substring(0, fullPath.lastIndexOf(File.separatorChar) + 1);
fDialog.setDirectory(fullPath);
fDialog.setFile(imageName);
} else {
fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar);
fDialog.setFile(getMech().getChassis() + " " + getMech().getModel() + ".png");
}
*/
fDialog.setLocationRelativeTo(this);
fDialog.setVisible(true);
if (fDialog.getFile() != null) {
String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath();
relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir").toString()).getAbsolutePath().length() + 1);
getInfantry().getFluff().setMMLImagePath(relativeFilePath);
}
refresh.refreshPreview();
return;
}
use of java.awt.FileDialog in project megameklab by MegaMek.
the class StatusBar method getFluffImage.
private void getFluffImage() {
// copied from structureTab
FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD);
fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar);
fDialog.setLocationRelativeTo(this);
fDialog.setVisible(true);
if (fDialog.getFile() != null) {
String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath();
relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir").toString()).getAbsolutePath().length() + 1);
getAero().getFluff().setMMLImagePath(relativeFilePath);
}
refresh.refreshPreview();
return;
}
use of java.awt.FileDialog in project megameklab by MegaMek.
the class StatusBar method getFluffImage.
private void getFluffImage() {
// copied from structureTab
FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD);
fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar);
fDialog.setLocationRelativeTo(this);
fDialog.setVisible(true);
if (fDialog.getFile() != null) {
String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath();
relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir").toString()).getAbsolutePath().length() + 1);
getAero().getFluff().setMMLImagePath(relativeFilePath);
}
refresh.refreshPreview();
return;
}
Aggregations