Browse Source

REPORT-3022 智能搜索619引擎功能改良

master
XiaXiang 8 years ago
parent
commit
cf1e437d40
  1. 21
      designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java
  2. 4
      designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java
  3. 18
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java

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

@ -17,23 +17,24 @@ public class ContentCellRender implements ListCellRenderer<Object> {
private UILabel content; private UILabel content;
public ContentCellRender() { 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) {
this.name = new UILabel();
this.content = 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; 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 && !model.hasNoResult()) { 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));
name.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";
if (model.hasNoResult()) { if (model.hasNoResult()) {
name.setIcon(null); name.setIcon(null);
@ -43,16 +44,20 @@ public class ContentCellRender implements ListCellRenderer<Object> {
name.setForeground(AlphaFineConstants.BLACK); name.setForeground(AlphaFineConstants.BLACK);
} }
name.setFont(AlphaFineConstants.MEDIUM_FONT); name.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); content.setText("-" + description);
content.setForeground(AlphaFineConstants.LIGHT_GRAY); content.setForeground(AlphaFineConstants.LIGHT_GRAY);
panel.add(content, BorderLayout.CENTER); 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.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; return panel;
} }
} }

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

@ -24,7 +24,7 @@ public class TitleCellRender implements ListCellRenderer<Object> {
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()); name.setText(moreModel.getName());
name.setFont(AlphaFineConstants.SMALL_FONT); name.setFont(AlphaFineConstants.SMALL_FONT);
more.setFont(AlphaFineConstants.SMALL_FONT); more.setFont(AlphaFineConstants.SMALL_FONT);
@ -44,7 +44,7 @@ public class TitleCellRender implements ListCellRenderer<Object> {
UILabel loadingLabel = new UILabel(imageIcon); UILabel loadingLabel = new UILabel(imageIcon);
panel.add(loadingLabel, BorderLayout.SOUTH); 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; return panel;
} }
} }

18
designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java

@ -174,7 +174,7 @@ 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);
centerWindow(this); centerWindow(this);
@ -394,7 +394,7 @@ public class AlphaFineDialog extends UIDialog {
} }
/** /**
* 初始化监听器 * 为各组件添加鼠标键盘监听器
*/ */
private void initListListener() { private void initListListener() {
/** /**
@ -432,7 +432,7 @@ public class AlphaFineDialog extends UIDialog {
}); });
/** /**
* 键盘监听器 * 为list添加键盘监听器
*/ */
searchResultList.addKeyListener(new KeyAdapter() { searchResultList.addKeyListener(new KeyAdapter() {
@Override @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) { private void showResult(int index, final Object selectedValue) {

Loading…
Cancel
Save