Browse Source

代码质量

master
XiaXiang 8 years ago
parent
commit
4d4905f1a5
  1. 35
      designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java
  2. 27
      designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java

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

@ -14,17 +14,12 @@ import java.awt.*;
* Created by XiaXiang on 2017/4/20. * Created by XiaXiang on 2017/4/20.
*/ */
public class ContentCellRender implements ListCellRenderer<Object> { public class ContentCellRender implements ListCellRenderer<Object> {
private UILabel name;
private UILabel content;
public ContentCellRender() {
}
@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(); UILabel titleLabel = new UILabel();
this.content = 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);
} }
@ -35,29 +30,29 @@ public class ContentCellRender implements ListCellRenderer<Object> {
panel.setBackground(AlphaFineConstants.BLUE); panel.setBackground(AlphaFineConstants.BLUE);
} }
panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
name.setText(" " + model.getName()); titleLabel.setText(" " + model.getName());
String iconUrl = "/com/fr/design/mainframe/alphafine/images/alphafine" + model.getType().getTypeValue() + ".png"; String iconUrl = "/com/fr/design/mainframe/alphafine/images/alphafine" + model.getType().getTypeValue() + ".png";
if (model.hasNoResult()) { if (model.hasNoResult()) {
name.setIcon(null); titleLabel.setIcon(null);
name.setForeground(AlphaFineConstants.MEDIUM_GRAY); titleLabel.setForeground(AlphaFineConstants.MEDIUM_GRAY);
} else { } else {
name.setIcon(new ImageIcon(IOUtils.readImage(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);
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) (name.getPreferredSize().getWidth() + content.getPreferredSize().getWidth()); int width = (int) (titleLabel.getPreferredSize().getWidth() + detailLabel.getPreferredSize().getWidth());
if ( width > AlphaFineConstants.LEFT_WIDTH - 30) { if ( width > AlphaFineConstants.LEFT_WIDTH - 30) {
int nameWidth = (int) (AlphaFineConstants.LEFT_WIDTH - content.getPreferredSize().getWidth() - 45); int nameWidth = (int) (AlphaFineConstants.LEFT_WIDTH - detailLabel.getPreferredSize().getWidth() - 45);
name.setPreferredSize(new Dimension(nameWidth, AlphaFineConstants.CELL_HEIGHT)); 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)); panel.setPreferredSize(new Dimension(list.getFixedCellWidth(), AlphaFineConstants.CELL_HEIGHT));
return panel; return panel;
} }

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

@ -12,30 +12,25 @@ import java.awt.*;
* Created by XiaXiang on 2017/4/20. * 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, 10, 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");

Loading…
Cancel
Save