Browse Source

Merge pull request #957 in BA/design from ~XIAOXIA/design:9.0 to 9.0

* commit '03a6db5813e8d92897005f18c33f0cd08a437858':
  bug fix pmd alphafine
  改几个方法名
  alphafine 代码质量 变量命名
  model里加一个count属性,修改本地常用的逻辑,按次数排序 代码质量, 修改部分变量命名
  代码质量
  bug fix
  代码质量
  rt
  rt
  bug fix
  快捷键设置优化
  REPORT-3022 智能搜索619引擎功能改良
  alphafine bug fix
master
superman 8 years ago
parent
commit
f5d9f2b68b
  1. 5
      designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java
  2. 4
      designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java
  3. 13
      designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java
  4. 27
      designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java
  5. 11
      designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java
  6. 9
      designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java
  7. 5
      designer/src/com/fr/design/mainframe/alphafine/cell/model/NoResultModel.java
  8. 7
      designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java
  9. 52
      designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java
  10. 31
      designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java
  11. 269
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  12. 9
      designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java
  13. 3
      designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java
  14. 16
      designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java
  15. 3
      designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java
  16. 31
      designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java
  17. 27
      designer_base/src/com/fr/design/actions/help/alphafine/AlphaFineConfigPane.java
  18. 1
      designer_base/src/com/fr/design/locale/designer.properties
  19. 1
      designer_base/src/com/fr/design/locale/designer_en_US.properties
  20. 2
      designer_base/src/com/fr/design/locale/designer_zh_CN.properties
  21. 1
      designer_base/src/com/fr/design/locale/designer_zh_TW.properties

5
designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java

@ -8,11 +8,10 @@ import java.awt.*;
* Created by XiaXiang on 2017/5/10. * Created by XiaXiang on 2017/5/10.
*/ */
public class AlphaFineConstants { public class AlphaFineConstants {
public static final String SAVE_FILE_NAME = "alpha.coco";
public static final int SHOW_SIZE = 5; 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; public static final int LATEST_SHOW_SIZE = 3;
@ -30,6 +29,8 @@ public class AlphaFineConstants {
public static final int CELL_HEIGHT = 32; 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); public static final Dimension FULL_SIZE = new Dimension(680, 460);

4
designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java

@ -19,13 +19,13 @@ public class CellModelHelper {
AlphaCellModel cellModel = null; AlphaCellModel cellModel = null;
switch (CellType.parse(typeValue)) { switch (CellType.parse(typeValue)) {
case ACTION: case ACTION:
cellModel = ActionSearchManager.getModelFromCloud(object.optString(RESULT)); cellModel = ActionSearchManager.getModelFromCloud(object.optJSONObject(RESULT));
break; break;
case DOCUMENT: case DOCUMENT:
cellModel = DocumentSearchManager.getModelFromCloud(object.optJSONObject(RESULT)); cellModel = DocumentSearchManager.getModelFromCloud(object.optJSONObject(RESULT));
break; break;
case FILE: case FILE:
cellModel = FileSearchManager.getModelFromCloud(object.optString(RESULT)); cellModel = FileSearchManager.getModelFromCloud(object.optJSONObject(RESULT));
break; break;
case PLUGIN: case PLUGIN:
case REUSE: case REUSE:

13
designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java

@ -13,10 +13,10 @@ import javax.swing.*;
public class ActionModel extends AlphaCellModel { public class ActionModel extends AlphaCellModel {
private Action action; private Action action;
private String className;
public ActionModel(String name, String content, CellType type) { public ActionModel(String name, String description, Action action, int searchCount) {
super(name, content, type); this(name, description, action);
setSearchCount(searchCount);
} }
public ActionModel(String name, String description, Action action) { public ActionModel(String name, String description, Action action) {
@ -55,7 +55,9 @@ public class ActionModel extends AlphaCellModel {
public JSONObject ModelToJson() { public JSONObject ModelToJson() {
JSONObject object = JSONObject.create(); JSONObject object = JSONObject.create();
try { 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) { } catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage()); FRLogger.getLogger().error(e.getMessage());
} }
@ -71,7 +73,4 @@ public class ActionModel extends AlphaCellModel {
return getAction().getClass().getName(); return getAction().getClass().getName();
} }
public void setClassName(String className) {
this.className = className;
}
} }

27
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. * Created by XiaXiang on 2017/3/23.
*/ */
public abstract class AlphaCellModel { public abstract class AlphaCellModel implements Comparable {
private String name; private String name;
private String content; private String content;
private String description; private String description;
private CellType type; private CellType type;
private int searchCount;
public AlphaCellModel(String name, String content, CellType type) { public AlphaCellModel(String name, String content, CellType type) {
this.name = name; this.name = name;
@ -60,6 +61,9 @@ public abstract class AlphaCellModel {
this.description = description; this.description = description;
} }
public boolean hasNoResult() {
return false;
}
/** /**
* model转json * model转json
* *
@ -75,4 +79,25 @@ public abstract class AlphaCellModel {
*/ */
abstract public String getStoreInformation(); 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());
}
} }

11
designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java

@ -14,10 +14,6 @@ public class DocumentModel extends AlphaCellModel {
private String informationUrl; private String informationUrl;
private int documentId; private int documentId;
public DocumentModel(String name, String content, CellType type) {
super(name, content, type);
}
public DocumentModel(String name, String content, int documentId) { public DocumentModel(String name, String content, int documentId) {
super(name, content, CellType.DOCUMENT); super(name, content, CellType.DOCUMENT);
this.documentId = documentId; this.documentId = documentId;
@ -25,6 +21,11 @@ public class DocumentModel extends AlphaCellModel {
this.documentUrl = AlphaFineConstants.DOCUMENT_DOC_URL + documentId + ".html"; 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() { public String getDocumentUrl() {
return documentUrl; return documentUrl;
} }
@ -38,7 +39,7 @@ public class DocumentModel extends AlphaCellModel {
JSONObject object = JSONObject.create(); JSONObject object = JSONObject.create();
try { try {
JSONObject modelObject = JSONObject.create(); 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()); object.put("result", modelObject).put("cellType", getType().getTypeValue());
} catch (JSONException e) { } catch (JSONException e) {
FRLogger.getLogger().error("DocumentModel: " + e.getMessage()); FRLogger.getLogger().error("DocumentModel: " + e.getMessage());

9
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 { public class FileModel extends AlphaCellModel {
private String filePath; private String filePath;
public FileModel(String name, String content, CellType type) { public FileModel(String name, String filePath, int searchCount) {
super(name, content, type); this(name, filePath);
setSearchCount(searchCount);
} }
public FileModel(String name, String filePath) { public FileModel(String name, String filePath) {
@ -34,7 +35,9 @@ public class FileModel extends AlphaCellModel {
public JSONObject ModelToJson() { public JSONObject ModelToJson() {
JSONObject object = JSONObject.create(); JSONObject object = JSONObject.create();
try { 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) { } catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage()); FRLogger.getLogger().error(e.getMessage());
} }

5
designer/src/com/fr/design/mainframe/alphafine/cell/model/NoResultModel.java

@ -21,4 +21,9 @@ public class NoResultModel extends AlphaCellModel {
public String getStoreInformation() { public String getStoreInformation() {
return null; return null;
} }
@Override
public boolean hasNoResult() {
return true;
}
} }

7
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 pluginId;
private int price; private int price;
public PluginModel(String name, String content, CellType type) { public PluginModel(String name, String content, String imageUrl, String version, String jartime, String link, CellType type, int price, int pluginId, int serchCount) {
super(name, content, type); 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) { 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(); JSONObject object = JSONObject.create();
try { try {
JSONObject modelObject = JSONObject.create(); 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()); object.put("result", modelObject).put("cellType", getType().getTypeValue());
} catch (JSONException e) { } catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage()); FRLogger.getLogger().error(e.getMessage());

52
designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java

@ -2,7 +2,6 @@ package com.fr.design.mainframe.alphafine.cell.render;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.alphafine.AlphaFineConstants; 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.AlphaCellModel;
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
@ -15,46 +14,47 @@ import java.awt.*;
* Created by XiaXiang on 2017/4/20. * Created by XiaXiang on 2017/4/20.
*/ */
public class ContentCellRender implements ListCellRenderer<Object> { public class ContentCellRender implements ListCellRenderer<Object> {
private UILabel name; private static final int OFFSET = 30;
private UILabel content; private static final int LABEL_OFFSET = 45;
public ContentCellRender() {
this.name = new UILabel();
this.content = new UILabel();
}
@Override @Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
UILabel titleLabel = new UILabel();
UILabel detailLabel = new UILabel();
if (value instanceof MoreModel) { if (value instanceof MoreModel) {
return new TitleCellRender().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); return new TitleCellRender().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
} }
AlphaCellModel model = (AlphaCellModel) value;
JPanel panel = new JPanel(new BorderLayout()); JPanel panel = new JPanel(new BorderLayout());
panel.setBackground(Color.white); panel.setBackground(null);
if (isSelected) { if (isSelected && !model.hasNoResult()) {
panel.setBackground(AlphaFineConstants.BLUE); panel.setBackground(AlphaFineConstants.BLUE);
} }
panel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0)); panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
AlphaCellModel model = (AlphaCellModel) value; titleLabel.setText(" " + model.getName());
name.setText(model.getName());
String iconUrl = "/com/fr/design/mainframe/alphafine/images/alphafine" + model.getType().getTypeValue() + ".png"; String iconUrl = "/com/fr/design/mainframe/alphafine/images/alphafine" + model.getType().getTypeValue() + ".png";
name.setIcon(IOUtils.readIcon(iconUrl)); if (model.hasNoResult()) {
if (model.getType() == CellType.NO_RESULT) { titleLabel.setIcon(null);
name.setIcon(null); titleLabel.setForeground(AlphaFineConstants.MEDIUM_GRAY);
name.setForeground(AlphaFineConstants.MEDIUM_GRAY);
} else { } else {
name.setIcon(new ImageIcon(getClass().getResource(iconUrl))); titleLabel.setIcon(new ImageIcon(IOUtils.readImage(iconUrl)));
name.setForeground(AlphaFineConstants.BLACK); titleLabel.setForeground(AlphaFineConstants.BLACK);
} }
name.setFont(AlphaFineConstants.MEDIUM_FONT); titleLabel.setFont(AlphaFineConstants.MEDIUM_FONT);
name.setVerticalTextPosition(SwingConstants.CENTER);
name.setHorizontalTextPosition(SwingConstants.RIGHT);
String description = model.getDescription(); String description = model.getDescription();
if (StringUtils.isNotBlank(description)) { if (StringUtils.isNotBlank(description)) {
content.setText("-" + description); detailLabel.setText("-" + description);
content.setForeground(AlphaFineConstants.LIGHT_GRAY); detailLabel.setForeground(AlphaFineConstants.LIGHT_GRAY);
panel.add(content, BorderLayout.CENTER); panel.add(detailLabel, BorderLayout.CENTER);
int width = (int) (titleLabel.getPreferredSize().getWidth() + detailLabel.getPreferredSize().getWidth());
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));
}
} }
panel.add(name, BorderLayout.WEST);
panel.add(titleLabel, BorderLayout.WEST);
panel.setPreferredSize(new Dimension(list.getFixedCellWidth(), AlphaFineConstants.CELL_HEIGHT));
return panel; return panel;
} }
} }

31
designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java

@ -12,39 +12,34 @@ import java.awt.*;
* Created by XiaXiang on 2017/4/20. * Created by XiaXiang on 2017/4/20.
*/ */
public class TitleCellRender implements ListCellRenderer<Object> { public class TitleCellRender implements ListCellRenderer<Object> {
private UILabel name;
private UILabel more;
public TitleCellRender() {
this.name = new UILabel();
this.more = new UILabel();
}
@Override @Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 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; MoreModel moreModel = (MoreModel) value;
JPanel panel = new JPanel(new BorderLayout()); JPanel panel = new JPanel(new BorderLayout());
panel.setBackground(AlphaFineConstants.WHITE); panel.setBackground(AlphaFineConstants.WHITE);
panel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0)); panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
name.setText(moreModel.getName()); titleLabel.setText(moreModel.getName());
name.setFont(AlphaFineConstants.SMALL_FONT); titleLabel.setFont(AlphaFineConstants.SMALL_FONT);
more.setFont(AlphaFineConstants.SMALL_FONT); showMoreLabel.setFont(AlphaFineConstants.SMALL_FONT);
more.setText(moreModel.getContent()); showMoreLabel.setText(moreModel.getContent());
name.setForeground(AlphaFineConstants.DARK_GRAY); titleLabel.setForeground(AlphaFineConstants.DARK_GRAY);
more.setForeground(AlphaFineConstants.DARK_GRAY); showMoreLabel.setForeground(AlphaFineConstants.DARK_GRAY);
panel.add(name, BorderLayout.WEST); panel.add(titleLabel, BorderLayout.WEST);
if (moreModel.isNeedMore()) { if (moreModel.isNeedMore()) {
this.more.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); showMoreLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
panel.add(this.more, BorderLayout.EAST); panel.add(showMoreLabel, BorderLayout.EAST);
} }
if (moreModel.isLoading()) { if (moreModel.isLoading()) {
ImageIcon imageIcon = (ImageIcon) IOUtils.readIcon("/com/fr/design/mainframe/alphafine/images/loading.gif"); ImageIcon imageIcon = (ImageIcon) IOUtils.readIcon("/com/fr/design/mainframe/alphafine/images/loading.gif");
//设置cell的加载动画 //设置cell的加载动画
imageIcon.setImageObserver(list); imageIcon.setImageObserver(list);
UILabel loadingLabel = new UILabel(imageIcon); UILabel loadingLabel = new UILabel(imageIcon);
panel.add(loadingLabel, BorderLayout.SOUTH); panel.add(loadingLabel, BorderLayout.SOUTH);
} }
panel.setPreferredSize(new Dimension(list.getFixedCellWidth(), AlphaFineConstants.CELL_TITLE_HEIGHT));
return panel; return panel;
} }
} }

269
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.form.main.FormIO;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.general.IOUtils;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.general.http.HttpClient; import com.fr.general.http.HttpClient;
import com.fr.io.TemplateWorkBookIO; import com.fr.io.TemplateWorkBookIO;
@ -60,29 +59,18 @@ import java.util.concurrent.ExecutionException;
* Created by XiaXiang on 2017/3/21. * Created by XiaXiang on 2017/3/21.
*/ */
public class AlphaFineDialog extends UIDialog { 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_SHORT = "k:1 ";
private static final String ACTION_MARK = "k:setting "; private static final String ACTION_MARK = "k:setting ";
private static final String DOCUMENT_MARK_SHORT = "k:2 "; private static final String DOCUMENT_MARK_SHORT = "k:2 ";
private static final String DOCUMENT_MARK = "k:help "; private static final String DOCUMENT_MARK = "k:help ";
private static final String FILE_MARK_SHORT = "k:3 "; private static final String FILE_MARK_SHORT = "k:3 ";
private static final String FILE_MARK = "k:reportlets "; private static final String FILE_MARK = "k:reportlets ";
private static final String CPT_MARK = "k:cpt "; private static final String CPT_MARK = "k:cpt ";
private static final String FRM_MARK = "k:frm "; private static final String FRM_MARK = "k:frm ";
private static final String DS_MARK = "k:ds "; private static final String DS_MARK = "k:ds ";
private static final String DS_NAME = "dsname=\""; private static final String DS_NAME = "dsname=\"";
private static final String PLUGIN_MARK_SHORT = "k:4 "; private static final String PLUGIN_MARK_SHORT = "k:4 ";
private static final String PLUGIN_MARK = "k:shop "; private static final String PLUGIN_MARK = "k:shop ";
private AlphaFineTextField searchTextField; private AlphaFineTextField searchTextField;
@ -94,6 +82,7 @@ public class AlphaFineDialog extends UIDialog {
private JList searchResultList; private JList searchResultList;
private SearchListModel searchListModel; private SearchListModel searchListModel;
private SwingWorker searchWorker; private SwingWorker searchWorker;
private SwingWorker showWorker;
//是否强制打开,因为面板是否关闭绑定了全局鼠标事件,这里需要处理一下 //是否强制打开,因为面板是否关闭绑定了全局鼠标事件,这里需要处理一下
private boolean forceOpen; private boolean forceOpen;
@ -102,7 +91,7 @@ public class AlphaFineDialog extends UIDialog {
super(parent); super(parent);
this.forceOpen = forceOpen; this.forceOpen = forceOpen;
initProperties(); initProperties();
initListener(); initGlobalListener();
initComponents(); initComponents();
} }
@ -112,12 +101,10 @@ public class AlphaFineDialog extends UIDialog {
* @return * @return
*/ */
public static AWTEventListener listener() { public static AWTEventListener listener() {
return new AWTEventListener() { return new AWTEventListener() {
@Override @Override
public void eventDispatched(AWTEvent event) { public void eventDispatched(AWTEvent event) {
if (event instanceof KeyEvent) { if (event instanceof KeyEvent) {
KeyEvent e = (KeyEvent) event; KeyEvent e = (KeyEvent) event;
KeyStroke keyStroke = (KeyStroke) KeyStroke.getAWTKeyStrokeForEvent(e); KeyStroke keyStroke = (KeyStroke) KeyStroke.getAWTKeyStrokeForEvent(e);
@ -132,7 +119,6 @@ public class AlphaFineDialog extends UIDialog {
} }
private static void doClickAction() { private static void doClickAction() {
AlphaFineHelper.showAlphaFineDialog(false); AlphaFineHelper.showAlphaFineDialog(false);
} }
@ -140,24 +126,21 @@ public class AlphaFineDialog extends UIDialog {
* 初始化全部组件 * 初始化全部组件
*/ */
private void initComponents() { private void initComponents() {
searchTextField = new AlphaFineTextField("AlphaFine"); searchTextField = new AlphaFineTextField("AlphaFine");
searchTextField.setFont(AlphaFineConstants.GREATER_FONT); searchTextField.setFont(AlphaFineConstants.GREATER_FONT);
searchTextField.setBackground(Color.white); searchTextField.setBackground(Color.white);
searchTextField.setBorderPainted(false); searchTextField.setBorderPainted(false);
searchTextField.initKeyListener(this); searchTextField.initKeyListener(this);
JPanel topPane = new JPanel(new BorderLayout()); 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.setPreferredSize(AlphaFineConstants.ICON_LABEL_SIZE);
iconLabel.setOpaque(true); iconLabel.setOpaque(true);
iconLabel.setBackground(Color.white); iconLabel.setBackground(Color.white);
topPane.add(iconLabel, BorderLayout.WEST); topPane.add(iconLabel, BorderLayout.WEST);
topPane.add(searchTextField, BorderLayout.CENTER); topPane.add(searchTextField, BorderLayout.CENTER);
closeButton = new UIButton() { closeButton = new UIButton() {
@Override @Override
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
g.setColor(Color.white); g.setColor(Color.white);
g.fillRect(0, 0, getSize().width, getSize().height); g.fillRect(0, 0, getSize().width, getSize().height);
super.paintComponent(g); super.paintComponent(g);
@ -165,13 +148,11 @@ public class AlphaFineDialog extends UIDialog {
}; };
closeButton.setContentAreaFilled(false); closeButton.setContentAreaFilled(false);
closeButton.setPreferredSize(AlphaFineConstants.CLOSE_BUTTON_SIZE); 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.set4ToolbarButton();
closeButton.addActionListener(new ActionListener() { closeButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
dispose(); dispose();
} }
}); });
@ -182,10 +163,8 @@ public class AlphaFineDialog extends UIDialog {
topPane.add(borderLabel, BorderLayout.SOUTH); topPane.add(borderLabel, BorderLayout.SOUTH);
add(topPane, BorderLayout.CENTER); add(topPane, BorderLayout.CENTER);
searchTextField.getDocument().addDocumentListener(new DocumentAdapter() { searchTextField.getDocument().addDocumentListener(new DocumentAdapter() {
@Override @Override
protected void textChanged(DocumentEvent e) { protected void textChanged(DocumentEvent e) {
doSearch(searchTextField.getText()); doSearch(searchTextField.getText());
} }
}); });
@ -195,7 +174,6 @@ public class AlphaFineDialog extends UIDialog {
* *
*/ */
private void initProperties() { private void initProperties() {
setUndecorated(true); setUndecorated(true);
addComponentListener(new ComponentHandler()); addComponentListener(new ComponentHandler());
setSize(AlphaFineConstants.FIELD_SIZE); setSize(AlphaFineConstants.FIELD_SIZE);
@ -209,7 +187,6 @@ public class AlphaFineDialog extends UIDialog {
* @param win * @param win
*/ */
private void centerWindow(Window win) { private void centerWindow(Window win) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension winSize = win.getSize(); Dimension winSize = win.getSize();
@ -226,13 +203,12 @@ public class AlphaFineDialog extends UIDialog {
// TODO: 2017/5/8 xiaxiang: 窗体圆角setShape()有毛边,重写paint方法可以解决毛边问题,但带来了别的问题,处理比较麻烦,暂用setShape(); // TODO: 2017/5/8 xiaxiang: 窗体圆角setShape()有毛边,重写paint方法可以解决毛边问题,但带来了别的问题,处理比较麻烦,暂用setShape();
// public void paint(Graphics g){ // public void paint(Graphics g){
//
// Graphics2D g2 = (Graphics2D) g.create(); // Graphics2D g2 = (Graphics2D) g.create();
// RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
// g2.setRenderingHints(qualityHints); // g2.setRenderingHints(qualityHints);
// g2.setPaint(Color.WHITE); // g2.setPaint(Color.WHITE);
// g2.fillRoundRect(0, 0, getWidth(), getHeight(), 25, 25); // g2.fillRoundRect(0, 0, getWidth(), getHeight(), 15, 15);
// g2.dispose(); // g2.dispose();
// } // }
@ -243,21 +219,21 @@ public class AlphaFineDialog extends UIDialog {
*/ */
private void doSearch(String text) { private void doSearch(String text) {
if (StringUtils.isBlank(text) || text.equals("AlphaFine")) { if (StringUtils.isBlank(text) || isNeedSearch(text)) {
removeSearchResult(); removeSearchResult();
} else if (text.contains("'")) {
return;
} else { } else {
showSearchResult(); showSearchResult();
} }
}
boolean isNeedSearch(String text) {
return ComparatorUtils.equals("AlphaFine", text) || text.contains("'");
} }
/** /**
* 移除搜索结果 * 移除搜索结果
*/ */
private void removeSearchResult() { private void removeSearchResult() {
if (searchResultPane != null) { if (searchResultPane != null) {
remove(searchResultPane); remove(searchResultPane);
searchResultPane = null; searchResultPane = null;
@ -281,7 +257,6 @@ public class AlphaFineDialog extends UIDialog {
* 初始化搜索面板 * 初始化搜索面板
*/ */
private void initSearchResultComponents() { private void initSearchResultComponents() {
searchResultList = new JList(); searchResultList = new JList();
searchListModel = new SearchListModel(new SearchResult()); searchListModel = new SearchListModel(new SearchResult());
searchResultList.setModel(searchListModel); searchResultList.setModel(searchListModel);
@ -289,7 +264,6 @@ public class AlphaFineDialog extends UIDialog {
searchResultPane.setPreferredSize(AlphaFineConstants.CONTENT_SIZE); searchResultPane.setPreferredSize(AlphaFineConstants.CONTENT_SIZE);
searchResultPane.setLayout(new BorderLayout()); searchResultPane.setLayout(new BorderLayout());
searchResultList.setCellRenderer(new ContentCellRender()); searchResultList.setCellRenderer(new ContentCellRender());
searchResultList.setFixedCellHeight(AlphaFineConstants.CELL_HEIGHT);
leftSearchResultPane = new UIScrollPane(searchResultList); leftSearchResultPane = new UIScrollPane(searchResultList);
leftSearchResultPane.setBackground(Color.white); leftSearchResultPane.setBackground(Color.white);
@ -315,15 +289,13 @@ public class AlphaFineDialog extends UIDialog {
this.searchWorker = new SwingWorker() { this.searchWorker = new SwingWorker() {
@Override @Override
protected Object doInBackground() throws Exception { protected Object doInBackground() throws Exception {
rebuildList(searchTextField.getText().toLowerCase()); rebuildList(searchTextField.getText().toLowerCase());
return null; return null;
} }
@Override @Override
protected void done() { protected void done() {
if (!isCancelled() && searchListModel.getSize() > 1) {
if (!isCancelled() && searchListModel.getSize() > 0) {
searchResultList.setSelectedIndex(1); searchResultList.setSelectedIndex(1);
showResult(searchResultList.getSelectedIndex(), searchResultList.getSelectedValue()); showResult(searchResultList.getSelectedIndex(), searchResultList.getSelectedValue());
} }
@ -339,37 +311,33 @@ public class AlphaFineDialog extends UIDialog {
* @param searchText * @param searchText
*/ */
private void rebuildList(String searchText) { private void rebuildList(String searchText) {
searchListModel.removeAllElements(); searchListModel.removeAllElements();
if (searchText.startsWith(ADVANCED_SEARCH_MARK)) {
if (searchText.startsWith(ACTION_MARK_SHORT) || searchText.startsWith(ACTION_MARK)) { if (searchText.startsWith(ACTION_MARK_SHORT) || searchText.startsWith(ACTION_MARK)) {
getActionList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); getActionList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
return;
} else if (searchText.startsWith(DOCUMENT_MARK_SHORT) || searchText.startsWith(DOCUMENT_MARK)) { } else if (searchText.startsWith(DOCUMENT_MARK_SHORT) || searchText.startsWith(DOCUMENT_MARK)) {
getDocumentList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); getDocumentList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
return;
} else if (searchText.startsWith(FILE_MARK_SHORT) || searchText.startsWith(FILE_MARK)) { } else if (searchText.startsWith(FILE_MARK_SHORT) || searchText.startsWith(FILE_MARK)) {
getFileList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); getFileList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
return;
} else if (searchText.startsWith(CPT_MARK) || searchText.startsWith(FRM_MARK)) { } else if (searchText.startsWith(CPT_MARK) || searchText.startsWith(FRM_MARK)) {
getFileList(searchText); getFileList(searchText);
return;
} else if (searchText.startsWith(DS_MARK)) { } else if (searchText.startsWith(DS_MARK)) {
getFileList(DS_NAME + searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); getFileList(DS_NAME + searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
return;
} else if (searchText.startsWith(PLUGIN_MARK_SHORT) || searchText.startsWith(PLUGIN_MARK)) { } else if (searchText.startsWith(PLUGIN_MARK_SHORT) || searchText.startsWith(PLUGIN_MARK)) {
getPluginList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length())); getPluginList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
return;
} }
} else {
doNormalSearch(searchText.trim()); doNormalSearch(searchText.trim());
} }
}
/** /**
* 普通搜索 * 普通搜索
* *
* @param searchText * @param searchText
*/ */
private void doNormalSearch(String searchText) { private void doNormalSearch(String searchText) {
getRecentList(searchText); getRecentList(searchText);
getRecommendList(searchText); getRecommendList(searchText);
getActionList(searchText); getActionList(searchText);
@ -378,18 +346,15 @@ public class AlphaFineDialog extends UIDialog {
getPluginList(searchText); getPluginList(searchText);
} }
private synchronized void getDocumentList(final String searchText) { private void getDocumentList(final String searchText) {
SearchResult documentModelList = DocumentSearchManager.getDocumentSearchManager().getLessSearchResult(searchText); SearchResult documentModelList = DocumentSearchManager.getDocumentSearchManager().getLessSearchResult(searchText);
for (Object object : documentModelList) { for (Object object : documentModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
searchListModel.addElement(object); searchListModel.addElement(object);
} }
} }
private synchronized void getFileList(final String searchText) { private void getFileList(final String searchText) {
SearchResult fileModelList = FileSearchManager.getFileSearchManager().getLessSearchResult(searchText); SearchResult fileModelList = FileSearchManager.getFileSearchManager().getLessSearchResult(searchText);
for (Object object : fileModelList) { for (Object object : fileModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
@ -397,8 +362,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); SearchResult actionModelList = ActionSearchManager.getActionSearchManager().getLessSearchResult(searchText);
for (Object object : actionModelList) { for (Object object : actionModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
@ -406,8 +370,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); SearchResult pluginModelList = PluginSearchManager.getPluginSearchManager().getLessSearchResult(searchText);
for (Object object : pluginModelList) { for (Object object : pluginModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
@ -415,8 +378,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); SearchResult recommendModelList = RecommendSearchManager.getRecommendSearchManager().getLessSearchResult(searchText);
for (Object object : recommendModelList) { for (Object object : recommendModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
@ -424,8 +386,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); SearchResult recentModelList = RecentSearchManager.getRecentSearchManger().getLessSearchResult(searchText);
for (Object object : recentModelList) { for (Object object : recentModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
@ -434,71 +395,13 @@ 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());
}
}
});
/**
* 键盘监听器
*/
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);
}
}
}
});
}
private void showResult(int index, final Object selectedValue) { private void showResult(int index, final Object selectedValue) {
if (selectedValue instanceof FileModel) { if (selectedValue instanceof FileModel) {
final String fileName = ((FileModel) selectedValue).getFilePath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1); final String fileName = ((FileModel) selectedValue).getFilePath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1);
showDefaultPreviewPane(); showDefaultPreviewPane();
if (fileName.endsWith(ProjectConstants.FRM_SUFFIX)) { if (fileName.endsWith(ProjectConstants.FRM_SUFFIX)) {
if (this.searchWorker != null && !this.searchWorker.isDone()) { checkWorker();
this.searchWorker.cancel(true); this.showWorker = new SwingWorker<BufferedImage, Void>() {
this.searchWorker = null;
}
this.searchWorker = new SwingWorker<BufferedImage, Void>() {
@Override @Override
protected BufferedImage doInBackground() throws Exception { protected BufferedImage doInBackground() throws Exception {
Form form = FormIO.readForm(FRContext.getCurrentEnv(), fileName); Form form = FormIO.readForm(FRContext.getCurrentEnv(), fileName);
@ -522,13 +425,10 @@ public class AlphaFineDialog extends UIDialog {
} }
}; };
this.searchWorker.execute(); this.showWorker.execute();
} else if (fileName.endsWith(ProjectConstants.CPT_SUFFIX)) { } else if (fileName.endsWith(ProjectConstants.CPT_SUFFIX)) {
if (this.searchWorker != null && !this.searchWorker.isDone()) { checkWorker();
this.searchWorker.cancel(true); this.showWorker = new SwingWorker<BufferedImage, Void>() {
this.searchWorker = null;
}
this.searchWorker = new SwingWorker<BufferedImage, Void>() {
@Override @Override
protected BufferedImage doInBackground() throws Exception { protected BufferedImage doInBackground() throws Exception {
WorkBook workBook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(FRContext.getCurrentEnv(), fileName); WorkBook workBook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(FRContext.getCurrentEnv(), fileName);
@ -553,11 +453,10 @@ public class AlphaFineDialog extends UIDialog {
} }
}; };
this.searchWorker.execute(); this.showWorker.execute();
} }
} else if (selectedValue instanceof DocumentModel) { } else if (selectedValue instanceof DocumentModel) {
rightSearchResultPane.removeAll(); rightSearchResultPane.removeAll();
rightSearchResultPane.add(new DocumentPreviewPane(((DocumentModel) selectedValue).getName(), ((DocumentModel) selectedValue).getContent())); rightSearchResultPane.add(new DocumentPreviewPane(((DocumentModel) selectedValue).getName(), ((DocumentModel) selectedValue).getContent()));
@ -565,18 +464,19 @@ public class AlphaFineDialog extends UIDialog {
repaint(); repaint();
} else if (selectedValue instanceof PluginModel) { } else if (selectedValue instanceof PluginModel) {
showDefaultPreviewPane(); showDefaultPreviewPane();
if (this.searchWorker != null && !this.searchWorker.isDone()) { checkWorker();
this.searchWorker.cancel(true); this.showWorker = new SwingWorker<Image, Void>() {
this.searchWorker = null;
}
this.searchWorker = new SwingWorker<Image, Void>() {
@Override @Override
protected Image doInBackground() { protected Image doInBackground() {
BufferedImage bufferedImage = null; BufferedImage bufferedImage = null;
try { try {
bufferedImage = ImageIO.read(new URL(((PluginModel) selectedValue).getImageUrl())); bufferedImage = ImageIO.read(new URL(((PluginModel) selectedValue).getImageUrl()));
} catch (IOException e) { } 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; return bufferedImage;
} }
@ -598,7 +498,7 @@ public class AlphaFineDialog extends UIDialog {
} }
}; };
this.searchWorker.execute(); this.showWorker.execute();
} else if (selectedValue instanceof ActionModel) { } else if (selectedValue instanceof ActionModel) {
rightSearchResultPane.removeAll(); rightSearchResultPane.removeAll();
@ -609,6 +509,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) { private void HandleMoreOrLessResult(int index, MoreModel selectedValue) {
if (selectedValue.getContent().equals(Inter.getLocText("FR-Designer_AlphaFine_ShowAll"))) { if (selectedValue.getContent().equals(Inter.getLocText("FR-Designer_AlphaFine_ShowAll"))) {
selectedValue.setContent(Inter.getLocText("FR-Designer_AlphaFine_ShowLess")); selectedValue.setContent(Inter.getLocText("FR-Designer_AlphaFine_ShowLess"));
@ -622,38 +532,106 @@ public class AlphaFineDialog extends UIDialog {
private void showDefaultPreviewPane() { private void showDefaultPreviewPane() {
rightSearchResultPane.removeAll(); rightSearchResultPane.removeAll();
UILabel label = new UILabel(IOUtils.readIcon("/com/fr/design/mainframe/alphafine/images/opening.gif")); UILabel label = new UILabel(new ImageIcon(getClass().getResource("/com/fr/design/mainframe/alphafine/images/opening.gif")));
label.setBorder(BorderFactory.createEmptyBorder(120,0,0,0)); label.setBorder(BorderFactory.createEmptyBorder(120, 0, 0, 0));
rightSearchResultPane.add(label, BorderLayout.CENTER); rightSearchResultPane.add(label, BorderLayout.CENTER);
validate(); validate();
repaint(); repaint();
} }
private void initListener() { /**
* 为面板添加全局监听器
*/
private void initGlobalListener() {
initAWTEventListener(); initAWTEventListener();
initMouseListener(); 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());
}
}
});
} }
/** /**
* 窗口拖拽 * 窗口拖拽
*/ */
private void initMouseListener() { private void initMouseListener() {
addMouseMotionListener(new MouseMotionAdapter() { addMouseMotionListener(new MouseMotionAdapter() {
@Override @Override
public void mouseDragged(MouseEvent e) { public void mouseDragged(MouseEvent e) {
doMouseDragged(e); doMouseDragged(e);
} }
}); });
addMouseListener(new MouseAdapter() { addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
doMousePressed(e); doMousePressed(e);
} }
@ -795,7 +773,6 @@ public class AlphaFineDialog extends UIDialog {
* @param selectedValue * @param selectedValue
*/ */
private void rebuildShowMoreList(int index, MoreModel selectedValue) { private void rebuildShowMoreList(int index, MoreModel selectedValue) {
SearchResult moreResult = getMoreResult(selectedValue); SearchResult moreResult = getMoreResult(selectedValue);
if ((selectedValue).getContent().equals(Inter.getLocText("FR-Designer_AlphaFine_ShowLess"))) { if ((selectedValue).getContent().equals(Inter.getLocText("FR-Designer_AlphaFine_ShowLess"))) {
for (int i = 0; i < moreResult.size(); i++) { for (int i = 0; i < moreResult.size(); i++) {
@ -861,12 +838,10 @@ public class AlphaFineDialog extends UIDialog {
public boolean isForceOpen() { public boolean isForceOpen() {
return forceOpen; return forceOpen;
} }
public void setForceOpen(boolean forceOpen) { public void setForceOpen(boolean forceOpen) {
this.forceOpen = forceOpen; this.forceOpen = forceOpen;
} }

9
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.design.mainframe.toolbar.UpdateActionModel;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.json.JSONObject;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import java.util.List; import java.util.List;
@ -35,14 +36,16 @@ public class ActionSearchManager implements AlphaFineSearchProcessor {
/** /**
* 根据类名获取对象 * 根据类名获取对象
* *
* @param actionName * @param object
* @return * @return
*/ */
public static ActionModel getModelFromCloud(String actionName) { public static ActionModel getModelFromCloud(JSONObject object) {
String actionName = object.optString("className");
int searchCount = object.optInt("searchCount");
List<UpdateActionModel> updateActions = UpdateActionManager.getUpdateActionManager().getUpdateActions(); List<UpdateActionModel> updateActions = UpdateActionManager.getUpdateActionManager().getUpdateActions();
for (UpdateActionModel updateActionModel : updateActions) { for (UpdateActionModel updateActionModel : updateActions) {
if (ComparatorUtils.equals(actionName, updateActionModel.getClassName())) { 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; return null;

3
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 name = object.optString("title");
String content = object.optString("summary"); String content = object.optString("summary");
int documentId = object.optInt("did"); int documentId = object.optInt("did");
return new DocumentModel(name, content, documentId); int searchCount = object.optInt("searchCount");
return new DocumentModel(name, content, documentId, searchCount);
} }
@Override @Override

16
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.ComparatorUtils;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.json.JSONObject;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
@ -27,6 +28,8 @@ import java.util.List;
public class FileSearchManager implements AlphaFineSearchProcessor { public class FileSearchManager implements AlphaFineSearchProcessor {
private static final int MARK_LENGTH = 6; private static final int MARK_LENGTH = 6;
private static final String DS_NAME = "dsname=\""; 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 final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_Templates"), CellType.FILE);
private static FileSearchManager fileSearchManager = null; private static FileSearchManager fileSearchManager = null;
private SearchResult filterModelList; private SearchResult filterModelList;
@ -51,22 +54,24 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
/** /**
* 根据文件路径获取文件模型 * 根据文件路径获取文件模型
* *
* @param filePath * @param object
* @return * @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); String name = AlphaFineHelper.findFileName(filePath);
return new FileModel(name, filePath); return new FileModel(name, filePath, searchCount);
} }
public synchronized SearchResult getLessSearchResult(String searchText) { public synchronized SearchResult getLessSearchResult(String searchText) {
this.filterModelList = new SearchResult(); this.filterModelList = new SearchResult();
this.lessModelList = new SearchResult(); this.lessModelList = new SearchResult();
this.moreModelList = new SearchResult(); this.moreModelList = new SearchResult();
if (searchText.startsWith("k:frm ")) { if (searchText.startsWith(FRM_PREFIX)) {
isContainCpt = false; isContainCpt = false;
searchText = searchText.substring(MARK_LENGTH, searchText.length()); searchText = searchText.substring(MARK_LENGTH, searchText.length());
} else if (searchText.startsWith("k:cpt ")) { } else if (searchText.startsWith(CPT_PREFIX)) {
isContainFrm = false; isContainFrm = false;
searchText = searchText.substring(MARK_LENGTH, searchText.length()); searchText = searchText.substring(MARK_LENGTH, searchText.length());
} }
@ -139,6 +144,7 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
FileModel model = new FileModel(node.getName(), node.getEnvPath()); FileModel model = new FileModel(node.getName(), node.getEnvPath());
this.filterModelList.add(model); this.filterModelList.add(model);
} }
isr.close();
reader.close(); reader.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
FRLogger.getLogger().error(e.getMessage()); FRLogger.getLogger().error(e.getMessage());

3
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 name = object.optString("name");
String content = object.optString("description"); String content = object.optString("description");
int pluginId = object.optInt("id"); int pluginId = object.optInt("id");
int searchCount = object.optInt("searchCount");
String imageUrl = null; String imageUrl = null;
try { try {
imageUrl = isFromCloud ? AlphaFineConstants.PLUGIN_IMAGE_URL + URLEncoder.encode(object.optString("pic").toString().substring(AlphaFineConstants.PLUGIN_IMAGE_URL.length()), "utf8") : object.optString("pic"); 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; type = CellType.REUSE;
} }
int price = object.optInt("price"); 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);
} }
/** /**

31
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 { 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 final int MAX_SIZE = 3;
private static RecentSearchManager recentSearchManager = null; private static RecentSearchManager recentSearchManager = null;
private static File recentFile = null; private static File recentFile = null;
@ -64,7 +64,7 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
String nodeName = reader.getTagName(); String nodeName = reader.getTagName();
if (nodeName.equals("RecentModelList")) { if (nodeName.equals("RecentModelList")) {
String key = reader.getAttrAsString("searchKey", StringUtils.EMPTY); String key = reader.getAttrAsString("searchKey", StringUtils.EMPTY);
final ArrayList<AlphaCellModel> list = new ArrayList<AlphaCellModel>(); final ArrayList<AlphaCellModel> list = new ArrayList<>();
reader.readXMLObject(new XMLReadable() { reader.readXMLObject(new XMLReadable() {
@Override @Override
public void readXML(XMLableReader reader) { public void readXML(XMLableReader reader) {
@ -85,16 +85,16 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
if (reader.isChildNode()) { if (reader.isChildNode()) {
String nodeName = reader.getTagName(); String nodeName = reader.getTagName();
if (nodeName.equals("model")) { if (nodeName.equals("model")) {
String name = reader.getAttrAsString("cellModel", StringUtils.EMPTY); String modelValue = reader.getAttrAsString("cellModel", StringUtils.EMPTY);
addModelToList(list, name); addModelToList(list, modelValue);
} }
} }
} }
private void addModelToList(List<AlphaCellModel> list, String name) { private void addModelToList(List<AlphaCellModel> list, String modelValue) {
try { try {
AlphaCellModel model = CellModelHelper.getModelFromJson(new JSONObject(name)); AlphaCellModel model = CellModelHelper.getModelFromJson(new JSONObject(modelValue));
if (model != null) { if (model != null) {
list.add(model); list.add(model);
} }
@ -113,9 +113,9 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
writer.attr("searchKey", key); writer.attr("searchKey", key);
for (AlphaCellModel model : recentKVModelMap.get(key)) { for (AlphaCellModel model : recentKVModelMap.get(key)) {
try { try {
String name = model.ModelToJson().toString(); String modelValue = model.ModelToJson().toString();
writer.startTAG("model"); writer.startTAG("model");
writer.attr("cellModel", name); writer.attr("cellModel", modelValue);
writer.end(); writer.end();
} catch (JSONException e) { } catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage()); FRLogger.getLogger().error(e.getMessage());
@ -130,7 +130,7 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
@Override @Override
public String fileName() { 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) { private void createRecentFile(File envFile) {
try { try {
FileWriter fileWriter = new FileWriter(envFile); FileWriter fileWriter = new FileWriter(envFile);
StringReader stringReader = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><AlphafineRecent></AlphafineRecent>"); StringReader stringReader = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><AlphaFineRecent></AlphaFineRecent>");
Utils.copyCharTo(stringReader, fileWriter); Utils.copyCharTo(stringReader, fileWriter);
stringReader.close(); stringReader.close();
fileWriter.close(); fileWriter.close();
@ -231,9 +231,10 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
} }
} }
Collections.sort(resultModelList);
int size = resultModelList.size(); int size = resultModelList.size();
if (size > MAX_SIZE) { if (size > MAX_SIZE) {
return resultModelList.subList(size - MAX_SIZE, size); return resultModelList.subList(0, MAX_SIZE);
} }
return resultModelList; return resultModelList;
} }
@ -250,13 +251,13 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
public void addRecentModel(String searchKey, AlphaCellModel cellModel) { public void addRecentModel(String searchKey, AlphaCellModel cellModel) {
if (recentKVModelMap.keySet().contains(searchKey)) { if (recentKVModelMap.keySet().contains(searchKey)) {
List<AlphaCellModel> cellModels = recentKVModelMap.get(searchKey); List<AlphaCellModel> cellModels = recentKVModelMap.get(searchKey);
if (cellModels.contains(cellModel)) { int index = cellModels.indexOf(cellModel);
cellModels.remove(cellModel); if (index >= 0) {
cellModels.add(cellModel); cellModels.get(index).addSearchCount();
} else { } else {
cellModels.add(cellModel); cellModels.add(cellModel);
} }
trimToSize(cellModels); //trimToSize(cellModels);
} else { } else {
List<AlphaCellModel> list = new ArrayList<>(); List<AlphaCellModel> list = new ArrayList<>();
list.add(cellModel); list.add(cellModel);

27
designer_base/src/com/fr/design/actions/help/alphafine/AlphaFineConfigPane.java

@ -13,10 +13,7 @@ import com.fr.general.Inter;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
/** /**
* Created by XiaXiang on 2017/4/6. * Created by XiaXiang on 2017/4/6.
@ -100,7 +97,25 @@ public class AlphaFineConfigPane extends BasicPane {
private void createShortcutsPane(JPanel contentPane) { private void createShortcutsPane(JPanel contentPane) {
JPanel northPane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Designer_AlphaFine_Shortcut_Config")); JPanel northPane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Designer_AlphaFine_Shortcut_Config"));
shortcutsField = new UITextField(); shortcutsField = new UITextField();
shortcutsField.setEditable(false);
shortcutsField.selectAll();
shortcutsField.setPreferredSize(new Dimension(100, 20)); 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() { shortcutsField.addKeyListener(new KeyAdapter() {
@Override @Override
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
@ -112,11 +127,9 @@ public class AlphaFineConfigPane extends BasicPane {
shortCutKeyStore = KeyStroke.getKeyStroke(keyCode, modifier); shortCutKeyStore = KeyStroke.getKeyStroke(keyCode, modifier);
String str = shortCutKeyStore.toString(); String str = shortCutKeyStore.toString();
shortcutsField.setText(getDisplayShortCut(str)); 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) { private void createOnlinePane(JPanel contentPane) {

1
designer_base/src/com/fr/design/locale/designer.properties

@ -2085,3 +2085,4 @@ FR-Designer-Plugin-Store_Disconnected=
FR-Designer_AlphaFine_NoResult=no results FR-Designer_AlphaFine_NoResult=no results
FR-Designer_ConnectionFailed=connection failed FR-Designer_ConnectionFailed=connection failed
FR-Designer_NoResult=No results FR-Designer_NoResult=No results
FR-Designer-AlphaFine_SetShortcuts=

1
designer_base/src/com/fr/design/locale/designer_en_US.properties

@ -2085,3 +2085,4 @@ FR-Designer_ConnectionFailed=Connection failed
FR-Designer_AlphaFine_EnableAlphaFine=Enable AlphaFine FR-Designer_AlphaFine_EnableAlphaFine=Enable AlphaFine
FR-Designer_AlphaFine_EnableInternet=Internet FR-Designer_AlphaFine_EnableInternet=Internet
FR-Designer_NoResult=No results FR-Designer_NoResult=No results
FR-Designer-AlphaFine_SetShortcuts=please press two key to set shortcut

2
designer_base/src/com/fr/design/locale/designer_zh_CN.properties

@ -2082,4 +2082,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_AlphaFine_NoResult=\u6682\u65E0\u76F8\u5173\u5185\u5BB9
FR-Designer_ConnectionFailed=\u94FE\u63A5\u5931\u8D25 FR-Designer_ConnectionFailed=\u94FE\u63A5\u5931\u8D25
FR-Designer_NoResult=\u6682\u4E0D\u652F\u6301\u663E\u793A 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

1
designer_base/src/com/fr/design/locale/designer_zh_TW.properties

@ -2083,3 +2083,4 @@ FR-Designer-Plugin-Store_Disconnected=
FR-Designer_AlphaFine_NoResult=\u66AB\u7121\u76F8\u95DC\u5167\u5BB9 FR-Designer_AlphaFine_NoResult=\u66AB\u7121\u76F8\u95DC\u5167\u5BB9
FR-Designer_ConnectionFailed=\u93C8\u63A5\u5931\u6557 FR-Designer_ConnectionFailed=\u93C8\u63A5\u5931\u6557
FR-Designer_NoResult=\u66AB\u4E0D\u652F\u6301\u986F\u793A 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

Loading…
Cancel
Save