Browse Source

自动选中第一项优化,之前是全部加载完才选中

master
XiaXiang 7 years ago
parent
commit
57059ba0af
  1. 95
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  2. 52
      designer/src/com/fr/design/mainframe/alphafine/model/SearchListModel.java

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

@ -13,7 +13,6 @@ import com.fr.design.mainframe.alphafine.cell.model.*;
import com.fr.design.mainframe.alphafine.cell.render.ContentCellRender;
import com.fr.design.mainframe.alphafine.listener.ComponentHandler;
import com.fr.design.mainframe.alphafine.listener.DocumentAdapter;
import com.fr.design.mainframe.alphafine.model.SearchListModel;
import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.preview.ActionPreviewPane;
import com.fr.design.mainframe.alphafine.preview.DocumentPreviewPane;
@ -79,9 +78,17 @@ public class AlphaFineDialog extends UIDialog {
private SwingWorker searchWorker;
private SwingWorker showWorker;
private String storeText;
//是否强制打开,因为面板是否关闭绑定了全局鼠标事件,这里需要处理一下
/**
* 是否强制打开因为面板是否关闭绑定了全局鼠标事件这里需要处理一下
*/
private boolean forceOpen;
/**
*List的第一可用项是否被选中
*/
private boolean isSelected;
public AlphaFineDialog(Frame parent, boolean forceOpen) {
super(parent);
@ -292,14 +299,6 @@ public class AlphaFineDialog extends UIDialog {
rebuildList(searchTextField.getText().toLowerCase());
return null;
}
@Override
protected void done() {
if (!isCancelled() && getModel().getSize() > 0) {
searchResultList.setSelectedIndex(0);
showResult(searchResultList.getSelectedValue());
}
}
};
this.searchWorker.execute();
}
@ -343,8 +342,8 @@ public class AlphaFineDialog extends UIDialog {
* 重置面板
*/
private void resetContainer() {
searchResultList.resetSelectedIndex();
searchListModel.removeAllElements();
setSelected(false);
rightSearchResultPane.removeAll();
rightSearchResultPane.validate();
rightSearchResultPane.repaint();
@ -800,6 +799,14 @@ public class AlphaFineDialog extends UIDialog {
this.storeText = storeText;
}
public boolean isSelected() {
return isSelected;
}
public void setSelected(boolean selected) {
isSelected = selected;
}
/**
+-------------------------------------+
@ -812,13 +819,6 @@ public class AlphaFineDialog extends UIDialog {
initListListener();
}
/**
* 重置选项
*/
public void resetSelectedIndex() {
super.setSelectedIndex(0);
}
/**
* 重写选中的方法
* @param index
@ -886,7 +886,7 @@ public class AlphaFineDialog extends UIDialog {
addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
if (!e.getValueIsAdjusting() && getSelectedValue() != null) {
showResult(getSelectedValue());
}
@ -897,4 +897,61 @@ public class AlphaFineDialog extends UIDialog {
}
/**
+-------------------------------------+
| 自定义ListModel |
+-------------------------------------+
*/
private class SearchListModel extends DefaultListModel<AlphaCellModel> {
SearchResult myDelegate;
public SearchListModel(SearchResult searchResult) {
this.myDelegate = searchResult;
}
@Override
public void addElement(AlphaCellModel element) {
int index = myDelegate.size();
myDelegate.add(element);
fireContentsChanged(this, index, index);
if (element.hasAction() && !isSelected()) {
searchResultList.setSelectedIndex(index);
setSelected(true);
}
}
@Override
public AlphaCellModel getElementAt(int index) {
return myDelegate.get(index);
}
@Override
public void add(int index, AlphaCellModel element) {
myDelegate.add(index, element);
fireIntervalAdded(this, index, index);
}
@Override
public AlphaCellModel remove(int index) {
AlphaCellModel object = myDelegate.get(index);
myDelegate.remove(object);
fireIntervalRemoved(this, index, index);
return object;
}
@Override
public int getSize() {
return this.myDelegate.size();
}
@Override
public void removeAllElements() {
this.myDelegate.clear();
}
}
}

52
designer/src/com/fr/design/mainframe/alphafine/model/SearchListModel.java

@ -1,52 +0,0 @@
package com.fr.design.mainframe.alphafine.model;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import javax.swing.*;
/**
* Created by XiaXiang on 2017/4/20.
*/
public class SearchListModel extends DefaultListModel<AlphaCellModel> {
SearchResult myDelegate;
public SearchListModel(SearchResult searchResult) {
this.myDelegate = searchResult;
}
@Override
public void addElement(AlphaCellModel element) {
int index = myDelegate.size();
myDelegate.add(element);
fireContentsChanged(this, index, index);
}
@Override
public AlphaCellModel getElementAt(int index) {
return myDelegate.get(index);
}
@Override
public void add(int index, AlphaCellModel element) {
myDelegate.add(index, element);
fireIntervalAdded(this, index, index);
}
@Override
public AlphaCellModel remove(int index) {
AlphaCellModel object = myDelegate.get(index);
myDelegate.remove(object);
fireIntervalRemoved(this, index, index);
return object;
}
@Override
public int getSize() {
return this.myDelegate.size();
}
@Override
public void removeAllElements() {
this.myDelegate.clear();
}
}
Loading…
Cancel
Save