Skip to content

Commit 8ad58a4

Browse files
committed
新增今日收益排行榜 表格排序
1 parent a1a6dfd commit 8ad58a4

2 files changed

Lines changed: 43 additions & 10 deletions

File tree

src/main/java/cn/fudoc/trade/view/TodayProfitView.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import cn.fudoc.trade.view.dto.HoldStockDataDto;
44
import cn.fudoc.trade.view.render.ProfitRenderer;
55
import cn.fudoc.trade.view.render.RankListCellRenderer;
6+
import com.intellij.ui.JBColor;
67
import com.intellij.ui.components.JBList;
78
import com.intellij.ui.components.JBScrollPane;
89
import lombok.Getter;
@@ -51,11 +52,34 @@ public TodayProfitView() {
5152
JPanel rankPanel = new JPanel(new BorderLayout());
5253
this.rankListModel = new DefaultListModel<>();
5354
this.rankList = new JBList<>(this.rankListModel);
55+
this.rankList.setFixedCellHeight(40);
56+
this.rankList.setFont(this.rankList.getFont().deriveFont(15.0f));
5457
this.rankList.setCellRenderer(new RankListCellRenderer());
58+
rankPanel.add(createProfitPanel(), BorderLayout.NORTH);
5559
rankPanel.add(new JBScrollPane(this.rankList), BorderLayout.CENTER);
5660
this.rootPanel.add(rankPanel, BorderLayout.CENTER);
5761
}
5862

63+
private JPanel createProfitPanel() {
64+
JLabel rankLabel = new JLabel("今日收益贡献度排名");
65+
JLabel profitLabel = new JLabel("今日收益");
66+
rankLabel.setForeground(JBColor.GRAY);
67+
rankLabel.setFont(rankLabel.getFont().deriveFont(13.0f));
68+
profitLabel.setForeground(JBColor.GRAY);
69+
profitLabel.setFont(rankLabel.getFont().deriveFont(13.0f));
70+
JPanel titlePanel = new JPanel();
71+
titlePanel.setLayout(new BoxLayout(titlePanel, BoxLayout.X_AXIS));
72+
titlePanel.add(Box.createHorizontalGlue());
73+
titlePanel.add(rankLabel);
74+
titlePanel.add(Box.createHorizontalGlue());
75+
titlePanel.add(profitLabel);
76+
titlePanel.add(Box.createHorizontalGlue());
77+
titlePanel.setPreferredSize(new Dimension(titlePanel.getWidth(), 50));
78+
titlePanel.setSize(new Dimension(titlePanel.getWidth(), 50));
79+
titlePanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
80+
return titlePanel;
81+
}
82+
5983

6084
public void setTodayProfit(String todayProfit) {
6185
todayProfitPanel.setValue(todayProfit, true);
@@ -70,9 +94,8 @@ public void setCompanyValue(String companyValue) {
7094
}
7195

7296

73-
74-
public void initData(List<HoldStockDataDto> dataList){
97+
public void initData(List<HoldStockDataDto> dataList) {
7598
this.rankListModel.clear();
76-
if(CollectionUtils.isNotEmpty(dataList)) this.rankListModel.addAll(dataList);
99+
if (CollectionUtils.isNotEmpty(dataList)) this.rankListModel.addAll(dataList);
77100
}
78101
}

src/main/java/cn/fudoc/trade/view/render/RankListCellRenderer.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javax.swing.*;
99
import java.awt.*;
1010
import java.math.BigDecimal;
11+
import java.util.Objects;
1112

1213
public class RankListCellRenderer extends JPanel implements ListCellRenderer<HoldStockDataDto> {
1314

@@ -17,12 +18,18 @@ public class RankListCellRenderer extends JPanel implements ListCellRenderer<Hol
1718
private final JLabel profitLabel = new JLabel();
1819

1920
public RankListCellRenderer() {
20-
// 设置布局:左侧图标,右侧上下两行文本
21-
setLayout(new BorderLayout(8, 0)); // 组件间距8px,垂直4px
21+
// 1. 初始化GridLayout:1行N列(N=组件数),间距0
22+
setLayout(new GridLayout(1, 3, 0, 0));
2223
setBorder(JBUI.Borders.empty(4, 8));
23-
add(rankLabel, BorderLayout.WEST);
24-
add(nameLabel, BorderLayout.CENTER);
25-
add(profitLabel, BorderLayout.EAST);
24+
25+
rankLabel.setFont(rankLabel.getFont().deriveFont(15.0f).deriveFont(Font.BOLD));
26+
nameLabel.setFont(nameLabel.getFont().deriveFont(15.0f).deriveFont(Font.BOLD));
27+
profitLabel.setFont(profitLabel.getFont().deriveFont(15.0f).deriveFont(Font.BOLD));
28+
rankLabel.setHorizontalAlignment(SwingConstants.CENTER);
29+
profitLabel.setHorizontalAlignment(SwingConstants.CENTER);
30+
add(rankLabel);
31+
add(nameLabel);
32+
add(profitLabel);
2633
// 设置面板透明(避免遮挡背景)
2734
setOpaque(true);
2835
}
@@ -50,13 +57,16 @@ public Component getListCellRendererComponent(JList<? extends HoldStockDataDto>
5057
codeLabel.setText(value.getStockCode());
5158
nameLabel.setText(value.getStockName());
5259
profitLabel.setText(NumberFormatUtil.format(value.getTodayProfit()));
53-
profitLabel.setForeground(getTextColor(value.getTodayProfit()));
60+
JBColor textColor = getTextColor(value.getTodayProfit());
61+
if(Objects.nonNull(textColor)){
62+
profitLabel.setForeground(textColor);
63+
}
5464
}
5565
return this;
5666
}
5767

5868
protected JBColor getTextColor(BigDecimal value) {
59-
int diff = BigDecimal.ZERO.compareTo(value);
69+
int diff = value.compareTo(BigDecimal.ZERO);
6070
if (diff == 0) {
6171
return null;
6272
}

0 commit comments

Comments
 (0)