Commit 567ff4e8 authored by Alina Hinzmann's avatar Alina Hinzmann

fixed update problem (with boolean listenersDisabled to wait before

updateVisualization())
set inital options for every visualization in createVisualization
parent bb50f2d0
......@@ -2,7 +2,6 @@ package de.jtem.halfedgetools.plugin.data.visualizer;
import static de.jreality.shader.CommonAttributes.DIFFUSE_COLOR;
import static de.jreality.shader.CommonAttributes.LINE_SHADER;
import static java.awt.GridBagConstraints.BOTH;
import java.awt.Color;
import java.awt.GridBagConstraints;
......@@ -10,8 +9,6 @@ import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
......@@ -52,7 +49,6 @@ import de.jtem.halfedgetools.plugin.data.AbstractDataVisualization;
import de.jtem.halfedgetools.plugin.data.DataVisualization;
import de.jtem.halfedgetools.plugin.data.DataVisualizer;
import de.jtem.halfedgetools.plugin.data.DataVisualizerPlugin;
import de.jtem.halfedgetools.plugin.data.visualizer.VectorFieldVisualizer.VectorFieldVisualization;
import de.jtem.halfedgetools.plugin.image.ImageHook;
import de.jtem.jrworkspace.plugin.Controller;
import de.jtem.jrworkspace.plugin.PluginInfo;
......@@ -81,7 +77,7 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
prefixTextField = new JTextField();
private JCheckBox
flipLabelChecker = new JCheckBox("Flip direction"); //TODO include the possibility to flip the labels (if normals are in the "wrong" direction for it)
flipLabelChecker = new JCheckBox("Flip direction"); //gives the possibility to flip the labels (if normals are in the "wrong" direction for it)
//do this by rotating the label-lineset 180degree around its bb-center-axis (z axis resp. earlier y-axis)
private ColorChooseJButton
labelColorButton = new ColorChooseJButton(true); //cool color button, true = showing colors to choose in new window
......@@ -91,6 +87,8 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
private LabelVisualization
activeVisualization = null; // a field holding the current Visualization, needed for interplay with the UI
private boolean listenersDisabled;
public LabelVisualizer() {
optionsPanel.setLayout(new GridBagLayout());
......@@ -141,23 +139,16 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
public DataVisualization createVisualization(HalfedgeLayer layer, NodeType type, Adapter<?> source) {
LabelVisualization vis = new LabelVisualization(layer,source, this, type);
// copy last values
vis.decimals = decimalsModel.getNumber().intValue();
vis.prefix = prefixTextField.getText();
vis.fontSize = fontSizeModel.getNumber().doubleValue();
// vis.decimals = decimalsModel.getNumber().intValue();
// vis.prefix = prefixTextField.getText();
vis.setFontSize(fontSizeModel.getNumber().doubleValue());
vis.labelFlip = flipLabelChecker.isSelected();
vis.color = getLabelColor();
// vis.setColor(getLabelColor());
// vis.update();
// layer.addTemporaryGeometry(vis.visualizationRoot);
// visualizationList.add(vis);
return vis;
}
// @Override
// public void disposeVisualization(DataVisualization vis) {
// LabelVisualization labelVis = (LabelVisualization) vis;
// vis.getLayer().removeTemporaryGeometry(labelVis.visualizationRoot);
// visualizationList.remove(vis);
// }
@Override
public void actionPerformed(ActionEvent e) {
......@@ -184,10 +175,16 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
}
private void updateLabelColor() {
if(listenersDisabled) {
return;
}
activeVisualization.setColor(getLabelColor());
}
private void updateVisualization() {
if(listenersDisabled) {
return;
}
activeVisualization.setDecimals(decimalsModel.getNumber().intValue());
activeVisualization.setPrefix(prefixTextField.getText());
activeVisualization.setLabelFlipped(flipLabelChecker.isSelected());
......@@ -198,13 +195,14 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
@Override
public JPanel connectUserInterfaceFor(DataVisualization visualization) {
listenersDisabled = true;
activeVisualization = (LabelVisualization) visualization;
decimalsModel.setValue(activeVisualization.getDecimals());
prefixTextField.setText(activeVisualization.getPrefix());
flipLabelChecker.setSelected(activeVisualization.isLabelFlipped());
fontSizeModel.setValue(activeVisualization.getFontSize());
labelColorButton.setColor(activeVisualization.getColor());
listenersDisabled = false;
return optionsPanel;
}
......@@ -229,7 +227,7 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
decimals = 3;
public String
prefix = null;
prefix = new String();
private boolean labelFlip;
......@@ -297,7 +295,7 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
.rotateFromTo(upDirection, normal) //new double[]{0, 0,1}, normal) //rotate the updirection to the vertexnormal
.getMatrix();
if(labelFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().rotateY(Math.PI).getMatrix());
M.multiplyOnRight(MatrixBuilder.euclidean().rotateY(Math.PI).getMatrix()); //if the label shall be flipped: rotate it 180degree around central axis of its boundingbox (since translated in the origin this is the y-axis)
}
M.multiplyOnRight(MatrixBuilder.euclidean().translate(Rn.negate(null, labelCenter)).getMatrix()); //translate the labels center to the origin
......@@ -315,8 +313,9 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
String label = generateDataString(data);
SceneGraphComponent sgc = new SceneGraphComponent("E" + String.format("%0"+numDigits+"d",e.getIndex()));
sgc.setGeometry(ttfLineSetFactory.getIndexLineSet(prefix + label));
Rectangle3D labelBoundingBox = BoundingBoxUtility.calculateBoundingBox(ttfLineSetFactory.getIndexLineSet(label));
IndexedLineSet labelLineSet = ttfLineSetFactory.getIndexLineSet(prefix + label);
sgc.setGeometry(labelLineSet);
Rectangle3D labelBoundingBox = BoundingBoxUtility.calculateBoundingBox(labelLineSet);
double[] bbCenter = labelBoundingBox.getCenter();
......@@ -361,7 +360,7 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
double[][] localCoordinateSystem = getFacesCoordinateSystem(f,a);
Matrix M = getTransformationMatrix(localCoordinateSystem, center);
if(labelFlip){
M.multiplyOnRight(MatrixBuilder.euclidean().rotateY(Math.PI).getMatrix());
M.multiplyOnRight(MatrixBuilder.euclidean().rotateY(Math.PI).getMatrix()); //if the label shall be flipped: rotate it 180degree around central axis of its boundingbox (since translated in the origin this is the y-axis)
}
M.multiplyOnRight(MatrixBuilder.euclidean().translate(Rn.negate(null, bbCenter)).getMatrix());
M.assignTo(sgc);
......@@ -385,21 +384,6 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
visualizationRoot.setAppearance(labelAppearance);
}
@Override
public void dispose() {
getLayer().removeTemporaryGeometry(visualizationRoot);
}
@Override
public void setActive(boolean active) {
visualizationRoot.setVisible(active);
}
@Override
public boolean isActive() {
return visualizationRoot.isVisible();
}
/**
* Generates a String from given Data with chosen options. If the data is a Double it is rounded to have the chosen decimals.
* @param data the data which shall be represented in a label
......@@ -487,6 +471,21 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
return matrix;
}
@Override
public void dispose() {
getLayer().removeTemporaryGeometry(visualizationRoot);
}
@Override
public void setActive(boolean active) {
visualizationRoot.setVisible(active);
}
@Override
public boolean isActive() {
return visualizationRoot.isVisible();
}
public int getDecimals() {
return decimals;
}
......
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