You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.8 KiB
85 lines
2.8 KiB
package com.fr.design.mainframe.alphafine.component; |
|
|
|
import com.fr.design.actions.help.alphafine.AlphaFineConstants; |
|
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
|
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel; |
|
import com.fr.design.mainframe.alphafine.cell.model.DocumentModel; |
|
import com.fr.design.mainframe.alphafine.preview.ResultShowPane; |
|
|
|
import javax.swing.JList; |
|
import java.awt.event.KeyAdapter; |
|
import java.awt.event.KeyEvent; |
|
import java.awt.event.MouseAdapter; |
|
import java.awt.event.MouseEvent; |
|
|
|
/** |
|
* @author hades |
|
* @version 11.0 |
|
* Created by hades on 2022/4/18 |
|
*/ |
|
public class AlphaFineList extends JList<AlphaCellModel> { |
|
|
|
private ResultShowPane resultShowPane; |
|
|
|
public AlphaFineList() { |
|
addMouseListener(new MouseAdapter() { |
|
@Override |
|
public void mouseClicked(MouseEvent e) { |
|
AlphaCellModel selectedValue = getSelectedValue(); |
|
if (e.getClickCount() == AlphaFineConstants.DEFAULT_CLICK_COUNT && selectedValue.hasAction()) { |
|
// 点击搜索结果 主页面移动到后面 |
|
if (!(selectedValue instanceof DocumentModel)) { |
|
// 帮助文档不跳转 |
|
AlphaFineHelper.getAlphaFineDialog().toBack(); |
|
} |
|
dealWithSearchResult(); |
|
} |
|
} |
|
}); |
|
|
|
addListSelectionListener(e -> { |
|
if (!e.getValueIsAdjusting() && getSelectedValue() != null) { |
|
if (resultShowPane != null) { |
|
resultShowPane.showResult(getSelectedValue()); |
|
} |
|
} |
|
}); |
|
|
|
|
|
addKeyListener(new KeyAdapter() { |
|
@Override |
|
public void keyPressed(KeyEvent e) { |
|
if (e.getKeyCode() == KeyEvent.VK_ENTER) { |
|
AlphaCellModel selectedValue = getSelectedValue(); |
|
if (selectedValue.hasAction() && !(selectedValue instanceof DocumentModel)) { |
|
AlphaFineHelper.getAlphaFineDialog().toBack(); |
|
} |
|
dealWithSearchResult(); |
|
} |
|
} |
|
}); |
|
} |
|
|
|
public void setResultShowPane(ResultShowPane resultShowPane) { |
|
this.resultShowPane = resultShowPane; |
|
} |
|
|
|
@Override |
|
public void setSelectedIndex(int index) { |
|
super.setSelectedIndex(index); |
|
AlphaCellModel alphaCellModel = getSelectedValue(); |
|
if (resultShowPane != null && alphaCellModel != null) { |
|
resultShowPane.showResult(getSelectedValue()); |
|
} |
|
ensureIndexIsVisible(getSelectedIndex()); |
|
} |
|
|
|
private void dealWithSearchResult() { |
|
final AlphaCellModel model = this.getSelectedValue(); |
|
if (model != null) { |
|
model.doAction(); |
|
} |
|
} |
|
|
|
|
|
} |