Skip to content

Commit

Permalink
fix: фильтр *.frame.cb.zip в диалоге открытия
Browse files Browse the repository at this point in the history
    Стандартный FileNameExtensionFilter учитывает только расширение
    после последней точки. Для поддержки *.frame.cb.zip введен
    FrameExtensionFilter.
  • Loading branch information
xlam committed Sep 6, 2018
1 parent 8129e74 commit f540ae1
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ru/cyberbiology/test/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
// Тест
// Основной класс программы.
import javax.swing.WindowConstants;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import ru.cyberbiology.test.gene.GeneMutate;

Expand Down Expand Up @@ -405,8 +406,23 @@ public void actionPerformed(ActionEvent e)
JMenuItem loadWorldItem = new JMenuItem("Загрузить мир");
toolsMenu.add(loadWorldItem);
loadWorldItem.addActionListener((ActionEvent e) -> {
// TODO фильтр "*.frame.cb.zip" не работает
FileNameExtensionFilter filter = new FileNameExtensionFilter("*.frame.cb.zip","*.*");
class FrameExtensionFilter extends FileFilter {
private static final String SUFFIX = ".frame.cb.zip";
private final String description;
public FrameExtensionFilter(String description) {
this.description = description;
};
@Override
public boolean accept(File f) {
return f.getName().endsWith(SUFFIX);
}
@Override
public String getDescription() {
return description;
}
}
FrameExtensionFilter filter = new FrameExtensionFilter(
"Сохраненный мир (*.frame.cb.zip)");
JFileChooser fc = new JFileChooser();
fc.setFileFilter(filter);
if (fc.showOpenDialog(window) == JFileChooser.APPROVE_OPTION) {
Expand Down

0 comments on commit f540ae1

Please sign in to comment.