Browse Source

REPORT-5208 使用文件扩展名枚举

master
vito 7 years ago
parent
commit
3cac7d1710
  1. 2
      designer-base/src/com/fr/design/mainframe/App.java
  2. 2
      designer-base/src/com/fr/design/mainframe/DesignerFrame.java
  3. 2
      designer-base/src/com/fr/design/mainframe/JTemplate.java
  4. 169
      designer-base/src/com/fr/file/FILEChooserPane.java
  5. 103
      designer-base/src/com/fr/file/filter/ChooseFileFilter.java
  6. 12
      designer-chart/src/com/fr/file/FILEChooserPane4Chart.java
  7. 2
      designer-form/src/com/fr/design/module/FormDesignerModule.java
  8. 3
      designer-realize/src/com/fr/design/actions/file/export/AbstractExportAction.java
  9. 7
      designer-realize/src/com/fr/design/actions/file/export/CSVExportAction.java
  10. 7
      designer-realize/src/com/fr/design/actions/file/export/EmbeddedExportExportAction.java
  11. 5
      designer-realize/src/com/fr/design/actions/file/export/PDFExportAction.java
  12. 19
      designer-realize/src/com/fr/design/actions/file/export/PageToSheetExcelExportAction.java
  13. 17
      designer-realize/src/com/fr/design/actions/file/export/SVGExportAction.java
  14. 17
      designer-realize/src/com/fr/design/actions/file/export/TextExportAction.java
  15. 17
      designer-realize/src/com/fr/design/actions/file/export/WordExportAction.java
  16. 17
      designer-realize/src/com/fr/design/module/DesignerModule.java

2
designer-base/src/com/fr/design/mainframe/App.java

@ -18,7 +18,7 @@ public interface App<T extends BaseBook> extends Mutable, Aftermath {
*
* @return 类型
*/
String[] defaultExtentions();
String[] defaultExtensions();
/**
* 打开模板

2
designer-base/src/com/fr/design/mainframe/DesignerFrame.java

@ -855,7 +855,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta
String fileExtention = fileName.substring(indexOfLastDot + 1);
for (int i = 0, len = appList.size(); i < len; i++) {
App<?> app = appList.get(i);
String[] defaultAppExtentions = app.defaultExtentions();
String[] defaultAppExtentions = app.defaultExtensions();
boolean opened = false;
for (int j = 0; j < defaultAppExtentions.length; j++) {
if (defaultAppExtentions[j].equalsIgnoreCase(fileExtention)) {

2
designer-base/src/com/fr/design/mainframe/JTemplate.java

@ -626,7 +626,7 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
}
protected FILEChooserPane getFILEChooserPane(boolean isShowLoc) {
return new FILEChooserPane(true, isShowLoc);
return FILEChooserPane.getInstance(true, isShowLoc);
}
protected boolean saveFile() {

169
designer-base/src/com/fr/file/FILEChooserPane.java

@ -1,6 +1,7 @@
package com.fr.file;
import com.fr.base.BaseUtils;
import com.fr.base.extension.FileExtension;
import com.fr.base.FRContext;
import com.fr.dav.LocalEnv;
import com.fr.design.DesignerEnvManager;
@ -25,19 +26,60 @@ import com.fr.file.filter.FILEFilter;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralContext;
import com.fr.general.Inter;
import com.fr.stable.*;
import com.fr.stable.CoreConstants;
import com.fr.stable.OperatingSystem;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import javax.swing.*;
import javax.swing.AbstractAction;
import javax.swing.AbstractListModel;
import javax.swing.ActionMap;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileSystemView;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicButtonUI;
import java.awt.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Insets;
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.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -46,6 +88,7 @@ import java.util.regex.Pattern;
* FileChooserPane要高亮显示某Button,以显示当前路径
* 边距要调整
* postfix还没有处理
* 该文件选择器整理行为如下
*/
public class FILEChooserPane extends BasicPane {
/**
@ -180,6 +223,7 @@ public class FILEChooserPane extends BasicPane {
// transfer focus to CurrentEditor
inputMapAncestor.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "dialogExit");
actionMap.put("dialogExit", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent evt) {
returnValue = CANCEL_OPTION;
dialogExit();
@ -240,17 +284,20 @@ public class FILEChooserPane extends BasicPane {
new double[]{TableLayout.PREFERRED, TableLayout.FILL});
this.add(contentPane, BorderLayout.CENTER);
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
doOK();
}
});
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
returnValue = CANCEL_OPTION;
doCancel();
}
});
fileNameTextField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
returnValue = CANCEL_OPTION;
@ -356,6 +403,7 @@ public class FILEChooserPane extends BasicPane {
/**
* 删除文件过滤器
* 这命名太乱了完全是误导
*
* @param filter 过滤
*/
@ -392,7 +440,7 @@ public class FILEChooserPane extends BasicPane {
*/
public void setFileNameTextField(String text, String suffix) {
if (StringUtils.isEmpty(suffix)) {
suffix = ".cpt";
suffix = FileExtension.CPT.getSuffix();
}
this.suffix = suffix;
@ -428,7 +476,7 @@ public class FILEChooserPane extends BasicPane {
* @return 类型
*/
public int showOpenDialog(Component parent) {
return showOpenDialog(parent, ".cpt");
return showOpenDialog(parent, FileExtension.CPT.getSuffix());
}
/**
@ -449,7 +497,7 @@ public class FILEChooserPane extends BasicPane {
* @return 类型
*/
public int showSaveDialog(Component parent) {
return showSaveDialog(parent, ".cpt");
return showSaveDialog(parent, FileExtension.CPT.getSuffix());
}
/**
@ -482,10 +530,12 @@ public class FILEChooserPane extends BasicPane {
okButton.setText(dialogName());
// kel:打开界面的时候让文本域获得焦点,支持enter打开或保存。
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowActivated(WindowEvent e) {
fileNameTextField.requestFocusInWindow();
}
@Override
public void windowClosing(WindowEvent e) {
returnValue = CANCEL_OPTION;
dialogExit();
@ -494,7 +544,7 @@ public class FILEChooserPane extends BasicPane {
// neil:默认打开pane里显示所有支持的格式
// daniel 从templateFileTree中取
if (!showWebReport) {
if (!showWebReport && filterList.isEmpty()) {
fileType();
}
chooseType();
@ -514,49 +564,48 @@ public class FILEChooserPane extends BasicPane {
protected void fileType() {
String appName = ProductConstants.APP_NAME;
JTemplate editing = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate();
if (ComparatorUtils.equals(suffix, ".crt")) {
this.addChooseFILEFilter(new ChooseFileFilter("crt", appName + Inter.getLocText(new String[]{"Utils-The-Chart", "FR-App-All_File"})));
if (FileExtension.CRT.matchExtension(suffix)) {
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.CRT, appName + Inter.getLocText(new String[]{"Utils-The-Chart", "FR-App-All_File"})));
return;
}
if (editing == null || !editing.isChartBook()) {
String[] fileSuffix_local = LocalEnv.FILE_TYPE;
String[] fileSuffix = {"cpt", "cptx", "frm", "form", "cht", "chart"};
EnumSet<FileExtension> fileExtensions = EnumSet.of(FileExtension.CPT, FileExtension.CPTX, FileExtension.FRM, FileExtension.FRMX, FileExtension.CHT);
if (type == JFileChooser.OPEN_DIALOG) {
if (FRContext.getCurrentEnv().isSupportLocalFileOperate()) { //本地连接
this.addChooseFILEFilter(new ChooseFileFilter(fileSuffix_local, appName + Inter.getLocText(new String[]{"FR-App-Report_Template", "FR-App-All_File"})));
} else {
this.addChooseFILEFilter(new ChooseFileFilter(fileSuffix, appName + Inter.getLocText(new String[]{"FR-App-Report_Template", "FR-App-All_File"})));
this.addChooseFILEFilter(new ChooseFileFilter(fileExtensions, appName + Inter.getLocText(new String[]{"FR-App-Report_Template", "FR-App-All_File"})));
}
}
// ben:filefilter设置初值为cpt过滤
this.addChooseFILEFilter(new ChooseFileFilter("cpt", appName + Inter.getLocText(new String[]{"FR-App-Report_Template", "FR-App-All_File"})));
this.addChooseFILEFilter(new ChooseFileFilter("cptx", appName + Inter.getLocText(new String[]{"FR-App-Report_Template", "FR-App-All_File"})));
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.CPT, appName + Inter.getLocText(new String[]{"FR-App-Report_Template", "FR-App-All_File"})));
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.CPTX, appName + Inter.getLocText(new String[]{"FR-App-Report_Template", "FR-App-All_File"})));
// richer:form文件 daniel 改成三个字
this.addChooseFILEFilter(new ChooseFileFilter("frm", appName + Inter.getLocText(new String[]{"FR-App-Template_Form", "FR-App-All_File"})));
this.addChooseFILEFilter(new ChooseFileFilter("form", appName + Inter.getLocText(new String[]{"FR-App-Template_Form", "FR-App-All_File"})));
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.FRM, appName + Inter.getLocText(new String[]{"FR-App-Template_Form", "FR-App-All_File"})));
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.FRMX, appName + Inter.getLocText(new String[]{"FR-App-Template_Form", "FR-App-All_File"})));
} else {
String[] fileSuffix_local = {"xls", "xlsx"};
if (type == JFileChooser.OPEN_DIALOG) {
this.addChooseFILEFilter(new ChooseFileFilter(fileSuffix_local, Inter.getLocText("Import-Excel_Source")));
this.addChooseFILEFilter(new ChooseFileFilter(EnumSet.of(FileExtension.XLS, FileExtension.XLSX), Inter.getLocText("Import-Excel_Source")));
}
}
// 添加 xls 文件类型过滤 kt
if (FRContext.getCurrentEnv().isSupportLocalFileOperate()) { //本地连接
this.addChooseFILEFilter(new ChooseFileFilter("xls", Inter.getLocText("Import-Excel_Source")));
this.addChooseFILEFilter(new ChooseFileFilter("xlsx", Inter.getLocText("Import-Excel2007_Source")));
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.XLS, Inter.getLocText("Import-Excel_Source")));
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.XLSX, Inter.getLocText("Import-Excel2007_Source")));
}
if (ComparatorUtils.equals(suffix, ".png")) {
this.addChooseFILEFilter(new ChooseFileFilter("png", Inter.getLocText("FR-App-Export_png")));
if (FileExtension.PNG.matchExtension(suffix)) {
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.PNG, Inter.getLocText("FR-App-Export_png")));
}
if (type == JFileChooser.SAVE_DIALOG) {
this.addChooseFILEFilter(new ChooseFileFilter("pdf", Inter.getLocText("FR-Import-Export_PDF")));
this.addChooseFILEFilter(new ChooseFileFilter("svg", Inter.getLocText("FR-Import-Export_SVG")));
this.addChooseFILEFilter(new ChooseFileFilter("csv", Inter.getLocText("FR-Import-Export_CSV")));
this.addChooseFILEFilter(new ChooseFileFilter("doc", Inter.getLocText("FR-Import-Export_Word")));
this.addChooseFILEFilter(new ChooseFileFilter("txt", Inter.getLocText("FR-Import-Export_Text")));
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.PDF, Inter.getLocText("FR-Import-Export_PDF")));
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.SVG, Inter.getLocText("FR-Import-Export_SVG")));
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.CSV, Inter.getLocText("FR-Import-Export_CSV")));
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.DOC, Inter.getLocText("FR-Import-Export_Word")));
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.TXT, Inter.getLocText("FR-Import-Export_Text")));
}
}
@ -564,8 +613,8 @@ public class FILEChooserPane extends BasicPane {
private void chooseType() {
DefaultComboBoxModel defaultComboBoxModel = (DefaultComboBoxModel) postfixComboBox.getModel();
defaultComboBoxModel.removeAllElements();
for (int i = 0; i < filterList.size(); i++) {
defaultComboBoxModel.addElement(filterList.get(i));
for (FILEFilter aFilterList : filterList) {
defaultComboBoxModel.addElement(aFilterList);
}
if (FRContext.getCurrentEnv().isSupportLocalFileOperate()) { //本地连接
if (!showWebReport) {
@ -578,38 +627,22 @@ public class FILEChooserPane extends BasicPane {
defaultComboBoxModel.setSelectedItem(filterList.get(0));
}
// richer:根据不同的文件类型显示不同的后缀名
if (ComparatorUtils.equals(suffix, ".cpt")) {
postfixComboBox.setSelectedIndex(suffixIndex("cpt"));
} else if (ComparatorUtils.equals(suffix, ".cptx")) {
postfixComboBox.setSelectedIndex(suffixIndex("cptx"));
} else if (ComparatorUtils.equals(suffix, ".frm") || ComparatorUtils.equals(suffix, ".form")) {
// postfixComboBox.setSelectedIndex(2);
// daniel 改成三个字保证兼容
// 现在默认用的是".frm"
postfixComboBox.setSelectedIndex(suffixIndex("frm"));
} else if (ComparatorUtils.equals(suffix, ".xls")) {
postfixComboBox.setSelectedIndex(suffixIndex("xls"));
} else if (ComparatorUtils.equals(suffix, ".xlsx")) {
postfixComboBox.setSelectedIndex(suffixIndex("xlsx"));
} else if (ComparatorUtils.equals(suffix, ".pdf")) {
postfixComboBox.setSelectedIndex(suffixIndex("pdf"));
} else if (ComparatorUtils.equals(suffix, ".svg")) {
postfixComboBox.setSelectedIndex(suffixIndex("svg"));
} else if (ComparatorUtils.equals(suffix, ".csv")) {
postfixComboBox.setSelectedIndex(suffixIndex("csv"));
} else if (ComparatorUtils.equals(suffix, ".doc")) {
postfixComboBox.setSelectedIndex(suffixIndex("doc"));
} else if (ComparatorUtils.equals(suffix, ".txt")) {
postfixComboBox.setSelectedIndex(suffixIndex("txt"));
} else if (ComparatorUtils.equals(suffix, ".png")) {
postfixComboBox.setSelectedIndex(suffixIndex("png"));
EnumSet<FileExtension> fileExtensions = EnumSet.of(
FileExtension.CPT, FileExtension.CPTX, FileExtension.FRM, FileExtension.FRMX,
FileExtension.XLS, FileExtension.XLSX, FileExtension.PDF, FileExtension.SVG,
FileExtension.CSV, FileExtension.DOC, FileExtension.TXT, FileExtension.PNG);
for (FileExtension fileExtension : fileExtensions) {
if (fileExtension.matchExtension(suffix)) {
postfixComboBox.setSelectedIndex(suffixIndex(fileExtension.getExtension()));
break;
}
}
//jerry 26216 只保留.cpt .frm有用的格式,并且不可编辑
// if (type == JFileChooser.OPEN_DIALOG) {
// postfixComboBox.setEnabled(true);
// } else {
// postfixComboBox.setEnabled(false);
// }
if (type == JFileChooser.OPEN_DIALOG) {
postfixComboBox.setEnabled(true);
} else {
postfixComboBox.setEnabled(false);
}
//只有一个类型时不可下拉
if (filterList.size() == 1) {
@ -749,6 +782,7 @@ public class FILEChooserPane extends BasicPane {
}
}
@Override
protected String title4PopupWindow() {
return dialogName();
}
@ -761,6 +795,7 @@ public class FILEChooserPane extends BasicPane {
PlaceListModel() {
if (FILEChooserPane.this.showEnv) {
envFILE = new FileNodeFILE(new FileNode(ProjectConstants.REPORTLETS_NAME, true)) {
@Override
public String getName() {
return getEnvProjectName();
}
@ -871,6 +906,7 @@ public class FILEChooserPane extends BasicPane {
private ListCellRenderer placelistRenderer = new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
@ -898,6 +934,7 @@ public class FILEChooserPane extends BasicPane {
*/
private ListCellRenderer listRenderer = new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
@ -920,6 +957,7 @@ public class FILEChooserPane extends BasicPane {
};
// placeList listener
ListSelectionListener placeListener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
Object selValue = placesList.getSelectedValue();
if (selValue instanceof FILE) {
@ -932,6 +970,7 @@ public class FILEChooserPane extends BasicPane {
* placeList mouseListener
*/
private MouseListener placeMouseListener = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
Object selValue = placesList.getSelectedValue();
if (selValue instanceof FILE) {
@ -944,6 +983,7 @@ public class FILEChooserPane extends BasicPane {
* right list.
*/
private KeyListener subFileListKeyListener = new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
Object source = e.getSource();
if (!(source instanceof JList)) {
@ -973,6 +1013,7 @@ public class FILEChooserPane extends BasicPane {
* 鼠标点击JList时的listener
*/
private MouseListener subFileListMouseListener = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
Object source = e.getSource();
if (!(source instanceof JList)) {
@ -1114,11 +1155,13 @@ public class FILEChooserPane extends BasicPane {
this.setLayout(FRGUIPaneFactory.createBoxFlowLayout());
leftArrowButton = new BasicArrowButton(BasicArrowButton.WEST) {
@Override
public Dimension getPreferredSize() {
return new Dimension(21, 21);
}
};
leftArrowButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (pathIndex > 0) {
pathIndex--;
@ -1129,11 +1172,13 @@ public class FILEChooserPane extends BasicPane {
});
rightArrowButton = new BasicArrowButton(BasicArrowButton.EAST) {
@Override
public Dimension getPreferredSize() {
return new Dimension(21, 21);
}
};
rightArrowButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (pathIndex < maxPathIndex) {
pathIndex++;
@ -1212,6 +1257,7 @@ public class FILEChooserPane extends BasicPane {
}
// doLayout
@Override
public void doLayout() {
this.removeAll();
@ -1310,6 +1356,7 @@ public class FILEChooserPane extends BasicPane {
this.dir = file;
}
@Override
public void actionPerformed(ActionEvent evt) {
if (dir != null) {
setSelectedDirectory(dir);
@ -1338,18 +1385,21 @@ public class FILEChooserPane extends BasicPane {
repaint();
}
@Override
public void mouseExited(MouseEvent e) {
blankButton.setBackground(FILEChooserPane.this.getBackground().darker());
blankButton.setBorderPainted(false);
repaint();
}
@Override
public void mousePressed(MouseEvent e) {
blankButton.setBackground(FILEChooserPane.this.getBackground().brighter());
blankButton.setBorderPainted(false);
repaint();
}
@Override
public void mouseReleased(MouseEvent e) {
blankButton.setBackground(FILEChooserPane.this.getBackground().brighter());
blankButton.setBorderPainted(true);
@ -1363,6 +1413,7 @@ public class FILEChooserPane extends BasicPane {
private ActionListener createFolderActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
if (currentDirectory == null) {
return;

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

@ -1,16 +1,17 @@
package com.fr.file.filter;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.swing.filechooser.FileFilter;
import com.fr.base.extension.FileExtension;
import com.fr.file.FILE;
import com.fr.file.FileFILE;
import com.fr.general.ComparatorUtils;
public class ChooseFileFilter extends FileFilter implements FILEFilter , java.io.FileFilter {
import javax.swing.filechooser.FileFilter;
import java.io.File;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
public class ChooseFileFilter extends FileFilter implements FILEFilter, java.io.FileFilter {
private List<String> filters = null;
private String description = null;
private String fullDescription = null;
@ -19,7 +20,7 @@ public class ChooseFileFilter extends FileFilter implements FILEFilter , java.io
private boolean isExtend = false;
public ChooseFileFilter() {
if (filters==null) {
if (filters == null) {
this.filters = new ArrayList<String>();
}
}
@ -51,9 +52,51 @@ public class ChooseFileFilter extends FileFilter implements FILEFilter , java.io
public ChooseFileFilter(String[] filters, String description) {
this();
for (int i = 0; i < filters.length; i++) {
for (String filter : filters) {
// add filters one by one
addExtension(filters[i]);
addExtension(filter);
}
if (description != null) {
setDescription(description);
}
}
public ChooseFileFilter(FileExtension extension) {
this(extension, null);
}
public ChooseFileFilter(FileExtension extension, String description) {
this();
if (extension != null) {
addExtension(extension.getExtension());
}
if (description != null) {
setDescription(description);
}
}
/**
* 使用指定枚举类集合构建文件过滤器
*
* @param filters 文件扩展名枚举类集合
*/
public ChooseFileFilter(EnumSet<FileExtension> filters) {
this(filters, null);
}
/**
* 使用指定枚举类集合构建文件过滤器
*
* @param filters 文件扩展名枚举类集合
* @param description 描述
*/
public ChooseFileFilter(EnumSet<FileExtension> filters, String description) {
this();
for (FileExtension filter : filters) {
addExtension(filter.getExtension());
}
if (description != null) {
@ -64,9 +107,11 @@ public class ChooseFileFilter extends FileFilter implements FILEFilter , java.io
/**
* 是否支持改文档
*
* @param f 文件
* @return 支持返回true
*/
@Override
public boolean accept(File f) {
if (f != null) {
if (this.filters == null) { //all file types.
@ -89,9 +134,11 @@ public class ChooseFileFilter extends FileFilter implements FILEFilter , java.io
/**
* 是否支持
*
* @param f 文件
* @return 支持返回 true
*/
@Override
public boolean accept(FILE f) {
if (f != null) {
if (this.filters == null) { //all file types.
@ -130,7 +177,7 @@ public class ChooseFileFilter extends FileFilter implements FILEFilter , java.io
if (f != null) {
String filename = f.getName();
if (f instanceof FileFILE) {
filename = ((FileFILE)f).getTotalName();
filename = ((FileFILE) f).getTotalName();
}
int i = filename.lastIndexOf('.');
@ -144,6 +191,7 @@ public class ChooseFileFilter extends FileFilter implements FILEFilter , java.io
/**
* 加扩展
*
* @param extension 扩展
*/
public void addExtension(String extension) {
@ -160,13 +208,16 @@ public class ChooseFileFilter extends FileFilter implements FILEFilter , java.io
/**
* 是否包含该扩展
* @param extension 扩展
*
* @param extension 扩展
* @return 是则返回true
*/
public boolean containsExtension(String extension){
return filters.contains(extension.toLowerCase());
@Override
public boolean containsExtension(String extension) {
return filters.contains(extension.toLowerCase());
}
@Override
public String getDescription() {
if (this.filters == null) { //all file types.
return fullDescription;
@ -187,11 +238,11 @@ public class ChooseFileFilter extends FileFilter implements FILEFilter , java.io
// }
// }
if (!filters.isEmpty()){
fullDescription += "." + filters.get(0);
for (int i=1;i<filters.size();i++){
fullDescription += ", ." + filters.get(i);
}
if (!filters.isEmpty()) {
fullDescription += "." + filters.get(0);
for (int i = 1; i < filters.size(); i++) {
fullDescription += ", ." + filters.get(i);
}
}
fullDescription += ")";
@ -216,6 +267,7 @@ public class ChooseFileFilter extends FileFilter implements FILEFilter , java.io
/**
* 扩展是否列在描述之内了
*
* @return 是则返回true
*/
public boolean isExtensionListInDescription() {
@ -237,8 +289,8 @@ public class ChooseFileFilter extends FileFilter implements FILEFilter , java.io
// extsb.append((String) keys.nextElement());
// }
for(int i=0;i<filters.size();i++){
extsb.append(filters.get(i));
for (int i = 0; i < filters.size(); i++) {
extsb.append(filters.get(i));
}
return extsb.toString();
@ -246,15 +298,18 @@ public class ChooseFileFilter extends FileFilter implements FILEFilter , java.io
/**
* toString方便重写
*
* @return 重写
*/
@Override
public String toString() {
return getDescription();
return getDescription();
}
@Override
public boolean equals(Object o) {
return (o instanceof ChooseFileFilter)
&& ComparatorUtils.equals(((ChooseFileFilter)o).getDescription(),getDescription());
return (o instanceof ChooseFileFilter)
&& ComparatorUtils.equals(((ChooseFileFilter) o).getDescription(), getDescription());
}
}

12
designer-chart/src/com/fr/file/FILEChooserPane4Chart.java

@ -1,7 +1,7 @@
package com.fr.file;
import com.fr.base.extension.FileExtension;
import com.fr.file.filter.ChooseFileFilter;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.stable.ProductConstants;
@ -12,7 +12,7 @@ import com.fr.stable.ProductConstants;
*/
public class FILEChooserPane4Chart extends FILEChooserPane {
private static final FILEChooserPane4Chart INSTANCE = new FILEChooserPane4Chart(true,true);
private static final FILEChooserPane4Chart INSTANCE = new FILEChooserPane4Chart(true, true);
/**
* @param showEnv
@ -36,15 +36,17 @@ public class FILEChooserPane4Chart extends FILEChooserPane {
super(showEnv, showLoc);
}
@Override
protected void fileType() {
String appName = ProductConstants.APP_NAME;
if(ComparatorUtils.equals(suffix, ".crt")){
this.addChooseFILEFilter(new ChooseFileFilter("crt", appName + Inter.getLocText(new String[]{"Utils-The-Chart", "FR-App-All_File"})));
if (FileExtension.CRT.matchExtension(suffix)) {
this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.CRT, appName + Inter.getLocText(new String[]{"Utils-The-Chart", "FR-App-All_File"})));
return;
}
}
protected String getEnvProjectName(){
@Override
protected String getEnvProjectName() {
return Inter.getLocText("FR-Chart-Env_Directory");
}

2
designer-form/src/com/fr/design/module/FormDesignerModule.java

@ -57,7 +57,7 @@ public class FormDesignerModule extends DesignModule {
return new App[]{new AbstractAppProvider<Form>() {
@Override
public String[] defaultExtentions() {
public String[] defaultExtensions() {
return new String[]{"frm", "form"};
}

3
designer-realize/src/com/fr/design/actions/file/export/AbstractExportAction.java

@ -57,6 +57,7 @@ public abstract class AbstractExportAction extends JWorkBookAction {
/**
* 执行方法
*/
@Override
public void actionPerformed(ActionEvent e) {
JWorkBook jwb = this.getEditingComponent();
FILE editingFILE = jwb.getEditingFILE();
@ -80,7 +81,7 @@ public abstract class AbstractExportAction extends JWorkBookAction {
// Choose a file name....
FILEChooserPane fileChooserPane = FILEChooserPane.getInstance(true, true);
fileChooserPane.setFILEFilter(this.getChooseFileFilter());
fileChooserPane.addChooseFILEFilter(this.getChooseFileFilter());
// 打开文件后输出文件名修改,eg:w.cpt.doc / w.svg.doc,去掉中间的后缀名~~ w.doc
String filenName = editingFILE.getName();

7
designer-realize/src/com/fr/design/actions/file/export/CSVExportAction.java

@ -4,6 +4,7 @@
package com.fr.design.actions.file.export;
import com.fr.base.BaseUtils;
import com.fr.base.extension.FileExtension;
import com.fr.design.mainframe.JWorkBook;
import com.fr.design.menu.KeySetUtils;
import com.fr.file.filter.ChooseFileFilter;
@ -40,16 +41,16 @@ public class CSVExportAction extends AbstractExportAction {
@Override
protected ChooseFileFilter getChooseFileFilter() {
return new ChooseFileFilter(new String[]{"csv"}, Inter.getLocText("Export-CSV"));
return new ChooseFileFilter(FileExtension.CSV, Inter.getLocText("Export-CSV"));
}
@Override
protected String getDefaultExtension() {
TemplateWorkBook tpl = this.getTemplateWorkBook();
if (hasLayerReport(tpl)) {
return "zip";
return FileExtension.ZIP.getExtension();
} else {
return "csv";
return FileExtension.CSV.getExtension();
}
}
}

7
designer-realize/src/com/fr/design/actions/file/export/EmbeddedExportExportAction.java

@ -1,6 +1,7 @@
package com.fr.design.actions.file.export;
import com.fr.base.BaseUtils;
import com.fr.base.extension.FileExtension;
import com.fr.design.mainframe.JWorkBook;
import com.fr.design.menu.KeySetUtils;
import com.fr.file.filter.ChooseFileFilter;
@ -8,6 +9,8 @@ import com.fr.general.Inter;
import com.fr.io.exporter.EmbeddedTableDataExporter;
import com.fr.io.exporter.Exporter;
import java.util.EnumSet;
/**
* Export Embedded.
*/
@ -30,13 +33,13 @@ public class EmbeddedExportExportAction extends AbstractExportAction {
@Override
protected ChooseFileFilter getChooseFileFilter() {
return new ChooseFileFilter(new String[]{"cpt"},
return new ChooseFileFilter(EnumSet.of(FileExtension.CPTX, FileExtension.CPT),
Inter.getLocText("Export-Template(embedded_data)"));
}
@Override
protected String getDefaultExtension() {
return "cpt";
return getEditingComponent().suffix().substring(1);
}
}

5
designer-realize/src/com/fr/design/actions/file/export/PDFExportAction.java

@ -4,6 +4,7 @@
package com.fr.design.actions.file.export;
import com.fr.base.BaseUtils;
import com.fr.base.extension.FileExtension;
import com.fr.design.mainframe.JWorkBook;
import com.fr.design.menu.KeySetUtils;
import com.fr.file.filter.ChooseFileFilter;
@ -34,12 +35,12 @@ public class PDFExportAction extends AbstractExportAction {
@Override
protected ChooseFileFilter getChooseFileFilter() {
return new ChooseFileFilter(new String[]{"pdf"}, Inter.getLocText("FR-Designer_Export-PDF"));
return new ChooseFileFilter(FileExtension.PDF, Inter.getLocText("FR-Designer_Export-PDF"));
}
@Override
protected String getDefaultExtension() {
return "pdf";
return FileExtension.PDF.getExtension();
}
}

19
designer-realize/src/com/fr/design/actions/file/export/PageToSheetExcelExportAction.java

@ -1,6 +1,7 @@
package com.fr.design.actions.file.export;
import com.fr.base.BaseUtils;
import com.fr.base.extension.FileExtension;
import com.fr.design.mainframe.JWorkBook;
import com.fr.design.menu.KeySetUtils;
import com.fr.file.filter.ChooseFileFilter;
@ -12,28 +13,28 @@ import com.fr.report.core.ReportUtils;
public class PageToSheetExcelExportAction extends AbstractExcelExportAction {
public PageToSheetExcelExportAction(JWorkBook jwb) {
super(jwb);
public PageToSheetExcelExportAction(JWorkBook jwb) {
super(jwb);
this.setMenuKeySet(KeySetUtils.PAGETOSHEET_EXCEL_EXPORT);
this.setName(getMenuKeySet().getMenuKeySetName()+"...");
this.setName(getMenuKeySet().getMenuKeySetName() + "...");
this.setMnemonic(getMenuKeySet().getMnemonic());
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/excel.png"));
}
@Override
protected Exporter getExporter() {
TemplateWorkBook tpl = this.getTemplateWorkBook();
protected Exporter getExporter() {
TemplateWorkBook tpl = this.getTemplateWorkBook();
return new PageToSheetExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(tpl));
}
@Override
protected ChooseFileFilter getChooseFileFilter() {
return new ChooseFileFilter(new String[]{"xls"}, Inter.getLocText("Export-Excel"));
protected ChooseFileFilter getChooseFileFilter() {
return new ChooseFileFilter(FileExtension.XLS, Inter.getLocText("Export-Excel"));
}
@Override
protected String getDefaultExtension() {
return "xls";
protected String getDefaultExtension() {
return FileExtension.XLS.getExtension();
}
}

17
designer-realize/src/com/fr/design/actions/file/export/SVGExportAction.java

@ -4,6 +4,7 @@
package com.fr.design.actions.file.export;
import com.fr.base.BaseUtils;
import com.fr.base.extension.FileExtension;
import com.fr.design.mainframe.JWorkBook;
import com.fr.design.menu.KeySetUtils;
import com.fr.file.filter.ChooseFileFilter;
@ -18,27 +19,27 @@ public class SVGExportAction extends AbstractExportAction {
/**
* Constructor
*/
public SVGExportAction(JWorkBook jwb) {
super(jwb);
public SVGExportAction(JWorkBook jwb) {
super(jwb);
this.setMenuKeySet(KeySetUtils.SVG_EXPORT);
this.setName(getMenuKeySet().getMenuKeySetName()+"...");
this.setName(getMenuKeySet().getMenuKeySetName() + "...");
this.setMnemonic(getMenuKeySet().getMnemonic());
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/svg.png"));
}
@Override
protected Exporter getExporter() {
protected Exporter getExporter() {
return new SVGExporter();
}
@Override
protected ChooseFileFilter getChooseFileFilter() {
return new ChooseFileFilter(new String[]{"svg"}, Inter.getLocText("Export-SVG"));
protected ChooseFileFilter getChooseFileFilter() {
return new ChooseFileFilter(FileExtension.SVG, Inter.getLocText("Export-SVG"));
}
@Override
protected String getDefaultExtension() {
return "svg";
protected String getDefaultExtension() {
return FileExtension.SVG.getExtension();
}
}

17
designer-realize/src/com/fr/design/actions/file/export/TextExportAction.java

@ -4,6 +4,7 @@
package com.fr.design.actions.file.export;
import com.fr.base.BaseUtils;
import com.fr.base.extension.FileExtension;
import com.fr.design.mainframe.JWorkBook;
import com.fr.design.menu.KeySetUtils;
import com.fr.file.filter.ChooseFileFilter;
@ -18,26 +19,26 @@ public class TextExportAction extends AbstractExportAction {
/**
* Constructor
*/
public TextExportAction(JWorkBook jwb) {
super(jwb);
public TextExportAction(JWorkBook jwb) {
super(jwb);
this.setMenuKeySet(KeySetUtils.TEXT_EXPORT);
this.setName(getMenuKeySet().getMenuKeySetName()+ "...");
this.setName(getMenuKeySet().getMenuKeySetName() + "...");
this.setMnemonic(getMenuKeySet().getMnemonic());
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/text.png"));
}
@Override
protected Exporter getExporter() {
protected Exporter getExporter() {
return new TextExporter();
}
@Override
protected ChooseFileFilter getChooseFileFilter() {
return new ChooseFileFilter(new String[]{"txt"}, Inter.getLocText("Export-Text"));
protected ChooseFileFilter getChooseFileFilter() {
return new ChooseFileFilter(FileExtension.TXT, Inter.getLocText("Export-Text"));
}
@Override
protected String getDefaultExtension() {
return "txt";
protected String getDefaultExtension() {
return FileExtension.TXT.getExtension();
}
}

17
designer-realize/src/com/fr/design/actions/file/export/WordExportAction.java

@ -4,6 +4,7 @@
package com.fr.design.actions.file.export;
import com.fr.base.BaseUtils;
import com.fr.base.extension.FileExtension;
import com.fr.design.mainframe.JWorkBook;
import com.fr.design.menu.KeySetUtils;
import com.fr.file.filter.ChooseFileFilter;
@ -18,26 +19,26 @@ public class WordExportAction extends AbstractExportAction {
/**
* Constructor
*/
public WordExportAction(JWorkBook jwb) {
super(jwb);
public WordExportAction(JWorkBook jwb) {
super(jwb);
this.setMenuKeySet(KeySetUtils.WORD_EXPORT);
this.setName(getMenuKeySet().getMenuKeySetName()+ "...");
this.setName(getMenuKeySet().getMenuKeySetName() + "...");
this.setMnemonic(getMenuKeySet().getMnemonic());
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/word.png"));
}
@Override
protected Exporter getExporter() {
protected Exporter getExporter() {
return new WordExporter();
}
@Override
protected ChooseFileFilter getChooseFileFilter() {
return new ChooseFileFilter(new String[]{"doc"}, Inter.getLocText("Export-Word"));
protected ChooseFileFilter getChooseFileFilter() {
return new ChooseFileFilter(FileExtension.DOC, Inter.getLocText("Export-Word"));
}
@Override
protected String getDefaultExtension() {
return "doc";
protected String getDefaultExtension() {
return FileExtension.DOC.getExtension();
}
}

17
designer-realize/src/com/fr/design/module/DesignerModule.java

@ -7,6 +7,7 @@ import com.fr.base.Formula;
import com.fr.base.MultiFieldParameter;
import com.fr.base.Style;
import com.fr.base.TempNameStyle;
import com.fr.base.extension.FileExtension;
import com.fr.base.frpx.exception.FRPackageRunTimeException;
import com.fr.base.frpx.exception.InvalidWorkBookException;
import com.fr.base.io.XMLEncryptUtils;
@ -302,8 +303,8 @@ public class DesignerModule extends DesignModule {
private AbstractWorkBookApp getXlsxApp() {
return new AbstractWorkBookApp() {
@Override
public String[] defaultExtentions() {
return new String[]{"xlsx"};
public String[] defaultExtensions() {
return new String[]{FileExtension.XLSX.getExtension()};
}
@Override
@ -322,8 +323,8 @@ public class DesignerModule extends DesignModule {
private AbstractWorkBookApp getXlsApp() {
return new AbstractWorkBookApp() {
@Override
public String[] defaultExtentions() {
return new String[]{"xls"};
public String[] defaultExtensions() {
return new String[]{FileExtension.XLS.getExtension()};
}
@Override
@ -342,8 +343,8 @@ public class DesignerModule extends DesignModule {
private AbstractWorkBookApp getCptApp() {
return new AbstractWorkBookApp() {
@Override
public String[] defaultExtentions() {
return new String[]{"cpt"};
public String[] defaultExtensions() {
return new String[]{FileExtension.CPT.getExtension()};
}
@Override
@ -381,8 +382,8 @@ public class DesignerModule extends DesignModule {
return new AbstractWorkBookApp() {
@Override
public String[] defaultExtentions() {
return new String[]{"cptx"};
public String[] defaultExtensions() {
return new String[]{FileExtension.CPTX.getExtension()};
}
@Override

Loading…
Cancel
Save