2
* FreeMind - A Program for creating and viewing Mindmaps Copyright (C)
3
* 2000-2004 Joerg Mueller, Daniel Polansky, Christian Foltin and others.
5
* See COPYING for Details
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
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
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.
21
* Created on 19.09.2004
23
/* $Id: CloudColorAction.java,v 1.1.2.2 2006/02/15 21:18:45 christianfoltin Exp $ */
25
package freemind.modes.mindmapmode.actions;
27
import java.awt.Color;
28
import java.awt.event.ActionEvent;
29
import java.util.ListIterator;
31
import javax.swing.Action;
32
import javax.swing.JMenuItem;
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;
46
public class CloudColorAction extends FreemindAction implements ActorXml , MenuItemEnabledListener{
47
private final MindMapController controller;
49
public CloudColorAction(MindMapController controller) {
50
super("cloud_color", "images/Colors24.gif", controller);
51
this.controller = controller;
52
controller.getActionFactory().registerActor(this, getDoActionClass());
55
public void actionPerformed(ActionEvent e) {
56
Color selectedColor = null;
57
if(controller.getSelected().getCloud() != null) {
58
selectedColor = controller.getSelected().getCloud().getColor();
60
Color color = Controller.showCommonJColorChooserDialog(controller
61
.getView().getSelected(), controller.getText("choose_cloud_color"), selectedColor);
65
for (ListIterator it = controller.getSelecteds().listIterator(); it
67
MindMapNodeModel selected = (MindMapNodeModel) it.next();
68
setCloudColor(selected, color);
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());
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));
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);
97
Color selectedColor = null;
98
if(node.getCloud() != null) {
99
selectedColor = node.getCloud().getColor();
101
if (!Tools.safeEquals(color, selectedColor)) {
102
((LineAdapter) node.getCloud()).setColor(color); // null
103
controller.nodeChanged(node);
108
public Class getDoActionClass() {
109
return CloudColorXmlAction.class;
115
public boolean isEnabled(JMenuItem item, Action action) {
116
return (controller != null) &&(controller.getSelected() != null) && (controller.getSelected().getCloud() != null);
b'\\ No newline at end of file'