Skip to content

Commit

Permalink
Category list update refa
Browse files Browse the repository at this point in the history
  • Loading branch information
berk76 committed Feb 6, 2021
1 parent 8f843c8 commit cfa2749
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
5 changes: 1 addition & 4 deletions src/main/java/cz/webstones/words/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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 {
Expand All @@ -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()) {
Expand Down
45 changes: 31 additions & 14 deletions src/main/java/cz/webstones/words/RenameCategoryDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -34,24 +51,24 @@ public String getNewCategoryText() {
return jTextField1.getText();
}

public void setCategoryList(ArrayList<String> 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());
}

/**
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/cz/webstones/words/WordDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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()) {
Expand Down

0 comments on commit cfa2749

Please sign in to comment.