From f06bebdf9fe51685c14c26f70db694b5e5c03363 Mon Sep 17 00:00:00 2001 From: "alex.sung" Date: Tue, 4 Sep 2018 17:19:23 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-10927=20alphafine=E7=83=AD=E9=97=A8?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E7=9A=84=E7=9B=B8=E5=85=B3=E9=97=AE=E9=A2=98?= =?UTF-8?q?=201.=E7=A7=BB=E5=88=B0=E7=83=AD=E9=97=A8=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E6=9D=A1=E7=9B=AE=E6=97=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=B0=8F?= =?UTF-8?q?=E6=89=8B=E6=A0=B7=E5=BC=8F=E3=80=82=202.=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=85=B3=E9=94=AE=E5=AD=97=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E5=8F=B3=E4=BE=A7=E6=98=AF=E7=A9=BA=E7=99=BD=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82=203.=E5=A2=9E=E5=8A=A0jeditpane=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E7=9A=84html=E7=9A=84=E5=90=84=E7=A7=8D=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E5=93=8D=E5=BA=94=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alphafine/AlphaFineConstants.java | 8 ++++ .../alphafine/cell/model/RobotModel.java | 19 ++++---- .../alphafine/component/AlphaFineDialog.java | 35 ++++++++++----- .../alphafine/preview/RobotPreviewPane.java | 45 +++++++++++++++++-- 4 files changed, 83 insertions(+), 24 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java index e84969bd0..fe72f9c1d 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java @@ -110,6 +110,10 @@ public class AlphaFineConstants { public static final String BOTTOM_REGEX_SECOND = "
"; + public static final String LINK_REGEX = "javascript:;\"([\\s\\S]*?)','"; + + public static final String LINK_REGEX_ANOTHER = "javascript:([\\s\\S]*?)url=\""; + public static final String ALPHA_ROBOT_SEARCH_TOKEN = "K8dl0Np6l0gs"; public static final String SIMILAR_SEARCH_URL_PREFIX = CloudCenter.getInstance().acquireUrlByKind("af.similar_search"); @@ -122,6 +126,10 @@ public class AlphaFineConstants { public static final String ALPHA_GO_TO_WEB = CloudCenter.getInstance().acquireUrlByKind("af.go_web"); + public static final String ALPHA_PREVIEW = CloudCenter.getInstance().acquireUrlByKind("af.preview"); + + public static final String JAVASCRIPT_PREFIX = "javascript:SendJava"; + public static final String CHINESE_CHARACTERS = "[\\u4e00-\\u9fa5]"; public static final String FIRST_PAGE = "-1"; diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/RobotModel.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/RobotModel.java index 47d95514e..273b29fef 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/RobotModel.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/RobotModel.java @@ -1,16 +1,15 @@ package com.fr.design.mainframe.alphafine.cell.model; import com.fr.design.mainframe.alphafine.AlphaFineConstants; -import com.fr.design.mainframe.alphafine.AlphaFineHelper; import com.fr.design.mainframe.alphafine.CellType; -import com.fr.general.http.HttpClient; +import com.fr.general.http.HttpToolbox; import com.fr.json.JSONException; import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; import com.fr.stable.AssistUtils; +import com.fr.stable.StringUtils; import org.apache.commons.codec.digest.DigestUtils; - import java.awt.Desktop; import java.io.IOException; import java.net.URI; @@ -44,17 +43,17 @@ public class RobotModel extends AlphaCellModel { } public static String getContent(String titleStr) { - String result; String token = DigestUtils.md5Hex(AlphaFineConstants.ALPHA_ROBOT_SEARCH_TOKEN + titleStr); String url = AlphaFineConstants.ALPHA_GO_TO_WEB + titleStr + "&token=" + token; - HttpClient httpClient = new HttpClient(url); - httpClient.asGet(); - result = httpClient.getResponseText(); - AlphaFineHelper.checkCancel(); + try { + String result = HttpToolbox.get(url); + if(StringUtils.isEmpty(result)){ + return StringUtils.EMPTY; + } JSONObject jsonObject = new JSONObject(result); return jsonObject.optString("msg"); - } catch (JSONException e) { + } catch (JSONException | IOException e) { FineLoggerFactory.getLogger().error("get robotmodel content error: " + e.getMessage()); } return null; @@ -86,7 +85,7 @@ public class RobotModel extends AlphaCellModel { @Override public void doAction() { try { - Desktop.getDesktop().browse(new URI("http://robot.finereport.com?send=" + super.getName())); + Desktop.getDesktop().browse(new URI(AlphaFineConstants.ALPHA_PREVIEW + super.getName())); } catch (IOException e) { FineLoggerFactory.getLogger().error(e.getMessage()); } catch (URISyntaxException e) { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java index 72156d8ae..7fd1dc09c 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java @@ -11,20 +11,20 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.mainframe.alphafine.AlphaFineConstants; import com.fr.design.mainframe.alphafine.AlphaFineHelper; import com.fr.design.mainframe.alphafine.cell.CellModelHelper; -import com.fr.design.mainframe.alphafine.cell.model.RobotModel; -import com.fr.design.mainframe.alphafine.cell.model.BottomModel; import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel; +import com.fr.design.mainframe.alphafine.cell.model.BottomModel; import com.fr.design.mainframe.alphafine.cell.model.FileModel; import com.fr.design.mainframe.alphafine.cell.model.MoreModel; import com.fr.design.mainframe.alphafine.cell.model.PluginModel; +import com.fr.design.mainframe.alphafine.cell.model.RobotModel; import com.fr.design.mainframe.alphafine.cell.render.ContentCellRender; import com.fr.design.mainframe.alphafine.model.SearchResult; +import com.fr.design.mainframe.alphafine.preview.ContainsCirclePane; import com.fr.design.mainframe.alphafine.preview.DocumentPreviewPane; import com.fr.design.mainframe.alphafine.preview.FilePreviewPane; import com.fr.design.mainframe.alphafine.preview.NoResultPane; import com.fr.design.mainframe.alphafine.preview.PluginPreviewPane; import com.fr.design.mainframe.alphafine.preview.RobotPreviewPane; -import com.fr.design.mainframe.alphafine.preview.ContainsCirclePane; import com.fr.design.mainframe.alphafine.search.manager.impl.ActionSearchManager; import com.fr.design.mainframe.alphafine.search.manager.impl.DocumentSearchManager; import com.fr.design.mainframe.alphafine.search.manager.impl.FileSearchManager; @@ -116,6 +116,7 @@ public class AlphaFineDialog extends UIDialog { private static final String PLACE_HOLDER = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine"); private static final int MAX_SHOW_SIZE = 12; private static final int TIMER_DELAY = 300; + private static final int ONLY_ONE_AVAILABLE_MODEL = 2; private AlphaFineTextField searchTextField; private UIButton closeButton; @@ -705,14 +706,20 @@ public class AlphaFineDialog extends UIDialog { this.showWorker = new SwingWorker() { @Override protected String doInBackground() { + if(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Alpha_Hot_No_Item").equals((selectedValue).getName())){ + return StringUtils.EMPTY; + } String content = RobotModel.getContent((selectedValue).getName()); if(StringUtils.isNotEmpty(content)){ - //去掉小帆底部的信息 - content = content.replaceAll(AlphaFineConstants.BOTTOM_REGEX_FIRST, "") - .replaceAll(AlphaFineConstants.BOTTOM_REGEX_SECOND, ""); + //1.去掉小帆底部的信息。2.修改链接标签,使点击能够正常跳转。 + content = content.replaceAll(AlphaFineConstants.BOTTOM_REGEX_FIRST, StringUtils.EMPTY) + .replaceAll(AlphaFineConstants.BOTTOM_REGEX_SECOND, StringUtils.EMPTY) + .replaceAll(AlphaFineConstants.LINK_REGEX,StringUtils.EMPTY) + .replaceAll("'\\)",StringUtils.EMPTY) + .replaceAll(AlphaFineConstants.LINK_REGEX_ANOTHER,StringUtils.EMPTY); return content; }else{ - return ""; + return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Alpha_Hot_No_Item"); } } @@ -1185,7 +1192,7 @@ public class AlphaFineDialog extends UIDialog { final int x = e.getX(); final int y = e.getY(); final Rectangle cellBounds = getCellBounds(getModel().getSize() - 1, getModel().getSize() - 1); - if (cellBounds != null && cellBounds.contains(x, y)) { + if (cellBounds != null && cellBounds.contains(x, y) && getModel().getElementAt(getModel().getSize() - 1) instanceof BottomModel) { setCursor(new Cursor(Cursor.HAND_CURSOR)); } else { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); @@ -1323,8 +1330,15 @@ public class AlphaFineDialog extends UIDialog { protected Object doInBackground() throws Exception { resetContainer(); - for (AlphaCellModel object : modeList) { - searchListModel.addElement(object); + if(modeList.size() == ONLY_ONE_AVAILABLE_MODEL && "".equals(modeList.get(1).getName())){ + RobotModel model = new RobotModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Alpha_Hot_No_Item"), null); + searchListModel.addElement(model); + }else { + for (AlphaCellModel object : modeList) { + if(!searchListModel.contains(object)){ + searchListModel.addElement(object); + } + } } return null; } @@ -1418,6 +1432,7 @@ public class AlphaFineDialog extends UIDialog { final UILabel subTitle = new UILabel(str[i]); subTitle.setForeground(AlphaFineConstants.DARK_GRAY); subTitle.setFont(AlphaFineConstants.MEDIUM_FONT_ANOTHER); + subTitle.setCursor(new Cursor(Cursor.HAND_CURSOR)); subTitle.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/RobotPreviewPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/RobotPreviewPane.java index 32c5cd820..336e64dce 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/RobotPreviewPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/RobotPreviewPane.java @@ -1,17 +1,26 @@ package com.fr.design.mainframe.alphafine.preview; +import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.itextarea.UITextArea; import com.fr.design.mainframe.alphafine.AlphaFineConstants; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.StringUtils; import javax.swing.BorderFactory; import javax.swing.JEditorPane; import javax.swing.JPanel; -import javax.swing.JScrollPane; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; import javax.swing.text.html.HTMLEditorKit; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Desktop; import java.awt.Dimension; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; /** @@ -30,11 +39,39 @@ public class RobotPreviewPane extends JPanel { titleArea.setFont(AlphaFineConstants.LARGE_FONT); add(titleArea, BorderLayout.NORTH); - JEditorPane editorPane = new JEditorPane(); + final JEditorPane editorPane = new JEditorPane(); editorPane.setEditorKit(new HTMLEditorKit()); - editorPane.setText(content); + editorPane.setText(content+"


"); + editorPane.addHyperlinkListener(new HyperlinkListener() { + @Override + public void hyperlinkUpdate(HyperlinkEvent e) { + if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) { + return; + } + if(e.getDescription().startsWith(AlphaFineConstants.JAVASCRIPT_PREFIX)){ + String s = e.getDescription().replaceAll(AlphaFineConstants.JAVASCRIPT_PREFIX,StringUtils.EMPTY) + .replaceAll("\\('",StringUtils.EMPTY) + .replaceAll("'\\)",StringUtils.EMPTY); + try { + Desktop.getDesktop().browse(new URI(AlphaFineConstants.ALPHA_PREVIEW + s)); + } catch (IOException e1) { + FineLoggerFactory.getLogger().error(e1.getMessage()); + } catch (URISyntaxException e1) { + FineLoggerFactory.getLogger().error(e1.getMessage()); + } + } + URL linkUrl = e.getURL();if (linkUrl != null) { + try { + Desktop.getDesktop().browse(e.getURL().toURI()); + } catch (IOException | URISyntaxException e1) { + FineLoggerFactory.getLogger().error(" Jump to webpage error: " + e1.getMessage()); + } + } + } + }); editorPane.setEditable(false); - JScrollPane jScrollPane = new JScrollPane(editorPane); + UIScrollPane jScrollPane = new UIScrollPane(editorPane); + jScrollPane.getVerticalScrollBar().setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0)); jScrollPane.setBorder(BorderFactory.createMatteBorder(5, 10, 0, 10, Color.white)); add(jScrollPane, BorderLayout.CENTER); }