/** * Adds the specified files to the list of import data. * * @param files The files to import. */ private void insertFiles(Map<File, StatusLabel> files) { if (files == null || files.size() == 0) { statusLabel.setText("No files to import."); return; } components = new HashMap<File, FileImportComponent>(); totalFiles = files.size(); String text = "Importing " + totalFiles + " file"; if (totalFiles > 1) text += "s"; statusLabel.setText(text); Entry entry; Iterator i = files.entrySet().iterator(); FileImportComponent c; JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); int index = 0; p.setBorder(BorderFactory.createLineBorder(Color.BLACK)); File f; DatasetData d = dataset; Object node = refNode; if (folderAsContainer) { node = null; d = new DatasetData(); d.setName(file.getName()); } while (i.hasNext()) { entry = (Entry) i.next(); f = (File) entry.getKey(); c = new FileImportComponent(f, folderAsContainer, browsable, group, singleGroup); if (f.isFile()) { c.setLocation(data, d, node); c.setParent(this); } c.showContainerLabel(showContainerLabel); c.setType(getType()); attachListeners(c); c.setStatusLabel((StatusLabel) entry.getValue()); if (index % 2 == 0) c.setBackground(UIUtilities.BACKGROUND_COLOUR_EVEN); else c.setBackground(UIUtilities.BACKGROUND_COLOUR_ODD); components.put((File) entry.getKey(), c); p.add(c); index++; } removeAll(); pane = EditorUtil.createTaskPane(""); pane.setCollapsed(false); setNumberOfImport(); IconManager icons = IconManager.getInstance(); pane.setIcon(icons.getIcon(IconManager.DIRECTORY)); Font font = pane.getFont(); pane.setFont(font.deriveFont(font.getStyle(), font.getSize() - 2)); pane.add(p); double[][] size = {{TableLayout.FILL}, {TableLayout.PREFERRED}}; setLayout(new TableLayout(size)); add(pane, "0, 0"); validate(); repaint(); }
/** Deletes the image that was imported but cannot be viewed. */ private void deleteImage() { List<DeletableObject> l = new ArrayList<DeletableObject>(); if (image instanceof ThumbnailData) { l.add(new DeletableObject(((ThumbnailData) image).getImage())); } else if (image instanceof ImageData) { l.add(new DeletableObject((DataObject) image)); } if (l.size() == 0) return; IconManager icons = IconManager.getInstance(); DeleteActivityParam p = new DeleteActivityParam(icons.getIcon(IconManager.APPLY_22), l); p.setFailureIcon(icons.getIcon(IconManager.DELETE_22)); UserNotifier un = MeasurementAgent.getRegistry().getUserNotifier(); // TODO: review // un.notifyActivity(p); // the row enabled deleteButton.setEnabled(false); errorBox.setEnabled(false); fileNameLabel.setEnabled(false); resultLabel.setEnabled(false); imageLabel.setEnabled(false); }
/** Initializes the components. */ private void initComponents() { reimportedLabel = new JLabel("Reimported"); reimportedLabel.setVisible(false); showContainerLabel = true; adapter = new MouseAdapter() { /** * Views the image. * * @see MouseListener#mousePressed(MouseEvent) */ public void mousePressed(MouseEvent e) { if (e.getClickCount() == 1) { ViewImage evt; int plugin = ImporterAgent.runAsPlugin(); if (image instanceof ThumbnailData) { ThumbnailData data = (ThumbnailData) image; EventBus bus = ImporterAgent.getRegistry().getEventBus(); if (data.getImage() != null) { evt = new ViewImage( new SecurityContext(group.getId()), new ViewImageObject(data.getImage()), null); evt.setPlugin(plugin); bus.post(evt); } } else if (image instanceof ImageData) { ImageData data = (ImageData) image; EventBus bus = ImporterAgent.getRegistry().getEventBus(); if (data != null) { evt = new ViewImage( new SecurityContext(group.getId()), new ViewImageObject(data), null); evt.setPlugin(plugin); bus.post(evt); } } else if (image instanceof PlateData) { firePropertyChange(BROWSE_PROPERTY, null, image); } } } }; setLayout(new FlowLayout(FlowLayout.LEFT)); busyLabel = new JXBusyLabel(SIZE); busyLabel.setVisible(false); busyLabel.setBusy(false); cancelButton = new JLabel("Cancel"); cancelButton.setForeground(UIUtilities.HYPERLINK_COLOR); cancelButton.addMouseListener( new MouseAdapter() { /** * Browses the object the image. * * @see MouseListener#mousePressed(MouseEvent) */ public void mousePressed(MouseEvent e) { Object src = e.getSource(); if (e.getClickCount() == 1 && src instanceof JLabel) { cancel(true); } } }); cancelButton.setVisible(true); browseButton = new JLabel(BROWSE_CONTAINER_TEXT); if (browsable) { browseButton.setToolTipText(BROWSE_CONTAINER_TOOLTIP); browseButton.setForeground(UIUtilities.HYPERLINK_COLOR); browseButton.addMouseListener( new MouseAdapter() { /** * Browses the object the image. * * @see MouseListener#mousePressed(MouseEvent) */ public void mousePressed(MouseEvent e) { Object src = e.getSource(); if (e.getClickCount() == 1 && src instanceof JLabel) { browse(); } } }); } browseButton.setVisible(false); containerLabel = new JLabel(); containerLabel.setVisible(false); groupLabel = new JLabel("Group: " + group.getName()); groupLabel.setVisible(false); namePane = new JPanel(); namePane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); IconManager icons = IconManager.getInstance(); Icon icon; if (file.isFile()) icon = icons.getIcon(IconManager.IMAGE); else icon = icons.getIcon(IconManager.DIRECTORY); imageLabel = new ThumbnailLabel(icon); imageLabel.addPropertyChangeListener(this); imageLabels = new ArrayList<ThumbnailLabel>(); ThumbnailLabel label; for (int i = 0; i < NUMBER; i++) { label = new ThumbnailLabel(); label.setVisible(false); imageLabels.add(label); } fileNameLabel = new JLabel(file.getName()); namePane.add(imageLabel); Iterator<ThumbnailLabel> j = imageLabels.iterator(); while (j.hasNext()) { namePane.add(j.next()); } namePane.add(Box.createHorizontalStrut(4)); namePane.add(fileNameLabel); namePane.add(Box.createHorizontalStrut(10)); resultLabel = new JLabel(); // control = busyLabel; errorBox = new JCheckBox("Mark to Send"); errorBox.setOpaque(false); errorBox.setToolTipText("Mark the file to send to the development " + "team."); errorBox.setVisible(false); errorBox.setSelected(true); errorButton = new JButton("Failed"); errorButton.setForeground(ERROR_COLOR); errorButton.addMouseListener( new MouseAdapter() { /** * Displays the error dialog at the specified location. * * @see MouseAdapter#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { showError(e.getPoint()); } }); errorButton.setVisible(false); statusLabel = new StatusLabel(); statusLabel.addPropertyChangeListener(this); deleteButton = new JButton(icons.getIcon(IconManager.DELETE)); deleteButton.setActionCommand("" + DELETE_ID); deleteButton.setToolTipText("Delete the image"); UIUtilities.unifiedButtonLookAndFeel(deleteButton); deleteButton.setVisible(false); image = null; }