Browse Source

alphafine bug fix

master
XiaXiang 7 years ago
parent
commit
ff8a971875
  1. 2
      designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java
  2. 3
      designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java
  3. 5
      designer/src/com/fr/design/mainframe/alphafine/cell/model/NoResultModel.java
  4. 10
      designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java
  5. 6
      designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java
  6. 192
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  7. 7
      designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java

2
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);

3
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
*

5
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;
}
}

10
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<Object> {
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<Object> {
panel.add(content, BorderLayout.CENTER);
}
panel.add(name, BorderLayout.WEST);
panel.setPreferredSize(new Dimension((int) panel.getPreferredSize().getWidth(), AlphaFineConstants.CELL_HEIGHT));
return panel;
}
}

6
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<Object> {
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;
}
}

192
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;
}
}

7
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());

Loading…
Cancel
Save