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 @ 854

History | View | Annotate | Download (1.81 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("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
            
37
                // required for animaged gifs in treenodes
38
            this.icon.setImageObserver(new ImageObserver() {
39
                @Override
40
                public boolean imageUpdate(
41
                    Image img, int infoflags, int x, int y, int w, int h) {
42
                        if (path == null || !LoadingNode.this.tree.isShowing()) {
43
                                return false;        
44
                        }
45
                        Rectangle cellRect = LoadingNode.this.tree.getPathBounds(path);
46
                  if ((infoflags & (FRAMEBITS | ALLBITS)) != 0 && Objects.nonNull(cellRect)) {
47
                          LoadingNode.this.tree.repaint(cellRect);
48
                  }
49
                  return (infoflags & (ALLBITS | ABORT)) == 0;
50
                }
51
          });
52
        }
53
        
54
        public void setMessage(String message) {
55
                this.message = message;
56
        }
57

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