This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 12th, 2013  |  syntax: Java  |  size: 5.07 KB  |  views: 38  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package musicdownloader;
  2.     import javax.swing.*;
  3.     import java.awt.*;
  4.     import java.awt.event.*;
  5. import java.io.File;
  6.  
  7. public class DownloadPanel extends JPanel{
  8.    
  9.     Bookmark[] bookmarks;
  10.     JLabel[] bookmarksLabel;
  11.     JCheckBox[] bookmarksCheckBox;
  12.     JScrollPane scrollPane;
  13.    
  14.     JLabel selectFilePrompt;
  15.     JLabel bookmarkPath;
  16.     JButton selectFile;
  17.     JButton acceptSelection;
  18.    
  19.     boolean fileExists;
  20.     JFileChooser chooseFile;
  21.    
  22.     String OS;
  23.     String path;
  24.     String defaultWindowsPath;
  25.     String defaultMacPath;
  26.    
  27.     ActionListener actionListener;
  28.    
  29.     public DownloadPanel(int w, int h, ActionListener al){
  30.        
  31.         setBackground(Color.RED);
  32.         setOpaque(true);
  33.         actionListener = al;
  34.        
  35.         OS = System.getProperty("os.name").toLowerCase();
  36.         defaultWindowsPath = "C:/Users/"+System.getProperty("user.name")+"/AppData/Local/Google/Chrome/User Data/Default/Bookmarks";
  37.         defaultMacPath = "/Users/"+System.getProperty("user.name")+"/Library/Application Support/Google/Chrome/Default/Bookmarks";
  38.         path = "";
  39.        
  40.         setPreferredSize(new Dimension(w,h));
  41.         setLayout(new BorderLayout());
  42.        
  43.         fileExists = false;
  44.         getBookmarksPath();
  45.        
  46.     }
  47.    
  48.     public void displaySongsList(Bookmark[] b){
  49. //        bookmarks = b;
  50. //        bookmarksLabel = new JLabel[b.length];
  51. //        bookmarksCheckBox = new JCheckBox[b.length];
  52.        
  53.         add(new JCheckBox("Hello my name is tod - beahafhaasg fsga"));
  54.        
  55.        
  56.     }
  57.    
  58.     public void displaySelectFile(){
  59.         selectFilePrompt = new JLabel("The file was not found in its default location. Please select the file manually.");
  60.         add(selectFilePrompt,BorderLayout.NORTH);
  61.        
  62.         selectFile = new JButton("Select File");
  63.         selectFile.setActionCommand("selectFile");
  64.         selectFile.addActionListener(actionListener);
  65.         add(selectFile,BorderLayout.WEST);
  66.        
  67.         bookmarkPath = new JLabel("");
  68.         add(bookmarkPath,BorderLayout.CENTER);
  69.  
  70.         acceptSelection = new JButton("Continue");
  71.         acceptSelection.addActionListener(actionListener);
  72.         acceptSelection.setActionCommand("continue");
  73.         add(acceptSelection,BorderLayout.EAST);
  74.     }
  75.    
  76.     public final void getBookmarksPath(){
  77.             if ((OS.indexOf("win") >= 0)){                  //this is windows
  78.                     if (fileExists()){
  79.                         System.out.println("File exists at default location.");
  80.                         path = defaultWindowsPath;
  81.                         fileExists = true;
  82.                     } else {
  83.                         System.out.println("File does not exist at default location.");
  84.                         JOptionPane.showMessageDialog(null,"Bookmarks file could not be found. Please locate it manually.");
  85.                     }
  86.                        
  87.                 } else if (OS.indexOf("mac") >= 0){         //this is mac
  88.                         if (fileExists()){
  89.                         System.out.println("File exists at default location.");
  90.                         path = defaultMacPath;
  91.                     } else {
  92.                         System.out.println("File does not exist at default location.");
  93.                         JOptionPane.showMessageDialog(null,"Bookmarks file could not be found. Please locate it manually.");
  94.                     }
  95.                 } else {
  96.                     System.out.println("OS not windows or Mac");
  97.                 }
  98.       }
  99.  
  100.     private boolean fileExists (){ //mac or win
  101.         boolean fileFound = false;
  102.        
  103.         if ((OS.indexOf("win") >= 0)){                  //this is for windows          
  104.                 File f = new File(defaultWindowsPath);
  105.                 fileFound = f.exists();
  106.         } else if (OS.indexOf("mac") >= 0){         //this is for mac
  107.                 File f = new File(defaultMacPath);
  108.                 fileFound = f.exists();
  109.         } else {
  110.                 System.out.println("This is not windows or mac. gtfo");
  111.                 System.exit(0);
  112.         }
  113.             return fileFound;
  114.     }
  115.        
  116.     public void chooseFile(){
  117.         final JFileChooser fc = new JFileChooser();
  118.                         int returnVal = fc.showOpenDialog(this);
  119.                         if (returnVal == JFileChooser.APPROVE_OPTION) {
  120.                             File file = fc.getSelectedFile();
  121.                             path = file.getPath();
  122.                             bookmarkPath.setText(path);
  123.                             System.out.println("File: " + file.getName() + ".");
  124.                             System.out.println("Path: "+path);
  125.                         } else {
  126.                             System.out.println("Open command cancelled by user.");
  127.                         }
  128.                         System.out.println(returnVal);
  129.     }
  130.    
  131.     public boolean getFileExists(){
  132.         //return fileExists;
  133.         return false;
  134.     }
  135.    
  136.     public String getFilePath(){
  137.         return path;
  138.     }
  139.    
  140. }
clone this paste RAW Paste Data