Skip to content

Commit

Permalink
Version 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
octaviospain committed Aug 19, 2015
1 parent be26637 commit 8048ca7
Show file tree
Hide file tree
Showing 29 changed files with 1,097 additions and 325 deletions.
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changes

## Version 0.6

* Now editing track information saves the metadata on the file, excepts wav files
* Improved error handling
* Minor refactors and fixes

## Version 0.5.1

* Fixed an error loading some resources

## Version 0.5.0

* Implemented search functionality
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ A JavaFX application for import, organize and play music files.

### To be implemented
* Play flac files
* Fix metadata from 3rd party
* Write metadata tags on edit
* Get metadata from 3rd party services (Beatport, discogs, etc)
* Advanced search feature
* Show cover image on table
* Ability to manage different formats for a single track (implementing a TreeTableView)
* Managing of HD space giving the option to move files to external drives but maintaining the info in the table

## Download
[Download](https://github.com/octaviospain/Musicott/releases "Download") the last release (version 0.6)

## Changes history
In [CHANGES.md](https://github.com/octaviospain/Musicott/tree/master/CHANGES.md "Changes")

Expand Down
4 changes: 2 additions & 2 deletions build.fxbuild
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="ASCII"?>
<anttasks:AntTask xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:anttasks="http://org.eclipse.fx.ide.jdt/1.0" buildDirectory="${project}/build">
<anttasks:AntTask xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:anttasks="http://org.eclipse.fx.ide.jdt/1.0" buildDirectory="${project}/build" cssToBin="true">
<deploy packagingFormat="dmg">
<application name="Musicott" mainclass="com.musicott.MainApp" version="0.5.0" toolkit="fx"/>
<application name="Musicott" mainclass="com.musicott.MainApp" version="0.6.0" toolkit="fx"/>
<info title="Musicott" vendor="Musicott"/>
</deploy>
<signjar/>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Musicott</groupId>
<artifactId>Musicott</artifactId>
<version>0.5.0</version>
<version>0.6.0</version>
<name>Musicott</name>
<build>
<sourceDirectory>src</sourceDirectory>
Expand Down
11 changes: 8 additions & 3 deletions src/com/musicott/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@
*/
public class MainApp extends Application {

private Stage mainStage;

public static void main(String[] args) {
launch();
}

@Override
public void start(Stage primaryStage) {
Stage mainStage = primaryStage;
mainStage = primaryStage;
mainStage.setTitle("Musicott");
mainStage.getIcons().add(new Image("file:resources/images/musicotticon.png"));
SceneManager sc = SceneManager.getInstance();
sc.setPrimaryStage(mainStage);
SceneManager.getInstance().setPrimaryStage(this);
}

public Stage getStage() {
return mainStage;
}
}
43 changes: 23 additions & 20 deletions src/com/musicott/SceneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import java.io.IOException;

import com.musicott.error.ErrorHandler;
import com.musicott.error.ErrorType;
import com.musicott.task.LoadLibraryTask;
import com.musicott.task.SaveLibraryTask;
import com.musicott.view.EditController;
import com.musicott.view.ErrorDialogController;
import com.musicott.view.ImportCollectionController;
import com.musicott.view.PlayQueueController;
import com.musicott.view.ProgressImportController;
Expand All @@ -51,11 +51,10 @@
*/
public class SceneManager {

private Stage rootStage;
private Stage importStage;
private Stage progressStage;
private Stage editStage;
private Scene mainScene;
private MainApp application;

private BorderPane rootLayout;
private AnchorPane playQueueLayout;
Expand All @@ -67,6 +66,7 @@ public class SceneManager {
private PlayQueueController playQueueController;

private static SceneManager instance;
private ErrorHandler errorHandler;

private SceneManager() {
}
Expand All @@ -77,18 +77,23 @@ public static SceneManager getInstance() {
return instance;
}

protected void setPrimaryStage(Stage primaryStage) {
rootStage = primaryStage;
protected void setPrimaryStage(MainApp application) {
this.application = application;
errorHandler = ErrorHandler.getInstance();
initPrimaryStage();
}

public void saveLibrary() {
SaveLibraryTask task = new SaveLibraryTask();
Thread t = new Thread(task, "SaveLibraryThread");
Thread t = new Thread(task, "SaveLibrary Thread");
t.setDaemon(true);
t.run();
}

public MainApp getApplication() {
return application;
}

public RootLayoutController getRootController() {
return rootController;
}
Expand Down Expand Up @@ -131,8 +136,8 @@ public void openEditScene(ObservableList<Track> selection) {
editStage.setResizable(false);
editStage.showAndWait();
} catch (IOException e) {
//TODO Show error dialog and closes edit scene
e.printStackTrace();
errorHandler.addError(e, ErrorType.COMMON);
errorHandler.showErrorDialog(ErrorType.COMMON);
}
}

Expand All @@ -155,17 +160,14 @@ public void openImportScene() {
importStage.setResizable(false);
importStage.showAndWait();
} catch (IOException e) {
//TODO Show error dialog and closes import scene
e.printStackTrace();
errorHandler.addError(e, ErrorType.COMMON);
errorHandler.showErrorDialog(ErrorType.COMMON);
}
}

public void closeImportScene() {
if(ErrorHandler.getInstance().hasErrors()) {
ErrorDialogController edc = new ErrorDialogController(progressStage.getScene());
edc.showDialog();
ErrorHandler.getInstance().reset();
}
if(errorHandler.hasErrors(ErrorType.PARSE))
errorHandler.showErrorDialog(progressStage.getScene(), ErrorType.PARSE);
progressStage.close();
if(importStage != null && importStage.isShowing())
importStage.close();
Expand All @@ -191,13 +193,14 @@ public void showImportProgressScene(Task<?> task, boolean hideCancelButton) {
progressStage.showAndWait();
}
catch(IOException e) {
// TODO Show error dialog and closes import scene
e.printStackTrace();
errorHandler.addError(e, ErrorType.COMMON);
errorHandler.showErrorDialog(ErrorType.COMMON);
}
}

private void initPrimaryStage() {
try {
Stage rootStage = application.getStage();
FXMLLoader rootLoader = new FXMLLoader();
rootLoader.setLocation(MainApp.class.getResource("view/RootLayout.fxml"));
rootLayout = (BorderPane) rootLoader.load();
Expand All @@ -214,7 +217,7 @@ private void initPrimaryStage() {
playQueueLayout = (AnchorPane) pqLoader.load();
playQueueController = pqLoader.getController();

mainScene = new Scene(rootLayout,1200,775);
Scene mainScene = new Scene(rootLayout,1200,775);
rootStage.setMinWidth(1200);
rootStage.setMinHeight(775);
rootStage.setScene(mainScene);
Expand Down Expand Up @@ -248,8 +251,8 @@ private void initPrimaryStage() {
thumb.getChildren().add(new ImageView(new Image(SceneManager.class.getResourceAsStream("/icons/sliderthumb-icon.png"))));
thumb.setPrefSize(5,5);
} catch (IOException e) {
//TODO Show error dialog and crashes
e.printStackTrace();
errorHandler.addError(e, ErrorType.COMMON);
errorHandler.showErrorDialog(ErrorType.COMMON);
}
}
}
42 changes: 42 additions & 0 deletions src/com/musicott/error/CommonException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* This file is part of Musicott software.
*
* Musicott software is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Musicott library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Musicott library. If not, see <http://www.gnu.org/licenses/>.
*
*/

package com.musicott.error;

/**
* @author Octavio Calleya
*
*/
public class CommonException extends Exception {

public CommonException() {
super();
}

public CommonException(String msg) {
super(msg);
}

public CommonException(Throwable cause) {
super(cause);
}

public CommonException(String msg, Throwable cause) {
super(msg,cause);
}
}
111 changes: 98 additions & 13 deletions src/com/musicott/error/ErrorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,24 @@

package com.musicott.error;

import java.util.ArrayList;
import java.util.List;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

import com.musicott.SceneManager;

import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;

/**
* @author Octavio Calleya
Expand All @@ -28,9 +44,13 @@
public class ErrorHandler {

private static ErrorHandler instance;
private List<ParseException> pExcs;
private Stage mainStage;
private Map<ErrorType,Stack<Exception>> mapExceptions;
private Alert alert;

private ErrorHandler() {
mapExceptions = new HashMap<ErrorType,Stack<Exception>>();
mainStage = SceneManager.getInstance().getApplication().getStage();
}

public static ErrorHandler getInstance() {
Expand All @@ -39,21 +59,86 @@ public static ErrorHandler getInstance() {
return instance;
}

public void reset() {
pExcs.clear();
public void addError(Exception ex, ErrorType type) {
if(mapExceptions.containsKey(type))
mapExceptions.get(type).push(ex);
else {
Stack<Exception> stack = new Stack<Exception>();
stack.push(ex);
mapExceptions.put(type, stack);
}
}

public void addParseException(ParseException e) {
if(pExcs == null)
pExcs = new ArrayList<ParseException>();
pExcs.add(e);
public boolean hasErrors(ErrorType type) {
boolean has = false;
if(!mapExceptions.isEmpty() && mapExceptions.containsKey(type) && !mapExceptions.get(type).isEmpty())
has = true;
return has;
}

public Stack<Exception> getErrors(ErrorType type){
return mapExceptions.get(type);
}

public boolean hasErrors() {
return pExcs != null && pExcs.size() != 0;
public void showErrorDialog(ErrorType type) {
showErrorDialog(mainStage.getScene(), type);
}

public List<ParseException> getParseExceptions(){
return pExcs;
public void showErrorDialog(Scene ownerScene, ErrorType type) {
alert = new Alert(AlertType.ERROR);
alert.initOwner(ownerScene.getWindow());
alert.setTitle("Error");
alert.setHeaderText("Error");
switch(type) {
case COMMON:
if(mapExceptions.get(type).size() == 1 && mapExceptions.get(type).peek() instanceof CommonException)
alert.getDialogPane().contentProperty().set(new Label(mapExceptions.get(type).pop().getMessage()));
else
setExpandable(getErrors(type));
break;
case METADATA:
alert.setHeaderText("Error(s) writing metadata on file(s)");
setExpandable(getErrors(type));
break;
case PARSE:
alert.setHeaderText("Error(s) parsing file(s)");
setExpandable(getErrors(type));
break;
case FATAL:
alert.setHeaderText("Fatal error");
setExpandable(getErrors(type));
Label text = new Label(" Please help Musicott to fix this kind of bugs. Report this error at");
Hyperlink githubIssuesLink = new Hyperlink("https://github.com/octaviospain/Musicott/issues");
githubIssuesLink.setOnAction(event -> {
SceneManager.getInstance().getApplication().getHostServices().showDocument(githubIssuesLink.getText());
});
FlowPane fp = new FlowPane();
fp.getChildren().addAll(text, githubIssuesLink);
alert.getDialogPane().contentProperty().set(fp);
break;
}
alert.showAndWait();
}

private void setExpandable(Stack<Exception> exceptions) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
while(!exceptions.isEmpty())
exceptions.pop().printStackTrace(pw);

TextArea textArea = new TextArea(sw.toString());
textArea.setEditable(false);
textArea.setWrapText(true);

textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);

GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(new Label("The exception stacktrace was:"), 0, 0);
expContent.add(textArea, 0, 1);
alert.getDialogPane().setExpandableContent(expContent);
}
}
Loading

0 comments on commit 8048ca7

Please sign in to comment.