-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Navigator: Allow keeping the directory structure when exporting files
- Loading branch information
1 parent
25c675f
commit 429baa9
Showing
12 changed files
with
160 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
modules/platform-ui/src/main/java/com/shade/platform/ui/controls/FileChooser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.shade.platform.ui.controls; | ||
|
||
import com.shade.util.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.io.File; | ||
|
||
public class FileChooser extends JFileChooser { | ||
public static final String OPTIONS_CHANGED_PROPERTY = "optionsChanged"; | ||
|
||
private JComponent options; | ||
|
||
@Override | ||
public void approveSelection() { | ||
final File file = getSelectedFile(); | ||
|
||
if (file != null && file.exists() && getDialogType() == SAVE_DIALOG) { | ||
final int result = JOptionPane.showConfirmDialog( | ||
this, | ||
"File '%s' already exists. Do you want to overwrite it?".formatted(file.getName()), | ||
"Confirm", | ||
JOptionPane.OK_CANCEL_OPTION, | ||
JOptionPane.QUESTION_MESSAGE | ||
); | ||
|
||
if (result != JOptionPane.OK_OPTION) { | ||
return; | ||
} | ||
} | ||
|
||
super.approveSelection(); | ||
} | ||
|
||
@Nullable | ||
public JComponent getOptions() { | ||
return options; | ||
} | ||
|
||
public void setOptions(@Nullable JComponent options) { | ||
final JComponent oldValue = this.options; | ||
this.options = options; | ||
firePropertyChange(OPTIONS_CHANGED_PROPERTY, oldValue, options); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
modules/platform-ui/src/main/java/com/shade/platform/ui/controls/plaf/FlatFileChooserUI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.shade.platform.ui.controls.plaf; | ||
|
||
import com.shade.platform.ui.controls.FileChooser; | ||
import com.shade.util.NotNull; | ||
import net.miginfocom.swing.MigLayout; | ||
|
||
import javax.swing.*; | ||
import javax.swing.plaf.ComponentUI; | ||
import java.awt.*; | ||
import java.beans.PropertyChangeEvent; | ||
import java.beans.PropertyChangeListener; | ||
|
||
public class FlatFileChooserUI extends com.formdev.flatlaf.ui.FlatFileChooserUI { | ||
private JComponent optionsPanel; | ||
|
||
public FlatFileChooserUI(JFileChooser fc) { | ||
super(fc); | ||
} | ||
|
||
public static ComponentUI createUI(JComponent c) { | ||
return new FlatFileChooserUI((JFileChooser) c); | ||
} | ||
|
||
@Override | ||
public void installComponents(JFileChooser fc) { | ||
super.installComponents(fc); | ||
|
||
optionsPanel = new JPanel(); | ||
optionsPanel.setLayout(new BorderLayout()); | ||
|
||
// Gaps and insets are defined according to MetalFileChooserUI.ButtonAreaLayout | ||
final JPanel buttonPanel = getButtonPanel(); | ||
buttonPanel.setLayout(new MigLayout("ins 0,gapx 5,ins 17 0 0 0", "push[][fill][fill]")); | ||
buttonPanel.add(optionsPanel, 0); | ||
|
||
if (getFileChooser() instanceof FileChooser fc1 && fc1.getOptions() != null) { | ||
optionsPanel.add(fc1.getOptions(), BorderLayout.CENTER); | ||
} | ||
} | ||
|
||
@Override | ||
public void uninstallComponents(JFileChooser fc) { | ||
super.uninstallComponents(fc); | ||
|
||
optionsPanel = null; | ||
} | ||
|
||
@Override | ||
public PropertyChangeListener createPropertyChangeListener(JFileChooser fc) { | ||
final PropertyChangeListener parent = super.createPropertyChangeListener(fc); | ||
return e -> { | ||
if (e.getPropertyName().equals(FileChooser.OPTIONS_CHANGED_PROPERTY)) { | ||
doOptionsChanged(e); | ||
} else { | ||
parent.propertyChange(e); | ||
} | ||
}; | ||
} | ||
|
||
private void doOptionsChanged(@NotNull PropertyChangeEvent e) { | ||
if (optionsPanel != null) { | ||
if (e.getOldValue() != null) { | ||
optionsPanel.remove((JComponent) e.getOldValue()); | ||
} | ||
if (e.getNewValue() != null) { | ||
optionsPanel.add((JComponent) e.getNewValue(), BorderLayout.CENTER); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters