1 /*
2 * Created on Oct 27, 2003
3 */
4 package portaview.view;
5
6 import java.awt.Color;
7 import java.awt.Component;
8
9 import javax.swing.JScrollPane;
10
11 import portaview.model.ObservableCollection;
12
13 /***
14 * Implements the generic scoll pane for icons.
15 * @author William Lee
16 */
17 public abstract class IconPanel extends JScrollPane
18 {
19
20 private IconPanelContent content = null; // contents of the icons.
21
22 public IconPanel()
23 {
24 this(new ObservableCollection());
25 }
26
27 /***
28 * Constructs a panel based on an observable list of items IconViews.
29 * @param olist
30 */
31 public IconPanel(ObservableCollection olist)
32 {
33 super(
34 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
35 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
36 content = new IconPanelContent(this, olist);
37 setBackground(Color.white);
38 setViewportView(content);
39 getViewport().addChangeListener(content);
40 }
41
42 /***
43 * Selects the first item in the panel.
44 *
45 */
46 public void selectFirst()
47 {
48 content.selectFirst();
49 }
50
51 /***
52 * Refreshes the panel.
53 */
54 public void refresh()
55 {
56 content.refresh();
57 repaint();
58 }
59
60 public void repaint()
61 {
62 super.repaint();
63 if (content != null)
64 content.repaint();
65 }
66
67 /***
68 * Children should implement this in order to get a view from the model.
69 * @param model model associated with the view.
70 * @param the icon panel (the view needs to refresh the panel as well)
71 * @return the view object that can be set in this IconPanel.
72 */
73 public abstract Object getViewFromModel(Object model, IconPanel ipanel);
74
75 /***
76 * Clean up the view when it is discarded. It should remove all listeners
77 * so they won't leak.
78 * @param view the view to remove.
79 */
80 public abstract void removeView(Object view);
81
82 /***
83 * Decorates the first view if necessary. Children can override this
84 * method to adds its own decoration.
85 */
86 public Component decorateFirstView(Component comp)
87 {
88 return comp;
89 }
90
91 /***
92 * Decorates the second view if necessary. Children can override this
93 * method to adds its own decoration. By default this returns the component
94 * that got passed into this.
95 * @param comp component to decorate.
96 */
97 public Component decorateSecondView(Component comp)
98 {
99 return comp;
100 }
101 }
This page was automatically generated by Maven