Harrison
5 years ago
17 changed files with 455 additions and 49 deletions
@ -0,0 +1,103 @@
|
||||
package com.fr.design.gui.ifilechooser; |
||||
|
||||
import javax.swing.filechooser.FileFilter; |
||||
import java.awt.*; |
||||
import java.io.File; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2020/3/31 |
||||
*/ |
||||
public abstract class AbstractFileChooser { |
||||
|
||||
/** |
||||
* 返回当前目录 |
||||
* |
||||
*/ |
||||
public abstract File getCurrentDirectory(); |
||||
|
||||
/** |
||||
* 返回当前的文件选择过滤器 |
||||
* |
||||
*/ |
||||
public abstract FileFilter getFileFilter(); |
||||
|
||||
/** |
||||
* 返回选择的文件 |
||||
* |
||||
*/ |
||||
public abstract File getSelectedFile(); |
||||
|
||||
/** |
||||
* 多文件选择模式下 返回选择的多个文件 |
||||
* |
||||
*/ |
||||
public abstract File[] getSelectedFiles(); |
||||
|
||||
/** |
||||
* 是否可以选择多个文件 |
||||
* |
||||
*/ |
||||
public abstract boolean isMultiSelectionEnabled(); |
||||
|
||||
/** |
||||
* 设置当前选择的目录 |
||||
* |
||||
*/ |
||||
public abstract void setCurrentDirectory(File dir); |
||||
|
||||
/** |
||||
* 设置左上角标题 |
||||
* |
||||
*/ |
||||
public abstract void setDialogTitle(String title); |
||||
|
||||
/** |
||||
* 设置当前的文件过滤器 |
||||
* |
||||
*/ |
||||
public abstract void setFileFilter(final FileFilter filter); |
||||
|
||||
/** |
||||
* 设置文件选择器模式 |
||||
* |
||||
* JFileChooser.FILES_ONLY |
||||
* JFileChooser.DIRECTORIES_ONLY |
||||
* JFileChooser.FILES_AND_DIRECTORIES |
||||
*/ |
||||
public abstract void setFileSelectionMode(int selectionMode); |
||||
|
||||
/** |
||||
* 设置是否允许选择多个文件 |
||||
* |
||||
*/ |
||||
public abstract void setMultiSelectionEnabled(boolean multiple); |
||||
|
||||
/** |
||||
* 设置选择的文件 用于showSaveDialog |
||||
* |
||||
*/ |
||||
public abstract void setSelectedFile(File file); |
||||
|
||||
/** |
||||
* 弹出文件选择器 打开文件 |
||||
* |
||||
*/ |
||||
public abstract int showOpenDialog(Component parent); |
||||
|
||||
/** |
||||
* 弹出文件选择器 保存文件 |
||||
* |
||||
*/ |
||||
public abstract int showSaveDialog(Component parent); |
||||
|
||||
|
||||
/** |
||||
* https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4031440
|
||||
* |
||||
* 设置文件名后缀 起到文件过滤的作用 形如 "*.jpg;*.jpeg" |
||||
* |
||||
*/ |
||||
public abstract void setExtensionFilter(String file); |
||||
} |
@ -0,0 +1,153 @@
|
||||
package com.fr.design.gui.ifilechooser; |
||||
|
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.stable.os.OperatingSystem; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.filechooser.FileFilter; |
||||
import java.awt.*; |
||||
import java.io.File; |
||||
import java.io.FilenameFilter; |
||||
|
||||
|
||||
/** |
||||
* 系统原生风格的文件选择器 |
||||
* |
||||
* jdk问题: |
||||
* https://bugs.openjdk.java.net/browse/JDK-4811090 不支持文件扩展选择
|
||||
* https://stackoverflow.com/questions/40713398/filter-not-working-in-filedialog windows下 setFilenameFilter不work
|
||||
* |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2020/3/31 |
||||
*/ |
||||
public class UINativeFileChooser extends AbstractFileChooser { |
||||
|
||||
private final FileDialog fileDialog; |
||||
private FileFilter fileFilter; |
||||
private int selectionMode; |
||||
|
||||
public UINativeFileChooser(File file) { |
||||
fileDialog = new FileDialog(DesignerContext.getDesignerFrame()); |
||||
if (file != null) { |
||||
fileDialog.setDirectory(file.getAbsolutePath()); |
||||
fileDialog.setFile(file.toString()); |
||||
} |
||||
} |
||||
|
||||
public UINativeFileChooser() { |
||||
this(null); |
||||
} |
||||
|
||||
@Override |
||||
public File getCurrentDirectory() { |
||||
return new File(fileDialog.getDirectory()); |
||||
} |
||||
|
||||
@Override |
||||
public FileFilter getFileFilter() { |
||||
return fileFilter; |
||||
} |
||||
|
||||
@Override |
||||
public File getSelectedFile() { |
||||
return new File(fileDialog.getDirectory() + fileDialog.getFile()); |
||||
} |
||||
|
||||
@Override |
||||
public File[] getSelectedFiles() { |
||||
return fileDialog.getFiles(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isMultiSelectionEnabled() { |
||||
return fileDialog.isMultipleMode(); |
||||
} |
||||
|
||||
@Override |
||||
public void setCurrentDirectory(File f) { |
||||
fileDialog.setDirectory(f.toString()); |
||||
} |
||||
|
||||
@Override |
||||
public void setDialogTitle(String title) { |
||||
fileDialog.setTitle(title); |
||||
} |
||||
|
||||
@Override |
||||
public void setFileFilter(final FileFilter cff) { |
||||
FilenameFilter filter = new FilenameFilter() { |
||||
@Override |
||||
public boolean accept(File Directory, String fileName) { |
||||
return cff.accept(new File(Directory.getAbsolutePath() + fileName)); |
||||
} |
||||
}; |
||||
fileDialog.setFilenameFilter(filter); |
||||
fileFilter = cff; |
||||
} |
||||
|
||||
@Override |
||||
public void setFileSelectionMode(int selectionMode) { |
||||
this.selectionMode = selectionMode; |
||||
} |
||||
|
||||
@Override |
||||
public void setMultiSelectionEnabled(boolean multiple) { |
||||
fileDialog.setMultipleMode(multiple); |
||||
} |
||||
|
||||
@Override |
||||
public void setSelectedFile(File file) { |
||||
fileDialog.setDirectory(file.getAbsolutePath()); |
||||
fileDialog.setFile(file.getName()); |
||||
} |
||||
|
||||
@Override |
||||
public int showOpenDialog(Component parent) { |
||||
boolean appleProperty = OperatingSystem.isMacos() && selectionMode == JFileChooser.DIRECTORIES_ONLY; |
||||
if (appleProperty) { |
||||
System.setProperty("apple.awt.fileDialogForDirectories", "true"); |
||||
} |
||||
try { |
||||
fileDialog.setLocale(JComponent.getDefaultLocale()); |
||||
fileDialog.setMode(FileDialog.LOAD); |
||||
fileDialog.setVisible(true); |
||||
return fileDialog.getFile() == null ? JFileChooser.CANCEL_OPTION : JFileChooser.APPROVE_OPTION; |
||||
} finally { |
||||
if (appleProperty) { |
||||
System.setProperty("apple.awt.fileDialogForDirectories", "false"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public int showSaveDialog(Component parent) { |
||||
fileDialog.setLocale(JComponent.getDefaultLocale()); |
||||
fileDialog.setMode(FileDialog.SAVE); |
||||
fileDialog.setVisible(true); |
||||
return fileDialog.getFile() == null ? JFileChooser.CANCEL_OPTION : JFileChooser.APPROVE_OPTION; |
||||
} |
||||
|
||||
@Override |
||||
public void setExtensionFilter(String file) { |
||||
fileDialog.setFile(file); |
||||
} |
||||
|
||||
/** |
||||
* 确认本地文件选择器是否支持选择模式 |
||||
* @param selectionMode 选择模式 |
||||
* @return 是否支持选择模式 |
||||
*/ |
||||
public static boolean supportsSelectionMode(int selectionMode) { |
||||
switch (selectionMode) { |
||||
case JFileChooser.FILES_AND_DIRECTORIES: |
||||
return false; |
||||
case JFileChooser.DIRECTORIES_ONLY: |
||||
return OperatingSystem.isMacos(); |
||||
case JFileChooser.FILES_ONLY: |
||||
default: |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.fr.design.formula; |
||||
|
||||
import junit.framework.TestCase; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2020/5/20 |
||||
*/ |
||||
public class FormulaPaneTest extends TestCase { |
||||
|
||||
@Test |
||||
public void testSimilarComparator() { |
||||
String[] strs = new String[] {"ScriptEval", "SPLIT", "SUMPRECISE"}; |
||||
String[] result = new String[] {"SPLIT", "ScriptEval", "SUMPRECISE"}; |
||||
Arrays.sort(strs, new FormulaPane.SimilarComparator("sp")); |
||||
Assert.assertArrayEquals(result, strs); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,29 @@
|
||||
package com.fr.van.chart.scatter.large; |
||||
|
||||
import com.fr.chart.chartglyph.Marker; |
||||
import com.fr.design.condition.ConditionAttributesPane; |
||||
import com.fr.plugin.chart.marker.type.MarkerType; |
||||
import com.fr.van.chart.designer.component.marker.VanChartCommonMarkerPane; |
||||
import com.fr.van.chart.designer.other.condition.item.VanChartMarkerConditionPane; |
||||
|
||||
public class VanChartScatterLargeModelMarkerConditionPane extends VanChartMarkerConditionPane { |
||||
|
||||
public VanChartScatterLargeModelMarkerConditionPane(ConditionAttributesPane conditionAttributesPane) { |
||||
super(conditionAttributesPane); |
||||
} |
||||
|
||||
protected void initMarkerPane() { |
||||
|
||||
markerPane = new VanChartLargeModelMarkerPane() { |
||||
protected VanChartCommonMarkerPane createCommonMarkerPane() { |
||||
|
||||
return new VanChartCommonMarkerPane() { |
||||
protected Marker[] getMarkers() { |
||||
return getNormalMarkersWithCustom(new MarkerType[]{MarkerType.MARKER_AUTO}); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
}; |
||||
} |
||||
} |
Loading…
Reference in new issue