Skip to content

Commit

Permalink
fixed problem related to hsv and rob colors.
Browse files Browse the repository at this point in the history
changed default values of text: color and alignment.
other bugs related to legend persistence are fixed
TODO: a field to edit table values, change colors of groups.
  • Loading branch information
edubecks committed Nov 19, 2012
1 parent 8e77b1d commit 63f1835
Show file tree
Hide file tree
Showing 18 changed files with 443 additions and 316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void refreshActiveLegendsComboBox() {
} else {
activeLegendsComboBox.setSelectedIndex(-1);
}
refreshRenderers();
refreshRenderers(activeLegendItem);
refreshPropertySheet();
}

Expand Down Expand Up @@ -310,12 +310,25 @@ private void removeLegendButtonActionPerformed(java.awt.event.ActionEvent evt) {
}//GEN-LAST:event_removeLegendButtonActionPerformed

private void activeLegendsComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_activeLegendsComboBoxActionPerformed
Item activeLegendItem = (Item) activeLegendsComboBox.getSelectedItem();
setActiveItem(activeLegendItem);
System.out.println("@Var: activeLegendsComboBox.getSelectedItem(): "+activeLegendsComboBox.getSelectedItem());
if(activeLegendsComboBox.getSelectedItem()!=null){
Item activeLegendItem = (Item) activeLegendsComboBox.getSelectedItem();
Object currentRenderer = activeLegendItem.getData(LegendItem.RENDERER);
System.out.println("@Var: OLD currentRenderer: "+currentRenderer);

setActiveItem(activeLegendItem);
refreshRenderers(activeLegendItem);
renderersComboBox.setSelectedItem(currentRenderer);
currentRenderer = activeLegendItem.getData(LegendItem.RENDERER);
System.out.println("@Var: NEW currentRenderer: "+currentRenderer);
}
}//GEN-LAST:event_activeLegendsComboBoxActionPerformed

public void selectActiveItemInCombobox(Item activeLegendItem) {
// setActiveItem(activeLegendItem);
// refreshRenderers(activeLegendItem);
activeLegendsComboBox.setSelectedItem(activeLegendItem);

}

public void setActiveItem(Item activeLegendItem) {
Expand All @@ -327,9 +340,8 @@ public void setActiveItem(Item activeLegendItem) {
// return;
// }

Object currentRenderer = activeLegendItem.getData(LegendItem.RENDERER);

renderersComboBox.setSelectedItem(currentRenderer);
// Object currentRenderer = activeLegendItem.getData(LegendItem.RENDERER);
// renderersComboBox.setSelectedItem(currentRenderer);


Boolean hasDynamicProperties = activeLegendItem.getData(LegendItem.HAS_DYNAMIC_PROPERTIES);
Expand All @@ -345,10 +357,10 @@ public void setActiveItem(Item activeLegendItem) {
refreshPropertySheet();
}

private void refreshRenderers() {
private void refreshRenderers(Item activeLegendItem) {
renderersComboBox.removeAllItems();

Item activeLegendItem = (Item) activeLegendsComboBox.getSelectedItem();
// Item activeLegendItem = (Item) activeLegendsComboBox.getSelectedItem();
if (activeLegendItem != null) {

Collection<? extends LegendItemRenderer> renderers = Lookup.getDefault().lookupAll(LegendItemRenderer.class);
Expand All @@ -360,8 +372,6 @@ private void refreshRenderers() {
}
}

Object currentRenderer = activeLegendItem.getData(LegendItem.RENDERER);
renderersComboBox.setSelectedItem(currentRenderer);
}
}

Expand Down Expand Up @@ -399,6 +409,7 @@ private void legendItemBuildersComboBoxActionPerformed(java.awt.event.ActionEven
tooltipRenderer.setTooltips(tooltips);
}//GEN-LAST:event_legendItemBuildersComboBoxActionPerformed


private void renderersComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_renderersComboBoxActionPerformed
Item item = (Item) activeLegendsComboBox.getSelectedItem();
Object renderer = renderersComboBox.getSelectedItem();
Expand Down
57 changes: 42 additions & 15 deletions Legend API/src/org/gephi/legend/api/AbstractLegendItemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.awt.Font;
import java.io.File;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
Expand Down Expand Up @@ -344,12 +346,10 @@ protected void writeXMLFromSingleProperty(XMLStreamWriter writer, PreviewPropert
Object propertyValue = previewProperties.getValue(property.getName());

if (propertyValue != null) {
String text = PreviewProperties.getValueAsText(propertyValue);
if (text == null) {
text = writeValueAsText(propertyValue);
}
String text = writeValueAsText(propertyValue);
writer.writeStartElement(XML_PROPERTY);
String name = LegendModel.getPropertyFromPreviewProperty(property);
System.out.println("@Var: SAVING XML name: "+name+" , "+text);
writer.writeAttribute(XML_NAME, name);
writer.writeAttribute(XML_CLASS, propertyValue.getClass().getName());
writer.writeCharacters(text);
Expand Down Expand Up @@ -418,10 +418,13 @@ public PreviewProperty readXMLToSingleLegendProperty(XMLStreamReader reader, Ite
String valueString = reader.getElementText();
int propertyIndex = LegendProperty.getInstance().getProperty(propertyName);
Class valueClass = defaultValuesArrayList.get(propertyIndex).getClass();
Object value = PreviewProperties.readValueFromText(valueString, valueClass);
if (value == null) {
value = readValueFromText(valueString, valueClass);
}

// Object value = PreviewProperties.readValueFromText(valueString, valueClass);
// if (value == null) {
// value = readValueFromText(valueString, valueClass);
// }

Object value = readValueFromText(valueString, valueClass);

PreviewProperty property = createLegendProperty(item, propertyIndex, value);
return property;
Expand All @@ -435,7 +438,24 @@ public PreviewProperty readXMLToSingleLegendProperty(XMLStreamReader reader, Ite
* @return
*/
protected Object readValueFromText(String valueString, Class valueClass) {
Object value = null;
// System.out.println("@Var: valueClass: "+valueClass);
// System.out.println("@Var: valueString: "+valueString);

// bug
if(valueString.startsWith("org.netbeans.beaninfo.editors.ColorEditor")){
// bug
Pattern rgb = Pattern.compile(".*\\[r=(\\d+),g=(\\d+),b=(\\d+)\\]");
Matcher matcher = rgb.matcher(valueString);
if(matcher.matches()){
valueString = "["+matcher.group(1) +","+matcher.group(2)+","+matcher.group(3)+"]";
}
}

Object value = PreviewProperties.readValueFromText(valueString, valueClass);
if (value != null){
return value;
}

if (valueClass.equals(LegendItem.Alignment.class)) {
value = availableAlignments[Integer.parseInt(valueString)];
} else if (valueClass.equals(LegendItem.Shape.class)) {
Expand All @@ -448,8 +468,7 @@ protected Object readValueFromText(String valueString, Class valueClass) {
value = Integer.parseInt(valueString);
} else if (valueClass.equals(File.class)) {
value = new File(valueString);
}

}
return value;
}

Expand Down Expand Up @@ -489,6 +508,9 @@ public ArrayList<PreviewProperty> readXMLToLegendProperties(XMLStreamReader read
switch (type) {
case XMLStreamReader.START_ELEMENT: {
PreviewProperty property = readXMLToSingleLegendProperty(reader, item);
// System.out.println("@Var: .. success property: "+property.getName());
// System.out.println("@Var: property: "+property.getValue());

properties.add(property);
break;
}
Expand All @@ -508,7 +530,9 @@ public ArrayList<PreviewProperty> readXMLToLegendProperties(XMLStreamReader read
public void readXMLToRenderer(XMLStreamReader reader, Item item) throws XMLStreamException {
if (reader.getLocalName().equals(XML_RENDERER)) {
String valueString = reader.getElementText();
System.out.println("@Var: renderer.... "+valueString);
LegendItemRenderer availableRenderer = LegendController.getInstance().getRenderers().get(valueString);
System.out.println("@Var: renderer.... "+availableRenderer);
if (availableRenderer != null) {
item.setData(LegendItem.RENDERER, availableRenderer);
}
Expand Down Expand Up @@ -546,7 +570,6 @@ public Item readXMLToItem(XMLStreamReader reader, Integer newItemIndex) throws X
// closing dynamic properties

// data
// reader.nextTag();
reader.nextTag();
readXMLToData(reader, item);

Expand All @@ -561,8 +584,8 @@ public Item readXMLToItem(XMLStreamReader reader, Integer newItemIndex) throws X

// setting data
item.setData(LegendItem.ITEM_INDEX, newItemIndex);
item.setData(LegendItem.PROPERTIES, legendPropertiesArray);
item.setData(LegendItem.OWN_PROPERTIES, ownPropertiesArray);
item.setData(LegendItem.PROPERTIES, legendPropertiesArray);

item.setData(LegendItem.HAS_DYNAMIC_PROPERTIES, hasDynamicProperties());
item.setData(LegendItem.DYNAMIC_PROPERTIES, dynamicPropertiesArray);
Expand All @@ -580,7 +603,11 @@ public Item readXMLToItem(XMLStreamReader reader, Integer newItemIndex) throws X
* @return
*/
protected String writeValueAsText(Object propertyValue) {
String text;

String text = PreviewProperties.getValueAsText(propertyValue);
if (text != null) {
return text;
}
if (propertyValue instanceof LegendItem.Alignment) {
LegendItem.Alignment propertyValueString = (LegendItem.Alignment) propertyValue;
text = propertyValueString.getValue();
Expand Down Expand Up @@ -641,7 +668,7 @@ public AbstractLegendItemBuilder() {
updateDefaultValues();
}

public void updateDefaultValues() {
public final void updateDefaultValues() {
this.defaultValuesArrayList = new ArrayList<Object>();
defaultValuesArrayList.add(this.defaultLabel);
defaultValuesArrayList.add(this.defaultIsDisplaying);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public abstract class AbstractLegendItemRenderer implements LegendItemRenderer,
* @param properties PreviewProperties of the current PreviewModel
*/
protected abstract void readOwnPropertiesAndValues(Item item, PreviewProperties properties);

public abstract boolean isAnAvailableRenderer(Item item);

private void readLocationProperties(Item item, PreviewProperties previewProperties) {
if (item != null) {
currentItemIndex = item.getData(LegendItem.ITEM_INDEX);
Expand Down Expand Up @@ -171,7 +171,7 @@ private void renderProcessing(ProcessingTarget target) {
// } else {
// render(graphics2D, originTranslation, currentWidth, currentHeight);
// }

render(graphics2D, originTranslation, currentWidth, currentHeight);
graphics2D.setTransform(saveState);
}
Expand Down Expand Up @@ -352,7 +352,7 @@ public PreviewProperty[] getProperties() {
return new PreviewProperty[0];
}

private float legendDrawText(Graphics2D graphics2D, String text, Font font, Color color, double x, double y, Integer width, Integer height, Alignment alignment, boolean isComputingSpace) {
protected float legendDrawText(Graphics2D graphics2D, String text, Font font, Color color, double x, double y, Integer width, Integer height, Alignment alignment, boolean isComputingSpace) {

if (text.isEmpty()) {
return 0f;
Expand All @@ -376,8 +376,15 @@ private float legendDrawText(Graphics2D graphics2D, String text, Font font, Colo
float descent = 0, leading = 0;
while (measurer.getPosition() < end) {
TextLayout layout = measurer.nextLayout(width);

yText += layout.getAscent();


if (!isComputingSpace) {




switch (alignment) {
case LEFT: {
break;
Expand All @@ -400,6 +407,13 @@ private float legendDrawText(Graphics2D graphics2D, String text, Font font, Colo
}

}
// System.out.println("@Var: y: "+y);
// System.out.println("@Var: yText: " + (yText - y - layout.getAscent()));
// System.out.println("@Var: height: " + height);
if (yText - y -layout.getAscent() > height) {
break;
}
// break;
layout.draw(graphics2D, xText, yText);
}
descent = layout.getDescent();
Expand Down Expand Up @@ -427,7 +441,9 @@ private float legendDrawText(Graphics2D graphics2D, String text, Font font, Colo
* @return
*/
protected float legendDrawText(Graphics2D graphics2D, String text, Font font, Color color, double x, double y, Integer width, Integer height, Alignment alignment) {
// System.out.println("@Var: drawElementLabel: " + text);
float spaceUsed = legendDrawText(graphics2D, text, font, color, x, y, width, height, alignment, true);
// System.out.println("@Var: spaceUsed: " + spaceUsed);
y = y + (height - spaceUsed) / 2;
return legendDrawText(graphics2D, text, font, color, x, y, width, height, alignment, false);
}
Expand All @@ -445,7 +461,7 @@ protected float legendDrawText(Graphics2D graphics2D, String text, Font font, Co
protected float computeVerticalTextSpaceUsed(Graphics2D graphics2D, String text, Font font, Integer width) {
return legendDrawText(graphics2D, text, font, Color.BLACK, 0, 0, width, currentHeight, Alignment.LEFT, true);
}

@Override
public boolean isRendererForitem(Item item, PreviewProperties properties) {
LegendItemRenderer renderer = item.getData(LegendItem.RENDERER);
Expand Down
1 change: 1 addition & 0 deletions Legend API/src/org/gephi/legend/api/LegendController.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private void registerLegendRenderers() {

// registering renderers
for (LegendItemRenderer legendItemRenderer : legendItemRenderers) {
System.out.println("@Var: registering ... legendItemRenderer: "+legendItemRenderer);
renderers.put(legendItemRenderer.getClass().getName(), legendItemRenderer);
}
}
Expand Down
16 changes: 8 additions & 8 deletions LegendPlugin/build.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="org.gephi.legend.plugin" default="netbeans" basedir=".">
<description>Builds, tests, and runs the project org.gephi.legend.plugin.</description>
<import file="nbproject/build-impl.xml"/>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="org.gephi.legend.plugin" default="netbeans" basedir=".">
<description>Builds, tests, and runs the project org.gephi.legend.plugin.</description>
<import file="nbproject/build-impl.xml"/>
</project>
Loading

0 comments on commit 63f1835

Please sign in to comment.