In this implementation, we provide an attributes shortcut panel for a triangle mesh layer. This panel only contains a button for the selection of a line color.
The following panel class was created using the Netbeans Matisse editor, then customized to extend com.interactive.intviewerapi.editors.AbstractVisualAttributesShortcutPanel.
TRIANGLEMESHLAYERATTRIBUTESSHORTCUTPANEL.JAVA
package com.interactive.intviewer.tmesh.editor.shortcut;import com.interactive.intviewerapi.events.PropertyProviderEvent;import com.interactive.intviewerapi.editors.AbstractVisualAttributesShortcutPanel;import com.interactive.intviewer.util.gui.LineColorButton;import com.interactive.intviewerapi.layers.ITriangleMeshLayer;import com.interactive.intviewerapi.layers.NamedProps;import java.awt.Color;public class TriangleMeshLayerAttributesShortcutPanel extends AbstractVisualAttributesShortcutPanel { public TriangleMeshLayerAttributesShortcutPanel(ITriangleMeshLayer tmeshLayer) { super(tmeshLayer); initComponents(); initGUI(); this.setReady(true); } /** * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel1 = new javax.swing.JLabel(); colorBtn = new LineColorButton("", Color.black); jLabel1.setText(org.openide.util.NbBundle.getMessage(TriangleMeshLayerAttributesShortcutPanel.class, "TriangleMeshLayerAttributesShortcutPanel.jLabel1.text")); // NOI18N colorBtn.setText(org.openide.util.NbBundle.getMessage(TriangleMeshLayerAttributesShortcutPanel.class, "TriangleMeshLayerAttributesShortcutPanel.colorBtn.text")); // NOI18N colorBtn.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { colorBtnPropertyChange(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addGap(27, 27, 27) .addComponent(colorBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(12, 12, 12) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(colorBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addContainerGap(24, Short.MAX_VALUE)) ); }// </editor-fold> private void colorBtnPropertyChange(java.beans.PropertyChangeEvent evt) { // TODO add your handling code here: if (!isReady()) { return; } if (this.getVisual() == null) { return; } if (evt.getSource() == colorBtn && evt.getPropertyName().equals(LineColorButton.COLOR_PROPERTY)) { Color c = ((LineColorButton) colorBtn).getSelectedColor(); NamedProps prop = new NamedProps(); prop.putProperty(ITriangleMeshLayer.LINE_COLOR, c); getVisual().setProperties(prop, this); } } // Variables declaration - do not modify private javax.swing.JButton colorBtn; private javax.swing.JLabel jLabel1; // End of variables declaration private void initGUI() { Color c = getVisual().getProperties().getProperty(ITriangleMeshLayer.LINE_COLOR); ((LineColorButton) colorBtn).setSelectedColor(c); } @Override protected void processEvent(PropertyProviderEvent e) { this.setReady(false); initGUI(); this.setReady(true); }}The following editor class does a lazy-instantiation of the panel created earlier.
TRIANGLEMESHLAYERATTRIBUTESSHORTCUTEDITOR.JAVA
package com.interactive.intviewer.tmesh.editor.shortcut;import com.interactive.intviewerapi.editors.AbstractVisualAttributesShortcutEditor;import com.interactive.intviewerapi.layers.ILayer2D;import com.interactive.intviewerapi.layers.IVisual;import com.interactive.intviewerapi.layers.ITriangleMeshLayer;import javax.swing.JComponent;public class TriangleMeshLayerAttributesShortcutEditor extends AbstractVisualAttributesShortcutEditor { private TriangleMeshLayerAttributesShortcutPanel panel; public TriangleMeshLayerAttributesShortcutEditor(ILayer2D layer) { super(layer); } @Override public JComponent getComponent() { if (panel == null) { panel = new TriangleMeshLayerAttributesShortcutPanel((ITriangleMeshLayer) this.getVisual()); } return panel; } @Override public void dispose() { super.dispose(); if (panel != null) { panel.dispose(); panel = null; } }}The following adapter class verifies that the object is a xsection triangle mesh layer, and vends the editor created earlier.
XSECTIONTRIANGLEMESHLAYERSHORTCUTADAPTER.JAVA
package com.interactive.intviewer.tmesh.editor.shortcut;import com.interactive.intviewer.tmesh.layer2d.XSectionTriangleMeshLayer;import com.interactive.intviewerapi.editors.IAttributesShortcutAdapter;import com.interactive.intviewerapi.editors.IAttributesShortcutProvider;import com.interactive.intviewerapi.editors.IAttributesShortcutProvider.IAttributesShortcutEditor;public class XSectionTriangleMeshLayerShortcutAdapter implements IAttributesShortcutAdapter { @Override public Class<?> getSupportedClass() { return XSectionTriangleMeshLayer.class; } @Override public boolean canProcess(Object o) { return (o instanceof XSectionTriangleMeshLayer); } @Override public IAttributesShortcutProvider getProvider(Object o) { if (o instanceof XSectionTriangleMeshLayer) { return new TriangleMeshShortcutProvider((XSectionTriangleMeshLayer) o); } else { return null; } } class TriangleMeshShortcutProvider implements IAttributesShortcutProvider { private XSectionTriangleMeshLayer layer; public TriangleMeshShortcutProvider(XSectionTriangleMeshLayer tmeshLayer) { layer = tmeshLayer; } @Override public IAttributesShortcutEditor[] getEditors() { return new IAttributesShortcutEditor[]{new TriangleMeshLayerAttributesShortcutEditor(layer)}; } }}Important: In the getSupportedClass method, indicate the implementation class, not the interface. To get the implementation class of a layer, use layer.getClass().
The following layer registration adds the adapter created earlier to the INTViewer desktop.
LAYER.XML
<folder name="ShortcutEditors"> <folder name="AttributesShortcut"> <file name="com-interactive-intviewer-tmesh-editor-shortcut-XSectionTriangleMeshLayerShortcutAdapter.instance"/> </folder> </folder>