Skip to content

Commit

Permalink
Dictionary state refa
Browse files Browse the repository at this point in the history
  • Loading branch information
berk76 committed Feb 6, 2021
1 parent cfa2749 commit 2718280
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/main/java/cz/webstones/words/AboutDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cz/webstones/words/FindDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/cz/webstones/words/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cz/webstones/words/RenameCategoryDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cz/webstones/words/WordDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
* @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;
private ArrayList<WordDto> dictAll = new ArrayList<>();
private ArrayList<WordDto> dictFil = new ArrayList<>();
private ArrayList<String> categoryList = new ArrayList<>();
private final ArrayList<IObserver> 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();
Expand Down Expand Up @@ -161,7 +161,7 @@ public void loadDictionary(Setup s)
current = -1;
setCurrnet(0);

subjectState = DictionaryStateEnum.stateDictionaryLoaded;
subjectState = DictionaryStateEnum.DICTIONARY_LOADED;
notifyAllObservers();
}

Expand Down Expand Up @@ -248,15 +248,15 @@ public void setCurrnet(int i) {

if (dictFil.isEmpty()) {
current = 0;
subjectState = DictionaryStateEnum.stateCurWordChanged;
subjectState = DictionaryStateEnum.CUR_WORD_CHANGED;
notifyAllObservers();
}

if (dictFil.size() > i) {
if (current != i) {
current = i;

subjectState = DictionaryStateEnum.stateCurWordChanged;
subjectState = DictionaryStateEnum.CUR_WORD_CHANGED;
notifyAllObservers();
}
}
Expand Down Expand Up @@ -322,7 +322,7 @@ public void addWord(WordDto w) throws DictionaryException {
setCurrent(w);
}

subjectState = DictionaryStateEnum.stateWordAdded;
subjectState = DictionaryStateEnum.WORD_ADDED;
notifyAllObservers();
}

Expand All @@ -341,7 +341,7 @@ public void updateWord(WordDto w) throws DictionaryException {
setCurrent(w);
}

subjectState = DictionaryStateEnum.stateCurWordChanged;
subjectState = DictionaryStateEnum.CUR_WORD_CHANGED;
notifyAllObservers();
}

Expand Down Expand Up @@ -380,7 +380,7 @@ public void deleteCurrentWord() {
dictFil.remove(w);
dictAll.remove(w);

subjectState = DictionaryStateEnum.stateCurWordDeleted;
subjectState = DictionaryStateEnum.CUR_WORD_DELETED;
notifyAllObservers();
}

Expand Down Expand Up @@ -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();
}
}
Expand All @@ -508,7 +508,7 @@ private void updateCategoryList() {

sortCategoryList();

subjectState = DictionaryStateEnum.stateCategoryListChanged;
subjectState = DictionaryStateEnum.CATEGORY_LIST_CHANGED;
notifyAllObservers();
}

Expand Down Expand Up @@ -556,7 +556,7 @@ public void addCategory(String category) throws DictionaryException {
categoryList.add(category);
sortCategoryList();

subjectState = DictionaryStateEnum.stateCategoryListChanged;
subjectState = DictionaryStateEnum.CATEGORY_LIST_CHANGED;
notifyAllObservers();
}

Expand All @@ -572,7 +572,7 @@ public void deleteCurrentCategory() throws DictionaryException {

categoryList.remove(currentCategory);

subjectState = DictionaryStateEnum.stateCategoryListChanged;
subjectState = DictionaryStateEnum.CATEGORY_LIST_CHANGED;
notifyAllObservers();

setCategory(ALL_CATEGORY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2718280

Please sign in to comment.