Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Decode sample code

  1. #1
    Member Cronus's Avatar
    Join Date
    Feb 2013
    Location
    Gothenburg, Sweden
    Posts
    41
    My Mood
    Inspired
    Thanks
    6
    Thanked 7 Times in 6 Posts

    Default Decode sample code

    "Hi everybody! Hi dr. Nick!"

    I'm really not a fan of JFileChooser - It's as anti-mac-looking as possible. So I messed around with FileDialog. I gave up on that because it's ancient compared to Swing and seems to have been abandoned by the Coffee Gods. I shoveled my way even deeper down by trying to figure out how to use a Finder/Explorer window instead of the given Java options (FileDialog, JFileChooser). I found this neat thread at JavaRanch:

    Open a folder in finder in Java (Mac OS forum at JavaRanch)

    "Houston, we have a problem", though. I'm to dimwitted to understand the sample code given by "Andrew Monkhouse". I thank him sincerely for lending internet a hand, but apparently, he doesn't explain his solution. I'm talking about this part:

    public class ColinMcTaggart {  
      private static final String[] prefix = {  
          "osascript",  
          "-e", "tell application \"Finder\"",  
          "-e", "activate",  
          "-e", "<openCmdGoesHere>",  
          "-e", "end tell"  
      };  
     
      public static void main(String[] args) throws Exception {  
        prefix[6] = buildFolderCommand(System.getProperty("user.dir"));  
        Runtime.getRuntime().exec(prefix).waitFor();  
      }  
     
      private static String buildFolderCommand(String folderPath) {  
        StringBuilder openCommand = new StringBuilder("open ");  
        String[] pathParts = folderPath.split("/");  
        for (int i = pathParts.length - 1; i > 0; i--) {  
          openCommand.append("folder \"").append(pathParts[i]).append("\" of ");  
        }  
        return openCommand.append("startup disk").toString();  
      }  
    }

    I ran the code and it worked perfectly. I just don't understand it. The first part was some osascript that opened the finder. The rest doesn't make sense to me. Could you decode this piece of information to me and future researchers?

    Also, is it possible to interact with the Finder window? Can you set filters, get selected files, etc? It's probably possible with osascript. What do you think?

    If it's not possible, I'd rather create my very own file dialog, which I think is the best choice of all above anyways, hardest but most awarding. Got any tips on that?

    Thanks!


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Decode sample code

    My advice would be to use FileDialog

Similar Threads

  1. [SOLVED] Help reading a file to decode or encode
    By mickey2012 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 29th, 2012, 10:46 PM
  2. Encode and decode - Caesar cipher
    By siabanie in forum Java Theory & Questions
    Replies: 1
    Last Post: October 7th, 2011, 06:25 PM
  3. I need help (Sample code)
    By AGBESI in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 2nd, 2011, 06:10 AM
  4. SQL Max Decode Problem
    By Jack_Maloney in forum Java Theory & Questions
    Replies: 1
    Last Post: July 21st, 2011, 07:13 PM
  5. Java application using C++.Also provide some links and sample code
    By jazz2k8 in forum Java Native Interface
    Replies: 5
    Last Post: July 23rd, 2008, 06:01 AM