KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > dck > items > ImagePreview


1 package rero.dck.items;
2
3 import java.awt.*;
4 import java.awt.event.*;
5
6 import javax.swing.*;
7 import javax.swing.event.*;
8
9 import rero.dck.*;
10 import rero.gui.background.*;
11
12 import java.util.*;
13
14 public class ImagePreview extends JPanel implements DItem
15 {
16    protected ImageConfigPreview preview;
17    protected JLabel evil;
18    protected int height;
19    protected int width;
20
21    public ImagePreview(int _width, int _height)
22    {
23       width = _width;
24       height = _height;
25
26       setBorder(BorderFactory.createEmptyBorder(0, width, 0, width));
27
28       setLayout(new GridLayout(1, 1));
29       preview = new ImageConfigPreview();
30    
31       add(preview);
32    }
33
34    public void setParent(DParent parent)
35    {
36
37    }
38
39    public void setEnabled(boolean b)
40    {
41    }
42
43    public void save()
44    {
45
46    }
47
48    public void refresh()
49    {
50       preview.center();
51    }
52
53    public int getEstimatedWidth()
54    {
55       return 0;
56    }
57
58    public void setAlignWidth(int width)
59    {
60    }
61
62    public void setParentVariable(String JavaDoc parent)
63    {
64       
65    }
66
67    public JComponent getComponent()
68    {
69       return this;
70    }
71
72    protected LinkedList listeners = new LinkedList();
73
74    protected void fireEvent(String JavaDoc command)
75    {
76       ActionEvent ev = new ActionEvent(this, 0, command);
77
78       Iterator i = listeners.iterator();
79       while (i.hasNext())
80       {
81          ActionListener temp = (ActionListener)i.next();
82          temp.actionPerformed(ev);
83       }
84    }
85
86    public void addActionListener(ActionListener l) { listeners.add(l); }
87
88    protected class ImageConfigPreview extends JPanel
89    {
90       protected BackgroundPanel window;
91       protected JPanel wparent;
92       protected JDesktopPane desktop;
93       protected BackgroundToolBar toolbar;
94
95       public ImageConfigPreview()
96       {
97          setLayout(new BorderLayout());
98          setBorder(BorderFactory.createEtchedBorder());
99
100          desktop = new JDesktopPane();
101
102          BackgroundDesktop wallpaper = new BackgroundDesktop(desktop);
103          wallpaper.setSize(Toolkit.getDefaultToolkit().getScreenSize());
104          desktop.add(wallpaper, new Integer JavaDoc(Integer.MIN_VALUE));
105
106          add(desktop, BorderLayout.CENTER);
107
108          window = new BackgroundPanel();
109
110          window.setLayout(new BorderLayout());
111
112          JPanel bottom = new JPanel();
113          bottom.setLayout(new BorderLayout());
114          bottom.setPreferredSize(new Dimension(0, 30));
115          bottom.setOpaque(false);
116
117          toolbar = new BackgroundToolBar();
118          toolbar.setPreferredSize(new Dimension(0, 15));
119          toolbar.setFloatable(false);
120          bottom.add(toolbar, BorderLayout.NORTH);
121
122          window.add(bottom, BorderLayout.SOUTH);
123
124          wparent = new JPanel();
125          wparent.setLayout(new BorderLayout());
126          wparent.setBorder(BorderFactory.createEtchedBorder());
127          wparent.add(window, BorderLayout.CENTER);
128
129          SwingUtilities.invokeLater(new Runnable JavaDoc()
130          {
131             public void run()
132             {
133                desktop.add(wparent);
134                center();
135                validate();
136             }
137          });
138
139          PreviewMouseListener listener = new PreviewMouseListener();
140
141          window.addMouseListener(listener);
142          toolbar.addMouseListener(listener);
143          desktop.addMouseListener(listener);
144       }
145
146       public void center()
147       {
148          int width, height, x, y, dw, dh;
149
150          dw = desktop.getBounds().width;
151          dh = desktop.getBounds().height;
152
153          width = dw - 40;
154          height = dh - 40;
155
156          x = 20;
157          y = 20;
158
159          wparent.setBounds(x, y, width, height);
160       }
161
162       public Dimension getPreferredSize()
163       {
164          return new Dimension(0, height);
165       }
166
167       public Dimension getMinimumSize()
168       {
169          return getPreferredSize();
170       }
171
172       protected class PreviewMouseListener extends MouseAdapter
173       {
174          public void mousePressed(MouseEvent ev)
175          {
176             if (ev.getSource() == window)
177             {
178                fireEvent("window");
179             }
180             else if (ev.getSource() == toolbar)
181             {
182                fireEvent("statusbar");
183             }
184             else if (ev.getSource() == desktop)
185             {
186                fireEvent("desktop");
187             }
188          }
189       }
190    }
191 }
192
193
Popular Tags