Thanks guys.
Code:
public void saveAll() {
jfc.setDialogTitle("Save Layers");
jfc.setApproveButtonText("Save");
// jfc.setApproveButtonMnemonic(KeyEvent.VK_S); //Doesn't seem to work
jfc.setSelectedFile(new File(""));
jfc.setApproveButtonToolTipText("Save Files");
int returnVal = jfc.showOpenDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File f = jfc.getSelectedFile();
if (f.exists()) {
int ans = JOptionPane.showConfirmDialog(frame, "File " + f.getName() + " exists already. Overwrite?", "Save", JOptionPane.YES_NO_OPTION);
if (ans == JOptionPane.OK_OPTION) {
saveAll(f);
}
}
else saveAll(f);
}
}
public void saveAll(File f) {
String where = f.getPath().substring(0, f.getPath().lastIndexOf("\\"))+ "\\";
String what;
File f2;
int x = 0;
int y = 0;
boolean saveImg = true;
if (templateLoaded) {
x = 25;
y = 25;
}
int w = width - (x * 2);
int h = height - (y * 2);
if (f.getName().toLowerCase().endsWith(".png"))
what = f.getName().substring(0, f.getName().lastIndexOf("."));
else what = f.getName();
String fileName = where + what;
for (int i = 1; i <= 4; i++) {
saveImg = true;
if (i == 1) layerShow = "Trees";
if (i == 2)
if (maskButton.isEnabled()) layerShow = "Masks";
else saveImg = false;
if (i == 3)
if (shadeButton.isEnabled()) layerShow = "Shades";
else saveImg = false;
if (i == 4)
if (shadowButton.isEnabled())layerShow = "Shadows";
else saveImg = false;
populateLayers();
if (saveImg) {
f2 = new File (fileName + "_" + layerShow + ".png");
try { ImageIO.write(workImg.getSubimage(x, y, w, h), "PNG", f2); }
catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
if (textCheck.isEnabled()) {
f2 = new File (fileName + "_Labels.png");
try { ImageIO.write(textImg.getSubimage(x, y, w, h), "PNG", f2); }
catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
layerShow = "All";
populateLayers();
}
Here is the relevant piece of code. If you two know what you are doing then the above code probably doesn't look too pretty.
On a forum I read it said that the mac had a problem with showDialog and showSaveDialog, giving the wrong path as a result. Apparently it can be deduped to get the correct path but without seeing the resultant path I cannot really do that. I've edited a showOpenDialog to work as a save dialog and according to the forum this was supposed to work.
So take a look at that and see if you can see a problem there, although out of context like that it may be a little awkward.
Odd that you cannot change directories or anything Paul. On mine, I have no problem changing directories but for some reason (it might be to do with changing it to an openDialog) I cannot create a new directory until I've changed direcory at least once. The option is greyed out. After changing to Desktop or whatever it works fine.
I've found one annoying bug though whilst checking this out that slipped through today due to messing with the saving code. I've noticed that if you don't have the layers switched on when you save the layers the files it spits out for those layers are blank. I cannot see from your screenshot paul what layers you have active (do the jToggleButtons work correctly on the mac?). I can see from your forest that you only have the brush layer active but the brush button at the top doesn't appear selected. Have you tried saving the layers after making sure that all four layers are active?