From 388db883d37aeaa8746335d9badebcf917df64d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 4 Nov 2023 08:35:13 +0100 Subject: [PATCH] Added Directory selection dialog in directory configs in advanced settings --- CHANGELOG.md | 1 + .../flash/gui/AdvancedSettingsDialog.java | 10 ++- .../gui/ConfigurationDirectorySelection.java | 84 +++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/com/jpexs/decompiler/flash/gui/ConfigurationDirectorySelection.java diff --git a/CHANGELOG.md b/CHANGELOG.md index f3c1cb22d..df09ee5a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java b/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java index ca982ce63..d4bd495e8 100644 --- a/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java @@ -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) c).getSelectedItem()).className; } else if (itemType == String.class) { diff --git a/src/com/jpexs/decompiler/flash/gui/ConfigurationDirectorySelection.java b/src/com/jpexs/decompiler/flash/gui/ConfigurationDirectorySelection.java new file mode 100644 index 000000000..c51acaf95 --- /dev/null +++ b/src/com/jpexs/decompiler/flash/gui/ConfigurationDirectorySelection.java @@ -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 . + */ +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; + } + +}