From 5d08968a8aab426fcf51c29c80e2a4e507e10324 Mon Sep 17 00:00:00 2001 From: Sylvain Vedrenne Date: Thu, 2 Feb 2012 21:53:42 +0100 Subject: [PATCH] Fixed #3482839 Exit Custom Grid Mode in case New/Open grid is selected Fixed #3482838 Actions to deactivate when in normal "custom grid" mode Fixed #3482837 Deactivate "play grid" if custom grid is invalid Fixed #3482836 Select-memos dialog should not always clear the cell value --- README | 5 + .../sudokuki/controller/GridController.java | 6 + .../net/jankenpoi/sudokuki/model/GridModel.java | 15 +- .../jankenpoi/sudokuki/ui/swing/AboutDialog.java | 79 +-- .../net/jankenpoi/sudokuki/ui/swing/CheatMenu.java | 192 +++--- .../sudokuki/ui/swing/CheckUpdateDialog.java | 423 ++++++------- .../sudokuki/ui/swing/DualSelectionDialog.java | 19 +- .../jankenpoi/sudokuki/ui/swing/ResolveAction.java | 5 +- .../sudokuki/ui/swing/SelectMemosPanel.java | 693 ++++++++++----------- .../net/jankenpoi/sudokuki/ui/swing/SwingView.java | 27 +- .../sudokuki/ui/swing/TranslateDialog.java | 265 ++++---- 11 files changed, 890 insertions(+), 839 deletions(-) diff --git a/README b/README index 02d4a7b..98c1d64 100644 --- a/README +++ b/README @@ -3,6 +3,11 @@ Sudokuki - essential sudoku game -- Changelog -- * 2012- +- Fixed #3482839 Exit Custom Grid Mode in case New/Open grid is selected +- Fixed #3482838 Actions to deactivate when in normal "custom grid" mode +- Fixed #3482837 Deactivate "play grid" if custom grid is invalid +- Fixed #3482836 Select-memos dialog should not always clear the cell value +- I18n the language dialog. Static language names (German => Deutsch). - Fixed #3476292 TODO: Application logo for final release - Fixed #3411638 Check the POEdit icon for "translate this app" icon diff --git a/src/classes/net/jankenpoi/sudokuki/controller/GridController.java b/src/classes/net/jankenpoi/sudokuki/controller/GridController.java index 0b64f56..5b87db7 100644 --- a/src/classes/net/jankenpoi/sudokuki/controller/GridController.java +++ b/src/classes/net/jankenpoi/sudokuki/controller/GridController.java @@ -94,11 +94,17 @@ public class GridController { } public void notifyNewGridRequested() { + if (model.getCustomGridMode()) { + model.exitCustomGridMode(); + } model.requestNewGrid(); model.fireGridChanged(new GridChangedEvent(model, 0, 0, (short)0)); } public void notifyResetGridFromShorts(short[] externalCellInfos) { + if (model.getCustomGridMode()) { + model.exitCustomGridMode(); + } model.resetGridModelFromShorts(externalCellInfos); model.fireGridChanged(new GridChangedEvent(model, 0, 0, (short)0)); } diff --git a/src/classes/net/jankenpoi/sudokuki/model/GridModel.java b/src/classes/net/jankenpoi/sudokuki/model/GridModel.java index 51b548a..f93a30d 100644 --- a/src/classes/net/jankenpoi/sudokuki/model/GridModel.java +++ b/src/classes/net/jankenpoi/sudokuki/model/GridModel.java @@ -476,7 +476,7 @@ public class GridModel implements Cloneable { private Integer firstErrorSquareX = null; private Integer firstErrorSquareY = null; - public GridValidity(boolean isValid, Integer lineWithError, Integer columnWithError, + private GridValidity(boolean isValid, Integer lineWithError, Integer columnWithError, Integer squareWithErrorX, Integer squareWithErrorY) { this.isValid = isValid; this.firstErrorLine = lineWithError; @@ -485,6 +485,17 @@ public class GridModel implements Cloneable { this.firstErrorSquareY = squareWithErrorY; } + private static GridValidity valueOf(boolean isValid, Integer lineWithError, Integer columnWithError, + Integer squareWithErrorX, Integer squareWithErrorY) { + if (isValid) { + return VALID; + } else { + return new GridValidity(isValid, lineWithError, columnWithError, + squareWithErrorX, squareWithErrorY); + } + + } + public boolean isGridValid() { return isValid; } @@ -563,7 +574,7 @@ public class GridModel implements Cloneable { } } } - return new GridValidity(isValid, lineWithError, columnWithError, + return GridValidity.valueOf(isValid, lineWithError, columnWithError, squareWithErrorX, squareWithErrorY); } diff --git a/src/classes/net/jankenpoi/sudokuki/ui/swing/AboutDialog.java b/src/classes/net/jankenpoi/sudokuki/ui/swing/AboutDialog.java index 3c86e7d..81ad7b3 100644 --- a/src/classes/net/jankenpoi/sudokuki/ui/swing/AboutDialog.java +++ b/src/classes/net/jankenpoi/sudokuki/ui/swing/AboutDialog.java @@ -53,11 +53,18 @@ public class AboutDialog extends JDialog { private Frame parent; + private final String ABOUT_SUDOKUKI = _("About Sudokuki..."); + private final String INFORMATION = _("Information"); + private final String CONTRIBUTORS = _("Contributors"); + private final String FEEDBACK = _("Feedback"); + private final String TRANSFER = _("Transfer"); + private final String LICENSE = _("License"); + public AboutDialog(Frame parent) { super(parent, true); this.parent = parent; initComponents(); - setTitle("About Sudokuki..."); + setTitle(ABOUT_SUDOKUKI); pack(); } @@ -77,8 +84,8 @@ public class AboutDialog extends JDialog { } JTabbedPane tabbedPane = new JTabbedPane(); - tabbedPane.addTab("Information", null, makeInfoPanel(sudokukiURI), - "Information"); + tabbedPane.addTab(INFORMATION, null, makeInfoPanel(sudokukiURI), + INFORMATION); String license_html = null; try { @@ -87,64 +94,63 @@ public class AboutDialog extends JDialog { } tabbedPane - .addTab("Contributors", + .addTab(CONTRIBUTORS, null, makeTextPanel(// " name_of_contributor | translation <= each line (aligned on '|')" "" + "" + "" - + "" + + "" + "" - + "" + + "" + "" + "" - + "" + + "" + "" - + "" + + "" + "" + "" - + "" + + "" + "" - + "" + + "" + "" + "" - + "" + + "" + "" - + "" + + "" + "" + "" - + "" + + "" + "" - + "" + + "" + "" + "" - + "" + + "" + "" - + "" + + "" + "" + "" - + "" + + "" + "" - + "" + + "" + "" + "
Aritz Beraza"+_("Aritz Beraza")+" Spanish translations (v1.0)"+_("Spanish translations (v1.0)")+"
Hélène Damianakos"+_("Helene Damianakos")+" Greek translations (v1.0)"+_("Greek translations (v1.0)")+"
Jeanne Peng"+_("Jeanne Peng")+" Chinese translations"+_("Chinese translations")+"
Claus Poerschke"+_("Claus Poerschke")+" Patches (v1.0) and German translations"+_("Patches (v1.0) and German translations")+"
Dmitry Salnikov"+_("Dmitry Salnikov")+" Portuguese and Russian translations"+_("Portuguese and Russian translations")+"
Hélène Vedrenne"+_("Helene Vedrenne")+" Japanese translations (v1.0)"+_("Japanese translations (v1.0)")+"
Sylvain Vedrenne"+_("Sylvain Vedrenne")+" Esperanto, French and Japanese translations"+_("Esperanto, French and Japanese translations")+"
" - + ""), "Contributors"); + + ""), CONTRIBUTORS); - tabbedPane.addTab("Feedback", null, makeFeedbackPanel(forumURI), - "Feedback"); + tabbedPane.addTab(FEEDBACK, null, makeFeedbackPanel(forumURI), + FEEDBACK); tabbedPane - .addTab("Transfer", + .addTab(TRANSFER, null, makeTextPanel("" + "" + "" + ""+ "" + "" + ""+ "" @@ -153,8 +159,7 @@ public class AboutDialog extends JDialog { + ""+ "" + "" + ""+ "" @@ -163,9 +168,7 @@ public class AboutDialog extends JDialog { + ""+ "" + "" + ""+ "" @@ -173,9 +176,7 @@ public class AboutDialog extends JDialog { + ""+ "" + "" + ""+ "" @@ -186,18 +187,18 @@ public class AboutDialog extends JDialog { + ""+ "" + "" + "" + "
" + "

" - + "Sudokuki is released under the terms of the GNU General Public " - + "License version 3 or later (GPL v3+).
" + + _("Sudokuki is released under the terms of the GNU General Public License version 3 or later (GPL v3+).")+"
" + "

" + "
" + "

" - + "The full license text is available in the file called COPYING that " - + "must be included in every copy of the program.
" + + _("The full license text is available in the file called COPYING that must be included in every copy of the program.")+"
" + "

" + "
" + "

" - + "This program is Free Software (\"Free\" as in \"Freedom\") developped " - + "during the author's free-time in the hope that some users will find it " - + "useful, but WITHOUT ANY WARRANTY of any kind.
" + + _("This program is Free Software (\"Free\" as in \"Freedom\") developped during the author's free-time in the hope that some users will find it useful, but WITHOUT ANY WARRANTY of any kind.")+"
" + "

" + "
" + "

" - + "You are welcome to transfer this program to other people as long as " - + "you respect the license terms. Read the GNU General Public License " - + "for more details.
" + + _("You are welcome to transfer this program to other people as long as you respect the license terms. Read the GNU General Public License for more details.")+"
" + "

" + "
" + "

" - + "Copyright (C) 2007-2012 Sylvain Vedrenne
" + + _("Copyright (C) 2007-2012 Sylvain Vedrenne") + "
" + "

" + "
" + "
"), - "Transfer"); // tooltip text + TRANSFER); // tooltip text JEditorPane editPane = new JEditorPane("text/html", license_html); editPane.setEditable(false); editPane.setBackground(Color.WHITE); editPane.setCaretPosition(0); JScrollPane scrollPane = new JScrollPane(editPane); - tabbedPane.addTab("License", null, scrollPane, "License"); + tabbedPane.addTab(LICENSE, null, scrollPane, LICENSE); Dimension parentDim = parent.getPreferredSize(); Dimension dim = new Dimension(); @@ -238,7 +239,8 @@ public class AboutDialog extends JDialog { + "" + "" + "" - + "Copyright 2007-2012 Sylvain Vedrenne" + + "" + + _("Copyright (C) 2007-2012 Sylvain Vedrenne") + "" + "" + "" + ""; JLabel label = new JLabel(feedbackStr); feedbackPanel.add(label); @@ -272,8 +274,9 @@ public class AboutDialog extends JDialog { JPanel panel = new JPanel(false); String feedbackStr = "" + "" + "" + "" + "" + "" + "" - + ""+ ""+""+"" + + ""+ ""+"" + +"" + "" + "" + "" + "
Feel free to request features and report bugs " - + "on the Sudokuki Forums hosted by Sourceforge! " + + ("Feel free to request features and report bugs on the Sudokuki Forums hosted by Sourceforge!")+"
" + ""; JLabel label = new JLabel(feedbackStr); label.setHorizontalAlignment(JLabel.CENTER); diff --git a/src/classes/net/jankenpoi/sudokuki/ui/swing/CheatMenu.java b/src/classes/net/jankenpoi/sudokuki/ui/swing/CheatMenu.java index 4d78621..9213457 100644 --- a/src/classes/net/jankenpoi/sudokuki/ui/swing/CheatMenu.java +++ b/src/classes/net/jankenpoi/sudokuki/ui/swing/CheatMenu.java @@ -1,97 +1,97 @@ -/* - * Sudokuki - essential sudoku game - * Copyright (C) 2007-2012 Sylvain Vedrenne - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.jankenpoi.sudokuki.ui.swing; - -import static net.jankenpoi.i18n.I18n._; - -import java.awt.event.KeyEvent; -import java.util.Locale; - -import javax.swing.Action; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuItem; - -import net.jankenpoi.i18n.I18n; -import net.jankenpoi.i18n.LocaleListener; -import net.jankenpoi.sudokuki.ui.L10nComponent; -import net.jankenpoi.sudokuki.view.GridView; - -@SuppressWarnings("serial") -public class CheatMenu extends JMenu implements L10nComponent { - - private final LocaleListener localeListener; - @Override - public void setL10nMessages(Locale locale, String languageCode) { - setText(_("Solution...")); - setIcon(StockIcons.ICON_SOLUTION_MENU); - - itemSetMemosHere.setText(_("Memos")); - actionSetMemosHere.putValue(Action.SHORT_DESCRIPTION, _("Set memos")); - itemSetAllMemos.setText(_("All memos")); - actionSetAllMemos.putValue(Action.SHORT_DESCRIPTION, _("Set memos in all cells")); - - itemResolve.setText(_("Resolve")); - actionResolve.putValue(Action.SMALL_ICON, StockIcons.ICON_GO_JUMP); - actionResolve.putValue(Action.SHORT_DESCRIPTION, _("Resolve the grid")); - actionResolve.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_R)); - } - - private final JMenuItem itemSetMemosHere = new JMenuItem(); - private final JMenuItem itemSetAllMemos = new JMenuItem(); - private final JMenuItem itemResolve = new JMenuItem(); - private final Action actionSetMemosHere; - private final Action actionSetAllMemos; - private final Action actionResolve; - - public CheatMenu(ActionsRepository actions, JFrame parent, GridView view) { - actionSetMemosHere = new SetMemosHereAction(parent, "Set memos here", - StockIcons.ICON_SET_MEMOS_HERE, "Set memos in current cell", new Integer( - KeyEvent.VK_T), view); - actions.put("SetMemosHere", actionSetMemosHere); - - actionSetAllMemos = new SetAllMemosAction(parent, "Set all memos", - StockIcons.ICON_SET_ALL_MEMOS, "Set memos in all cells of the grid", new Integer( - KeyEvent.VK_X), view); - actions.put("SetAllMemos", actionSetAllMemos); - - actionResolve = new ResolveAction(parent, _("Resolve"), - StockIcons.ICON_GO_JUMP, _("Resolve the grid"), new Integer( - KeyEvent.VK_R), view); - actions.put("ResolveGrid", actionResolve); - - addItems(); - setEnabled(true); - setL10nMessages(null, null); - localeListener = new LocaleListenerImpl(this); - I18n.addLocaleListener(localeListener); - } - - private void addItems() { - itemSetMemosHere.setAction(actionSetMemosHere); - add(itemSetMemosHere); - - itemSetAllMemos.setAction(actionSetAllMemos); - add(itemSetAllMemos); - - addSeparator(); - - itemResolve.setAction(actionResolve); - add(itemResolve); - } +/* + * Sudokuki - essential sudoku game + * Copyright (C) 2007-2012 Sylvain Vedrenne + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.jankenpoi.sudokuki.ui.swing; + +import static net.jankenpoi.i18n.I18n._; + +import java.awt.event.KeyEvent; +import java.util.Locale; + +import javax.swing.Action; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuItem; + +import net.jankenpoi.i18n.I18n; +import net.jankenpoi.i18n.LocaleListener; +import net.jankenpoi.sudokuki.ui.L10nComponent; +import net.jankenpoi.sudokuki.view.GridView; + +@SuppressWarnings("serial") +public class CheatMenu extends JMenu implements L10nComponent { + + private final LocaleListener localeListener; + @Override + public void setL10nMessages(Locale locale, String languageCode) { + setText(_("Solution...")); + setIcon(StockIcons.ICON_SOLUTION_MENU); + + itemSetMemosHere.setText(_("Memos")); + actionSetMemosHere.putValue(Action.SHORT_DESCRIPTION, _("Set memos")); + itemSetAllMemos.setText(_("All memos")); + actionSetAllMemos.putValue(Action.SHORT_DESCRIPTION, _("Set memos in all cells")); + + itemResolve.setText(_("Resolve")); + actionResolve.putValue(Action.SMALL_ICON, StockIcons.ICON_GO_JUMP); + actionResolve.putValue(Action.SHORT_DESCRIPTION, _("Resolve the grid")); + actionResolve.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_R)); + } + + private final JMenuItem itemSetMemosHere = new JMenuItem(); + private final JMenuItem itemSetAllMemos = new JMenuItem(); + private final JMenuItem itemResolve = new JMenuItem(); + private final Action actionSetMemosHere; + private final Action actionSetAllMemos; + private final Action actionResolve; + + public CheatMenu(ActionsRepository actions, JFrame parent, GridView view) { + actionSetMemosHere = new SetMemosHereAction(parent, _("Memos"), + StockIcons.ICON_SET_MEMOS_HERE, _("Set memos"), new Integer( + KeyEvent.VK_T), view); + actions.put("SetMemosHere", actionSetMemosHere); + + actionSetAllMemos = new SetAllMemosAction(parent, _("All memos"), + StockIcons.ICON_SET_ALL_MEMOS, _("Set memos in all cells"), new Integer( + KeyEvent.VK_X), view); + actions.put("SetAllMemos", actionSetAllMemos); + + actionResolve = new ResolveAction(parent, _("Resolve"), + StockIcons.ICON_GO_JUMP, _("Resolve the grid"), new Integer( + KeyEvent.VK_R), view); + actions.put("ResolveGrid", actionResolve); + + addItems(); + setEnabled(true); + setL10nMessages(null, null); + localeListener = new LocaleListenerImpl(this); + I18n.addLocaleListener(localeListener); + } + + private void addItems() { + itemSetMemosHere.setAction(actionSetMemosHere); + add(itemSetMemosHere); + + itemSetAllMemos.setAction(actionSetAllMemos); + add(itemSetAllMemos); + + addSeparator(); + + itemResolve.setAction(actionResolve); + add(itemResolve); + } } \ No newline at end of file diff --git a/src/classes/net/jankenpoi/sudokuki/ui/swing/CheckUpdateDialog.java b/src/classes/net/jankenpoi/sudokuki/ui/swing/CheckUpdateDialog.java index 0064840..805ab42 100644 --- a/src/classes/net/jankenpoi/sudokuki/ui/swing/CheckUpdateDialog.java +++ b/src/classes/net/jankenpoi/sudokuki/ui/swing/CheckUpdateDialog.java @@ -1,210 +1,215 @@ -/* - * Sudokuki - essential sudoku game - * Copyright (C) 2007-2012 Sylvain Vedrenne - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.jankenpoi.sudokuki.ui.swing; - -import java.awt.Container; -import java.awt.GridLayout; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; - -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.SwingWorker; - -import net.jankenpoi.sudokuki.Version; - -/** - * CheckUpdateDialog.java - * - * @author svedrenne - */ -@SuppressWarnings("serial") -public class CheckUpdateDialog extends JDialog { - - private JFrame parent; - - final CheckUpdateAction checkUpdateAction; - - int result = -1; - - private final SwingWorker worker = new SwingWorker() { - - @Override - protected String doInBackground() throws Exception { - /* Executed in a background thread */ - final String str = getHttpLatestVersionString(); - - return str; - } - - @Override - protected void done() { - /* Executed in the EDT */ - try { - String httpVersionString = get(); - - System.out - .println("SwingApp.getHttpLatestVersionString() (embedded) Version.versionString:" - + Version.versionString); - System.out - .println("SwingApp.getHttpLatestVersionString() retrieved versionString:" - + httpVersionString); - - if (httpVersionString.equals(Version.versionString)) { - System.out - .println("SwingApp.getHttpLatestVersionString() This version is up-to-date"); - result = 0; - } else if (httpVersionString.startsWith("Sudokuki")) { - System.out - .println("SwingApp.getHttpLatestVersionString() This version is outdated. Please download the latest version from Sourceforge."); - checkUpdateAction.notifyNewVersionFound(); - result = 1; - } else { - result = -1; - } - } catch (InterruptedException e) { - System.out - .println("CheckUpdateDialog.worker.new SwingWorker() {...}.done() Interrupted !!!!"); - } catch (ExecutionException e) { - System.out - .println("CheckUpdateDialog.worker.new SwingWorker() {...}.done() ExecutionException !!!!"); - } catch (CancellationException e) { - System.out - .println("CheckUpdateDialog.worker.new SwingWorker() {...}.done() CancellationException !!!!"); - } - CheckUpdateDialog.this.dispose(); - } - - private String getHttpLatestVersionString() { - String line = null; - BufferedReader dis = null; - try { - URL url; - URLConnection urlConn; - - url = new URL( - "http://sourceforge.net/projects/sudokuki/files/sudokuki/1.1/Beta/LATEST/download"); - - // Note: a more portable URL: - // url = new URL(getCodeBase().toString() + - // "/ToDoList/ToDoList.txt"); - - urlConn = url.openConnection(); - urlConn.setDoInput(true); - urlConn.setUseCaches(false); - - // BufferedReader d - // = new BufferedReader(new InputStreamReader(in)); - - dis = new BufferedReader(new InputStreamReader( - urlConn.getInputStream())); - - line = dis.readLine(); - } catch (MalformedURLException mue) { - mue.printStackTrace(); - } catch (IOException ioe) { - ioe.printStackTrace(); - } finally { - try { - dis.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - System.out.println("getHttpLatestVersionString() line:" + line); - String versionString = ""; - if (line != null) { - // line.startsWith("Sudokuki "); - // line.endsWith(") is the latest version."); - String[] strs = line.split(" is the latest version."); - if (strs.length >= 1) { - versionString = strs[0]; - } - } - return versionString; - } - }; - - public CheckUpdateDialog(JFrame parent, - final CheckUpdateAction checkUpdateAction) { - super(parent, true); - this.checkUpdateAction = checkUpdateAction; - this.parent = parent; - initComponents(); - setResizable(false); - worker.execute(); - } - - private void initComponents() { - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - - Container pane = getContentPane(); - GridLayout btnLayout = new GridLayout(4, 1); - pane.setLayout(btnLayout); - - JLabel messageLbl1 = new JLabel("" + "" - + "" + "" + ""); - JLabel messageLbl2 = new JLabel("" + "
" - + "Checking for available updates.
" - + "" + "" - + ""); - JLabel messageLbl3 = new JLabel(""); - JButton cancelBtn = new JButton("Cancel"); - cancelBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - cancelBtn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - cancelButtonClicked(); - } - }); - - pane.add(messageLbl1); - pane.add(messageLbl2); - pane.add(messageLbl3); - pane.add(cancelBtn); - - pack(); - setLocationRelativeTo(parent); - } - - private void cancelButtonClicked() { - System.out.println("CheckUpdateDialog.cancelButtonClicked()"); - boolean cancelled = worker.cancel(true); - System.out.println("CheckUpdateDialog.cancelButtonClicked() cancelled:" - + cancelled); - } - - public int getResult() { - System.out.println("CheckUpdateDialog.getResult() Thread:" - + Thread.currentThread().getName()); - - System.out.println("result: " + result); - return result; - } - +/* + * Sudokuki - essential sudoku game + * Copyright (C) 2007-2012 Sylvain Vedrenne + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.jankenpoi.sudokuki.ui.swing; + +import static net.jankenpoi.i18n.I18n._; + +import java.awt.Container; +import java.awt.GridLayout; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.SwingWorker; + +import net.jankenpoi.sudokuki.Version; + +/** + * CheckUpdateDialog.java + * + * @author svedrenne + */ +@SuppressWarnings("serial") +public class CheckUpdateDialog extends JDialog { + + private JFrame parent; + + final CheckUpdateAction checkUpdateAction; + + /** + * Warning: read/write this variable from the EDT thread only. + */ + private int result = -1; + + private final SwingWorker worker = new SwingWorker() { + + @Override + protected String doInBackground() throws Exception { + /* Executed in a background thread */ + final String str = getHttpLatestVersionString(); + + return str; + } + + @Override + protected void done() { + /* Executed in the EDT */ + result = -1; + try { + String httpVersionString = get(); + + System.out + .println("SwingApp.getHttpLatestVersionString() (embedded) Version.versionString:" + + Version.versionString); + System.out + .println("SwingApp.getHttpLatestVersionString() retrieved versionString:" + + httpVersionString); + + if (httpVersionString.equals(Version.versionString)) { + System.out + .println("SwingApp.getHttpLatestVersionString() This version is up-to-date"); + result = 0; + } else if (httpVersionString.startsWith("Sudokuki")) { + System.out + .println("SwingApp.getHttpLatestVersionString() This version is outdated. Please download the latest version from Sourceforge."); + checkUpdateAction.notifyNewVersionFound(); + result = 1; + } + } catch (InterruptedException e) { + System.out + .println("CheckUpdateDialog.worker.new SwingWorker() {...}.done() Interrupted !!!!"); + } catch (ExecutionException e) { + System.out + .println("CheckUpdateDialog.worker.new SwingWorker() {...}.done() ExecutionException !!!!"); + } catch (CancellationException e) { + System.out + .println("CheckUpdateDialog.worker.new SwingWorker() {...}.done() CancellationException !!!!"); + result = -2; + } + CheckUpdateDialog.this.dispose(); + } + + private String getHttpLatestVersionString() { + String line = null; + BufferedReader dis = null; + try { + URL url; + URLConnection urlConn; + + url = new URL( + "http://sourceforge.net/projects/sudokuki/files/sudokuki/1.1/Beta/LATEST/download"); + + urlConn = url.openConnection(); + urlConn.setDoInput(true); + urlConn.setUseCaches(false); + + dis = new BufferedReader(new InputStreamReader( + urlConn.getInputStream())); + + line = dis.readLine(); + } catch (MalformedURLException mue) { + mue.printStackTrace(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } finally { + try { + dis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + System.out.println("getHttpLatestVersionString() line:" + line); + String versionString = ""; + if (line != null) { + String[] strs = line.split(_(" is the latest version.")); + if (strs.length >= 1) { + versionString = strs[0]; + } + } + return versionString; + } + }; + + public CheckUpdateDialog(JFrame parent, + final CheckUpdateAction checkUpdateAction) { + super(parent, true); + this.checkUpdateAction = checkUpdateAction; + this.parent = parent; + initComponents(); + setResizable(false); + worker.execute(); + } + + private void initComponents() { + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + Container pane = getContentPane(); + GridLayout btnLayout = new GridLayout(4, 1); + pane.setLayout(btnLayout); + + JLabel messageLbl1 = new JLabel("" + "
" + "Please wait...
" + + "" + "" + ""); + JLabel messageLbl2 = new JLabel("" + "
" + + _("Checking for available updates")+".
" + + "" + "" + + ""); + JLabel messageLbl3 = new JLabel(""); + JButton cancelBtn = new JButton(_("Cancel")); + cancelBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + cancelBtn.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonClicked(); + } + }); + + pane.add(messageLbl1); + pane.add(messageLbl2); + pane.add(messageLbl3); + pane.add(cancelBtn); + + pack(); + setLocationRelativeTo(parent); + } + + private void cancelButtonClicked() { + System.out.println("CheckUpdateDialog.cancelButtonClicked()"); + boolean cancelled = worker.cancel(true); + System.out.println("CheckUpdateDialog.cancelButtonClicked() cancelled:" + + cancelled); + } + + /** + * @return
    + *
  • 1 if a new version is available
  • + *
  • 0 if the version is up-to-date
  • + *
  • -1 if an error occurred
  • + *
  • -2 if cancelled by the user
  • + *
+ * + * Must be executed in the EDT only (because it accesses + * result). + */ + int getResult() { + System.out.println("CheckUpdateDialog.getResult() Thread:" + + Thread.currentThread().getName()); + + System.out.println("result: " + result); + return result; + } + } \ No newline at end of file diff --git a/src/classes/net/jankenpoi/sudokuki/ui/swing/DualSelectionDialog.java b/src/classes/net/jankenpoi/sudokuki/ui/swing/DualSelectionDialog.java index 90a6d1f..c24556b 100644 --- a/src/classes/net/jankenpoi/sudokuki/ui/swing/DualSelectionDialog.java +++ b/src/classes/net/jankenpoi/sudokuki/ui/swing/DualSelectionDialog.java @@ -17,24 +17,33 @@ */ package net.jankenpoi.sudokuki.ui.swing; +import java.util.Arrays; +import java.util.Locale; +import static net.jankenpoi.i18n.I18n._; + import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JTabbedPane; +import net.jankenpoi.i18n.I18n; +import net.jankenpoi.i18n.LocaleListener; +import net.jankenpoi.sudokuki.ui.L10nComponent; + @SuppressWarnings("serial") public class DualSelectionDialog extends JDialog { private SelectNumberPanel numberPanel; private SelectMemosPanel memosPanel; - + public DualSelectionDialog(boolean valuePickerOnTop, JFrame parent, byte previousValue, Byte[] previousMemos) { super(parent, true); tabbedPane = new JTabbedPane(); numberPanel = new SelectNumberPanel(this, previousValue); memosPanel = new SelectMemosPanel(this, previousMemos); - tabbedPane.addTab("Select", numberPanel); - tabbedPane.addTab("Memos", memosPanel); + tabbedPane.addTab(_("Select"), numberPanel); + tabbedPane.addTab(_("Memos"), memosPanel); + tabbedPane.setSelectedComponent(valuePickerOnTop ? numberPanel : memosPanel); add(tabbedPane); @@ -60,8 +69,10 @@ public class DualSelectionDialog extends JDialog { } void memosPanelConfirmed() { - value = 0; memos = memosPanel.getSelectedMemos(); + if (memosPanel.memosChanged()) { + value = 0; + } dispose(); } diff --git a/src/classes/net/jankenpoi/sudokuki/ui/swing/ResolveAction.java b/src/classes/net/jankenpoi/sudokuki/ui/swing/ResolveAction.java index 4aa2171..bc036ab 100644 --- a/src/classes/net/jankenpoi/sudokuki/ui/swing/ResolveAction.java +++ b/src/classes/net/jankenpoi/sudokuki/ui/swing/ResolveAction.java @@ -25,6 +25,7 @@ import javax.swing.JFrame; import javax.swing.JOptionPane; import net.jankenpoi.sudokuki.view.GridView; +import static net.jankenpoi.i18n.I18n._; @SuppressWarnings("serial") public class ResolveAction extends AbstractAction { @@ -52,12 +53,12 @@ public class ResolveAction extends AbstractAction { setEnabled(false); JOptionPane.showMessageDialog(frame, "" + "
" + _("Please wait...")+"
" + "" - + "Grid resolved with success." + "" + + _("Grid resolved with success.") + "" + "", "Sudokuki", JOptionPane.PLAIN_MESSAGE); } else if (result == 2) { JOptionPane.showMessageDialog(frame, "" + "
" + "" - + "This grid has no solution.

" + + _("This grid has no solution.")+"

" + "" + "", "Sudokuki", JOptionPane.WARNING_MESSAGE); } else if (result == 1) { diff --git a/src/classes/net/jankenpoi/sudokuki/ui/swing/SelectMemosPanel.java b/src/classes/net/jankenpoi/sudokuki/ui/swing/SelectMemosPanel.java index ce72153..110802b 100644 --- a/src/classes/net/jankenpoi/sudokuki/ui/swing/SelectMemosPanel.java +++ b/src/classes/net/jankenpoi/sudokuki/ui/swing/SelectMemosPanel.java @@ -1,350 +1,343 @@ -/* - * Sudokuki - essential sudoku game - * Copyright (C) 2007-2012 Sylvain Vedrenne - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.jankenpoi.sudokuki.ui.swing; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Font; -import java.awt.GridLayout; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.util.HashSet; -import java.util.Iterator; - -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JPanel; -import javax.swing.JToggleButton; - -/** - * - * @author svedrenne - */ -@SuppressWarnings("serial") -public class SelectMemosPanel extends JPanel { - - private JButton btnClear; - private JCheckBox[] ckb = new JCheckBox[9]; - private int focusedElement = 4; - private JButton btnConfirm; - private JPanel panelClear = new JPanel(new GridLayout()); - private JPanel panel789 = new JPanel(new GridLayout()); - private JPanel panel456 = new JPanel(new GridLayout()); - private JPanel panel123 = new JPanel(new GridLayout()); - private JPanel panelConfirm = new JPanel(new GridLayout()); - private HashSet memos = new HashSet(); - - private Font BOLD_FONT = new Font("Serif", Font.BOLD, 18); - private Font NORMAL_FONT = new Font("Serif", Font.PLAIN, 18); - - private InnerKeyListener innerKeyListener = new InnerKeyListener(); - private InnerFocusListener innerFocusListener = new InnerFocusListener(); - - private DualSelectionDialog parent; - - public SelectMemosPanel(DualSelectionDialog parent, Byte[] previousMemos) { - super(true); - this.parent = parent; - initComponents(previousMemos); - parent.getTabbedPane().addKeyListener(innerKeyListener); - parent.getTabbedPane().addFocusListener(innerFocusListener); - } - - private void configureCheckBox(JCheckBox btn, String text, final int button) { - // System.out.println("InputDialog.configureButton() btn:"+btn+" text:"+text+" value:"+value); - -// btn.setBorderPainted(false); - btn.setFont(NORMAL_FONT); - -// btn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btn.setToolTipText(text); - btn.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); - btn.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonClicked(button); - } - }); - btn.addKeyListener(innerKeyListener); - btn.addFocusListener(innerFocusListener); - } - - private void initComponents(Byte[] previousMemos) { - - if (previousMemos != null) { - for (int i = 0; i < previousMemos.length; i++) { - memos.add(previousMemos[i]); - } - } - for (int i = 0; i < ckb.length; i++) { - ckb[i] = new JCheckBox(String.valueOf(i+1)); - } - btnConfirm = new JButton(); - - btnClear = new JButton(); - btnClear.setText("Clear memos"); - btnClear.setEnabled(true); - btnClear.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - clearClicked(); - } - private void clearClicked() { - for (byte i=1; i<=ckb.length; i++) { - memos.remove(Byte.valueOf(i)); - ckb[i-1].setFont(NORMAL_FONT); - ckb[i-1].setSelected(false); - } - } - }); - btnClear.addKeyListener(innerKeyListener); - btnClear.addFocusListener(innerFocusListener); - configureCheckBox(ckb[6], "7", 6); - configureCheckBox(ckb[7], "8", 7); - configureCheckBox(ckb[8], "9", 8); - configureCheckBox(ckb[3], "4", 3); - configureCheckBox(ckb[4], "5", 4); - configureCheckBox(ckb[5], "6", 5); - configureCheckBox(ckb[0], "1", 0); - configureCheckBox(ckb[1], "2", 1); - configureCheckBox(ckb[2], "3", 2); - btnConfirm.setText("Ok"); - btnConfirm.setEnabled(true); - btnConfirm.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - confirmClicked(); - } - - private void confirmClicked() { - parent.memosPanelConfirmed(); - } - }); - btnConfirm.addKeyListener(innerKeyListener); - btnConfirm.addFocusListener(innerFocusListener); - - Iterator it = memos.iterator(); - while (it.hasNext()) { - JToggleButton button = ckb[it.next()-1]; - button.setSelected(true); - button.setFont(BOLD_FONT); - } - - - GridLayout btnLayout = new GridLayout(5, 1); - setLayout(btnLayout); - add(panelClear); - add(panel123); - add(panel456); - add(panel789); - add(panelConfirm); - - panelClear.add(btnClear); - panel789.add(ckb[6], BorderLayout.LINE_START); - panel789.add(ckb[7], BorderLayout.CENTER); - panel789.add(ckb[8], BorderLayout.LINE_END); - panel456.add(ckb[3], BorderLayout.LINE_START); - panel456.add(ckb[4], BorderLayout.CENTER); - panel456.add(ckb[5], BorderLayout.LINE_END); - panel123.add(ckb[0], BorderLayout.LINE_START); - panel123.add(ckb[1], BorderLayout.CENTER); - panel123.add(ckb[2], BorderLayout.LINE_END); - panelConfirm.add(btnConfirm); - - ckb[4].requestFocusInWindow(); - focusedElement = 4; - } - - private boolean isTabSelected() { - int idx = parent.getTabbedPane().getSelectedIndex(); - if (idx != 1) { - System.out.println("SelectMemosPanel.isTabSelected() TAB NOT SELECTED"); - } - return (idx == 1); - } - - private void buttonClicked(int button) { - System.out.println("InputDialog.buttonClicked() button:" + button); - byte value = (byte)(button + 1); - if (ckb[button].isSelected()) { - memos.add(value); - ckb[button].setFont(BOLD_FONT); - } else { - memos.remove(value); - ckb[button].setFont(NORMAL_FONT); - } - } - - public byte[] getSelectedMemos() { - byte[] memosArray = new byte[memos.size()]; - - Iterator it = memos.iterator(); - int i = 0; - while (it.hasNext()) { - memosArray[i] = it.next(); - i++; - } - return memosArray; - } - - private class InnerKeyListener extends KeyAdapter { - @Override - public void keyPressed(KeyEvent ke) { - if (isTabSelected() && focusedTabPane()) { - int code = ke.getKeyCode(); - if (code == KeyEvent.VK_H) { - System.out.println("MemosPanel tab selected <>HL"); - int index = parent.getTabbedPane().getSelectedIndex(); - int newIndex = (index == 0)?1:0; - System.out.println("MemosPanel tab selected index:"+index); - System.out.println("MemosPanel tab selected newIndex:"+newIndex); - parent.getTabbedPane().setSelectedIndex(newIndex); - parent.getTabbedPane().requestFocusInWindow(); - return; - } - else if (code == KeyEvent.VK_L) { - return; - } - } - if (!isTabSelected()) { - return; - } - int code = ke.getKeyCode(); - if (code == KeyEvent.VK_KP_UP || code == KeyEvent.VK_UP || code == KeyEvent.VK_K) { - if (focusedTabPane()) { - return; - } - if (focusedClearButton()) { - parent.getTabbedPane().requestFocusInWindow(); - return; - } - if (focusedOkButton()) { - ckb[focusedElement].requestFocusInWindow(); - return; - } - if (focusedElement / 3 == 0) { - btnClear.requestFocusInWindow(); - return; - } - focusedElement = Math.max(0, focusedElement-3); - ckb[focusedElement].requestFocusInWindow(); - } - else if (code == KeyEvent.VK_KP_DOWN || code == KeyEvent.VK_DOWN || code == KeyEvent.VK_J) { - if (focusedTabPane()) { - btnClear.requestFocusInWindow(); - return; - } - if (focusedOkButton()) { - return; - } - if (focusedClearButton()) { - focusedElement = 1; - System.out.println("focusedElement: "+focusedElement); - ckb[focusedElement].requestFocusInWindow(); - return; - } - if (focusedElement / 3 == 2) { - btnConfirm.requestFocusInWindow(); - return; - } - focusedElement = Math.min(8, focusedElement+3); - ckb[focusedElement].requestFocusInWindow(); - } - else if (code == KeyEvent.VK_KP_LEFT || code == KeyEvent.VK_LEFT || code == KeyEvent.VK_H) { - if (focusedElement%3 == 0 || btnConfirm.hasFocus() || btnClear.hasFocus()) { - System.out - .println("SelectMemosPanel.InnerKeyListener.keyPressed() OK or CLEAR has focus"); - return; - } - focusedElement = Math.max(0, focusedElement-1); - ckb[focusedElement].requestFocusInWindow(); - } - else if (code == KeyEvent.VK_KP_RIGHT || code == KeyEvent.VK_RIGHT || code == KeyEvent.VK_L) { - if (focusedElement%3 == 2 || focusedOkButton() || focusedClearButton()) { - return; - } - focusedElement = Math.min(8, focusedElement+1); - ckb[focusedElement].requestFocusInWindow(); - } - else if (code == KeyEvent.VK_ESCAPE) { - parent.memosPanelEscaped(); - } - } - - private boolean focusedTabPane() { - return parent.getTabbedPane().hasFocus(); - } - - @Override - public void keyReleased(KeyEvent ke) { - if (!isTabSelected()) { - return; - } - int code = ke.getKeyCode(); - if (code == KeyEvent.VK_ENTER) { - if (focusedClearButton() || focusedOkButton()) { - /* - * Buttons actions are managing this so Nothing to do. - */ - return; - } - parent.memosPanelConfirmed(); - } - } - - } - - private class InnerFocusListener extends FocusAdapter { - - @Override - public void focusGained(FocusEvent e) { - - Component comp = e.getComponent(); - if (comp == ckb[focusedElement]) { - return; - } - for (int i=0; i. + */ +package net.jankenpoi.sudokuki.ui.swing; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Font; +import java.awt.GridLayout; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.HashSet; +import java.util.Iterator; + +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JPanel; +import javax.swing.JToggleButton; +import static net.jankenpoi.i18n.I18n._; + +/** + * + * @author svedrenne + */ +@SuppressWarnings("serial") +public class SelectMemosPanel extends JPanel { + + private JButton btnClear; + private JCheckBox[] ckb = new JCheckBox[9]; + private int focusedElement = 4; + private JButton btnConfirm; + private JPanel panelClear = new JPanel(new GridLayout()); + private JPanel panel789 = new JPanel(new GridLayout()); + private JPanel panel456 = new JPanel(new GridLayout()); + private JPanel panel123 = new JPanel(new GridLayout()); + private JPanel panelConfirm = new JPanel(new GridLayout()); + private HashSet memos = new HashSet(); + private HashSet previousMemos = new HashSet(); + + private Font BOLD_FONT = new Font("Serif", Font.BOLD, 18); + private Font NORMAL_FONT = new Font("Serif", Font.PLAIN, 18); + + private InnerKeyListener innerKeyListener = new InnerKeyListener(); + private InnerFocusListener innerFocusListener = new InnerFocusListener(); + + private DualSelectionDialog parent; + + public SelectMemosPanel(DualSelectionDialog parent, Byte[] previousMemos) { + super(true); + this.parent = parent; + initComponents(previousMemos); + parent.getTabbedPane().addKeyListener(innerKeyListener); + parent.getTabbedPane().addFocusListener(innerFocusListener); + } + + private void configureCheckBox(JCheckBox btn, String text, final int button) { + + btn.setFont(NORMAL_FONT); + + btn.setToolTipText(text); + btn.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); + btn.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonClicked(button); + } + }); + btn.addKeyListener(innerKeyListener); + btn.addFocusListener(innerFocusListener); + } + + private void initComponents(Byte[] previousMemos) { + + if (previousMemos != null) { + for (int i = 0; i < previousMemos.length; i++) { + memos.add(previousMemos[i]); + this.previousMemos.add(previousMemos[i]); + } + } + for (int i = 0; i < ckb.length; i++) { + ckb[i] = new JCheckBox(String.valueOf(i+1)); + } + btnConfirm = new JButton(); + + btnClear = new JButton(); + btnClear.setText(_("Clear memos")); + btnClear.setEnabled(true); + btnClear.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + clearClicked(); + } + private void clearClicked() { + for (byte i=1; i<=ckb.length; i++) { + memos.remove(Byte.valueOf(i)); + ckb[i-1].setFont(NORMAL_FONT); + ckb[i-1].setSelected(false); + } + } + }); + btnClear.addKeyListener(innerKeyListener); + btnClear.addFocusListener(innerFocusListener); + configureCheckBox(ckb[6], "7", 6); + configureCheckBox(ckb[7], "8", 7); + configureCheckBox(ckb[8], "9", 8); + configureCheckBox(ckb[3], "4", 3); + configureCheckBox(ckb[4], "5", 4); + configureCheckBox(ckb[5], "6", 5); + configureCheckBox(ckb[0], "1", 0); + configureCheckBox(ckb[1], "2", 1); + configureCheckBox(ckb[2], "3", 2); + btnConfirm.setText(_("Ok")); + btnConfirm.setEnabled(true); + btnConfirm.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + confirmClicked(); + } + + private void confirmClicked() { + parent.memosPanelConfirmed(); + } + }); + btnConfirm.addKeyListener(innerKeyListener); + btnConfirm.addFocusListener(innerFocusListener); + + Iterator it = memos.iterator(); + while (it.hasNext()) { + JToggleButton button = ckb[it.next()-1]; + button.setSelected(true); + button.setFont(BOLD_FONT); + } + + + GridLayout btnLayout = new GridLayout(5, 1); + setLayout(btnLayout); + add(panelClear); + add(panel123); + add(panel456); + add(panel789); + add(panelConfirm); + + panelClear.add(btnClear); + panel789.add(ckb[6], BorderLayout.LINE_START); + panel789.add(ckb[7], BorderLayout.CENTER); + panel789.add(ckb[8], BorderLayout.LINE_END); + panel456.add(ckb[3], BorderLayout.LINE_START); + panel456.add(ckb[4], BorderLayout.CENTER); + panel456.add(ckb[5], BorderLayout.LINE_END); + panel123.add(ckb[0], BorderLayout.LINE_START); + panel123.add(ckb[1], BorderLayout.CENTER); + panel123.add(ckb[2], BorderLayout.LINE_END); + panelConfirm.add(btnConfirm); + + ckb[4].requestFocusInWindow(); + focusedElement = 4; + } + + private boolean isTabSelected() { + int idx = parent.getTabbedPane().getSelectedIndex(); + if (idx != 1) { + System.out.println("SelectMemosPanel.isTabSelected() TAB NOT SELECTED"); + } + return (idx == 1); + } + + private void buttonClicked(int button) { + System.out.println("InputDialog.buttonClicked() button:" + button); + byte value = (byte)(button + 1); + if (ckb[button].isSelected()) { + memos.add(value); + ckb[button].setFont(BOLD_FONT); + } else { + memos.remove(value); + ckb[button].setFont(NORMAL_FONT); + } + } + + public byte[] getSelectedMemos() { + byte[] memosArray = new byte[memos.size()]; + + Iterator it = memos.iterator(); + int i = 0; + while (it.hasNext()) { + memosArray[i] = it.next(); + i++; + } + return memosArray; + } + + private class InnerKeyListener extends KeyAdapter { + @Override + public void keyPressed(KeyEvent ke) { + if (isTabSelected() && focusedTabPane()) { + int code = ke.getKeyCode(); + if (code == KeyEvent.VK_H) { + System.out.println("MemosPanel tab selected <>HL"); + int index = parent.getTabbedPane().getSelectedIndex(); + int newIndex = (index == 0)?1:0; + System.out.println("MemosPanel tab selected index:"+index); + System.out.println("MemosPanel tab selected newIndex:"+newIndex); + parent.getTabbedPane().setSelectedIndex(newIndex); + parent.getTabbedPane().requestFocusInWindow(); + return; + } + else if (code == KeyEvent.VK_L) { + return; + } + } + if (!isTabSelected()) { + return; + } + int code = ke.getKeyCode(); + if (code == KeyEvent.VK_KP_UP || code == KeyEvent.VK_UP || code == KeyEvent.VK_K) { + if (focusedTabPane()) { + return; + } + if (focusedClearButton()) { + parent.getTabbedPane().requestFocusInWindow(); + return; + } + if (focusedOkButton()) { + ckb[focusedElement].requestFocusInWindow(); + return; + } + if (focusedElement / 3 == 0) { + btnClear.requestFocusInWindow(); + return; + } + focusedElement = Math.max(0, focusedElement-3); + ckb[focusedElement].requestFocusInWindow(); + } + else if (code == KeyEvent.VK_KP_DOWN || code == KeyEvent.VK_DOWN || code == KeyEvent.VK_J) { + if (focusedTabPane()) { + btnClear.requestFocusInWindow(); + return; + } + if (focusedOkButton()) { + return; + } + if (focusedClearButton()) { + focusedElement = 1; + System.out.println("focusedElement: "+focusedElement); + ckb[focusedElement].requestFocusInWindow(); + return; + } + if (focusedElement / 3 == 2) { + btnConfirm.requestFocusInWindow(); + return; + } + focusedElement = Math.min(8, focusedElement+3); + ckb[focusedElement].requestFocusInWindow(); + } + else if (code == KeyEvent.VK_KP_LEFT || code == KeyEvent.VK_LEFT || code == KeyEvent.VK_H) { + if (focusedElement%3 == 0 || btnConfirm.hasFocus() || btnClear.hasFocus()) { + System.out + .println("SelectMemosPanel.InnerKeyListener.keyPressed() OK or CLEAR has focus"); + return; + } + focusedElement = Math.max(0, focusedElement-1); + ckb[focusedElement].requestFocusInWindow(); + } + else if (code == KeyEvent.VK_KP_RIGHT || code == KeyEvent.VK_RIGHT || code == KeyEvent.VK_L) { + if (focusedElement%3 == 2 || focusedOkButton() || focusedClearButton()) { + return; + } + focusedElement = Math.min(8, focusedElement+1); + ckb[focusedElement].requestFocusInWindow(); + } + else if (code == KeyEvent.VK_ESCAPE) { + parent.memosPanelEscaped(); + } + } + + private boolean focusedTabPane() { + return parent.getTabbedPane().hasFocus(); + } + + @Override + public void keyReleased(KeyEvent ke) { + if (!isTabSelected()) { + return; + } + int code = ke.getKeyCode(); + if (code == KeyEvent.VK_ENTER) { + if (focusedClearButton() || focusedOkButton()) { + /* + * Buttons actions are managing this so Nothing to do. + */ + return; + } + parent.memosPanelConfirmed(); + } + } + + } + + private class InnerFocusListener extends FocusAdapter { + + @Override + public void focusGained(FocusEvent e) { + + Component comp = e.getComponent(); + if (comp == ckb[focusedElement]) { + return; + } + for (int i=0; i. - */ -package net.jankenpoi.sudokuki.ui.swing; - -import static net.jankenpoi.i18n.I18n._; - -import java.awt.Color; -import java.awt.Desktop; -import java.awt.Dimension; -import java.awt.Frame; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; - -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.SwingConstants; - -@SuppressWarnings("serial") -public class TranslateDialog extends JDialog { - - private Frame parent; - - public TranslateDialog(Frame parent) { - super(parent, true); - this.parent = parent; - initComponents(); - // setResizable(false); - setTitle(_("Translate this application")); - pack(); - } - - private void initComponents() { - URI sudokukiURI = null; - try { - sudokukiURI = new URI("http://sourceforge.net/projects/sudokuki/forums/forum/1801058"); - } catch (URISyntaxException e1) { - e1.printStackTrace(); - } - - JPanel panel = makeInfoPanel(sudokukiURI); - - - - Dimension parentDim = parent.getPreferredSize(); - Dimension dim = new Dimension(); - dim.setSize(parentDim.getHeight() * 1.75, parentDim.getWidth() * 1.25); - add(panel); - pack(); - setLocationRelativeTo(parent); - } - - protected JPanel makeInfoPanel(final URI sudokukiURI) { - JPanel panel = new JPanel(false); - panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - - JPanel feedbackPanel = new JPanel(false); - String feedbackStr = "" - + "
" - + "" - + "" - + "" - + "You can easily translate Sudokuki into your own language!
" - +"
" - + "" - + "" - + "Propose your help and get information on how to proceed
" - +"on the Translators Forum hosted by Sourceforge:
" - + "" - + "" - + "" + "" + "" + "
" + ""; - JLabel label = new JLabel(feedbackStr); - feedbackPanel.add(label); - - panel.add(feedbackPanel); - - JPanel linkPanel = new JPanel(false); - JButton linkButton = new JButton(); - - linkButton - .setText("Sudokuki Translators Forum"); - linkButton.setHorizontalAlignment(SwingConstants.CENTER); - linkButton.setBorderPainted(false); - linkButton.setOpaque(false); - linkButton.setBackground(Color.WHITE); - linkButton.setToolTipText(sudokukiURI.toString()); - linkButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - TranslateDialog.this.open(sudokukiURI); - } - }); - linkButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); - linkPanel.add(linkButton); - panel.add(linkPanel); - - return panel; - } - - private void open(URI uri) { - if (Desktop.isDesktopSupported()) { - Desktop desktop = Desktop.getDesktop(); - try { - desktop.browse(uri); - } catch (IOException e) { - e.printStackTrace(); - } - } else { - // TODO: error handling - } - } - -} +/* + * Sudokuki - essential sudoku game + * Copyright (C) 2007-2012 Sylvain Vedrenne + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.jankenpoi.sudokuki.ui.swing; + +import static net.jankenpoi.i18n.I18n._; + +import java.awt.Color; +import java.awt.Desktop; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingConstants; + +@SuppressWarnings("serial") +public class TranslateDialog extends JDialog { + + private Frame parent; + + public TranslateDialog(Frame parent) { + super(parent, true); + this.parent = parent; + initComponents(); + // setResizable(false); + setTitle(_("Translate this application")); + pack(); + } + + private void initComponents() { + URI sudokukiURI = null; + try { + sudokukiURI = new URI("http://sourceforge.net/projects/sudokuki/forums/forum/1801058"); + } catch (URISyntaxException e1) { + e1.printStackTrace(); + } + + JPanel panel = makeInfoPanel(sudokukiURI); + + + + Dimension parentDim = parent.getPreferredSize(); + Dimension dim = new Dimension(); + dim.setSize(parentDim.getHeight() * 1.75, parentDim.getWidth() * 1.25); + add(panel); + pack(); + setLocationRelativeTo(parent); + } + + protected JPanel makeInfoPanel(final URI sudokukiURI) { + JPanel panel = new JPanel(false); + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); + + JPanel feedbackPanel = new JPanel(false); + String feedbackStr = "" + + "" + + "" + + "" + + "" + + _("You can easily translate Sudokuki into your own language!")+"
" + +"
" + + "" + + "" + + _("Propose your help and get information on how to proceed
on the Translators Forum hosted by Sourceforge:")+"
" + + "" + + "" + + "" + "" + "" + "
" + ""; + JLabel label = new JLabel(feedbackStr); + feedbackPanel.add(label); + + panel.add(feedbackPanel); + + JPanel linkPanel = new JPanel(false); + JButton linkButton = new JButton(); + + linkButton + .setText(""+_("Sudokuki Translators Forum")+""); + linkButton.setHorizontalAlignment(SwingConstants.CENTER); + linkButton.setBorderPainted(false); + linkButton.setOpaque(false); + linkButton.setBackground(Color.WHITE); + linkButton.setToolTipText(sudokukiURI.toString()); + linkButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + TranslateDialog.this.open(sudokukiURI); + } + }); + linkButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); + linkPanel.add(linkButton); + panel.add(linkPanel); + + return panel; + } + + private void open(URI uri) { + if (Desktop.isDesktopSupported()) { + Desktop desktop = Desktop.getDesktop(); + try { + desktop.browse(uri); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + // TODO: error handling + } + } + +} -- 2.11.0