diff --git a/src/main/java/cz/webstones/words/Main.java b/src/main/java/cz/webstones/words/Main.java index 8971334..fec2cf8 100644 --- a/src/main/java/cz/webstones/words/Main.java +++ b/src/main/java/cz/webstones/words/Main.java @@ -60,7 +60,7 @@ public Main() throws DictionaryException { super(); dict = new DictionaryImpl(); addCatDialog = new AddCategoryDialog(this, true); - renameCatDialog = new RenameCategoryDialog(this, true); + renameCatDialog = new RenameCategoryDialog(this, true, dict); wordDialog = new WordDialog(this, true, addCatDialog, dict); aboutDialog = new AboutDialog(this, true, dict); findDialog = new FindDialog(this, false, dict); @@ -877,7 +877,6 @@ private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed // Rename Category renameCatDialog.setNewCategoryText(""); - renameCatDialog.setCategoryList(dict.getCategoryList(), jComboBox1.getSelectedItem().toString()); renameCatDialog.setVisible(true); if (renameCatDialog.isCommited()) { renameCategory(renameCatDialog.getOldCategoryText(), renameCatDialog.getNewCategoryText()); @@ -889,7 +888,6 @@ private void editWord() { WordDto w = dict.getWord(); String oldWordPath = w.getMp3FilenameEn(dict.getSetup().getFullMp3Path()); wordDialog.setWord(w); - //wordDialog.setForeignWordEditable(false); wordDialog.setVisible(true); try { @@ -914,7 +912,6 @@ private void addWord() { WordDto w = new WordDto(); w.setCategory(jComboBox1.getSelectedItem().toString()); wordDialog.setWord(w); - wordDialog.setForeignWordEditable(true); wordDialog.setVisible(true); if (wordDialog.isCommited()) { diff --git a/src/main/java/cz/webstones/words/RenameCategoryDialog.java b/src/main/java/cz/webstones/words/RenameCategoryDialog.java index 9be32a7..19e7985 100644 --- a/src/main/java/cz/webstones/words/RenameCategoryDialog.java +++ b/src/main/java/cz/webstones/words/RenameCategoryDialog.java @@ -5,27 +5,44 @@ package cz.webstones.words; import static cz.webstones.words.Service.findFont; +import cz.webstones.words.dictionary.IDictionary; +import cz.webstones.words.dictionary.IObserver; import java.awt.Font; -import java.util.ArrayList; /** * * @author jaroslav_b */ -public class RenameCategoryDialog extends JEscapeableDialog { +public class RenameCategoryDialog extends JEscapeableDialog implements IObserver { private boolean commited; + private IDictionary dict; /** * Creates new form RenameCategoryDialog */ - public RenameCategoryDialog(java.awt.Frame parent, boolean modal) { + public RenameCategoryDialog(java.awt.Frame parent, boolean modal, IDictionary dic) { super(parent, modal); initComponents(); + dict = dic; + dict.attach(this); jTextField1.getDocument().addDocumentListener(new TextFieldFontChangeListener(jTextField1)); this.setLocationRelativeTo(null); } + public void updateObserver() { + switch (dict.getSubjectState()) { + case stateCategoryListChanged: + updateCategoryCombo(); + break; + case stateCurCategoryChanged: + if (!dict.getCurrentCategory().equals(jComboBox1.getSelectedItem().toString())) { + jComboBox1.setSelectedItem(dict.getCurrentCategory()); + } + break; + } + } + public void setNewCategoryText(String s) { jTextField1.setText(s); } @@ -34,24 +51,24 @@ public String getNewCategoryText() { return jTextField1.getText(); } - public void setCategoryList(ArrayList categoryList, String selectedItem) { + public String getOldCategoryText() { + return jComboBox1.getSelectedItem().toString(); + } + + public boolean isCommited() { + return commited; + } + + private void updateCategoryCombo() { jComboBox1.removeAllItems(); - for (String s: categoryList) { + for (String s: dict.getCategoryList()) { jComboBox1.addItem(s); if (jComboBox1.getFont().canDisplayUpTo(s) != -1) { Font f = findFont(s, jComboBox1.getFont()); jComboBox1.setFont(f); } } - jComboBox1.setSelectedItem(selectedItem); - } - - public String getOldCategoryText() { - return jComboBox1.getSelectedItem().toString(); - } - - public boolean isCommited() { - return commited; + 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 caebc24..4c91ed8 100644 --- a/src/main/java/cz/webstones/words/WordDialog.java +++ b/src/main/java/cz/webstones/words/WordDialog.java @@ -43,6 +43,11 @@ public void updateObserver() { case stateCategoryListChanged: updateCategoryCombo(); break; + case stateCurCategoryChanged: + if (!dict.getCurrentCategory().equals(jComboBox1.getSelectedItem().toString())) { + jComboBox1.setSelectedItem(dict.getCurrentCategory()); + } + break; } } @@ -68,12 +73,6 @@ public void setWord(WordDto w) { jTextField6.setText(String.valueOf(rate)); } - public void setForeignWordEditable(boolean b) { - jTextField1.setEditable(b); - jTextField1.setEnabled(b); - jTextField1.setFocusable(b); - } - private void updateCategoryCombo() { jComboBox1.removeAllItems(); for (String s: dict.getCategoryList()) {