Browse Source

REPORT-39757 处理搜索词高亮

feature/big-screen
Yyming 4 years ago
parent
commit
9b25fb0625
  1. 24
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java
  2. 34
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  3. 2
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/PluginPreviewPane.java
  4. 4
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/RobotPreviewPane.java
  5. 4
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java
  6. 5
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java
  7. 23
      designer-realize/src/test/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRenderTest.java

24
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java

@ -106,11 +106,10 @@ public class ContentCellRender implements ListCellRenderer<Object> {
if (strings == null) { if (strings == null) {
return modelName; return modelName;
} }
for (int i = 0; i < strings.length; i++) { for (String string : strings) {
String primaryStr = getReplacedString(modelName, strings[i]); String primaryStr = getReplacedString(modelName, string);
modelName = modelName.replaceAll("(?i)" + strings[i], "|<font color=" + AlphaFineConstants.HIGH_LIGHT_COLOR + ">" + strings[i] + "</font>|");
if (StringUtils.isNotEmpty(primaryStr)) { if (StringUtils.isNotEmpty(primaryStr)) {
modelName = modelName.replaceAll(strings[i], primaryStr); modelName = modelName.replaceAll("(?i)" + primaryStr, "|<font color=" + AlphaFineConstants.HIGH_LIGHT_COLOR + ">" + primaryStr + "</font>|");
} }
} }
modelName = "<html><head><style> .style{" + modelName = "<html><head><style> .style{" +
@ -121,13 +120,24 @@ public class ContentCellRender implements ListCellRenderer<Object> {
return modelName; return modelName;
} }
private String getReplacedString(String modelName, String string) { private String getReplacedString(String modelName, String string) {
int index = modelName.toLowerCase().indexOf(string.toLowerCase()); //需要考虑modelName有空格的情况
//比如现在是work boo k 搜索词是workb,应该要替换的部分是work b
//先去掉空格进行匹配
String noBlackName = modelName.replaceAll(StringUtils.BLANK, StringUtils.EMPTY).toLowerCase();
int index = noBlackName.indexOf(string.toLowerCase());
if (index == -1) { if (index == -1) {
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
return modelName.substring(index, index + string.length()); StringBuilder result = new StringBuilder();
int count = 0;
while (count < string.length()) {
char pos = modelName.charAt(index++);
result.append(pos);
count += pos == ' ' ? 0 : 1;
}
return result.toString();
} }

34
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java

@ -162,10 +162,7 @@ public class AlphaFineDialog extends UIDialog {
* @return * @return
*/ */
public static AWTEventListener listener() { public static AWTEventListener listener() {
return new AWTEventListener() { return event -> {
@Override
public void eventDispatched(AWTEvent event) {
if (event instanceof KeyEvent) { if (event instanceof KeyEvent) {
KeyEvent e = (KeyEvent) event; KeyEvent e = (KeyEvent) event;
KeyStroke keyStroke = (KeyStroke) KeyStroke.getAWTKeyStrokeForEvent(e); KeyStroke keyStroke = (KeyStroke) KeyStroke.getAWTKeyStrokeForEvent(e);
@ -175,7 +172,6 @@ public class AlphaFineDialog extends UIDialog {
} }
} }
}
}; };
} }
@ -513,7 +509,8 @@ public class AlphaFineDialog extends UIDialog {
* @return * @return
*/ */
private String getStoreText(String searchText) { private String getStoreText(String searchText) {
setStoreText(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); //这里也需要先做一个去除不需要空格的处理
setStoreText((searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1)).replaceAll(StringUtils.BLANK, StringUtils.EMPTY));
return storeText; return storeText;
} }
@ -616,9 +613,7 @@ public class AlphaFineDialog extends UIDialog {
rightSearchResultPane.removeAll(); rightSearchResultPane.removeAll();
try { try {
rightSearchResultPane.add(new FilePreviewPane(get())); rightSearchResultPane.add(new FilePreviewPane(get()));
} catch (InterruptedException e) { } catch (InterruptedException | ExecutionException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (ExecutionException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
validate(); validate();
@ -651,9 +646,7 @@ public class AlphaFineDialog extends UIDialog {
rightSearchResultPane.add(new FilePreviewPane(get())); rightSearchResultPane.add(new FilePreviewPane(get()));
validate(); validate();
repaint(); repaint();
} catch (InterruptedException e) { } catch (InterruptedException | ExecutionException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (ExecutionException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
} }
@ -876,7 +869,7 @@ public class AlphaFineDialog extends UIDialog {
searchText = searchText.toLowerCase(); searchText = searchText.toLowerCase();
Pattern p = Pattern.compile(AlphaFineConstants.SPECIAL_CHARACTER_REGEX); Pattern p = Pattern.compile(AlphaFineConstants.SPECIAL_CHARACTER_REGEX);
Matcher m = p.matcher(searchText); Matcher m = p.matcher(searchText);
searchText = m.replaceAll("").trim().replaceAll(" ", ""); searchText = m.replaceAll(StringUtils.EMPTY).trim().replaceAll(StringUtils.BLANK, StringUtils.EMPTY);
if (searchText.length() == 0) { if (searchText.length() == 0) {
return null; return null;
} }
@ -897,9 +890,7 @@ public class AlphaFineDialog extends UIDialog {
* 当鼠标在搜索界面边界外点击时触发 * 当鼠标在搜索界面边界外点击时触发
*/ */
private void initAWTEventListener() { private void initAWTEventListener() {
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { Toolkit.getDefaultToolkit().addAWTEventListener(event -> {
@Override
public void eventDispatched(AWTEvent event) {
if (!AlphaFineDialog.this.isVisible()) { if (!AlphaFineDialog.this.isVisible()) {
return; return;
} }
@ -915,7 +906,6 @@ public class AlphaFineDialog extends UIDialog {
} }
} }
} }
}
}, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK); }, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
} }
@ -944,15 +934,12 @@ public class AlphaFineDialog extends UIDialog {
if (cellModel instanceof BottomModel) { if (cellModel instanceof BottomModel) {
return; return;
} }
Thread sendThread = new Thread(new Runnable() { Thread sendThread = new Thread(() -> {
@Override
public void run() {
if (StringUtils.isNotEmpty(storeText)) { if (StringUtils.isNotEmpty(storeText)) {
RecentSearchManager searchManager = RecentSearchManager.getInstance(); RecentSearchManager searchManager = RecentSearchManager.getInstance();
searchManager.addModel(storeText, cellModel); searchManager.addModel(storeText, cellModel);
sendDataToServer(storeText, cellModel); sendDataToServer(storeText, cellModel);
} }
}
}); });
sendThread.start(); sendThread.start();
} }
@ -1178,13 +1165,10 @@ public class AlphaFineDialog extends UIDialog {
} }
}); });
addListSelectionListener(new ListSelectionListener() { addListSelectionListener(e -> {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting() && getSelectedValue() != null) { if (!e.getValueIsAdjusting() && getSelectedValue() != null) {
showResult(getSelectedValue()); showResult(getSelectedValue());
} }
}
}); });
addMouseMotionListener(new MouseMotionListener() { addMouseMotionListener(new MouseMotionListener() {

2
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/PluginPreviewPane.java

@ -49,7 +49,7 @@ public class PluginPreviewPane extends JPanel {
nameLabel.setBackground(AlphaFineConstants.BLUE); nameLabel.setBackground(AlphaFineConstants.BLUE);
nameLabel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20)); nameLabel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20));
line.setBorder(BorderFactory.createEmptyBorder(20, 0, 10, 0)); line.setBorder(BorderFactory.createEmptyBorder(20, 0, 10, 0));
String price0 = price == 0 ? com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Collect_Information_free") : "¥" + String.valueOf(price); String price0 = price == 0 ? com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Collect_Information_free") : "¥" + price;
UILabel priceLabel = new UILabel(price0); UILabel priceLabel = new UILabel(price0);
priceLabel.setForeground(AlphaFineConstants.RED); priceLabel.setForeground(AlphaFineConstants.RED);
priceLabel.setFont(AlphaFineConstants.MEDIUM_FONT); priceLabel.setFont(AlphaFineConstants.MEDIUM_FONT);

4
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/RobotPreviewPane.java

@ -61,9 +61,7 @@ public class RobotPreviewPane extends JPanel {
.replaceAll("'\\)", StringUtils.EMPTY); .replaceAll("'\\)", StringUtils.EMPTY);
try { try {
Desktop.getDesktop().browse(new URI(AlphaFineConstants.ALPHA_PREVIEW + URLEncoder.encode(s, EncodeConstants.ENCODING_UTF_8))); Desktop.getDesktop().browse(new URI(AlphaFineConstants.ALPHA_PREVIEW + URLEncoder.encode(s, EncodeConstants.ENCODING_UTF_8)));
} catch (IOException e1) { } catch (IOException | URISyntaxException e1) {
FineLoggerFactory.getLogger().error(e1.getMessage());
} catch (URISyntaxException e1) {
FineLoggerFactory.getLogger().error(e1.getMessage()); FineLoggerFactory.getLogger().error(e1.getMessage());
} }
} }

4
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java

@ -142,10 +142,10 @@ public class FileSearchManager implements AlphaFineSearchProvider {
private String dealWithSearchText(String searchText) { private String dealWithSearchText(String searchText) {
if (searchText.startsWith(FRM_PREFIX)) { if (searchText.startsWith(FRM_PREFIX)) {
isContainCpt = false; isContainCpt = false;
searchText = searchText.substring(MARK_LENGTH, searchText.length()); searchText = searchText.substring(MARK_LENGTH);
} else if (searchText.startsWith(CPT_PREFIX)) { } else if (searchText.startsWith(CPT_PREFIX)) {
isContainFrm = false; isContainFrm = false;
searchText = searchText.substring(MARK_LENGTH, searchText.length()); searchText = searchText.substring(MARK_LENGTH);
} }
return searchText; return searchText;
} }

5
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java

@ -42,10 +42,7 @@ public class SegmentationManager {
count = count + 1; count = count + 1;
} }
} }
if (count >= MAX_CHINESE_CHARACTERS_NUM) { return count >= MAX_CHINESE_CHARACTERS_NUM;
return true;
}
return false;
} }
/** /**

23
designer-realize/src/test/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRenderTest.java

@ -0,0 +1,23 @@
package com.fr.design.mainframe.alphafine.cell.render;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Yyming
* @version 10.0
* Created by Yyming on 2020/9/16
*/
public class ContentCellRenderTest {
@Test
public void highLightModelName() {
String searchText = "workb";
ContentCellRender contentCellRender = new ContentCellRender(searchText,new String[]{searchText});
String workbook = contentCellRender.highLightModelName("workbook", new String[]{searchText});
assertTrue(workbook.endsWith("workb</font>ook</body></HTML>"));
workbook = contentCellRender.highLightModelName("work book", new String[]{searchText});
assertTrue(workbook.endsWith("work b</font>ook</body></HTML>"));
}
}
Loading…
Cancel
Save