Added Directory selection dialog in directory configs in advanced settings

This commit is contained in:
Jindra Petřík
2023-11-04 08:35:13 +01:00
parent 0d1e2f1422
commit 388db883d3
3 changed files with 94 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
- Morphshape SVG Export - bitmap fill strokes
- SVG Export/Import - retain bitmap fill smoothed attribute
- Export Morphshape as start and end shape (SVG, PNG, BMP)
- Directory selection dialog in directory configs in advanced settings
### Fixed
- [#1306], [#1768] Maximizing window on other than main monitor

View File

@@ -454,9 +454,12 @@ public class AdvancedSettingsDialog extends AppDialog {
tf.setMaximumSize(new Dimension(Integer.MAX_VALUE, tf.getPreferredSize().height));
c = tf;
if (confFile != null) { //|| confDirectory != null) {
if (confFile != null) {
c = new ConfigurationFileSelection(item, confFile, val.toString(), description);
}
if (confDirectory != null) {
c = new ConfigurationDirectorySelection(item, val.toString(), description);
}
} else if (itemType == Boolean.class) {
JCheckBox cb = new JCheckBox();
cb.setSelected((Boolean) item.get());
@@ -493,6 +496,9 @@ public class AdvancedSettingsDialog extends AppDialog {
if (toLabelComponent instanceof ConfigurationFileSelection) {
toLabelComponent = ((ConfigurationFileSelection) toLabelComponent).getTextField();
}
if (toLabelComponent instanceof ConfigurationDirectorySelection) {
toLabelComponent = ((ConfigurationDirectorySelection) toLabelComponent).getTextField();
}
l.setLabelFor(toLabelComponent);
configPanel.add(c);
} catch (IllegalArgumentException | IllegalAccessException ex) {
@@ -560,6 +566,8 @@ public class AdvancedSettingsDialog extends AppDialog {
Class itemType = (Class<?>) itemType2;
if (c instanceof ConfigurationFileSelection) {
value = ((ConfigurationFileSelection) c).getValue();
} else if (c instanceof ConfigurationDirectorySelection) {
value = ((ConfigurationDirectorySelection) c).getValue();
} else if (name.equals("gui.skin")) {
value = ((SkinSelect) ((JComboBox<SkinSelect>) c).getSelectedItem()).className;
} else if (itemType == String.class) {

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2022-2023 JPEXS
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.configuration.ConfigurationFile;
import com.jpexs.decompiler.flash.configuration.ConfigurationItem;
import com.jpexs.helpers.Helper;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.ResourceBundle;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.filechooser.FileFilter;
/**
*
* @author JPEXS
*/
public class ConfigurationDirectorySelection extends JPanel {
private JTextField textField;
public ConfigurationDirectorySelection(ConfigurationItem item, String value, String description) {
setLayout(new BorderLayout());
textField = new JTextField();
textField.setText(value);
textField.setToolTipText(description);
textField.setMaximumSize(new Dimension(Integer.MAX_VALUE, textField.getPreferredSize().height));
setMaximumSize(new Dimension(Integer.MAX_VALUE, textField.getPreferredSize().height));
add(textField, BorderLayout.CENTER);
JButton butSelect = new JButton(View.getIcon("folderopen16"));
butSelect.setToolTipText(ResourceBundle.getBundle(AppStrings.getResourcePath(MainFrame.class)).getString("FileChooser.openButtonText"));
butSelect.setMargin(new Insets(2, 2, 2, 2));
butSelect.addActionListener((ActionEvent e) -> {
textField.setText(selectConfigDirectory(item, textField.getText()));
});
add(butSelect, BorderLayout.EAST);
}
private static String selectConfigDirectory(ConfigurationItem config, String current) {
JFileChooser fc = new JFileChooser();
fc.setSelectedFile(new File(current));
fc.setMultiSelectionEnabled(false);
fc.setCurrentDirectory(new File((String) config.get()));
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setAcceptAllFileFilterUsed(false);
int returnVal = fc.showOpenDialog(Main.getDefaultMessagesComponent());
if (returnVal == JFileChooser.APPROVE_OPTION) {
return Helper.fixDialogFile(fc.getSelectedFile()).getAbsolutePath();
} else {
return (String) config.get();
}
}
public String getValue() {
return textField.getText();
}
public JTextField getTextField() {
return textField;
}
}