source: java/main/src/main/java/com/framsticks/gui/view/TreeCellRenderer.java @ 84

Last change on this file since 84 was 84, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • simplification of entities management model
  • cleanup around params (improve hierarchy)
  • migrate from JUnit to TestNG
  • introduce FEST to automatically test GUI
  • improve slider control
  • loosen synchronization between gui tree and backend representation
  • and many other bug fixes

NOTICE:

  • a great many of lines is changed only because of substituting spaces with tabs

CHANGELOG (oldest changes at the bottom):

Some cleaning after fix found.

Fix bug with tree.

More changes with TreeNodes?.

Finally fix issue with tree.

Improve gui tree management.

Decouple update of values from fetch request in gui.

Minor changes.

Minor changes.

Minor change.

Change Path construction wording.

More fixes to SliderControl?.

Fix SliderControl?.

Fix SliderControl?.

Minor improvement.

Several changes.

Make NumberParam? a generic class.

Add robot to the gui test.

Setup common testing logging configuration.

Remove Parameters class.

Remove entityOwner from Parameters.

Move name out from Parameters class.

Move configuration to after the construction.

Simplify observers and endpoints.

Remove superfluous configureEntity overrides.

Add dependency on fest-swing-testng.

Use FEST for final print test.

Use FEST for more concise and readable assertions.

Divide test of F0Parser into multiple methods.

Migrate to TestNG

Minor change.

Change convention from LOGGER to log.

Fix reporting of errors during controls filling.

Bound maximal height of SliderControl?.

Minor improvements.

Improve tooltips for controls.

Also use Delimeted in more places.

Move static control utilities to Gui.

Rename package gui.components to controls.

Some cleaning in controls.

Improve Param classes placing.

Move ValueParam?, PrimitiveParam? and CompositeParam? one package up.

Improve ParamBuilder?.

Move getDef to ValueParam? and PrimitiveParam?.

Move getMax and getDef to ValueParam?.

Move getMin to ValueParam?.

Upgrade to laters apache commons versions.

Use filterInstanceof extensively.

Add instanceof filters.

Make ValueParam? in many places of Param.

Place assertions about ValueParam?.

Add ValueParam?

Rename ValueParam? to PrimitiveParam?

Minor changes.

Several improvements to params types.

Add NumberParam?.

Add TextControl? component.

Add .swp files to .gitignore

Greatly improved slider component.

Some improvements.

Make Param.reassign return also a state.

Add IterableIterator?.

Several changes.

  • Move util classes to better packages.
  • Remove warnings from eclim.

Several improvements.

Fix bug with BooleanParam?.

Some experiments with visualization.

Another fix to panel management.

Improve panel management.

Some refactorization around panels.

Add root class for panel.

File size: 3.9 KB
Line 
1package com.framsticks.gui.view;
2
3import com.framsticks.gui.ImageProvider;
4import com.framsticks.gui.TreeNode;
5
6import javax.swing.*;
7import javax.swing.tree.DefaultTreeCellRenderer;
8
9import org.apache.log4j.Logger;
10
11import java.awt.*;
12
13/**
14 * Renderer of Tree. Sets appropriate icons for nodes.
15 */
16@SuppressWarnings("serial")
17public class TreeCellRenderer extends DefaultTreeCellRenderer {
18        private static final Logger log =
19                Logger.getLogger(TreeCellRenderer.class);
20
21
22        public TreeCellRenderer() {
23                setOpenIcon(null);
24                setClosedIcon(null);
25                setLeafIcon(null);
26        }
27
28        @Override
29        public Component getTreeCellRendererComponent(JTree tree, Object value,
30                        boolean sel, boolean expanded, boolean leaf, int row,
31                        boolean hasFocus) {
32
33                //super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
34                //              row, hasFocus);
35                if (value == null) {
36                        return this;
37                }
38                if (!(value instanceof TreeNode)) {
39                        setIcon(ImageProvider.loadImage(ImageProvider.SERVER));
40                        setText("framsticks");
41                        return this;
42                }
43                TreeNode treeNode = (TreeNode)value;
44                assert treeNode.getFrame().isActive();
45                setToolTipText(treeNode.getTooltip());
46                setIcon(ImageProvider.loadImage(treeNode.getIconName()));
47                setText(treeNode.getName());
48                return this;
49        }
50
51        public static String findIconName(String nodeName, String path) {
52                if (nodeName == null || path == null) {
53                        log.warn("given invalid parameters: " + nodeName + " " + path);
54                        // return null;
55                        return ImageProvider.SERVER;
56                }
57                if (path.equals("/")) {
58                        return ImageProvider.SERVER;
59                }
60                if (path.endsWith("simulator")) {
61                        return ImageProvider.SIMULATOR;
62                }
63                if (path.endsWith("cli")) {
64                        return ImageProvider.CLI;
65                }
66                if (path.endsWith("world")) {
67                        return ImageProvider.WORLD;
68                }
69                if (path.endsWith("genepools")) {
70                        return ImageProvider.GENEPOOLS;
71                }
72                if (path.endsWith("populations")) {
73                        return ImageProvider.POPULATIONS;
74                }
75                if (path.endsWith("experiment")) {
76                        return ImageProvider.EXPERIMENT;
77                }
78                if (path.endsWith("stats")) {
79                        return ImageProvider.STATISTIC;
80                }
81                if (nodeName.equals("creatures") || path.endsWith("creatures")) {
82                        return ImageProvider.CREATURES_GROUP;
83                }
84                if (nodeName.equals("Favourite Fields")) {
85                        return ImageProvider.FAVORITE_FIELDS;
86                }
87                if (nodeName.equals("genotypes") || path.endsWith("creatures")) {
88                        return ImageProvider.GENOTYPES_GROUP;
89                }
90                if (nodeName.equals("parts") || path.endsWith("parts")) {
91                        return ImageProvider.PART_GROUP;
92                }
93                if (nodeName.equals("joints") || path.endsWith("joints")) {
94                        return ImageProvider.JOINT_GROUP;
95                }
96                if (nodeName.equals("neurodefs") || path.endsWith("neurodefs")) {
97                        return ImageProvider.NEURON_DEF_GROUP;
98                }
99                if (nodeName.equals("mechparts") || path.endsWith("mechparts")) {
100                        return ImageProvider.MECH_PART_GROUP;
101                }
102                if (nodeName.equals("mechjoints") || path.endsWith("mechjoints")) {
103                        return ImageProvider.MECH_JOINT_GROUP;
104                }
105                if (nodeName.equals("neurons") || path.endsWith("neurons")) {
106                        return ImageProvider.NEURON_GROUP;
107                }
108                if (path.matches("^.*parts/[0-9]+$")) {
109                        return ImageProvider.PART;
110                }
111                if (path.matches("^.*joints/[0-9]+$")) {
112                        return ImageProvider.JOINT;
113                }
114                if (path.matches("^.*neurodefs/[0-9]+$")) {
115                        return ImageProvider.NEURON_DEF;
116                }
117                if (path.matches("^.*mechparts/[0-9]+$")) {
118                        return ImageProvider.MECH_PART;
119                }
120                if (path.matches("^.*mechjoints/[0-9]+$")) {
121                        return ImageProvider.MECH_JOINT;
122                }
123                if (path.matches("^.*neurons/[0-9]+$")) {
124                        return ImageProvider.NEURON;
125                }
126                if (path.matches("^.*creatures/c[0-9]+$")) {
127                        return ImageProvider.CREATURE;
128                }
129                if (path.matches("^.*genotypes/g[0-9]+$")) {
130                        return ImageProvider.GENOTYPES;
131                }
132                if (path.matches("^.*populations/groups/[0-9]+$")) {
133                        return ImageProvider.POPULATION_GROUP;
134                }
135                if (path.matches("^.*genepools/groups/[0-9]+$")) {
136                        return ImageProvider.GENEPOOLS_GROUP;
137                }
138                if (path.matches("^.*events/e[0-9]+$")) {
139                        return ImageProvider.EVENT;
140                }
141                return ImageProvider.SERVER;
142        }
143
144
145}
Note: See TracBrowser for help on using the repository browser.