Skip to content

Commit

Permalink
Minor fixes (#398)
Browse files Browse the repository at this point in the history
* Passes findbugs

* Fixes 'Exit Topsoil' bug

* Fixes 'New Project' overwrite bug
  • Loading branch information
jakemarotta committed Oct 4, 2017
1 parent ddcbee0 commit 87074b6
Show file tree
Hide file tree
Showing 44 changed files with 335 additions and 291 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ task jarWithDependencies(type: Jar) {
)
}

// baseName = 'topsoil-' + getVersionName().split('-')[0]
baseName = 'topsoil-v2.0.2'
baseName = 'topsoil-' + getVersionName().split('-')[0]
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/java/org/cirdles/topsoil/app/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.stage.*;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import org.cirdles.commons.util.ResourceExtractor;
import org.cirdles.topsoil.app.menu.MenuItemEventHandler;
import org.cirdles.topsoil.app.tab.TopsoilTabPane;
Expand Down Expand Up @@ -63,9 +65,9 @@ public class MainWindow extends Application {
private static Image windowIcon;
private static String OS;

private final static String WINDOWS = "Windows";
private final static String MAC = "Mac";
private final static String LINUX = "Linux";
private static final String WINDOWS = "Windows";
private static final String MAC = "Mac";
private static final String LINUX = "Linux";

//***********************
// Methods
Expand Down Expand Up @@ -99,7 +101,7 @@ public void start(Stage primaryStage) {
RESOURCE_EXTRACTOR.extractResourceAsPath(TOPSOIL_MAIN_WINDOW_FXML_PATH).toUri().toURL());
mainWindow = mainFXMLLoader.load();
mainWindowController = mainFXMLLoader.getController();
} catch (IOException|NullPointerException e) {
} catch (IOException | NullPointerException e) {
e.printStackTrace();
throw new LoadException("Could not load " + TOPSOIL_MAIN_WINDOW_FXML_PATH);
}
Expand All @@ -114,7 +116,6 @@ public void start(Stage primaryStage) {
scene.getStylesheets().add(css);
} catch (MalformedURLException e) {
e.printStackTrace();
System.err.printf("Could not load CSS.%n");
}

// If main window is closed, all other windows close.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ private Menu getProjectMenu(TopsoilTabPane tabs) {
} else {
Platform.exit();
}
} // If nothing is open.
else {
Platform.exit();
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
*/
public class MenuItemEventHandler {

/**
/**
* Handles importing tables from CSV / TSV files
*
* @return Topsoil Table file
Expand Down Expand Up @@ -308,41 +308,41 @@ public static TopsoilDataTable handleOpenExampleTable(TopsoilTabPane tabs, Isoto
UncertaintyFormat format;

if (isotopeType != null) {

List<TopsoilDataEntry> entries = null;
String[] headers = null;
String exampleContent = new ExampleDataTable().getSampleData(isotopeType);
String exampleContentDelimiter = ",";

try {
headers = FileParser.parseHeaders(exampleContent, exampleContentDelimiter);
entries = FileParser.parseTxt(FileParser.readLines(exampleContent), exampleContentDelimiter, true);

switch (isotopeType) {
case Generic:
format = UncertaintyFormat.TWO_SIGMA_PERCENT;
break;
case UPb:
format = UncertaintyFormat.TWO_SIGMA_PERCENT;
break;
case UTh:
format = UncertaintyFormat.TWO_SIGMA_ABSOLUTE;
break;
default:
format = UncertaintyFormat.TWO_SIGMA_PERCENT;
}
List<TopsoilDataEntry> entries = null;
String[] headers = null;
String exampleContent = new ExampleDataTable().getSampleData(isotopeType);
String exampleContentDelimiter = ",";

ObservableList<TopsoilDataEntry> data = FXCollections.observableList(entries);
try {
headers = FileParser.parseHeaders(exampleContent, exampleContentDelimiter);
entries = FileParser.parseTxt(FileParser.readLines(exampleContent), exampleContentDelimiter, true);

table = new TopsoilDataTable(headers, isotopeType, format, data.toArray(new TopsoilDataEntry[data.size()]));
table.setTitle(isotopeType.getName()+" Example Data");
} catch (TopsoilException e) {
e.printStackTrace();
switch (isotopeType) {
case Generic:
format = UncertaintyFormat.TWO_SIGMA_PERCENT;
break;
case UPb:
format = UncertaintyFormat.TWO_SIGMA_PERCENT;
break;
case UTh:
format = UncertaintyFormat.TWO_SIGMA_ABSOLUTE;
break;
default:
format = UncertaintyFormat.TWO_SIGMA_PERCENT;
}

ObservableList<TopsoilDataEntry> data = FXCollections.observableList(entries);

table = new TopsoilDataTable(headers, isotopeType, format, data.toArray(new TopsoilDataEntry[data.size()]));
table.setTitle(isotopeType.getName() + " Example Data");
} catch (TopsoilException e) {
e.printStackTrace();
}
}
return table;
}

/**
* Open default browser and create a new GitHub issue with user specifications already supplied.
* */
Expand All @@ -355,15 +355,15 @@ public static void handleReportIssue() {
);
issueCreator.create();
}

/**
* Open default browser at the Topsoil Project Page on CIRLDES website.
* */
public static void handleOpenOnlineHelp() {

String TOPSOIL_URL = "http://cirdles.org/projects/topsoil/";
new DesktopWebBrowser(Desktop.getDesktop()).browse(TOPSOIL_URL);

}

/**
Expand Down Expand Up @@ -418,22 +418,24 @@ public static void handleExportTable(TopsoilDataTable table) {
writer = new PrintWriter(location, "UTF-8");
for (int i = 0; i < titles.length; i++) {
writer.print(titles[i]);
if (i < titles.length - 1)
if (i < titles.length - 1) {
writer.print(delim);
}
}
writer.print('\n');
for (int i = 0; i < data.size(); i++) {
for (int j = 0; j < data.get(i).length; j++) {
writer.print(data.get(i)[j]);
if (j < data.get(i).length - 1)
if (j < data.get(i).length - 1) {
writer.print(delim);
}
}
writer.print('\n');
}
writer.close();
}

} catch (FileNotFoundException|UnsupportedEncodingException ex) {
} catch (FileNotFoundException | UnsupportedEncodingException ex) {
Logger.getLogger(MenuItemEventHandler.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (writer != null) {
Expand Down Expand Up @@ -463,7 +465,7 @@ private static void closeAllTabsAndPlots(TopsoilTabPane tabs) {
* @param tabs TopsoilTabPane
*/
public static void handleNewProject(TopsoilTabPane tabs) {
AtomicReference<List<TopsoilDataTable>> tablesReference = new AtomicReference<>();
AtomicReference<List<TopsoilDataTable>> tablesReference = new AtomicReference<>(null);
if (TopsoilSerializer.isProjectOpen()) {
TopsoilNotification.showNotification(
NotificationType.YES_NO,
Expand All @@ -477,7 +479,7 @@ public static void handleNewProject(TopsoilTabPane tabs) {
tablesReference.set(NewProjectWindow.newProject());
}
});
} else if (!tabs.isEmpty()){
} else if (!tabs.isEmpty()) {
TopsoilNotification.showNotification(
NotificationType.VERIFICATION,
"Create New Project",
Expand Down Expand Up @@ -528,7 +530,7 @@ public static void handleOpenProjectFile(TopsoilTabPane tabs) {
NotificationType.VERIFICATION,
"Open Project",
"Opening a Topsoil project will replace your current tables. Continue?")
.ifPresent( response -> {
.ifPresent(response -> {
if (response == ButtonType.OK) {
File file = TopsoilFileChooser.getTopsoilOpenFileChooser().showOpenDialog(StageHelper.getStages().get(0));
openProjectFile(tabs, file);
Expand Down Expand Up @@ -654,7 +656,7 @@ public static boolean handleCloseProjectFile(TopsoilTabPane tabs) {
return didClose.get();
}

// /**
// /**
// * Normalizes the supplied data using the value of the specified {@code UncertaintyFormat}.
// *
// * @param format UncertaintyFormat
Expand All @@ -675,7 +677,7 @@ public static boolean handleCloseProjectFile(TopsoilTabPane tabs) {
private static final String TAB = "Tabs";
private static final String COLON = "Colons";
private static final String SEMICOLON = "Semicolons";

private static final HashMap<String, String> COMMON_DELIMITERS; // Checked against when guessing a delimiter
static {
COMMON_DELIMITERS = new LinkedHashMap<>();
Expand All @@ -684,7 +686,7 @@ public static boolean handleCloseProjectFile(TopsoilTabPane tabs) {
COMMON_DELIMITERS.put(COLON, ":");
COMMON_DELIMITERS.put(SEMICOLON, ";");
}

private static String requestDelimiter() {
String otherDelimiterOption = "Other";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ public String getActionName() {
return "Clear table";
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.cirdles.topsoil.app.util.undo.Command;

/**
* A {@code Command} instance to delete a table.
* A {@code Command} instance to delete a table.
* This {@code Command} stores the the {@link TopsoilTab} that was cleared.
* TO DO : add this command to a TabPane UndoManager to make the command undoable
*
Expand All @@ -26,7 +26,6 @@ public class DeleteTableCommand implements Command {
*/
private final TopsoilTab topsoilTab;


//***********************
// Constructors
//***********************
Expand All @@ -37,16 +36,15 @@ public class DeleteTableCommand implements Command {
* @param topsoilTab the Topsoil Tab that was deleted
*/
public DeleteTableCommand(TopsoilTab topsoilTab) {

this.topsoilTab = topsoilTab;

}

//***********************
// Methods
//***********************


/**
* Asks the user if they really want to delete the open data table.
*
Expand All @@ -68,17 +66,17 @@ public static Boolean confirmDeletion() {

return reference.get();
}

/**
* Called to execute the table deleting.
*/
public void execute() {
if(DeleteTableCommand.confirmDeletion()){
if (DeleteTableCommand.confirmDeletion()) {

TopsoilTabPane topsoilTabPane = (TopsoilTabPane) topsoilTab.getTabPane();
topsoilTabPane.getTabs().remove(topsoilTabPane.getSelectedTab());
}

}

/**
Expand All @@ -95,4 +93,4 @@ public String getActionName() {
return "Delete table";
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.cirdles.topsoil.app.MainWindow;
import org.cirdles.topsoil.app.plot.variable.Variable;
import org.cirdles.topsoil.app.plot.variable.Variables;
import org.cirdles.topsoil.app.tab.TopsoilTab;
import org.cirdles.topsoil.app.tab.TopsoilTabPane;
import org.cirdles.topsoil.app.table.TopsoilDataColumn;
import org.cirdles.topsoil.app.table.TopsoilTableController;
import org.cirdles.topsoil.app.util.dialog.VariableChooserDialog;
import org.cirdles.topsoil.app.util.serialization.PlotInformation;
import org.cirdles.topsoil.plot.Plot;

import java.util.List;
import java.util.Map;

import static java.util.Arrays.asList;

/**
* A class containing a set of methods for handling plot generation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,12 +777,12 @@ public void setProperties(Map<String, Object> plotProperties) {

// If X and Y aren't specified.
if (!tableController.getTable().getVariableAssignments().containsKey(Variables.X)
|| !tableController.getTable().getVariableAssignments().containsKey(Variables.Y)) {
|| !tableController.getTable().getVariableAssignments().containsKey(Variables.Y)) {
tableController.showVariableChooserDialog(asList(Variables.X, Variables.Y));
}

if (tableController.getTable().getVariableAssignments().containsKey(Variables.X)
&& tableController.getTable().getVariableAssignments().containsKey(Variables.Y)) {
&& tableController.getTable().getVariableAssignments().containsKey(Variables.Y)) {
PlotGenerationHandler.handlePlotGenerationForSelectedTab((TopsoilTabPane) generatePlotButton.getScene().lookup
("#TopsoilTabPane"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.cirdles.topsoil.plot.Plot;
import org.cirdles.topsoil.plot.base.BasePlot;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -85,11 +86,7 @@ public List<Variable> getVariables() {
public Plot getPlot() {
try {
return plot.newInstance();
} catch (InstantiationException e) {
System.err.println("Error in plot instantiation: Class must have nullary constructor.");
e.printStackTrace();
} catch (IllegalAccessException e) {
System.err.println("Error in plot instantiation: Class and nullary constructor must be accessible.");
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public TopsoilTab(TopsoilTabContent tabContent, TopsoilTableController tableCont
setTitle(this.actualTitle.get());
});


this.titleLabel = new Label(isotopePrefix + actualTitle.get());
this.titleLabel.setId("Title");
this.titleLabel.setOnMouseClicked(event -> {
Expand Down

0 comments on commit 87074b6

Please sign in to comment.