source: java/main/src/main/java/com/framsticks/gui/ObjectPanel.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 3.2 KB
RevLine 
[77]1package com.framsticks.gui;
2
[84]3import com.framsticks.gui.controls.Control;
[90]4import com.framsticks.gui.controls.ControlOwner;
[84]5import com.framsticks.gui.controls.ValueControl;
[100]6import com.framsticks.params.Access;
[77]7import com.framsticks.params.Param;
[84]8
[100]9import org.apache.logging.log4j.Logger;
10import org.apache.logging.log4j.LogManager;
[77]11
12import javax.swing.*;
[90]13
[77]14import java.util.Collection;
[101]15import java.util.HashMap;
[77]16import java.util.Map;
[105]17
18import static com.framsticks.structure.TreeOperations.*;
[84]19import static com.framsticks.util.lang.Containers.filterInstanceof;
[97]20
[105]21import com.framsticks.structure.Path;
[97]22import com.framsticks.util.FramsticksException;
[77]23
[101]24
[77]25@SuppressWarnings("serial")
[90]26public class ObjectPanel extends ModifiablePanel implements ControlOwner {
[77]27
[100]28        private static final Logger log = LogManager.getLogger(ObjectPanel.class);
[77]29
[101]30        final protected Map<String, Control> controls = new HashMap<String, Control>();
31        final protected Map<String, ValueControl> valueControls = new HashMap<String, ValueControl>();
[77]32
[99]33        protected final JPanel contentPanel;
34        protected final JScrollPane scrollPane;
35
[100]36        public ObjectPanel(TreePanel.Parameters parameters, Collection<Param> params) {
[84]37                super(parameters);
[77]38
[99]39                contentPanel = new JPanel();
40                scrollPane = new JScrollPane(contentPanel);
[101]41
[99]42                setupContentComponent(scrollPane);
43
[101]44                Gui.fillWithControls(this, contentPanel, params, controls, Control.class);
[90]45                setName(framsClass.getId());
[77]46
[101]47                for (final ValueControl c : filterInstanceof(controls.values(), ValueControl.class)) {
48                        valueControls.put(c.getParam().getId(), c);
[98]49                        c.setUserEnabled(true);
[77]50                }
[90]51
[77]52                contentPanel.add(Box.createVerticalGlue());
53                this.revalidate();
54        }
55
56        @Override
57        protected void applyChanges() {
58                assert frame.isActive();
[100]59                assert currentPath != null;
[101]60                treeAtFrame.pushUserChangesToTree(currentPath);
61                refreshControlButtons();
[77]62        }
63
[101]64
65        @Override
66        protected void revertChanges() {
67                assert currentPath != null;
68                removeSideNote(currentPath, treeAtFrame.getUserChangesKey());
69                pullValuesFromLocalToUser(bindAccess(currentPath));
[77]70        }
71
72        @Override
[100]73        public void pullValuesFromLocalToUser(Access access) {
74                assert currentPath != null;
[84]75                log.debug("refreshing components");
[77]76
[101]77                UserChanges userChanges = getSideNote(currentPath, treeAtFrame.getUserChangesKey());
[77]78
[98]79
[101]80                for (Map.Entry<String, ValueControl> e : valueControls.entrySet()) {
81                        String id = e.getKey();
82                        Object value;
83                        if (userChanges != null && userChanges.changes.containsKey(id)) {
84                                value = userChanges.changes.get(id);
85                        } else {
86                                value = access.get(id, Object.class);
[84]87                        }
[101]88
89                        e.getValue().pushValueToUserInterface(value);
[98]90                }
[77]91
[101]92                for (Map.Entry<String, Control> e : controls.entrySet()) {
93                        e.getValue().refreshState();
[98]94                }
[101]95
[98]96                refreshControlButtons();
[101]97                // ObjectPanel.this.revalidate();
[77]98        }
99
[84]100        @Override
101        public String getTitle() {
102                return "Properties";
103        }
[77]104
[90]105        @Override
[98]106        public void handle(FramsticksException exception) {
107                frame.handle(exception);
[90]108        }
109
[97]110        @Override
[100]111        public Path getCurrentPath() {
112                return super.getCurrentPath();
[97]113        }
114
[101]115        @Override
116        public boolean onValueChange(ValueControl control, Object newValue) {
117                if (currentPath == null) {
118                        return true;
119                }
120                boolean result = treeAtFrame.changeValue(currentPath.assureResolved().getTopObject(), control, newValue);
121                refreshControlButtons();
122                return result;
123        }
124
[84]125}
Note: See TracBrowser for help on using the repository browser.