Commit 519cbf53 authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

* cardlayout used for switching editors

 * better size settings attempt
parent c63ec38c
......@@ -16,27 +16,42 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" alignment="0" pref="495" max="32767" attributes="0"/>
<Component id="jSplitPane1" alignment="0" pref="421" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="jSplitPane1" min="-2" pref="390" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Component id="jSplitPane1" alignment="0" pref="454" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
<Properties>
<Property name="dividerSize" type="int" value="5"/>
<Property name="dividerSize" type="int" value="6"/>
<Property name="resizeWeight" type="double" value="0.1"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="null"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="new Dimension(jTablePreferredSize.width+editorPreferredSize.width, Math.max(jTablePreferredSize.height,editorPreferredSize.height))" type="code"/>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPaneRight">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="editorMaxSize" type="code"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="editorMinSize" type="code"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="editorPreferredSize" type="code"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="right"/>
......@@ -44,8 +59,25 @@
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="editorsPanel">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignCardLayout"/>
</Container>
</SubComponents>
</Container>
<Container class="javax.swing.JScrollPane" name="jScrollPaneLeft">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="jTableMaxSize" type="code"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="jTableMinSize" type="code"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="jTablePreferredSize" type="code"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
......@@ -62,6 +94,15 @@
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="outlineModel" type="code"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="jTableMaxSize" type="code"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="jTableMinSize" type="code"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="jTablePreferredSize" type="code"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new Outline()"/>
......
......@@ -27,8 +27,16 @@ import fr.cemagref.ohoui.reflect.IntrospectionException;
import fr.cemagref.ohoui.reflect.OhOuiContext;
import fr.cemagref.ohoui.structure.OhObject;
import fr.cemagref.ohoui.structure.OhObjectComplex;
import fr.cemagref.ohoui.ui.panels.AbstractOhEditor;
import fr.cemagref.ohoui.ui.panels.DefaultObjectEditor;
import java.awt.CardLayout;
import java.awt.Dimension;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.netbeans.swing.outline.DefaultOutlineModel;
......@@ -39,30 +47,71 @@ import org.netbeans.swing.outline.OutlineModel;
*
* @author Nicolas Dumoulin <nicolas.dumoulin@cemagref.fr>
*/
public class NodesAndPanelsPanel extends JPanel {
public class NodesAndPanelsPanel extends JPanel implements ListSelectionListener {
private static final Logger LOGGER = Logger.getLogger(NodesAndPanelsPanel.class.getName());
private final static Dimension jTableMinSize = new Dimension(150, 100);
private final static Dimension jTableMaxSize = new Dimension(32767, 32767);
private final static Dimension jTablePreferredSize = new Dimension(200, 400);
private final static Dimension editorMinSize = new Dimension(200, 100);
private final static Dimension editorMaxSize = new Dimension(32767, 32767);
private final static Dimension editorPreferredSize = new Dimension(200, 400);
private OutlineModel outlineModel;
private OhTreeModel treeModel;
private Map<Object, AbstractOhEditor<Object, JComponent>> editorsMap;
private CardLayout editorsCardLayout;
private final static String EMPTY_EDITOR_CODE = "empty";
/** Creates new form NodesAndPanelsPanel */
public NodesAndPanelsPanel(Object o) throws IntrospectionException {
// build data model
OhObjectComplex ohObjectComplex = DefaultObjectIntrospector.introspect("test", o, new OhOuiContext());
treeModel = new OhTreeModel(ohObjectComplex);
outlineModel = DefaultOutlineModel.createOutlineModel(treeModel, new OhRowModel());
// build form and adjust UI settings
initComponents();
jSplitPane1.setPreferredSize(new Dimension(jTablePreferredSize.width + editorPreferredSize.width, Math.max(jTablePreferredSize.height, editorPreferredSize.height)));
jTable.setPreferredScrollableViewportSize(jTable.getPreferredSize());
// adjust the table renderer and listener
Outline outline = (Outline) jTable;
outline.setRenderDataProvider(new OhDataProvider());
outline.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
// TODO wrong index is fetched
OhObject selectedObject = (OhObject) outlineModel.getValueAt(e.getLastIndex(), 0);
System.out.println(e.getLastIndex() + " - " + outlineModel.getValueAt(e.getLastIndex(), 0));
// TODO put object editors in cache indexed by nodes (or handled object)
jScrollPaneRight.setViewportView(new DefaultObjectEditor(selectedObject).getPanel());
outline.getSelectionModel().addListSelectionListener(this);
// init editors
editorsMap = new HashMap<Object, AbstractOhEditor<Object, JComponent>>();
editorsCardLayout = (CardLayout) editorsPanel.getLayout();
editorsPanel.add(new JPanel(), EMPTY_EDITOR_CODE);
}
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (lsm.isSelectionEmpty()) {
// clear right panel
editorsCardLayout.show(editorsPanel, EMPTY_EDITOR_CODE);
LOGGER.fine("No selection");
} else {
int selectedRow = lsm.getMinSelectionIndex();
LOGGER.fine("Selection : " + selectedRow + " - " + outlineModel.getValueAt(selectedRow, 0));
OhObject selectedObject = (OhObject) outlineModel.getValueAt(selectedRow, 0);
if (editorsMap.containsKey(selectedObject)) {
// editor is already in cache
editorsCardLayout.show(editorsPanel, getCode(selectedObject));
} else {
// retrieve editor and put it in cache
AbstractOhEditor<Object, JComponent> editor = new DefaultObjectEditor(selectedObject);
editorsMap.put(selectedObject, editor);
editorsPanel.add(editor.getPanel(), getCode(selectedObject));
editorsCardLayout.show(editorsPanel, getCode(selectedObject));
}
});
}
editorsPanel.revalidate();
}
private String getCode(OhObject selectedObject) {
return Integer.toString(selectedObject.hashCode());
}
/** This method is called from within the constructor to
......@@ -76,13 +125,32 @@ public class NodesAndPanelsPanel extends JPanel {
jSplitPane1 = new javax.swing.JSplitPane();
jScrollPaneRight = new javax.swing.JScrollPane();
editorsPanel = new javax.swing.JPanel();
jScrollPaneLeft = new javax.swing.JScrollPane();
jTable = new Outline();
jSplitPane1.setDividerSize(5);
jSplitPane1.setDividerSize(6);
jSplitPane1.setResizeWeight(0.1);
jSplitPane1.setMinimumSize(null);
jSplitPane1.setPreferredSize(new Dimension(jTablePreferredSize.width+editorPreferredSize.width, Math.max(jTablePreferredSize.height,editorPreferredSize.height)));
jScrollPaneRight.setMaximumSize(editorMaxSize);
jScrollPaneRight.setMinimumSize(editorMinSize);
jScrollPaneRight.setPreferredSize(editorPreferredSize);
editorsPanel.setLayout(new java.awt.CardLayout());
jScrollPaneRight.setViewportView(editorsPanel);
jSplitPane1.setRightComponent(jScrollPaneRight);
jScrollPaneLeft.setMaximumSize(jTableMaxSize);
jScrollPaneLeft.setMinimumSize(jTableMinSize);
jScrollPaneLeft.setPreferredSize(jTablePreferredSize);
jTable.setModel(outlineModel);
jTable.setMaximumSize(jTableMaxSize);
jTable.setMinimumSize(jTableMinSize);
jTable.setPreferredSize(jTablePreferredSize);
jScrollPaneLeft.setViewportView(jTable);
jSplitPane1.setLeftComponent(jScrollPaneLeft);
......@@ -91,16 +159,15 @@ public class NodesAndPanelsPanel extends JPanel {
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
.addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 390, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel editorsPanel;
private javax.swing.JScrollPane jScrollPaneLeft;
private javax.swing.JScrollPane jScrollPaneRight;
private javax.swing.JSplitPane jSplitPane1;
......
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