提交 ab8b8b63 编写于 作者: M Mathieu Bastian

Add refresh mechanism

上级 b8294372
......@@ -116,6 +116,14 @@ public class AttributePartitionImpl extends PartitionImpl {
return false;
}
@Override
public int getVersion(Graph graph) {
if (isValid(graph)) {
return getIndex(graph.getModel().getGraph()).getColumnIndex(column.get()).getVersion();
}
return 0;
}
@Override
public int hashCode() {
int hash = 3;
......
......@@ -88,7 +88,7 @@ public class EdgeTypePartitionImpl extends PartitionImpl {
@Override
public float percentage(Object value, Graph graph) {
int count = count(value, graph);
return (float) count / graph.getEdgeCount();
return ((float) count) / graph.getEdgeCount();
}
@Override
......@@ -109,6 +109,12 @@ public class EdgeTypePartitionImpl extends PartitionImpl {
@Override
public boolean isValid(Graph graph) {
return graph.getModel().getEdgeTypeCount() > 1;
return graph.getModel().isMultiGraph();
}
@Override
public int getVersion(Graph graph) {
// TODO
return 0;
}
}
......@@ -43,6 +43,7 @@
package org.gephi.appearance;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import org.gephi.appearance.api.Function;
import org.gephi.appearance.spi.PartitionTransformer;
import org.gephi.appearance.spi.RankingTransformer;
......@@ -66,6 +67,8 @@ public abstract class FunctionImpl implements Function {
protected final TransformerUI transformerUI;
protected final PartitionImpl partition;
protected final RankingImpl ranking;
// Version
protected final AtomicInteger version;
protected FunctionImpl(AppearanceModelImpl model, String name, Class<? extends Element> elementClass, Column column,
Transformer transformer, TransformerUI transformerUI, PartitionImpl partition,
......@@ -85,6 +88,7 @@ public abstract class FunctionImpl implements Function {
this.transformerUI = transformerUI;
this.partition = partition;
this.ranking = ranking;
this.version = new AtomicInteger(Integer.MIN_VALUE);
}
@Override
......@@ -123,6 +127,16 @@ public abstract class FunctionImpl implements Function {
}
}
public boolean hasChanged() {
if(isSimple()) {
return false;
} else {
Graph graph = model.getGraph();
int newVersion = isPartition() ? partition.getVersion(graph) : 0;
return version.getAndSet(newVersion) != newVersion;
}
}
public boolean isValid() {
if (isRanking()) {
return ranking.isValid(getGraph());
......
......@@ -86,4 +86,6 @@ public abstract class PartitionImpl implements Partition {
public abstract boolean isValid(Graph graph);
public abstract Class getValueType();
public abstract int getVersion(Graph graph);
}
......@@ -142,4 +142,11 @@ public interface Function {
* @return model
*/
AppearanceModel getModel();
/**
* Returns true if the underlying partition or ranking changed its boundaries or values since last time checked.
*
* @return true if changed, false otherwise
*/
boolean hasChanged();
}
......@@ -103,4 +103,20 @@ public class AttributePartitionTest {
clearNodeAttributes(graph);
Assert.assertFalse(p.isValid(graph));
}
@Test
public void testVersion() {
Graph graph = GraphGenerator.build().generateTinyGraph().addIntNodeColumn().getGraph();
Column column = graph.getModel().getNodeTable().getColumn(GraphGenerator.INT_COLUMN);
Node n1 = graph.getNode(GraphGenerator.FIRST_NODE);
AttributePartitionImpl p = new AttributePartitionImpl(column);
int version = p.getVersion(graph);
n1.setAttribute(column, 99);
Assert.assertNotEquals(version, version = p.getVersion(graph));
Assert.assertEquals(version, p.getVersion(graph));
graph.removeNode(n1);
Assert.assertNotEquals(version, p.getVersion(graph));
}
}
......@@ -152,6 +152,8 @@ public class AppearanceTopComponent extends TopComponent implements Lookup.Provi
refreshControls();
} else if (pce.getPropertyName().equals(AppearanceUIModelEvent.ATTRIBUTE_LIST)) {
refreshCombo();
} else if (pce.getPropertyName().equals(AppearanceUIModelEvent.REFRESH_FUNCTION)) {
refreshCenterPanel();
}
// if (pce.getPropertyName().equals(RankingUIModel.LIST_VISIBLE)) {
// listButton.setSelected((Boolean) pce.getNewValue());
......
......@@ -50,21 +50,12 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import org.gephi.appearance.api.AppearanceController;
import org.gephi.appearance.api.AppearanceModel;
import org.gephi.appearance.api.AttributeFunction;
import org.gephi.appearance.api.Function;
import org.gephi.appearance.spi.Transformer;
import org.gephi.appearance.spi.TransformerCategory;
import org.gephi.appearance.spi.TransformerUI;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.ColumnObserver;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphObserver;
import org.gephi.graph.api.TableObserver;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.gephi.project.api.WorkspaceListener;
......@@ -269,11 +260,18 @@ public class AppearanceUIController {
}
public void refreshColumnsList() {
if(model != null) {
if (model != null) {
firePropertyChangeEvent(AppearanceUIModelEvent.ATTRIBUTE_LIST, null, null);
}
}
public void refreshFunction() {
if (model != null) {
System.out.println("Refresh");
firePropertyChangeEvent(AppearanceUIModelEvent.REFRESH_FUNCTION, null, null);
}
}
public AppearanceController getAppearanceController() {
return appearanceController;
}
......
......@@ -74,6 +74,7 @@ public class AppearanceUIModel {
protected final Map<String, Map<TransformerCategory, AutoAppyTransformer>> selectedAutoTransformer;
protected final Map<Function, Map<String, Object>> savedProperties;
protected final TableObserverExecutor tableObserverExecutor;
protected final FunctionObserverExecutor functionObserverExecutor;
protected String selectedElementClass = AppearanceUIController.NODE_ELEMENT;
public AppearanceUIModel(AppearanceModel model) {
......@@ -91,8 +92,9 @@ public class AppearanceUIModel {
initSelectedTransformerUIs(ec);
}
//Init observer
//Init observers
tableObserverExecutor = new TableObserverExecutor(this);
functionObserverExecutor = new FunctionObserverExecutor(this);
}
private void initSelectedTransformerUIs(String elementClass) {
......@@ -108,7 +110,7 @@ public class AppearanceUIModel {
TransformerCategory cat = ui.getCategory();
selectedCategory.put(elementClass, cat);
if(func.isSimple()) {
if (func.isSimple()) {
selectedTransformerUI.get(elementClass).put(cat, ui);
selectedFunction.get(elementClass).put(ui, func);
}
......@@ -124,10 +126,12 @@ public class AppearanceUIModel {
public void select() {
tableObserverExecutor.start();
functionObserverExecutor.start();
}
public void unselect() {
tableObserverExecutor.stop();
functionObserverExecutor.stop();
}
public boolean isLocalScale() {
......@@ -309,6 +313,8 @@ public class AppearanceUIModel {
} else if (type.isArray()) {
Class cmp = type.getComponentType();
return cmp.isPrimitive() || cmp.equals(Color.class);
} else return type.equals(Color.class);
} else {
return type.equals(Color.class);
}
}
}
......@@ -55,6 +55,7 @@ public class AppearanceUIModelEvent extends PropertyChangeEvent {
public static String SELECTED_TRANSFORMER_UI = "selectedTransformerUI";
public static String SELECTED_FUNCTION = "selectedFunction";
public static String ATTRIBUTE_LIST = "attributeList";
public static String REFRESH_FUNCTION = "refreshFunction";
public static String START_STOP_AUTO_APPLY = "startStopAutoApply";
public static String SET_AUTO_APPLY = "setStopAutoApply";
public static String SET_LOCAL_SCALE = "setLocalScale";
......
......@@ -46,7 +46,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import org.gephi.appearance.api.AppearanceController;
import org.gephi.appearance.api.Function;
import org.openide.util.Lookup;
......
package org.gephi.desktop.appearance;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.gephi.appearance.api.Function;
import org.openide.util.Lookup;
public class FunctionObserverExecutor implements Runnable {
private static final long DEFAULT_DELAY = 1000; //ms
private final AppearanceUIModel model;
private final AppearanceUIController controller;
private ScheduledExecutorService executor;
public FunctionObserverExecutor(AppearanceUIModel model) {
this.model = model;
this.controller = Lookup.getDefault().lookup(AppearanceUIController.class);
}
public void start() {
executor = Executors.newSingleThreadScheduledExecutor(r -> new Thread(r, "Appearance Function Observer"));
executor.scheduleWithFixedDelay(this, getDelayInMs(), getDelayInMs(), TimeUnit.MILLISECONDS);
}
public void stop() {
if (executor != null && !executor.isShutdown()) {
executor.shutdown();
}
executor = null;
}
@Override
public void run() {
synchronized (this) {
Function selectedFunction = model.getSelectedFunction();
if (selectedFunction != null && selectedFunction.hasChanged()) {
controller.refreshFunction();
}
}
}
public boolean isRunning() {
return executor != null;
}
private long getDelayInMs() {
return DEFAULT_DELAY;
}
}
......@@ -137,7 +137,7 @@
<netbeans.version>RELEASE126</netbeans.version>
<!-- GraphStore version -->
<graphstore.version>0.6.1</graphstore.version>
<graphstore.version>0.6.2</graphstore.version>
<!-- Localization ZIP version, from 'http://netbeans.org/project_downloads/nblocalization' -->
<gephi.platform.localization.version>1.1-NB80</gephi.platform.localization.version>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册