Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:cytoscape/cytoscape-impl into de…
Browse files Browse the repository at this point in the history
…velop
  • Loading branch information
scootermorris committed Jan 26, 2021
2 parents 1474c84 + cae471b commit 1830cc9
Show file tree
Hide file tree
Showing 23 changed files with 408 additions and 488 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.ding.impl.DRenderingEngine;
import org.cytoscape.ding.impl.DingRenderer;
import org.cytoscape.event.CyEventHelper;
import org.cytoscape.event.DebounceTimer;
import org.cytoscape.property.CyProperty;
Expand All @@ -40,6 +45,8 @@ public class SettingsPanel extends BasicCollapsiblePanel {
private PropEditor prop4;
private PropEditor prop5;
private PropEditor prop6;
private PropEditor prop7;
private JButton cacheStatsButton;


@SuppressWarnings("unchecked")
Expand All @@ -51,13 +58,17 @@ public SettingsPanel(CyServiceRegistrar registrar) {
}

private void createContents() {
prop1 = new NumberPropEditor("render.coarseDetailThreshold");
prop2 = new NumberPropEditor("render.nodeBorderThreshold");
prop3 = new NumberPropEditor("render.nodeLabelThreshold");
prop4 = new NumberPropEditor("render.edgeArrowThreshold");
prop5 = new NumberPropEditor("render.edgeLabelThreshold");
prop6 = new BooleanPropEditor("render.edgeBufferPan");
prop1 = new NumberPropEditor("render.coarseDetailThreshold", "coarseDetailThreshold");
prop2 = new NumberPropEditor("render.nodeBorderThreshold", "nodeBorderThreshold");
prop3 = new NumberPropEditor("render.nodeLabelThreshold", "nodeLabelThreshold");
prop4 = new NumberPropEditor("render.edgeArrowThreshold", "edgeArrowThreshold");
prop5 = new NumberPropEditor("render.edgeLabelThreshold", "edgeLabelThreshold");
prop6 = new BooleanPropEditor("render.edgeBufferPan", "edgeBufferPan");
prop7 = new BooleanPropEditor("render.labelCache", "labelCache");
cacheStatsButton = new JButton("show stats");
cacheStatsButton.addActionListener(e-> showCacheStats());

LookAndFeelUtil.makeSmall(cacheStatsButton);

JPanel panel = new JPanel();
panel.setOpaque(false);
Expand All @@ -74,6 +85,7 @@ private void createContents() {
.addComponent(prop4.getLabel())
.addComponent(prop5.getLabel())
.addComponent(prop6.getLabel())
.addComponent(prop7.getLabel())
)
.addGroup(layout.createParallelGroup()
.addComponent(prop1.getEditor())
Expand All @@ -82,6 +94,10 @@ private void createContents() {
.addComponent(prop4.getEditor())
.addComponent(prop5.getEditor())
.addComponent(prop6.getEditor())
.addComponent(prop7.getEditor())
)
.addGroup(layout.createParallelGroup()
.addComponent(cacheStatsButton)
)
);

Expand Down Expand Up @@ -110,6 +126,11 @@ private void createContents() {
.addComponent(prop6.getLabel())
.addComponent(prop6.getEditor(), PREFERRED_SIZE, PREFERRED_SIZE, PREFERRED_SIZE)
)
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(prop7.getLabel())
.addComponent(prop7.getEditor(), PREFERRED_SIZE, PREFERRED_SIZE, PREFERRED_SIZE)
.addComponent(cacheStatsButton)
)
);

JPanel content = getContentPane();
Expand All @@ -124,6 +145,23 @@ public void update() {
prop4.update();
prop5.update();
prop6.update();
prop7.update();
}


private void showCacheStats() {
var renderer = registrar.getService(DingRenderer.class);
var appManager = registrar.getService(CyApplicationManager.class);

var netView = appManager.getCurrentNetworkView();
if(netView == null)
return;

DRenderingEngine re = renderer.getRenderingEngine(netView);
var labelCache = re.getLabelCache();
String stats = labelCache.getStats();

JOptionPane.showMessageDialog(this, stats);
}


Expand All @@ -150,9 +188,9 @@ private class NumberPropEditor implements PropEditor, ChangeListener {
private final JLabel label;
private final JSpinner spinner;

public NumberPropEditor(String propName) {
public NumberPropEditor(String propName, String labelText) {
this.propName = propName;
label = new JLabel(propName);
label = new JLabel(labelText);
int value = getPropValue();
model = new SpinnerNumberModel(value, 0, 1000000, 100);
spinner = new JSpinner(model);
Expand Down Expand Up @@ -197,9 +235,9 @@ private class BooleanPropEditor implements PropEditor, ActionListener {
private final JLabel label;
private final JCheckBox checkBox;

public BooleanPropEditor(String propName) {
public BooleanPropEditor(String propName, String labelText) {
this.propName = propName;
label = new JLabel(propName);
label = new JLabel(labelText);
checkBox = new JCheckBox();
boolean value = getPropValue();
checkBox.setSelected(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,6 @@ public Paint getBorderPaint(View<CyNode> nodeView) {
return getTransparentColor(paint, trans);
}

@Override
public int getLabelCount(View<CyNode> nodeView) {
String label = getLabelText(nodeView);
return (label == null || label.isEmpty()) ? 0 : 1;
}

@Override
public String getLabelText(View<CyNode> nodeView) {
return nodeView.getVisualProperty(NODE_LABEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.cytoscape.ding.DVisualLexicon;
import org.cytoscape.ding.PrintLOD;
import org.cytoscape.ding.debug.DebugProgressMonitorFactory;
import org.cytoscape.ding.debug.DingDebugMediator;
import org.cytoscape.ding.icon.VisualPropertyIconFactory;
import org.cytoscape.ding.impl.canvas.CompositeGraphicsCanvas;
import org.cytoscape.ding.impl.canvas.MainRenderComponent;
Expand All @@ -42,6 +43,8 @@
import org.cytoscape.graph.render.stateful.EdgeDetails;
import org.cytoscape.graph.render.stateful.GraphLOD;
import org.cytoscape.graph.render.stateful.GraphLOD.RenderEdges;
import org.cytoscape.graph.render.stateful.LabelInfoCache;
import org.cytoscape.graph.render.stateful.LabelInfoProvider;
import org.cytoscape.graph.render.stateful.NodeDetails;
import org.cytoscape.graph.render.stateful.RenderDetailFlags;
import org.cytoscape.model.CyEdge;
Expand Down Expand Up @@ -142,6 +145,8 @@ public enum UpdateType {
private final Timer checkDirtyTimer;
private final DebounceTimer eventFireTimer;

private final LabelInfoCache labelInfoCache;

private final BendStore bendStore;
private InputHandlerGlassPane inputHandler = null;
private DebugProgressMonitorFactory debugProgressMonitorFactory;
Expand Down Expand Up @@ -188,6 +193,8 @@ public DRenderingEngine(

viewModelSnapshot = viewModel.createSnapshot();

labelInfoCache = new LabelInfoCache(1000, DingDebugMediator.showDebugPanel(registrar)); // MKTODO should maxSize be hardcoded?

eventFireTimer = new DebounceTimer(240);

// Check if the view model has changed approximately 30 times per second
Expand Down Expand Up @@ -229,6 +236,9 @@ public ExecutorService getSingleThreadExecutorService() {
return singleThreadExecutor;
}

public LabelInfoProvider getLabelCache() {
return labelInfoCache;
}

public Rectangle getComponentBounds() {
return renderComponent.getBounds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public class DingGraphLOD implements GraphLOD, PropertyUpdatedListener {
protected int nodeLabelThreshold;
protected int edgeArrowThreshold;
protected int edgeLabelThreshold;

protected boolean edgeBufferPan;
protected boolean labelCache;

private final Properties props;
private final CyProperty<Properties> cyProp;
Expand All @@ -70,6 +72,7 @@ private void init() {
edgeArrowThreshold = parseInt(props.getProperty("render.edgeArrowThreshold"), 600);
edgeLabelThreshold = parseInt(props.getProperty("render.edgeLabelThreshold"), 200);
edgeBufferPan = Boolean.valueOf(props.getProperty("render.edgeBufferPan"));
labelCache = Boolean.valueOf(props.getProperty("render.labelCache"));
}

private static int parseInt(String intString, int defaultValue) {
Expand Down Expand Up @@ -132,6 +135,10 @@ public double getNestedNetworkImageScaleFactor() {
public boolean edgeBufferPan() {
return DingGraphLOD.this.edgeBufferPan();
}
@Override
public boolean labelCache() {
return DingGraphLOD.this.labelCache();
}
};
}

Expand Down Expand Up @@ -416,6 +423,11 @@ public boolean edgeBufferPan() {
return edgeBufferPan;
}

@Override
public boolean labelCache() {
return labelCache;
}

@Override
public double getNestedNetworkImageScaleFactor() {
final String scaleFactor = props.getProperty("nestedNetwork.imageScaleFactor", "1.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1573,8 +1573,10 @@ public void mouseReleased(MouseEvent e) {
mousePressedPoint = null;
undoPanEdit = null;

panner.endPan();
panner = null;
if(panner != null) { // why does this happen?
panner.endPan();
panner = null;
}
}

private Cursor createPanCursor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import org.cytoscape.graph.render.immed.GraphGraphics;
import org.cytoscape.graph.render.stateful.EdgeDetails;
import org.cytoscape.graph.render.stateful.GraphRenderer;
import org.cytoscape.graph.render.stateful.MeasuredLineCreator;
import org.cytoscape.graph.render.stateful.LabelInfo;
import org.cytoscape.graph.render.stateful.LabelInfoProvider;
import org.cytoscape.graph.render.stateful.NodeDetails;
import org.cytoscape.graph.render.stateful.RenderDetailFlags;
import org.cytoscape.model.CyEdge;
Expand Down Expand Up @@ -128,7 +129,7 @@ public DLabelSelection getNodeLabelAt(Point2D pt) {
* @param pt point where the mouse was clicked.
* @return a DLabelSelection object if there is a node label under the specified point. null if no labels are found at this point.
*/
private DLabelSelection selectLabel(CyNetworkViewSnapshot snapshot, Point2D pt ) {
private DLabelSelection selectLabel(CyNetworkViewSnapshot snapshot, Point2D pt) {
double[] locn = {pt.getX(), pt.getY()};
re.getTransform().xformImageToNodeCoords(locn);
double xP = locn[0];
Expand All @@ -150,6 +151,9 @@ private DLabelSelection selectLabel(CyNetworkViewSnapshot snapshot, Point2D pt )

SpacialIndex2DEnumerator<Long> under = snapshot.getSpacialIndex2D().queryOverlap(xMin, yMin, xMax, yMax);

LabelInfoProvider labelProvider = re.getGraphLOD().labelCache() ? re.getLabelCache() : LabelInfoProvider.INSTANCE;
FontRenderContext frc = new FontRenderContext(null,true,true); // MKTODO

float[] extentsBuff = new float[4];

while (under.hasNext()) {
Expand All @@ -159,13 +163,13 @@ private DLabelSelection selectLabel(CyNetworkViewSnapshot snapshot, Point2D pt )
// compute the actual size of label text rectangle
String labelText = nodeDetails.getLabelText(nodeView);

Font font = nodeDetails.getLabelFont(nodeView);
Font font = nodeDetails.getLabelFont(nodeView);
double labelWidth = nodeDetails.getLabelWidth(nodeView);

MeasuredLineCreator mlCreator = new MeasuredLineCreator(labelText, font, new FontRenderContext(null,true,true), 1.0, true, labelWidth);
LabelInfo mlCreator = labelProvider.getLabelInfo(labelText, font, labelWidth, frc);

double h = mlCreator.getTotalHeight(); // actual label text box height
double w = mlCreator.getMaxLineWidth(); // actual label text box width.
double w = mlCreator.getMaxLineWidth(); // actual label text box width.

// compute the actual position of the label text box.
double x = nodeDetails.getXPosition(nodeView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.cytoscape.ding.impl.work.ProgressMonitor;
import org.cytoscape.graph.render.immed.GraphGraphics;
import org.cytoscape.graph.render.stateful.GraphRenderer;
import org.cytoscape.graph.render.stateful.LabelInfoProvider;
import org.cytoscape.graph.render.stateful.RenderDetailFlags;

public class EdgeCanvas<GP extends GraphicsProvider> extends DingCanvas<GP> {
Expand All @@ -27,9 +28,10 @@ public void paint(ProgressMonitor pm, RenderDetailFlags flags) {
var netViewSnapshot = re.getViewModelSnapshot();
var edgeDetails = re.getEdgeDetails();
var nodeDetails = re.getNodeDetails();
var labelProvider = flags.has(RenderDetailFlags.OPT_LABEL_CACHE) ? re.getLabelCache() : LabelInfoProvider.INSTANCE;

graphGraphics.update();
GraphRenderer.renderEdges(pm, graphGraphics, netViewSnapshot, flags, nodeDetails, edgeDetails);
graphGraphics.update(flags);
GraphRenderer.renderEdges(pm, graphGraphics, netViewSnapshot, flags, nodeDetails, edgeDetails, labelProvider);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.cytoscape.ding.impl.work.ProgressMonitor;
import org.cytoscape.graph.render.immed.GraphGraphics;
import org.cytoscape.graph.render.stateful.GraphRenderer;
import org.cytoscape.graph.render.stateful.LabelInfoProvider;
import org.cytoscape.graph.render.stateful.RenderDetailFlags;
import org.cytoscape.view.model.CyNetworkViewSnapshot;

Expand All @@ -25,11 +26,11 @@ public String getCanvasDebugName() {
@Override
public void paint(ProgressMonitor pm, RenderDetailFlags flags) {
var graphics = new GraphGraphics(graphicsProvider);

var edgeDetails = new DEdgeDetails(null);
var nodeDetails = new DNodeDetails(null, null);
var labelInfoCache = LabelInfoProvider.INSTANCE;

GraphRenderer.renderEdges(pm, graphics, snapshot, flags, nodeDetails, edgeDetails);
GraphRenderer.renderEdges(pm, graphics, snapshot, flags, nodeDetails, edgeDetails, labelInfoCache);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.cytoscape.ding.impl.work.ProgressMonitor;
import org.cytoscape.graph.render.immed.GraphGraphics;
import org.cytoscape.graph.render.stateful.GraphRenderer;
import org.cytoscape.graph.render.stateful.LabelInfoProvider;
import org.cytoscape.graph.render.stateful.RenderDetailFlags;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.vizmap.VisualMappingManager;
Expand Down Expand Up @@ -67,8 +68,9 @@ public void paint(ProgressMonitor pm, RenderDetailFlags flags) {
var snapshot = re.getViewModelSnapshot();
var edgeDetails = re.getEdgeDetails();
var nodeDetails = re.getNodeDetails();
var labelProvider = flags.has(RenderDetailFlags.OPT_LABEL_CACHE) ? re.getLabelCache() : LabelInfoProvider.INSTANCE;

graphGraphics.update();
GraphRenderer.renderNodes(pm, graphGraphics, snapshot, flags, nodeDetails, edgeDetails, dependencies);
graphGraphics.update(flags);
GraphRenderer.renderNodes(pm, graphGraphics, snapshot, flags, nodeDetails, edgeDetails, dependencies, labelProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.cytoscape.ding.impl.work.ProgressMonitor;
import org.cytoscape.graph.render.immed.GraphGraphics;
import org.cytoscape.graph.render.stateful.GraphRenderer;
import org.cytoscape.graph.render.stateful.LabelInfoProvider;
import org.cytoscape.graph.render.stateful.RenderDetailFlags;
import org.cytoscape.view.model.CyNetworkViewSnapshot;

Expand All @@ -25,11 +26,11 @@ public String getCanvasDebugName() {
@Override
public void paint(ProgressMonitor pm, RenderDetailFlags flags) {
var graphics = new GraphGraphics(graphicsProvider);

var edgeDetails = new DEdgeDetails(null);
var nodeDetails = new DNodeDetails(null, null);
var labelInfoCache = LabelInfoProvider.INSTANCE;

GraphRenderer.renderNodes(pm, graphics, snapshot, flags, nodeDetails, edgeDetails, null);
GraphRenderer.renderNodes(pm, graphics, snapshot, flags, nodeDetails, edgeDetails, null, labelInfoCache);
}

}

0 comments on commit 1830cc9

Please sign in to comment.