forked from ome/openmicroscopy
/
MetadataViewerUI.java
369 lines (332 loc) · 11.3 KB
/
MetadataViewerUI.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*
* org.openmicroscopy.shoola.agents.metadata.view.MetadataViewerUI
*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2008 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*------------------------------------------------------------------------------
*/
package org.openmicroscopy.shoola.agents.metadata.view;
//Java imports
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSplitPane;
//Third-party libraries
//Application-internal dependencies
import org.openmicroscopy.shoola.agents.metadata.IconManager;
import org.openmicroscopy.shoola.agents.util.ViewedByItem;
import org.openmicroscopy.shoola.agents.util.ViewerSorter;
import org.openmicroscopy.shoola.env.rnd.RndProxyDef;
import org.openmicroscopy.shoola.env.ui.TopWindow;
import org.openmicroscopy.shoola.util.ui.TitlePanel;
import pojos.DatasetData;
import pojos.ExperimenterData;
import pojos.ImageData;
import pojos.ProjectData;
/**
* The View.
*
* @author Jean-Marie Burel
* <a href="mailto:j.burel@dundee.ac.uk">j.burel@dundee.ac.uk</a>
* @author Donald MacDonald
* <a href="mailto:donald@lifesci.dundee.ac.uk">donald@lifesci.dundee.ac.uk</a>
* @version 3.0
* <small>
* (<b>Internal version:</b> $Revision: $Date: $)
* </small>
* @since OME3.0
*/
class MetadataViewerUI
extends TopWindow
implements PropertyChangeListener
{
/** The text corresponding to the creation of a <code>Project</code>. */
private static final String PROJECT_MSG = "Project";
/** The text corresponding to the creation of a <code>Dataset</code>. */
private static final String DATASET_MSG = "Dataset";
/** The text corresponding to the creation of a <code>Image</code>. */
private static final String IMAGE_MSG = "Image";
/** The title of the dialog. */
private static final String TITLE = "Add metadata";
/** The description of the dialog. */
private static final String DESCRIPTION = "Add comments, tags, etc., " +
"to the selected items.";
/** Reference to the Control. */
private MetadataViewerControl controller;
/** Reference to the Model. */
private MetadataViewerModel model;
/** The component hosting the UI components. */
private JPanel uiDelegate;
/** The header of the component. */
private TitlePanel titlePanel;
/**
* The source invoking the menu displaying the list of users
* who viewed the image.
*/
private Component source;
/**
* The location where to pop up the menu displaying the list of users
* who viewed the image.
*/
private Point location;
/** The menu displaying the user who viewed the image. */
private JPopupMenu viewedByMenu;
/** The item used to display the thumbnails. */
private JMenuItem thumbnailsMenuItem;
/**
* Returns the message corresponding to the <code>DataObject</code>.
*
* @return See above
*/
private String getMessage()
{
Class nodeType = model.getRefObject().getClass();
if (nodeType.equals(ProjectData.class)) return PROJECT_MSG;
else if (nodeType.equals(DatasetData.class)) return DATASET_MSG;
else if (nodeType.equals(ImageData.class)) return IMAGE_MSG;
return "";
}
/** Builds and lays out the GUI. */
private void buildGUI()
{
IconManager icons = IconManager.getInstance();
titlePanel = new TitlePanel(TITLE, DESCRIPTION,
icons.getIcon(IconManager.METADATA_48));
Container c = getContentPane();
c.setLayout(new BorderLayout(0, 0));
//c.add(model.getEditor().getUI());
JSplitPane pane = new JSplitPane();
pane.setResizeWeight(1.0);
pane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
pane.setOneTouchExpandable(true);
pane.setContinuousLayout(true);
pane.setLeftComponent(model.getEditor().getUI());
//pane.setRightComponent(model.getBrowser().getUI());
uiDelegate = new JPanel();
uiDelegate.setLayout(new BorderLayout(0, 0));
uiDelegate.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
//uiDelegate.add(titlePanel, BorderLayout.NORTH);
uiDelegate.add(model.getEditor().getUI(), BorderLayout.CENTER);
c.add(titlePanel, BorderLayout.NORTH);
c.add(uiDelegate, BorderLayout.CENTER);
}
/**
* Creates a new instance.
* The
* {@link #initialize(MetadataViewerControl, MetadataViewerModel) initialize}
* method should be called straight after to link this View
* to the Controller.
*
* @param title The window title.
*/
MetadataViewerUI()
{
super("");
}
/**
* Links this View to its Controller and Model.
*
* @param controller Reference to the Control.
* Mustn't be <code>null</code>.
* @param model Reference to the Model.
* Mustn't be <code>null</code>.
*/
void initialize(MetadataViewerControl controller, MetadataViewerModel model)
{
if (controller == null) throw new NullPointerException("No control.");
if (model == null) throw new NullPointerException("No model.");
this.controller = controller;
this.model = model;
buildGUI();
setName("metadata viewer window");
}
/** Updates display when the new root node is set. */
void setRootObject()
{
String message = getMessage();
titlePanel.setTitle(message);
titlePanel.setSubtitle("Edit the "+ message.toLowerCase()+": "+
model.getRefObjectName());
uiDelegate.revalidate();
uiDelegate.repaint();
viewedByMenu = null;
}
/**
* Returns the UI.
*
* @return See above.
*/
JComponent getUI() { return uiDelegate; }
/**
* Indicates that the color of the passed channel has changed.
*
* @param index The index of the channel.
*/
void onChannelColorChanged(int index)
{
model.getEditor().onChannelColorChanged(index);
}
/**
* Sets the location and the source where to pop up the menu.
*
* @param source The source to set.
* @param location The location to set.
*/
void setLocationAndSource(Component source, Point location)
{
this.source = source;
this.location = location;
}
/**
* Displays the menu displaying the list of users who viewed the image.
*
* @param source The component invoking the loading.
* @param location The location of the mouse pressed.
*/
void viewedBy(Component source, Point location)
{
if (viewedByMenu == null) {
viewedByMenu = new JPopupMenu();
}
viewedByMenu.removeAll();
Map m = model.getViewedBy();
ViewerSorter sorter = new ViewerSorter();
List list = sorter.sort(m.keySet());
Iterator i = list.iterator();
ViewedByItem item ;
ExperimenterData exp;
while (i.hasNext()) {
exp = (ExperimenterData) i.next();
item = new ViewedByItem(exp, (RndProxyDef) m.get(exp));
item.addPropertyChangeListener(
ViewedByItem.VIEWED_BY_PROPERTY, this);
viewedByMenu.add(item);
}
if (list.size() == 0) {
thumbnailsMenuItem = new JMenuItem("No settings saved");
thumbnailsMenuItem.setToolTipText("No other users " +
"saved the rendering settings.");
} else {
IconManager icons = IconManager.getInstance();
thumbnailsMenuItem = new JMenuItem("Show thumbnails");
thumbnailsMenuItem.setIcon(icons.getIcon(
IconManager.PREVIEW_THUMBNAILS_32));
thumbnailsMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
showViewedBy();
}
});
}
viewedByMenu.add(thumbnailsMenuItem);
if (source != null && source.isVisible()) {
viewedByMenu.show(source, location.x, location.y);
}
}
/** Displays all the thumbnails. */
private void showViewedBy()
{
if (viewedByMenu == null) return;
ViewedByItem item, itemNew;
Component comp;
BufferedImage img;
Component[] components = viewedByMenu.getComponents();
List<ViewedByItem> items = new ArrayList<ViewedByItem>();
for (int i = 0; i < components.length; i++) {
comp = components[i];
if (comp instanceof ViewedByItem) {
item = (ViewedByItem) comp;
img = item.getImage();
if (img != null) {
item.setImage(img);
itemNew = new ViewedByItem(item.getExperimenter(),
item.getRndDef(), false);
itemNew.setImage(img);
itemNew.addPropertyChangeListener(
ViewedByItem.VIEWED_BY_PROPERTY, this);
items.add(itemNew);
}
}
}
model.getEditor().getRenderer().loadRndSettings(true, items);
}
/**
* Sets the thumbnails.
*
* @param thumbnails The value to set.
*/
void setThumbnails(Map<Long, BufferedImage> thumbnails)
{
if (viewedByMenu == null) return;
Component[] components = viewedByMenu.getComponents();
Component comp;
ViewedByItem item, itemNew;
BufferedImage img;
List<ViewedByItem> items = new ArrayList<ViewedByItem>();
for (int i = 0; i < components.length; i++) {
comp = components[i];
if (comp instanceof ViewedByItem) {
item = (ViewedByItem) comp;
img = thumbnails.get(item.getExperimenterID());
if (img != null) {
item.setImage(img);
itemNew = new ViewedByItem(item.getExperimenter(),
item.getRndDef(), false);
itemNew.setImage(img);
itemNew.addPropertyChangeListener(
ViewedByItem.VIEWED_BY_PROPERTY, this);
items.add(itemNew);
}
}
}
if (items != null) showViewedBy();
thumbnailsMenuItem.setEnabled(items.size() > 0);
model.getEditor().getRenderer().loadRndSettings(true, null);
}
/**
* Sets the rendering settings.
* @see PropertyChangeListener#propertyChange(PropertyChangeEvent)
*/
public void propertyChange(PropertyChangeEvent evt)
{
if (ViewedByItem.VIEWED_BY_PROPERTY.equals(
evt.getPropertyName()))
model.applyRenderingSettings(
(RndProxyDef) evt.getNewValue());
}
/**
* Overridden so the pack method is not invoked and the component is
* not displayed on screen.
*/
public void setOnScreen() {}
}