Statistics
| Revision:

root / org.gvsig.proj / branches / refactor2018 / org.gvsig.proj / org.gvsig.proj.swing / org.gvsig.proj.swing.impl / src / main / java / org / gvsig / proj / swing / impl / tree / LoadingNode.java @ 866

History | View | Annotate | Download (1.74 KB)

1
package org.gvsig.proj.swing.impl.tree;
2

    
3
import java.awt.Image;
4
import java.awt.Rectangle;
5
import java.awt.image.ImageObserver;
6
import java.util.Objects;
7

    
8
import javax.swing.ImageIcon;
9
import javax.swing.JTree;
10
import javax.swing.tree.TreeNode;
11
import javax.swing.tree.TreePath;
12

    
13
import org.gvsig.tools.swing.api.ToolsSwingLocator;
14

    
15
public class LoadingNode extends LeafNode {
16
        private String message;
17
        private ImageIcon icon;
18
        final protected TreePath path;
19
        final protected JTree tree;
20
        
21
        public LoadingNode(BranchNode parent, TreeContainer container, String message) {
22
                super(parent);
23
                
24
                // we don't want to reuse the icon for other nodes, since we'll add an observer to the icon 
25
                this.icon = new ImageIcon(ToolsSwingLocator.getIconThemeManager().getCurrent().get("crs-loadingnode-spinner").getImage());
26
                this.message = message;
27
                this.tree = container.getTree();
28
                
29
                TreeNode[] nodeList = container.getModel().getPathToRoot(this);
30
                if (nodeList!=null) {
31
                        path = new TreePath(nodeList);
32
                }
33
                else {
34
                        path = null;
35
                }
36
                // required for animaged gifs in treenodes
37
                this.icon.setImageObserver(new ImageObserver() {
38
                        @Override
39
                        public boolean imageUpdate(
40
                                        Image img, int infoflags, int x, int y, int w, int h) {
41
                                if (path == null || !LoadingNode.this.tree.isShowing()) {
42
                                        return false;        
43
                                }
44
                                Rectangle cellRect = LoadingNode.this.tree.getPathBounds(path);
45
                                if ((infoflags & (FRAMEBITS | ALLBITS)) != 0 && Objects.nonNull(cellRect)) {
46
                                        LoadingNode.this.tree.repaint(cellRect);
47
                                }
48
                                return (infoflags & (ALLBITS | ABORT)) == 0;
49
                        }
50
                });
51
        }
52
        
53
        public void setMessage(String message) {
54
                this.message = message;
55
        }
56

    
57
        @Override
58
        public String toString() {
59
                return message;
60
        }
61
        
62
        @Override
63
        public ImageIcon getIcon() {
64
                return icon;
65
        }
66
}