From ff8a971875f5b46a8df6cc162f4c6e4de40f08b8 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Mon, 19 Jun 2017 17:30:59 +0800 Subject: [PATCH 01/13] alphafine bug fix --- .../alphafine/AlphaFineConstants.java | 2 + .../alphafine/cell/model/AlphaCellModel.java | 3 + .../alphafine/cell/model/NoResultModel.java | 5 + .../cell/render/ContentCellRender.java | 10 +- .../cell/render/TitleCellRender.java | 6 +- .../alphafine/component/AlphaFineDialog.java | 192 +++++++----------- .../search/manager/FileSearchManager.java | 7 +- 7 files changed, 95 insertions(+), 130 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java b/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java index c0ca472c6..3fd3a3b14 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java +++ b/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java @@ -30,6 +30,8 @@ public class AlphaFineConstants { public static final int CELL_HEIGHT = 32; + public static final int CELL_TITLE_HEIGHT = 24; + public static final Dimension FULL_SIZE = new Dimension(680, 460); diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java index 5241fee0e..d37d2708d 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java @@ -60,6 +60,9 @@ public abstract class AlphaCellModel { this.description = description; } + public boolean hasNoResult() { + return false; + } /** * model转json * diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/model/NoResultModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/model/NoResultModel.java index 1dbdb450b..afd500ee9 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/model/NoResultModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/model/NoResultModel.java @@ -21,4 +21,9 @@ public class NoResultModel extends AlphaCellModel { public String getStoreInformation() { return null; } + + @Override + public boolean hasNoResult() { + return true; + } } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java b/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java index b6b8e738e..29f22b029 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java @@ -2,10 +2,8 @@ package com.fr.design.mainframe.alphafine.cell.render; import com.fr.design.gui.ilable.UILabel; import com.fr.design.mainframe.alphafine.AlphaFineConstants; -import com.fr.design.mainframe.alphafine.CellType; import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel; import com.fr.design.mainframe.alphafine.cell.model.MoreModel; -import com.fr.general.IOUtils; import com.fr.stable.StringUtils; import javax.swing.*; @@ -28,17 +26,16 @@ public class ContentCellRender implements ListCellRenderer { if (value instanceof MoreModel) { return new TitleCellRender().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } + AlphaCellModel model = (AlphaCellModel) value; JPanel panel = new JPanel(new BorderLayout()); panel.setBackground(Color.white); - if (isSelected) { + if (isSelected && !model.hasNoResult()) { panel.setBackground(AlphaFineConstants.BLUE); } panel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0)); - AlphaCellModel model = (AlphaCellModel) value; name.setText(model.getName()); String iconUrl = "/com/fr/design/mainframe/alphafine/images/alphafine" + model.getType().getTypeValue() + ".png"; - name.setIcon(IOUtils.readIcon(iconUrl)); - if (model.getType() == CellType.NO_RESULT) { + if (model.hasNoResult()) { name.setIcon(null); name.setForeground(AlphaFineConstants.MEDIUM_GRAY); } else { @@ -55,6 +52,7 @@ public class ContentCellRender implements ListCellRenderer { panel.add(content, BorderLayout.CENTER); } panel.add(name, BorderLayout.WEST); + panel.setPreferredSize(new Dimension((int) panel.getPreferredSize().getWidth(), AlphaFineConstants.CELL_HEIGHT)); return panel; } } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java b/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java index 54e9ed15c..03c1c5f8b 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java @@ -3,7 +3,6 @@ package com.fr.design.mainframe.alphafine.cell.render; import com.fr.design.gui.ilable.UILabel; import com.fr.design.mainframe.alphafine.AlphaFineConstants; import com.fr.design.mainframe.alphafine.cell.model.MoreModel; -import com.fr.general.IOUtils; import javax.swing.*; import java.awt.*; @@ -38,13 +37,14 @@ public class TitleCellRender implements ListCellRenderer { panel.add(this.more, BorderLayout.EAST); } if (moreModel.isLoading()) { - ImageIcon imageIcon = (ImageIcon) IOUtils.readIcon("/com/fr/design/mainframe/alphafine/images/loading.gif"); - + ImageIcon imageIcon = new ImageIcon(getClass().getResource("/com/fr/design/mainframe/alphafine/images/loading.gif")); + //设置cell的加载动画 imageIcon.setImageObserver(list); UILabel loadingLabel = new UILabel(imageIcon); panel.add(loadingLabel, BorderLayout.SOUTH); } + panel.setPreferredSize(new Dimension((int) panel.getPreferredSize().getWidth(), AlphaFineConstants.CELL_TITLE_HEIGHT)); return panel; } } 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 18df7363c..8b0e91da9 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java +++ b/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java @@ -27,7 +27,6 @@ import com.fr.form.main.Form; import com.fr.form.main.FormIO; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; -import com.fr.general.IOUtils; import com.fr.general.Inter; import com.fr.general.http.HttpClient; import com.fr.io.TemplateWorkBookIO; @@ -60,29 +59,18 @@ import java.util.concurrent.ExecutionException; * Created by XiaXiang on 2017/3/21. */ public class AlphaFineDialog extends UIDialog { - + private static final String ADVANCED_SEARCH_MARK = "k:"; private static final String ACTION_MARK_SHORT = "k:1 "; - private static final String ACTION_MARK = "k:setting "; - private static final String DOCUMENT_MARK_SHORT = "k:2 "; - private static final String DOCUMENT_MARK = "k:help "; - private static final String FILE_MARK_SHORT = "k:3 "; - private static final String FILE_MARK = "k:reportlets "; - private static final String CPT_MARK = "k:cpt "; - private static final String FRM_MARK = "k:frm "; - private static final String DS_MARK = "k:ds "; - private static final String DS_NAME = "dsname=\""; - private static final String PLUGIN_MARK_SHORT = "k:4 "; - private static final String PLUGIN_MARK = "k:shop "; private AlphaFineTextField searchTextField; @@ -96,8 +84,8 @@ public class AlphaFineDialog extends UIDialog { private SwingWorker searchWorker; //是否强制打开,因为面板是否关闭绑定了全局鼠标事件,这里需要处理一下 private boolean forceOpen; - - + + public AlphaFineDialog(Frame parent, boolean forceOpen) { super(parent); this.forceOpen = forceOpen; @@ -105,19 +93,17 @@ public class AlphaFineDialog extends UIDialog { initListener(); initComponents(); } - + /** * 全局快捷键 * * @return */ public static AWTEventListener listener() { - return new AWTEventListener() { - + @Override public void eventDispatched(AWTEvent event) { - if (event instanceof KeyEvent) { KeyEvent e = (KeyEvent) event; KeyStroke keyStroke = (KeyStroke) KeyStroke.getAWTKeyStrokeForEvent(e); @@ -125,39 +111,35 @@ public class AlphaFineDialog extends UIDialog { if (ComparatorUtils.equals(keyStroke.toString(), storeKeyStroke.toString()) && AlphaFinePane.getAlphaFinePane().isVisible()) { doClickAction(); } - + } } }; } - + private static void doClickAction() { - AlphaFineHelper.showAlphaFineDialog(false); } - + /** * 初始化全部组件 */ private void initComponents() { - searchTextField = new AlphaFineTextField("AlphaFine"); searchTextField.setFont(AlphaFineConstants.GREATER_FONT); searchTextField.setBackground(Color.white); searchTextField.setBorderPainted(false); searchTextField.initKeyListener(this); JPanel topPane = new JPanel(new BorderLayout()); - UILabel iconLabel = new UILabel(IOUtils.readIcon("/com/fr/design/mainframe/alphafine/images/bigsearch.png")); + UILabel iconLabel = new UILabel(new ImageIcon(getClass().getResource("/com/fr/design/mainframe/alphafine/images/bigsearch.png"))); iconLabel.setPreferredSize(AlphaFineConstants.ICON_LABEL_SIZE); iconLabel.setOpaque(true); iconLabel.setBackground(Color.white); topPane.add(iconLabel, BorderLayout.WEST); topPane.add(searchTextField, BorderLayout.CENTER); closeButton = new UIButton() { - @Override public void paintComponent(Graphics g) { - g.setColor(Color.white); g.fillRect(0, 0, getSize().width, getSize().height); super.paintComponent(g); @@ -165,13 +147,11 @@ public class AlphaFineDialog extends UIDialog { }; closeButton.setContentAreaFilled(false); closeButton.setPreferredSize(AlphaFineConstants.CLOSE_BUTTON_SIZE); - closeButton.setIcon(IOUtils.readIcon("/com/fr/design/mainframe/alphafine/images/alphafine_close.png")); + closeButton.setIcon(new ImageIcon(getClass().getResource("/com/fr/design/mainframe/alphafine/images/alphafine_close.png"))); closeButton.set4ToolbarButton(); closeButton.addActionListener(new ActionListener() { - @Override public void actionPerformed(ActionEvent e) { - dispose(); } }); @@ -182,38 +162,34 @@ public class AlphaFineDialog extends UIDialog { topPane.add(borderLabel, BorderLayout.SOUTH); add(topPane, BorderLayout.CENTER); searchTextField.getDocument().addDocumentListener(new DocumentAdapter() { - @Override protected void textChanged(DocumentEvent e) { - doSearch(searchTextField.getText()); } }); } - + /** * */ private void initProperties() { - setUndecorated(true); addComponentListener(new ComponentHandler()); setSize(AlphaFineConstants.FIELD_SIZE); centerWindow(this); - + } - + /** * 设置面板位置 * * @param win */ private void centerWindow(Window win) { - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - + Dimension winSize = win.getSize(); - + if (winSize.height > screenSize.height) { winSize.height = screenSize.height; } @@ -223,7 +199,7 @@ public class AlphaFineDialog extends UIDialog { //这里设置位置:水平居中,竖直偏上 win.setLocation((screenSize.width - winSize.width) / 2, (screenSize.height - winSize.height) / AlphaFineConstants.SHOW_SIZE); } - + // TODO: 2017/5/8 xiaxiang: 窗体圆角setShape()有毛边,重写paint方法可以解决毛边问题,但带来了别的问题,处理比较麻烦,暂用setShape(); // public void paint(Graphics g){ // @@ -235,29 +211,26 @@ public class AlphaFineDialog extends UIDialog { // g2.fillRoundRect(0, 0, getWidth(), getHeight(), 25, 25); // g2.dispose(); // } - + /** * 执行搜索 * * @param text */ private void doSearch(String text) { - - if (StringUtils.isBlank(text) || text.equals("AlphaFine")) { + + if (StringUtils.isBlank(text) || text.equals("AlphaFine") || text.contains("'")) { removeSearchResult(); - } else if (text.contains("'")) { - return; } else { showSearchResult(); } - + } - + /** * 移除搜索结果 */ private void removeSearchResult() { - if (searchResultPane != null) { remove(searchResultPane); searchResultPane = null; @@ -265,7 +238,7 @@ public class AlphaFineDialog extends UIDialog { setSize(AlphaFineConstants.FIELD_SIZE); repaint(); } - + /** * 展示搜索结果 */ @@ -276,12 +249,11 @@ public class AlphaFineDialog extends UIDialog { } initSearchWorker(); } - + /** * 初始化搜索面板 */ private void initSearchResultComponents() { - searchResultList = new JList(); searchListModel = new SearchListModel(new SearchResult()); searchResultList.setModel(searchListModel); @@ -289,8 +261,7 @@ public class AlphaFineDialog extends UIDialog { searchResultPane.setPreferredSize(AlphaFineConstants.CONTENT_SIZE); searchResultPane.setLayout(new BorderLayout()); searchResultList.setCellRenderer(new ContentCellRender()); - searchResultList.setFixedCellHeight(AlphaFineConstants.CELL_HEIGHT); - + leftSearchResultPane = new UIScrollPane(searchResultList); leftSearchResultPane.setBackground(Color.white); leftSearchResultPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); @@ -303,7 +274,7 @@ public class AlphaFineDialog extends UIDialog { add(searchResultPane, BorderLayout.SOUTH); setSize(AlphaFineConstants.FULL_SIZE); } - + /** * 异步加载搜索结果 */ @@ -315,15 +286,13 @@ public class AlphaFineDialog extends UIDialog { this.searchWorker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { - rebuildList(searchTextField.getText().toLowerCase()); return null; } @Override protected void done() { - - if (!isCancelled() && searchListModel.getSize() > 0) { + if (!isCancelled() && searchListModel.getSize() > 1) { searchResultList.setSelectedIndex(1); showResult(searchResultList.getSelectedIndex(), searchResultList.getSelectedValue()); } @@ -331,7 +300,7 @@ public class AlphaFineDialog extends UIDialog { }; this.searchWorker.execute(); } - + /** * 重新构建搜索结果列表 * 先根据输入判断是不是隐藏的搜索功能 @@ -339,37 +308,33 @@ public class AlphaFineDialog extends UIDialog { * @param searchText */ private void rebuildList(String searchText) { - searchListModel.removeAllElements(); - if (searchText.startsWith(ACTION_MARK_SHORT) || searchText.startsWith(ACTION_MARK)) { - getActionList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); - return; - } else if (searchText.startsWith(DOCUMENT_MARK_SHORT) || searchText.startsWith(DOCUMENT_MARK)) { - getDocumentList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); - return; - } else if (searchText.startsWith(FILE_MARK_SHORT) || searchText.startsWith(FILE_MARK)) { - getFileList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); - return; - } else if (searchText.startsWith(CPT_MARK) || searchText.startsWith(FRM_MARK)) { - getFileList(searchText); - return; - } else if (searchText.startsWith(DS_MARK)) { - getFileList(DS_NAME + searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); - return; - } else if (searchText.startsWith(PLUGIN_MARK_SHORT) || searchText.startsWith(PLUGIN_MARK)) { - getPluginList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); - return; + if (searchText.startsWith(ADVANCED_SEARCH_MARK)) { + if (searchText.startsWith(ACTION_MARK_SHORT) || searchText.startsWith(ACTION_MARK)) { + getActionList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); + } else if (searchText.startsWith(DOCUMENT_MARK_SHORT) || searchText.startsWith(DOCUMENT_MARK)) { + getDocumentList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); + } else if (searchText.startsWith(FILE_MARK_SHORT) || searchText.startsWith(FILE_MARK)) { + getFileList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); + } else if (searchText.startsWith(CPT_MARK) || searchText.startsWith(FRM_MARK)) { + getFileList(searchText); + } else if (searchText.startsWith(DS_MARK)) { + getFileList(DS_NAME + searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); + } else if (searchText.startsWith(PLUGIN_MARK_SHORT) || searchText.startsWith(PLUGIN_MARK)) { + getPluginList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); + } + } else { + doNormalSearch(searchText.trim()); } - doNormalSearch(searchText.trim()); + } - + /** * 普通搜索 * * @param searchText */ private void doNormalSearch(String searchText) { - getRecentList(searchText); getRecommendList(searchText); getActionList(searchText); @@ -377,63 +342,57 @@ public class AlphaFineDialog extends UIDialog { getDocumentList(searchText); getPluginList(searchText); } - + private synchronized void getDocumentList(final String searchText) { - SearchResult documentModelList = DocumentSearchManager.getDocumentSearchManager().getLessSearchResult(searchText); for (Object object : documentModelList) { AlphaFineHelper.checkCancel(); searchListModel.addElement(object); } - + } - + private synchronized void getFileList(final String searchText) { - SearchResult fileModelList = FileSearchManager.getFileSearchManager().getLessSearchResult(searchText); for (Object object : fileModelList) { AlphaFineHelper.checkCancel(); searchListModel.addElement(object); } } - + private synchronized void getActionList(final String searchText) { - SearchResult actionModelList = ActionSearchManager.getActionSearchManager().getLessSearchResult(searchText); for (Object object : actionModelList) { AlphaFineHelper.checkCancel(); searchListModel.addElement(object); } } - + private synchronized void getPluginList(final String searchText) { - SearchResult pluginModelList = PluginSearchManager.getPluginSearchManager().getLessSearchResult(searchText); for (Object object : pluginModelList) { AlphaFineHelper.checkCancel(); searchListModel.addElement(object); } } - + private synchronized void getRecommendList(final String searchText) { - SearchResult recommendModelList = RecommendSearchManager.getRecommendSearchManager().getLessSearchResult(searchText); for (Object object : recommendModelList) { AlphaFineHelper.checkCancel(); searchListModel.addElement(object); } } - + private synchronized void getRecentList(final String searchText) { - SearchResult recentModelList = RecentSearchManager.getRecentSearchManger().getLessSearchResult(searchText); for (Object object : recentModelList) { AlphaFineHelper.checkCancel(); searchListModel.addElement(object); } - + } - + /** * 初始化监听器 */ @@ -458,7 +417,7 @@ public class AlphaFineDialog extends UIDialog { } } }); - + /** *单击时触发右侧面板展示搜索结果 */ @@ -471,7 +430,7 @@ public class AlphaFineDialog extends UIDialog { } } }); - + /** * 键盘监听器 */ @@ -557,7 +516,6 @@ public class AlphaFineDialog extends UIDialog { } - } else if (selectedValue instanceof DocumentModel) { rightSearchResultPane.removeAll(); rightSearchResultPane.add(new DocumentPreviewPane(((DocumentModel) selectedValue).getName(), ((DocumentModel) selectedValue).getContent())); @@ -576,7 +534,11 @@ public class AlphaFineDialog extends UIDialog { try { bufferedImage = ImageIO.read(new URL(((PluginModel) selectedValue).getImageUrl())); } catch (IOException e) { - bufferedImage = IOUtils.readImage("/com/fr/design/mainframe/alphafine/images/default_product.png"); + try { + bufferedImage = ImageIO.read(getClass().getResource("/com/fr/design/mainframe/alphafine/images/default_product.png")); + } catch (IOException e1) { + FRLogger.getLogger().error(e.getMessage()); + } } return bufferedImage; } @@ -622,8 +584,8 @@ public class AlphaFineDialog extends UIDialog { private void showDefaultPreviewPane() { rightSearchResultPane.removeAll(); - UILabel label = new UILabel(IOUtils.readIcon("/com/fr/design/mainframe/alphafine/images/opening.gif")); - label.setBorder(BorderFactory.createEmptyBorder(120,0,0,0)); + UILabel label = new UILabel(new ImageIcon(getClass().getResource("/com/fr/design/mainframe/alphafine/images/opening.gif"))); + label.setBorder(BorderFactory.createEmptyBorder(120, 0, 0, 0)); rightSearchResultPane.add(label, BorderLayout.CENTER); validate(); repaint(); @@ -635,28 +597,23 @@ public class AlphaFineDialog extends UIDialog { initMouseListener(); } - + /** * 窗口拖拽 */ private void initMouseListener() { - addMouseMotionListener(new MouseMotionAdapter() { - @Override public void mouseDragged(MouseEvent e) { - doMouseDragged(e); } }); - + addMouseListener(new MouseAdapter() { - public void mousePressed(MouseEvent e) { - doMousePressed(e); } - + }); } @@ -787,7 +744,7 @@ public class AlphaFineDialog extends UIDialog { } } - + /** * 点击显示更多时,添加对应的model到list;点击收起是移除model * @@ -795,7 +752,6 @@ public class AlphaFineDialog extends UIDialog { * @param selectedValue */ private void rebuildShowMoreList(int index, MoreModel selectedValue) { - SearchResult moreResult = getMoreResult(selectedValue); if ((selectedValue).getContent().equals(Inter.getLocText("FR-Designer_AlphaFine_ShowLess"))) { for (int i = 0; i < moreResult.size(); i++) { @@ -804,14 +760,14 @@ public class AlphaFineDialog extends UIDialog { } else { for (int i = 0; i < moreResult.size(); i++) { this.searchListModel.remove(index + AlphaFineConstants.SHOW_SIZE + 1); - + } } this.searchResultList.validate(); this.searchResultList.repaint(); validate(); repaint(); - + } private void rebuildList() { @@ -858,16 +814,14 @@ public class AlphaFineDialog extends UIDialog { public void setSearchWorker(SwingWorker searchWorker) { this.searchWorker = searchWorker; } - - + + public boolean isForceOpen() { - return forceOpen; } - + public void setForceOpen(boolean forceOpen) { - this.forceOpen = forceOpen; } - + } \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java index 19cc5d526..dd8f6312b 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java @@ -27,6 +27,8 @@ import java.util.List; public class FileSearchManager implements AlphaFineSearchProcessor { private static final int MARK_LENGTH = 6; private static final String DS_NAME = "dsname=\""; + private static final String FRM_PREFIX = "k:frm "; + private static final String CPT_PREFIX = "k:cpt "; private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_Templates"), CellType.FILE); private static FileSearchManager fileSearchManager = null; private SearchResult filterModelList; @@ -63,10 +65,10 @@ public class FileSearchManager implements AlphaFineSearchProcessor { this.filterModelList = new SearchResult(); this.lessModelList = new SearchResult(); this.moreModelList = new SearchResult(); - if (searchText.startsWith("k:frm ")) { + if (searchText.startsWith(FRM_PREFIX)) { isContainCpt = false; searchText = searchText.substring(MARK_LENGTH, searchText.length()); - } else if (searchText.startsWith("k:cpt ")) { + } else if (searchText.startsWith(CPT_PREFIX)) { isContainFrm = false; searchText = searchText.substring(MARK_LENGTH, searchText.length()); } @@ -139,6 +141,7 @@ public class FileSearchManager implements AlphaFineSearchProcessor { FileModel model = new FileModel(node.getName(), node.getEnvPath()); this.filterModelList.add(model); } + isr.close(); reader.close(); } catch (FileNotFoundException e) { FRLogger.getLogger().error(e.getMessage()); From cf1e437d40704a0f46d5310c90c4a7ef7c558a6a Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Tue, 20 Jun 2017 16:53:13 +0800 Subject: [PATCH 02/13] =?UTF-8?q?REPORT-3022=20=E6=99=BA=E8=83=BD=E6=90=9C?= =?UTF-8?q?=E7=B4=A2619=E5=BC=95=E6=93=8E=E5=8A=9F=E8=83=BD=E6=94=B9?= =?UTF-8?q?=E8=89=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cell/render/ContentCellRender.java | 21 ++++++++++++------- .../cell/render/TitleCellRender.java | 4 ++-- .../alphafine/component/AlphaFineDialog.java | 18 +++++++++++++--- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java b/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java index 29f22b029..f5369a9c5 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java @@ -17,23 +17,24 @@ public class ContentCellRender implements ListCellRenderer { private UILabel content; public ContentCellRender() { - this.name = new UILabel(); - this.content = new UILabel(); + } @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + this.name = new UILabel(); + this.content = new UILabel(); if (value instanceof MoreModel) { return new TitleCellRender().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } AlphaCellModel model = (AlphaCellModel) value; JPanel panel = new JPanel(new BorderLayout()); - panel.setBackground(Color.white); + panel.setBackground(null); if (isSelected && !model.hasNoResult()) { panel.setBackground(AlphaFineConstants.BLUE); } - panel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0)); - name.setText(model.getName()); + panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); + name.setText(" " + model.getName()); String iconUrl = "/com/fr/design/mainframe/alphafine/images/alphafine" + model.getType().getTypeValue() + ".png"; if (model.hasNoResult()) { name.setIcon(null); @@ -43,16 +44,20 @@ public class ContentCellRender implements ListCellRenderer { name.setForeground(AlphaFineConstants.BLACK); } name.setFont(AlphaFineConstants.MEDIUM_FONT); - name.setVerticalTextPosition(SwingConstants.CENTER); - name.setHorizontalTextPosition(SwingConstants.RIGHT); String description = model.getDescription(); if (StringUtils.isNotBlank(description)) { content.setText("-" + description); content.setForeground(AlphaFineConstants.LIGHT_GRAY); panel.add(content, BorderLayout.CENTER); + int width = (int) (name.getPreferredSize().getWidth() + content.getPreferredSize().getWidth()); + if ( width > AlphaFineConstants.LEFT_WIDTH - 30) { + int nameWidth = (int) (AlphaFineConstants.LEFT_WIDTH - content.getPreferredSize().getWidth() - 45); + name.setPreferredSize(new Dimension(nameWidth, AlphaFineConstants.CELL_HEIGHT)); + } } + panel.add(name, BorderLayout.WEST); - panel.setPreferredSize(new Dimension((int) panel.getPreferredSize().getWidth(), AlphaFineConstants.CELL_HEIGHT)); + panel.setPreferredSize(new Dimension(list.getFixedCellWidth(), AlphaFineConstants.CELL_HEIGHT)); return panel; } } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java b/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java index 03c1c5f8b..215355639 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java @@ -24,7 +24,7 @@ public class TitleCellRender implements ListCellRenderer { MoreModel moreModel = (MoreModel) value; JPanel panel = new JPanel(new BorderLayout()); panel.setBackground(AlphaFineConstants.WHITE); - panel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0)); + panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); name.setText(moreModel.getName()); name.setFont(AlphaFineConstants.SMALL_FONT); more.setFont(AlphaFineConstants.SMALL_FONT); @@ -44,7 +44,7 @@ public class TitleCellRender implements ListCellRenderer { UILabel loadingLabel = new UILabel(imageIcon); panel.add(loadingLabel, BorderLayout.SOUTH); } - panel.setPreferredSize(new Dimension((int) panel.getPreferredSize().getWidth(), AlphaFineConstants.CELL_TITLE_HEIGHT)); + panel.setPreferredSize(new Dimension(list.getFixedCellWidth(), AlphaFineConstants.CELL_TITLE_HEIGHT)); return panel; } } 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 8b0e91da9..3dd2b844e 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java +++ b/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java @@ -174,7 +174,7 @@ public class AlphaFineDialog extends UIDialog { */ private void initProperties() { setUndecorated(true); - addComponentListener(new ComponentHandler()); + //addComponentListener(new ComponentHandler()); setSize(AlphaFineConstants.FIELD_SIZE); centerWindow(this); @@ -394,7 +394,7 @@ public class AlphaFineDialog extends UIDialog { } /** - * 初始化监听器 + * 为各组件添加鼠标,键盘监听器 */ private void initListListener() { /** @@ -432,7 +432,7 @@ public class AlphaFineDialog extends UIDialog { }); /** - * 键盘监听器 + * 为list添加键盘监听器 */ searchResultList.addKeyListener(new KeyAdapter() { @Override @@ -446,6 +446,18 @@ public class AlphaFineDialog extends UIDialog { } } }); + + /** + * 为textField添加键盘监听器,按上下方向键时把焦点给list,实现键盘操作 + */ + searchTextField.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) { + searchResultList.requestFocus(); + } + } + }); } private void showResult(int index, final Object selectedValue) { From 4fb6b8c56df2534042f18f41cb1f4909c25504b7 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Wed, 21 Jun 2017 11:32:42 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../help/alphafine/AlphaFineConfigPane.java | 27 ++++++++++++++----- .../com/fr/design/locale/designer.properties | 1 + .../design/locale/designer_en_US.properties | 1 + .../design/locale/designer_zh_CN.properties | 2 +- .../design/locale/designer_zh_TW.properties | 1 + 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/designer_base/src/com/fr/design/actions/help/alphafine/AlphaFineConfigPane.java b/designer_base/src/com/fr/design/actions/help/alphafine/AlphaFineConfigPane.java index 59fef5952..a868e404d 100644 --- a/designer_base/src/com/fr/design/actions/help/alphafine/AlphaFineConfigPane.java +++ b/designer_base/src/com/fr/design/actions/help/alphafine/AlphaFineConfigPane.java @@ -13,10 +13,7 @@ import com.fr.general.Inter; import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; +import java.awt.event.*; /** * Created by XiaXiang on 2017/4/6. @@ -100,7 +97,25 @@ public class AlphaFineConfigPane extends BasicPane { private void createShortcutsPane(JPanel contentPane) { JPanel northPane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Designer_AlphaFine_Shortcut_Config")); shortcutsField = new UITextField(); + shortcutsField.setEditable(false); + shortcutsField.selectAll(); shortcutsField.setPreferredSize(new Dimension(100, 20)); + initFieldListener(); + northPane.add(new UILabel(Inter.getLocText("FR-Designer_Open") + ":")); + northPane.add(shortcutsField); + UILabel label = new UILabel(Inter.getLocText("FR-Designer-AlphaFine_SetShortcuts")); + label.setForeground(Color.RED); + northPane.add(label); + contentPane.add(northPane); + } + + private void initFieldListener() { + shortcutsField.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + shortcutsField.selectAll(); + } + }); shortcutsField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { @@ -112,11 +127,9 @@ public class AlphaFineConfigPane extends BasicPane { shortCutKeyStore = KeyStroke.getKeyStroke(keyCode, modifier); String str = shortCutKeyStore.toString(); shortcutsField.setText(getDisplayShortCut(str)); + shortcutsField.selectAll(); } }); - northPane.add(new UILabel(Inter.getLocText("FR-Designer_Open") + ":")); - northPane.add(shortcutsField); - contentPane.add(northPane); } private void createOnlinePane(JPanel contentPane) { diff --git a/designer_base/src/com/fr/design/locale/designer.properties b/designer_base/src/com/fr/design/locale/designer.properties index 5e197ba34..3a2aa1a49 100644 --- a/designer_base/src/com/fr/design/locale/designer.properties +++ b/designer_base/src/com/fr/design/locale/designer.properties @@ -2078,3 +2078,4 @@ FR-Designer-Plugin-Store_Disconnected= FR-Designer_AlphaFine_NoResult=no results FR-Designer_ConnectionFailed=connection failed FR-Designer_NoResult=No results +FR-Designer-AlphaFine_SetShortcuts= diff --git a/designer_base/src/com/fr/design/locale/designer_en_US.properties b/designer_base/src/com/fr/design/locale/designer_en_US.properties index 0d48fd184..35d097a29 100644 --- a/designer_base/src/com/fr/design/locale/designer_en_US.properties +++ b/designer_base/src/com/fr/design/locale/designer_en_US.properties @@ -2078,3 +2078,4 @@ FR-Designer_ConnectionFailed=Connection failed FR-Designer_AlphaFine_EnableAlphaFine=Enable AlphaFine FR-Designer_AlphaFine_EnableInternet=Internet FR-Designer_NoResult=No results +FR-Designer-AlphaFine_SetShortcuts=please press two key to set shortcut diff --git a/designer_base/src/com/fr/design/locale/designer_zh_CN.properties b/designer_base/src/com/fr/design/locale/designer_zh_CN.properties index ed27f84a9..635e0bdac 100644 --- a/designer_base/src/com/fr/design/locale/designer_zh_CN.properties +++ b/designer_base/src/com/fr/design/locale/designer_zh_CN.properties @@ -2075,4 +2075,4 @@ FR-Designer-Plugin-Store_Disconnected=\u65E0\u6CD5\u8FDE\u63A5\u5E94\u7528\u4E2D FR-Designer_AlphaFine_NoResult=\u6682\u65E0\u76F8\u5173\u5185\u5BB9 FR-Designer_ConnectionFailed=\u94FE\u63A5\u5931\u8D25 FR-Designer_NoResult=\u6682\u4E0D\u652F\u6301\u663E\u793A ->>>>>>> d2de164e77196e797f514ec75b52974b32b99ac5 +FR-Designer-AlphaFine_SetShortcuts=\u8BF7\u76F4\u63A5\u5728\u952E\u76D8\u4E0A\u6309\u4E24\u4E2A\u7EC4\u5408\u952E diff --git a/designer_base/src/com/fr/design/locale/designer_zh_TW.properties b/designer_base/src/com/fr/design/locale/designer_zh_TW.properties index 4e7fa5056..82cd6f8af 100644 --- a/designer_base/src/com/fr/design/locale/designer_zh_TW.properties +++ b/designer_base/src/com/fr/design/locale/designer_zh_TW.properties @@ -2076,3 +2076,4 @@ FR-Designer-Plugin-Store_Disconnected= FR-Designer_AlphaFine_NoResult=\u66AB\u7121\u76F8\u95DC\u5167\u5BB9 FR-Designer_ConnectionFailed=\u93C8\u63A5\u5931\u6557 FR-Designer_NoResult=\u66AB\u4E0D\u652F\u6301\u986F\u793A +FR-Designer-AlphaFine_SetShortcuts=\u8ACB\u76F4\u63A5\u5728\u9375\u76E4\u4E0A\u6309\u5169\u500B\u7D44\u5408\u9375 From 445533fe60a4019af4c7190fac376fbee4374115 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Wed, 21 Jun 2017 11:41:20 +0800 Subject: [PATCH 04/13] bug fix --- .../mainframe/alphafine/cell/render/TitleCellRender.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java b/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java index 215355639..4dfa5be3c 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java @@ -3,6 +3,7 @@ package com.fr.design.mainframe.alphafine.cell.render; import com.fr.design.gui.ilable.UILabel; import com.fr.design.mainframe.alphafine.AlphaFineConstants; import com.fr.design.mainframe.alphafine.cell.model.MoreModel; +import com.fr.general.IOUtils; import javax.swing.*; import java.awt.*; @@ -37,7 +38,7 @@ public class TitleCellRender implements ListCellRenderer { panel.add(this.more, BorderLayout.EAST); } if (moreModel.isLoading()) { - ImageIcon imageIcon = new ImageIcon(getClass().getResource("/com/fr/design/mainframe/alphafine/images/loading.gif")); + ImageIcon imageIcon = (ImageIcon) IOUtils.readIcon("/com/fr/design/mainframe/alphafine/images/loading.gif"); //设置cell的加载动画 imageIcon.setImageObserver(list); From 69f4ae582306f0cd5dc09d928f290f0815277f50 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Wed, 21 Jun 2017 11:42:30 +0800 Subject: [PATCH 05/13] rt --- .../design/mainframe/alphafine/cell/render/TitleCellRender.java | 1 - 1 file changed, 1 deletion(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java b/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java index 4dfa5be3c..3a037a701 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java @@ -39,7 +39,6 @@ public class TitleCellRender implements ListCellRenderer { } if (moreModel.isLoading()) { ImageIcon imageIcon = (ImageIcon) IOUtils.readIcon("/com/fr/design/mainframe/alphafine/images/loading.gif"); - //设置cell的加载动画 imageIcon.setImageObserver(list); UILabel loadingLabel = new UILabel(imageIcon); From 5c50c39cdc9949cb6ab6d143a8b90db57f60212f Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Wed, 21 Jun 2017 11:46:12 +0800 Subject: [PATCH 06/13] rt --- .../mainframe/alphafine/cell/render/ContentCellRender.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java b/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java index f5369a9c5..ca97c6a07 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java @@ -4,6 +4,7 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.mainframe.alphafine.AlphaFineConstants; import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel; import com.fr.design.mainframe.alphafine.cell.model.MoreModel; +import com.fr.general.IOUtils; import com.fr.stable.StringUtils; import javax.swing.*; @@ -40,7 +41,7 @@ public class ContentCellRender implements ListCellRenderer { name.setIcon(null); name.setForeground(AlphaFineConstants.MEDIUM_GRAY); } else { - name.setIcon(new ImageIcon(getClass().getResource(iconUrl))); + name.setIcon(new ImageIcon(IOUtils.readImage(iconUrl))); name.setForeground(AlphaFineConstants.BLACK); } name.setFont(AlphaFineConstants.MEDIUM_FONT); From 4d4905f1a529ae5a41b854568367fe311f4e7c6f Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Wed, 21 Jun 2017 14:04:48 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B4=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cell/render/ContentCellRender.java | 35 ++++++++----------- .../cell/render/TitleCellRender.java | 27 ++++++-------- 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java b/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java index ca97c6a07..10b72813e 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java @@ -14,17 +14,12 @@ import java.awt.*; * Created by XiaXiang on 2017/4/20. */ public class ContentCellRender implements ListCellRenderer { - private UILabel name; - private UILabel content; - public ContentCellRender() { - - } @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - this.name = new UILabel(); - this.content = new UILabel(); + UILabel titleLabel = new UILabel(); + UILabel detailLabel = new UILabel(); if (value instanceof MoreModel) { return new TitleCellRender().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } @@ -35,29 +30,29 @@ public class ContentCellRender implements ListCellRenderer { panel.setBackground(AlphaFineConstants.BLUE); } panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); - name.setText(" " + model.getName()); + titleLabel.setText(" " + model.getName()); String iconUrl = "/com/fr/design/mainframe/alphafine/images/alphafine" + model.getType().getTypeValue() + ".png"; if (model.hasNoResult()) { - name.setIcon(null); - name.setForeground(AlphaFineConstants.MEDIUM_GRAY); + titleLabel.setIcon(null); + titleLabel.setForeground(AlphaFineConstants.MEDIUM_GRAY); } else { - name.setIcon(new ImageIcon(IOUtils.readImage(iconUrl))); - name.setForeground(AlphaFineConstants.BLACK); + titleLabel.setIcon(new ImageIcon(IOUtils.readImage(iconUrl))); + titleLabel.setForeground(AlphaFineConstants.BLACK); } - name.setFont(AlphaFineConstants.MEDIUM_FONT); + titleLabel.setFont(AlphaFineConstants.MEDIUM_FONT); String description = model.getDescription(); if (StringUtils.isNotBlank(description)) { - content.setText("-" + description); - content.setForeground(AlphaFineConstants.LIGHT_GRAY); - panel.add(content, BorderLayout.CENTER); - int width = (int) (name.getPreferredSize().getWidth() + content.getPreferredSize().getWidth()); + detailLabel.setText("-" + description); + detailLabel.setForeground(AlphaFineConstants.LIGHT_GRAY); + panel.add(detailLabel, BorderLayout.CENTER); + int width = (int) (titleLabel.getPreferredSize().getWidth() + detailLabel.getPreferredSize().getWidth()); if ( width > AlphaFineConstants.LEFT_WIDTH - 30) { - int nameWidth = (int) (AlphaFineConstants.LEFT_WIDTH - content.getPreferredSize().getWidth() - 45); - name.setPreferredSize(new Dimension(nameWidth, AlphaFineConstants.CELL_HEIGHT)); + int nameWidth = (int) (AlphaFineConstants.LEFT_WIDTH - detailLabel.getPreferredSize().getWidth() - 45); + titleLabel.setPreferredSize(new Dimension(nameWidth, AlphaFineConstants.CELL_HEIGHT)); } } - panel.add(name, BorderLayout.WEST); + panel.add(titleLabel, BorderLayout.WEST); panel.setPreferredSize(new Dimension(list.getFixedCellWidth(), AlphaFineConstants.CELL_HEIGHT)); return panel; } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java b/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java index 3a037a701..b105adba9 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java @@ -12,30 +12,25 @@ import java.awt.*; * Created by XiaXiang on 2017/4/20. */ public class TitleCellRender implements ListCellRenderer { - private UILabel name; - private UILabel more; - - public TitleCellRender() { - this.name = new UILabel(); - this.more = new UILabel(); - } @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + UILabel titleLabel = new UILabel(); + UILabel showMoreLabel = new UILabel(); MoreModel moreModel = (MoreModel) value; JPanel panel = new JPanel(new BorderLayout()); panel.setBackground(AlphaFineConstants.WHITE); panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); - name.setText(moreModel.getName()); - name.setFont(AlphaFineConstants.SMALL_FONT); - more.setFont(AlphaFineConstants.SMALL_FONT); - more.setText(moreModel.getContent()); - name.setForeground(AlphaFineConstants.DARK_GRAY); - more.setForeground(AlphaFineConstants.DARK_GRAY); - panel.add(name, BorderLayout.WEST); + titleLabel.setText(moreModel.getName()); + titleLabel.setFont(AlphaFineConstants.SMALL_FONT); + showMoreLabel.setFont(AlphaFineConstants.SMALL_FONT); + showMoreLabel.setText(moreModel.getContent()); + titleLabel.setForeground(AlphaFineConstants.DARK_GRAY); + showMoreLabel.setForeground(AlphaFineConstants.DARK_GRAY); + panel.add(titleLabel, BorderLayout.WEST); if (moreModel.isNeedMore()) { - this.more.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); - panel.add(this.more, BorderLayout.EAST); + showMoreLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); + panel.add(showMoreLabel, BorderLayout.EAST); } if (moreModel.isLoading()) { ImageIcon imageIcon = (ImageIcon) IOUtils.readIcon("/com/fr/design/mainframe/alphafine/images/loading.gif"); From 3316bd2419e339c802102f0828c55a9a0078d47d Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Thu, 22 Jun 2017 00:06:10 +0800 Subject: [PATCH 08/13] bug fix --- .../alphafine/AlphaFineConstants.java | 2 +- .../alphafine/component/AlphaFineDialog.java | 43 ++++++++++--------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java b/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java index 3fd3a3b14..c1f200d24 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java +++ b/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java @@ -12,7 +12,7 @@ public class AlphaFineConstants { public static final int SHOW_SIZE = 5; - public static final int MAX_FILE_SIZE = 100; + public static final int MAX_FILE_SIZE = 1000; public static final int LATEST_SHOW_SIZE = 3; 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 3dd2b844e..c454af3d2 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java +++ b/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java @@ -82,6 +82,7 @@ public class AlphaFineDialog extends UIDialog { private JList searchResultList; private SearchListModel searchListModel; private SwingWorker searchWorker; + private SwingWorker showWorker; //是否强制打开,因为面板是否关闭绑定了全局鼠标事件,这里需要处理一下 private boolean forceOpen; @@ -174,7 +175,7 @@ public class AlphaFineDialog extends UIDialog { */ private void initProperties() { setUndecorated(true); - //addComponentListener(new ComponentHandler()); + addComponentListener(new ComponentHandler()); setSize(AlphaFineConstants.FIELD_SIZE); centerWindow(this); @@ -202,13 +203,12 @@ public class AlphaFineDialog extends UIDialog { // TODO: 2017/5/8 xiaxiang: 窗体圆角setShape()有毛边,重写paint方法可以解决毛边问题,但带来了别的问题,处理比较麻烦,暂用setShape(); // public void paint(Graphics g){ -// // Graphics2D g2 = (Graphics2D) g.create(); // RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // g2.setRenderingHints(qualityHints); // g2.setPaint(Color.WHITE); -// g2.fillRoundRect(0, 0, getWidth(), getHeight(), 25, 25); +// g2.fillRoundRect(0, 0, getWidth(), getHeight(), 15, 15); // g2.dispose(); // } @@ -465,11 +465,8 @@ public class AlphaFineDialog extends UIDialog { final String fileName = ((FileModel) selectedValue).getFilePath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1); showDefaultPreviewPane(); if (fileName.endsWith(ProjectConstants.FRM_SUFFIX)) { - if (this.searchWorker != null && !this.searchWorker.isDone()) { - this.searchWorker.cancel(true); - this.searchWorker = null; - } - this.searchWorker = new SwingWorker() { + checkWorker(); + this.showWorker = new SwingWorker() { @Override protected BufferedImage doInBackground() throws Exception { Form form = FormIO.readForm(FRContext.getCurrentEnv(), fileName); @@ -493,13 +490,10 @@ public class AlphaFineDialog extends UIDialog { } }; - this.searchWorker.execute(); + this.showWorker.execute(); } else if (fileName.endsWith(ProjectConstants.CPT_SUFFIX)) { - if (this.searchWorker != null && !this.searchWorker.isDone()) { - this.searchWorker.cancel(true); - this.searchWorker = null; - } - this.searchWorker = new SwingWorker() { + checkWorker(); + this.showWorker = new SwingWorker() { @Override protected BufferedImage doInBackground() throws Exception { WorkBook workBook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(FRContext.getCurrentEnv(), fileName); @@ -524,7 +518,7 @@ public class AlphaFineDialog extends UIDialog { } }; - this.searchWorker.execute(); + this.showWorker.execute(); } @@ -535,11 +529,8 @@ public class AlphaFineDialog extends UIDialog { repaint(); } else if (selectedValue instanceof PluginModel) { showDefaultPreviewPane(); - if (this.searchWorker != null && !this.searchWorker.isDone()) { - this.searchWorker.cancel(true); - this.searchWorker = null; - } - this.searchWorker = new SwingWorker() { + checkWorker(); + this.showWorker = new SwingWorker() { @Override protected Image doInBackground() { BufferedImage bufferedImage = null; @@ -572,7 +563,7 @@ public class AlphaFineDialog extends UIDialog { } }; - this.searchWorker.execute(); + this.showWorker.execute(); } else if (selectedValue instanceof ActionModel) { rightSearchResultPane.removeAll(); @@ -583,6 +574,16 @@ public class AlphaFineDialog extends UIDialog { } + /** + * 检查 + */ + private void checkWorker() { + if (this.showWorker != null && !this.showWorker.isDone()) { + this.showWorker.cancel(true); + this.showWorker = null; + } + } + private void HandleMoreOrLessResult(int index, MoreModel selectedValue) { if (selectedValue.getContent().equals(Inter.getLocText("FR-Designer_AlphaFine_ShowAll"))) { selectedValue.setContent(Inter.getLocText("FR-Designer_AlphaFine_ShowLess")); From c2a1303274317e6147d70fbc022668864c3c0076 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Fri, 23 Jun 2017 09:57:07 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B4=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../search/manager/RecentSearchManager.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java index 6dcebbf63..e27a01038 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java @@ -34,7 +34,7 @@ import java.util.*; */ public class RecentSearchManager extends XMLFileManager implements AlphaFineSearchProcessor { - private static final String XML_TAG = "AlphafineRecent"; + private static final String XML_TAG = "AlphaFineRecent"; private static final int MAX_SIZE = 3; private static RecentSearchManager recentSearchManager = null; private static File recentFile = null; @@ -64,7 +64,7 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear String nodeName = reader.getTagName(); if (nodeName.equals("RecentModelList")) { String key = reader.getAttrAsString("searchKey", StringUtils.EMPTY); - final ArrayList list = new ArrayList(); + final ArrayList list = new ArrayList<>(); reader.readXMLObject(new XMLReadable() { @Override public void readXML(XMLableReader reader) { @@ -85,16 +85,16 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear if (reader.isChildNode()) { String nodeName = reader.getTagName(); if (nodeName.equals("model")) { - String name = reader.getAttrAsString("cellModel", StringUtils.EMPTY); - addModelToList(list, name); + String modelValue = reader.getAttrAsString("cellModel", StringUtils.EMPTY); + addModelToList(list, modelValue); } } } - private void addModelToList(List list, String name) { + private void addModelToList(List list, String modelValue) { try { - AlphaCellModel model = CellModelHelper.getModelFromJson(new JSONObject(name)); + AlphaCellModel model = CellModelHelper.getModelFromJson(new JSONObject(modelValue)); if (model != null) { list.add(model); } @@ -113,9 +113,9 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear writer.attr("searchKey", key); for (AlphaCellModel model : recentKVModelMap.get(key)) { try { - String name = model.ModelToJson().toString(); + String modelValue = model.ModelToJson().toString(); writer.startTAG("model"); - writer.attr("cellModel", name); + writer.attr("cellModel", modelValue); writer.end(); } catch (JSONException e) { FRLogger.getLogger().error(e.getMessage()); @@ -130,7 +130,7 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear @Override public String fileName() { - return "alphafine_recent.xml"; + return "AlphaFine_Recent.xml"; } @@ -162,7 +162,7 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear private void createRecentFile(File envFile) { try { FileWriter fileWriter = new FileWriter(envFile); - StringReader stringReader = new StringReader(""); + StringReader stringReader = new StringReader(""); Utils.copyCharTo(stringReader, fileWriter); stringReader.close(); fileWriter.close(); From fc104d928f0a42849693564af171be060d95c35b Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Fri, 23 Jun 2017 13:50:55 +0800 Subject: [PATCH 10/13] =?UTF-8?q?model=E9=87=8C=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?count=E5=B1=9E=E6=80=A7=EF=BC=8C=E4=BF=AE=E6=94=B9=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E5=B8=B8=E7=94=A8=E7=9A=84=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=8C=89=E6=AC=A1=E6=95=B0=E6=8E=92=E5=BA=8F=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=B4=A8=E9=87=8F=EF=BC=8C=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=8F=98=E9=87=8F=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alphafine/AlphaFineConstants.java | 1 - .../alphafine/cell/CellModelHelper.java | 4 ++-- .../alphafine/cell/model/ActionModel.java | 13 +++++----- .../alphafine/cell/model/AlphaCellModel.java | 24 ++++++++++++++++++- .../alphafine/cell/model/DocumentModel.java | 11 +++++---- .../alphafine/cell/model/FileModel.java | 9 ++++--- .../alphafine/cell/model/PluginModel.java | 7 +++--- .../search/manager/ActionSearchManager.java | 9 ++++--- .../search/manager/DocumentSearchManager.java | 3 ++- .../search/manager/FileSearchManager.java | 9 ++++--- .../search/manager/PluginSearchManager.java | 3 ++- .../search/manager/RecentSearchManager.java | 11 +++++---- 12 files changed, 69 insertions(+), 35 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java b/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java index c1f200d24..a05e520f4 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java +++ b/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java @@ -8,7 +8,6 @@ import java.awt.*; * Created by XiaXiang on 2017/5/10. */ public class AlphaFineConstants { - public static final String SAVE_FILE_NAME = "alpha.coco"; public static final int SHOW_SIZE = 5; diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java b/designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java index 52a8fafd4..ae86cab4d 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java @@ -19,13 +19,13 @@ public class CellModelHelper { AlphaCellModel cellModel = null; switch (CellType.parse(typeValue)) { case ACTION: - cellModel = ActionSearchManager.getModelFromCloud(object.optString(RESULT)); + cellModel = ActionSearchManager.getModelFromCloud(object.optJSONObject(RESULT)); break; case DOCUMENT: cellModel = DocumentSearchManager.getModelFromCloud(object.optJSONObject(RESULT)); break; case FILE: - cellModel = FileSearchManager.getModelFromCloud(object.optString(RESULT)); + cellModel = FileSearchManager.getModelFromCloud(object.optJSONObject(RESULT)); break; case PLUGIN: case REUSE: diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java index 2850e0156..5fe38c7ba 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java @@ -13,10 +13,10 @@ import javax.swing.*; public class ActionModel extends AlphaCellModel { private Action action; - private String className; - public ActionModel(String name, String content, CellType type) { - super(name, content, type); + public ActionModel(String name, String description, Action action, int searchCount) { + this(name, description, action); + setSearchCount(searchCount); } public ActionModel(String name, String description, Action action) { @@ -55,7 +55,9 @@ public class ActionModel extends AlphaCellModel { public JSONObject ModelToJson() { JSONObject object = JSONObject.create(); try { - object.put("result", getAction().getClass().getName()).put("cellType", getType().getTypeValue()); + JSONObject modelObject = JSONObject.create(); + modelObject.put("className", getAction().getClass().getName()).put("searchCount", getSearchCount()); + object.put("result", modelObject).put("cellType", getType().getTypeValue()); } catch (JSONException e) { FRLogger.getLogger().error(e.getMessage()); } @@ -71,7 +73,4 @@ public class ActionModel extends AlphaCellModel { return getAction().getClass().getName(); } - public void setClassName(String className) { - this.className = className; - } } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java index d37d2708d..c9226ff00 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java @@ -8,11 +8,12 @@ import com.fr.json.JSONObject; /** * Created by XiaXiang on 2017/3/23. */ -public abstract class AlphaCellModel { +public abstract class AlphaCellModel implements Comparable { private String name; private String content; private String description; private CellType type; + private int searchCount; public AlphaCellModel(String name, String content, CellType type) { this.name = name; @@ -78,4 +79,25 @@ public abstract class AlphaCellModel { */ abstract public String getStoreInformation(); + public int getSearchCount() { + return searchCount; + } + + public void setSearchCount(int searchCount) { + this.searchCount = searchCount; + } + + public void addSearchCount() { + searchCount++; + } + + @Override + public int compareTo(Object o) { + AlphaCellModel cellModel = (AlphaCellModel)o; + int difference = cellModel.getSearchCount() - this.getSearchCount(); + if (difference != 0) { + return difference; + } + return this.getName().compareTo(cellModel.getName()); + } } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java index b9237c671..642629675 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java @@ -14,10 +14,6 @@ public class DocumentModel extends AlphaCellModel { private String informationUrl; private int documentId; - public DocumentModel(String name, String content, CellType type) { - super(name, content, type); - } - public DocumentModel(String name, String content, int documentId) { super(name, content, CellType.DOCUMENT); this.documentId = documentId; @@ -25,6 +21,11 @@ public class DocumentModel extends AlphaCellModel { this.documentUrl = AlphaFineConstants.DOCUMENT_DOC_URL + documentId + ".html"; } + public DocumentModel(String name, String content, int documentId, int searchCount) { + this(name, content, documentId); + setSearchCount(searchCount); + } + public String getDocumentUrl() { return documentUrl; } @@ -38,7 +39,7 @@ public class DocumentModel extends AlphaCellModel { JSONObject object = JSONObject.create(); try { JSONObject modelObject = JSONObject.create(); - modelObject.put("title", getName()).put("summary", getContent()).put("did", getDocumentId()); + modelObject.put("title", getName()).put("summary", getContent()).put("did", getDocumentId()).put("searchCount", getSearchCount()); object.put("result", modelObject).put("cellType", getType().getTypeValue()); } catch (JSONException e) { FRLogger.getLogger().error("DocumentModel: " + e.getMessage()); diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java index 3d5289cca..4ab0bb2f4 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java @@ -12,8 +12,9 @@ import com.fr.json.JSONObject; public class FileModel extends AlphaCellModel { private String filePath; - public FileModel(String name, String content, CellType type) { - super(name, content, type); + public FileModel(String name, String filePath, int searchCount) { + this(name, filePath); + setSearchCount(searchCount); } public FileModel(String name, String filePath) { @@ -34,7 +35,9 @@ public class FileModel extends AlphaCellModel { public JSONObject ModelToJson() { JSONObject object = JSONObject.create(); try { - object.put("result", getFilePath()).put("cellType", getType().getTypeValue()); + JSONObject modelObject = JSONObject.create(); + modelObject.put("filePath", getFilePath()).put("searchCount", getSearchCount()); + object.put("result", modelObject).put("cellType", getType().getTypeValue()); } catch (JSONException e) { FRLogger.getLogger().error(e.getMessage()); } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java index dce1dd281..27b552096 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java @@ -21,8 +21,9 @@ public class PluginModel extends AlphaCellModel { private int pluginId; private int price; - public PluginModel(String name, String content, CellType type) { - super(name, content, type); + public PluginModel(String name, String content, String imageUrl, String version, String jartime, String link, CellType type, int price, int pluginId, int serchCount) { + this(name, content, imageUrl, version, jartime, link, type, price, pluginId); + setSearchCount(serchCount); } public PluginModel(String name, String content, String imageUrl, String version, String jartime, String link, CellType type, int price, int pluginId) { @@ -97,7 +98,7 @@ public class PluginModel extends AlphaCellModel { JSONObject object = JSONObject.create(); try { JSONObject modelObject = JSONObject.create(); - modelObject.put("name", getName()).put("description", getContent()).put("pic", getImageUrl()).put("version", getVersion()).put("jartime", getJartime()).put("type", getType().getTypeValue()).put("price", getPrice()).put("id", getPluginId()).put("link", getLink()); + modelObject.put("name", getName()).put("description", getContent()).put("pic", getImageUrl()).put("version", getVersion()).put("jartime", getJartime()).put("type", getType().getTypeValue()).put("price", getPrice()).put("id", getPluginId()).put("link", getLink()).put("searchCount", getSearchCount()); object.put("result", modelObject).put("cellType", getType().getTypeValue()); } catch (JSONException e) { FRLogger.getLogger().error(e.getMessage()); diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java index 03a63e063..6b048c4a4 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java @@ -11,6 +11,7 @@ import com.fr.design.mainframe.toolbar.UpdateActionManager; import com.fr.design.mainframe.toolbar.UpdateActionModel; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; +import com.fr.json.JSONObject; import com.fr.stable.StringUtils; import java.util.List; @@ -35,14 +36,16 @@ public class ActionSearchManager implements AlphaFineSearchProcessor { /** * 根据类名获取对象 * - * @param actionName + * @param object * @return */ - public static ActionModel getModelFromCloud(String actionName) { + public static ActionModel getModelFromCloud(JSONObject object) { + String actionName = object.optString("className"); + int searchCount = object.optInt("searchCount"); List updateActions = UpdateActionManager.getUpdateActionManager().getUpdateActions(); for (UpdateActionModel updateActionModel : updateActions) { if (ComparatorUtils.equals(actionName, updateActionModel.getClassName())) { - return new ActionModel(updateActionModel.getActionName(), updateActionModel.getParentName(), updateActionModel.getAction()); + return new ActionModel(updateActionModel.getActionName(), updateActionModel.getParentName(), updateActionModel.getAction(), searchCount); } } return null; diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java index b56b975aa..c9418792f 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java @@ -42,7 +42,8 @@ public class DocumentSearchManager implements AlphaFineSearchProcessor { String name = object.optString("title"); String content = object.optString("summary"); int documentId = object.optInt("did"); - return new DocumentModel(name, content, documentId); + int searchCount = object.optInt("searchCount"); + return new DocumentModel(name, content, documentId, searchCount); } @Override diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java index dd8f6312b..c198ee917 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java @@ -13,6 +13,7 @@ import com.fr.file.filetree.FileNode; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; import com.fr.general.Inter; +import com.fr.json.JSONObject; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; @@ -53,12 +54,14 @@ public class FileSearchManager implements AlphaFineSearchProcessor { /** * 根据文件路径获取文件模型 * - * @param filePath + * @param object * @return */ - public static FileModel getModelFromCloud(String filePath) { + public static FileModel getModelFromCloud(JSONObject object) { + String filePath = object.optString("filePath"); + int searchCount = object.optInt("searchCount"); String name = AlphaFineHelper.findFileName(filePath); - return new FileModel(name, filePath); + return new FileModel(name, filePath, searchCount); } public synchronized SearchResult getLessSearchResult(String searchText) { diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java index 569ae7936..3e457fd1a 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java @@ -41,6 +41,7 @@ public class PluginSearchManager implements AlphaFineSearchProcessor { String name = object.optString("name"); String content = object.optString("description"); int pluginId = object.optInt("id"); + int searchCount = object.optInt("searchCount"); String imageUrl = null; try { imageUrl = isFromCloud ? AlphaFineConstants.PLUGIN_IMAGE_URL + URLEncoder.encode(object.optString("pic").toString().substring(AlphaFineConstants.PLUGIN_IMAGE_URL.length()), "utf8") : object.optString("pic"); @@ -59,7 +60,7 @@ public class PluginSearchManager implements AlphaFineSearchProcessor { type = CellType.REUSE; } int price = object.optInt("price"); - return new PluginModel(name, content, imageUrl, version, jartime, link, type, price, pluginId); + return new PluginModel(name, content, imageUrl, version, jartime, link, type, price, pluginId, searchCount); } /** diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java index e27a01038..4e70277f1 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java @@ -231,9 +231,10 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear } } + Collections.sort(resultModelList); int size = resultModelList.size(); if (size > MAX_SIZE) { - return resultModelList.subList(size - MAX_SIZE, size); + return resultModelList.subList(0, MAX_SIZE); } return resultModelList; } @@ -250,13 +251,13 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear public void addRecentModel(String searchKey, AlphaCellModel cellModel) { if (recentKVModelMap.keySet().contains(searchKey)) { List cellModels = recentKVModelMap.get(searchKey); - if (cellModels.contains(cellModel)) { - cellModels.remove(cellModel); - cellModels.add(cellModel); + int index = cellModels.indexOf(cellModel); + if (index >= 0) { + cellModels.get(index).addSearchCount(); } else { cellModels.add(cellModel); } - trimToSize(cellModels); + //trimToSize(cellModels); } else { List list = new ArrayList<>(); list.add(cellModel); From dace91a48611ef00931461319ce29c566648a654 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Fri, 23 Jun 2017 16:13:52 +0800 Subject: [PATCH 11/13] =?UTF-8?q?alphafine=20=E4=BB=A3=E7=A0=81=E8=B4=A8?= =?UTF-8?q?=E9=87=8F=20=E5=8F=98=E9=87=8F=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alphafine/component/AlphaFineDialog.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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 c454af3d2..4d74910be 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java +++ b/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java @@ -343,16 +343,15 @@ public class AlphaFineDialog extends UIDialog { getPluginList(searchText); } - private synchronized void getDocumentList(final String searchText) { + private void getDocumentList(final String searchText) { SearchResult documentModelList = DocumentSearchManager.getDocumentSearchManager().getLessSearchResult(searchText); for (Object object : documentModelList) { AlphaFineHelper.checkCancel(); searchListModel.addElement(object); } - } - private synchronized void getFileList(final String searchText) { + private void getFileList(final String searchText) { SearchResult fileModelList = FileSearchManager.getFileSearchManager().getLessSearchResult(searchText); for (Object object : fileModelList) { AlphaFineHelper.checkCancel(); @@ -360,7 +359,7 @@ public class AlphaFineDialog extends UIDialog { } } - private synchronized void getActionList(final String searchText) { + private void getActionList(final String searchText) { SearchResult actionModelList = ActionSearchManager.getActionSearchManager().getLessSearchResult(searchText); for (Object object : actionModelList) { AlphaFineHelper.checkCancel(); @@ -368,7 +367,7 @@ public class AlphaFineDialog extends UIDialog { } } - private synchronized void getPluginList(final String searchText) { + private void getPluginList(final String searchText) { SearchResult pluginModelList = PluginSearchManager.getPluginSearchManager().getLessSearchResult(searchText); for (Object object : pluginModelList) { AlphaFineHelper.checkCancel(); @@ -376,7 +375,7 @@ public class AlphaFineDialog extends UIDialog { } } - private synchronized void getRecommendList(final String searchText) { + private void getRecommendList(final String searchText) { SearchResult recommendModelList = RecommendSearchManager.getRecommendSearchManager().getLessSearchResult(searchText); for (Object object : recommendModelList) { AlphaFineHelper.checkCancel(); @@ -384,7 +383,7 @@ public class AlphaFineDialog extends UIDialog { } } - private synchronized void getRecentList(final String searchText) { + private void getRecentList(final String searchText) { SearchResult recentModelList = RecentSearchManager.getRecentSearchManger().getLessSearchResult(searchText); for (Object object : recentModelList) { AlphaFineHelper.checkCancel(); From 8784569d3a0a70ab4fab00eef8a7217ad7f5a3bf Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Fri, 23 Jun 2017 17:05:34 +0800 Subject: [PATCH 12/13] =?UTF-8?q?=E6=94=B9=E5=87=A0=E4=B8=AA=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alphafine/component/AlphaFineDialog.java | 146 +++++++++--------- 1 file changed, 76 insertions(+), 70 deletions(-) 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 4d74910be..194bca0b4 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java +++ b/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java @@ -91,7 +91,7 @@ public class AlphaFineDialog extends UIDialog { super(parent); this.forceOpen = forceOpen; initProperties(); - initListener(); + initGlobalListener(); initComponents(); } @@ -392,73 +392,6 @@ public class AlphaFineDialog extends UIDialog { } - /** - * 为各组件添加鼠标,键盘监听器 - */ - private void initListListener() { - /** - * 鼠标监听器 - */ - searchResultList.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - int selectedIndex = searchResultList.getSelectedIndex(); - Object selectedValue = searchResultList.getSelectedValue(); - if (e.getClickCount() == 2) { - doNavigate(selectedIndex); - if (selectedValue instanceof AlphaCellModel) { - saveHistory((AlphaCellModel) selectedValue); - } - } else if (e.getClickCount() == 1) { - if (selectedValue instanceof MoreModel && ((MoreModel) selectedValue).isNeedMore()) { - HandleMoreOrLessResult(selectedIndex, (MoreModel) selectedValue); - } - } - } - }); - - /** - *单击时触发右侧面板展示搜索结果 - */ - searchResultList.addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - if (!e.getValueIsAdjusting()) { - showResult(searchResultList.getSelectedIndex(), searchResultList.getSelectedValue()); - - } - } - }); - - /** - * 为list添加键盘监听器 - */ - searchResultList.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - Object selectedValue = searchResultList.getSelectedValue(); - doNavigate(searchResultList.getSelectedIndex()); - if (searchResultList.getSelectedValue() instanceof AlphaCellModel) { - saveHistory((AlphaCellModel) selectedValue); - } - } - } - }); - - /** - * 为textField添加键盘监听器,按上下方向键时把焦点给list,实现键盘操作 - */ - searchTextField.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) { - searchResultList.requestFocus(); - } - } - }); - } - private void showResult(int index, final Object selectedValue) { if (selectedValue instanceof FileModel) { final String fileName = ((FileModel) selectedValue).getFilePath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1); @@ -603,11 +536,84 @@ public class AlphaFineDialog extends UIDialog { repaint(); } - private void initListener() { + /** + * 为面板添加全局监听器 + */ + private void initGlobalListener() { initAWTEventListener(); - initMouseListener(); + } + /** + * 为面板中各组件添加监听器 + */ + private void initListListener() { + initListMouseListener(); + initListKeyListener(); + } + + private void initListKeyListener() { + /** + * 为list添加键盘监听器 + */ + searchResultList.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + Object selectedValue = searchResultList.getSelectedValue(); + doNavigate(searchResultList.getSelectedIndex()); + if (searchResultList.getSelectedValue() instanceof AlphaCellModel) { + saveHistory((AlphaCellModel) selectedValue); + } + } + } + }); + /** + * 为textField添加键盘监听器,按上下方向键时把焦点给list,实现键盘操作 + */ + searchTextField.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) { + searchResultList.requestFocus(); + } + } + }); + } + + private void initListMouseListener() { + /** + * 鼠标监听器 + */ + searchResultList.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + int selectedIndex = searchResultList.getSelectedIndex(); + Object selectedValue = searchResultList.getSelectedValue(); + if (e.getClickCount() == 2) { + doNavigate(selectedIndex); + if (selectedValue instanceof AlphaCellModel) { + saveHistory((AlphaCellModel) selectedValue); + } + } else if (e.getClickCount() == 1) { + if (selectedValue instanceof MoreModel && ((MoreModel) selectedValue).isNeedMore()) { + HandleMoreOrLessResult(selectedIndex, (MoreModel) selectedValue); + } + } + } + }); + /** + *单击时触发右侧面板展示搜索结果 + */ + searchResultList.addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + if (!e.getValueIsAdjusting()) { + showResult(searchResultList.getSelectedIndex(), searchResultList.getSelectedValue()); + + } + } + }); } /** From 03a6db5813e8d92897005f18c33f0cd08a437858 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Fri, 23 Jun 2017 17:23:12 +0800 Subject: [PATCH 13/13] bug fix pmd alphafine --- .../mainframe/alphafine/cell/render/ContentCellRender.java | 7 ++++--- .../mainframe/alphafine/component/AlphaFineDialog.java | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java b/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java index 10b72813e..aa91989f9 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java @@ -14,7 +14,8 @@ import java.awt.*; * Created by XiaXiang on 2017/4/20. */ public class ContentCellRender implements ListCellRenderer { - + private static final int OFFSET = 30; + private static final int LABEL_OFFSET = 45; @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { @@ -46,8 +47,8 @@ public class ContentCellRender implements ListCellRenderer { detailLabel.setForeground(AlphaFineConstants.LIGHT_GRAY); panel.add(detailLabel, BorderLayout.CENTER); int width = (int) (titleLabel.getPreferredSize().getWidth() + detailLabel.getPreferredSize().getWidth()); - if ( width > AlphaFineConstants.LEFT_WIDTH - 30) { - int nameWidth = (int) (AlphaFineConstants.LEFT_WIDTH - detailLabel.getPreferredSize().getWidth() - 45); + if ( width > AlphaFineConstants.LEFT_WIDTH - OFFSET) { + int nameWidth = (int) (AlphaFineConstants.LEFT_WIDTH - detailLabel.getPreferredSize().getWidth() - LABEL_OFFSET); titleLabel.setPreferredSize(new Dimension(nameWidth, AlphaFineConstants.CELL_HEIGHT)); } } 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 194bca0b4..534170516 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java +++ b/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java @@ -219,12 +219,15 @@ public class AlphaFineDialog extends UIDialog { */ private void doSearch(String text) { - if (StringUtils.isBlank(text) || text.equals("AlphaFine") || text.contains("'")) { + if (StringUtils.isBlank(text) || isNeedSearch(text)) { removeSearchResult(); } else { showSearchResult(); } + } + boolean isNeedSearch(String text) { + return ComparatorUtils.equals("AlphaFine", text) || text.contains("'"); } /**