diff --git a/src/main/java/featurecat/lizzie/Config.java b/src/main/java/featurecat/lizzie/Config.java index be35f4043..677c113f7 100644 --- a/src/main/java/featurecat/lizzie/Config.java +++ b/src/main/java/featurecat/lizzie/Config.java @@ -195,7 +195,7 @@ public Config() throws IOException { uiConfig = config.getJSONObject("ui"); persistedUi = persisted.getJSONObject("ui-persist"); - theme = new Theme(uiConfig); + applyTheme(); panelUI = uiConfig.optBoolean("panel-ui", false); showBorder = uiConfig.optBoolean("show-border", false); @@ -231,9 +231,6 @@ public Config() throws IOException { limitBranchLength = uiConfig.optInt("limit-branch-length", 0); minPlayoutRatioForStats = uiConfig.optDouble("min-playout-ratio-for-stats", 0.1); - winrateStrokeWidth = theme.winrateStrokeWidth(); - minimumBlunderBarWidth = theme.minimumBlunderBarWidth(); - shadowSize = theme.shadowSize(); showLcbWinrate = config.getJSONObject("leelaz").optBoolean("show-lcb-winrate"); showKataGoScoreMean = uiConfig.optBoolean("show-katago-scoremean", true); @@ -253,6 +250,18 @@ public Config() throws IOException { toolbarPosition = uiConfig.optString("toolbar-position", persistedUi.optString("toolbar-position", "South")); + gtpConsoleStyle = uiConfig.optString("gtp-console-style", defaultGtpConsoleStyle); + + System.out.println(Locale.getDefault().getLanguage()); // todo add config option for language... + setLanguage(Locale.getDefault().getLanguage()); + } + + public void applyTheme() { + theme = new Theme(uiConfig); + winrateStrokeWidth = theme.winrateStrokeWidth(); + minimumBlunderBarWidth = theme.minimumBlunderBarWidth(); + shadowSize = theme.shadowSize(); + if (theme.fontName() != null) fontName = theme.fontName(); if (theme.uiFontName() != null) uiFontName = theme.uiFontName(); @@ -272,11 +281,6 @@ public Config() throws IOException { blunderWinrateThresholds = theme.blunderWinrateThresholds(); blunderNodeColors = theme.blunderNodeColors(); nodeColorMode = theme.nodeColorMode(); - - gtpConsoleStyle = uiConfig.optString("gtp-console-style", defaultGtpConsoleStyle); - - System.out.println(Locale.getDefault().getLanguage()); // todo add config option for language... - setLanguage(Locale.getDefault().getLanguage()); } // Modifies config by adding in values from default_config that are missing. diff --git a/src/main/java/featurecat/lizzie/gui/BoardPane.java b/src/main/java/featurecat/lizzie/gui/BoardPane.java index 4abd47f85..5a65d0181 100644 --- a/src/main/java/featurecat/lizzie/gui/BoardPane.java +++ b/src/main/java/featurecat/lizzie/gui/BoardPane.java @@ -593,6 +593,10 @@ public void drawEstimateRect(ArrayList estimateArray, boolean isZen) { boardRenderer.drawEstimateRect(estimateArray, isZen); } + public void resetImages() { + boardRenderer.resetImages(); + } + public void saveImage() { JSONObject filesystem = Lizzie.config.persisted.getJSONObject("filesystem"); JFileChooser chooser = new JFileChooser(filesystem.getString("last-folder")); diff --git a/src/main/java/featurecat/lizzie/gui/BoardRenderer.java b/src/main/java/featurecat/lizzie/gui/BoardRenderer.java index 76351c04d..e5d6b27d2 100644 --- a/src/main/java/featurecat/lizzie/gui/BoardRenderer.java +++ b/src/main/java/featurecat/lizzie/gui/BoardRenderer.java @@ -1352,6 +1352,18 @@ public BufferedImage getWallpaper() { return cachedWallpaperImage; } + public void resetImages() { + cachedBackgroundImage = emptyImage; + cachedStonesImage = emptyImage; + cachedBoardImage = emptyImage; + cachedWallpaperImage = emptyImage; + cachedStonesShadowImage = emptyImage; + cachedBlackStoneImage = emptyImage; + cachedWhiteStoneImage = emptyImage; + cachedEstimateLargeRectImage = emptyImage; + cachedEstimateSmallRectImage = emptyImage; + } + /** * Draw scale smooth image, enhanced display quality (Not use, for future) This function use the * traditional Image.getScaledInstance() method to provide the nice quality, but the performance diff --git a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java index a0d50074e..8b1500792 100644 --- a/src/main/java/featurecat/lizzie/gui/ConfigDialog.java +++ b/src/main/java/featurecat/lizzie/gui/ConfigDialog.java @@ -41,13 +41,12 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.ResourceBundle; -import java.util.Timer; -import java.util.TimerTask; import java.util.Vector; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -235,6 +234,7 @@ public ConfigDialog() { okButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { + finalizeEditedBlunderColors(); setVisible(false); saveConfig(); applyChange(); @@ -1541,7 +1541,7 @@ protected DocumentFilter getDocumentFilter() { btnAdd.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { - ((BlunderNodeTableModel) tblBlunderNodes.getModel()).addRow("", Color.WHITE); + ((BlunderNodeTableModel) tblBlunderNodes.getModel()).addRow(null, Color.WHITE); } }); themeTab.add(btnAdd); @@ -1815,7 +1815,7 @@ protected void paintComponent(Graphics g) { @Override protected void done() { okButton.setEnabled(true); - pnlBoardPreview.repaint(); + tabbedPane.repaint(); } } @@ -1925,6 +1925,7 @@ private void read() { } private void applyChange() { + Lizzie.config.applyTheme(); int[] size = getBoardSize(); Lizzie.board.reopen(size[0], size[1]); if (Lizzie.engineManager == null) { @@ -1937,6 +1938,9 @@ private void applyChange() { } catch (IOException e) { e.printStackTrace(); } + Lizzie.frame.resetImages(); + Lizzie.frame.refreshBackground(); + Lizzie.frame.refresh(); } private Integer txtFieldIntValue(JTextField txt) { @@ -2088,7 +2092,7 @@ public BlunderNodeTableModel( if (blunderWinrateThresholds != null) { for (Double d : blunderWinrateThresholds) { Vector row = new Vector(); - row.add(String.valueOf(d)); + row.add(d); row.add(blunderNodeColors.get(d)); data.add(row); } @@ -2097,7 +2101,7 @@ public BlunderNodeTableModel( public JSONArray getThresholdArray() { JSONArray thresholds = new JSONArray("[]"); - data.forEach(d -> thresholds.put(new Double((String) d.get(0)))); + data.forEach(d -> thresholds.put(toDouble(d.get(0)))); return thresholds; } @@ -2107,7 +2111,7 @@ public JSONArray getColorArray() { return colors; } - public void addRow(String threshold, Color color) { + public void addRow(Double threshold, Color color) { Vector row = new Vector(); row.add(threshold); row.add(color); @@ -2118,7 +2122,7 @@ public void addRow(String threshold, Color color) { public void removeRow(int index) { if (index >= 0 && index < data.size()) { data.remove(index); - fireTableRowsDeleted(0, data.size() - 1); + fireTableRowsDeleted(index, index); } } @@ -2139,7 +2143,7 @@ public Object getValueAt(int row, int col) { } public Class getColumnClass(int c) { - return getValueAt(0, c).getClass(); + return c == 0 ? Double.class : Color.class; } public void setValueAt(Object value, int row, int col) { @@ -2150,6 +2154,24 @@ public void setValueAt(Object value, int row, int col) { public boolean isCellEditable(int row, int col) { return true; } + + private double toDouble(Object x) { + final double invalid = 0.0; + try { + return (Double) x; + } catch (Exception e) { + return invalid; + } + } + + public void sortData() { + data.sort( + new Comparator>() { + public int compare(Vector a, Vector b) { + return Double.compare(toDouble(a.get(0)), toDouble(b.get(0))); + } + }); + } } public boolean isWindows() { @@ -2477,6 +2499,14 @@ private void writeDefaultTheme() { ((BlunderNodeTableModel) tblBlunderNodes.getModel()).getColorArray()); } + private void finalizeEditedBlunderColors() { + if (tblBlunderNodes == null) return; + TableCellEditor editor = tblBlunderNodes.getCellEditor(); + BlunderNodeTableModel model = (BlunderNodeTableModel) tblBlunderNodes.getModel(); + if (editor != null) editor.stopCellEditing(); + if (model != null) model.sortData(); + } + private void saveConfig() { try { leelazConfig.putOpt("max-analyze-time-minutes", txtFieldIntValue(txtMaxAnalyzeTime)); @@ -2571,16 +2601,5 @@ private void saveConfig() { public void switchTab(int index) { tabbedPane.setSelectedIndex(index); - if (index == 2) { - Timer timer = new Timer(); - timer.schedule( - new TimerTask() { - public void run() { - tabbedPane.repaint(); - this.cancel(); - } - }, - 100); - } } } diff --git a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java index 434828245..c2689e8c4 100644 --- a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java +++ b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java @@ -699,6 +699,11 @@ public void refreshBackground() { redrawBackgroundAnyway = true; } + public void resetImages() { + boardRenderer.resetImages(); + subBoardRenderer.resetImages(); + } + private Graphics2D createBackground(int width, int hight) { cachedBackground = new BufferedImage(width, hight, TYPE_INT_RGB); cachedBackgroundWidth = cachedBackground.getWidth(); diff --git a/src/main/java/featurecat/lizzie/gui/LizzieMain.java b/src/main/java/featurecat/lizzie/gui/LizzieMain.java index 5c03a9e44..b7cb9fe0d 100644 --- a/src/main/java/featurecat/lizzie/gui/LizzieMain.java +++ b/src/main/java/featurecat/lizzie/gui/LizzieMain.java @@ -318,6 +318,15 @@ public void refreshBackground() { redrawBackgroundAnyway = true; } + public void resetImages() { + cachedBasicInfoContainer = emptyImage; + cachedWinrateContainer = emptyImage; + cachedVariationContainer = emptyImage; + cachedWallpaperImage = emptyImage; + boardPane.resetImages(); + subBoardPane.resetImages(); + } + public BufferedImage getWallpaper() { if (cachedWallpaperImage == emptyImage) { cachedWallpaperImage = Lizzie.config.theme.background(); diff --git a/src/main/java/featurecat/lizzie/gui/MainFrame.java b/src/main/java/featurecat/lizzie/gui/MainFrame.java index d3074ef09..2faf067d1 100644 --- a/src/main/java/featurecat/lizzie/gui/MainFrame.java +++ b/src/main/java/featurecat/lizzie/gui/MainFrame.java @@ -125,6 +125,8 @@ public boolean processCommentMouseWheelMoved(MouseWheelEvent e) { public abstract void refreshBackground(); + public abstract void resetImages(); + public abstract void clear(); public abstract boolean isMouseOver(int x, int y); diff --git a/src/main/java/featurecat/lizzie/gui/SubBoardPane.java b/src/main/java/featurecat/lizzie/gui/SubBoardPane.java index 2e550fb56..f879b1a8c 100644 --- a/src/main/java/featurecat/lizzie/gui/SubBoardPane.java +++ b/src/main/java/featurecat/lizzie/gui/SubBoardPane.java @@ -138,6 +138,10 @@ protected void paintComponent(Graphics g0) { // bs.show(); } + public void resetImages() { + subBoardRenderer.resetImages(); + } + /** * Checks whether or not something was clicked and performs the appropriate action * diff --git a/src/main/java/featurecat/lizzie/util/Utils.java b/src/main/java/featurecat/lizzie/util/Utils.java index 4dde476d2..24d653208 100644 --- a/src/main/java/featurecat/lizzie/util/Utils.java +++ b/src/main/java/featurecat/lizzie/util/Utils.java @@ -153,9 +153,9 @@ public static Color getBlunderNodeColor(BoardHistoryNode node) { Optional st = diffWinrate >= 0 ? Lizzie.config.blunderWinrateThresholds.flatMap( - l -> l.stream().filter(t -> (t > 0 && t <= diffWinrate)).reduce((f, s) -> s)) + l -> l.stream().filter(t -> (t >= 0 && t <= diffWinrate)).reduce((f, s) -> s)) : Lizzie.config.blunderWinrateThresholds.flatMap( - l -> l.stream().filter(t -> (t < 0 && t >= diffWinrate)).reduce((f, s) -> f)); + l -> l.stream().filter(t -> (t <= 0 && t >= diffWinrate)).reduce((f, s) -> f)); if (st.isPresent()) { return Lizzie.config.blunderNodeColors.map(m -> m.get(st.get())).get(); } else {