Browse Source

REPORT-28383 设计器菜单栏-文件-输出

feature/big-screen
hades 5 years ago
parent
commit
dca98b2582
  1. 26
      designer-base/src/main/java/com/fr/file/filter/ChooseFileFilter.java
  2. 10
      designer-base/src/test/java/com/fr/file/FILEChooserPaneTest.java
  3. 33
      designer-base/src/test/java/com/fr/file/filter/ChooseFileFilterTest.java

26
designer-base/src/main/java/com/fr/file/filter/ChooseFileFilter.java

@ -4,6 +4,8 @@ import com.fr.base.extension.FileExtension;
import com.fr.file.FILE; import com.fr.file.FILE;
import com.fr.file.FileFILE; import com.fr.file.FileFILE;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.stable.CoreConstants;
import com.fr.stable.StringUtils;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
import java.io.File; import java.io.File;
@ -275,25 +277,25 @@ public class ChooseFileFilter extends FileFilter implements FILEFilter, java.io.
} }
/** /**
* 默认情况下 返回首位的后缀名
* get extention. * get extention.
*/ */
public String getExtensionString() { public String getExtensionString() {
if (filters == null) { return getExtensionString(0);
return "";
} }
StringBuffer extsb = new StringBuffer("."); public String getExtensionString(int index) {
if (filters == null || filters.isEmpty() || index >= filters.size()) {
// Enumeration keys = filters.keys(); return StringUtils.EMPTY;
// while (keys.hasMoreElements()) { }
// extsb.append((String) keys.nextElement()); return CoreConstants.DOT + filters.get(index);
// }
for (int i = 0; i < filters.size(); i++) {
extsb.append(filters.get(i));
} }
return extsb.toString(); public int getExtensionCount() {
if (filters == null || filters.isEmpty()) {
return 0;
}
return filters.size();
} }
/** /**

10
designer-base/src/test/java/com/fr/file/FILEChooserPaneTest.java

@ -39,6 +39,16 @@ public class FILEChooserPaneTest {
String result6 = Reflect.on(chooserPane).call("calProperFileName", "WorkBook1.xls", chooseFileFilter6).get(); String result6 = Reflect.on(chooserPane).call("calProperFileName", "WorkBook1.xls", chooseFileFilter6).get();
Assert.assertEquals("WorkBook1.xls.cpt", result6); Assert.assertEquals("WorkBook1.xls.cpt", result6);
ChooseFileFilter chooseFileFilter7 = new ChooseFileFilter(FileExtension.XLS, StringUtils.EMPTY);
chooseFileFilter7.addExtension(".xlsx");
String result7 = Reflect.on(chooserPane).call("calProperFileName", "WorkBook1", chooseFileFilter7).get();
Assert.assertEquals("WorkBook1.xls", result7);
ChooseFileFilter chooseFileFilter8 = new ChooseFileFilter(FileExtension.XLSX, StringUtils.EMPTY);
chooseFileFilter8.addExtension(".xls");
String result8 = Reflect.on(chooserPane).call("calProperFileName", "WorkBook1", chooseFileFilter8).get();
Assert.assertEquals("WorkBook1.xlsx", result8);
} }
} }

33
designer-base/src/test/java/com/fr/file/filter/ChooseFileFilterTest.java

@ -0,0 +1,33 @@
package com.fr.file.filter;
import com.fr.base.extension.FileExtension;
import com.fr.stable.CoreConstants;
import com.fr.stable.StringUtils;
import junit.framework.TestCase;
import org.junit.Assert;
/**
* @author hades
* @version 10.0
* Created by hades on 2020/3/18
*/
public class ChooseFileFilterTest extends TestCase {
public void testGetExtensionString() {
ChooseFileFilter chooseFileFilter = new ChooseFileFilter(FileExtension.XLSX, StringUtils.EMPTY);
chooseFileFilter.addExtension(FileExtension.XLS.getExtension());
Assert.assertEquals(CoreConstants.DOT + FileExtension.XLSX.getExtension(), chooseFileFilter.getExtensionString());
Assert.assertEquals(CoreConstants.DOT + FileExtension.XLS.getExtension(), chooseFileFilter.getExtensionString(1));
ChooseFileFilter chooseFileFilter1 = new ChooseFileFilter();
Assert.assertEquals(StringUtils.EMPTY, chooseFileFilter1.getExtensionString());
Assert.assertEquals(StringUtils.EMPTY, chooseFileFilter1.getExtensionString(1));
}
public void testGetExtensionCount() {
ChooseFileFilter chooseFileFilter = new ChooseFileFilter(FileExtension.CPT, StringUtils.EMPTY);
chooseFileFilter.addExtension(FileExtension.CPTX.getExtension());
Assert.assertEquals(2, chooseFileFilter.getExtensionCount());
}
}
Loading…
Cancel
Save