1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dishevelled.curate.impl;
25
26 import java.awt.BorderLayout;
27 import java.awt.event.MouseAdapter;
28 import java.awt.event.MouseEvent;
29
30 import java.util.Collection;
31 import java.util.Iterator;
32
33 import javax.swing.JCheckBoxMenuItem;
34 import javax.swing.JPanel;
35 import javax.swing.JPopupMenu;
36
37 import javax.swing.border.EmptyBorder;
38
39 import org.dishevelled.curate.CullView;
40
41 import org.dishevelled.iconbundle.tango.TangoProject;
42
43 import org.dishevelled.identify.IdToolBar;
44
45
46
47
48
49
50
51
52 public final class CullDialog<E>
53 extends AbstractCurateDialog
54 implements CullView<E>
55 {
56
57 private final CullPanel<E> cullPanel;
58
59
60 private final IdToolBar toolBar;
61
62
63
64
65
66 public CullDialog()
67 {
68 cullPanel = new CullPanel<E>();
69 toolBar = new IdToolBar();
70 toolBar.add(cullPanel.getRemoveAction());
71 toolBar.add(cullPanel.getRemoveAllAction());
72 toolBar.addSeparator();
73 toolBar.add(cullPanel.getStartAssistAction());
74 toolBar.add(cullPanel.getStopAssistAction());
75 toolBar.displayIcons();
76 toolBar.setFloatable(false);
77 toolBar.setIconSize(TangoProject.SMALL);
78
79 final JPopupMenu toolBarContextMenu = new JPopupMenu();
80 for (Iterator<?> displayMenuItems = toolBar.getDisplayMenuItems().iterator(); displayMenuItems.hasNext(); )
81 {
82 JCheckBoxMenuItem displayMenuItem = (JCheckBoxMenuItem) displayMenuItems.next();
83 toolBarContextMenu.add(displayMenuItem);
84 }
85 toolBarContextMenu.addSeparator();
86 for (Iterator<?> iconSizeMenuItems = toolBar.getDefaultIconSizeMenuItems().iterator(); iconSizeMenuItems.hasNext(); )
87 {
88 JCheckBoxMenuItem iconSizeMenuItem = (JCheckBoxMenuItem) iconSizeMenuItems.next();
89 toolBarContextMenu.add(iconSizeMenuItem);
90 }
91 toolBar.addMouseListener(new MouseAdapter()
92 {
93
94 public void mousePressed(final MouseEvent event)
95 {
96 showContextMenu(event);
97 }
98
99
100 public void mouseReleased(final MouseEvent event)
101 {
102 showContextMenu(event);
103 }
104
105
106
107
108
109
110 private void showContextMenu(final MouseEvent event)
111 {
112 if (event.isPopupTrigger())
113 {
114 toolBarContextMenu.show(event.getComponent(), event.getX(), event.getY());
115 }
116 }
117 });
118
119 JPanel contentPane = (JPanel) getContentPane();
120 contentPane.setLayout(new BorderLayout());
121 cullPanel.setBorder(new EmptyBorder(20, 10, 20, 10));
122 JPanel buttonPanel = createButtonPanel();
123 buttonPanel.setBorder(new EmptyBorder(0, 10, 10, 10));
124
125 contentPane.add("North", toolBar);
126 contentPane.add("Center", cullPanel);
127 contentPane.add("South", buttonPanel);
128 contentPane.requestFocus();
129 }
130
131
132
133 public void setInput(final Collection<E> input)
134 {
135 cullPanel.setInput(input);
136 }
137
138
139 public Collection<E> getRemaining()
140 {
141 return cullPanel.getRemaining();
142 }
143
144
145 public Collection<E> getRemoved()
146 {
147 return cullPanel.getRemoved();
148 }
149
150
151 protected void cancel()
152 {
153
154 setVisible(false);
155 }
156
157
158 protected void help()
159 {
160
161 }
162
163
164 protected void ok()
165 {
166
167 setVisible(false);
168 }
169 }