Page 12 of 21 FirstFirst ... 21011121314 ... LastLast
Results 111 to 120 of 206
Like Tree19Likes

Thread: TreeThing

  1. #111
      Ramah is offline
    Guild Expert Ramah's Avatar
    Join Date
    Mar 2009
    Location
    Nottinghamshire
    Posts
    1,327
    Blog Entries
    3

    Default

    Thanks for that Paul, that was very helpful to me. I did some digging and found that the Mac version of Java is bugged in certain ways, one of which is the way it responds to ShowSaveDialog, returning an incorrect path which in turn is giving me the substring error. I'll have a play around and try and get a fixed version up soon. It may be that the program will lose the ability to create a new folder for saved files as this is the easiest fix.

    Ravs: Heh. The ability to separate the layers was the reason why I took up the programming of this in the first place and has been there since the very first version that I implemented. I'm impressed that you got such good results in your last map with just the single layer and also realise now that you probably had no idea what I was talking about when I said you should have used the mask layer to underpaint your trees to stop coasts and rivers showing through.
    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

  2. #112
    Guild Apprentice paulbhartzog's Avatar
    Join Date
    Mar 2010
    Posts
    48

    Default

    Awesome. Glad to help.
    Perhaps the user could select the destination folder for the layer images? This would mean the user would have to make the folder first (which is fine) and then that takes it out of the the program's "hands" entirely.

    There's always: JFileChooser (Swing)

    Thanks for continuing to work on the program.
    Last edited by paulbhartzog; 11-19-2011 at 12:21 PM.

  3. #113
      Ramah is offline
    Guild Expert Ramah's Avatar
    Join Date
    Mar 2009
    Location
    Nottinghamshire
    Posts
    1,327
    Blog Entries
    3

    Default

    Quote Originally Posted by paulbhartzog View Post
    Awesome. Glad to help.
    Perhaps the user could select the destination folder for the layer images? This would mean the user would have to make the folder first (which is fine) and then that takes it out of the the program's "hands" entirely.

    There's always: JFileChooser (Swing)
    The user can already select the destination folder and can also create a new folder for said images if they want.
    It also already uses a JFileChooser and it is the dialog box for this that apparently casuses the problem on mac OS.

    Anyway, I've changed the program to what I hope will now work correctly on a mac. Having no way to test this myself all I can rely on is troubleshooting forums on the web for answers so if you could let me know if it works now Paul then that would be cool.

    I'll upload this new version here and if it works then I'll update the original post.

    This is version 0.96.

    I've disabled most of my WIP elements on it. I've enabled the faux perspective option this time although it still isn't integrated properly and is of limited use right now.

    I guess the only main additions to this version are:

    1) the ability to load a background jpg image (depending on size this may take a short while to load and it can also have a negative effect on how large a forest can be created)

    2) the ability to remove trees from a generated forest. This is still in its early stages and I plan to do a lot more with this but for now you can press Alt to bring up the tree origins and then click on an origin to toggle it. Then once you have selected all that you want to press Refresh at the top and it should remove/replace all toggled trees.

    EDIT: Removed bugged version. Fixed version a few posts below.
    Last edited by Ramah; 11-21-2011 at 06:09 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

  4. #114
    Guild Apprentice paulbhartzog's Avatar
    Join Date
    Mar 2010
    Posts
    48

    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.

    TreeThing-screen1.jpg

  5. #115
      jfrazierjr is offline
    Community Leader jfrazierjr's Avatar
    Join Date
    Oct 2007
    Location
    Apex, NC USA
    Posts
    2,963

    Default

    Ramah, if you want to share that section of the java code, I could eyeball it to see if I see any obvious issues...here or offline, either way is fine if your up for it.
    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. #116
      Ramah is offline
    Guild Expert Ramah's Avatar
    Join Date
    Mar 2009
    Location
    Nottinghamshire
    Posts
    1,327
    Blog Entries
    3

    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

  7. #117
      Ramah is offline
    Guild Expert Ramah's Avatar
    Join Date
    Mar 2009
    Location
    Nottinghamshire
    Posts
    1,327
    Blog Entries
    3

    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

  8. #118
      jfrazierjr is offline
    Community Leader jfrazierjr's Avatar
    Join Date
    Oct 2007
    Location
    Apex, NC USA
    Posts
    2,963

    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.

  9. #119
      jfrazierjr is offline
    Community Leader jfrazierjr's Avatar
    Join Date
    Oct 2007
    Location
    Apex, NC USA
    Posts
    2,963

    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.

  10. #120
      Ramah is offline
    Guild Expert Ramah's Avatar
    Join Date
    Mar 2009
    Location
    Nottinghamshire
    Posts
    1,327
    Blog Entries
    3

    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

Page 12 of 21 FirstFirst ... 21011121314 ... 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
  •