Skip to content

Commit ff65a9e

Browse files
committedDec 7, 2012
Include preview mouse listeners support and bug fixes implemented in legend project.
1 parent 3cef860 commit ff65a9e

File tree

10 files changed

+1081
-670
lines changed

10 files changed

+1081
-670
lines changed
 

‎modules/PreviewAPI/src/main/java/org/gephi/preview/PreviewControllerImpl.java

+76-20
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,13 @@ Development and Distribution License("CDDL") (collectively, the
4343

4444
import java.awt.Dimension;
4545
import java.awt.Point;
46+
import java.util.ArrayList;
4647
import java.util.LinkedHashMap;
4748
import org.gephi.data.attributes.api.AttributeController;
4849
import org.gephi.data.attributes.api.AttributeModel;
4950
import org.gephi.graph.api.*;
5051
import org.gephi.preview.api.*;
51-
import org.gephi.preview.spi.ItemBuilder;
52-
import org.gephi.preview.spi.RenderTargetBuilder;
53-
import org.gephi.preview.spi.Renderer;
52+
import org.gephi.preview.spi.*;
5453
import org.gephi.project.api.ProjectController;
5554
import org.gephi.project.api.Workspace;
5655
import org.gephi.project.api.WorkspaceListener;
@@ -150,7 +149,21 @@ public synchronized void refreshPreview(Workspace workspace) {
150149
}
151150
}
152151

153-
Renderer[] renderers = model.getManagedEnabledRenderers();
152+
Renderer[] renderers;
153+
if (!mousePressed) {
154+
renderers = model.getManagedEnabledRenderers();
155+
} else {
156+
ArrayList<Renderer> renderersList = new ArrayList<Renderer>();
157+
for(Renderer renderer: model.getManagedEnabledRenderers()){
158+
//Only mouse responsive renderers will be called while mouse is pressed
159+
if(renderer instanceof MouseResponsiveRenderer){
160+
renderersList.add(renderer);
161+
}
162+
}
163+
164+
renderers = renderersList.toArray(new Renderer[0]);
165+
}
166+
154167
if (renderers == null) {
155168
renderers = getRegisteredRenderers();
156169
}
@@ -250,25 +263,24 @@ public void render(RenderTarget target, Renderer[] renderers) {
250263

251264
@Override
252265
public void render(RenderTarget target, Renderer[] renderers, Workspace workspace) {
253-
render(target, renderers, getModel(workspace));
266+
render(target, renderers != null ? renderers : getModel(workspace).getManagedEnabledRenderers(), getModel(workspace));
254267
}
255268

256269
private synchronized void render(RenderTarget target, Renderer[] renderers, PreviewModelImpl previewModel) {
257270
if (previewModel != null) {
258-
if (renderers == null) {
259-
renderers = getRegisteredRenderers();
260-
}
261271
PreviewProperties properties = previewModel.getProperties();
262272

263273
//Progress
264274
ProgressTicket progressTicket = null;
265275
if (target instanceof AbstractRenderTarget) {
266276
int tasks = 0;
267277
for (Renderer r : renderers) {
268-
for (String type : previewModel.getItemTypes()) {
269-
for (Item item : previewModel.getItems(type)) {
270-
if (r.isRendererForitem(item, properties)) {
271-
tasks++;
278+
if (!mousePressed || r instanceof MouseResponsiveRenderer) {
279+
for (String type : previewModel.getItemTypes()) {
280+
for (Item item : previewModel.getItems(type)) {
281+
if (r.isRendererForitem(item, properties)) {
282+
tasks++;
283+
}
272284
}
273285
}
274286
}
@@ -280,14 +292,16 @@ private synchronized void render(RenderTarget target, Renderer[] renderers, Prev
280292

281293
//Render items
282294
for (Renderer r : renderers) {
283-
for (String type : previewModel.getItemTypes()) {
284-
for (Item item : previewModel.getItems(type)) {
285-
if (r.isRendererForitem(item, properties)) {
286-
r.render(item, target, properties);
287-
Progress.progress(progressTicket);
288-
if (target instanceof AbstractRenderTarget) {
289-
if (((AbstractRenderTarget) target).isCancelled()) {
290-
return;
295+
if (!mousePressed || r instanceof MouseResponsiveRenderer) {
296+
for (String type : previewModel.getItemTypes()) {
297+
for (Item item : previewModel.getItems(type)) {
298+
if (r.isRendererForitem(item, properties)) {
299+
r.render(item, target, properties);
300+
Progress.progress(progressTicket);
301+
if (target instanceof AbstractRenderTarget) {
302+
if (((AbstractRenderTarget) target).isCancelled()) {
303+
return;
304+
}
291305
}
292306
}
293307
}
@@ -373,4 +387,46 @@ public boolean isAnyPluginRendererRegistered() {
373387
}
374388
return anyPluginRendererRegistered;
375389
}
390+
private boolean mousePressed = false;
391+
392+
@Override
393+
public boolean sendMouseEvent(PreviewMouseEvent event){
394+
return sendMouseEvent(event, Lookup.getDefault().lookup(ProjectController.class).getCurrentWorkspace());
395+
}
396+
397+
@Override
398+
public boolean sendMouseEvent(PreviewMouseEvent event, Workspace workspace) {
399+
if(workspace == null){
400+
return false;
401+
}
402+
403+
PreviewModel previewModel = getModel(workspace);
404+
405+
//Avoid drag events arriving to listeners if they did not consume previous press event.
406+
if ((event.type != PreviewMouseEvent.Type.DRAGGED && event.type != PreviewMouseEvent.Type.RELEASED) || mousePressed) {
407+
for (PreviewMouseListener listener : previewModel.getEnabledMouseListeners()) {
408+
switch (event.type) {
409+
case CLICKED:
410+
listener.mouseClicked(event, previewModel.getProperties(), workspace);
411+
break;
412+
case PRESSED:
413+
mousePressed = true;
414+
listener.mousePressed(event, previewModel.getProperties(), workspace);
415+
break;
416+
case DRAGGED:
417+
listener.mouseDragged(event, previewModel.getProperties(), workspace);
418+
break;
419+
case RELEASED:
420+
mousePressed = false;
421+
listener.mouseReleased(event, previewModel.getProperties(), workspace);
422+
}
423+
if (event.isConsumed()) {
424+
return true;
425+
}
426+
}
427+
}
428+
429+
mousePressed = false;//Avoid drag events arriving to listeners if they did not consume previous press event.
430+
return false;
431+
}
376432
}

‎modules/PreviewAPI/src/main/java/org/gephi/preview/PreviewModelImpl.java

+528-499
Large diffs are not rendered by default.

‎modules/PreviewAPI/src/main/java/org/gephi/preview/ProcessingApplet.java

+74-12
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,11 @@ Development and Distribution License("CDDL") (collectively, the
4545
import java.awt.Dimension;
4646
import java.awt.Font;
4747
import java.awt.Point;
48-
import java.awt.event.MouseWheelEvent;
49-
import java.awt.event.MouseWheelListener;
48+
import java.awt.event.*;
5049
import java.util.HashMap;
5150
import java.util.Timer;
5251
import java.util.TimerTask;
53-
import org.gephi.preview.api.PreviewController;
54-
import org.gephi.preview.api.PreviewModel;
55-
import org.gephi.preview.api.PreviewProperty;
56-
import org.gephi.preview.api.RenderTarget;
52+
import org.gephi.preview.api.*;
5753
import org.openide.util.Lookup;
5854
import processing.core.PApplet;
5955
import processing.core.PFont;
@@ -143,24 +139,90 @@ protected void resizeRenderer(int i, int i1) {
143139
super.resizeRenderer(i, i1);
144140
}
145141
}
142+
143+
private PVector screenPositionToModelPosition(PVector screenPos) {
144+
PVector center = new PVector(width / 2f, height / 2f);
145+
PVector scaledCenter = PVector.mult(center, scaling);
146+
PVector scaledTrans = PVector.sub(center, scaledCenter);
147+
148+
PVector modelPos = new PVector(screenPos.x, screenPos.y);
149+
modelPos.sub(scaledTrans);
150+
modelPos.div(scaling);
151+
modelPos.sub(trans);
152+
return modelPos;
153+
}
154+
155+
private PVector getMouseModelPosition(){
156+
return screenPositionToModelPosition(new PVector(mouseX, mouseY));
157+
}
158+
159+
private PreviewMouseEvent buildPreviewMouseEvent(PreviewMouseEvent.Type type){
160+
PVector pos = getMouseModelPosition();
161+
PreviewMouseEvent.Button button;
162+
163+
switch(mouseButton){
164+
case CENTER:
165+
button = PreviewMouseEvent.Button.MIDDLE;
166+
break;
167+
case RIGHT:
168+
button = PreviewMouseEvent.Button.RIGHT;
169+
break;
170+
case LEFT:
171+
default:
172+
button = PreviewMouseEvent.Button.LEFT;
173+
}
174+
175+
return new PreviewMouseEvent((int)pos.x, (int)pos.y, type, button, keyEvent);
176+
}
146177

147178
@Override
148-
public void mousePressed() {
149-
ref.set(mouseX, mouseY, 0);
179+
public void mouseClicked() {
180+
if (previewController.sendMouseEvent(buildPreviewMouseEvent(PreviewMouseEvent.Type.CLICKED))) {
181+
previewController.refreshPreview();
182+
redraw();
183+
}
150184
}
151185

186+
@Override
187+
public void mousePressed() {
188+
previewController.sendMouseEvent(buildPreviewMouseEvent(PreviewMouseEvent.Type.PRESSED));
189+
190+
previewController.refreshPreview();
191+
handleMousePress();
192+
redraw();
193+
}
194+
152195
@Override
153196
public void mouseDragged() {
197+
if (!previewController.sendMouseEvent(buildPreviewMouseEvent(PreviewMouseEvent.Type.DRAGGED))) {
198+
handleMouseDrag();
199+
}
200+
redraw();
201+
}
202+
203+
@Override
204+
public void mouseReleased() {
205+
if (!previewController.sendMouseEvent(buildPreviewMouseEvent(PreviewMouseEvent.Type.RELEASED))) {
206+
handleMouseRelease();
207+
}
208+
209+
previewController.refreshPreview();
210+
redraw();
211+
}
212+
213+
private void handleMousePress(){
214+
ref.set(mouseX, mouseY, 0);
215+
}
216+
217+
private void handleMouseDrag(){
154218
setMoving(true);
155219
trans.set(mouseX, mouseY, 0);
156220
trans.sub(ref);
157221
trans.div(scaling); // ensure const. moving speed whatever the zoom is
158222
trans.add(lastMove);
159-
redraw();
160223
}
161-
162-
@Override
163-
public void mouseReleased() {
224+
225+
private void handleMouseRelease() {
164226
lastMove.set(trans);
165227
setMoving(false);
166228
redraw();

‎modules/PreviewAPI/src/main/java/org/gephi/preview/api/PreviewController.java

+15
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,19 @@ public interface PreviewController {
169169
* @return True if any plugin renderer is found in the system
170170
*/
171171
public boolean isAnyPluginRendererRegistered();
172+
173+
/**
174+
* Sends a <code>PreviewMouseEvent</code> to the current workspace, if any.
175+
* @param event PreviewMouseEvent
176+
* @return True if the event was consumed, false otherwise
177+
*/
178+
public boolean sendMouseEvent(PreviewMouseEvent event);
179+
180+
/**
181+
* Sends a <code>PreviewMouseEvent</code> to the given workspace.
182+
* @param event PreviewMouseEvent
183+
* @param workspace
184+
* @return True if the event was consumed, false otherwise
185+
*/
186+
public boolean sendMouseEvent(PreviewMouseEvent event, Workspace workspace);
172187
}

‎modules/PreviewAPI/src/main/java/org/gephi/preview/api/PreviewModel.java

+84-78
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
/*
2-
Copyright 2008-2011 Gephi
3-
Authors : Yudi Xue <yudi.xue@usask.ca>, Mathieu Bastian
4-
Website : http://www.gephi.org
5-
6-
This file is part of Gephi.
7-
8-
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9-
10-
Copyright 2011 Gephi Consortium. All rights reserved.
11-
12-
The contents of this file are subject to the terms of either the GNU
13-
General Public License Version 3 only ("GPL") or the Common
14-
Development and Distribution License("CDDL") (collectively, the
15-
"License"). You may not use this file except in compliance with the
16-
License. You can obtain a copy of the License at
17-
http://gephi.org/about/legal/license-notice/
18-
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
19-
specific language governing permissions and limitations under the
20-
License. When distributing the software, include this License Header
21-
Notice in each file and include the License files at
22-
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
23-
License Header, with the fields enclosed by brackets [] replaced by
24-
your own identifying information:
25-
"Portions Copyrighted [year] [name of copyright owner]"
26-
27-
If you wish your version of this file to be governed by only the CDDL
28-
or only the GPL Version 3, indicate your decision by adding
29-
"[Contributor] elects to include this software in this distribution
30-
under the [CDDL or GPL Version 3] license." If you do not indicate a
31-
single choice of license, a recipient has the option to distribute
32-
your version of this file under either the CDDL, the GPL Version 3 or
33-
to extend the choice of license to its licensees as provided above.
34-
However, if you add GPL Version 3 code and therefore, elected the GPL
35-
Version 3 license, then the option applies only if the new code is
36-
made subject to such option by the copyright holder.
37-
38-
Contributor(s):
39-
40-
Portions Copyrighted 2011 Gephi Consortium.
2+
Copyright 2008-2011 Gephi
3+
Authors : Yudi Xue <yudi.xue@usask.ca>, Mathieu Bastian
4+
Website : http://www.gephi.org
5+
6+
This file is part of Gephi.
7+
8+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9+
10+
Copyright 2011 Gephi Consortium. All rights reserved.
11+
12+
The contents of this file are subject to the terms of either the GNU
13+
General Public License Version 3 only ("GPL") or the Common
14+
Development and Distribution License("CDDL") (collectively, the
15+
"License"). You may not use this file except in compliance with the
16+
License. You can obtain a copy of the License at
17+
http://gephi.org/about/legal/license-notice/
18+
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
19+
specific language governing permissions and limitations under the
20+
License. When distributing the software, include this License Header
21+
Notice in each file and include the License files at
22+
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
23+
License Header, with the fields enclosed by brackets [] replaced by
24+
your own identifying information:
25+
"Portions Copyrighted [year] [name of copyright owner]"
26+
27+
If you wish your version of this file to be governed by only the CDDL
28+
or only the GPL Version 3, indicate your decision by adding
29+
"[Contributor] elects to include this software in this distribution
30+
under the [CDDL or GPL Version 3] license." If you do not indicate a
31+
single choice of license, a recipient has the option to distribute
32+
your version of this file under either the CDDL, the GPL Version 3 or
33+
to extend the choice of license to its licensees as provided above.
34+
However, if you add GPL Version 3 code and therefore, elected the GPL
35+
Version 3 license, then the option applies only if the new code is
36+
made subject to such option by the copyright holder.
37+
38+
Contributor(s):
39+
40+
Portions Copyrighted 2011 Gephi Consortium.
4141
*/
4242
package org.gephi.preview.api;
4343

@@ -47,19 +47,15 @@ Development and Distribution License("CDDL") (collectively, the
4747
import org.gephi.graph.api.Graph;
4848
import org.gephi.graph.api.Node;
4949
import org.gephi.preview.spi.ItemBuilder;
50+
import org.gephi.preview.spi.PreviewMouseListener;
5051
import org.gephi.preview.spi.Renderer;
5152

5253
/**
53-
* The Preview Model contains all items and all preview properties.
54-
* <p>
55-
* Items are the visual elements built from the {@link Graph} by {@link ItemBuilder}
56-
* implementations and can be retrieved from this class. Each item has a type and
57-
* default types are {@link Item#NODE}, {@link Item#EDGE}, {@link Item#NODE_LABEL}
58-
* and {@link Item#EDGE_LABEL}.
59-
* <p>
60-
* A preview model is attached to it's workspace and can be retrieved from the
54+
* The Preview Model contains all items and all preview properties. <p> Items are the visual elements built from the {@link Graph} by {@link ItemBuilder} implementations and can be retrieved from this
55+
* class. Each item has a type and default types are {@link Item#NODE}, {@link Item#EDGE}, {@link Item#NODE_LABEL} and {@link Item#EDGE_LABEL}. <p> A preview model is attached to it's workspace and
56+
* can be retrieved from the
6157
* {@link PreviewController}.
62-
*
58+
*
6359
* @author Yudi Xue, Mathieu Bastian
6460
* @see Item
6561
* @see Renderer
@@ -68,78 +64,88 @@ public interface PreviewModel {
6864

6965
/**
7066
* Returns the preview properties attached to this model.
67+
*
7168
* @return the preview properties
7269
*/
7370
public PreviewProperties getProperties();
7471

7572
/**
76-
* Returns all items with <code>type</code> as type.
77-
* <p>
78-
* Default types are {@link Item#NODE}, {@link Item#EDGE}, {@link Item#NODE_LABEL}
79-
* and {@link Item#EDGE_LABEL}.
73+
* Returns all items with
74+
* <code>type</code> as type. <p> Default types are {@link Item#NODE}, {@link Item#EDGE}, {@link Item#NODE_LABEL} and {@link Item#EDGE_LABEL}.
75+
*
8076
* @param type the item's type
8177
* @return all items from this type
8278
*/
8379
public Item[] getItems(String type);
8480

8581
/**
86-
* Returns all items attached to <code>source</code>.
87-
* <p>
88-
* The source is the graph object behind the item (e.g.
89-
* {@link Node} or {@link Edge}). Multiple items can be created from the same
90-
* source object. For instance both <code>Item.NODE</code> and
82+
* Returns all items attached to
83+
* <code>source</code>. <p> The source is the graph object behind the item (e.g.
84+
* {@link Node} or {@link Edge}). Multiple items can be created from the same source object. For instance both
85+
* <code>Item.NODE</code> and
9186
* <code>Item.NODE_LABEL</code> have the node object as source.
87+
*
9288
* @param source the item's source
93-
* @return all items with <code>source</code> as source
89+
* @return all items with
90+
* <code>source</code> as source
9491
*/
9592
public Item[] getItems(Object source);
9693

9794
/**
98-
* Returns the item attached to <code>source</code> and with the type
99-
* <code>type</code>.
100-
* <p>
101-
* The source is the graph object behind the item (e.g.
102-
* {@link Node} or {@link Edge}) and the type a default or a custom type.
103-
* <p>
104-
* Default types are {@link Item#NODE}, {@link Item#EDGE}, {@link Item#NODE_LABEL}
105-
* and {@link Item#EDGE_LABEL}.
95+
* Returns the item attached to
96+
* <code>source</code> and with the type
97+
* <code>type</code>. <p> The source is the graph object behind the item (e.g.
98+
* {@link Node} or {@link Edge}) and the type a default or a custom type. <p> Default types are {@link Item#NODE}, {@link Item#EDGE}, {@link Item#NODE_LABEL} and {@link Item#EDGE_LABEL}.
99+
*
106100
* @param type the item's type
107101
* @param source the item's source object
108-
* @return the item or <code>null</code> if not found
102+
* @return the item or
103+
* <code>null</code> if not found
109104
*/
110105
public Item getItem(String type, Object source);
111-
106+
112107
/**
113-
* <p>Returns currently managed renderers, or null.</p>
114-
* <p>If <code>managedRenderers</code> is set to null, all renderers will be executed when rendering, in default implementation order.</p>
108+
* <p>Returns currently managed renderers, or null.</p> <p>If
109+
* <code>managedRenderers</code> is set to null, all renderers will be executed when rendering, in default implementation order.</p>
110+
*
115111
* @return Enabled renderers or null
116112
*/
117113
public ManagedRenderer[] getManagedRenderers();
118114

119115
/**
120-
* <p>Sets an user-defined array of managed renderers to use when rendering.</p>
121-
* <p><b>Only</b> the renderers marked as enabled will be executed when rendering, and <b>respecting the array order</b></p>
122-
* <p>If the input array does not contain a managed renderer for some renderer existing implementation, a new not enabled managed renderer will be added to the end of the input array</p>
123-
* <p>If <code>managedRenderers</code> is set to null, all renderers will be executed when rendering, in default implementation order.</p>
116+
* <p>Sets an user-defined array of managed renderers to use when rendering.</p> <p><b>Only</b> the renderers marked as enabled will be executed when rendering, and <b>respecting the array
117+
* order</b></p> <p>If the input array does not contain a managed renderer for some renderer existing implementation, a new not enabled managed renderer will be added to the end of the input
118+
* array</p> <p>If
119+
* <code>managedRenderers</code> is set to null, all renderers will be executed when rendering, in default implementation order.</p>
120+
*
124121
* @param managedRenderers Managed renderers for future renderings
125122
*/
126123
public void setManagedRenderers(ManagedRenderer[] managedRenderers);
127-
124+
128125
/**
129-
* Returns <code>managedRenderers</code> Renderers that are enabled, or null if <code>managedRenderers</code> is null.
126+
* Returns
127+
* <code>managedRenderers</code> Renderers that are enabled, or null if
128+
* <code>managedRenderers</code> is null.
129+
*
130130
* @return Enabled renderers or null
131131
*/
132132
public Renderer[] getManagedEnabledRenderers();
133133

134+
/*
135+
* Returns <code>managedPreviewMouseListeners</code> containing the <code>PreviewMouseListeners</code> that are declared by the current enabled managed renderers.
136+
*/
137+
public PreviewMouseListener[] getEnabledMouseListeners();
138+
134139
/**
135140
* Returns the width and height of the graph in the graph coordinates.
141+
*
136142
* @return the graph dimensions
137143
*/
138144
public Dimension getDimensions();
139145

140146
/**
141-
* Returns the top left position in the graph coordinate (i.e. not the preview
142-
* coordinates).
147+
* Returns the top left position in the graph coordinate (i.e. not the preview coordinates).
148+
*
143149
* @return the top left position point
144150
*/
145151
public Point getTopLeftPosition();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Copyright 2008-2012 Gephi
3+
Authors : Eduardo Ramos
4+
Website : http://www.gephi.org
5+
6+
This file is part of Gephi.
7+
8+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9+
10+
Copyright 2011 Gephi Consortium. All rights reserved.
11+
12+
The contents of this file are subject to the terms of either the GNU
13+
General Public License Version 3 only ("GPL") or the Common
14+
Development and Distribution License("CDDL") (collectively, the
15+
"License"). You may not use this file except in compliance with the
16+
License. You can obtain a copy of the License at
17+
http://gephi.org/about/legal/license-notice/
18+
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
19+
specific language governing permissions and limitations under the
20+
License. When distributing the software, include this License Header
21+
Notice in each file and include the License files at
22+
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
23+
License Header, with the fields enclosed by brackets [] replaced by
24+
your own identifying information:
25+
"Portions Copyrighted [year] [name of copyright owner]"
26+
27+
If you wish your version of this file to be governed by only the CDDL
28+
or only the GPL Version 3, indicate your decision by adding
29+
"[Contributor] elects to include this software in this distribution
30+
under the [CDDL or GPL Version 3] license." If you do not indicate a
31+
single choice of license, a recipient has the option to distribute
32+
your version of this file under either the CDDL, the GPL Version 3 or
33+
to extend the choice of license to its licensees as provided above.
34+
However, if you add GPL Version 3 code and therefore, elected the GPL
35+
Version 3 license, then the option applies only if the new code is
36+
made subject to such option by the copyright holder.
37+
38+
Contributor(s):
39+
40+
Portions Copyrighted 2012 Gephi Consortium.
41+
*/
42+
package org.gephi.preview.api;
43+
44+
import java.awt.event.KeyEvent;
45+
46+
/**
47+
* <p>Mouse event for preview. Contains the event type and graph coordinates for the event.
48+
* If you attend a <code>PreviewMouseEvent</code>, it should be marked as consumed.</p>
49+
* <p>The public keyEvent field contains the keyboard state for the given mouse event. Can be null.</p>
50+
* @author Eduardo Ramos<eduramiba@gmail.com>
51+
*/
52+
public class PreviewMouseEvent {
53+
54+
public enum Type {
55+
CLICKED,
56+
PRESSED,
57+
RELEASED,
58+
DRAGGED
59+
}
60+
61+
public enum Button{
62+
LEFT,
63+
RIGHT,
64+
MIDDLE
65+
}
66+
67+
public final Type type;
68+
public final Button button;
69+
public final int x;
70+
public final int y;
71+
private boolean consumed;
72+
73+
/**
74+
* Contains the keyboard state for the given mouse event. Can be null.
75+
*/
76+
public final KeyEvent keyEvent;
77+
78+
public PreviewMouseEvent(int x, int y, Type type, Button button, KeyEvent keyEvent) {
79+
this.x = x;
80+
this.y = y;
81+
this.type = type;
82+
this.button = button;
83+
this.keyEvent = keyEvent;
84+
consumed = false;
85+
}
86+
87+
public boolean isConsumed() {
88+
return consumed;
89+
}
90+
91+
public void setConsumed(boolean consumed) {
92+
this.consumed = consumed;
93+
}
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2008-2012 Gephi
3+
Authors : Eduardo Ramos
4+
Website : http://www.gephi.org
5+
6+
This file is part of Gephi.
7+
8+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9+
10+
Copyright 2011 Gephi Consortium. All rights reserved.
11+
12+
The contents of this file are subject to the terms of either the GNU
13+
General Public License Version 3 only ("GPL") or the Common
14+
Development and Distribution License("CDDL") (collectively, the
15+
"License"). You may not use this file except in compliance with the
16+
License. You can obtain a copy of the License at
17+
http://gephi.org/about/legal/license-notice/
18+
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
19+
specific language governing permissions and limitations under the
20+
License. When distributing the software, include this License Header
21+
Notice in each file and include the License files at
22+
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
23+
License Header, with the fields enclosed by brackets [] replaced by
24+
your own identifying information:
25+
"Portions Copyrighted [year] [name of copyright owner]"
26+
27+
If you wish your version of this file to be governed by only the CDDL
28+
or only the GPL Version 3, indicate your decision by adding
29+
"[Contributor] elects to include this software in this distribution
30+
under the [CDDL or GPL Version 3] license." If you do not indicate a
31+
single choice of license, a recipient has the option to distribute
32+
your version of this file under either the CDDL, the GPL Version 3 or
33+
to extend the choice of license to its licensees as provided above.
34+
However, if you add GPL Version 3 code and therefore, elected the GPL
35+
Version 3 license, then the option applies only if the new code is
36+
made subject to such option by the copyright holder.
37+
38+
Contributor(s):
39+
40+
Portions Copyrighted 2012 Gephi Consortium.
41+
*/
42+
package org.gephi.preview.spi;
43+
44+
/**
45+
* <b>Optionally</b> implement this interface in a <code>Renderer</code> that needs to be responsive to mouse events.
46+
* Only renderers that implement this interface will be drawn while mouse events are being attended (such as dragging).
47+
* @author Eduardo Ramos<eduramiba@gmail.com>
48+
*/
49+
public interface MouseResponsiveRenderer {
50+
public boolean needsPreviewMouseListener(PreviewMouseListener previewMouseListener);
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
Copyright 2008-2012 Gephi
3+
Authors : Eduardo Ramos
4+
Website : http://www.gephi.org
5+
6+
This file is part of Gephi.
7+
8+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9+
10+
Copyright 2011 Gephi Consortium. All rights reserved.
11+
12+
The contents of this file are subject to the terms of either the GNU
13+
General Public License Version 3 only ("GPL") or the Common
14+
Development and Distribution License("CDDL") (collectively, the
15+
"License"). You may not use this file except in compliance with the
16+
License. You can obtain a copy of the License at
17+
http://gephi.org/about/legal/license-notice/
18+
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
19+
specific language governing permissions and limitations under the
20+
License. When distributing the software, include this License Header
21+
Notice in each file and include the License files at
22+
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
23+
License Header, with the fields enclosed by brackets [] replaced by
24+
your own identifying information:
25+
"Portions Copyrighted [year] [name of copyright owner]"
26+
27+
If you wish your version of this file to be governed by only the CDDL
28+
or only the GPL Version 3, indicate your decision by adding
29+
"[Contributor] elects to include this software in this distribution
30+
under the [CDDL or GPL Version 3] license." If you do not indicate a
31+
single choice of license, a recipient has the option to distribute
32+
your version of this file under either the CDDL, the GPL Version 3 or
33+
to extend the choice of license to its licensees as provided above.
34+
However, if you add GPL Version 3 code and therefore, elected the GPL
35+
Version 3 license, then the option applies only if the new code is
36+
made subject to such option by the copyright holder.
37+
38+
Contributor(s):
39+
40+
Portions Copyrighted 2012 Gephi Consortium.
41+
*/
42+
package org.gephi.preview.spi;
43+
44+
import org.gephi.preview.api.PreviewMouseEvent;
45+
import org.gephi.preview.api.PreviewProperties;
46+
import org.gephi.project.api.Workspace;
47+
48+
/**
49+
* <p>Listener for mouse events in Preview.</p>
50+
* <p>Listeners will <b>always</b> receive left mouse button events. Right button is reserved for zooming and moving the canvas</p>
51+
*
52+
* <p>In order to enable a <code>PreviewMouseListener</code>, annotate it with <code>ServiceProvider</code> annotation and implement <code>MouseResponsiveRenderer</code>
53+
* in a <code>Renderer</code> and return true for the listener in the <code>needsPreviewMouseListener</code> method.</p>
54+
* @author Eduardo Ramos<eduramiba@gmail.com>
55+
*/
56+
public interface PreviewMouseListener {
57+
58+
/**
59+
* A single click event.
60+
* @param event Mouse event
61+
* @param properties Preview properties for the workspace
62+
* @param workspace Current workspace
63+
*/
64+
public void mouseClicked(PreviewMouseEvent event, PreviewProperties properties, Workspace workspace);
65+
66+
/**
67+
* A mouse press event. If your listener needs to receive drag or release events, you <b>must</b> mark the previous press event as consumed.
68+
* @param event Mouse event
69+
* @param properties Preview properties for the workspace
70+
* @param workspace Current workspace
71+
*/
72+
public void mousePressed(PreviewMouseEvent event, PreviewProperties properties, Workspace workspace);
73+
74+
/**
75+
* If your listener needs to receive drag events, you <b>must</b> mark the previous press event as consumed.
76+
* @param event Mouse event
77+
* @param properties Preview properties for the workspace
78+
* @param workspace Current workspace
79+
*/
80+
public void mouseDragged(PreviewMouseEvent event, PreviewProperties properties, Workspace workspace);
81+
82+
/**
83+
* If your listener needs to receive release events, you <b>must</b> mark the previous press event as consumed.
84+
* @param event Mouse event
85+
* @param properties Preview properties for the workspace
86+
* @param workspace Current workspace
87+
*/
88+
public void mouseReleased(PreviewMouseEvent event, PreviewProperties properties, Workspace workspace);
89+
}
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,69 @@
1-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2-
<html>
3-
<body bgcolor="white">
4-
Interfaces for creating new renderers, item builders and render targets.
5-
<h3>Create a new Item Builder</h3>
6-
<ol><li>Create a new module and set <code>Preview API</code>,
7-
<code>Graph API</code>, <code>AttributesAPI</code> and
8-
<code>Lookup</code> as dependencies.</li>
9-
<li>Create a new item class which implements <code>Item</code> or
10-
extends <code>AbstractItem</code>. The <code>AbstractItem</code>
11-
class is located in the <code>PreviewPlugin</code> module so add
12-
it as dependency first. An item should be very simple but has a
13-
unique identifier returned by its <code>getType()</code> method.</li>
14-
<li>Create a new builder class that implements <code>ItemBuilder</code></li>
15-
<li>Implement the <code>getType()</code> method and returns the <b>same</b>
16-
identifier than the <code>Item</code> you created earlier.</li>
17-
<li>Implement the <code>getItems()</code> method by retrieving objects
18-
from the given graph.</li>
19-
<li>Add <b>@ServiceProvider</b> annotation to your builder, that it can
20-
be found by the system. Set <code>ItemBuilder</code> as the
21-
annotation parameter.</li>
22-
</ol>
23-
<h3>Create a new Renderer</h3>
24-
<ol><li>Create a new module and set <code>Preview API</code>,
25-
<code>GraphAPI</code>, <code>Processing Wrapper</code>,
26-
<code>iText Wrapper</code> and <code>Lookup</code> as dependencies.</li>
27-
<li>Create a new class that implements <code>Renderer</code>.</li>
28-
<li>Implement the renderer methods. </li>
29-
<li>Add <b>@ServiceProvider</b> annotation to your builder, that it can
30-
be found by the system. Set <code>Renderer</code> as the
31-
annotation parameter.</li>
32-
</ol>
33-
<h3>Add data to an existing item</h3>
34-
To add an additional data attribute to a Node or Edge item, you need to create
35-
a new item builder for the specific type. For instance if one want to add
36-
a new attribute to nodes create a new <code>ItemBuilder</code> for the
37-
type <code>Item.Node</code>. Simply return item objects with the data you
38-
want to add. The system will automatically merge your new data to node items.
39-
<h3>Override a Renderer</h3>
40-
Default renderers can be completely replaced by custom implementations. The
41-
implementation needs to customize its <code>@ServiceProvider</code> annotation
42-
with the renderer path it is overriding:
43-
<ul>
44-
<li><pre>@ServiceProvider(service=Renderer.class, supersedes="org.gephi.preview.plugin.renderers.NodeRenderer")</pre></li>
45-
<li><pre>@ServiceProvider(service=Renderer.class, supersedes="org.gephi.preview.plugin.renderers.EdgeRenderer")</pre></li>
46-
<li><pre>@ServiceProvider(service=Renderer.class, supersedes="org.gephi.preview.plugin.renderers.NodeLabelRenderer")</pre></li>
47-
<li><pre>@ServiceProvider(service=Renderer.class, supersedes="org.gephi.preview.plugin.renderers.EdgeLabelRenderer")</pre></li>
48-
<li><pre>@ServiceProvider(service=Renderer.class, supersedes="org.gephi.preview.plugin.renderers.ArrowRenderer")</pre></li>
49-
</ul>
50-
<h3>Add a new PreviewUI settings panel</h3>
51-
Plug-ins can add UI components to the Preview Settings module. Additional components are placed in new tabs and have access to the
52-
current <code>PreviewModel</code> and therefore <code>PreviewProperties</code>.
53-
<ol><li>Create a new module and set <code>Preview API</code> and
54-
<code>Lookup</code> as dependencies.</li>
55-
<li>Create a new class that implements <code>PreviewUI</code> and implements
56-
methods.</li>
57-
<li>Add <b>@ServiceProvider</b> annotation to your builder, that it can
58-
be found by the system. Set <code>PreviewUI</code> as the
59-
'service' annotation parameter.</li>
60-
</ol>
61-
</body>
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2+
<html>
3+
<body bgcolor="white">
4+
Interfaces for creating new renderers, item builders and render targets.
5+
<h3>Create a new Item Builder</h3>
6+
<ol><li>Create a new module and set <code>Preview API</code>,
7+
<code>Graph API</code>, <code>AttributesAPI</code> and
8+
<code>Lookup</code> as dependencies.</li>
9+
<li>Create a new item class which implements <code>Item</code> or
10+
extends <code>AbstractItem</code>. The <code>AbstractItem</code>
11+
class is located in the <code>PreviewPlugin</code> module so add
12+
it as dependency first. An item should be very simple but has a
13+
unique identifier returned by its <code>getType()</code> method.</li>
14+
<li>Create a new builder class that implements <code>ItemBuilder</code></li>
15+
<li>Implement the <code>getType()</code> method and returns the <b>same</b>
16+
identifier than the <code>Item</code> you created earlier.</li>
17+
<li>Implement the <code>getItems()</code> method by retrieving objects
18+
from the given graph.</li>
19+
<li>Add <b>@ServiceProvider</b> annotation to your builder, that it can
20+
be found by the system. Set <code>ItemBuilder</code> as the
21+
annotation parameter.</li>
22+
</ol>
23+
<h3>Create a new Renderer</h3>
24+
<ol><li>Create a new module and set <code>Preview API</code>,
25+
<code>GraphAPI</code>, <code>Processing Wrapper</code>,
26+
<code>iText Wrapper</code> and <code>Lookup</code> as dependencies.</li>
27+
<li>Create a new class that implements <code>Renderer</code>.</li>
28+
<li>Implement the renderer methods. </li>
29+
<li>Add <b>@ServiceProvider</b> annotation to your builder, that it can
30+
be found by the system. Set <code>Renderer</code> as the
31+
annotation parameter.</li>
32+
</ol>
33+
<h3>Add data to an existing item</h3>
34+
To add an additional data attribute to a Node or Edge item, you need to create
35+
a new item builder for the specific type. For instance if one want to add
36+
a new attribute to nodes create a new <code>ItemBuilder</code> for the
37+
type <code>Item.Node</code>. Simply return item objects with the data you
38+
want to add. The system will automatically merge your new data to node items.
39+
<h3>Extend or replace an existing renderer</h3>
40+
<p>To extend or completely replace a default Renderer by your own implementation,
41+
create a new Renderer and set the annotation like below. In addition add Preview Plugin module as a dependency.
42+
</p><p><code>
43+
@ServiceProvider(service=Renderer.class, position=XXX)
44+
public class MyRenderer extends NodeRenderer
45+
</code>
46+
</p><p>Being XXX the new position of the renderer
47+
Then you can reuse parts of the base class or just override them.
48+
</p><p>Default renderers are:
49+
</p>
50+
<ul>
51+
<li> org.gephi.preview.plugin.renderers.NodeRenderer</li>
52+
<li> org.gephi.preview.plugin.renderers.EdgeRenderer</li>
53+
<li> org.gephi.preview.plugin.renderers.NodeLabelRenderer</li>
54+
<li> org.gephi.preview.plugin.renderers.EdgeLabelRenderer</li>
55+
<li> org.gephi.preview.plugin.renderers.ArrowRenderer</li>
56+
</ul>
57+
<h3>Add a new PreviewUI settings panel</h3>
58+
Plug-ins can add UI components to the Preview Settings module. Additional components are placed in new tabs and have access to the
59+
current <code>PreviewModel</code> and therefore <code>PreviewProperties</code>.
60+
<ol><li>Create a new module and set <code>Preview API</code> and
61+
<code>Lookup</code> as dependencies.</li>
62+
<li>Create a new class that implements <code>PreviewUI</code> and implements
63+
methods.</li>
64+
<li>Add <b>@ServiceProvider</b> annotation to your builder, that it can
65+
be found by the system. Set <code>PreviewUI</code> as the
66+
'service' annotation parameter.</li>
67+
</ol>
68+
</body>
6269
</html>

‎src/main/javadoc/overview.html

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
<h2>API Changes</h2>
2020
<p>
2121
<ul>
22+
<li>(December 07 2012) Add support for mouse listeners in Preview plugins. Create a <code>PreviewMouseListener</code> and implement <code>MouseResponsiveRenderer</code> interface in the renderers that use the listener.
23+
</li>
2224
<li>(April 10 2012) Add a <code>getShortDescription()</code> method to the <code>StatisticsUI</code> API. It enables to get a short description of statistics (used to display tooltips).
2325
</li>
2426
<li>(March 26 2012) Add a <code>needsItemBuilder</code> method to <code>Renderer</code> in Preview API.

0 commit comments

Comments
 (0)
Please sign in to comment.