2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.spellchecker
.options
;
18 import com
.intellij
.openapi
.Disposable
;
19 import com
.intellij
.openapi
.ui
.Messages
;
20 import com
.intellij
.spellchecker
.dictionary
.Dictionary
;
21 import com
.intellij
.spellchecker
.SpellCheckerManager
;
22 import com
.intellij
.spellchecker
.util
.SpellCheckerBundle
;
23 import com
.intellij
.spellchecker
.util
.Strings
;
24 import com
.intellij
.ui
.AddDeleteListPanel
;
25 import com
.intellij
.util
.containers
.HashSet
;
28 import javax
.swing
.event
.ChangeListener
;
29 import javax
.swing
.event
.ChangeEvent
;
30 import java
.util
.ArrayList
;
31 import java
.util
.Collections
;
32 import java
.util
.List
;
36 public class SpellCheckerOptions
implements Disposable
{
38 private final SpellCheckerConfiguration configuration
;
39 private final SpellCheckerManager manager
;
43 private WordsPanel userDictionaryWords
;
44 /*private WordsPanel ignoredWords;*/
45 private JRadioButton projectRB
;
46 private JRadioButton localRB
;
47 private JLabel globalDictionaries
;
49 private Dictionary shownDictionary
;
51 public Dictionary
getShownDictionary() {
52 return shownDictionary
;
55 public SpellCheckerOptions(SpellCheckerConfiguration configuration
, SpellCheckerManager manager
) {
56 this.configuration
= configuration
;
57 this.manager
= manager
;
60 private void createUIComponents() {
61 userDictionaryWords
= new WordsPanel(manager
.getProjectWordList().getWords(), manager
);
62 /*ignoredWords = new WordsPanel(manager.getProjectWordList().getIgnoredWords(), manager);*/
63 shownDictionary
= manager
.getProjectWordList();
67 public Set
<String
> getUserDictionaryWordsSet() {
68 return getWords(userDictionaryWords
);
71 public boolean useProjectDictionary() {
72 return projectRB
.isSelected();
75 public void setUserDictionaryWords(Set
<String
> words
) {
76 userDictionaryWords
.replaceAll(words
);
79 /*public Set<String> getIgnoredWords() {
80 return getWords(ignoredWords);
83 /* public void setIgnoredWords(Set<String> dictionary) {
84 ignoredWords.replaceAll(dictionary);
88 public JPanel
getRoot() {
89 projectRB
.setSelected(true);
90 projectRB
.addChangeListener(new ChangeListener() {
91 public void stateChanged(ChangeEvent e
) {
92 if (projectRB
.isSelected()) {
93 shownDictionary
= manager
.getProjectWordList();
94 userDictionaryWords
.replaceAll(shownDictionary
.getWords());
95 /*ignoredWords.replaceAll(shownDictionary.getIgnoredWords());*/
99 localRB
.addChangeListener(new ChangeListener() {
100 public void stateChanged(ChangeEvent e
) {
101 if (localRB
.isSelected()) {
102 shownDictionary
= manager
.getCachedWordList();
103 userDictionaryWords
.replaceAll(shownDictionary
.getWords());
104 /*ignoredWords.replaceAll(shownDictionary.getIgnoredWords());*/
109 if (manager
.getDictionaries() != null) {
110 String label
= "Global dictionaries: ";
111 for (String dic
: manager
.getDictionaries()) {
114 globalDictionaries
.setText(label
);
120 private static Set
<String
> getWords(AddDeleteListPanel panel
) {
121 Set
<String
> words
= new HashSet
<String
>();
122 Object
[] objects
= panel
.getListItems();
123 for (Object object
: objects
) {
124 words
.add((String
)object
);
130 public void dispose() {
131 userDictionaryWords
.dispose();
132 /*ignoredWords.dispose();*/
136 private static final class WordsPanel
extends AddDeleteListPanel
implements Disposable
{
137 private SpellCheckerManager manager
;
139 private WordsPanel(Set
<String
> words
, SpellCheckerManager manager
) {
140 super(null, sort(words
));
141 this.manager
= manager
;
144 private static List
<String
> sort(Set
<String
> words
) {
145 List
<String
> arrayList
= new ArrayList
<String
>(words
);
146 Collections
.sort(arrayList
);
152 protected Object
findItemToAdd() {
154 Messages
.showInputDialog(SpellCheckerBundle
.message("enter.simple.word"), SpellCheckerBundle
.message("add.new.word"), null);
162 if (Strings
.isMixedCase(word
)) {
163 Messages
.showWarningDialog(SpellCheckerBundle
.message("entered.word.0.is.mixed.cased.you.must.enter.simple.word", word
),
164 SpellCheckerBundle
.message("add.new.word"));
167 if (!manager
.hasProblem(word
)) {
168 Messages
.showWarningDialog(SpellCheckerBundle
.message("entered.word.0.is.correct.you.no.need.to.add.this.in.list", word
),
169 SpellCheckerBundle
.message("add.new.word"));
175 public void replaceAll(Set
<String
> words
) {
176 myList
.clearSelection();
177 myListModel
.removeAllElements();
178 for (String word
: sort(words
)) {
179 myListModel
.addElement(word
);
183 public void dispose() {
184 myListModel
.removeAllElements();