From 27182804d09295fcc5c10e4fc96a42e89cae68ae Mon Sep 17 00:00:00 2001 From: Jaroslav Beran Date: Sat, 6 Feb 2021 18:48:13 +0100 Subject: [PATCH] Dictionary state refa --- .../java/cz/webstones/words/AboutDialog.java | 2 +- .../java/cz/webstones/words/FindDialog.java | 2 +- src/main/java/cz/webstones/words/Main.java | 14 +++++------ .../webstones/words/RenameCategoryDialog.java | 4 ++-- .../java/cz/webstones/words/WordDialog.java | 4 ++-- .../words/dictionary/DictionaryStateEnum.java | 14 +++++------ .../words/dictionary/impl/DictionaryImpl.java | 24 +++++++++---------- .../words/dictionary/ObserverTestHelper.java | 12 +++++----- 8 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/main/java/cz/webstones/words/AboutDialog.java b/src/main/java/cz/webstones/words/AboutDialog.java index 8f1f712..c2330b7 100644 --- a/src/main/java/cz/webstones/words/AboutDialog.java +++ b/src/main/java/cz/webstones/words/AboutDialog.java @@ -98,7 +98,7 @@ public void mouseExited(MouseEvent e) { @Override public void updateObserver() { - if (dict.getSubjectState() == DictionaryStateEnum.stateDictionaryLoaded) { + if (dict.getSubjectState() == DictionaryStateEnum.DICTIONARY_LOADED) { try { setPronunciation(dict.getLanguage()); } catch (IOException ex) { diff --git a/src/main/java/cz/webstones/words/FindDialog.java b/src/main/java/cz/webstones/words/FindDialog.java index e1df9e0..a3d7b43 100644 --- a/src/main/java/cz/webstones/words/FindDialog.java +++ b/src/main/java/cz/webstones/words/FindDialog.java @@ -49,7 +49,7 @@ public void focusGained(FocusEvent e) @Override public void updateObserver() { - if (dict.getSubjectState() == DictionaryStateEnum.stateCurCategoryChanged) { + if (dict.getSubjectState() == DictionaryStateEnum.CUR_CATEGORY_CHANGED) { setLabel(dict.getCurrentCategory()); } } diff --git a/src/main/java/cz/webstones/words/Main.java b/src/main/java/cz/webstones/words/Main.java index fec2cf8..9c04b4c 100644 --- a/src/main/java/cz/webstones/words/Main.java +++ b/src/main/java/cz/webstones/words/Main.java @@ -9,7 +9,7 @@ import cz.webstones.words.dictionary.IObserver; import cz.webstones.words.dictionary.WordDto; import cz.webstones.words.dictionary.DictionaryException; -import static cz.webstones.words.dictionary.DictionaryStateEnum.stateCurWordChanged; +import static cz.webstones.words.dictionary.DictionaryStateEnum.CUR_WORD_CHANGED; import cz.webstones.words.dictionary.impl.DictionaryImpl; import cz.webstones.words.mp3.Mp3Creator; import cz.webstones.words.mp3.Mp3CreatorException; @@ -128,25 +128,25 @@ private boolean isRunning() { public void updateObserver() { switch (dict.getSubjectState()) { - case stateWordAdded: - case stateCurWordChanged: - case stateCurWordDeleted: + case WORD_ADDED: + case CUR_WORD_CHANGED: + case CUR_WORD_DELETED: nextRelative(0); break; - case stateCurCategoryChanged: + case CUR_CATEGORY_CHANGED: if (!dict.getCurrentCategory().equals(jComboBox1.getSelectedItem().toString())) { jComboBox1.setSelectedItem(dict.getCurrentCategory()); } break; - case stateCategoryListChanged: + case CATEGORY_LIST_CHANGED: disableCategotyChange = true; updateCategoryCombo(); disableCategotyChange = false; break; - case stateDictionaryLoaded: + case DICTIONARY_LOADED: try { this.setTitleText(Service.VERSION, dict.getDictionaryName(), dict.getLanguage()); } catch (IOException ex) { diff --git a/src/main/java/cz/webstones/words/RenameCategoryDialog.java b/src/main/java/cz/webstones/words/RenameCategoryDialog.java index 19e7985..eec6e2b 100644 --- a/src/main/java/cz/webstones/words/RenameCategoryDialog.java +++ b/src/main/java/cz/webstones/words/RenameCategoryDialog.java @@ -32,10 +32,10 @@ public RenameCategoryDialog(java.awt.Frame parent, boolean modal, IDictionary di public void updateObserver() { switch (dict.getSubjectState()) { - case stateCategoryListChanged: + case CATEGORY_LIST_CHANGED: updateCategoryCombo(); break; - case stateCurCategoryChanged: + case CUR_CATEGORY_CHANGED: if (!dict.getCurrentCategory().equals(jComboBox1.getSelectedItem().toString())) { jComboBox1.setSelectedItem(dict.getCurrentCategory()); } diff --git a/src/main/java/cz/webstones/words/WordDialog.java b/src/main/java/cz/webstones/words/WordDialog.java index 4c91ed8..c220163 100644 --- a/src/main/java/cz/webstones/words/WordDialog.java +++ b/src/main/java/cz/webstones/words/WordDialog.java @@ -40,10 +40,10 @@ public WordDialog(java.awt.Frame parent, boolean modal, AddCategoryDialog d, IDi public void updateObserver() { switch (dict.getSubjectState()) { - case stateCategoryListChanged: + case CATEGORY_LIST_CHANGED: updateCategoryCombo(); break; - case stateCurCategoryChanged: + case CUR_CATEGORY_CHANGED: if (!dict.getCurrentCategory().equals(jComboBox1.getSelectedItem().toString())) { jComboBox1.setSelectedItem(dict.getCurrentCategory()); } diff --git a/src/main/java/cz/webstones/words/dictionary/DictionaryStateEnum.java b/src/main/java/cz/webstones/words/dictionary/DictionaryStateEnum.java index 6a8c3bc..cb1192d 100644 --- a/src/main/java/cz/webstones/words/dictionary/DictionaryStateEnum.java +++ b/src/main/java/cz/webstones/words/dictionary/DictionaryStateEnum.java @@ -9,11 +9,11 @@ * @author jaroslav_b */ public enum DictionaryStateEnum { - stateNoChabge, - stateCurWordChanged, - stateCurWordDeleted, - stateCurCategoryChanged, - stateCategoryListChanged, - stateWordAdded, - stateDictionaryLoaded + NO_CHANGE, + CUR_WORD_CHANGED, + CUR_WORD_DELETED, + CUR_CATEGORY_CHANGED, + CATEGORY_LIST_CHANGED, + WORD_ADDED, + DICTIONARY_LOADED } diff --git a/src/main/java/cz/webstones/words/dictionary/impl/DictionaryImpl.java b/src/main/java/cz/webstones/words/dictionary/impl/DictionaryImpl.java index 17d5037..a66cafe 100644 --- a/src/main/java/cz/webstones/words/dictionary/impl/DictionaryImpl.java +++ b/src/main/java/cz/webstones/words/dictionary/impl/DictionaryImpl.java @@ -45,7 +45,7 @@ * @author jarberan */ public class DictionaryImpl implements IDictionary, Serializable { - + private static final long serialVersionUID = 2405172041950251876L; private static final Logger LOGGER = Logger.getLogger(DictionaryImpl.class.getName()); private Setup setup = null; @@ -53,7 +53,7 @@ public class DictionaryImpl implements IDictionary, Serializable { private ArrayList dictFil = new ArrayList<>(); private ArrayList categoryList = new ArrayList<>(); private final ArrayList observers = new ArrayList<>(); - private DictionaryStateEnum subjectState = DictionaryStateEnum.stateNoChabge; + private DictionaryStateEnum subjectState = DictionaryStateEnum.NO_CHANGE; private int current = 0; private String currentCategory; private Random rand = new Random(); @@ -161,7 +161,7 @@ public void loadDictionary(Setup s) current = -1; setCurrnet(0); - subjectState = DictionaryStateEnum.stateDictionaryLoaded; + subjectState = DictionaryStateEnum.DICTIONARY_LOADED; notifyAllObservers(); } @@ -248,7 +248,7 @@ public void setCurrnet(int i) { if (dictFil.isEmpty()) { current = 0; - subjectState = DictionaryStateEnum.stateCurWordChanged; + subjectState = DictionaryStateEnum.CUR_WORD_CHANGED; notifyAllObservers(); } @@ -256,7 +256,7 @@ public void setCurrnet(int i) { if (current != i) { current = i; - subjectState = DictionaryStateEnum.stateCurWordChanged; + subjectState = DictionaryStateEnum.CUR_WORD_CHANGED; notifyAllObservers(); } } @@ -322,7 +322,7 @@ public void addWord(WordDto w) throws DictionaryException { setCurrent(w); } - subjectState = DictionaryStateEnum.stateWordAdded; + subjectState = DictionaryStateEnum.WORD_ADDED; notifyAllObservers(); } @@ -341,7 +341,7 @@ public void updateWord(WordDto w) throws DictionaryException { setCurrent(w); } - subjectState = DictionaryStateEnum.stateCurWordChanged; + subjectState = DictionaryStateEnum.CUR_WORD_CHANGED; notifyAllObservers(); } @@ -380,7 +380,7 @@ public void deleteCurrentWord() { dictFil.remove(w); dictAll.remove(w); - subjectState = DictionaryStateEnum.stateCurWordDeleted; + subjectState = DictionaryStateEnum.CUR_WORD_DELETED; notifyAllObservers(); } @@ -483,7 +483,7 @@ public int compare(WordDto a, WordDto b) { setCurrnet(0); if (!oldCategory.equals(currentCategory)) { - subjectState = DictionaryStateEnum.stateCurCategoryChanged; + subjectState = DictionaryStateEnum.CUR_CATEGORY_CHANGED; notifyAllObservers(); } } @@ -508,7 +508,7 @@ private void updateCategoryList() { sortCategoryList(); - subjectState = DictionaryStateEnum.stateCategoryListChanged; + subjectState = DictionaryStateEnum.CATEGORY_LIST_CHANGED; notifyAllObservers(); } @@ -556,7 +556,7 @@ public void addCategory(String category) throws DictionaryException { categoryList.add(category); sortCategoryList(); - subjectState = DictionaryStateEnum.stateCategoryListChanged; + subjectState = DictionaryStateEnum.CATEGORY_LIST_CHANGED; notifyAllObservers(); } @@ -572,7 +572,7 @@ public void deleteCurrentCategory() throws DictionaryException { categoryList.remove(currentCategory); - subjectState = DictionaryStateEnum.stateCategoryListChanged; + subjectState = DictionaryStateEnum.CATEGORY_LIST_CHANGED; notifyAllObservers(); setCategory(ALL_CATEGORY); diff --git a/src/test/java/cz/webstones/words/dictionary/ObserverTestHelper.java b/src/test/java/cz/webstones/words/dictionary/ObserverTestHelper.java index 99b6dea..b3e4cc2 100644 --- a/src/test/java/cz/webstones/words/dictionary/ObserverTestHelper.java +++ b/src/test/java/cz/webstones/words/dictionary/ObserverTestHelper.java @@ -31,22 +31,22 @@ public ObserverTestHelper(IDictionary d) { @Override public void updateObserver() { switch (dict.getSubjectState()) { - case stateNoChabge: + case NO_CHANGE: noChange++; break; - case stateCurWordChanged: + case CUR_WORD_CHANGED: curWordChanged++; break; - case stateCurWordDeleted: + case CUR_WORD_DELETED: curWordDeleted++; break; - case stateCurCategoryChanged: + case CUR_CATEGORY_CHANGED: curCategoryChanged++; break; - case stateCategoryListChanged: + case CATEGORY_LIST_CHANGED: categoryListChanged++; break; - case stateWordAdded: + case WORD_ADDED: wordAdded++; break; default: