Commit d2210599 authored by Simon Rahn's avatar Simon Rahn
Browse files

Merge branch 'table_stsc' into 'table'

add missing updateFromOutside flag toggel.

See merge request !221
parents 5fd6511d 282684ed
Pipeline #1080711 passed with stages
in 134 minutes and 52 seconds
......@@ -196,6 +196,7 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
}
}
}
this.updateFromOutside = false;
}
@Override
......
......@@ -4,9 +4,9 @@ package org.vadere.gui.projectview;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.projectview.view.ProjectView;
import org.vadere.gui.topographycreator.control.attribtable.tree.TreeModelCache;
import org.vadere.util.io.VadereArgumentParser;
import org.vadere.util.logging.Logger;
import org.vadere.util.logging.StdOutErrLog;
......@@ -37,6 +37,7 @@ public class VadereApplication {
try {
ns = vadereArgumentParser.parseArgsAndProcessInitialOptions(args);
Messages.loadLanguageFromPreferences(VadereApplication.class);
TreeModelCache.buildTreeModelCache();
ProjectView.start(ns.getString("project-path"));
} catch (UnsatisfiedLinkError linkError) {
System.err.println("[LWJGL]: " + linkError.getMessage());
......
......@@ -17,6 +17,7 @@ public class JAttributeTable extends JPanel implements AttributeTreeModel.ValueL
private final List<JComponent> renderOrderModel;
private final HashMap<AttributeTreeModel.TreeNode, Pair<AttributeEditor,JComponent>> editors;
private final GridBagConstraints gbc = Layouts.initGridBagConstraint(1.0);
private final ArrayList<Component> focusOrder;
Styler rowDelegate;
private final EditorRegistry registry = EditorRegistry.getInstance();
......@@ -27,6 +28,7 @@ public class JAttributeTable extends JPanel implements AttributeTreeModel.ValueL
this.renderOrderModel = new ArrayList<>();
this.rowDelegate = rowDelegateStyler;
this.model = model;
this.focusOrder = new ArrayList<>();
editors = new HashMap<>();
model.addChangeListener(this);
......@@ -36,6 +38,10 @@ public class JAttributeTable extends JPanel implements AttributeTreeModel.ValueL
refreshUI(model);
}
public List<Component> getFocusOrder(){
return focusOrder;
}
public void refreshUI(AttributeTreeModel.TreeNode model) {
this.removeAll();
if (model != null) {
......@@ -52,6 +58,7 @@ public class JAttributeTable extends JPanel implements AttributeTreeModel.ValueL
}
var delegates = editors.get(subModel);
var editor = delegates.getFirst();
focusOrder.addAll(editor.getInputComponent());
var subPanel = delegates.getSecond();
renderOrderModel.add(this.rowDelegate.rowDelegateStyle(key, editor));
if (subPanel.getComponentCount() > 0) {
......
......@@ -12,10 +12,8 @@ import javax.swing.*;
import java.awt.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
/**
......@@ -40,6 +38,11 @@ public class AbstractTypeCellEditor extends AttributeEditor{
protected AttributeTableView view;
private Object instanceOfSelected;
@Override
public List<Component> getInputComponent() {
return Collections.singletonList(comboBox);
}
public AbstractTypeCellEditor(AttributeTreeModel.TreeNode model, JPanel contentPanel, Object initialValue) {
super(model, contentPanel,initialValue);
}
......
......@@ -14,6 +14,7 @@ public abstract class AttributeEditor extends JPanel implements AttributeTreeMod
Object oldValue;
private boolean locked = false;
public abstract java.util.List<Component> getInputComponent();
public AttributeEditor(AttributeTreeModel.TreeNode model, JPanel contentPanel, Object initialValue) {
super(new BorderLayout());
......
......@@ -2,7 +2,12 @@ package org.vadere.gui.topographycreator.control.attribtable.cells.delegates;
import org.vadere.gui.topographycreator.control.attribtable.tree.AttributeTreeModel;
import javax.naming.CompositeName;
import javax.swing.*;
import java.awt.*;
import java.util.Arrays;
import java.util.Collections;
/**
* @author Ludwig Jaeck
* This class is a table delegate for editing boolean fields.
......@@ -10,6 +15,11 @@ import javax.swing.*;
public class CheckBoxCellEditor extends AttributeEditor {
private JCheckBox checkBox;
@Override
public java.util.List<Component> getInputComponent() {
return Collections.singletonList(checkBox);
}
public CheckBoxCellEditor(AttributeTreeModel.TreeNode model, JPanel contentPanel, Object initialValue) {
super(model, contentPanel,initialValue);
}
......
......@@ -8,6 +8,7 @@ import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Collections;
/**
* ChildObjectCellEditor is an editor used for any Object not registered and not abstract.
......@@ -28,6 +29,11 @@ public class ChildObjectCellEditor extends AttributeEditor {
protected Object objectInstance;
@Override
public java.util.List<Component> getInputComponent() {
return Collections.singletonList(button);
}
public ChildObjectCellEditor(AttributeTreeModel.TreeNode model, JPanel contentPanel, Object initialValue) {
super(model, contentPanel,initialValue);
this.clazz = model.getFieldType();
......
......@@ -3,10 +3,17 @@ package org.vadere.gui.topographycreator.control.attribtable.cells.delegates;
import org.vadere.gui.topographycreator.control.attribtable.tree.AttributeTreeModel;
import javax.swing.*;
import java.awt.*;
import java.util.Collections;
public class ComboBoxCellEditor extends AttributeEditor {
private JComboBox comboBox;
@Override
public java.util.List<Component> getInputComponent() {
return Collections.singletonList(comboBox);
}
public ComboBoxCellEditor(AttributeTreeModel.TreeNode model, JPanel contentPanel, Object initialValue) {
super(model, contentPanel,initialValue);
}
......
......@@ -5,6 +5,9 @@ import org.vadere.gui.topographycreator.control.attribtable.tree.FieldNode;
import javax.swing.*;
import javax.swing.text.NumberFormatter;
import java.awt.*;
import java.util.Collections;
/**
* @author Ludwig Jaeck
* This class is a table delegate for editing Double fields.
......@@ -12,6 +15,12 @@ import javax.swing.text.NumberFormatter;
public class DoubleSpinnerCellEditor extends AttributeEditor {
private JSpinner spinner;
@Override
public java.util.List<Component> getInputComponent() {
return Collections.singletonList(
((JSpinner.NumberEditor) spinner.getEditor()).getTextField());
}
public DoubleSpinnerCellEditor(AttributeTreeModel.TreeNode model, JPanel contentPanel, Object initialValue) {
super(model, contentPanel,initialValue);
}
......
......@@ -5,10 +5,20 @@ import org.vadere.gui.topographycreator.control.attribtable.tree.FieldNode;
import javax.swing.*;
import javax.swing.text.NumberFormatter;
import java.awt.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.util.Collections;
public class SpinnerCellEditor extends AttributeEditor {
private JSpinner spinner;
@Override
public java.util.List<Component> getInputComponent() {
return Collections.singletonList(
((JSpinner.NumberEditor) spinner.getEditor()).getTextField());
}
public SpinnerCellEditor(AttributeTreeModel.TreeNode model, JPanel contentPanel, Object initialValue) {
super(model, contentPanel,initialValue);
}
......@@ -26,7 +36,8 @@ public class SpinnerCellEditor extends AttributeEditor {
private void initializeSpinnerModel() {
JFormattedTextField txt = ((JSpinner.NumberEditor) spinner.getEditor()).getTextField();
((NumberFormatter) txt.getFormatter()).setAllowsInvalid(false);
// allow invalid true to allow a single '-' minus Symbol to be valid
((NumberFormatter) txt.getFormatter()).setAllowsInvalid(true);
}
private void initializeSpinnerValue() {
......
......@@ -7,6 +7,8 @@ import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DocumentFilter;
import javax.swing.text.PlainDocument;
import java.awt.*;
import java.util.Collections;
/**
* @author Ludwig Jaeck
......@@ -16,6 +18,11 @@ import javax.swing.text.PlainDocument;
public class TextEditCellEditor extends AttributeEditor {
private JTextField textField;
@Override
public java.util.List<Component> getInputComponent() {
return Collections.singletonList(textField);
}
public TextEditCellEditor(AttributeTreeModel.TreeNode model, JPanel contentPanel, Object initialValue) {
super(model, contentPanel,initialValue);
}
......
......@@ -9,6 +9,7 @@ import javax.swing.text.NumberFormatter;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.Arrays;
public class VPointCellEditor extends AttributeEditor {
......@@ -16,6 +17,11 @@ public class VPointCellEditor extends AttributeEditor {
private JSpinner ySpinner;
private VPoint pointBuffer;
@Override
public java.util.List<Component> getInputComponent() {
return Arrays.asList(xSpinner, ySpinner);
}
public VPointCellEditor(AttributeTreeModel.TreeNode model, JPanel contentPanel, Object initialValue) {
super(model, contentPanel,initialValue);
}
......
......@@ -15,6 +15,9 @@ import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class VShapeCellEditor extends AttributeEditor implements ViewListener {
......@@ -25,6 +28,12 @@ public class VShapeCellEditor extends AttributeEditor implements ViewListener {
private AttributeTableView view;
private GridBagConstraints gbc;
@Override
public List<Component> getInputComponent() {
return Collections.emptyList();
}
public VShapeCellEditor(AttributeTreeModel.TreeNode model, JPanel contentPanel, Object initialValue) {
super(model, contentPanel, initialValue);
initializeGridBagConstraint();
......
package org.vadere.gui.topographycreator.control.attribtable.tree;
import org.reflections.Reflections;
import org.vadere.simulator.context.VadereContext;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -22,8 +23,8 @@ public class AbstrNode extends AttributeTreeModel.TreeNode {
super(parent,fieldName,fieldType);
node = new ObjectNode(getParent(), fieldName,fieldType);
setValueNode(new ValueNode(this,fieldName, fieldType,null));
this.classRegistry = (Map<Class<?>, AttributeTreeModel.TreeNode>) new Reflections("org.vadere")
.getSubTypesOf(fieldType)
var cache = (TreeModelCache) VadereContext.getCtx("GUI").get(VadereContext.TREE_NODE_CTX);
this.classRegistry = cache.getSubTypeOff(fieldType)
.stream()
.collect(Collectors.toMap(
aClass -> aClass,
......
......@@ -63,32 +63,20 @@ public class ArrayNode extends AttributeTreeModel.TreeNode {
getValueNode().setReference(obj);
var array = (List)obj;
var children = super.getChildren();
if(children.size() > array.size()){
for(int i = array.size(); i <= children.size(); i++){
children.remove(String.valueOf(i));
}
}
for (int i = 0; i < array.size(); i++) {
// 1. clear old array values
children.clear();
// 2. create new array values based on obj data.
for (int i = 0; i<array.size();i++) {
var key = String.valueOf(i);
var value = array.get(i);
if (children.containsKey(key)) {
var node = ((AttributeTreeModel.TreeNode)((Pair) children.get(key)).getSecond());
node.setValueNode(new ValueNode(this, key, genericType, value));
AttributeTreeModel.TreeNode newNode = null;
if (Modifier.isAbstract(genericType.getModifiers())) {
newNode = new AbstrNode(this, key, genericType);
} else {
AttributeTreeModel.TreeNode newNode = null;
if(Modifier.isAbstract(genericType.getModifiers())){
newNode = new AbstrNode(this,key,genericType);
}else{
newNode = new FieldNode(this, key, genericType, new ValueNode(this, key, genericType, value));
}
children.put(key, new Pair(null, newNode));//new ValueNode(this, key, value.getClass(), value)
}
}
if(children.size() > array.size()){
for(int i = array.size(); i < children.size(); i++){
children.remove(String.valueOf(i));
newNode = new FieldNode(this, key, genericType, new ValueNode(this, key, genericType, value));
}
children.put(key, new Pair(null, newNode));//new ValueNode(this, key, value.getClass(), value)
}
}
notifyStructureListeners();
......
package org.vadere.gui.topographycreator.control.attribtable.tree;
import org.reflections.Reflections;
import org.vadere.simulator.context.VadereContext;
import org.vadere.state.attributes.AttributesScenarioElement;
import java.util.HashMap;
import java.util.Set;
/**
* Simple Cache to store Reflection calls to save time.
*/
public class TreeModelCache {
private final HashMap<String, Set<Class<?>>> classCache = new HashMap<>();
public static TreeModelCache buildTreeModelCache(){
System.out.println("build tree model cache ...");
VadereContext ctx = new VadereContext();
ctx.put(VadereContext.TREE_NODE_CTX, new TreeModelCache());
VadereContext.add("GUI", ctx);
TreeModelCache cache = (TreeModelCache)VadereContext.getCtx("GUI").get(VadereContext.TREE_NODE_CTX);
cache.getSubTypeOff(AttributesScenarioElement.class);
return cache;
}
public Set<Class<?>> getSubTypeOff(Class clazz){
if (!classCache.containsKey(clazz.getCanonicalName())){
classCache.put(clazz.getCanonicalName(), new Reflections("org.vadere").getSubTypesOf(clazz));
}
return classCache.get(clazz.getCanonicalName());
}
}
......@@ -4,8 +4,11 @@ import org.reflections.Reflections;
import org.vadere.gui.components.view.ISelectScenarioElementListener;
import org.vadere.gui.topographycreator.control.AttributeHelpView;
import org.vadere.gui.topographycreator.control.attribtable.ViewListener;
import org.vadere.gui.topographycreator.control.attribtable.tree.TreeAdapter;
import org.vadere.gui.topographycreator.control.attribtable.tree.TreeException;
import org.vadere.gui.topographycreator.control.attribtable.tree.TreeModelCache;
import org.vadere.gui.topographycreator.model.TopographyCreatorModel;
import org.vadere.simulator.context.VadereContext;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.AttributesScenarioElement;
......@@ -19,6 +22,7 @@ import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;
import static org.vadere.gui.topographycreator.control.attribtable.util.Layouts.initGridBagConstraint;
......@@ -35,7 +39,6 @@ public class AttributeTableContainer extends JPanel implements ISelectScenarioEl
AttributeTableView attrView;
JTextPane helpView;
private final NotifyContext ctx = new NotifyContext(this.getClass());
ScenarioElement selectedElement;
TopographyCreatorModel panelModel;
......@@ -70,13 +73,11 @@ public class AttributeTableContainer extends JPanel implements ISelectScenarioEl
this.add(new JScrollPane(attrView), gbcPage);
this.add(helpView, gbcHelp);
var registeredClasses = new Reflections("org.vadere")
.getSubTypesOf(AttributesScenarioElement.class);
for(var clazz : registeredClasses){
var cache = (TreeModelCache) VadereContext.getCtx("GUI").get(VadereContext.TREE_NODE_CTX);
for(var clazz : cache.getSubTypeOff(AttributesScenarioElement.class)){
attrView.buildPageFor(clazz);
}
defaultModel.addSelectScenarioElementListener(this);
defaultModel.addObserver(this);
}
......
......@@ -9,6 +9,7 @@ import org.vadere.gui.topographycreator.control.attribtable.cells.CellValueDeleg
import org.vadere.gui.topographycreator.control.attribtable.cells.delegates.AttributeEditor;
import org.vadere.gui.topographycreator.control.attribtable.tree.AttributeTreeModel;
import org.vadere.gui.topographycreator.control.attribtable.tree.TreeException;
import org.vadere.gui.topographycreator.control.attribtable.util.ManualAttributeTableFocus;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
......@@ -50,6 +51,12 @@ public class AttributeTablePage extends JPanel implements AttributeTreeModel.Val
this.add(container);
}
public void applyFocusPolicy(ManualAttributeTableFocus focusTraversalPolicy){
focusTraversalPolicy.add(view.getFocusOrder());
focusTraversalPolicy.addListener();
}
@NotNull
public static String generateHeaderName(Class clazz) {
......
......@@ -5,6 +5,8 @@ import org.vadere.gui.topographycreator.control.attribtable.ViewListener;
import org.vadere.gui.topographycreator.control.attribtable.tree.AttributeTreeModel;
import org.vadere.gui.topographycreator.control.attribtable.tree.TreeAdapter;
import org.vadere.gui.topographycreator.control.attribtable.tree.TreeException;
import org.vadere.gui.topographycreator.control.attribtable.util.ManualAttributeTableFocus;
import org.vadere.simulator.context.Context;
import javax.swing.*;
import java.awt.*;
......@@ -12,12 +14,14 @@ import java.util.HashMap;
public class AttributeTableView extends JPanel implements ViewListener {
HashMap<Class, AttributeTablePage> pages;
private HashMap<Class, ManualAttributeTableFocus> pageFocus;
AttributeTablePage activePage;
ViewListener viewListener;
public AttributeTableView(ViewListener viewListener) {
super(new BorderLayout());
this.pages = new HashMap<>();
this.pageFocus = new HashMap<>();
this.viewListener = viewListener;
}
......@@ -57,11 +61,17 @@ public class AttributeTableView extends JPanel implements ViewListener {
public void buildPageFor(Class clazz){
var tree = AttributeTreeModel.parseClassTree(new TreeAdapter(this), null, clazz);
var page = new AttributeTablePage(tree,AttributeTablePage.generateHeaderName(clazz),new AttributeTablePage.TableStyler(tree));
var f = new ManualAttributeTableFocus();
page.applyFocusPolicy(f);
this.pages.put(clazz, page);
this.pageFocus.put(clazz, f);
}
public void buildPageFor(AttributeTreeModel.TreeNode tree){
var page = new AttributeTablePage(tree,AttributeTablePage.generateHeaderName(tree.getFieldType()),new AttributeTablePage.TableStyler(tree));
var f = new ManualAttributeTableFocus();
page.applyFocusPolicy(f);
this.pages.put(tree.getFieldType(), page);
this.pageFocus.put(tree.getFieldType(), f);
}
}
package org.vadere.gui.topographycreator.control.attribtable.util;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.LinkedList;
public class ManualAttributeTableFocus {
private ArrayList<Component> focusList = new ArrayList<>();
public void add(Component c){
focusList.add(c);
}
public void add(java.util.List<Component> c){
focusList.addAll(c);
}
public void addListener(){
for(var c : focusList){
c.addKeyListener( new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_TAB){
if (e.isShiftDown()){
var c =getComponentBefore(e.getComponent());
var ret = c.requestFocusInWindow();
System.out.println("Last");
} else {
var c =getComponentAfter(e.getComponent());
var ret = c.requestFocusInWindow();
System.out.println("Next");
}
e.consume();
}
}
public Component getComponentAfter(Component component) {
int newIndex = (focusList.indexOf(component) + 1)% focusList.size();
return focusList.get(newIndex);
}
public Component getComponentBefore(Component component) {
var nextIndex = focusList.indexOf(component)-1;
if (nextIndex < 0){
nextIndex = focusList.size() -1;
}
return focusList.get(nextIndex);
}
});
}
}
}
Supports Markdown
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