Merge pull request #92 from kruland2607/master
synchronize the drop down with the file name in chooser.
This commit is contained in:
commit
2f0e636489
@ -3,6 +3,8 @@ package net.sf.openrocket.gui;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
@ -29,7 +31,8 @@ public class ExportDecalDialog extends JDialog {
|
||||
|
||||
private final OpenRocketDocument document;
|
||||
|
||||
private JComboBox decalComboBox;
|
||||
private final JComboBox decalComboBox;
|
||||
private final JFileChooser chooser;
|
||||
|
||||
public ExportDecalDialog(Window parent, OpenRocketDocument doc) {
|
||||
super(parent, trans.get("ExportDecalDialog.title"), ModalityType.APPLICATION_MODAL);
|
||||
@ -48,11 +51,26 @@ public class ExportDecalDialog extends JDialog {
|
||||
decalComboBox.setEditable(false);
|
||||
panel.add(decalComboBox, "growx, wrap");
|
||||
|
||||
final JFileChooser chooser = new JFileChooser();
|
||||
chooser = new JFileChooser();
|
||||
chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
|
||||
chooser.setVisible(true);
|
||||
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
|
||||
// Add an item change listener to the decal chooser to detect when the selected image has change
|
||||
decalComboBox.addItemListener(new ItemListener() {
|
||||
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||
updateChoosenDecal();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Call the update to synchronize the boxes on startup.
|
||||
updateChoosenDecal();
|
||||
|
||||
chooser.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@ -88,4 +106,13 @@ public class ExportDecalDialog extends JDialog {
|
||||
JOptionPane.showMessageDialog(this, message, "", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateChoosenDecal() {
|
||||
DecalImage image = (DecalImage) decalComboBox.getSelectedItem();
|
||||
if (image == null) {
|
||||
return;
|
||||
}
|
||||
File fullName = new File(image.getName());
|
||||
chooser.setSelectedFile(new File(fullName.getName()));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user