1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2000, 2010 IBM Corporation and others.
|
3
|
* All rights reserved. This program and the accompanying materials
|
4
|
* are made available under the terms of the Eclipse Public License v1.0
|
5
|
* which accompanies this distribution, and is available at
|
6
|
* http://www.eclipse.org/legal/epl-v10.html
|
7
|
*
|
8
|
* Contributors:
|
9
|
* IBM Corporation - initial API and implementation
|
10
|
*******************************************************************************/
|
11
|
package org.eclipse.gef.palette;
|
12
|
|
13
|
import org.eclipse.jface.resource.ImageDescriptor;
|
14
|
|
15
|
import org.eclipse.gef.SharedImages;
|
16
|
import org.eclipse.gef.internal.GEFMessages;
|
17
|
import org.eclipse.gef.tools.MarqueeSelectionTool;
|
18
|
|
19
|
/**
|
20
|
* A palette ToolEntry for a {@link org.eclipse.gef.tools.MarqueeSelectionTool}.
|
21
|
*
|
22
|
* @author rhudson
|
23
|
* @author pshah
|
24
|
* @author anyssen
|
25
|
*
|
26
|
* @since 2.1
|
27
|
*/
|
28
|
public class MarqueeToolEntry extends ToolEntry {
|
29
|
|
30
|
/**
|
31
|
* Creates a new MarqueeToolEntry that can select nodes
|
32
|
*/
|
33
|
public MarqueeToolEntry() {
|
34
|
this(null, null);
|
35
|
}
|
36
|
|
37
|
/**
|
38
|
* Constructor for MarqueeToolEntry.
|
39
|
*
|
40
|
* @param label
|
41
|
* the label
|
42
|
*/
|
43
|
public MarqueeToolEntry(String label) {
|
44
|
this(label, null);
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* Constructor for MarqueeToolEntry.
|
49
|
*
|
50
|
* @param label
|
51
|
* the label; can be <code>null</code>
|
52
|
* @param description
|
53
|
* the description (can be <code>null</code>)
|
54
|
*/
|
55
|
public MarqueeToolEntry(String label, String description) {
|
56
|
super(label, description, null, null, MarqueeSelectionTool.class);
|
57
|
if (label == null || label.length() == 0)
|
58
|
setLabel(GEFMessages.MarqueeTool_Label);
|
59
|
setUserModificationPermission(PERMISSION_NO_MODIFICATION);
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* @see org.eclipse.gef.palette.PaletteEntry#getDescription()
|
64
|
*/
|
65
|
public String getDescription() {
|
66
|
String description = super.getDescription();
|
67
|
if (description != null)
|
68
|
return description;
|
69
|
|
70
|
int marqueeBehavior = getMarqueeBehavior();
|
71
|
if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_TOUCHED) {
|
72
|
return GEFMessages.MarqueeTool_Connections_Touched_Desc;
|
73
|
}
|
74
|
if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_CONTAINED) {
|
75
|
return GEFMessages.MarqueeTool_Connections_Contained_Desc;
|
76
|
}
|
77
|
if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_TOUCHED) {
|
78
|
return GEFMessages.MarqueeTool_Nodes_Touched_Desc;
|
79
|
}
|
80
|
if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_CONTAINED) {
|
81
|
return GEFMessages.MarqueeTool_Nodes_Contained_Desc;
|
82
|
}
|
83
|
if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_TOUCHED_AND_RELATED_CONNECTIONS) {
|
84
|
return GEFMessages.MarqueeTool_Nodes_Touched_And_Related_Connections_Desc;
|
85
|
}
|
86
|
if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_CONTAINED_AND_RELATED_CONNECTIONS) {
|
87
|
return GEFMessages.MarqueeTool_Nodes_Contained_And_Related_Connections_Desc;
|
88
|
}
|
89
|
throw new IllegalArgumentException("Unknown marquee behavior"); //$NON-NLS-1$
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* @see org.eclipse.gef.palette.PaletteEntry#getLargeIcon()
|
94
|
*/
|
95
|
public ImageDescriptor getLargeIcon() {
|
96
|
ImageDescriptor imageDescriptor = super.getLargeIcon();
|
97
|
if (imageDescriptor != null) {
|
98
|
return imageDescriptor;
|
99
|
}
|
100
|
// infer icon from behavior mode
|
101
|
int marqueeBehavior = getMarqueeBehavior();
|
102
|
if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_CONTAINED
|
103
|
|| marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_TOUCHED) {
|
104
|
return SharedImages.DESC_MARQUEE_TOOL_CONNECTIONS_24;
|
105
|
} else if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_CONTAINED
|
106
|
|| marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_TOUCHED) {
|
107
|
return SharedImages.DESC_MARQUEE_TOOL_NODES_24;
|
108
|
} else {
|
109
|
return SharedImages.DESC_MARQUEE_TOOL_24;
|
110
|
}
|
111
|
}
|
112
|
|
113
|
private int getMarqueeBehavior() {
|
114
|
// retrieve marquee behavior from tool property
|
115
|
Object value = getToolProperty(MarqueeSelectionTool.PROPERTY_MARQUEE_BEHAVIOR);
|
116
|
if (value != null && value instanceof Integer) {
|
117
|
return ((Integer) value).intValue();
|
118
|
}
|
119
|
// return default behavior
|
120
|
return MarqueeSelectionTool.DEFAULT_MARQUEE_BEHAVIOR;
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* @see org.eclipse.gef.palette.PaletteEntry#getSmallIcon()
|
125
|
*/
|
126
|
public ImageDescriptor getSmallIcon() {
|
127
|
ImageDescriptor imageDescriptor = super.getSmallIcon();
|
128
|
if (imageDescriptor != null) {
|
129
|
return imageDescriptor;
|
130
|
}
|
131
|
// infer icon from marquee behavior
|
132
|
int marqueeBehavior = getMarqueeBehavior();
|
133
|
if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_CONTAINED
|
134
|
|| marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_CONNECTIONS_TOUCHED) {
|
135
|
return SharedImages.DESC_MARQUEE_TOOL_CONNECTIONS_16;
|
136
|
} else if (marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_CONTAINED
|
137
|
|| marqueeBehavior == MarqueeSelectionTool.BEHAVIOR_NODES_TOUCHED) {
|
138
|
return SharedImages.DESC_MARQUEE_TOOL_NODES_16;
|
139
|
} else {
|
140
|
return SharedImages.DESC_MARQUEE_TOOL_16;
|
141
|
}
|
142
|
}
|
143
|
|
144
|
}
|