diff --git a/build.gradle b/build.gradle index 908ff0b..6ffc345 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'com.huage2580' -version '2.0.1' +version '2.1.0' sourceCompatibility = 1.8 diff --git a/src/main/java/bean/StockBean.java b/src/main/java/bean/StockBean.java index 79b4eff..4c21f94 100644 --- a/src/main/java/bean/StockBean.java +++ b/src/main/java/bean/StockBean.java @@ -1,6 +1,7 @@ package bean; import org.apache.commons.lang3.StringUtils; + import utils.PinYinUtils; import java.time.LocalDate; @@ -8,6 +9,8 @@ import java.util.Map; import java.util.Objects; +import com.intellij.ide.util.PropertiesComponent; + public class StockBean { private String code; private String name; @@ -25,11 +28,16 @@ public class StockBean { private String min; private String costPrise;//成本价 -// private String cost;//成本 + // private String cost;//成本 private String bonds;//持仓 private String incomePercent;//收益率 private String income;//收益 + //盯盘低价 + private String lowRemind; + //盯盘高价 + private String highRemind; + public StockBean() { } @@ -52,11 +60,18 @@ public StockBean(String code) { this.code = code; } this.name = "--"; + + PropertiesComponent instance = PropertiesComponent.getInstance(); + String remindPrice = instance.getValue(code + "_remind"); + if (StringUtils.isNotBlank(remindPrice)) { + this.lowRemind = remindPrice.split("_")[0]; + this.highRemind = remindPrice.split("_")[1]; + } } - public StockBean(String code, Map codeMap){ + public StockBean(String code, Map codeMap) { this.code = code; - if(codeMap.containsKey(code)){ + if (codeMap.containsKey(code)) { String[] codeStr = codeMap.get(code); if (codeStr.length > 2) { this.code = codeStr[0]; @@ -171,6 +186,22 @@ public void setIncome(String income) { this.income = income; } + public String getLowRemind() { + return lowRemind; + } + + public void setLowRemind(String lowRemind) { + this.lowRemind = lowRemind; + } + + public String getHighRemind() { + return highRemind; + } + + public void setHighRemind(String highRemind) { + this.highRemind = highRemind; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -224,6 +255,10 @@ public String getValueByColumn(String colums, boolean colorful) { return this.getCostPrise() != null ? this.getIncomePercent() + "%" : this.getIncomePercent(); case "收益": return this.getIncome(); + case "盯盘低价": + return "0".equals(this.getLowRemind()) ? null : this.getLowRemind(); + case "盯盘高价": + return "0".equals(this.getHighRemind()) ? null : this.getHighRemind(); case "更新时间": String timeStr = "--"; if (this.getTime() != null) { diff --git a/src/main/java/CoinWindow.form b/src/main/java/form/CoinWindow.form similarity index 90% rename from src/main/java/CoinWindow.form rename to src/main/java/form/CoinWindow.form index 5e2179f..7b2bb8f 100644 --- a/src/main/java/CoinWindow.form +++ b/src/main/java/form/CoinWindow.form @@ -1,5 +1,5 @@ -
+ diff --git a/src/main/java/CoinWindow.java b/src/main/java/form/CoinWindow.java similarity index 99% rename from src/main/java/CoinWindow.java rename to src/main/java/form/CoinWindow.java index c8bee68..f6e32a2 100644 --- a/src/main/java/CoinWindow.java +++ b/src/main/java/form/CoinWindow.java @@ -1,3 +1,5 @@ +package form; + import com.intellij.icons.AllIcons; import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.actionSystem.ActionToolbarPosition; diff --git a/src/main/java/FundWindow.form b/src/main/java/form/FundWindow.form similarity index 90% rename from src/main/java/FundWindow.form rename to src/main/java/form/FundWindow.form index 8deb941..462ff97 100644 --- a/src/main/java/FundWindow.form +++ b/src/main/java/form/FundWindow.form @@ -1,5 +1,5 @@ - + diff --git a/src/main/java/FundWindow.java b/src/main/java/form/FundWindow.java similarity index 99% rename from src/main/java/FundWindow.java rename to src/main/java/form/FundWindow.java index 0122012..716848d 100644 --- a/src/main/java/FundWindow.java +++ b/src/main/java/form/FundWindow.java @@ -1,3 +1,5 @@ +package form; + import com.intellij.icons.AllIcons; import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.actionSystem.ActionToolbarPosition; diff --git a/src/main/java/SettingsWindow.form b/src/main/java/form/SettingsWindow.form similarity index 99% rename from src/main/java/SettingsWindow.form rename to src/main/java/form/SettingsWindow.form index 52e6e5d..1dc3708 100644 --- a/src/main/java/SettingsWindow.form +++ b/src/main/java/form/SettingsWindow.form @@ -1,5 +1,5 @@ - + diff --git a/src/main/java/SettingsWindow.java b/src/main/java/form/SettingsWindow.java similarity index 99% rename from src/main/java/SettingsWindow.java rename to src/main/java/form/SettingsWindow.java index 344cae6..265403f 100644 --- a/src/main/java/SettingsWindow.java +++ b/src/main/java/form/SettingsWindow.java @@ -1,3 +1,5 @@ +package form; + import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurationException; diff --git a/src/main/java/StockWindow.form b/src/main/java/form/StockWindow.form similarity index 90% rename from src/main/java/StockWindow.form rename to src/main/java/form/StockWindow.form index 614e8d9..19496ff 100644 --- a/src/main/java/StockWindow.form +++ b/src/main/java/form/StockWindow.form @@ -1,5 +1,5 @@ - + diff --git a/src/main/java/StockWindow.java b/src/main/java/form/StockWindow.java similarity index 91% rename from src/main/java/StockWindow.java rename to src/main/java/form/StockWindow.java index 8444584..2432a08 100644 --- a/src/main/java/StockWindow.java +++ b/src/main/java/form/StockWindow.java @@ -1,7 +1,14 @@ +package form; + import com.intellij.icons.AllIcons; import com.intellij.ide.util.PropertiesComponent; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationDisplayType; +import com.intellij.notification.NotificationGroup; +import com.intellij.notification.Notifications; import com.intellij.openapi.actionSystem.ActionToolbarPosition; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.ui.popup.util.BaseListPopupStep; @@ -29,7 +36,6 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import java.net.MalformedURLException; -import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -94,7 +100,12 @@ public void mousePressed(MouseEvent e) { @Override public @Nullable PopupStep onChosen(PopupsUiUtil.StockShowType selectedValue, boolean finalChoice) { try { - PopupsUiUtil.showImageByStockCode(code, selectedValue, new Point(e.getXOnScreen(), e.getYOnScreen())); + if (PopupsUiUtil.StockShowType.remind.getType().equals(selectedValue.getType())){ + PopupsUiUtil.showRemindPanel(code, selectedValue, new Point(e.getXOnScreen(), e.getYOnScreen())); + + }else { + PopupsUiUtil.showImageByStockCode(code, selectedValue, new Point(e.getXOnScreen(), e.getYOnScreen())); + } } catch (MalformedURLException ex) { ex.printStackTrace(); LogUtil.info(ex.getMessage()); diff --git a/src/main/java/handler/SinaStockHandler.java b/src/main/java/handler/SinaStockHandler.java index e33b8b9..1eaa69f 100644 --- a/src/main/java/handler/SinaStockHandler.java +++ b/src/main/java/handler/SinaStockHandler.java @@ -1,13 +1,18 @@ package handler; import bean.StockBean; + import com.google.common.base.Joiner; import com.google.common.base.Strings; +import com.intellij.ide.util.PropertiesComponent; + import org.apache.commons.lang.StringUtils; + import utils.HttpClientPool; import utils.LogUtil; import javax.swing.*; + import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; @@ -92,6 +97,13 @@ public void handleResponse(String response, Map codeMap) { bean.setMax(split[4]); bean.setMin(split[5]); + PropertiesComponent instance = PropertiesComponent.getInstance(); + String remindPrice = instance.getValue(code + "_remind"); + if (StringUtils.isNotBlank(remindPrice)) { + bean.setLowRemind(remindPrice.split("_")[0]); + bean.setHighRemind(remindPrice.split("_")[1]); + } + String costPriceStr = bean.getCostPrise(); if (StringUtils.isNotEmpty(costPriceStr)) { BigDecimal costPriceDec = new BigDecimal(costPriceStr); diff --git a/src/main/java/handler/StockRefreshHandler.java b/src/main/java/handler/StockRefreshHandler.java index fd74e0d..ca84524 100644 --- a/src/main/java/handler/StockRefreshHandler.java +++ b/src/main/java/handler/StockRefreshHandler.java @@ -1,11 +1,20 @@ package handler; import bean.StockBean; + import com.intellij.ide.util.PropertiesComponent; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationDisplayType; +import com.intellij.notification.NotificationGroup; +import com.intellij.notification.Notifications; +import com.intellij.openapi.ui.MessageType; import com.intellij.ui.JBColor; import com.intellij.ui.table.JBTable; + import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; + +import utils.LogUtil; import utils.PinYinUtils; import utils.WindowUtils; @@ -13,7 +22,9 @@ import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableRowSorter; + import java.awt.*; +import java.math.BigDecimal; import java.util.List; import java.util.*; @@ -167,6 +178,28 @@ protected void updateData(StockBean bean) { } else { addRow(convertData); } + + //盯盘提醒 + PropertiesComponent instance = PropertiesComponent.getInstance(); + String remindPrice = instance.getValue(bean.getCode() + "_remind"); + if (StringUtils.isNotBlank(remindPrice) && StringUtils.isNotBlank(bean.getNow())) { + String lowPrice = remindPrice.split("_")[0]; + String highPrice = remindPrice.split("_")[1]; + + BigDecimal nowValue = new BigDecimal(bean.getNow()); + String remindText = ""; + if (!StringUtils.equals("0", lowPrice) && new BigDecimal(lowPrice).compareTo(nowValue) > -1) { + remindText = "低价提醒!" + bean.getCode() + bean.getName() + ",现价:" + nowValue + ",低于盯盘价:" + lowPrice; + instance.setValue(bean.getCode() + "_remind", "0_" + highPrice); + LogUtil.info(remindText); + LogUtil.notify(remindText, true); + } else if (!StringUtils.equals("0", highPrice) && new BigDecimal(highPrice).compareTo(nowValue) < 1) { + remindText = "高价提醒!" + bean.getCode() + bean.getName() + ",现价:" + nowValue + ",高于盯盘价:" + highPrice; + instance.setValue(bean.getCode() + "_remind", lowPrice + "_0"); + LogUtil.info(remindText); + LogUtil.notify(remindText, true); + } + } } /** diff --git a/src/main/java/handler/TencentStockHandler.java b/src/main/java/handler/TencentStockHandler.java index 35824cc..9a4d3e0 100644 --- a/src/main/java/handler/TencentStockHandler.java +++ b/src/main/java/handler/TencentStockHandler.java @@ -1,11 +1,14 @@ package handler; import bean.StockBean; + import org.apache.commons.lang.StringUtils; + import utils.HttpClientPool; import utils.LogUtil; import javax.swing.*; + import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDateTime; @@ -13,6 +16,8 @@ import java.util.HashMap; import java.util.List; +import com.intellij.ide.util.PropertiesComponent; + public class TencentStockHandler extends StockRefreshHandler { private String urlPara; private HashMap codeMap; @@ -86,6 +91,13 @@ private void parse(String result) { bean.setMax(values[33]);//33 bean.setMin(values[34]);//34 + PropertiesComponent instance = PropertiesComponent.getInstance(); + String remindPrice = instance.getValue(code + "_remind"); + if (StringUtils.isNotBlank(remindPrice)) { + bean.setLowRemind(remindPrice.split("_")[0]); + bean.setHighRemind(remindPrice.split("_")[1]); + } + BigDecimal now = new BigDecimal(values[3]); String costPriceStr = bean.getCostPrise(); if (StringUtils.isNotEmpty(costPriceStr)) { diff --git a/src/main/java/utils/PopupsUiUtil.java b/src/main/java/utils/PopupsUiUtil.java index aaf60b7..4a1428f 100644 --- a/src/main/java/utils/PopupsUiUtil.java +++ b/src/main/java/utils/PopupsUiUtil.java @@ -1,18 +1,29 @@ package utils; +import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.ui.awt.RelativePoint; +import com.intellij.ui.components.JBLabel; import com.intellij.ui.tabs.TabInfo; import com.intellij.ui.tabs.TabsListener; import com.intellij.ui.tabs.impl.JBTabsImpl; + import org.apache.commons.lang.StringUtils; import javax.swing.*; +import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; +import javax.swing.text.PlainDocument; + import java.awt.*; import java.net.MalformedURLException; import java.net.URL; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import form.StockWindow; /** * intellij ui 弹窗展示工具类
@@ -28,7 +39,7 @@ public class PopupsUiUtil { public static void showImageByFundCode(String fundCode, FundShowType type, Point showByPoint) throws MalformedURLException { //------试图解决个BUG,项目销毁的问题------- Project project = LogUtil.getProject(); - if (project.isDisposed()){ + if (project.isDisposed()) { return; } // 图片接口 @@ -144,6 +155,52 @@ public void selectionChanged(TabInfo oldSelection, TabInfo newSelection) { .createBalloon().show(RelativePoint.fromScreen(showByPoint), Balloon.Position.atRight); } + public static void showRemindPanel(String stockCode, StockShowType selectType, Point showByPoint) throws MalformedURLException { + JBPopupFactory instance = JBPopupFactory.getInstance();//创建JBPopupFactory实例 + JLabel lowPriceLabel = new JLabel(RemindType.lowPrice.getDesc()); + JLabel highPriceLabel = new JLabel(RemindType.highPrice.getDesc()); + JTextField lowPriceArea = new JTextField(10); + JTextField highPriceArea = new JTextField(10); + lowPriceArea.setToolTipText("请输入整数或三位以内小数"); + highPriceArea.setToolTipText("请输入整数或三位以内小数"); + JButton button = new JButton("确定"); + JPanel panel = new JPanel(); + panel.setSize(80, 30); + panel.add(lowPriceLabel); + panel.add(lowPriceArea); + panel.add(highPriceLabel); + panel.add(highPriceArea); + panel.add(button); + // 添加监听事件 + PropertiesComponent component = PropertiesComponent.getInstance(); + button.addActionListener(d -> { + + if (StringUtils.isNotBlank(lowPriceArea.getText()) && !Pattern.matches("[0-9]+(\\.[0-9]{1,3})?", lowPriceArea.getText())) { + lowPriceArea.requestFocus(); + return; + } + if (StringUtils.isNotBlank(highPriceArea.getText()) && !Pattern.matches("[0-9]+(\\.[0-9]{1,3})?", highPriceArea.getText())) { + highPriceArea.requestFocus(); + return; + } + + if (StringUtils.isNotBlank(lowPriceArea.getText()) || StringUtils.isNotBlank(highPriceArea.getText())) { + String lowPrice = StringUtils.isBlank(lowPriceArea.getText()) ? "0" : lowPriceArea.getText(); + String highPrice = StringUtils.isBlank(highPriceArea.getText()) ? "0" : highPriceArea.getText(); + component.setValue(stockCode + "_remind", lowPrice + "_" + highPrice); + StockWindow.refresh(); + } + }); + instance.createComponentPopupBuilder(panel, lowPriceLabel) + .setTitle("盯盘提醒") + .setRequestFocus(true) + .setMovable(true) + .setResizable(true) + .setNormalWindowLevel(false) + .createPopup() + .show(RelativePoint.fromScreen(showByPoint)); + } + public enum FundShowType { /** * 净值估算图 @@ -176,7 +233,11 @@ public enum StockShowType { /** * 月K线图 */ - monthly("monthly", "月K线图"); + monthly("monthly", "月K线图"), + /** + * 盯盘提醒 + */ + remind("remind", "盯盘提醒"); private String type; private String desc; @@ -194,4 +255,31 @@ public String getDesc() { return desc; } } + + public enum RemindType { + /** + * 价格低于 + */ + lowPrice("lowPrice", "价格低于"), + /** + * 价格高于 + */ + highPrice("highPrice", "价格高于"); + + private String type; + private String desc; + + RemindType(String type, String desc) { + this.type = type; + this.desc = desc; + } + + public String getType() { + return type; + } + + public String getDesc() { + return desc; + } + } } diff --git a/src/main/java/utils/WindowUtils.java b/src/main/java/utils/WindowUtils.java index d405cca..653334d 100644 --- a/src/main/java/utils/WindowUtils.java +++ b/src/main/java/utils/WindowUtils.java @@ -12,8 +12,8 @@ public class WindowUtils { public static final String FUND_TABLE_HEADER_KEY = "fund_table_header_key2"; //移动表头时存储的key public static final String FUND_TABLE_HEADER_VALUE = "编码,基金名称,估算涨跌,当日净值,估算净值,持仓成本价,持有份额,收益率,收益,更新时间"; //股票表头 - public static final String STOCK_TABLE_HEADER_KEY = "stock_table_header_key2"; //移动表头时存储的key - public static final String STOCK_TABLE_HEADER_VALUE = "编码,股票名称,涨跌,涨跌幅,最高价,最低价,当前价,成本价,持仓,收益率,收益,更新时间"; + public static final String STOCK_TABLE_HEADER_KEY = "stock_table_header_key3"; //移动表头时存储的key + public static final String STOCK_TABLE_HEADER_VALUE = "编码,股票名称,涨跌,涨跌幅,最高价,最低价,当前价,盯盘低价,盯盘高价,成本价,持仓,收益率,收益,更新时间"; //货币表头 public static final String COIN_TABLE_HEADER_KEY = "coin_table_header_key2"; //移动表头时存储的key public static final String COIN_TABLE_HEADER_VALUE = "编码,当前价,涨跌,涨跌幅,最高价,最低价,更新时间"; @@ -42,6 +42,9 @@ public class WindowUtils { remapPinYinMap.put(PinYinUtils.toPinYin("持仓成本价"), "持仓成本价"); remapPinYinMap.put(PinYinUtils.toPinYin("持有份额"), "持有份额"); + + remapPinYinMap.put(PinYinUtils.toPinYin("盯盘低价"), "盯盘低价"); + remapPinYinMap.put(PinYinUtils.toPinYin("盯盘高价"), "盯盘高价"); } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index eaba230..a7c629b 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -18,8 +18,8 @@ - - + +