Page 12 of 22 FirstFirst ... 28910111213141516 ... LastLast
Results 111 to 120 of 217

Thread: TreeThing

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default

    Tested using:
    File > Save Layers

    1) The "Save" Dialog that pops up does not have a way to create a new folder (as you mentioned it should. SCREENSHOT BELOW)
    2) The "Save" Dialog that pops up does not let you select a folder (the "Save" button stays greyed out and does not activate)
    3) The "Save" Dialog that pops up only continues if you select a file (the "Save" button activates), but the save fails with the same error as before.

    I'm a Java programmer too, and I LOVE this program, so feel free to talk to me independently, or we can keep going in here and share the news with everyone as we go.

    Click image for larger version. 

Name:	screen1.jpg 
Views:	97 
Size:	206.2 KB 
ID:	40105

  2. #2
    Guild Expert Ramah's Avatar
    Join Date
    Mar 2009
    Location
    Nottinghamshire
    Posts
    1,414
    Blog Entries
    4

    Default

    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?
    Royal: I'm very sorry for your loss, your mother was a terribly attractive woman.


    My Cartographer's Guild maps: Finished Maps


    More maps viewable at my DeviantArt page: Ramah-Palmer DeviantArt

  3. #3

    Default

    Quote Originally Posted by Ramah View Post
    Thanks guys.
    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?
    Thanks for the effort. Good eye!

    I have tested the latest version (TreeThing_962).
    The screenshot remains the same, but you may have identified the problem. YES, the JToggle buttons are darkened when all the layers are visible, BUT as soon as the Save dialog pops up, they go light (unselected) again. Still can't select the destination folder, and the Save button stays greyed out, but this may be due to the fact that the layers are being de-activated by the Save dialog.

    Oh, and you say you can create a directory but how? What do you click on? As you can see in the screenshot there is no interface to create a new directory (which may be a separate issue, or the same one).

    Hope that helps. :-)

  4. #4
    Guild Expert Ramah's Avatar
    Join Date
    Mar 2009
    Location
    Nottinghamshire
    Posts
    1,414
    Blog Entries
    4

    Default

    Here is a replacement for the last version I posted with the "blank images when layers turned off" fix.

    I also added some code to change the cursor when it is performing long operations so any comments on whether that is working ok would be cool.

    Edit: File removed.
    Last edited by Ramah; 11-21-2011 at 11:47 AM.
    Royal: I'm very sorry for your loss, your mother was a terribly attractive woman.


    My Cartographer's Guild maps: Finished Maps


    More maps viewable at my DeviantArt page: Ramah-Palmer DeviantArt

  5. #5
    Community Leader jfrazierjr's Avatar
    Join Date
    Oct 2007
    Location
    Apex, NC USA
    Posts
    3,057

    Default

    You are thinking in windows... don't do that...

    Code:
             String where = f.getPath().substring(0, f.getPath().lastIndexOf("\\"))+ "\\";

    I assume you are looking for the fully qualified directory name right? For one, backslash is the folder seperator on windows only. Also, there is a system property for this you should use instead of hard coding
    Code:
    System.getProperty("path.separator");
    OR, just use forward slash (/) as I am 99.999% sure that just works on all machines(I know it works on windows).

    However, in this case, you just need to use the correct file method, I THINK getCanonicalPath() is what you want. From my understanding, this should also properly resolve to symbolic links as *NIX has used and as windows 7+ now uses for it's "libraries" folder structure.


    Code:
    what = f.getName().substring(0, f.getName().lastIndexOf("."));
    should be just f.getName() to get the "basename" of the file. One question here, why are you checking to see if the file is a .png or not? Or are you checking to see if it's a directory? If the latter, then just use .isFile() or .isDirectory() as needed.



    Note: If I am missing something on your logic flow, please let me know and I will try to correct my brain...lol
    My Finished Maps
    Works in Progress(or abandoned tests)
    My Tutorials:
    Explanation of Layer Masks in GIMP
    How to create ISO Mountains in GIMP/PS using the Smudge tool
    ----------------------------------------------------------
    Unless otherwise stated by me in the post, all work is licensed under a Creative Commons Attribution-Noncommercial 3.0 United States License.

  6. #6
    Community Leader jfrazierjr's Avatar
    Join Date
    Oct 2007
    Location
    Apex, NC USA
    Posts
    3,057

    Default

    Code:
    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;
    Also, on another side note, I "personally" would suggest never using the optional braces format for anything. ie, add braces (and indention) to each "if" statement. It just really makes it easier to read IMHO and it keeps someone(you) from forgetting to add them when you add additional statements since they are already there....Again, that is a) personal preference and it also conforms to Sun's coding style guidelines(of which I don't agree 100%, but that's neither here nor their!!!)

    For that matter, I personally would probably just refactor that bit out into it's own method, passing the "name" as an enum and just remove the whole for statement all together(again, just personal preference).
    My Finished Maps
    Works in Progress(or abandoned tests)
    My Tutorials:
    Explanation of Layer Masks in GIMP
    How to create ISO Mountains in GIMP/PS using the Smudge tool
    ----------------------------------------------------------
    Unless otherwise stated by me in the post, all work is licensed under a Creative Commons Attribution-Noncommercial 3.0 United States License.

  7. #7
    Guild Expert Ramah's Avatar
    Join Date
    Mar 2009
    Location
    Nottinghamshire
    Posts
    1,414
    Blog Entries
    4

    Default

    Cheers, for that man.

    I've altered it to use getCanonicalPath. I do use that command elsewhere, to point the filechoosers towards a template or background image that was previously loaded instead of the program root directory but it hadn't occurred to use it there. :S

    The f.getName without the substring removal doesn't return the base name... well, it does but if the user enters ".png" on the end then the filename would end up as: forest_Trees.png.png which is a bit crap. But you are right to question why it does it for .png as someone may be as likely to add .jpg on the end I guess. Changing it to a substring up to firstIndexOf "." would make more sense.

    As for curly brackets... tsk! Real men use global variables whenever possible and no curly brackets. \0/
    Royal: I'm very sorry for your loss, your mother was a terribly attractive woman.


    My Cartographer's Guild maps: Finished Maps


    More maps viewable at my DeviantArt page: Ramah-Palmer DeviantArt

  8. #8
    Community Leader jfrazierjr's Avatar
    Join Date
    Oct 2007
    Location
    Apex, NC USA
    Posts
    3,057

    Default

    Quote Originally Posted by Ramah View Post
    The f.getName without the substring removal doesn't return the base name... well, it does but if the user enters ".png" on the end then the filename would end up as: forest_Trees.png.png which is a bit crap. But you are right to question why it does it for .png as someone may be as likely to add .jpg on the end I guess. Changing it to a substring up to firstIndexOf "." would make more sense.
    Not necessarily. It is typically common place in *nix for files to have multiple "dot"(.) in the filename, BUT since you already test for endsWith(".png") anyway, you should already be safe. Sorry..I thought you were trying to do something else AND I was also confusing java with a perl module( that does all of that fiddly breaking down crap for you).


    Also, on a side note, you might want to look into using the FileNameFilter so you can have it just show .png files to begin with and let the OS deal with the whole (is it showing file extensions or not). Typically, even if someone types in "forest_Trees.png" in a file save dialog, IF there is a file filter, you will always get back EXACTLY "forest_Trees.png", at least in my experience. Now... there is one BIG caveat to this, and that is that if the user actually types in "forest_Trees.png" into the dialog box AND also puts quotes around it, in which case it takes the literal input string and then adds the FileNameFilter to the end. Of course, if someone REALLY wants to do that, then they should know what they are doing anyway since it's far beyond be realm of what a "normal" person would do.

    I hope that makes sense.
    My Finished Maps
    Works in Progress(or abandoned tests)
    My Tutorials:
    Explanation of Layer Masks in GIMP
    How to create ISO Mountains in GIMP/PS using the Smudge tool
    ----------------------------------------------------------
    Unless otherwise stated by me in the post, all work is licensed under a Creative Commons Attribution-Noncommercial 3.0 United States License.

  9. #9
    Guild Expert Ramah's Avatar
    Join Date
    Mar 2009
    Location
    Nottinghamshire
    Posts
    1,414
    Blog Entries
    4

    Default

    Actually, getCanonicalPath and getPath in this respect work the same for me. The problem was as you say, extracting the path from the filename irrespective of what I used to get it. getParent() works great though for returning the path alone. In conjunction with a "/" when stitching them back together it should now hopefully work ok on a mac.

    Edit: Heh. Just went through the rest of the program to adjust all the other file saving and reading that goes on from the Windows standard and it turns out that in all other places I had used "/", hence the program only falling over on the mac in that one place.... So... D'oh! for doing that particular one like that. :s
    Last edited by Ramah; 11-21-2011 at 11:39 AM.
    Royal: I'm very sorry for your loss, your mother was a terribly attractive woman.


    My Cartographer's Guild maps: Finished Maps


    More maps viewable at my DeviantArt page: Ramah-Palmer DeviantArt

  10. #10
    Guild Expert Ramah's Avatar
    Join Date
    Mar 2009
    Location
    Nottinghamshire
    Posts
    1,414
    Blog Entries
    4

    Default

    Ok then, another fixed version. This one should work.

    EDIT: Removed file. Newer version later in thread
    Last edited by Ramah; 11-26-2011 at 11:35 AM.
    Royal: I'm very sorry for your loss, your mother was a terribly attractive woman.


    My Cartographer's Guild maps: Finished Maps


    More maps viewable at my DeviantArt page: Ramah-Palmer DeviantArt

Page 12 of 22 FirstFirst ... 28910111213141516 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •