Commit ac1d2cda authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

buttons for navigation in subobjects

parent 6119b40c
......@@ -26,8 +26,14 @@ import fr.cemagref.ohoui.ui.swing.basiccontrols.AbstractOhEditor;
import fr.cemagref.ohoui.ui.swing.basiccontrols.EditorsProvider;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
......@@ -63,7 +69,8 @@ public class OhPanel extends JPanel {
this.editorsCardLayout = new CardLayout();
this.editorsPanel = new JPanel(editorsCardLayout);
editorsPanel.add(new JPanel(), EMPTY_EDITOR_CODE);
pathPanel = new JLabel();
pathPanel = new JPanel();
pathPanel.setLayout(new BoxLayout(pathPanel, BoxLayout.LINE_AXIS));
this.setLayout(new BorderLayout());
this.add(pathPanel, BorderLayout.NORTH);
this.add(editorsPanel);
......@@ -82,15 +89,25 @@ public class OhPanel extends JPanel {
* @param selectedObject
*/
public final AbstractOhEditor<Object, JComponent> selectObject(OhObjectComplex selectedObject) {
// find the path of the edited object from the root
// find the path of the edited object from the root and update the path display
OhObjectComplex current = selectedObject;
StringBuilder buff = new StringBuilder();
Dimension dimension = new Dimension(40, 40);
pathPanel.removeAll();
JLabel label = new JLabel(current.getName());
label.setPreferredSize(dimension);
pathPanel.add(label);
current = current.getParent();
while (current != null) {
buff.insert(0, current.getName()).insert(0, " > ");
pathPanel.add(Box.createRigidArea(new Dimension(5, 0)), 0);
JButton pathButton = new JButton(current.getName());
pathButton.setPreferredSize(dimension);
pathButton.setContentAreaFilled(false);
pathButton.addActionListener(new PathActionListener(current));
pathPanel.add(pathButton, 0);
current = current.getParent();
}
// update the path display
((JLabel) pathPanel).setText(buff.substring(3));
pathPanel.add(new JLabel("Editing: "), 0);
pathPanel.repaint();
// display the editor
boolean firstAdd = !editorsMap.containsKey(selectedObject);
AbstractOhEditor<Object, JComponent> editor = getEditorFor(selectedObject);
......@@ -128,4 +145,18 @@ public class OhPanel extends JPanel {
public void applyChanges() {
rootEditor.getValue();
}
private class PathActionListener implements ActionListener {
private final OhObjectComplex current;
public PathActionListener(OhObjectComplex current) {
this.current = current;
}
@Override
public void actionPerformed(ActionEvent e) {
selectObject(current);
}
}
}
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