sticky documentation popup [take 1]
[fedora-idea.git] / platform / platform-impl / src / com / intellij / ide / util / PropertiesComponentImpl.java
blob2ba64b19a7ad39b63a18becea19789c54062debf
1 /*
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.ide.util;
18 import com.intellij.openapi.components.*;
19 import com.intellij.util.containers.HashMap;
20 import org.jdom.Element;
21 import org.jetbrains.annotations.NonNls;
22 import org.jetbrains.annotations.NotNull;
25 public class PropertiesComponentImpl extends PropertiesComponent
26 implements PersistentStateComponent<Element> {
27 private final HashMap<String, String> myMap = new HashMap<String, String>();
28 @NonNls private static final String ELEMENT_PROPERTY = "property";
29 @NonNls private static final String ATTRIBUTE_NAME = "name";
30 @NonNls private static final String ATTRIBUTE_VALUE = "value";
33 @NotNull
34 public String getComponentName() {
35 return "PropertiesComponent";
38 PropertiesComponentImpl() {
43 public Element getState() {
44 Element parentNode = new Element("state");
45 for (final String key : myMap.keySet()) {
46 String value = myMap.get(key);
47 if (value != null) {
48 Element element = new Element(ELEMENT_PROPERTY);
49 element.setAttribute(ATTRIBUTE_NAME, key);
50 element.setAttribute(ATTRIBUTE_VALUE, value);
51 parentNode.addContent(element);
54 return parentNode;
57 public void loadState(final Element parentNode) {
58 myMap.clear();
59 for (final Object o : parentNode.getChildren(ELEMENT_PROPERTY)) {
60 Element e = (Element)o;
62 String name = e.getAttributeValue(ATTRIBUTE_NAME);
63 String value = e.getAttributeValue(ATTRIBUTE_VALUE);
65 if (name != null) {
66 myMap.put(name, value);
71 public String getValue(String name) {
72 return myMap.get(name);
75 public void setValue(String name, String value) {
76 myMap.put(name, value);
79 public boolean isValueSet(String name) {
80 return myMap.containsKey(name);