package musicdownloader; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.File; public class DownloadPanel extends JPanel{ Bookmark[] bookmarks; JLabel[] bookmarksLabel; JCheckBox[] bookmarksCheckBox; JScrollPane scrollPane; JLabel selectFilePrompt; JLabel bookmarkPath; JButton selectFile; JButton acceptSelection; boolean fileExists; JFileChooser chooseFile; String OS; String path; String defaultWindowsPath; String defaultMacPath; ActionListener actionListener; public DownloadPanel(int w, int h, ActionListener al){ setBackground(Color.RED); setOpaque(true); actionListener = al; OS = System.getProperty("os.name").toLowerCase(); defaultWindowsPath = "C:/Users/"+System.getProperty("user.name")+"/AppData/Local/Google/Chrome/User Data/Default/Bookmarks"; defaultMacPath = "/Users/"+System.getProperty("user.name")+"/Library/Application Support/Google/Chrome/Default/Bookmarks"; path = ""; setPreferredSize(new Dimension(w,h)); setLayout(new BorderLayout()); fileExists = false; getBookmarksPath(); } public void displaySongsList(Bookmark[] b){ // bookmarks = b; // bookmarksLabel = new JLabel[b.length]; // bookmarksCheckBox = new JCheckBox[b.length]; add(new JCheckBox("Hello my name is tod - beahafhaasg fsga")); } public void displaySelectFile(){ selectFilePrompt = new JLabel("The file was not found in its default location. Please select the file manually."); add(selectFilePrompt,BorderLayout.NORTH); selectFile = new JButton("Select File"); selectFile.setActionCommand("selectFile"); selectFile.addActionListener(actionListener); add(selectFile,BorderLayout.WEST); bookmarkPath = new JLabel(""); add(bookmarkPath,BorderLayout.CENTER); acceptSelection = new JButton("Continue"); acceptSelection.addActionListener(actionListener); acceptSelection.setActionCommand("continue"); add(acceptSelection,BorderLayout.EAST); } public final void getBookmarksPath(){ if ((OS.indexOf("win") >= 0)){ //this is windows if (fileExists()){ System.out.println("File exists at default location."); path = defaultWindowsPath; fileExists = true; } else { System.out.println("File does not exist at default location."); JOptionPane.showMessageDialog(null,"Bookmarks file could not be found. Please locate it manually."); } } else if (OS.indexOf("mac") >= 0){ //this is mac if (fileExists()){ System.out.println("File exists at default location."); path = defaultMacPath; } else { System.out.println("File does not exist at default location."); JOptionPane.showMessageDialog(null,"Bookmarks file could not be found. Please locate it manually."); } } else { System.out.println("OS not windows or Mac"); } } private boolean fileExists (){ //mac or win boolean fileFound = false; if ((OS.indexOf("win") >= 0)){ //this is for windows File f = new File(defaultWindowsPath); fileFound = f.exists(); } else if (OS.indexOf("mac") >= 0){ //this is for mac File f = new File(defaultMacPath); fileFound = f.exists(); } else { System.out.println("This is not windows or mac. gtfo"); System.exit(0); } return fileFound; } public void chooseFile(){ final JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); path = file.getPath(); bookmarkPath.setText(path); System.out.println("File: " + file.getName() + "."); System.out.println("Path: "+path); } else { System.out.println("Open command cancelled by user."); } System.out.println(returnVal); } public boolean getFileExists(){ //return fileExists; return false; } public String getFilePath(){ return path; } }