From 4d4905f1a529ae5a41b854568367fe311f4e7c6f Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Wed, 21 Jun 2017 14:04:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B4=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cell/render/ContentCellRender.java | 35 ++++++++----------- .../cell/render/TitleCellRender.java | 27 ++++++-------- 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java b/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java index ca97c6a077..10b72813e8 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java +++ b/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 { - 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 { 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; } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java b/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java index 3a037a7014..b105adba9d 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/render/TitleCellRender.java +++ b/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 { - 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");