Statistics
| Revision:

root / trunk / extensions / extHyperlink / src / org / gvsig / hyperlink / ShowPanel.java @ 28132

History | View | Annotate | Download (4.03 KB)

1
package org.gvsig.hyperlink;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.event.ComponentEvent;
5
import java.awt.event.ComponentListener;
6
import java.io.File;
7
import java.net.MalformedURLException;
8

    
9
import javax.swing.JPanel;
10
import javax.swing.JScrollPane;
11

    
12
import org.apache.log4j.Logger;
13

    
14
import com.iver.andami.PluginServices;
15
import com.iver.andami.ui.mdiManager.IWindow;
16
import com.iver.andami.ui.mdiManager.WindowInfo;
17

    
18
/**
19
 * This class extends JPanel. This class implements a Panel to show the content of the URI
20
 * that the constructor of the class receives. This panel invokes a new one with the content
21
 * of the URI. The type of the supported URI should be added like extension point in the
22
 * initialization of the extension.
23
 *
24
 * @author Vicente Caballero Navarro
25
 * @author Eustaquio Vercher
26
 *
27
 */
28
public class ShowPanel extends JPanel implements IWindow, ComponentListener{
29
        private static Logger logger = Logger.getLogger(ShowPanel.class.getName());
30
        private JScrollPane jScrollPane = null;
31
        private WindowInfo m_ViewInfo = null;
32
        private AbstractHyperLinkPanel contents = null;
33
        private static int xpos = 0;
34
        private static int ypos = 0;
35
        
36

    
37
        public ShowPanel(AbstractHyperLinkPanel contents) {
38
                super();
39
                this.contents = contents;
40
                initialize();
41
        }
42

    
43
        /**
44
         * This method initializes this
45
         */
46
        private void initialize() {
47
                this.setLayout(new BorderLayout());
48
                this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
49
                getJScrollPane().setViewportView(contents);
50
        }
51

    
52

    
53
        
54
        /**
55
         * Returns a Scroll Pane with the content of the HyperLink
56
         * @return jScrollPane
57
         */
58
        private JScrollPane getJScrollPane() {
59
                if (jScrollPane == null) {
60
                        jScrollPane = new JScrollPane();
61
                        //jScrollPane.setPreferredSize(new java.awt.Dimension(300, 400));
62
                }
63
                return jScrollPane;
64
        }
65

    
66
        /*
67
         *  (non-Javadoc)
68
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
69
         */
70
    public WindowInfo getWindowInfo() {
71
            if (m_ViewInfo==null) {
72
                    m_ViewInfo = new WindowInfo(WindowInfo.RESIZABLE |
73
                                    WindowInfo.MAXIMIZABLE |
74
                                    WindowInfo.ICONIFIABLE |
75
                                    WindowInfo.PALETTE);
76
                    if (contents.getURI().toString().startsWith("file:") && contents.getURI().isAbsolute()) {
77
                            try {
78
                                    File file = new File(contents.getURI().toURL().getFile());
79
                                        m_ViewInfo.setTitle(PluginServices.getText(this,"Hyperlink")+" - "+ file.getName());
80
                                } catch (MalformedURLException e) {
81
                                        m_ViewInfo.setTitle(PluginServices.getText(this,"Hyperlink")+" - "+ contents.getURI().toString());
82
                                } catch (NullPointerException e) {
83
                                        m_ViewInfo.setTitle(PluginServices.getText(this,"Hyperlink")+" - "+ contents.getURI().toString());
84
                                }
85
                    }
86
                    else {
87
                            m_ViewInfo.setTitle(PluginServices.getText(this,"Hyperlink")+" - "+ contents.getURI().toString());
88
                    }
89
                    int height = (int)contents.getPreferredSize().getHeight()+15;
90
                    if (height>650)
91
                            height = 650;
92
                    else if (height<450)
93
                            height = 450;
94
                    int width = (int)contents.getPreferredSize().getWidth()+20;
95
                    if (width>800)
96
                            width = 800;
97
                    else if (width<450)
98
                            width = 450;
99
                    m_ViewInfo.setWidth(width);
100
                    m_ViewInfo.setHeight(height);
101
                    m_ViewInfo.setX(xpos);
102
                    xpos = (xpos + 20)%270;
103
                    m_ViewInfo.setY(ypos);
104
                    ypos = (ypos + 15)%150;
105
            }
106
                return m_ViewInfo;
107
        }
108
    
109
    /*
110
     *  (non-Javadoc)
111
     * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
112
     */
113
    public void componentResized(ComponentEvent e) {
114

    
115
        }
116
    
117
    /*
118
     *  (non-Javadoc)
119
     * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
120
     */
121
        public void componentMoved(ComponentEvent e) {
122

    
123
        }
124
        
125
        /*
126
         *  (non-Javadoc)
127
         * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
128
         */
129
        public void componentShown(ComponentEvent e) {
130

    
131
        }
132
        
133
        /*
134
         *  (non-Javadoc)
135
         * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
136
         */
137
        public void componentHidden(ComponentEvent e) {
138

    
139
        }
140

    
141

    
142
        public Object getWindowProfile() {
143
                return WindowInfo.EDITOR_PROFILE;
144
        }
145
}