Browse Source

搜索去除中文输入法的影响 多线程问题

master
XiaXiang 7 years ago
parent
commit
51993ef323
  1. 43
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java

43
designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java

@ -15,6 +15,7 @@ import com.fr.design.mainframe.alphafine.cell.model.FileModel;
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
import com.fr.design.mainframe.alphafine.cell.model.PluginModel; import com.fr.design.mainframe.alphafine.cell.model.PluginModel;
import com.fr.design.mainframe.alphafine.cell.render.ContentCellRender; import com.fr.design.mainframe.alphafine.cell.render.ContentCellRender;
import com.fr.design.mainframe.alphafine.listener.DocumentAdapter;
import com.fr.design.mainframe.alphafine.model.SearchResult; import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.preview.DocumentPreviewPane; import com.fr.design.mainframe.alphafine.preview.DocumentPreviewPane;
import com.fr.design.mainframe.alphafine.preview.FilePreviewPane; import com.fr.design.mainframe.alphafine.preview.FilePreviewPane;
@ -39,6 +40,7 @@ import com.fr.stable.project.ProjectConstants;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import java.awt.*; import java.awt.*;
@ -49,8 +51,6 @@ import java.net.URL;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
/** /**
@ -90,7 +90,6 @@ public class AlphaFineDialog extends UIDialog {
//是否强制打开,因为面板是否关闭绑定了全局鼠标事件,这里需要处理一下 //是否强制打开,因为面板是否关闭绑定了全局鼠标事件,这里需要处理一下
private boolean forceOpen; private boolean forceOpen;
public AlphaFineDialog(Frame parent, boolean forceOpen) { public AlphaFineDialog(Frame parent, boolean forceOpen) {
super(parent); super(parent);
this.forceOpen = forceOpen; this.forceOpen = forceOpen;
@ -223,15 +222,10 @@ public class AlphaFineDialog extends UIDialog {
* @param text * @param text
*/ */
private void doSearch(String text) { private void doSearch(String text) {
showSearchResult(text);
if (isNeedSearch(text)) {
removeSearchResult();
} else {
showSearchResult(text);
}
} }
boolean isNeedSearch(String text) { boolean isNoNeedSearch(String text) {
return ComparatorUtils.equals(PLACE_HOLDER, text) || text.contains("'") || StringUtils.isBlank(text); return ComparatorUtils.equals(PLACE_HOLDER, text) || text.contains("'") || StringUtils.isBlank(text);
} }
@ -294,6 +288,7 @@ public class AlphaFineDialog extends UIDialog {
searchResultList.setCellRenderer(new ContentCellRender()); searchResultList.setCellRenderer(new ContentCellRender());
leftSearchResultPane = new UIScrollPane(searchResultList); leftSearchResultPane = new UIScrollPane(searchResultList);
leftSearchResultPane.setBorder(null);
leftSearchResultPane.setBackground(Color.WHITE); leftSearchResultPane.setBackground(Color.WHITE);
leftSearchResultPane.setPreferredSize(new Dimension(AlphaFineConstants.LEFT_WIDTH, AlphaFineConstants.CONTENT_HEIGHT)); leftSearchResultPane.setPreferredSize(new Dimension(AlphaFineConstants.LEFT_WIDTH, AlphaFineConstants.CONTENT_HEIGHT));
rightSearchResultPane = new JPanel(); rightSearchResultPane = new JPanel();
@ -319,7 +314,7 @@ public class AlphaFineDialog extends UIDialog {
this.searchWorker = new SwingWorker() { this.searchWorker = new SwingWorker() {
@Override @Override
protected Object doInBackground() throws Exception { protected Object doInBackground() throws Exception {
rebuildList(searchTextField.getText().toLowerCase()); rebuildList(text);
return null; return null;
} }
@ -384,6 +379,7 @@ public class AlphaFineDialog extends UIDialog {
*/ */
private void rebuildList(String searchText) { private void rebuildList(String searchText) {
resetContainer(); resetContainer();
if (searchText.startsWith(ADVANCED_SEARCH_MARK)) { if (searchText.startsWith(ADVANCED_SEARCH_MARK)) {
if (searchText.startsWith(ACTION_MARK_SHORT) || searchText.startsWith(ACTION_MARK)) { if (searchText.startsWith(ACTION_MARK_SHORT) || searchText.startsWith(ACTION_MARK)) {
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()); storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
@ -679,17 +675,22 @@ public class AlphaFineDialog extends UIDialog {
searchTextField.setText(null); searchTextField.setText(null);
removeSearchResult(); removeSearchResult();
} }
} else if (keyCode == KeyEvent.VK_SHIFT) { }
new Timer().schedule(new TimerTask() { }
@Override });
public void run() {
doSearch(searchTextField.getText()); searchTextField.getDocument().addDocumentListener(new DocumentAdapter() {
} @Override
}, 50); protected void textChanged(DocumentEvent e) {
} else if (keyCode == KeyEvent.VK_UP) { if (isNoNeedSearch(searchTextField.getText())) {
return; removeSearchResult();
} else { } else {
doSearch(searchTextField.getText()); try {
Thread.sleep(10);
doSearch(searchTextField.getText());
} catch (InterruptedException e1) {
FRLogger.getLogger().error(e1.getMessage());
}
} }
} }

Loading…
Cancel
Save