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

Merge branch 'master' of github.com:gephi/gephi

......@@ -113,6 +113,16 @@ public interface GraphElementsController {
* @return New edge if the edge was created succesfully, null otherwise
*/
Edge createEdge(Node source, Node target, boolean directed);
/**
* <p>Creates and edge between source and target node (if it does not already exist), directed or undirected, in the current graph.</p>
* @param source Source node
* @param target Target node
* @param directed Indicates if the edge has to be directed
* @param typeLabel Edge type label or null
* @return New edge if the edge was created succesfully, null otherwise
*/
Edge createEdge(Node source, Node target, boolean directed, Object typeLabel);
/**
* <p>Creates and edge between source and target node (if it does not already exist), directed or undirected.</p>
......@@ -123,7 +133,18 @@ public interface GraphElementsController {
* @return New edge if the edge was created succesfully, null otherwise
*/
Edge createEdge(Node source, Node target, boolean directed, Graph graph);
/**
* <p>Creates and edge between source and target node (if it does not already exist), directed or undirected.</p>
* @param source Source node
* @param target Target node
* @param directed Indicates if the edge has to be directed
* @param typeLabel Edge type label or null
* @param graph Graph to insert the node into
* @return New edge if the edge was created succesfully, null otherwise
*/
Edge createEdge(Node source, Node target, boolean directed, Object typeLabel, Graph graph);
/**
* <p>Creates and edge between source and target node (if it does not already exist), directed or undirected.</p>
* <p>If a edge with the given id already exists, no edge will be created.</p>
......@@ -134,7 +155,19 @@ public interface GraphElementsController {
* @return New edge if the edge was created succesfully, null otherwise
*/
Edge createEdge(String id, Node source, Node target, boolean directed);
/**
* <p>Creates and edge between source and target node (if it does not already exist), directed or undirected.</p>
* <p>If a edge with the given id already exists, no edge will be created.</p>
* @param id Id for the new edge
* @param source Source node
* @param target Target node
* @param directed Indicates if the edge has to be directed
* @param typeLabel Edge type label or null
* @return New edge if the edge was created succesfully, null otherwise
*/
Edge createEdge(String id, Node source, Node target, boolean directed, Object typeLabel);
/**
* <p>Creates and edge between source and target node (if it does not already exist), directed or undirected, in the current graph.</p>
* <p>If a edge with the given id already exists, no edge will be created.</p>
......@@ -147,6 +180,19 @@ public interface GraphElementsController {
*/
Edge createEdge(String id, Node source, Node target, boolean directed, Graph graph);
/**
* <p>Creates and edge between source and target node (if it does not already exist), directed or undirected, in the current graph.</p>
* <p>If a edge with the given id already exists, no edge will be created.</p>
* @param id Id for the new edge
* @param source Source node
* @param target Target node
* @param directed Indicates if the edge has to be directed
* @param typeLabel Edge type label or null
* @param graph Graph to insert the node into
* @return New edge if the edge was created succesfully, null otherwise
*/
Edge createEdge(String id, Node source, Node target, boolean directed, Object typeLabel, Graph graph);
/**
* <p>Tries to create edges between the source node and all other edges, directed or undirected.</p>
* <p>An edge won't be created if it already exists or is a self-loop.</p>
......
......@@ -66,7 +66,6 @@ import org.openide.util.lookup.ServiceProvider;
public class GraphElementsControllerImpl implements GraphElementsController {
private static final float DEFAULT_NODE_SIZE = 10f;
private static final int DEFAULT_EDGE_TYPE = 0;//0 is graphstore EdgeTypeStore.NULL_LABEL
private static final float DEFAULT_EDGE_WEIGHT = 1f;
@Override
......@@ -126,19 +125,39 @@ public class GraphElementsControllerImpl implements GraphElementsController {
public Edge createEdge(String id, Node source, Node target, boolean directed) {
return createEdge(id, source, target, directed, getCurrentGraph());
}
@Override
public Edge createEdge(Node source, Node target, boolean directed, Object typeLabel) {
return createEdge(null, source, target, directed, typeLabel, getCurrentGraph());
}
@Override
public Edge createEdge(Node source, Node target, boolean directed, Object typeLabel, Graph graph) {
return createEdge(null, source, target, directed, typeLabel, graph);
}
@Override
public Edge createEdge(String id, Node source, Node target, boolean directed, Object typeLabel) {
return createEdge(id, source, target, directed, typeLabel, getCurrentGraph());
}
@Override
public Edge createEdge(String id, Node source, Node target, boolean directed, Graph graph) {
return createEdge(id, source, target, directed, null, graph);
}
@Override
public Edge createEdge(String id, Node source, Node target, boolean directed, Object typeLabel, Graph graph) {
Edge newEdge;
if (directed) {
newEdge = buildEdge(graph, id, source, target, true);
newEdge = buildEdge(graph, id, source, target, true, typeLabel);
if (graph.addEdge(newEdge)) {//The edge will be created if it does not already exist.
return newEdge;
} else {
return null;
}
} else {
newEdge = buildEdge(graph, id, source, target, false);
newEdge = buildEdge(graph, id, source, target, false, typeLabel);
if (graph.addEdge(newEdge)) {//The edge will be created if it does not already exist.
return newEdge;
} else {
......@@ -255,7 +274,7 @@ public class GraphElementsControllerImpl implements GraphElementsController {
continue;
}
newEdge = createEdge(newEdgeSource, newEdgeTarget, edge.isDirected(), graph);
newEdge = createEdge(newEdgeSource, newEdgeTarget, edge.isDirected(), edge.getTypeLabel(), graph);
if (newEdge != null) {//Edge may not be created if repeated
//Copy edge attributes:
......@@ -381,12 +400,20 @@ public class GraphElementsControllerImpl implements GraphElementsController {
return newNode;
}
private Edge buildEdge(Graph graph, String id, Node source, Node target, boolean directed) {
private Edge buildEdge(Graph graph, String id, Node source, Node target, boolean directed, Object typeLabel) {
int type;
if(typeLabel == null){
type = graph.getModel().getEdgeType(null);
} else {
//Create the type if missing:
type = graph.getModel().addEdgeType(typeLabel);
}
Edge newEdge;
if (id != null) {
newEdge = graph.getModel().factory().newEdge(id, source, target, DEFAULT_EDGE_TYPE, DEFAULT_EDGE_WEIGHT, directed);
newEdge = graph.getModel().factory().newEdge(id, source, target, type, DEFAULT_EDGE_WEIGHT, directed);
} else {
newEdge = graph.getModel().factory().newEdge(source, target, DEFAULT_EDGE_TYPE, DEFAULT_EDGE_WEIGHT, directed);
newEdge = graph.getModel().factory().newEdge(source, target, type, DEFAULT_EDGE_WEIGHT, directed);
}
return newEdge;
}
......
......@@ -64,12 +64,13 @@ public class AddEdgeToGraph implements GeneralActionsManipulator {
private Node source = null, target = null;
private boolean directed;
private Object edgeTypeLabel = null;
private GraphModel graphModel = null;
@Override
public void execute() {
if (source != null && target != null) {
Lookup.getDefault().lookup(GraphElementsController.class).createEdge(source, target, directed);
Lookup.getDefault().lookup(GraphElementsController.class).createEdge(source, target, directed, edgeTypeLabel);
}
}
......@@ -137,4 +138,12 @@ public class AddEdgeToGraph implements GeneralActionsManipulator {
public void setTarget(Node target) {
this.target = target;
}
public Object getEdgeTypeLabel() {
return edgeTypeLabel;
}
public void setEdgeTypeLabel(Object edgeTypeLabel) {
this.edgeTypeLabel = edgeTypeLabel;
}
}
......@@ -40,6 +40,11 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="targetNodesComboBox" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="edgeTypeLabel" min="-2" pref="73" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="edgeTypeComboBox" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
......@@ -50,7 +55,7 @@
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="descriptionLabel" min="-2" pref="25" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="directedRadioButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="undirectedRadioButton" alignment="3" min="-2" max="-2" attributes="0"/>
......@@ -65,7 +70,12 @@
<Component id="targetNodesComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="targetNodeLabel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="edgeTypeLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="edgeTypeComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
......@@ -135,5 +145,23 @@
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="edgeTypeLabel">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/datalab/plugin/manipulators/general/ui/Bundle.properties" key="AddEdgeToGraphUI.edgeTypeLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="edgeTypeComboBox">
<Properties>
<Property name="editable" type="boolean" value="true"/>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="edgeTypeComboBoxActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
......@@ -50,6 +50,7 @@ import org.gephi.datalab.spi.ManipulatorUI;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.openide.util.Lookup;
......@@ -81,24 +82,25 @@ public class AddEdgeToGraphUI extends javax.swing.JPanel implements ManipulatorU
} else {
undirectedRadioButton.setSelected(true);
}
graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
nodes = graph.getNodes().toArray();
for (Node n : nodes) {
sourceNodesComboBox.addItem(n.getId() + " - " + n.getLabel());
}
Node selectedSource = manipulator.getSource();
if(selectedSource != null){
if (selectedSource != null) {
for (int i = 0; i < nodes.length; i++) {
if(nodes[i] == selectedSource){
if (nodes[i] == selectedSource) {
sourceNodesComboBox.setSelectedIndex(i);
}
}
}
refreshAvailableTargetNodes();
refreshAvailableEdgeTypes();
}
@Override
......@@ -107,6 +109,8 @@ public class AddEdgeToGraphUI extends javax.swing.JPanel implements ManipulatorU
if (targetNodesComboBox.getSelectedIndex() != -1) {
manipulator.setSource(nodes[sourceNodesComboBox.getSelectedIndex()]);
manipulator.setTarget(targetNodes[targetNodesComboBox.getSelectedIndex()]);
String edgeType = getSelectedEdgeType();
manipulator.setEdgeTypeLabel(edgeType);
}
}
......@@ -124,14 +128,29 @@ public class AddEdgeToGraphUI extends javax.swing.JPanel implements ManipulatorU
public boolean isModal() {
return true;
}
private boolean canCreateEdge(Graph graph, Node source, Node target, boolean undirected) {
Edge existingEdge = graph.getEdge(source, target);
if(existingEdge == null && undirected){
existingEdge = graph.getEdge(target, source);
private String getSelectedEdgeType(){
String edgeType = edgeTypeComboBox.getSelectedItem() != null ? edgeTypeComboBox.getSelectedItem().toString() : null;
if(edgeType != null && edgeType.trim().isEmpty()){
edgeType = null;
}
return edgeType;
}
private boolean canCreateEdge(Graph graph, Node source, Node target, boolean undirected, String edgeType) {
GraphModel model = graph.getModel();
int type = model.getEdgeType(edgeType);
if (type == -1) {
return true;//New type
}
Edge existingEdge = graph.getEdge(source, target, type);
if (existingEdge == null && undirected) {
existingEdge = graph.getEdge(target, source, type);
}
return existingEdge == null;//Edge in that direction not found. An edge in the opposite direction is allowed.
}
......@@ -139,10 +158,11 @@ public class AddEdgeToGraphUI extends javax.swing.JPanel implements ManipulatorU
if (nodes != null) {
ArrayList<Node> availableTargetNodes = new ArrayList<Node>();
Node sourceNode = nodes[sourceNodesComboBox.getSelectedIndex()];
boolean undirected = undirectedRadioButton.isSelected();
String edgeType = getSelectedEdgeType();
for (Node targetNode : nodes) {
if (canCreateEdge(graph, sourceNode, targetNode, undirected)) {
if (canCreateEdge(graph, sourceNode, targetNode, undirected, edgeType)) {
availableTargetNodes.add(targetNode);
}
}
......@@ -156,6 +176,12 @@ public class AddEdgeToGraphUI extends javax.swing.JPanel implements ManipulatorU
}
}
private void refreshAvailableEdgeTypes() {
for (Object edgeType : graph.getModel().getEdgeTypeLabels()) {
edgeTypeComboBox.addItem(edgeType);
}
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
*/
......@@ -171,6 +197,8 @@ public class AddEdgeToGraphUI extends javax.swing.JPanel implements ManipulatorU
sourceNodeLabel = new javax.swing.JLabel();
targetNodeLabel = new javax.swing.JLabel();
targetNodesComboBox = new javax.swing.JComboBox();
edgeTypeLabel = new javax.swing.JLabel();
edgeTypeComboBox = new javax.swing.JComboBox();
directedUndirectedRadioButtonGroup.add(directedRadioButton);
directedRadioButton.setText(org.openide.util.NbBundle.getMessage(AddEdgeToGraphUI.class, "AddEdgeToGraphUI.directedRadioButton.text")); // NOI18N
......@@ -200,6 +228,15 @@ public class AddEdgeToGraphUI extends javax.swing.JPanel implements ManipulatorU
targetNodeLabel.setText(org.openide.util.NbBundle.getMessage(AddEdgeToGraphUI.class, "AddEdgeToGraphUI.targetNodeLabel.text")); // NOI18N
edgeTypeLabel.setText(org.openide.util.NbBundle.getMessage(AddEdgeToGraphUI.class, "AddEdgeToGraphUI.edgeTypeLabel.text")); // NOI18N
edgeTypeComboBox.setEditable(true);
edgeTypeComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
edgeTypeComboBoxActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
......@@ -219,7 +256,11 @@ public class AddEdgeToGraphUI extends javax.swing.JPanel implements ManipulatorU
.addGroup(layout.createSequentialGroup()
.addComponent(targetNodeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(targetNodesComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(targetNodesComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(edgeTypeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(edgeTypeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
......@@ -227,7 +268,7 @@ public class AddEdgeToGraphUI extends javax.swing.JPanel implements ManipulatorU
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(directedRadioButton)
.addComponent(undirectedRadioButton))
......@@ -239,7 +280,11 @@ public class AddEdgeToGraphUI extends javax.swing.JPanel implements ManipulatorU
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(targetNodesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(targetNodeLabel))
.addContainerGap())
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(edgeTypeLabel)
.addComponent(edgeTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
......@@ -254,10 +299,17 @@ public class AddEdgeToGraphUI extends javax.swing.JPanel implements ManipulatorU
private void undirectedRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_undirectedRadioButtonItemStateChanged
refreshAvailableTargetNodes();
}//GEN-LAST:event_undirectedRadioButtonItemStateChanged
private void edgeTypeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_edgeTypeComboBoxActionPerformed
refreshAvailableTargetNodes();
}//GEN-LAST:event_edgeTypeComboBoxActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel descriptionLabel;
private javax.swing.JRadioButton directedRadioButton;
private javax.swing.ButtonGroup directedUndirectedRadioButtonGroup;
private javax.swing.JComboBox edgeTypeComboBox;
private javax.swing.JLabel edgeTypeLabel;
private javax.swing.JLabel sourceNodeLabel;
private javax.swing.JComboBox sourceNodesComboBox;
private javax.swing.JLabel targetNodeLabel;
......
......@@ -6,6 +6,7 @@ AddEdgeToGraphUI.directedRadioButton.text=Directed
AddEdgeToGraphUI.undirectedRadioButton.text=Undirected
AddEdgeToGraphUI.sourceNodeLabel.text=Source node:
AddEdgeToGraphUI.targetNodeLabel.text=Target node:
AddEdgeToGraphUI.edgeTypeLabel.text=Edge Kind:
SearchReplaceUI.searchLabel.text=Search:
SearchReplaceUI.replaceLabel.text=Replace with:
SearchReplaceUI.matchWholeValueCheckBox.text=Only match whole value
......
......@@ -19,21 +19,23 @@
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="showEdgesNodesLabelsCheckBox" alignment="0" max="32767" attributes="1"/>
<Component id="timeIntervalsGraphicsCheckBox" alignment="0" max="32767" attributes="1"/>
<Component id="useSparklinesCheckBox" pref="301" max="32767" attributes="1"/>
<Component id="onlyVisibleCheckBox" alignment="0" max="32767" attributes="1"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Component id="timeZoneLabel" min="-2" pref="87" max="-2" attributes="0"/>
<Component id="timeFormatLabel" min="-2" pref="87" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="timeFormatLabel" min="-2" pref="96" max="-2" attributes="0"/>
<Component id="timeZoneLabel" min="-2" pref="106" max="-2" attributes="0"/>
<Component id="timeRepresentationLabel" alignment="0" min="-2" pref="109" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="timeZoneComboBox" max="32767" attributes="0"/>
<Component id="timeRepresentationComboBox" max="32767" attributes="0"/>
<Component id="timeFormatComboBox" max="32767" attributes="0"/>
<Component id="timeZoneComboBox" max="32767" attributes="0"/>
</Group>
</Group>
<Component id="showEdgesNodesLabelsCheckBox" alignment="0" max="32767" attributes="1"/>
<Component id="timeIntervalsGraphicsCheckBox" alignment="0" max="32767" attributes="1"/>
<Component id="useSparklinesCheckBox" pref="305" max="32767" attributes="1"/>
<Component id="onlyVisibleCheckBox" alignment="0" max="32767" attributes="1"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
......@@ -60,6 +62,11 @@
<Component id="timeZoneLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="timeZoneComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="timeRepresentationLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="timeRepresentationComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
......@@ -137,5 +144,22 @@
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value=""/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="timeRepresentationLabel">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/desktop/datalab/Bundle.properties" key="ConfigurationPanel.timeRepresentationLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="timeRepresentationComboBox">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value=""/>
</AuxValues>
</Component>
</SubComponents>
</Form>
......@@ -45,8 +45,11 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Configuration;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.TimeRepresentation;
import org.joda.time.DateTimeZone;
import org.openide.util.NbBundle;
......@@ -103,6 +106,50 @@ public class ConfigurationPanel extends javax.swing.JPanel {
dataTableTopComponent.refreshCurrentTable();
}
});
//Time representation:
for (TimeRepresentation tr : TimeRepresentation.values()) {
timeRepresentationComboBox.addItem(new TimeRepresentationWrapper(tr));
}
timeRepresentationComboBox.setSelectedItem(new TimeRepresentationWrapper(graphModel.getConfiguration().getTimeRepresentation()));
if (canChangeTimeRepresentation(graphModel)) {
timeRepresentationComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Configuration c = graphModel.getConfiguration();
c.setTimeRepresentation(((TimeRepresentationWrapper) timeRepresentationComboBox.getSelectedItem()).timeRepresentation);
graphModel.setConfiguration(c);
}
});
} else {
timeRepresentationComboBox.setEnabled(false);
timeRepresentationComboBox.setToolTipText(NbBundle.getMessage(ConfigurationPanel.class, "ConfigurationPanel.timeRepresentation.disabled.tooltip"));
}
}
private boolean canChangeTimeRepresentation(GraphModel graphModel) {
if (graphModel.getGraph().getEdgeCount() > 0) {
return false;//Graph has to be empty
}
//Also there cannot be any column apart from the basic ones:
for (Column column : graphModel.getNodeTable()) {
String id = column.getId();
if (!id.equalsIgnoreCase("Id") && !id.equalsIgnoreCase("Label") && !id.equalsIgnoreCase("timeset")) {
return false;
}
}
for (Column column : graphModel.getEdgeTable()) {
String id = column.getId();
if (!id.equalsIgnoreCase("Id") && !id.equalsIgnoreCase("Label") && !id.equalsIgnoreCase("timeset") && !id.equalsIgnoreCase("Weight")) {
return false;
}
}
return true;
}
private void buildTimeZoneList() {
......@@ -151,6 +198,45 @@ public class ConfigurationPanel extends javax.swing.JPanel {
}
}
class TimeRepresentationWrapper {
private final TimeRepresentation timeRepresentation;
public TimeRepresentationWrapper(TimeRepresentation timeRepresentation) {
this.timeRepresentation = timeRepresentation;
}
@Override
public int hashCode() {
int hash = 3;
hash = 41 * hash + (this.timeRepresentation != null ? this.timeRepresentation.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final TimeRepresentationWrapper other = (TimeRepresentationWrapper) obj;
if (this.timeRepresentation != other.timeRepresentation) {
return false;
}
return true;
}
@Override
public String toString() {
return NbBundle.getMessage(ConfigurationPanel.class, "ConfigurationPanel.timeRepresentation." + timeRepresentation.name());
}
}
class TimeZoneWrapper {
private final TimeZone timeZone;
......@@ -221,6 +307,8 @@ public class ConfigurationPanel extends javax.swing.JPanel {
timeFormatLabel = new javax.swing.JLabel();
timeZoneLabel = new javax.swing.JLabel();
timeZoneComboBox = new javax.swing.JComboBox();
timeRepresentationLabel = new javax.swing.JLabel();
timeRepresentationComboBox = new javax.swing.JComboBox();
onlyVisibleCheckBox.setText(org.openide.util.NbBundle.getMessage(ConfigurationPanel.class, "ConfigurationPanel.onlyVisibleCheckBox.text")); // NOI18N
onlyVisibleCheckBox.addActionListener(new java.awt.event.ActionListener() {
......@@ -254,6 +342,8 @@ public class ConfigurationPanel extends javax.swing.JPanel {
timeZoneLabel.setText(org.openide.util.NbBundle.getMessage(ConfigurationPanel.class, "ConfigurationPanel.timeZoneLabel.text")); // NOI18N
timeRepresentationLabel.setText(org.openide.util.NbBundle.getMessage(ConfigurationPanel.class, "ConfigurationPanel.timeRepresentationLabel.text")); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
......@@ -261,18 +351,20 @@ public class ConfigurationPanel extends javax.swing.JPanel {
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(showEdgesNodesLabelsCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(timeIntervalsGraphicsCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(useSparklinesCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE)
.addComponent(onlyVisibleCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(timeZoneLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(timeFormatLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(timeFormatLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(timeZoneLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(timeRepresentationLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(timeZoneComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(timeFormatComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(showEdgesNodesLabelsCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(timeIntervalsGraphicsCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(useSparklinesCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
.addComponent(onlyVisibleCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(timeRepresentationComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(timeFormatComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(timeZoneComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap())
);
layout.setVerticalGroup(
......@@ -294,6 +386,10 @@ public class ConfigurationPanel extends javax.swing.JPanel {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(timeZoneLabel)
.addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(timeRepresentationLabel)
.addComponent(timeRepresentationComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
......@@ -320,6 +416,8 @@ public class ConfigurationPanel extends javax.swing.JPanel {
private javax.swing.JComboBox timeFormatComboBox;
private javax.swing.JLabel timeFormatLabel;
private javax.swing.JCheckBox timeIntervalsGraphicsCheckBox;
private javax.swing.JComboBox timeRepresentationComboBox;
private javax.swing.JLabel timeRepresentationLabel;
private javax.swing.JComboBox timeZoneComboBox;
private javax.swing.JLabel timeZoneLabel;
private javax.swing.JCheckBox useSparklinesCheckBox;
......
......@@ -113,7 +113,7 @@ public abstract class AbstractElementsDataTable<T extends Element> {
prepareRenderers();
}
public abstract List<? extends ElementDataColumn<T>> getFakeDataColumns();
public abstract List<? extends ElementDataColumn<T>> getFakeDataColumns(GraphModel graphModel, DataTablesModel dataTablesModel);
private void prepareCellEditors() {
for (Class<?> typeClass : AttributeUtils.getSupportedTypes()) {
......@@ -195,12 +195,7 @@ public abstract class AbstractElementsDataTable<T extends Element> {
public void refreshModel(T[] elements, Column[] cols, GraphModel graphModel, DataTablesModel dataTablesModel) {
showingColumns = cols;
Interval timeBounds = null;
try {
timeBounds = graphModel.getTimeBounds();
} catch (Exception e) {
//Current graphstore does not implement this for intervals... (TODO)
}
Interval timeBounds = graphModel.getTimeBounds();
double min = timeBounds != null ? timeBounds.getLow() : Double.NEGATIVE_INFINITY;
double max = timeBounds != null ? timeBounds.getHigh() : Double.POSITIVE_INFINITY;
TimeFormat currentTimeFormat = graphModel.getTimeFormat();
......@@ -228,7 +223,7 @@ public abstract class AbstractElementsDataTable<T extends Element> {
selectedElements = getElementsFromSelectedRows();
}
ArrayList<ElementDataColumn<T>> columns = new ArrayList<ElementDataColumn<T>>();
columns.addAll(getFakeDataColumns());
columns.addAll(getFakeDataColumns(graphModel, dataTablesModel));
for (Column c : cols) {
columns.add(new AttributeDataColumn<T>(attributeColumnsController, c));
......@@ -253,15 +248,11 @@ public abstract class AbstractElementsDataTable<T extends Element> {
/**
*
* @param columnIndex View index, not model index
* @return
* @return Column or null if it's a fake column
*/
public Column getColumnAtIndex(int columnIndex) {
int realColumnIndex = table.convertColumnIndexToModel(columnIndex) - getFakeDataColumns().size();//Get real attribute column index not counting fake columns.
if (realColumnIndex >= 0 && realColumnIndex < showingColumns.length) {
return showingColumns[realColumnIndex];
} else {
return null;
}
int realColumnIndex = table.convertColumnIndexToModel(columnIndex);
return model.getColumnAtIndex(realColumnIndex);
}
public void setElementsSelection(List<T> elements) {
......
......@@ -51,8 +51,10 @@ import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.gephi.datalab.api.DataLaboratoryHelper;
import org.gephi.datalab.spi.edges.EdgesManipulator;
import org.gephi.desktop.datalab.DataTablesModel;
import org.gephi.desktop.datalab.tables.popup.EdgesPopupAdapter;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.GraphModel;
import org.gephi.tools.api.EditWindowController;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
......@@ -65,7 +67,7 @@ public final class EdgesDataTable extends AbstractElementsDataTable<Edge> {
public EdgesDataTable() {
super();
//Add listener of table selection to refresh edit window when the selection changes (and if the table is not being refreshed):
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
......@@ -83,9 +85,7 @@ public final class EdgesDataTable extends AbstractElementsDataTable<Edge> {
}
}
});
table.addMouseListener(new EdgesPopupAdapter(this));
table.addKeyListener(new KeyAdapter() {
......@@ -107,74 +107,87 @@ public final class EdgesDataTable extends AbstractElementsDataTable<Edge> {
}
});
}
private List<PropertyDataColumn<Edge>> propertiesColumns;
private boolean showEdgesNodesLabels = false;
@Override
public List<? extends ElementDataColumn<Edge>> getFakeDataColumns() {
if(propertiesColumns != null){
return propertiesColumns;
}
propertiesColumns = new ArrayList<PropertyDataColumn<Edge>>();
private final PropertyDataColumn<Edge> SOURCE_COLUMN = new PropertyDataColumn<Edge>(NbBundle.getMessage(EdgesDataTable.class, "EdgeDataTable.source.column.text")) {
propertiesColumns.add(new PropertyDataColumn<Edge>(NbBundle.getMessage(EdgesDataTable.class, "EdgeDataTable.source.column.text")) {
@Override
public Class getColumnClass() {
return String.class;
}
@Override
public Class getColumnClass() {
return String.class;
@Override
public Object getValueFor(Edge edge) {
if (showEdgesNodesLabels) {
return edge.getSource().getId() + " - " + edge.getSource().getLabel();
} else {
return edge.getSource().getId();
}
}
};
@Override
public Object getValueFor(Edge edge) {
if (showEdgesNodesLabels) {
return edge.getSource().getId() + " - " + edge.getSource().getLabel();
} else {
return edge.getSource().getId();
}
}
});
private final PropertyDataColumn<Edge> TARGET_COLUMN = new PropertyDataColumn<Edge>(NbBundle.getMessage(EdgesDataTable.class, "EdgeDataTable.target.column.text")) {
propertiesColumns.add(new PropertyDataColumn<Edge>(NbBundle.getMessage(EdgesDataTable.class, "EdgeDataTable.target.column.text")) {
@Override
public Class getColumnClass() {
return String.class;
}
@Override
public Class getColumnClass() {
return String.class;
@Override
public Object getValueFor(Edge edge) {
if (showEdgesNodesLabels) {
return edge.getTarget().getId() + " - " + edge.getTarget().getLabel();
} else {
return edge.getTarget().getId();
}
}
};
@Override
public Object getValueFor(Edge edge) {
if (showEdgesNodesLabels) {
return edge.getTarget().getId() + " - " + edge.getTarget().getLabel();
} else {
return edge.getTarget().getId();
}
}
});
propertiesColumns.add(new PropertyDataColumn<Edge>(NbBundle.getMessage(EdgesDataTable.class, "EdgeDataTable.type.column.text")) {
private final PropertyDataColumn<Edge> TYPE_COLUMN = new PropertyDataColumn<Edge>(NbBundle.getMessage(EdgesDataTable.class, "EdgeDataTable.type.column.text")) {
@Override
public Class getColumnClass() {
return String.class;
}
@Override
public Class getColumnClass() {
return String.class;
}
@Override
public Object getValueFor(Edge edge) {
if (edge.isDirected()) {
return NbBundle.getMessage(EdgesDataTable.class, "EdgeDataTable.type.column.directed");
} else {
return NbBundle.getMessage(EdgesDataTable.class, "EdgeDataTable.type.column.undirected");
}
@Override
public Object getValueFor(Edge edge) {
if (edge.isDirected()) {
return NbBundle.getMessage(EdgesDataTable.class, "EdgeDataTable.type.column.directed");
} else {
return NbBundle.getMessage(EdgesDataTable.class, "EdgeDataTable.type.column.undirected");
}
});
}
};
private final PropertyDataColumn<Edge> KIND_COLUMN = new PropertyDataColumn<Edge>(NbBundle.getMessage(EdgesDataTable.class, "EdgeDataTable.kind.column.text")) {
@Override
public Class getColumnClass() {
return String.class;
}
@Override
public Object getValueFor(Edge edge) {
return edge.getTypeLabel() != null ? edge.getTypeLabel().toString() : null;
}
};
@Override
public List<? extends ElementDataColumn<Edge>> getFakeDataColumns(GraphModel graphModel, DataTablesModel dataTablesModel) {
ArrayList<PropertyDataColumn<Edge>> propertiesColumns = new ArrayList<PropertyDataColumn<Edge>>();
propertiesColumns.add(SOURCE_COLUMN);
propertiesColumns.add(TARGET_COLUMN);
propertiesColumns.add(TYPE_COLUMN);
if (graphModel.isMultiGraph()) {
propertiesColumns.add(KIND_COLUMN);
}
return propertiesColumns;
}
public boolean isShowEdgesNodesLabels() {
return showEdgesNodesLabels;
}
......
......@@ -46,6 +46,7 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.swing.table.AbstractTableModel;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Element;
/**
......@@ -132,4 +133,16 @@ public class ElementsDataTableModel<T extends Element> extends AbstractTableMode
fireTableDataChanged();
}
}
/**
* Column at index or null if it's a fake column.
* @return
*/
public Column getColumnAtIndex(int i){
if (i >= 0 && i < columns.length) {
return columns[i].getColumn();
} else {
return null;
}
}
}
......@@ -51,7 +51,9 @@ import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.gephi.datalab.api.DataLaboratoryHelper;
import org.gephi.datalab.spi.nodes.NodesManipulator;
import org.gephi.desktop.datalab.DataTablesModel;
import org.gephi.desktop.datalab.tables.popup.NodesPopupAdapter;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.tools.api.EditWindowController;
import org.openide.util.Lookup;
......@@ -110,7 +112,7 @@ public final class NodesDataTable extends AbstractElementsDataTable<Node> {
private final List<PropertyDataColumn<Node>> propertiesColumns = new ArrayList<PropertyDataColumn<Node>>();
@Override
public List<? extends ElementDataColumn<Node>> getFakeDataColumns() {
public List<? extends ElementDataColumn<Node>> getFakeDataColumns(GraphModel graphModel, DataTablesModel dataTablesModel) {
return propertiesColumns;
}
}
......@@ -105,4 +105,9 @@ public class AttributeDataColumn<T extends Element> implements ElementDataColumn
public boolean isEditable() {
return attributeColumnsController.canChangeColumnData(column);
}
@Override
public Column getColumn() {
return column;
}
}
......@@ -41,6 +41,7 @@
*/
package org.gephi.desktop.datalab.tables.columns;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Element;
/**
......@@ -58,4 +59,6 @@ public interface ElementDataColumn<T extends Element> {
public void setValueFor(T element, Object value);
public boolean isEditable();
public Column getColumn();
}
......@@ -41,6 +41,7 @@
*/
package org.gephi.desktop.datalab.tables.columns;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Element;
/**
......@@ -48,29 +49,35 @@ import org.gephi.graph.api.Element;
* @author Eduardo Ramos
*/
public abstract class PropertyDataColumn<T extends Element> implements ElementDataColumn<T> {
private final String name;
public PropertyDataColumn(String name) {
this.name = name;
}
public PropertyDataColumn(String name) {
this.name = name;
}
@Override
public abstract Class getColumnClass();
@Override
public abstract Class getColumnClass();
@Override
public String getColumnName() {
return name;
}
@Override
public String getColumnName() {
return name;
}
@Override
public abstract Object getValueFor(T element);
@Override
public abstract Object getValueFor(T element);
@Override
public void setValueFor(T element, Object value) {
}
@Override
public void setValueFor(T element, Object value) {
}
@Override
public boolean isEditable() {
return false;
}
@Override
public boolean isEditable() {
return false;
}
@Override
public Column getColumn() {
return null;
}
}
......@@ -50,3 +50,7 @@ ConfigurationPanel.timeFormat.DOUBLE=Double
ConfigurationPanel.timeFormat.DATE=Date
ConfigurationPanel.timeFormat.DATETIME=Date and time
ConfigurationPanel.timeZoneLabel.text=Time zone
ConfigurationPanel.timeRepresentationLabel.text=Time representation
ConfigurationPanel.timeRepresentation.INTERVAL=Intervals
ConfigurationPanel.timeRepresentation.TIMESTAMP=Timestamps
ConfigurationPanel.timeRepresentation.disabled.tooltip=Time representation can only be changed when the graph is empty
......@@ -2,4 +2,5 @@ EdgeDataTable.source.column.text=Source
EdgeDataTable.target.column.text=Target
EdgeDataTable.type.column.text=Type
EdgeDataTable.type.column.directed=Directed
EdgeDataTable.type.column.undirected=Undirected
\ No newline at end of file
EdgeDataTable.type.column.undirected=Undirected
EdgeDataTable.kind.column.text=Kind
\ No newline at end of file
......@@ -23,7 +23,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>graphstore</artifactId>
<version>0.4.4</version>
<version>0.4.5</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册