KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > status > ShowTextAnnotationsAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.subversion.ui.status;
21
22 import org.openide.util.NbBundle;
23 import org.openide.util.HelpCtx;
24 import org.openide.util.actions.SystemAction;
25 import org.openide.awt.DynamicMenuContent;
26 import org.openide.awt.Mnemonics;
27 import org.netbeans.modules.subversion.SvnModuleConfig;
28
29 import javax.swing.*;
30 import java.awt.event.ActionEvent JavaDoc;
31 import java.util.prefs.Preferences JavaDoc;
32
33 /**
34  * View menu action that shows/hides textual Subversion annotations.
35  *
36  * @author Maros Sandor
37  */

38 public class ShowTextAnnotationsAction extends SystemAction implements DynamicMenuContent {
39
40     private JCheckBoxMenuItem [] menuItems;
41     
42     public JComponent[] getMenuPresenters() {
43         createItems();
44         updateState();
45         return menuItems;
46     }
47
48     public JComponent[] synchMenuPresenters(JComponent[] items) {
49         updateState();
50         return items;
51     }
52     
53     private void updateState() {
54         String JavaDoc taf = SvnModuleConfig.getDefault().getPreferences().get(SvnModuleConfig.PROP_TEXT_ANNOTATIONS_FORMAT, null);
55         menuItems[0].setSelected(taf != null);
56     }
57     
58     private void createItems() {
59         if (menuItems == null) {
60             menuItems = new JCheckBoxMenuItem[1];
61             menuItems[0] = new JCheckBoxMenuItem(this);
62             menuItems[0].setIcon(null);
63             Mnemonics.setLocalizedText(menuItems[0], NbBundle.getMessage(ShowTextAnnotationsAction.class, "CTL_MenuItem_ShowTextAnnotations"));
64         }
65     }
66
67     public String JavaDoc getName() {
68         return NbBundle.getMessage(ShowTextAnnotationsAction.class, "CTL_MenuItem_ShowTextAnnotations");
69     }
70
71     public boolean isEnabled() {
72         return true;
73     }
74     
75     public HelpCtx getHelpCtx() {
76         return new HelpCtx(ShowTextAnnotationsAction.class);
77     }
78
79     public void actionPerformed(ActionEvent JavaDoc e) {
80         Preferences JavaDoc prefs = SvnModuleConfig.getDefault().getPreferences();
81         String JavaDoc taf = prefs.get(SvnModuleConfig.PROP_TEXT_ANNOTATIONS_FORMAT, null);
82         if (taf == null) {
83             prefs.put(SvnModuleConfig.PROP_TEXT_ANNOTATIONS_FORMAT, SvnModuleConfig.TEXT_ANNOTATIONS_FORMAT_DEFAULT);
84         } else {
85             prefs.remove(SvnModuleConfig.PROP_TEXT_ANNOTATIONS_FORMAT);
86         }
87     }
88 }
89
Popular Tags