Commit 571c3264 authored by Krzysztof Nowinski's avatar Krzysztof Nowinski

text glyph UI, formatting, complex and vector components done

parent 9bba7554
......@@ -43,6 +43,9 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import pl.edu.icm.jscic.Field;
import pl.edu.icm.jscic.RegularField;
import pl.edu.icm.jscic.dataarrays.DataArray;
import pl.edu.icm.jscic.dataarrays.DataArrayType;
import static pl.edu.icm.jscic.dataarrays.DataArrayType.*;
import pl.edu.icm.visnow.geometries.parameters.DataMappingParams;
/**
......@@ -65,6 +68,8 @@ public class GUI extends javax.swing.JPanel
};
private float smax = 1;
private int[] downsize;
private String floatFormat = "%4.1f", intFormat = "%3d";
private String format = floatFormat;
/**
* Creates new form VNgraph3DUI
......@@ -238,7 +243,6 @@ public class GUI extends javax.swing.JPanel
downLabels.get(i).setFont(new java.awt.Font("Dialog", 0, 8));
}
downsizeSlider.setLabelTable(downLabels);
mapComboBox.setScalarComponentsOnly(true);
mapComboBox.setTitle("glyph size component");
thrComponentSelector.setAddNullComponent(true);
thrComponentSelector.setScalarComponentsOnly(true);
......@@ -262,16 +266,31 @@ public class GUI extends javax.swing.JPanel
params.setDownsize(down[downsizeSlider.getValue()]);
}//GEN-LAST:event_downsizeSliderStateChanged
private void updateUI(DataArray da)
{
thrSlider.setMin((float)da.getPreferredMinValue());
thrSlider.setMax((float)da.getPreferredMaxValue());
DataArrayType daType = da.getType();
if ((daType == FIELD_DATA_BYTE || daType == DataArrayType.FIELD_DATA_SHORT ||
daType == FIELD_DATA_INT || daType == DataArrayType.FIELD_DATA_LONG) &&
!format.endsWith("d"))
format = intFormat;
if ((daType == FIELD_DATA_FLOAT || daType == DataArrayType.FIELD_DATA_DOUBLE ||
daType == FIELD_DATA_COMPLEX) &&
!(format.endsWith("e") || format.endsWith("f")))
format = floatFormat;
formatField.setText(format);
params.setFormat(format);
}
private void mapComboBoxStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_mapComboBoxStateChanged
{//GEN-HEADEREND:event_mapComboBoxStateChanged
params.setActive(false);
int m = mapComboBox.getComponent();
params.setComponent(m);
if (m >= 0) {
thrSlider.setMin((float)inField.getComponent(m).getPreferredMinValue());
thrSlider.setMax((float)inField.getComponent(m).getPreferredMaxValue());
//setScaleMinMax();
}
String s = mapComboBox.getComponentName();
params.setComponent(s);
DataArray da = inField.getComponent(s);
if (da != null)
updateUI(da);
params.setActive(true);
}//GEN-LAST:event_mapComboBoxStateChanged
......@@ -282,12 +301,15 @@ public class GUI extends javax.swing.JPanel
private void thrComponentSelectorStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_thrComponentSelectorStateChanged
{//GEN-HEADEREND:event_thrComponentSelectorStateChanged
params.setThrComponent(thrComponentSelector.getComponent());
params.setThrComponent(thrComponentSelector.getComponentName());
}//GEN-LAST:event_thrComponentSelectorStateChanged
private void formatFieldActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_formatFieldActionPerformed
{//GEN-HEADEREND:event_formatFieldActionPerformed
params.setFormat(formatField.getText());
String fmt = formatField.getText();
if (fmt.matches("%1?\\dd") || fmt.matches("%1?\\d\\.\\d[ef]"))
format = fmt;
params.setFormat(format);
}//GEN-LAST:event_formatFieldActionPerformed
private void cropUIStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_cropUIStateChanged
......@@ -301,6 +323,7 @@ public class GUI extends javax.swing.JPanel
{
if (newInField == null)
return;
params.setActive(false);
if (!newInField.isStructureCompatibleWith(inField)) {
CardLayout cl = (CardLayout) (jPanel5.getLayout());
if (newInField instanceof RegularField) {
......@@ -349,7 +372,12 @@ public class GUI extends javax.swing.JPanel
mapComboBox.setDataSchema(inField.getSchema());
thrComponentSelector.setDataSchema(inField.getSchema());
thrComponentSelector.setComponent(-1);
params.setComponent(mapComboBox.getComponent());
String s = mapComboBox.getComponentName();
params.setComponent(s);
DataArray da = inField.getComponent(s);
if (da != null)
updateUI(da);
params.setActive(true);
}
public void setParams(Params params)
......
......@@ -38,14 +38,13 @@
//</editor-fold>
package pl.edu.icm.visnow.lib.basic.mappers.TextGlyphs;
import java.awt.Color;
import java.util.IllegalFormatException;
import javax.media.j3d.*;
import org.apache.log4j.Logger;
import pl.edu.icm.jscic.dataarrays.DataArray;
import pl.edu.icm.jscic.Field;
import pl.edu.icm.jscic.RegularField;
import pl.edu.icm.jscic.dataarrays.DataArrayType;
import static pl.edu.icm.jscic.dataarrays.DataArrayType.*;
import pl.edu.icm.jscic.dataarrays.StringDataArray;
import pl.edu.icm.jlargearrays.FloatLargeArray;
import pl.edu.icm.visnow.geometries.objects.DataMappedGeometryObject;
......@@ -61,6 +60,7 @@ import pl.edu.icm.visnow.system.main.VisNow;
import pl.edu.icm.visnow.system.utils.usermessage.Level;
import pl.edu.icm.visnow.system.utils.usermessage.UserMessage;
import static org.apache.commons.math3.util.FastMath.*;
import pl.edu.icm.jscic.dataarrays.ComplexDataArray;
import pl.edu.icm.jscic.dataarrays.ObjectDataArray;
/**
......@@ -76,7 +76,7 @@ public class GlyphsObject extends DataMappedGeometryObject
private FontParams fontParams;
private Field inField = null;
private OpenBranchGroup outGroup = null;
private DataArray glyphDaraArray, thresholdDataArray;
private DataArray glyphDataArray, thresholdDataArray;
private float thr = -Float.MAX_VALUE;
private float[] baseCoords = null;
private long[] glyphIn = null;
......@@ -163,12 +163,12 @@ public class GlyphsObject extends DataMappedGeometryObject
private void prepareGlyphCount()
{
nGlyphs = 0;
glyphDaraArray = inField.getComponent(params.getComponent());
if (glyphDaraArray == null || (glyphDaraArray.getVectorLength() != 3 && glyphDaraArray.getVectorLength() != 1))
glyphDataArray = inField.getComponent(params.getComponent());
if (glyphDataArray == null || (glyphDataArray.getVectorLength() != 3 && glyphDataArray.getVectorLength() != 1))
return;
thr = params.getThr();
thresholdDataArray = null;
if (params.getThrComponent() >= 0)
if (inField.getComponent(params.getThrComponent()) != null)
thresholdDataArray = inField.getComponent(params.getThrComponent());
int maxNGlyphs = 1;
if (inField instanceof RegularField) {
......@@ -251,38 +251,108 @@ public class GlyphsObject extends DataMappedGeometryObject
getCurrentViewer().getWidth(),
getCurrentViewer().getHeight());
fontSize = fontParams.getFontSize();
glyphDaraArray = inField.getComponent(params.getComponent());
if (glyphDaraArray == null || glyphDaraArray.getVectorLength() != 1 || nGlyphs < 1)
glyphDataArray = inField.getComponent(params.getComponent());
if (glyphDataArray == null || nGlyphs < 1)
return;
String format = params.getFormat();
Color textColor2d = fontParams.getColor();
if (outGroup != null)
outGroup.detach();
outGroup = null;
String[] texts = new String[nGlyphs];
if (glyphDaraArray.getType() == DataArrayType.FIELD_DATA_STRING) {
String[] sData = ((StringDataArray) glyphDaraArray).getRawArray().getData();
if (sData == null)
return;
for (int i = 0; i < texts.length; i++)
texts[i] = sData[(int) glyphIn[i]];
} else if (glyphDaraArray.getType() == DataArrayType.FIELD_DATA_OBJECT) {
Object[] sData = ((ObjectDataArray) glyphDaraArray).getRawArray().getData();
if (sData == null)
return;
for (int i = 0; i < texts.length; i++)
texts[i] = sData[(int) glyphIn[i]].toString();
} else {
switch (glyphDataArray.getType()) {
case FIELD_DATA_STRING:
{
String[] sData = ((StringDataArray) glyphDataArray).getRawArray().getData();
if (sData == null)
return;
for (int i = 0; i < texts.length; i++)
texts[i] = sData[(int) glyphIn[i]];
break;
}
case FIELD_DATA_OBJECT:
{
Object[] sData = ((ObjectDataArray) glyphDataArray).getRawArray().getData();
if (sData == null)
return;
for (int i = 0; i < texts.length; i++)
texts[i] = sData[(int) glyphIn[i]].toString();
break;
}
default:
texts = new String[nGlyphs];
format = format.trim();
float[] fData;
float[][] cData;
ComplexDataArray cDataArray = null;
if (glyphDataArray.getType() == FIELD_DATA_COMPLEX)
cDataArray = (ComplexDataArray)glyphDataArray;
try {
for (int i = 0; i < texts.length; i++)
texts[i] = String.format(format, glyphDaraArray.getFloatElement(glyphIn[i])[0]);
for (int i = 0; i < texts.length; i++) {
if (glyphDataArray.getType() == FIELD_DATA_COMPLEX) {
cData = cDataArray.getComplexFloatElement(i);
if (format.endsWith("d")) {
StringBuilder b = new StringBuilder();
if (cData.length > 1)
b.append("[");
for (int j = 0; j < cData.length; j++) {
if (j > 0)
b.append(",");
b.append(String.format(format + "+" + format + "i", (int)cData[j][0], (int)cData[j][1]));
}
if (cData.length > 1)
b.append("]");
texts[i] = b.toString();
}
else{
StringBuilder b = new StringBuilder();
if (cData.length > 1)
b.append("[");
for (int j = 0; j < cData.length; j++) {
if (j > 0)
b.append(",");
b.append(String.format(format + "+" + format + "i", cData[j][0], cData[j][1]));
}
if (cData.length > 1)
b.append("]");
texts[i] = b.toString();
}
}
else {
fData = glyphDataArray.getFloatElement(glyphIn[i]);
if (format.endsWith("d")) {
StringBuilder b = new StringBuilder();
if (fData.length > 1)
b.append("[");
for (int j = 0; j < fData.length; j++) {
if (j > 0)
b.append(",");
b.append(String.format(format, (int)fData[j]));
}
if (fData.length > 1)
b.append("]");
texts[i] = b.toString();
}
else{
StringBuilder b = new StringBuilder();
if (fData.length > 1)
b.append("[");
for (int j = 0; j < fData.length; j++) {
if (j > 0)
b.append(",");
b.append(String.format(format, fData[j]));
}
if (fData.length > 1)
b.append("]");
texts[i] = b.toString();
}
}
}
} catch (IllegalFormatException ex) { //if incorrect format then drop to default format
//TODO: how to resolve problem with no access to current application? Maybe some VisNow.getCurrentApplication()
VisNow.get().userMessageSend(new UserMessage("", "text glyphs", "Incorrect text format", "Specified format is incorrect: " + format + "<br>" + "Dropped to default one: " + defaultTextFormat, Level.WARNING));
for (int i = 0; i < texts.length; i++)
texts[i] = String.format(defaultTextFormat, glyphDaraArray.getFloatElement(glyphIn[i])[0]);
}
texts[i] = String.format(defaultTextFormat, glyphDataArray.getFloatElement(glyphIn[i])[0]);
} break;
}
if (fontParams.isThreeDimensional()) {
glyphs = null;
......
......@@ -57,8 +57,8 @@ public class Params extends Parameters
protected int change = 0;
protected FontParams fontParams = new FontParams();
protected static ParameterEgg[] eggs = new ParameterEgg[]{
new ParameterEgg<Integer>("component", ParameterType.dependent, 0),
new ParameterEgg<Integer>("thrComponent", ParameterType.dependent, -1),
new ParameterEgg<String>("component", ParameterType.dependent, ""),
new ParameterEgg<String>("thrComponent", ParameterType.dependent, ""),
new ParameterEgg<Float>("thr", ParameterType.dependent, .1f),
new ParameterEgg<Float>("scale", ParameterType.dependent, .02f),
new ParameterEgg<String>("format", ParameterType.dependent, "%4.1f"),
......@@ -86,24 +86,24 @@ public class Params extends Parameters
});
}
public int getComponent()
public String getComponent()
{
return (Integer) getValue("component");
return (String) getValue("component");
}
public void setComponent(int component)
public void setComponent(String component)
{
setValue("component", component);
change = max(change, GLYPHS_CHANGED);
fireStateChanged();
}
public int getThrComponent()
public String getThrComponent()
{
return (Integer) getValue("thrComponent");
return (String) getValue("thrComponent");
}
public void setThrComponent(int component)
public void setThrComponent(String component)
{
setValue("thrComponent", component);
change = COUNT_CHANGED;
......
......@@ -118,7 +118,7 @@ public class TextGlyphs extends VisualizationModule //implements RenderWindowLis
params.setActive(true);
fromIn = false;
}
if (params.getComponent() < 0)
if (inField == null || params.getComponent() == null || inField.getComponent(params.getComponent()) == null)
return;
glyphObj.update(inField, params);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment