Link.Zhao
2 years ago
73 changed files with 1146 additions and 183 deletions
@ -0,0 +1,174 @@ |
|||||||
|
package com.fr.design.actions.help.alphafine.component; |
||||||
|
|
||||||
|
import com.fr.base.svg.IconUtils; |
||||||
|
import com.fr.design.actions.help.alphafine.AlphaFineConfigPane; |
||||||
|
import com.fr.design.gui.ibutton.UIButton; |
||||||
|
import com.fr.design.gui.icheckbox.UICheckBox; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.SwingUtilities; |
||||||
|
import javax.swing.plaf.PanelUI; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.FlowLayout; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Comparator; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.HashSet; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.function.Function; |
||||||
|
|
||||||
|
/** |
||||||
|
* @version 11.0 |
||||||
|
* @author: Link |
||||||
|
* @date: 2022/9/9 |
||||||
|
* @Description: alphafine设置 - 搜索范围 - 自定义排序 - 弹出面板 |
||||||
|
*/ |
||||||
|
public class CustomSortPane extends JPanel { |
||||||
|
|
||||||
|
|
||||||
|
private static final int WIDTH = 147; |
||||||
|
private static final int ITEM_HEIGHT = 23; |
||||||
|
private static final int GAP = 1; |
||||||
|
private static final Color BACKGROUND_COLOR = new Color(0xdadadd); |
||||||
|
|
||||||
|
private UIButton top; |
||||||
|
private UIButton bottom; |
||||||
|
private UIButton up; |
||||||
|
private UIButton down; |
||||||
|
private JPanel toolbarPane; |
||||||
|
private MenuLabelPane sortItemPane; |
||||||
|
private List<UICheckBox> sortItems; |
||||||
|
private MenuLabel selectedLabel; |
||||||
|
private AlphaFineConfigPane parentPane; |
||||||
|
|
||||||
|
public CustomSortPane(List<UICheckBox> items, AlphaFineConfigPane parentPane) { |
||||||
|
this.sortItems = items; |
||||||
|
this.parentPane = parentPane; |
||||||
|
setLayout(new BorderLayout(GAP, GAP)); |
||||||
|
int height = (sortItems.size() + 1) * (ITEM_HEIGHT + GAP) + GAP; |
||||||
|
setPreferredSize(new Dimension(WIDTH, height)); |
||||||
|
initComponent(); |
||||||
|
add(toolbarPane, BorderLayout.NORTH); |
||||||
|
add(sortItemPane, BorderLayout.CENTER); |
||||||
|
revalidate(); |
||||||
|
this.setVisible(true); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setUI(PanelUI ui) { |
||||||
|
super.setUI(ui); |
||||||
|
setBackground(BACKGROUND_COLOR); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private void initComponent() { |
||||||
|
createToolbarPane(); |
||||||
|
createSortItemPane(); |
||||||
|
} |
||||||
|
|
||||||
|
private void createToolbarPane() { |
||||||
|
top = new UIButton(IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/top.svg")); |
||||||
|
bottom = new UIButton(IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/bottom.svg")); |
||||||
|
up = new UIButton(IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/up.svg")); |
||||||
|
down = new UIButton(IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/down.svg")); |
||||||
|
top.addActionListener(e -> { |
||||||
|
SwingUtilities.invokeLater(()->{ |
||||||
|
sortItemPane.setComponentZOrder(selectedLabel, 0); |
||||||
|
CustomSortPane.this.revalidate(); |
||||||
|
CustomSortPane.this.repaint(); |
||||||
|
refreshCurrentOrder(); |
||||||
|
}); |
||||||
|
|
||||||
|
}); |
||||||
|
bottom.addActionListener(e -> { |
||||||
|
SwingUtilities.invokeLater(()->{ |
||||||
|
sortItemPane.setComponentZOrder(selectedLabel, sortItemPane.getComponentCount() - 1); |
||||||
|
CustomSortPane.this.revalidate(); |
||||||
|
CustomSortPane.this.repaint(); |
||||||
|
refreshCurrentOrder(); |
||||||
|
}); |
||||||
|
|
||||||
|
}); |
||||||
|
up.addActionListener(e -> { |
||||||
|
SwingUtilities.invokeLater(()->{ |
||||||
|
sortItemPane.setComponentZOrder(selectedLabel, sortItemPane.getComponentZOrder(selectedLabel) - 1); |
||||||
|
CustomSortPane.this.revalidate(); |
||||||
|
CustomSortPane.this.repaint(); |
||||||
|
refreshCurrentOrder(); |
||||||
|
}); |
||||||
|
|
||||||
|
}); |
||||||
|
down.addActionListener(e -> { |
||||||
|
SwingUtilities.invokeLater(()->{ |
||||||
|
sortItemPane.setComponentZOrder(selectedLabel, sortItemPane.getComponentZOrder(selectedLabel) + 1); |
||||||
|
CustomSortPane.this.revalidate(); |
||||||
|
CustomSortPane.this.repaint(); |
||||||
|
refreshCurrentOrder(); |
||||||
|
}); |
||||||
|
|
||||||
|
}); |
||||||
|
toolbarPane = new JPanel(new FlowLayout(FlowLayout.TRAILING, GAP, GAP)); |
||||||
|
toolbarPane.setBorder(BorderFactory.createEmptyBorder()); |
||||||
|
toolbarPane.add(top); |
||||||
|
toolbarPane.add(bottom); |
||||||
|
toolbarPane.add(up); |
||||||
|
toolbarPane.add(down); |
||||||
|
} |
||||||
|
|
||||||
|
private void createSortItemPane() { |
||||||
|
String[] currentTabOrder = parentPane.getCurrentOrder(); |
||||||
|
Map<String, Integer> sortMap = new HashMap<>(); |
||||||
|
for (int i = 0; i < currentTabOrder.length; i++) { |
||||||
|
sortMap.put(currentTabOrder[i], i); |
||||||
|
} |
||||||
|
List<MenuLabel> sortLabels = new ArrayList<>(); |
||||||
|
for (UICheckBox item : sortItems) { |
||||||
|
MenuLabel label = new MenuLabel(item.getText(), (Function<MenuLabel, Object>) o -> { |
||||||
|
selectedLabel = o; |
||||||
|
return null; |
||||||
|
}); |
||||||
|
sortLabels.add(label); |
||||||
|
} |
||||||
|
sortLabels.sort(Comparator.comparingInt(tab -> sortMap.get(tab.getText()))); |
||||||
|
sortItemPane = new MenuLabelPane(sortLabels); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private void refreshCurrentOrder() { |
||||||
|
String[] currentTabOrder = parentPane.getCurrentOrder(); |
||||||
|
HashSet<String> selectedTab = new HashSet<>(); |
||||||
|
for (UICheckBox item : sortItems) { |
||||||
|
selectedTab.add(item.getText()); |
||||||
|
} |
||||||
|
|
||||||
|
// 未选中的tab,保持原排序不变
|
||||||
|
Map<String, Integer> exTab = new HashMap<>(); |
||||||
|
for (int i = 0; i < currentTabOrder.length; i++) { |
||||||
|
if (!selectedTab.contains(currentTabOrder[i])) { |
||||||
|
exTab.put(currentTabOrder[i], i); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 计算当前排序
|
||||||
|
String[] newOrder = new String[currentTabOrder.length]; |
||||||
|
Component[] components =sortItemPane.getComponents(); |
||||||
|
for (String s : exTab.keySet()) { |
||||||
|
newOrder[exTab.get(s)] = s; |
||||||
|
} |
||||||
|
|
||||||
|
int t = 0; |
||||||
|
for (int i = 0; i < newOrder.length; i++) { |
||||||
|
if (StringUtils.isEmpty(newOrder[i])) { |
||||||
|
newOrder[i] = ((MenuLabel)components[t++]).getText(); |
||||||
|
} |
||||||
|
} |
||||||
|
parentPane.setCurrentOrder(newOrder); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,95 @@ |
|||||||
|
package com.fr.design.actions.help.alphafine.component; |
||||||
|
|
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.utils.DesignUtils; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.plaf.LabelUI; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.event.MouseAdapter; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.awt.event.MouseListener; |
||||||
|
import java.util.function.Function; |
||||||
|
|
||||||
|
/** |
||||||
|
* @version 11.0 |
||||||
|
* @author: Link |
||||||
|
* @date: 2022/9/12 |
||||||
|
* @Description: 菜单label |
||||||
|
*/ |
||||||
|
public class MenuLabel extends UILabel { |
||||||
|
|
||||||
|
private static final Color BACKGROUND_COLOR = Color.white; |
||||||
|
private static final Color SELECTED_COLOR = new Color(0x419BF9); |
||||||
|
private static final Color HOVERED_COLOR = new Color(0xd9ebfe); |
||||||
|
private static final int HEIGHT = 23; |
||||||
|
private static final int WIDTH = 147; |
||||||
|
|
||||||
|
private MenuLabelPane parentMenu; |
||||||
|
private Function function; |
||||||
|
private boolean isSelected; |
||||||
|
|
||||||
|
public MenuLabel(String text, Function function) { |
||||||
|
super(text); |
||||||
|
this.function = function; |
||||||
|
setOpaque(true); |
||||||
|
addMouseListener(createMouseListener()); |
||||||
|
} |
||||||
|
|
||||||
|
public void setParentMenu(MenuLabelPane menu) { |
||||||
|
this.parentMenu = menu; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public void setUI(LabelUI ui) { |
||||||
|
super.setUI(ui); |
||||||
|
this.setBackground(BACKGROUND_COLOR); |
||||||
|
this.setBorder(BorderFactory.createEmptyBorder(2,10,1,10)); |
||||||
|
this.setPreferredSize(new Dimension(WIDTH, HEIGHT)); |
||||||
|
this.setFont(DesignUtils.getDefaultGUIFont().applySize(12)); |
||||||
|
} |
||||||
|
|
||||||
|
public void setSelected(boolean selected) { |
||||||
|
if (selected) { |
||||||
|
parentMenu.setNoneSelected(); |
||||||
|
setBackground(SELECTED_COLOR); |
||||||
|
function.apply(this); |
||||||
|
isSelected = true; |
||||||
|
} else { |
||||||
|
setBackground(BACKGROUND_COLOR); |
||||||
|
isSelected = false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isSelected() { |
||||||
|
return isSelected; |
||||||
|
} |
||||||
|
|
||||||
|
MouseListener createMouseListener() { |
||||||
|
return new MouseAdapter() { |
||||||
|
@Override |
||||||
|
public void mouseClicked(MouseEvent e) { |
||||||
|
super.mouseClicked(e); |
||||||
|
setSelected(true); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void mouseEntered(MouseEvent e) { |
||||||
|
super.mouseEntered(e); |
||||||
|
if (!isSelected) { |
||||||
|
setBackground(HOVERED_COLOR); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void mouseExited(MouseEvent e) { |
||||||
|
super.mouseExited(e); |
||||||
|
if (!isSelected) { |
||||||
|
setBackground(BACKGROUND_COLOR); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
package com.fr.design.actions.help.alphafine.component; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.FlowLayout; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @version 11.0 |
||||||
|
* @author: Link |
||||||
|
* @date: 2022/9/12 |
||||||
|
* @Description: 简单菜单面板 |
||||||
|
*/ |
||||||
|
public class MenuLabelPane extends JPanel { |
||||||
|
|
||||||
|
private static final int GAP = 1; |
||||||
|
|
||||||
|
private List<MenuLabel> labels; |
||||||
|
|
||||||
|
public MenuLabelPane(List<MenuLabel> labels) { |
||||||
|
this.labels = labels; |
||||||
|
setLayout(new FlowLayout(FlowLayout.CENTER, GAP, GAP)); |
||||||
|
for (MenuLabel label : labels) { |
||||||
|
label.setParentMenu(this); |
||||||
|
add(label); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void setNoneSelected() { |
||||||
|
for (MenuLabel label : labels) { |
||||||
|
label.setSelected(false); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,53 @@ |
|||||||
|
package com.fr.design.mainframe.alphafine.component; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||||
|
import org.jetbrains.annotations.NotNull; |
||||||
|
|
||||||
|
import javax.swing.JLabel; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.FlowLayout; |
||||||
|
import java.awt.event.MouseAdapter; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Link |
||||||
|
* @version 11.0 |
||||||
|
* Created by Link on 2022/9/19 |
||||||
|
* alphaFine - 推荐搜索词标签 |
||||||
|
*/ |
||||||
|
public class RecommendSearchLabel extends JPanel { |
||||||
|
|
||||||
|
private static final Color RECOMMEND_SEARCH_KEY_BLUE = new Color(0x419bf9); |
||||||
|
|
||||||
|
public RecommendSearchLabel(String title, @NotNull List<String> tips) { |
||||||
|
this.setLayout(new FlowLayout(FlowLayout.LEFT)); |
||||||
|
this.setBackground(Color.WHITE); |
||||||
|
JLabel recommend = new JLabel(title); |
||||||
|
this.add(recommend); |
||||||
|
|
||||||
|
for (String key : tips) { |
||||||
|
JLabel keyLabel = new SearchKeyLabel(key); |
||||||
|
this.add(keyLabel); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public class SearchKeyLabel extends JLabel { |
||||||
|
String searchKey; |
||||||
|
|
||||||
|
SearchKeyLabel(String searchKey) { |
||||||
|
this.searchKey = searchKey; |
||||||
|
setText(searchKey); |
||||||
|
setBackground(Color.WHITE); |
||||||
|
setForeground(RECOMMEND_SEARCH_KEY_BLUE); |
||||||
|
addMouseListener(new MouseAdapter() { |
||||||
|
@Override |
||||||
|
public void mouseClicked(MouseEvent e) { |
||||||
|
AlphaFineHelper.getAlphaFineDialog().fireSearch(searchKey); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,76 @@ |
|||||||
|
package com.fr.design.mainframe.alphafine.component; |
||||||
|
|
||||||
|
import com.fr.base.svg.IconUtils; |
||||||
|
import com.fr.common.util.Collections; |
||||||
|
import com.fr.design.actions.help.alphafine.AlphaFineConstants; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.utils.DesignUtils; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.Icon; |
||||||
|
import javax.swing.JLabel; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.SwingConstants; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Link |
||||||
|
* @version 11.0 |
||||||
|
* Created by Link on 2022/9/18 |
||||||
|
* alphafine - 搜索提示面板 |
||||||
|
*/ |
||||||
|
public class SearchHintPane extends JPanel { |
||||||
|
|
||||||
|
private static final String TITLE = Toolkit.i18nText("Fine-Design_Report_AlphaFine_Search_Title"); |
||||||
|
private static final String RECOMMEND = Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend_Search"); |
||||||
|
private static final Icon icon = IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/search_hint.svg"); |
||||||
|
private static final int HEIGHT = 305; |
||||||
|
private static final int WIDTH = 300; |
||||||
|
private static final int TITLE_FONT_SIZE = 14; |
||||||
|
|
||||||
|
public SearchHintPane() { |
||||||
|
this(new ArrayList<>()); |
||||||
|
} |
||||||
|
|
||||||
|
public SearchHintPane(List<String> hints) { |
||||||
|
this(hints, icon, TITLE); |
||||||
|
} |
||||||
|
|
||||||
|
public SearchHintPane(List<String> hints, Icon icon, String title) { |
||||||
|
setLayout(new BorderLayout()); |
||||||
|
setBackground(Color.white); |
||||||
|
setPreferredSize(new Dimension(WIDTH, HEIGHT)); |
||||||
|
setAlignmentY(SwingConstants.CENTER); |
||||||
|
UILabel image = new UILabel(); |
||||||
|
image.setPreferredSize(new Dimension(150, 111)); |
||||||
|
image.setHorizontalAlignment(SwingConstants.CENTER); |
||||||
|
image.setIcon(icon); |
||||||
|
image.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
||||||
|
add(image, BorderLayout.NORTH); |
||||||
|
add(generateDescription(title), BorderLayout.CENTER); |
||||||
|
add(generateHintsLabel(hints), BorderLayout.SOUTH); |
||||||
|
} |
||||||
|
|
||||||
|
protected Component generateDescription(String title) { |
||||||
|
JLabel description = new JLabel(title); |
||||||
|
description.setForeground(AlphaFineConstants.MEDIUM_GRAY); |
||||||
|
description.setFont(DesignUtils.getDefaultGUIFont().applySize(TITLE_FONT_SIZE)); |
||||||
|
description.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
||||||
|
description.setHorizontalAlignment(SwingConstants.CENTER); |
||||||
|
return description; |
||||||
|
} |
||||||
|
|
||||||
|
private Component generateHintsLabel(List<String> hints) { |
||||||
|
if (Collections.isEmpty(hints)) { |
||||||
|
return new JLabel(); |
||||||
|
} |
||||||
|
return new RecommendSearchLabel(RECOMMEND, hints); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
package com.fr.design.mainframe.alphafine.preview; |
||||||
|
|
||||||
|
import com.fr.design.actions.help.alphafine.AlphaFineConstants; |
||||||
|
import com.fr.design.mainframe.alphafine.CellType; |
||||||
|
import com.fr.design.mainframe.alphafine.component.AlphaFineFrame; |
||||||
|
import com.fr.design.mainframe.alphafine.component.SearchHintPane; |
||||||
|
import com.fr.design.mainframe.alphafine.search.SearchWorkerManager; |
||||||
|
import com.fr.design.mainframe.alphafine.search.manager.SearchProviderRegistry; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
|
||||||
|
/** |
||||||
|
* @version 11.0 |
||||||
|
* @author: Link |
||||||
|
* @date: 2022/9/16 |
||||||
|
* @Description: alphaFine - 默认展示页面 |
||||||
|
*/ |
||||||
|
public class DefaultContentPane extends JPanel { |
||||||
|
|
||||||
|
// 左边展示内容,右边展示搜索提示
|
||||||
|
private SearchWorkerManager searchWorkerManager; |
||||||
|
private CellType cellType; |
||||||
|
|
||||||
|
public DefaultContentPane(CellType cellType, AlphaFineFrame parentWindow) { |
||||||
|
this.setLayout(new BorderLayout()); |
||||||
|
this.setPreferredSize(AlphaFineConstants.PREVIEW_SIZE); |
||||||
|
this.searchWorkerManager = new SearchWorkerManager( |
||||||
|
cellType, |
||||||
|
searchTextBean -> SearchProviderRegistry.getSearchProvider(cellType).getDefaultResult(), |
||||||
|
parentWindow, |
||||||
|
new SimpleRightSearchResultPane(new SearchHintPane()) |
||||||
|
); |
||||||
|
this.searchWorkerManager.showDefault(this); |
||||||
|
} |
||||||
|
|
||||||
|
public DefaultContentPane() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public CellType getCellType() { |
||||||
|
return cellType; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCellType(CellType cellType) { |
||||||
|
this.cellType = cellType; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,80 @@ |
|||||||
|
package com.fr.design.mainframe.alphafine.preview; |
||||||
|
|
||||||
|
import com.fr.design.actions.help.alphafine.AlphaFineConstants; |
||||||
|
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||||
|
import com.fr.design.mainframe.alphafine.CellType; |
||||||
|
import com.fr.design.mainframe.alphafine.component.AlphaFineFrame; |
||||||
|
import com.fr.design.mainframe.alphafine.component.SearchHintPane; |
||||||
|
import com.fr.design.mainframe.alphafine.search.SearchWorkerManager; |
||||||
|
import com.fr.design.mainframe.alphafine.search.manager.SearchProviderRegistry; |
||||||
|
import com.fr.general.CloudCenter; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
|
||||||
|
import javax.swing.SwingWorker; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Link |
||||||
|
* @version 11.0 |
||||||
|
* Created by Link on 2022/9/18 |
||||||
|
* alphafine插件默认页 |
||||||
|
*/ |
||||||
|
public class DefaultPluginContentPane extends DefaultContentPane { |
||||||
|
|
||||||
|
// 左边展示内容,右边展示搜索提示
|
||||||
|
private SearchWorkerManager searchWorkerManager; |
||||||
|
private CellType cellType; |
||||||
|
|
||||||
|
private static final String[] HINTS = CloudCenter.getInstance().acquireConf("alphafine.plugin.recommend", "JS,API,JSON").split(","); |
||||||
|
|
||||||
|
public DefaultPluginContentPane(CellType cellType, AlphaFineFrame parentWindow) { |
||||||
|
super(); |
||||||
|
this.setLayout(new BorderLayout()); |
||||||
|
this.setPreferredSize(AlphaFineConstants.PREVIEW_SIZE); |
||||||
|
new SwingWorker<Boolean, Void>(){ |
||||||
|
@Override |
||||||
|
protected Boolean doInBackground() throws Exception { |
||||||
|
add(new SearchLoadingPane()); |
||||||
|
return AlphaFineHelper.isNetworkOk(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void done() { |
||||||
|
super.done(); |
||||||
|
try { |
||||||
|
boolean networkOk = get(); |
||||||
|
removeAll(); |
||||||
|
if (!networkOk) { |
||||||
|
add(new NetWorkFailedPane()); |
||||||
|
} else { |
||||||
|
List<String> searchKeys = new ArrayList<>(); |
||||||
|
for (String s : HINTS) { |
||||||
|
searchKeys.add(s); |
||||||
|
} |
||||||
|
searchWorkerManager = new SearchWorkerManager( |
||||||
|
cellType, |
||||||
|
searchTextBean -> SearchProviderRegistry.getSearchProvider(cellType).getDefaultResult(), |
||||||
|
parentWindow, |
||||||
|
new SimpleRightSearchResultPane(new SearchHintPane(searchKeys)) |
||||||
|
); |
||||||
|
searchWorkerManager.showDefault(DefaultPluginContentPane.this); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
}.execute(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public CellType getCellType() { |
||||||
|
return cellType; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCellType(CellType cellType) { |
||||||
|
this.cellType = cellType; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
package com.fr.design.mainframe.alphafine.search.manager; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.alphafine.CellType; |
||||||
|
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider; |
||||||
|
import com.fr.design.mainframe.alphafine.search.manager.impl.ActionSearchManager; |
||||||
|
import com.fr.design.mainframe.alphafine.search.manager.impl.FileSearchManager; |
||||||
|
import com.fr.design.mainframe.alphafine.search.manager.impl.PluginSearchManager; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Link |
||||||
|
* @version 11.0 |
||||||
|
* Created by Link on 2022/9/18 |
||||||
|
* alphafine搜索提供者注册到这里 |
||||||
|
*/ |
||||||
|
public class SearchProviderRegistry { |
||||||
|
private static Map<CellType, AlphaFineSearchProvider> map; |
||||||
|
|
||||||
|
static { |
||||||
|
map = new HashMap<>(); |
||||||
|
map.put(CellType.PLUGIN, PluginSearchManager.getInstance()); |
||||||
|
map.put(CellType.ACTION, ActionSearchManager.getInstance()); |
||||||
|
map.put(CellType.FILE, FileSearchManager.getInstance()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据celltype获得对应searchProvider |
||||||
|
* */ |
||||||
|
public static AlphaFineSearchProvider getSearchProvider(CellType cellType) { |
||||||
|
return map.get(cellType); |
||||||
|
} |
||||||
|
} |
After Width: | Height: | Size: 4.3 KiB |
Loading…
Reference in new issue