diff --git a/README.md b/README.md index c3dd97a..2c1042f 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,9 @@ double shift,连按两下shift,输入leeks,找到toolWindow,打开以后 - v1.6.2 适配IDEA 2020.3 - v1.6.3 -修复颜色错乱问题 +修复颜色错乱问题 , 日志调整 merge from [qwn3213](https://github.com/qwn3213) +- v1.7.1 +增加日志开关 ,设置界面样式调整 merge from [dengerYang](https://github.com/dengerYang) ,增加新浪股票接口备选 merge from [JulianXG](https://github.com/JulianXG) + diff --git a/build.gradle b/build.gradle index a34f94a..d24c217 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'com.huage2580' -version '1.6.4' +version '1.7.1' sourceCompatibility = 1.8 @@ -32,6 +32,7 @@ patchPluginXml { v1.4 增加了隐蔽模式(全拼音和无色涨跌幅 v1.5 增加了股票界面的排序~,可按净值和涨跌幅等列排序 v1.6 样式修改,增加精确净值(当日,上一交易日 + v1.7 设置界面样式调整,增加新浪股票接口备选 """ sinceBuild '173.*' untilBuild '203.*' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 731c706..3d11bb9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ #Wed Jul 15 10:09:28 CST 2020 -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/leeks-1.6.3.zip b/leeks-1.7.1.zip similarity index 73% rename from leeks-1.6.3.zip rename to leeks-1.7.1.zip index 58eb05f..b5a30ea 100644 Binary files a/leeks-1.6.3.zip and b/leeks-1.7.1.zip differ diff --git a/src/main/java/SettingsWindow.form b/src/main/java/SettingsWindow.form index 61aa9f2..741d016 100644 --- a/src/main/java/SettingsWindow.form +++ b/src/main/java/SettingsWindow.form @@ -6,9 +6,11 @@ - + + + @@ -27,20 +29,9 @@ - - - - - - - - - - - - + @@ -88,7 +79,7 @@ - + @@ -156,7 +147,7 @@ - + @@ -192,9 +183,43 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/SettingsWindow.java b/src/main/java/SettingsWindow.java index ce22947..7ff413e 100644 --- a/src/main/java/SettingsWindow.java +++ b/src/main/java/SettingsWindow.java @@ -18,6 +18,8 @@ public class SettingsWindow implements Configurable { private JCheckBox checkBoxTableStriped; private JSpinner spinnerFund; private JSpinner spinnerStock; + private JCheckBox checkboxSina; + private JCheckBox checkboxLog; @Override public @Nls(capitalization = Nls.Capitalization.Title) String getDisplayName() { @@ -34,6 +36,8 @@ public class SettingsWindow implements Configurable { textAreaStock.setText(value_stock); checkbox.setSelected(!value_color); checkBoxTableStriped.setSelected(instance.getBoolean("key_table_striped")); + checkboxSina.setSelected(instance.getBoolean("key_stocks_sina")); + checkboxLog.setSelected(instance.getBoolean("key_close_log")); spinnerFund.setModel(new SpinnerNumberModel(instance.getInt("key_funds_thread_time", 60), 1, Integer.MAX_VALUE, 1)); spinnerStock.setModel(new SpinnerNumberModel(instance.getInt("key_stocks_thread_time", 10), 1, Integer.MAX_VALUE, 1)); return panel1; @@ -53,6 +57,8 @@ public void apply() throws ConfigurationException { instance.setValue("key_funds_thread_time", spinnerFund.getValue().toString()); instance.setValue("key_stocks_thread_time", spinnerStock.getValue().toString()); instance.setValue("key_table_striped", checkBoxTableStriped.isSelected()); + instance.setValue("key_stocks_sina",checkboxSina.isSelected()); + instance.setValue("key_close_log",checkboxLog.isSelected()); StockWindow.apply(); FundWindow.apply(); } diff --git a/src/main/java/StockWindow.java b/src/main/java/StockWindow.java index 6ad0a67..7c4da9b 100644 --- a/src/main/java/StockWindow.java +++ b/src/main/java/StockWindow.java @@ -18,19 +18,26 @@ public class StockWindow { private JPanel mPanel; - static TencentStockHandler handler; + static StockRefreshHandler handler; + + static JBTable table; + static JLabel refreshTimeLabel; public JPanel getmPanel() { return mPanel; } - public StockWindow() { - JLabel refreshTimeLabel = new JLabel(); + static { + refreshTimeLabel = new JLabel(); refreshTimeLabel.setToolTipText("最后刷新时间"); refreshTimeLabel.setBorder(new EmptyBorder(0, 0, 0, 5)); + table = new JBTable(); + } - JBTable table = new JBTable(); - handler = new TencentStockHandler(table, refreshTimeLabel); + public StockWindow() { + + //切换接口 + handler = factoryHandler(); AnActionButton refreshAction = new AnActionButton("停止刷新当前表格数据", AllIcons.Actions.StopRefresh) { @Override @@ -57,8 +64,29 @@ public void actionPerformed(@NotNull AnActionEvent e) { apply(); } + private static StockRefreshHandler factoryHandler(){ + boolean useSinaApi = PropertiesComponent.getInstance().getBoolean("key_stocks_sina"); + if (useSinaApi){ + if (handler instanceof SinaStockHandler){ + return handler; + } + if (handler!=null){ + handler.stopHandle(); + } + return new SinaStockHandler(table, refreshTimeLabel); + } + if (handler instanceof TencentStockHandler){ + return handler; + } + if (handler!=null){ + handler.stopHandle(); + } + return new TencentStockHandler(table, refreshTimeLabel); + } + public static void apply() { if (handler != null) { + handler = factoryHandler(); PropertiesComponent instance = PropertiesComponent.getInstance(); handler.setStriped(instance.getBoolean("key_table_striped")); handler.setThreadSleepTime(instance.getInt("key_stocks_thread_time", handler.getThreadSleepTime())); diff --git a/src/main/java/utils/LogUtil.java b/src/main/java/utils/LogUtil.java index 26f7301..6ae42b2 100644 --- a/src/main/java/utils/LogUtil.java +++ b/src/main/java/utils/LogUtil.java @@ -1,5 +1,6 @@ package utils; +import com.intellij.ide.util.PropertiesComponent; import com.intellij.notification.NotificationDisplayType; import com.intellij.notification.NotificationGroup; import com.intellij.openapi.project.Project; @@ -13,6 +14,9 @@ public static void setProject(Project project) { } public static void info(String text){ - new NotificationGroup("Gradle sync", NotificationDisplayType.NONE, true).createNotification(text, MessageType.INFO).notify(project); + boolean closeLog = PropertiesComponent.getInstance().getBoolean("key_close_log"); + if (!closeLog){ + new NotificationGroup("Gradle sync", NotificationDisplayType.NONE, true).createNotification(text, MessageType.INFO).notify(project); + } } } diff --git a/src/main/java/utils/SinaStockHandler.java b/src/main/java/utils/SinaStockHandler.java index a197e9f..0879b27 100644 --- a/src/main/java/utils/SinaStockHandler.java +++ b/src/main/java/utils/SinaStockHandler.java @@ -22,9 +22,7 @@ public class SinaStockHandler extends StockRefreshHandler { private static final Pattern DEFAULT_STOCK_PATTERN = Pattern.compile("var hq_str_(\\w+?)=\"(.*?)\";"); private final JLabel refreshTimeLabel; - private static final ScheduledExecutorService mSchedulerExecutor = Executors.newSingleThreadScheduledExecutor(); - private volatile boolean working = true; - private volatile boolean started = false; + private static ScheduledExecutorService mSchedulerExecutor = Executors.newSingleThreadScheduledExecutor(); public SinaStockHandler(JTable table, JLabel label) { super(table); @@ -41,21 +39,15 @@ public void handle(List code) { } public void useScheduleThreadExecutor(List code) { - if (!started) { - mSchedulerExecutor.scheduleAtFixedRate(getWork(code), 0, 1, TimeUnit.SECONDS); - started = true; - LogUtil.info("stock 定时线程池 init success"); + if (mSchedulerExecutor.isShutdown()){ + mSchedulerExecutor = Executors.newSingleThreadScheduledExecutor(); } - working = true; - System.out.println("working = " + working); - LogUtil.info("stock 定时线程池 start success"); + mSchedulerExecutor.scheduleAtFixedRate(getWork(code), 0, threadSleepTime, TimeUnit.SECONDS); } private Runnable getWork(List code) { return () -> { - if (working) { - pollStock(code); - } + pollStock(code); }; } @@ -63,8 +55,8 @@ private void pollStock(List code) { String params = Joiner.on(",").join(code); try { String res = HttpClientPool.getHttpClient().get(URL + params); - String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss,SSS")); - System.out.printf("%s,%s%n", time, res); +// String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss,SSS")); +// System.out.printf("%s,%s%n", time, res); handleResponse(res); } catch (Exception e) { LogUtil.info(e.getMessage()); @@ -80,7 +72,7 @@ public void handleResponse(String response) { } String code = matcher.group(1); String[] split = matcher.group(2).split(","); - if (split == null || split.length < 32) { + if (split.length < 32) { continue; } StockBean bean = new StockBean(code); @@ -109,7 +101,7 @@ public void handleResponse(String response) { @Override public void stopHandle() { - working = false; + mSchedulerExecutor.shutdown(); LogUtil.info("leeks stock 自动刷新关闭!"); } } diff --git a/src/main/java/utils/StockRefreshHandler.java b/src/main/java/utils/StockRefreshHandler.java index b6254d9..f3ae1df 100644 --- a/src/main/java/utils/StockRefreshHandler.java +++ b/src/main/java/utils/StockRefreshHandler.java @@ -19,6 +19,11 @@ public abstract class StockRefreshHandler extends DefaultTableModel { private JTable table; private boolean colorful = true; + /** + * 更新数据的间隔时间(秒) + */ + protected volatile int threadSleepTime = 10; + public StockRefreshHandler(JTable table) { this.table = table; table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); @@ -213,4 +218,12 @@ private Vector convertData(StockBean fundBean) { public boolean isCellEditable(int row, int column) { return false; } + + public int getThreadSleepTime() { + return threadSleepTime; + } + + public void setThreadSleepTime(int threadSleepTime) { + this.threadSleepTime = threadSleepTime; + } } diff --git a/src/main/java/utils/TencentStockHandler.java b/src/main/java/utils/TencentStockHandler.java index fd4fe82..624c921 100644 --- a/src/main/java/utils/TencentStockHandler.java +++ b/src/main/java/utils/TencentStockHandler.java @@ -12,10 +12,7 @@ public class TencentStockHandler extends StockRefreshHandler { private Thread worker; private JLabel refreshTimeLabel; - /** - * 更新数据的间隔时间(秒) - */ - private volatile int threadSleepTime = 10; + public TencentStockHandler(JTable table1, JLabel refreshTimeLabel) { super(table1); @@ -111,11 +108,5 @@ public void run() { }); } - public int getThreadSleepTime() { - return threadSleepTime; - } - public void setThreadSleepTime(int threadSleepTime) { - this.threadSleepTime = threadSleepTime; - } }