fileChooser.addChoosableFileFilter(moreFileFilter);
fileChooser.setFileFilter(gifFileFilter);
PropertyChangeListener fileFilterChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
CommonFileFilter ff = (CommonFileFilter) e.getNewValue();
if (!e.getPropertyName().equals(
JFileChooser.FILE_FILTER_CHANGED_PROPERTY))
return;
if (ff.getSuffix().equalsIgnoreCase("more")) {
fileChooser.cancelSelection();
Action action = (Action) graphicalEditorActionMap
.getInterface("exportView");
action
.putValue(
de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.IMAGE_TYPE,
"more");
action
.putValue(
de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.UI_FRAME,
uiJPanel);
action.actionPerformed(null);
((JFileChooser) e.getSource())
.removePropertyChangeListener(
JFileChooser.FILE_FILTER_CHANGED_PROPERTY,
this);
}
}
};
fileChooser.addPropertyChangeListener(
JFileChooser.FILE_FILTER_CHANGED_PROPERTY,
fileFilterChangeListener);
for (;;) {
if (fileChooser.showDialog(uiJPanel, null) == JFileChooser.APPROVE_OPTION) {
imageFile = fileChooser.getSelectedFile();
CommonFileFilter currentFilter = (CommonFileFilter) fileChooser
.getFileFilter();
if (!currentFilter.getSuffix().equalsIgnoreCase(
CommonFileFilter.getSuffix(imageFile))) {
String path = imageFile.getPath() + "."
+ currentFilter.getSuffix();
imageFile = new File(path);
}
if (imageFile.exists()) {
int result_tmp = JOptionPane.showConfirmDialog(
uiJPanel, "�ļ� " + imageFile.getPath()
+ " �Ѿ����ڣ��ǷǸ��ļ���", "ȷ�ϴ���",
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE);
if (result_tmp == JOptionPane.YES_OPTION) {
break;
} else {
continue;
}
}
break;
} else {
break;
}
}
fileChooser.removePropertyChangeListener(
JFileChooser.FILE_FILTER_CHANGED_PROPERTY,
fileFilterChangeListener);
CommonFileFilter selectedFilter = (CommonFileFilter) fileChooser
.getFileFilter();
fileChooser.removeChoosableFileFilter(moreFileFilter);
fileChooser.removeChoosableFileFilter(svgFileFilter);
fileChooser.removeChoosableFileFilter(gifFileFilter);
for (int i = 0; i < oldFilter.length; i++) {
fileChooser.addChoosableFileFilter(oldFilter[i]);
}
fileChooser.setSelectedFile(null);
// end: get the image file's path from user
// begin:
if (imageFile == null)
return;
if (!imageFile.exists()) {
try {
imageFile.createNewFile();
} catch (IOException ioe) {
JOptionPane.showMessageDialog(uiJPanel,
"�������ļ�ʧ��,����洢�豸�Ƿ�������", "���洰��",
JOptionPane.ERROR_MESSAGE);
return;
}
}
// end:
Action action = (Action) graphicalEditorActionMap
.getInterface("exportView");
action
.putValue(
de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.FILE,
imageFile);
action
.putValue(
de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.IMAGE_TYPE,
selectedFilter.getSuffix());
action
.putValue(
de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.UI_FRAME,
uiJPanel);
action.actionPerformed(null);