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.
*/
public class ContentCellRender implements ListCellRenderer<Object> {
private UILabel name;
private UILabel content;
public ContentCellRender() {
}
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
this.name = new UILabel();
this.content = new UILabel();
UILabel titleLabel = new UILabel();
UILabel detailLabel = new UILabel();
if (value instanceof MoreModel) {
return new TitleCellRender().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
@ -35,29 +30,29 @@ public class ContentCellRender implements ListCellRenderer<Object> {
panel.setBackground(AlphaFineConstants.BLUE);
}
panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
name.setText(" " + model.getName());
titleLabel.setText(" " + model.getName());
String iconUrl = "/com/fr/design/mainframe/alphafine/images/alphafine" + model.getType().getTypeValue() + ".png";
if (model.hasNoResult()) {
name.setIcon(null);
name.setForeground(AlphaFineConstants.MEDIUM_GRAY);
titleLabel.setIcon(null);
titleLabel.setForeground(AlphaFineConstants.MEDIUM_GRAY);
} else {
name.setIcon(new ImageIcon(IOUtils.readImage(iconUrl)));
name.setForeground(AlphaFineConstants.BLACK);
titleLabel.setIcon(new ImageIcon(IOUtils.readImage(iconUrl)));
titleLabel.setForeground(AlphaFineConstants.BLACK);
}
name.setFont(AlphaFineConstants.MEDIUM_FONT);
titleLabel.setFont(AlphaFineConstants.MEDIUM_FONT);
String description = model.getDescription();
if (StringUtils.isNotBlank(description)) {
content.setText("-" + description);
content.setForeground(AlphaFineConstants.LIGHT_GRAY);
panel.add(content, BorderLayout.CENTER);
int width = (int) (name.getPreferredSize().getWidth() + content.getPreferredSize().getWidth());
detailLabel.setText("-" + description);
detailLabel.setForeground(AlphaFineConstants.LIGHT_GRAY);
panel.add(detailLabel, BorderLayout.CENTER);
int width = (int) (titleLabel.getPreferredSize().getWidth() + detailLabel.getPreferredSize().getWidth());
if ( width > AlphaFineConstants.LEFT_WIDTH - 30) {
int nameWidth = (int) (AlphaFineConstants.LEFT_WIDTH - content.getPreferredSize().getWidth() - 45);
name.setPreferredSize(new Dimension(nameWidth, AlphaFineConstants.CELL_HEIGHT));
int nameWidth = (int) (AlphaFineConstants.LEFT_WIDTH - detailLabel.getPreferredSize().getWidth() - 45);
titleLabel.setPreferredSize(new Dimension(nameWidth, AlphaFineConstants.CELL_HEIGHT));
}
}
panel.add(name, BorderLayout.WEST);
panel.add(titleLabel, BorderLayout.WEST);
panel.setPreferredSize(new Dimension(list.getFixedCellWidth(), AlphaFineConstants.CELL_HEIGHT));
return panel;
}

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.
*/
public class TitleCellRender implements ListCellRenderer<Object> {
private UILabel name;
private UILabel more;
public TitleCellRender() {
this.name = new UILabel();
this.more = new UILabel();
}
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
UILabel titleLabel = new UILabel();
UILabel showMoreLabel = new UILabel();
MoreModel moreModel = (MoreModel) value;
JPanel panel = new JPanel(new BorderLayout());
panel.setBackground(AlphaFineConstants.WHITE);
panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
name.setText(moreModel.getName());
name.setFont(AlphaFineConstants.SMALL_FONT);
more.setFont(AlphaFineConstants.SMALL_FONT);
more.setText(moreModel.getContent());
name.setForeground(AlphaFineConstants.DARK_GRAY);
more.setForeground(AlphaFineConstants.DARK_GRAY);
panel.add(name, BorderLayout.WEST);
titleLabel.setText(moreModel.getName());
titleLabel.setFont(AlphaFineConstants.SMALL_FONT);
showMoreLabel.setFont(AlphaFineConstants.SMALL_FONT);
showMoreLabel.setText(moreModel.getContent());
titleLabel.setForeground(AlphaFineConstants.DARK_GRAY);
showMoreLabel.setForeground(AlphaFineConstants.DARK_GRAY);
panel.add(titleLabel, BorderLayout.WEST);
if (moreModel.isNeedMore()) {
this.more.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
panel.add(this.more, BorderLayout.EAST);
showMoreLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
panel.add(showMoreLabel, BorderLayout.EAST);
}
if (moreModel.isLoading()) {
ImageIcon imageIcon = (ImageIcon) IOUtils.readIcon("/com/fr/design/mainframe/alphafine/images/loading.gif");

Loading…
Cancel
Save