// Set the buttons displayed in the panel // textFilePath - The path to the sound effect definition file // Returns 0 (an error occurred and a new project was opened), 1 (an error occurred), 2 (the // project opened normally) public int loadFile(String textFilePath) { clearBoard(); // Get the sounds contained in the given project file ArrayList<SoundInfo> readSounds = soundManager.readFile(textFilePath); // Add buttons to the interface for each sound in the file for (int s = 0; s < readSounds.size(); s++) { SoundInfo curr = readSounds.get(s); if (checkValidKey(curr.getKeyName())) { addSound(readSounds.get(s)); } else { soundManager.deleteSound(curr.getKeyCode()); } } // Report if an error occurred while opening the project // Allow the user to close the project without proceeding if (soundManager.getProjectModified()) { int choice = JOptionPane.showConfirmDialog( frame, "One or more errors were encountered while reading the project file. " + "The file may be missing, not well-formatted, or not a Cue Masher project file. Do you want to proceed?", "Keep Project Open?", JOptionPane.YES_NO_OPTION); if (choice == JOptionPane.NO_OPTION) { openNewProject(); return 0; } return 1; } return 2; }
// Update a sound in the displayed buttons, sound list, and sound file // soundClip - An object storing information about the added or updated sound public void updateSound(SoundInfo soundClip) { // Add the sound to the project SoundInfo newSound = soundManager.addSound(soundClip); if (newSound != null) { // Add a new button to the GUI addSound(newSound); } if (soundManager.getProjectModified()) { if (newSound == null) { // An existing sound was updated // Update the button label and tooltip for (int s = 0; s < soundList.size(); s++) { BoardButton button = soundList.get(s); if (button.getKeyCode() == soundClip.getKeyCode()) { button.updateButtonText(); break; } } } // Update the GUI frame.setProjectModified(); refreshSoundBoard(); } }