~ubuntu-branches/ubuntu/utopic/freemind/utopic

« back to all changes in this revision

Viewing changes to freemind/freemind/common/ScriptEditorProperty.java

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-01-03 14:19:19 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100103141919-m5az7dkicy21hqop
Tags: 0.9.0~rc6+dfsg-1ubuntu1
* Merge from Debian unstable (LP: #182927), remaining changes:
  - debian/copyright: add license/copyright for
    freemind/freemind/main/ExampleFileFilter.java

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*FreeMind - A Program for creating and viewing Mindmaps
 
2
 *Copyright (C) 2000-2006  Joerg Mueller, Daniel Polansky, Christian Foltin and others.
 
3
 *
 
4
 *See COPYING for Details
 
5
 *
 
6
 *This program is free software; you can redistribute it and/or
 
7
 *modify it under the terms of the GNU General Public License
 
8
 *as published by the Free Software Foundation; either version 2
 
9
 *of the License, or (at your option) any later version.
 
10
 *
 
11
 *This program is distributed in the hope that it will be useful,
 
12
 *but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *GNU General Public License for more details.
 
15
 *
 
16
 *You should have received a copy of the GNU General Public License
 
17
 *along with this program; if not, write to the Free Software
 
18
 *Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
 *
 
20
 * Created on 25.02.2006
 
21
 */
 
22
/*$Id: ScriptEditorProperty.java,v 1.1.2.6 2008/07/04 20:44:02 christianfoltin Exp $*/
 
23
package freemind.common;
 
24
 
 
25
import java.awt.event.ActionEvent;
 
26
import java.awt.event.ActionListener;
 
27
import java.util.Iterator;
 
28
 
 
29
import javax.swing.JButton;
 
30
import javax.swing.JLabel;
 
31
import javax.swing.JPopupMenu;
 
32
 
 
33
import com.jgoodies.forms.builder.DefaultFormBuilder;
 
34
 
 
35
import freemind.main.HtmlTools;
 
36
import freemind.modes.mindmapmode.MindMapController;
 
37
import freemind.modes.mindmapmode.MindMapController.MindMapControllerPlugin;
 
38
 
 
39
public class ScriptEditorProperty extends PropertyBean implements
 
40
                PropertyControl, ActionListener {
 
41
 
 
42
        public interface ScriptEditorStarter extends MindMapControllerPlugin {
 
43
                String startEditor(String scriptInput);
 
44
        }
 
45
 
 
46
        String description;
 
47
 
 
48
        String label;
 
49
 
 
50
        String script;
 
51
 
 
52
        JButton mButton;
 
53
        final JPopupMenu menu = new JPopupMenu();
 
54
 
 
55
        private final MindMapController mMindMapController;
 
56
 
 
57
        private static java.util.logging.Logger logger = null;
 
58
 
 
59
        /**
 
60
         */
 
61
        public ScriptEditorProperty(String description, String label,
 
62
                        MindMapController pMindMapController) {
 
63
                super();
 
64
                this.description = description;
 
65
                this.label = label;
 
66
                mMindMapController = pMindMapController;
 
67
                if (logger == null) {
 
68
                        logger = mMindMapController.getFrame().getLogger(
 
69
                                        this.getClass().getName());
 
70
                }
 
71
                mButton = new JButton();
 
72
                mButton.addActionListener(this);
 
73
                script = "";
 
74
        }
 
75
 
 
76
        public String getDescription() {
 
77
                return description;
 
78
        }
 
79
 
 
80
        public String getLabel() {
 
81
                return label;
 
82
        }
 
83
 
 
84
        public void setValue(String value) {
 
85
                setScriptValue(value);
 
86
        }
 
87
 
 
88
        public String getValue() {
 
89
                return HtmlTools.unicodeToHTMLUnicodeEntity(HtmlTools.toXMLEscapedText(script));
 
90
        }
 
91
 
 
92
        public void layout(DefaultFormBuilder builder, TextTranslator pTranslator) {
 
93
                JLabel label = builder.append(pTranslator.getText(getLabel()), mButton);
 
94
                label.setToolTipText(pTranslator.getText(getDescription()));
 
95
        }
 
96
 
 
97
        public void actionPerformed(ActionEvent arg0) {
 
98
                // search for plugin that handles the script editor.
 
99
                for (Iterator iter = mMindMapController.getPlugins().iterator(); iter
 
100
                                .hasNext();) {
 
101
                        MindMapControllerPlugin plugin = (MindMapControllerPlugin) iter
 
102
                                        .next();
 
103
                        if (plugin instanceof ScriptEditorStarter) {
 
104
                                ScriptEditorStarter starter = (ScriptEditorStarter) plugin;
 
105
                                String resultScript = starter.startEditor(script);
 
106
                                if (resultScript != null) {
 
107
                                        script = resultScript;
 
108
                                        firePropertyChangeEvent();
 
109
                                }
 
110
                        }
 
111
                }
 
112
        }
 
113
 
 
114
        /**
 
115
         */
 
116
        private void setScriptValue(String result) {
 
117
                if (result == null) {
 
118
                        result = "";
 
119
                }
 
120
                script = HtmlTools.toXMLUnescapedText(HtmlTools.unescapeHTMLUnicodeEntity(result));
 
121
                logger.fine("Setting script to " +script);
 
122
                mButton.setText(script);
 
123
        }
 
124
 
 
125
        // /**
 
126
        // */
 
127
        // private Color getColorValue() {
 
128
        // return color;
 
129
        // }
 
130
 
 
131
        public void setEnabled(boolean pEnabled) {
 
132
                mButton.setEnabled(pEnabled);
 
133
        }
 
134
 
 
135
}