From 57059ba0af77964f435b91d570e9e6ba4481fa96 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Wed, 28 Jun 2017 00:23:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=80=89=E4=B8=AD=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E9=A1=B9=E4=BC=98=E5=8C=96=EF=BC=8C=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E6=98=AF=E5=85=A8=E9=83=A8=E5=8A=A0=E8=BD=BD=E5=AE=8C=E6=89=8D?= =?UTF-8?q?=E9=80=89=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alphafine/component/AlphaFineDialog.java | 95 +++++++++++++++---- .../alphafine/model/SearchListModel.java | 52 ---------- 2 files changed, 76 insertions(+), 71 deletions(-) delete mode 100644 designer/src/com/fr/design/mainframe/alphafine/model/SearchListModel.java diff --git a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java b/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java index c88aea15d1..154f3cf393 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java +++ b/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 { + 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(); + } + } + } \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/alphafine/model/SearchListModel.java b/designer/src/com/fr/design/mainframe/alphafine/model/SearchListModel.java deleted file mode 100644 index 303e778e8b..0000000000 --- a/designer/src/com/fr/design/mainframe/alphafine/model/SearchListModel.java +++ /dev/null @@ -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 { - 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(); - } -}