提交 ad5a2a08 编写于 作者: E Eduardo Ramos

Fix #1360 Table alternative rows sometimes have the wrong highlight color (unreadable)

上级 cbd68ce0
......@@ -21,15 +21,15 @@
<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="useSparklinesCheckBox" pref="321" max="32767" attributes="1"/>
<Component id="onlyVisibleCheckBox" alignment="0" max="32767" attributes="1"/>
<Group type="102" alignment="0" 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"/>
<Component id="timeRepresentationLabel" min="-2" pref="132" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="timeRepresentationComboBox" max="32767" attributes="0"/>
<Component id="timeFormatComboBox" max="32767" attributes="0"/>
......
......@@ -312,7 +312,6 @@ public class ConfigurationPanel extends javax.swing.JPanel {
onlyVisibleCheckBox.setText(org.openide.util.NbBundle.getMessage(ConfigurationPanel.class, "ConfigurationPanel.onlyVisibleCheckBox.text")); // NOI18N
onlyVisibleCheckBox.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
onlyVisibleCheckBoxActionPerformed(evt);
}
......@@ -320,7 +319,6 @@ public class ConfigurationPanel extends javax.swing.JPanel {
useSparklinesCheckBox.setText(org.openide.util.NbBundle.getMessage(ConfigurationPanel.class, "ConfigurationPanel.useSparklinesCheckBox.text")); // NOI18N
useSparklinesCheckBox.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
useSparklinesCheckBoxActionPerformed(evt);
}
......@@ -328,7 +326,6 @@ public class ConfigurationPanel extends javax.swing.JPanel {
showEdgesNodesLabelsCheckBox.setText(org.openide.util.NbBundle.getMessage(ConfigurationPanel.class, "ConfigurationPanel.showEdgesNodesLabelsCheckBox.text")); // NOI18N
showEdgesNodesLabelsCheckBox.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
showEdgesNodesLabelsCheckBoxActionPerformed(evt);
}
......@@ -336,7 +333,6 @@ public class ConfigurationPanel extends javax.swing.JPanel {
timeIntervalsGraphicsCheckBox.setText(org.openide.util.NbBundle.getMessage(ConfigurationPanel.class, "ConfigurationPanel.timeIntervalsGraphicsCheckBox.text")); // NOI18N
timeIntervalsGraphicsCheckBox.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
timeIntervalsGraphicsCheckBoxActionPerformed(evt);
}
......@@ -357,14 +353,14 @@ public class ConfigurationPanel extends javax.swing.JPanel {
.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(useSparklinesCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, 321, 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.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)
.addComponent(timeRepresentationLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(timeRepresentationComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(timeFormatComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
......
......@@ -56,26 +56,29 @@ import javax.swing.table.TableCellRenderer;
import org.gephi.graph.api.Column;
import org.gephi.datalab.api.AttributeColumnsController;
import org.gephi.desktop.datalab.tables.celleditors.AttributeTypesSupportCellEditor;
import org.gephi.desktop.datalab.utils.ArrayRenderer;
import org.gephi.desktop.datalab.utils.DefaultStringRepresentationRenderer;
import org.gephi.desktop.datalab.utils.DoubleRenderer;
import org.gephi.desktop.datalab.utils.IntervalMapRenderer;
import org.gephi.desktop.datalab.utils.TimestampMapRenderer;
import org.gephi.desktop.datalab.utils.SparkLinesRenderer;
import org.gephi.desktop.datalab.utils.IntervalSetRenderer;
import org.gephi.desktop.datalab.utils.TimestampSetRenderer;
import org.gephi.desktop.datalab.utils.stringconverters.ArrayStringConverter;
import org.gephi.desktop.datalab.utils.stringconverters.DefaultStringRepresentationConverter;
import org.gephi.desktop.datalab.utils.GraphModelProvider;
import org.gephi.desktop.datalab.utils.componentproviders.IntervalSetGraphicsComponentProvider;
import org.gephi.desktop.datalab.utils.componentproviders.AbstractSparklinesGraphicsComponentProvider;
import org.gephi.desktop.datalab.utils.componentproviders.ArraySparklinesGraphicsComponentProvider;
import org.gephi.desktop.datalab.utils.componentproviders.IntervalMapSparklinesGraphicsComponentProvider;
import org.gephi.desktop.datalab.utils.componentproviders.TimestampMapSparklinesGraphicsComponentProvider;
import org.gephi.desktop.datalab.utils.componentproviders.TimestampSetGraphicsComponentProvider;
import org.gephi.desktop.datalab.utils.stringconverters.DoubleStringConverter;
import org.gephi.desktop.datalab.utils.stringconverters.TimeMapStringConverter;
import org.gephi.desktop.datalab.utils.stringconverters.TimeSetStringConverter;
import org.gephi.graph.api.AttributeUtils;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Interval;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.types.IntervalMap;
import org.gephi.graph.api.types.IntervalSet;
import org.gephi.graph.api.types.TimestampMap;
import org.gephi.graph.api.types.TimestampSet;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.HighlighterFactory;
import org.joda.time.DateTimeZone;
import org.jdesktop.swingx.renderer.DefaultTableRenderer;
import org.openide.util.Lookup;
/**
......@@ -83,7 +86,7 @@ import org.openide.util.Lookup;
* @author Mathieu Bastian
* @author Eduardo Ramos
*/
public abstract class AbstractElementsDataTable<T extends Element> {
public abstract class AbstractElementsDataTable<T extends Element> implements GraphModelProvider {
protected final JXTable table;
protected String filterPattern;
......@@ -92,15 +95,25 @@ public abstract class AbstractElementsDataTable<T extends Element> {
protected boolean refreshingTable = false;
protected Column[] showingColumns = null;
protected ElementsDataTableModel<T> model;
private final IntervalSetRenderer intervalSetRenderer;
private final TimestampSetRenderer timestampSetRenderer;
private final IntervalMapRenderer intervalMapRenderer;
private final TimestampMapRenderer timestampMapRenderer;
private final List<AttributeTypesSupportCellEditor> cellEditors = new ArrayList<AttributeTypesSupportCellEditor>();
private final List<SparkLinesRenderer> sparkLinesRenderers;
private final ArrayRenderer arrayRenderer = new ArrayRenderer();
private final DefaultStringRepresentationRenderer defaultStringRepresentationRenderer = new DefaultStringRepresentationRenderer();
private final DoubleRenderer doubleRenderer = new DoubleRenderer();
protected GraphModel graphModel;
//Renderers:
private boolean drawTimeIntervalGraphics = false;
private boolean drawSparklines = false;
private final DefaultTableRenderer arrayRenderer = new DefaultTableRenderer(new ArrayStringConverter());
private final DefaultTableRenderer defaultStringRepresentationRenderer = new DefaultTableRenderer(new DefaultStringRepresentationConverter());
private final DefaultTableRenderer timeSetRenderer;
private final DefaultTableRenderer timeMapRenderer;
private final DefaultTableRenderer doubleRenderer = new DefaultTableRenderer(new DoubleStringConverter());
//Graphics renderers:
private final IntervalSetGraphicsComponentProvider intervalSetGraphicsComponentProvider;
private final TimestampSetGraphicsComponentProvider timestampSetGraphicsComponentProvider;
private final DefaultTableRenderer intervalSetGraphicsRenderer;
private final DefaultTableRenderer timestampSetGraphicsRenderer;
private final DefaultTableRenderer intervalMapSparklinesGraphicsRenderer;
private final DefaultTableRenderer timestampMapSparklinesGraphicsRenderer;
private final DefaultTableRenderer arraySparklinesGraphicsRenderer;
public AbstractElementsDataTable() {
attributeColumnsController = Lookup.getDefault().lookup(AttributeColumnsController.class);
......@@ -109,12 +122,20 @@ public abstract class AbstractElementsDataTable<T extends Element> {
table.setColumnControlVisible(false);
table.setSortable(true);
table.setAutoCreateRowSorter(true);
sparkLinesRenderers = new ArrayList<SparkLinesRenderer>();
intervalSetRenderer = new IntervalSetRenderer();
timestampSetRenderer = new TimestampSetRenderer();
intervalMapRenderer = new IntervalMapRenderer();
timestampMapRenderer = new TimestampMapRenderer();
intervalSetGraphicsComponentProvider = new IntervalSetGraphicsComponentProvider(this, table);
timestampSetGraphicsComponentProvider = new TimestampSetGraphicsComponentProvider(this, table);
intervalSetGraphicsRenderer = new DefaultTableRenderer(intervalSetGraphicsComponentProvider);
timestampSetGraphicsRenderer = new DefaultTableRenderer(timestampSetGraphicsComponentProvider);
timeSetRenderer = new DefaultTableRenderer(new TimeSetStringConverter(this));
timeMapRenderer = new DefaultTableRenderer(new TimeMapStringConverter(this));
intervalMapSparklinesGraphicsRenderer = new DefaultTableRenderer(new IntervalMapSparklinesGraphicsComponentProvider(this, table));
timestampMapSparklinesGraphicsRenderer = new DefaultTableRenderer(new TimestampMapSparklinesGraphicsComponentProvider(this, table));
arraySparklinesGraphicsRenderer = new DefaultTableRenderer(new ArraySparklinesGraphicsComponentProvider(this, table));
prepareCellEditors();
prepareRenderers();
}
......@@ -126,9 +147,7 @@ public abstract class AbstractElementsDataTable<T extends Element> {
//For booleans we want the default cell editor that uses a checkbox
//For any other type, use our own cell editor that supports all attribute types parsing.
if (!typeClass.equals(Boolean.class) && !typeClass.equals(boolean.class)) {
AttributeTypesSupportCellEditor cellEditor = new AttributeTypesSupportCellEditor(typeClass);
cellEditors.add(cellEditor);
table.setDefaultEditor(typeClass, cellEditor);
table.setDefaultEditor(typeClass, new AttributeTypesSupportCellEditor(this, typeClass));
}
}
}
......@@ -136,24 +155,32 @@ public abstract class AbstractElementsDataTable<T extends Element> {
private void prepareRenderers() {
for (Class<?> typeClass : AttributeUtils.getSupportedTypes()) {
TableCellRenderer typeRenderer = null;
if (typeClass.equals(IntervalSet.class)) {
typeRenderer = intervalSetRenderer;
}
if (typeClass.equals(TimestampSet.class)) {
typeRenderer = timestampSetRenderer;
}
boolean isNumberType = AttributeUtils.isNumberType(typeClass);
boolean isDynamic = AttributeUtils.isDynamicType(typeClass);
boolean isArray = typeClass.isArray();
if (isNumberType) {
if (isDynamic || isArray) {
SparkLinesRenderer renderer = new SparkLinesRenderer(typeClass);
sparkLinesRenderers.add(renderer);
typeRenderer = renderer;
} else {
if (typeClass.equals(IntervalSet.class)) {
typeRenderer = drawTimeIntervalGraphics ? intervalSetGraphicsRenderer : timeSetRenderer;
} else if (typeClass.equals(TimestampSet.class)) {
typeRenderer = drawTimeIntervalGraphics ? timestampSetGraphicsRenderer : timeSetRenderer;
} else if (drawSparklines && isNumberType && (isArray || isDynamic)) {
if (isArray) {
typeRenderer = arraySparklinesGraphicsRenderer;
} else if (IntervalMap.class.isAssignableFrom(typeClass)) {
typeRenderer = intervalMapSparklinesGraphicsRenderer;
} else if (TimestampMap.class.isAssignableFrom(typeClass)) {
typeRenderer = timestampMapSparklinesGraphicsRenderer;
}
}
if (typeRenderer == null) {
if (isArray) {
typeRenderer = arrayRenderer;
} else if (isDynamic) {
typeRenderer = timeMapRenderer;
} else if (isNumberType) {
boolean isDecimalType = typeClass.equals(Double.class)
|| typeClass.equals(double.class)
|| typeClass.equals(Float.class)
......@@ -163,17 +190,6 @@ public abstract class AbstractElementsDataTable<T extends Element> {
typeRenderer = doubleRenderer;
}
}
} else if (isArray) {
typeRenderer = arrayRenderer;
} else if (isDynamic) {
boolean isTimestampMapType = TimestampMap.class.isAssignableFrom(typeClass);
boolean isIntervalMapType = IntervalMap.class.isAssignableFrom(typeClass);
if (isTimestampMapType) {
typeRenderer = timestampMapRenderer;
} else if (isIntervalMapType) {
typeRenderer = intervalMapRenderer;
}
}
if (typeRenderer == null) {
......@@ -220,12 +236,14 @@ public abstract class AbstractElementsDataTable<T extends Element> {
}
public void refreshModel(T[] elements, Column[] cols, GraphModel graphModel, DataTablesModel dataTablesModel) {
this.graphModel = graphModel;
showingColumns = cols;
Interval timeBounds = graphModel.getTimeBounds();
double min = timeBounds != null ? timeBounds.getLow() : 0;
double max = timeBounds != null ? timeBounds.getHigh() : 0;
refreshCellRenderersAndEditorsConfiguration(graphModel, min, max);
refreshCellRenderersConfiguration(graphModel, min, max);
refreshingTable = true;
if (selectedElements == null) {
......@@ -250,33 +268,14 @@ public abstract class AbstractElementsDataTable<T extends Element> {
refreshingTable = false;
}
private void refreshCellRenderersAndEditorsConfiguration(GraphModel graphModel, double min, double max) {
TimeFormat currentTimeFormat = graphModel.getTimeFormat();
DateTimeZone currentTimeZone = graphModel.getTimeZone();
for (SparkLinesRenderer sparkLinesRenderer : sparkLinesRenderers) {
sparkLinesRenderer.setTimeFormat(currentTimeFormat);
sparkLinesRenderer.setTimeZone(currentTimeZone);
}
intervalSetRenderer.setTimeFormat(currentTimeFormat);
intervalSetRenderer.setTimeZone(currentTimeZone);
intervalSetRenderer.setMinMax(min, max);
timestampSetRenderer.setTimeFormat(currentTimeFormat);
timestampSetRenderer.setTimeZone(currentTimeZone);
timestampSetRenderer.setMinMax(min, max);
intervalMapRenderer.setTimeFormat(currentTimeFormat);
intervalMapRenderer.setTimeZone(currentTimeZone);
timestampMapRenderer.setTimeZone(currentTimeZone);
for (AttributeTypesSupportCellEditor cellEditor : cellEditors) {
cellEditor.setTimeFormat(currentTimeFormat);
cellEditor.setTimeZone(currentTimeZone);
}
private void refreshCellRenderersConfiguration(GraphModel graphModel, double min, double max) {
intervalSetGraphicsComponentProvider.setMinMax(min, max);
timestampSetGraphicsComponentProvider.setMinMax(min, max);
}
@Override
public GraphModel getGraphModel() {
return graphModel;
}
public boolean isRefreshingTable() {
......@@ -322,14 +321,17 @@ public abstract class AbstractElementsDataTable<T extends Element> {
}
public void setDrawSparklines(boolean drawSparklines) {
for (SparkLinesRenderer sparkLinesRenderer : sparkLinesRenderers) {
sparkLinesRenderer.setDrawGraphics(drawSparklines);
}
this.drawSparklines = drawSparklines;
prepareRenderers();
}
public void setDrawTimeIntervalGraphics(boolean drawTimeIntervalGraphics) {
intervalSetRenderer.setDrawGraphics(drawTimeIntervalGraphics);
timestampSetRenderer.setDrawGraphics(drawTimeIntervalGraphics);
this.drawTimeIntervalGraphics = drawTimeIntervalGraphics;
prepareRenderers();
}
public boolean isDrawTimeIntervalGraphics() {
return drawTimeIntervalGraphics;
}
public T getElementFromRow(int row) {
......
......@@ -48,7 +48,8 @@ import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import org.gephi.desktop.datalab.utils.DoubleRenderer;
import org.gephi.desktop.datalab.utils.stringconverters.DoubleStringConverter;
import org.gephi.desktop.datalab.utils.GraphModelProvider;
import org.gephi.graph.api.AttributeUtils;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.types.IntervalMap;
......@@ -65,6 +66,8 @@ public class AttributeTypesSupportCellEditor extends DefaultCellEditor {
private static final Border RED_BORDER = new LineBorder(Color.red);
private final GraphModelProvider graphModelProvider;
private final JTextField textField;
private final Border originalBorder;
private final Class<?> typeClass;
......@@ -75,11 +78,9 @@ public class AttributeTypesSupportCellEditor extends DefaultCellEditor {
private final boolean isArrayType;
private final boolean isDecimalType;
private TimeFormat timeFormat = TimeFormat.DOUBLE;
private DateTimeZone timeZone = DateTimeZone.UTC;
public AttributeTypesSupportCellEditor(Class<?> typeClass) {
public AttributeTypesSupportCellEditor(GraphModelProvider graphModelProvider, Class<?> typeClass) {
super(new JTextField());
this.graphModelProvider = graphModelProvider;
this.typeClass = typeClass;
textField = new JTextField();
......@@ -120,6 +121,9 @@ public class AttributeTypesSupportCellEditor extends DefaultCellEditor {
public Component getTableCellEditorComponent(JTable table,
Object value, boolean isSelected, int row, int column) {
TimeFormat timeFormat = graphModelProvider.getGraphModel().getTimeFormat();
DateTimeZone timeZone = graphModelProvider.getGraphModel().getTimeZone();
String valueStr;
if (value == null) {
valueStr = "";
......@@ -134,7 +138,7 @@ public class AttributeTypesSupportCellEditor extends DefaultCellEditor {
} else if (isArrayType) {
valueStr = AttributeUtils.printArray(value);
} else if (isDecimalType) {
valueStr = DoubleRenderer.FORMAT.format(value);
valueStr = DoubleStringConverter.FORMAT.format(value);
} else {
valueStr = value.toString();
}
......@@ -144,20 +148,4 @@ public class AttributeTypesSupportCellEditor extends DefaultCellEditor {
textField.setText(valueStr);
return textField;
}
public TimeFormat getTimeFormat() {
return timeFormat;
}
public void setTimeFormat(TimeFormat timeFormat) {
this.timeFormat = timeFormat;
}
public DateTimeZone getTimeZone() {
return timeZone;
}
public void setTimeZone(DateTimeZone timeZone) {
this.timeZone = timeZone;
}
}
/*
Copyright 2008-2010 Gephi
Authors : Eduardo Ramos
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.desktop.datalab.utils;
import org.gephi.graph.api.GraphModel;
/**
*
* @author Eduardo Ramos
*/
public interface GraphModelProvider {
/**
* Returns the current graph model. Cannot be null
* @return
*/
GraphModel getGraphModel();
}
/*
Copyright 2008-2010 Gephi
Authors : Eduardo Ramos
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.desktop.datalab.utils;
import java.awt.Color;
import java.awt.Component;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.types.IntervalSet;
import org.gephi.utils.TimeIntervalGraphics;
import org.joda.time.DateTimeZone;
/**
* TableCellRenderer for drawing time intervals graphics from cells that have a {@link IntervalSet} as their value.
*
* @author Eduardo Ramos
*/
public class IntervalSetRenderer extends DefaultTableCellRenderer {
private static final Color SELECTED_BACKGROUND = new Color(225, 255, 255);
private static final Color UNSELECTED_BACKGROUND = Color.white;
private static final Color FILL_COLOR = new Color(153, 255, 255);
private static final Color BORDER_COLOR = new Color(2, 104, 255);
private boolean drawGraphics = false;
private final TimeIntervalGraphics timeIntervalGraphics;
private TimeFormat timeFormat = TimeFormat.DOUBLE;
private DateTimeZone timeZone = DateTimeZone.UTC;
public IntervalSetRenderer() {
this(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
}
public IntervalSetRenderer(double min, double max) {
timeIntervalGraphics = new TimeIntervalGraphics(min, max);
}
public IntervalSetRenderer(double min, double max, boolean drawGraphics) {
timeIntervalGraphics = new TimeIntervalGraphics(min, max);
this.drawGraphics = drawGraphics;
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value == null) {
//Render empty string when null
return super.getTableCellRendererComponent(table, null, isSelected, hasFocus, row, column);
}
IntervalSet intervalSet = (IntervalSet) value;
String stringRepresentation = intervalSet.toString(timeFormat, timeZone);
if (drawGraphics) {
JLabel label = new JLabel();
Color background;
if (isSelected) {
background = SELECTED_BACKGROUND;
} else {
background = UNSELECTED_BACKGROUND;
}
double[] intervals = intervalSet.getIntervals();
double starts[] = new double[intervals.length / 2];
double ends[] = new double[intervals.length / 2];
for (int i = 0, startIndex = 0; startIndex < intervals.length; i++, startIndex += 2) {
starts[i] = intervals[startIndex];
ends[i] = intervals[startIndex + 1];
}
final BufferedImage i = timeIntervalGraphics.createTimeIntervalImage(starts, ends, table.getColumnModel().getColumn(column).getWidth() - 1, table.getRowHeight(row) - 1, FILL_COLOR, BORDER_COLOR, background);
label.setIcon(new ImageIcon(i));
label.setToolTipText(stringRepresentation);//String representation as tooltip
return label;
} else {
return super.getTableCellRendererComponent(table, stringRepresentation, isSelected, hasFocus, row, column);
}
}
public boolean isDrawGraphics() {
return drawGraphics;
}
public void setDrawGraphics(boolean drawGraphics) {
this.drawGraphics = drawGraphics;
}
public TimeFormat getTimeFormat() {
return timeFormat;
}
public void setTimeFormat(TimeFormat timeFormat) {
this.timeFormat = timeFormat;
}
public DateTimeZone getTimeZone() {
return timeZone;
}
public void setTimeZone(DateTimeZone timeZone) {
this.timeZone = timeZone;
}
public double getMax() {
return timeIntervalGraphics.getMax();
}
public double getMin() {
return timeIntervalGraphics.getMin();
}
public void setMinMax(double min, double max) {
timeIntervalGraphics.setMinMax(min, max);
}
}
/*
Copyright 2008-2010 Gephi
Authors : Eduardo Ramos
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.desktop.datalab.utils;
import java.awt.Color;
import java.awt.Component;
import java.awt.image.BufferedImage;
import java.lang.reflect.Array;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import org.gephi.graph.api.AttributeUtils;
import org.gephi.graph.api.Interval;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.types.IntervalMap;
import org.gephi.graph.api.types.TimestampMap;
import org.gephi.utils.sparklines.SparklineGraph;
import org.gephi.utils.sparklines.SparklineParameters;
import org.joda.time.DateTimeZone;
/**
* TableCellRenderer for drawing sparklines from cells that have a NumberList or DynamicNumber as their value.
*
* @author Eduardo Ramos
*/
public class SparkLinesRenderer extends DefaultTableCellRenderer {
private static final Color SELECTED_BACKGROUND = new Color(225, 255, 255);
private static final Color UNSELECTED_BACKGROUND = Color.white;
private TimeFormat timeFormat = TimeFormat.DOUBLE;
private DateTimeZone timeZone = DateTimeZone.UTC;
private boolean drawGraphics = false;
//Config:
private final boolean isTimestampMapType;
private final boolean isIntervalMapType;
private final boolean isArrayType;
public SparkLinesRenderer(Class<?> typeClass) {
if(!AttributeUtils.isNumberType(typeClass)){
throw new IllegalArgumentException("Unsupported type " + typeClass.getName());
}
isTimestampMapType = TimestampMap.class.isAssignableFrom(typeClass);
isIntervalMapType = IntervalMap.class.isAssignableFrom(typeClass);
isArrayType = typeClass.isArray();
if(!isTimestampMapType && !isIntervalMapType && !isArrayType){
throw new IllegalArgumentException("Unsupported type " + typeClass.getName());
}
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value == null) {
//Render empty string when null
return super.getTableCellRendererComponent(table, null, isSelected, hasFocus, row, column);
}
String stringRepresentation = null;
if (isArrayType) {
stringRepresentation = AttributeUtils.printArray(value);
} else if (isTimestampMapType) {
stringRepresentation = ((TimestampMap) value).toString(timeFormat, timeZone);
} else if (isIntervalMapType) {
stringRepresentation = ((IntervalMap) value).toString(timeFormat, timeZone);
}
if (drawGraphics) {
Number[] xValues = null;
Number[] yValues = null;
if (isArrayType) {
yValues = getArrayNumbers(value);
} else if (isTimestampMapType) {
//Use the intervals start time as X values
Number[][] values = getTimestampMapNumbers((TimestampMap) value);
xValues = values[0];
yValues = values[1];
} else if (isIntervalMapType) {
//Use the intervals start time as X values
Number[][] values = getIntervalMapNumbers((IntervalMap) value);
xValues = values[0];
yValues = values[1];
} else {
throw new IllegalArgumentException("Only number lists and dynamic numbers are supported for sparklines rendering");
}
//If there is less than 1 element, show as a String.
if (yValues.length < 1) {
return super.getTableCellRendererComponent(table, stringRepresentation, isSelected, hasFocus, row, column);
}
if (yValues.length == 1) {
//SparklineGraph needs at least 2 values, duplicate the only one we have to get a sparkline with a single line showing that the value does not change over time
xValues = null;
yValues = new Number[]{yValues[0], yValues[0]};
}
JLabel label = new JLabel();
Color background;
if (isSelected) {
background = SELECTED_BACKGROUND;
} else {
background = UNSELECTED_BACKGROUND;
}
//Note: Can't use interactive SparklineComponent because TableCellEditors don't receive mouse events.
final SparklineParameters sparklineParameters = new SparklineParameters(table.getColumnModel().getColumn(column).getWidth() - 1, table.getRowHeight(row) - 1, Color.BLUE, background, Color.RED, Color.GREEN, null);
final BufferedImage i = SparklineGraph.draw(xValues, yValues, sparklineParameters);
label.setIcon(new ImageIcon(i));
label.setToolTipText(stringRepresentation);//String representation as tooltip
return label;
} else {
return super.getTableCellRendererComponent(table, stringRepresentation, isSelected, hasFocus, row, column);
}
}
private Number[][] getTimestampMapNumbers(TimestampMap timestampMap) {
Double[] timestamps = timestampMap.toKeysArray();
Number[] values = (Number[]) timestampMap.toValuesArray();
return new Number[][]{timestamps, values};
}
private Number[][] getIntervalMapNumbers(IntervalMap intervalMap) {
ArrayList<Number> xValues = new ArrayList<Number>();
ArrayList<Number> yValues = new ArrayList<Number>();
if (intervalMap == null) {
return new Number[2][0];
}
Interval[] intervals = intervalMap.toKeysArray();
Object[] values = intervalMap.toValuesArray();
Number n;
for (int i = 0; i < intervals.length; i++) {
n = (Number) values[i];
if (n != null) {
xValues.add(intervals[i].getLow());
yValues.add(n);
}
}
return new Number[][]{xValues.toArray(new Number[0]), yValues.toArray(new Number[0])};
}
public TimeFormat getTimeFormat() {
return timeFormat;
}
public void setTimeFormat(TimeFormat timeFormat) {
this.timeFormat = timeFormat;
}
public DateTimeZone getTimeZone() {
return timeZone;
}
public void setTimeZone(DateTimeZone timeZone) {
this.timeZone = timeZone;
}
public boolean isDrawGraphics() {
return drawGraphics;
}
public void setDrawGraphics(boolean drawGraphics) {
this.drawGraphics = drawGraphics;
}
private Number[] getArrayNumbers(Object arr) {
int size = Array.getLength(arr);
Number[] result = new Number[size];
for (int i = 0; i < size; i++) {
result[i] = (Number) Array.get(arr, i);//This will do the auto-boxing of primitives
}
return result;
}
}
/*
Copyright 2008-2010 Gephi
Authors : Eduardo Ramos
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.desktop.datalab.utils;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.types.TimestampMap;
import org.joda.time.DateTimeZone;
/**
* TableCellRenderer for representing dynamic timestamp maps as strings in a table.
* Only used for non-numeric maps. Numeric maps use the sparklines renderer.
*
* @author Eduardo Ramos
*/
public class TimestampMapRenderer extends DefaultTableCellRenderer {
private TimeFormat timeFormat = TimeFormat.DOUBLE;
private DateTimeZone timeZone = DateTimeZone.UTC;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
String stringRepresentation = null;
if (value != null) {
stringRepresentation = ((TimestampMap) value).toString(timeFormat, timeZone);
}
return super.getTableCellRendererComponent(table, stringRepresentation, isSelected, hasFocus, row, column);
}
public TimeFormat getTimeFormat() {
return timeFormat;
}
public void setTimeFormat(TimeFormat timeFormat) {
this.timeFormat = timeFormat;
}
public DateTimeZone getTimeZone() {
return timeZone;
}
public void setTimeZone(DateTimeZone timeZone) {
this.timeZone = timeZone;
}
}
/*
Copyright 2008-2010 Gephi
Authors : Eduardo Ramos
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.desktop.datalab.utils;
import java.awt.Color;
import java.awt.Component;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.types.TimestampSet;
import org.gephi.utils.TimeIntervalGraphics;
import org.joda.time.DateTimeZone;
/**
* TableCellRenderer for drawing time intervals graphics from cells that have a {@link TimestampSet} as their value.
*
* @author Eduardo Ramos
*/
public class TimestampSetRenderer extends DefaultTableCellRenderer {
private static final Color SELECTED_BACKGROUND = new Color(225, 255, 255);
private static final Color UNSELECTED_BACKGROUND = Color.white;
private static final Color FILL_COLOR = new Color(153, 255, 255);
private static final Color BORDER_COLOR = new Color(2, 104, 255);
private boolean drawGraphics = false;
private final TimeIntervalGraphics timeIntervalGraphics;
private TimeFormat timeFormat = TimeFormat.DOUBLE;
private DateTimeZone timeZone = DateTimeZone.UTC;
public TimestampSetRenderer() {
this(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
}
public TimestampSetRenderer(double min, double max) {
timeIntervalGraphics = new TimeIntervalGraphics(min, max);
}
public TimestampSetRenderer(double min, double max, boolean drawGraphics) {
timeIntervalGraphics = new TimeIntervalGraphics(min, max);
this.drawGraphics = drawGraphics;
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value == null) {
//Render empty string when null
return super.getTableCellRendererComponent(table, null, isSelected, hasFocus, row, column);
}
TimestampSet timestampSet = (TimestampSet) value;
String stringRepresentation = timestampSet.toString(timeFormat, timeZone);
if (drawGraphics) {
JLabel label = new JLabel();
Color background;
if (isSelected) {
background = SELECTED_BACKGROUND;
} else {
background = UNSELECTED_BACKGROUND;
}
double[] timestamps = timestampSet.toPrimitiveArray();
double starts[] = new double[timestamps.length];
double ends[] = new double[timestamps.length];
for (int i = 0; i < timestamps.length; i++) {
starts[i] = timestamps[i];
ends[i] = timestamps[i];
}
final BufferedImage i = timeIntervalGraphics.createTimeIntervalImage(starts, ends, table.getColumnModel().getColumn(column).getWidth() - 1, table.getRowHeight(row) - 1, FILL_COLOR, BORDER_COLOR, background);
label.setIcon(new ImageIcon(i));
label.setToolTipText(stringRepresentation);//String representation as tooltip
return label;
} else {
return super.getTableCellRendererComponent(table, stringRepresentation, isSelected, hasFocus, row, column);
}
}
public boolean isDrawGraphics() {
return drawGraphics;
}
public void setDrawGraphics(boolean drawGraphics) {
this.drawGraphics = drawGraphics;
}
public TimeFormat getTimeFormat() {
return timeFormat;
}
public void setTimeFormat(TimeFormat timeFormat) {
this.timeFormat = timeFormat;
}
public DateTimeZone getTimeZone() {
return timeZone;
}
public void setTimeZone(DateTimeZone timeZone) {
this.timeZone = timeZone;
}
public double getMax() {
return timeIntervalGraphics.getMax();
}
public double getMin() {
return timeIntervalGraphics.getMin();
}
public void setMinMax(double min, double max) {
timeIntervalGraphics.setMinMax(min, max);
}
}
package org.gephi.desktop.datalab.utils.componentproviders;
import org.gephi.desktop.datalab.utils.GraphModelProvider;
import java.awt.Color;
import java.awt.image.BufferedImage;
import javax.swing.JLabel;
import org.gephi.utils.sparklines.SparklineGraph;
import org.gephi.utils.sparklines.SparklineParameters;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.painter.ImagePainter;
import org.jdesktop.swingx.renderer.CellContext;
import org.jdesktop.swingx.renderer.ComponentProvider;
import org.jdesktop.swingx.renderer.JRendererLabel;
/**
*
* @author Eduardo Ramos
*/
public abstract class AbstractSparklinesGraphicsComponentProvider extends ComponentProvider<JLabel> {
protected static final Color SELECTED_BACKGROUND = new Color(225, 255, 255);
protected static final Color UNSELECTED_BACKGROUND = Color.white;
protected final GraphModelProvider graphModelProvider;
protected final JXTable table;
protected JRendererLabel rendererLabel;
public AbstractSparklinesGraphicsComponentProvider(GraphModelProvider graphModelProvider, JXTable table) {
super(null, JLabel.LEADING);
this.graphModelProvider = graphModelProvider;
this.table = table;
}
public abstract String getTextFromValue(Object value);
@Override
protected void format(CellContext context) {
//Set image or text
int witdth = table.getColumnModel().getColumn(context.getColumn()).getWidth();
int height = table.getRowHeight(context.getRow());
String text = getTextFromValue(context.getValue());
rendererLabel.setSize(witdth, height);
rendererLabel.setToolTipText(text);
rendererLabel.setBorder(null);
setImagePainter(context.getValue(), context.isSelected());
}
@Override
protected void configureState(CellContext context) {
}
@Override
protected JLabel createRendererComponent() {
return rendererLabel = new JRendererLabel();
}
public void setImagePainter(Object value, boolean isSelected) {
if (value == null) {
rendererLabel.setPainter(null);
return;
}
Number[][] values = getSparklinesXAndYNumbers(value);
Number[] xValues = values[0];
Number[] yValues = values[1];
//If there is less than 1 element, don't show anything.
if (yValues.length < 1) {
rendererLabel.setPainter(null);
return;
}
if (yValues.length == 1) {
//SparklineGraph needs at least 2 values, duplicate the only one we have to get a sparkline with a single line showing that the value does not change over time
xValues = null;
yValues = new Number[]{yValues[0], yValues[0]};
}
Color background;
if (isSelected) {
background = SELECTED_BACKGROUND;
} else {
background = UNSELECTED_BACKGROUND;
}
//Note: Can't use interactive SparklineComponent because TableCellEditors don't receive mouse events.
final SparklineParameters sparklineParameters = new SparklineParameters(
rendererLabel.getWidth() - 1,
rendererLabel.getHeight() - 1,
Color.BLUE,
background,
Color.RED,
Color.GREEN,
null
);
final BufferedImage image = SparklineGraph.draw(xValues, yValues, sparklineParameters);
rendererLabel.setPainter(new ImagePainter(image));
}
public abstract Number[][] getSparklinesXAndYNumbers(Object value);
}
package org.gephi.desktop.datalab.utils.componentproviders;
import org.gephi.desktop.datalab.utils.GraphModelProvider;
import java.awt.Color;
import java.awt.image.BufferedImage;
import javax.swing.JLabel;
import org.gephi.graph.api.types.TimeSet;
import org.gephi.utils.TimeIntervalGraphics;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.painter.ImagePainter;
import org.jdesktop.swingx.renderer.CellContext;
import org.jdesktop.swingx.renderer.ComponentProvider;
import org.jdesktop.swingx.renderer.JRendererLabel;
/**
*
* @author Eduardo Ramos
*/
public abstract class AbstractTimeSetGraphicsComponentProvider extends ComponentProvider<JLabel> {
protected static final Color SELECTED_BACKGROUND = new Color(225, 255, 255);
protected static final Color UNSELECTED_BACKGROUND = Color.white;
protected static final Color FILL_COLOR = new Color(153, 255, 255);
protected static final Color BORDER_COLOR = new Color(2, 104, 255);
protected final TimeIntervalGraphics timeIntervalGraphics;
protected final JXTable table;
protected final GraphModelProvider graphModelProvider;
protected JRendererLabel rendererLabel;
public AbstractTimeSetGraphicsComponentProvider(GraphModelProvider graphModelProvider, JXTable table) {
super(null, JLabel.LEADING);
this.graphModelProvider = graphModelProvider;
this.table = table;
this.timeIntervalGraphics = new TimeIntervalGraphics(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
}
private String getTextFromValue(Object value) {
TimeSet timeSet = (TimeSet) value;
String text = null;
if (timeSet != null) {
text = timeSet.toString(graphModelProvider.getGraphModel().getTimeFormat(), graphModelProvider.getGraphModel().getTimeZone());
}
return text;
}
@Override
protected void format(CellContext context) {
//Set image or text
int witdth = table.getColumnModel().getColumn(context.getColumn()).getWidth();
int height = table.getRowHeight(context.getRow());
String text = getTextFromValue(context.getValue());
rendererLabel.setSize(witdth, height);
rendererLabel.setToolTipText(text);
rendererLabel.setBorder(null);
setImagePainter((TimeSet) context.getValue(), context.isSelected());
}
@Override
protected void configureState(CellContext context) {
}
@Override
protected JLabel createRendererComponent() {
return rendererLabel = new JRendererLabel();
}
protected class TimeIntervalGraphicsParameters {
private final double[] starts;
private final double[] ends;
public TimeIntervalGraphicsParameters(double[] starts, double[] ends) {
this.starts = starts;
this.ends = ends;
}
}
public abstract TimeIntervalGraphicsParameters getTimeIntervalGraphicsParameters(TimeSet value);
public void setImagePainter(TimeSet value, boolean isSelected) {
if (value == null) {
rendererLabel.setPainter(null);
return;
}
Color background;
if (isSelected) {
background = SELECTED_BACKGROUND;
} else {
background = UNSELECTED_BACKGROUND;
}
TimeIntervalGraphicsParameters params = getTimeIntervalGraphicsParameters(value);
final BufferedImage image = timeIntervalGraphics.createTimeIntervalImage(
params.starts,
params.ends,
rendererLabel.getWidth() - 1,
rendererLabel.getHeight() - 1,
FILL_COLOR,
BORDER_COLOR,
background
);
rendererLabel.setPainter(new ImagePainter(image));
}
public double getMax() {
return timeIntervalGraphics.getMax();
}
public double getMin() {
return timeIntervalGraphics.getMin();
}
public void setMinMax(double min, double max) {
timeIntervalGraphics.setMinMax(min, max);
}
}
package org.gephi.desktop.datalab.utils.componentproviders;
import java.lang.reflect.Array;
import org.gephi.desktop.datalab.utils.GraphModelProvider;
import org.gephi.graph.api.AttributeUtils;
import org.jdesktop.swingx.JXTable;
/**
*
* @author Eduardo Ramos
*/
public class ArraySparklinesGraphicsComponentProvider extends AbstractSparklinesGraphicsComponentProvider {
public ArraySparklinesGraphicsComponentProvider(GraphModelProvider graphModelProvider, JXTable table) {
super(graphModelProvider, table);
}
@Override
public String getTextFromValue(Object value) {
if (value == null) {
return null;
}
return AttributeUtils.printArray(value);
}
@Override
public Number[][] getSparklinesXAndYNumbers(Object arr) {
int size = Array.getLength(arr);
Number[] result = new Number[size];
for (int i = 0; i < size; i++) {
result[i] = (Number) Array.get(arr, i);//This will do the auto-boxing of primitives
}
return new Number[][]{null, result};
}
}
package org.gephi.desktop.datalab.utils.componentproviders;
import java.util.ArrayList;
import org.gephi.desktop.datalab.utils.GraphModelProvider;
import org.gephi.graph.api.Interval;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.types.IntervalMap;
import org.jdesktop.swingx.JXTable;
import org.joda.time.DateTimeZone;
/**
*
* @author Eduardo Ramos
*/
public class IntervalMapSparklinesGraphicsComponentProvider extends AbstractSparklinesGraphicsComponentProvider {
public IntervalMapSparklinesGraphicsComponentProvider(GraphModelProvider graphModelProvider, JXTable table) {
super(graphModelProvider, table);
}
@Override
public String getTextFromValue(Object value) {
if (value == null) {
return null;
}
TimeFormat timeFormat = graphModelProvider.getGraphModel().getTimeFormat();
DateTimeZone timeZone = graphModelProvider.getGraphModel().getTimeZone();
return ((IntervalMap) value).toString(timeFormat, timeZone);
}
@Override
public Number[][] getSparklinesXAndYNumbers(Object value) {
IntervalMap intervalMap = (IntervalMap) value;
ArrayList<Number> xValues = new ArrayList<Number>();
ArrayList<Number> yValues = new ArrayList<Number>();
if (intervalMap == null) {
return new Number[2][0];
}
Interval[] intervals = intervalMap.toKeysArray();
Object[] values = intervalMap.toValuesArray();
Number n;
for (int i = 0; i < intervals.length; i++) {
n = (Number) values[i];
if (n != null) {
xValues.add(intervals[i].getLow());
yValues.add(n);
}
}
return new Number[][]{xValues.toArray(new Number[0]), yValues.toArray(new Number[0])};
}
}
package org.gephi.desktop.datalab.utils.componentproviders;
import org.gephi.desktop.datalab.utils.GraphModelProvider;
import org.gephi.graph.api.types.IntervalSet;
import org.gephi.graph.api.types.TimeSet;
import org.jdesktop.swingx.JXTable;
/**
*
* @author Eduardo Ramos
*/
public class IntervalSetGraphicsComponentProvider extends AbstractTimeSetGraphicsComponentProvider {
public IntervalSetGraphicsComponentProvider(GraphModelProvider graphModelProvider, JXTable table) {
super(graphModelProvider, table);
}
@Override
public TimeIntervalGraphicsParameters getTimeIntervalGraphicsParameters(TimeSet value) {
IntervalSet intervalSet = (IntervalSet) value;
double[] intervals = intervalSet.getIntervals();
double starts[] = new double[intervals.length / 2];
double ends[] = new double[intervals.length / 2];
for (int i = 0, startIndex = 0; startIndex < intervals.length; i++, startIndex += 2) {
starts[i] = intervals[startIndex];
ends[i] = intervals[startIndex + 1];
}
return new TimeIntervalGraphicsParameters(starts, ends);
}
}
package org.gephi.desktop.datalab.utils.componentproviders;
import org.gephi.desktop.datalab.utils.GraphModelProvider;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.types.TimestampMap;
import org.jdesktop.swingx.JXTable;
import org.joda.time.DateTimeZone;
/**
*
* @author Eduardo Ramos
*/
public class TimestampMapSparklinesGraphicsComponentProvider extends AbstractSparklinesGraphicsComponentProvider {
public TimestampMapSparklinesGraphicsComponentProvider(GraphModelProvider graphModelProvider, JXTable table) {
super(graphModelProvider, table);
}
@Override
public String getTextFromValue(Object value) {
if (value == null) {
return null;
}
TimeFormat timeFormat = graphModelProvider.getGraphModel().getTimeFormat();
DateTimeZone timeZone = graphModelProvider.getGraphModel().getTimeZone();
return ((TimestampMap) value).toString(timeFormat, timeZone);
}
@Override
public Number[][] getSparklinesXAndYNumbers(Object value) {
TimestampMap timestampMap = (TimestampMap) value;
Double[] timestamps = timestampMap.toKeysArray();
Number[] values = (Number[]) timestampMap.toValuesArray();
return new Number[][]{timestamps, values};
}
}
package org.gephi.desktop.datalab.utils.componentproviders;
import org.gephi.desktop.datalab.utils.GraphModelProvider;
import org.gephi.graph.api.types.TimestampSet;
import org.gephi.graph.api.types.TimeSet;
import org.jdesktop.swingx.JXTable;
/**
*
* @author Eduardo Ramos
*/
public class TimestampSetGraphicsComponentProvider extends AbstractTimeSetGraphicsComponentProvider {
public TimestampSetGraphicsComponentProvider(GraphModelProvider graphModelProvider, JXTable table) {
super(graphModelProvider, table);
}
@Override
public TimeIntervalGraphicsParameters getTimeIntervalGraphicsParameters(TimeSet value) {
TimestampSet timestampSet = (TimestampSet) value;
double[] timestamps = timestampSet.toPrimitiveArray();
double starts[] = new double[timestamps.length];
double ends[] = new double[timestamps.length];
for (int i = 0; i < timestamps.length; i++) {
starts[i] = timestamps[i];
ends[i] = timestamps[i];
}
return new TimeIntervalGraphicsParameters(starts, ends);
}
}
......@@ -39,30 +39,26 @@
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.desktop.datalab.utils;
package org.gephi.desktop.datalab.utils.stringconverters;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import org.gephi.graph.api.AttributeUtils;
import org.jdesktop.swingx.renderer.StringValue;
/**
* TableCellRenderer for representing arrays as strings in a table.
* SwingX renderer for representing arrays as strings in a table.
* Only used for non-numeric arrays. Numeric arrays use the sparklines renderer.
*
* @author Eduardo Ramos
*/
public class ArrayRenderer extends DefaultTableCellRenderer {
public class ArrayStringConverter implements StringValue {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
String stringRepresentation = null;
public String getString(Object value) {
String str = null;
if (value != null) {
stringRepresentation = AttributeUtils.printArray(value);
str = AttributeUtils.printArray(value);
}
return super.getTableCellRendererComponent(table, stringRepresentation, isSelected, hasFocus, row, column);
return str;
}
}
......@@ -39,27 +39,25 @@
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.desktop.datalab.utils;
package org.gephi.desktop.datalab.utils.stringconverters;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import org.jdesktop.swingx.renderer.StringValue;
/**
* TableCellRenderer for representing gephi supported types always with the toString representation, independently of user language, etc.
* Only used for types that don't have any other special renderer. Used for example with primitive wrappers, BigDecimal and BigInteger
* SwingX renderer for representing gephi supported types always with the toString representation, independently of user language, etc.
* Only used for types that don't have any other special renderer. Used for example with primitive wrappers, String, BigDecimal and BigInteger
*
* @author Eduardo Ramos
*/
public class DefaultStringRepresentationRenderer extends DefaultTableCellRenderer {
public class DefaultStringRepresentationConverter implements StringValue {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
String stringRepresentation = null;
public String getString(Object value) {
String str = null;
if (value != null) {
stringRepresentation = value.toString();
str = value.toString();
}
return super.getTableCellRendererComponent(table, stringRepresentation, isSelected, hasFocus, row, column);
return str;
}
}
......@@ -39,21 +39,19 @@
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.desktop.datalab.utils;
package org.gephi.desktop.datalab.utils.stringconverters;
import java.awt.Component;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import org.jdesktop.swingx.renderer.StringValue;
/**
* TableCellRenderer for representing float/doubles always with the english locale representation, and a limited precision, independently of user language, etc.
* SwingX converter for representing float/doubles always with the english locale representation, and a limited precision, independently of user language, etc.
*
* @author Eduardo Ramos
*/
public class DoubleRenderer extends DefaultTableCellRenderer {
public class DoubleStringConverter implements StringValue {
/**
* Formatter for limiting precision to 6 decimals, avoiding precision errors (epsilon).
......@@ -66,12 +64,12 @@ public class DoubleRenderer extends DefaultTableCellRenderer {
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
String stringRepresentation = null;
public String getString(Object value) {
String str = null;
if (value != null) {
stringRepresentation = FORMAT.format(value);
str = FORMAT.format(value);
}
return super.getTableCellRendererComponent(table, stringRepresentation, isSelected, hasFocus, row, column);
return str;
}
}
......@@ -39,49 +39,34 @@
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.desktop.datalab.utils;
package org.gephi.desktop.datalab.utils.stringconverters;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.types.IntervalMap;
import org.joda.time.DateTimeZone;
import org.gephi.desktop.datalab.utils.GraphModelProvider;
import org.gephi.graph.api.types.TimeMap;
import org.gephi.graph.api.types.TimeSet;
import org.jdesktop.swingx.renderer.StringValue;
/**
* TableCellRenderer for representing dynamic interval maps as strings in a table.
* Only used for non-numeric maps. Numeric maps use the sparklines renderer.
* SwingX renderer for representing {@link TimeSet} as strings in a table.
*
* @author Eduardo Ramos
*/
public class IntervalMapRenderer extends DefaultTableCellRenderer {
private TimeFormat timeFormat = TimeFormat.DOUBLE;
private DateTimeZone timeZone = DateTimeZone.UTC;
public class TimeMapStringConverter implements StringValue {
private final GraphModelProvider graphModelProvider;
public TimeMapStringConverter(GraphModelProvider graphModelProvider) {
this.graphModelProvider = graphModelProvider;
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
String stringRepresentation = null;
public String getString(Object value) {
String str = null;
if (value != null) {
stringRepresentation = ((IntervalMap) value).toString(timeFormat, timeZone);
TimeMap timeMap = (TimeMap) value;
str = timeMap.toString(graphModelProvider.getGraphModel().getTimeFormat(), graphModelProvider.getGraphModel().getTimeZone());
}
return super.getTableCellRendererComponent(table, stringRepresentation, isSelected, hasFocus, row, column);
}
public TimeFormat getTimeFormat() {
return timeFormat;
}
public void setTimeFormat(TimeFormat timeFormat) {
this.timeFormat = timeFormat;
}
public DateTimeZone getTimeZone() {
return timeZone;
}
public void setTimeZone(DateTimeZone timeZone) {
this.timeZone = timeZone;
return str;
}
}
/*
Copyright 2008-2010 Gephi
Authors : Eduardo Ramos
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.desktop.datalab.utils.stringconverters;
import org.gephi.desktop.datalab.utils.GraphModelProvider;
import org.gephi.graph.api.types.TimeSet;
import org.jdesktop.swingx.renderer.StringValue;
/**
* SwingX renderer for representing {@link TimeSet} as strings in a table.
*
* @author Eduardo Ramos
*/
public class TimeSetStringConverter implements StringValue {
private final GraphModelProvider graphModelProvider;
public TimeSetStringConverter(GraphModelProvider graphModelProvider) {
this.graphModelProvider = graphModelProvider;
}
@Override
public String getString(Object value) {
String str = null;
if (value != null) {
TimeSet timeSet = (TimeSet) value;
str = timeSet.toString(graphModelProvider.getGraphModel().getTimeFormat(), graphModelProvider.getGraphModel().getTimeZone());
}
return str;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册