Sample Layer Property Panel Implementation for an existing layer
TRIANGLEMESHLAYERDISPLAYEDITOR.JAVA
package com.interactive.intviewer.tmesh.editor;
import com.interactive.intviewer.view2d.util.HelpCtxUtils;
import com.interactive.intviewerapi.IVisual;
import com.interactive.intviewerapi.editors.IObjectEditorNode;
import com.interactive.intviewerapi.editors.VisualPropertyEditor;
import com.interactive.intviewerapi.layers.ILayer2D;
import com.interactive.intviewerapi.layers.NamedProps;
import javax.swing.JPanel;
import org.netbeans.validation.api.ui.ValidationPanel;
import org.openide.util.HelpCtx;
public class TriangleMeshLayerDisplayEditor extends VisualPropertyEditor {
private static final long serialVersionUID = 2463020299625836800L;
private TriangleMeshLayerDisplayPanel panel;
private ValidationPanel validationPanel;
public TriangleMeshLayerDisplayEditor() {
}
@Override
public VisualPropertyEditor getInstance(IVisual visual) {
return new TriangleMeshLayerDisplayEditor((ILayer2D) visual);
}
public TriangleMeshLayerDisplayEditor(ILayer2D layer) {
super(layer);
}
@Override
public boolean isFolder() {
return false;
}
@Override
public IObjectEditorNode[] getChildren() {
return null;
}
@Override
public JPanel getPanel() {
if (this.panel == null) {
this.validationPanel = new ValidationPanel();
this.panel = new TriangleMeshLayerDisplayPanel((ILayer2D) this.getVisual());
this.panel.setUp(this.getVisual().getProperties());
this.panel.setUpValidationGroup(this.validationPanel.getValidationGroup());
this.validationPanel.setInnerComponent(this.panel);
}
return this.validationPanel;
}
@Override
public HelpCtx getHelpCtx() {
return new HelpCtx(HelpCtxUtils.PROPERTY_DISPLAY_PARAMETERS);
}
@Override
public String getDisplayName() {
return "Display Parameters";
}
@Override
public void apply() {
NamedProps props = new NamedProps();
panel.getProps(props);
this.getVisual().setProperties(props, this);
}
}
TRIANGLEMESHLAYERDISPLAYPANEL.JAVA
package com.interactive.intviewer.tmesh.editor;
import com.interactive.intviewer.util.AttributesUtil;
import com.interactive.intviewer.util.gui.LineProperties;
import com.interactive.intviewerapi.layers.ILayer2D;
import com.interactive.intviewerapi.layers.NamedProps;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import org.netbeans.validation.api.builtin.Validators;
import org.netbeans.validation.api.ui.ValidationGroup;
public class TriangleMeshLayerDisplayPanel extends JPanel {
private static final long serialVersionUID = 2463020299625836800L;
private JTextField _nameField;
private LineAttributePanel _lineEditor;
public TriangleMeshLayerDisplayPanel(ILayer2D layer) {
super();
buildGUI();
}
private void buildGUI() {
_nameField = new JTextField("");
_lineEditor = new LineAttributePanel(false);
JPanel layerPanel = new JPanel(new GridLayout(1, 2));
layerPanel.setBorder(new TitledBorder("Layer"));
layerPanel.add(new JLabel(" Layer Name"));
layerPanel.add(_nameField);
Box box = new Box(BoxLayout.Y_AXIS);
box.add(Box.createVerticalStrut(10));
box.add(layerPanel);
box.add(Box.createVerticalStrut(10));
box.add(_lineEditor);
box.add(Box.createVerticalStrut(10));
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(10, 25, 10, 25));
add(box, BorderLayout.CENTER);
}
public void setUp(NamedProps lp) {
_nameField.setText(lp.getProperty(ILayer2D.DISPLAY_NAME));
_lineEditor.setLineStyle(AttributesUtil.getLineStyleFromName(lp.getProperty(LineProperties.LINE_STYLE)));
_lineEditor.setLineColor(lp.getProperty(LineProperties.LINE_COLOR));
_lineEditor.setLineWidth(lp.getProperty(LineProperties.LINE_WIDTH));
}
public void getProps(NamedProps lp) {
lp.putProperty(ILayer2D.DISPLAY_NAME, _nameField.getText());
lp.putProperty(LineProperties.LINE_STYLE, AttributesUtil.getLineStyleName(_lineEditor.getLineStyle()));
lp.putProperty(LineProperties.LINE_COLOR, _lineEditor.getLineColor());
lp.putProperty(LineProperties.LINE_WIDTH, _lineEditor.getLineWidth());
}
@SuppressWarnings("unchecked")
public void setUpValidationGroup(ValidationGroup validationGroup) {
_nameField.setName("Layer Name");
validationGroup.add(_nameField, Validators.REQUIRE_NON_EMPTY_STRING);
}
}
LAYER.XML
<folder name="VisualPropertyEditors">
<folder name="XSectionTriangleMeshLayer">
<file name="com-interactive-intviewer-tmesh-editor-TriangleMeshLayerDisplayEditor.instance">
<attr name="position" intvalue="100"/>
</file>
</folder>
</folder>
For XSection seismic layers, use "ViewerSeismicLayer" as folder name.