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

« back to all changes in this revision

Viewing changes to freemind/freemind/modes/mindmapmode/actions/CloudColorAction.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
/*
 
2
 * FreeMind - A Program for creating and viewing Mindmaps Copyright (C)
 
3
 * 2000-2004 Joerg Mueller, Daniel Polansky, Christian Foltin and others.
 
4
 * 
 
5
 * See COPYING for Details
 
6
 * 
 
7
 * This program is free software; you can redistribute it and/or modify it under
 
8
 * the terms of the GNU General Public License as published by the Free Software
 
9
 * Foundation; either version 2 of the License, or (at your option) any later
 
10
 * version.
 
11
 * 
 
12
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
14
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 
15
 * details.
 
16
 * 
 
17
 * You should have received a copy of the GNU General Public License along with
 
18
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
19
 * Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 * 
 
21
 * Created on 19.09.2004
 
22
 */
 
23
/* $Id: CloudColorAction.java,v 1.1.2.2 2006/02/15 21:18:45 christianfoltin Exp $ */
 
24
 
 
25
package freemind.modes.mindmapmode.actions;
 
26
 
 
27
import java.awt.Color;
 
28
import java.awt.event.ActionEvent;
 
29
import java.util.ListIterator;
 
30
 
 
31
import javax.swing.Action;
 
32
import javax.swing.JMenuItem;
 
33
 
 
34
import freemind.controller.Controller;
 
35
import freemind.controller.MenuItemEnabledListener;
 
36
import freemind.controller.actions.generated.instance.CloudColorXmlAction;
 
37
import freemind.controller.actions.generated.instance.XmlAction;
 
38
import freemind.main.Tools;
 
39
import freemind.modes.LineAdapter;
 
40
import freemind.modes.MindMapNode;
 
41
import freemind.modes.mindmapmode.MindMapController;
 
42
import freemind.modes.mindmapmode.MindMapNodeModel;
 
43
import freemind.modes.mindmapmode.actions.xml.ActionPair;
 
44
import freemind.modes.mindmapmode.actions.xml.ActorXml;
 
45
 
 
46
public class CloudColorAction extends FreemindAction implements ActorXml , MenuItemEnabledListener{
 
47
    private final MindMapController controller;
 
48
 
 
49
    public CloudColorAction(MindMapController controller) {
 
50
        super("cloud_color", "images/Colors24.gif", controller);
 
51
        this.controller = controller;
 
52
        controller.getActionFactory().registerActor(this, getDoActionClass());
 
53
    }
 
54
 
 
55
    public void actionPerformed(ActionEvent e) {
 
56
        Color selectedColor =  null;
 
57
        if(controller.getSelected().getCloud() != null) {
 
58
            selectedColor = controller.getSelected().getCloud().getColor();
 
59
        }
 
60
        Color color = Controller.showCommonJColorChooserDialog(controller
 
61
                .getView().getSelected(), controller.getText("choose_cloud_color"), selectedColor);
 
62
        if (color == null) {
 
63
            return;
 
64
        }
 
65
        for (ListIterator it = controller.getSelecteds().listIterator(); it
 
66
                .hasNext();) {
 
67
            MindMapNodeModel selected = (MindMapNodeModel) it.next();
 
68
            setCloudColor(selected, color); 
 
69
        }
 
70
    }
 
71
    
 
72
    public void setCloudColor(MindMapNode node, Color color) {
 
73
                CloudColorXmlAction doAction = createCloudColorXmlAction(node, color);
 
74
        CloudColorXmlAction undoAction = createCloudColorXmlAction(node, 
 
75
                (node.getCloud()==null)?null:node.getCloud().getColor());
 
76
        controller.getActionFactory().startTransaction(this.getClass().getName());
 
77
        controller.getActionFactory().executeAction(new ActionPair(doAction, undoAction));
 
78
        controller.getActionFactory().endTransaction(this.getClass().getName());
 
79
    }
 
80
 
 
81
    public CloudColorXmlAction createCloudColorXmlAction(MindMapNode node, Color color)  {
 
82
                CloudColorXmlAction nodeAction = new CloudColorXmlAction();
 
83
                nodeAction.setNode(node.getObjectId(controller));
 
84
            nodeAction.setColor(Tools.colorToXml(color));
 
85
                return nodeAction;
 
86
    }
 
87
    
 
88
    public void act(XmlAction action) {
 
89
                if (action instanceof CloudColorXmlAction) {
 
90
                        CloudColorXmlAction nodeColorAction = (CloudColorXmlAction) action;
 
91
                        Color color = Tools.xmlToColor(nodeColorAction.getColor());
 
92
                        MindMapNode node = controller.getNodeFromID(nodeColorAction.getNode());
 
93
                        // this is not necessary, as this action is not enabled if there is no cloud.
 
94
                        if(node.getCloud()==null) {
 
95
                            controller.setCloud(node, true);
 
96
                        }
 
97
                Color selectedColor =  null;
 
98
                if(node.getCloud() != null) {
 
99
                    selectedColor = node.getCloud().getColor();
 
100
                }
 
101
                        if (!Tools.safeEquals(color, selectedColor)) {
 
102
                ((LineAdapter) node.getCloud()).setColor(color); // null
 
103
                controller.nodeChanged(node);
 
104
            }
 
105
                }
 
106
   }
 
107
 
 
108
    public Class getDoActionClass() {
 
109
        return CloudColorXmlAction.class;
 
110
    }
 
111
    /**
 
112
     *
 
113
     */
 
114
 
 
115
    public boolean isEnabled(JMenuItem item, Action action) {
 
116
        return (controller != null) &&(controller.getSelected() != null) && (controller.getSelected().getCloud() != null);
 
117
    }
 
118
 
 
119
}
 
 
b'\\ No newline at end of file'