Skip to content

Commit

Permalink
wip FileChooserComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
clagomess committed Mar 11, 2024
1 parent e3ae152 commit 3669ab7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import javax.swing.*;
import java.io.File;
import java.util.prefs.Preferences;

public class FileChooserComponent extends JPanel {
private final JTextField text = new JTextField();
Expand All @@ -23,17 +24,24 @@ public FileChooserComponent(){

public FileChooserComponent(String label){
setLayout(new MigLayout("insets 0 0 0 0", "[grow,fill]"));
text.setEditable(false);
button = new JButton(label);

Preferences prefs = Preferences.userRoot().node(getClass().getName());

button.addActionListener(l -> {
JFileChooser fc = new JFileChooser();
JFileChooser fc = new JFileChooser(prefs.get("LAST_USED_FOLDER", ""));
config.apply(fc);

int ret = fc.showOpenDialog(null);
if(ret == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null){
text.setText(fc.getSelectedFile().getAbsolutePath());
value = fc.getSelectedFile();

if(fc.getSelectedFile().isDirectory()){
prefs.put("LAST_USED_FOLDER", fc.getSelectedFile().getAbsolutePath());
}else{
prefs.put("LAST_USED_FOLDER", fc.getSelectedFile().getParentFile().getAbsolutePath());
}
}
});

Expand All @@ -48,6 +56,7 @@ public void reset(){
}

public void setEnabled(boolean enabled){
this.text.setEditable(enabled);
this.button.setEnabled(enabled);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class MainForm {
new RadioButtonGroupComponent.RadioButton<>("Closed", HtmlPanelToggleEnum.CLOSED)
));

public final JCheckBox chkEmbedImages = new JCheckBox();
public final JCheckBox chkEmbedImages = new JCheckBox(){{setSelected(true);}};
public final ColorChooserComponent ccMenuColor = new ColorChooserComponent(
"Menu Color",
defaultDto.getMenuColor()
Expand All @@ -84,4 +84,6 @@ public class MainForm {
new RadioButtonGroupComponent.RadioButton<>(LayoutPdfEnum.PORTRAIT, true),
new RadioButtonGroupComponent.RadioButton<>(LayoutPdfEnum.LANDSCAPE)
));

public final JButton btnCompile = new JButton("Compile!");
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ public MainUI() {
pTabArtifact.addTab("PDF", pPdf);
add(pTabArtifact, "wrap");

/*
JPanel pProgress = new JPanel(new MigLayout("", "[grow,fill]"));
pProgress.setBorder(BorderFactory.createTitledBorder("Progress"));
pProgress.add(new JProgressBar(), "wrap");
pProgress.add(new JTextArea(), "wrap");
add(pProgress);
*/

add(form.btnCompile);
getRootPane().setDefaultButton(form.btnCompile);

pack();
setLocationRelativeTo(null);
Expand Down

0 comments on commit 3669ab7

Please sign in to comment.