From fb7c0dcf2c90256ae85139870def9f1651ee171b Mon Sep 17 00:00:00 2001 From: Felix Reimann Date: Mon, 26 Mar 2018 23:32:21 +0200 Subject: [PATCH] #10 file annotation has additional optional attributes file and folder if file is true, files can be selected if folder is true, folders can be selected --- .../opt4j/core/config/annotations/File.java | 44 ++++++++++------- .../config/visualization/PropertyPanel.java | 48 +++++++++---------- 2 files changed, 50 insertions(+), 42 deletions(-) diff --git a/opt4j-core/src/main/java/org/opt4j/core/config/annotations/File.java b/opt4j-core/src/main/java/org/opt4j/core/config/annotations/File.java index dcf7d229..5ded675f 100644 --- a/opt4j-core/src/main/java/org/opt4j/core/config/annotations/File.java +++ b/opt4j-core/src/main/java/org/opt4j/core/config/annotations/File.java @@ -1,25 +1,19 @@ /******************************************************************************* * Copyright (c) 2014 Opt4J * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the + * Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ - package org.opt4j.core.config.annotations; @@ -31,8 +25,8 @@ import java.lang.annotation.Target; /** - * The {@link File} annotation marks a {@link String} property as a file such - * that the {@link String} can be changed by a browser. + * The {@link File} annotation marks a {@link String} property as a file such that the {@link String} can be changed by + * a browser. * * @author lukasiewycz * @@ -46,4 +40,18 @@ * @return the file extension string */ String value() default ""; + + /** + * The annotated property is a file. Defaults to {@code true}. + * + * @return {@code true}, if files are selectable + */ + boolean file() default true; + + /** + * The annotated property is a folder. Defaults to {@code false}. + * + * @return {@code true}, if folders are selectable + */ + boolean folder() default false; } diff --git a/opt4j-core/src/main/java/org/opt4j/core/config/visualization/PropertyPanel.java b/opt4j-core/src/main/java/org/opt4j/core/config/visualization/PropertyPanel.java index f4d95ebe..d6a53107 100644 --- a/opt4j-core/src/main/java/org/opt4j/core/config/visualization/PropertyPanel.java +++ b/opt4j-core/src/main/java/org/opt4j/core/config/visualization/PropertyPanel.java @@ -1,23 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Opt4J * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the + * Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ package org.opt4j.core.config.visualization; @@ -64,8 +59,8 @@ import org.opt4j.core.config.annotations.File; /** - * The {@link PropertyPanel} is a panel for the configuration of one module. - * Properties and values are arranged in a table. + * The {@link PropertyPanel} is a panel for the configuration of one module. Properties and values are arranged in a + * table. * * @author lukasiewycz * @@ -84,8 +79,7 @@ public class PropertyPanel extends JPanel { protected final Map components = new HashMap(); /** - * Constructs a {@link PropertyPanel} for one {@link PropertyModule} - * instance. + * Constructs a {@link PropertyPanel} for one {@link PropertyModule} instance. * * @param module * the instance of the {@link PropertyModule} @@ -288,9 +282,8 @@ public void actionPerformed(ActionEvent e) { } /** - * Adds a row showing the {@link Citation}. On the left hand side, - * "reference" is printed while on the right hand side, the {@link Citation} - * is added in a static {@link TextArea}. + * Adds a row showing the {@link Citation}. On the left hand side, "reference" is printed while on the right hand + * side, the {@link Citation} is added in a static {@link TextArea}. * * @param citation * the citation to add @@ -310,8 +303,6 @@ protected void addReferenceRow(Citation citation) { field.setBackground(label.getBackground()); field.setEditable(false); field.setText(Format.formatJava(citation)); - System.out.println("title: " + citation.title()); - System.out.println("formatJava: " + Format.formatJava(citation)); if (!citation.doi().isEmpty()) { final String doi = citation.doi(); @@ -421,6 +412,15 @@ public String getDescription() { fileChooser.setFileFilter(null); } + if (file.folder()) { + if (file.file()) { + fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + } else { + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + } + } else { + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + } fileChooser.setVisible(true); int status = fileChooser.showOpenDialog(null);