/** * Sets the result of the import. * * @param status Flag indicating the status of the import. * @param image The image. */ public void setStatus(boolean status, Object image) { this.image = image; busyLabel.setBusy(false); busyLabel.setVisible(false); cancelButton.setVisible(false); importCount++; if (parent != null) parent.increaseNumberOfImport(); if (image instanceof ImageData) { ImageData img = (ImageData) image; Exception error = null; try { img.getDefaultPixels(); } catch (Exception e) { error = e; toReImport = true; } if (error != null) { exception = error; fileNameLabel.setForeground(ERROR_COLOR); resultLabel.setVisible(false); errorButton.setToolTipText(UIUtilities.formatExceptionForToolTip(error)); errorButton.setVisible(true); errorBox.setVisible(true); errorBox.addChangeListener(this); deleteButton.setVisible(true); deleteButton.addActionListener(this); } else { imageLabel.setData(img); resultLabel.setText(VIEW_TEXT); resultLabel.setForeground(UIUtilities.HYPERLINK_COLOR); if (browsable) resultLabel.setToolTipText(ThumbnailLabel.IMAGE_LABEL_TOOLTIP); else imageLabel.setToolTipText(""); resultLabel.setVisible(true); fileNameLabel.addMouseListener(adapter); resultLabel.addMouseListener(adapter); addMouseListener(adapter); showContainerLabel = (dataset != null || containerFromFolder != null); if (noContainer) { browseButton.setVisible(false); containerLabel.setVisible(false); } else { browseButton.setVisible(showContainerLabel); containerLabel.setVisible(showContainerLabel); } groupLabel.setVisible(!singleGroup); } } else if (image instanceof ThumbnailData) { ThumbnailData thumbnail = (ThumbnailData) image; groupLabel.setVisible(!singleGroup); if (thumbnail.isValidImage()) { imageLabel.setData(thumbnail); statusLabel.setVisible(false); fileNameLabel.addMouseListener(adapter); addMouseListener(adapter); resultLabel.setText(VIEW_TEXT); resultLabel.setForeground(UIUtilities.HYPERLINK_COLOR); if (browsable) resultLabel.setToolTipText(ThumbnailLabel.IMAGE_LABEL_TOOLTIP); else imageLabel.setToolTipText(""); resultLabel.setVisible(false); if (thumbnail.requirePyramid() != null && thumbnail.requirePyramid().booleanValue()) { imageLabel.setToolTipText(PYRAMID_TEXT); resultLabel.setVisible(true); resultLabel.addMouseListener(adapter); } showContainerLabel = (dataset != null || containerFromFolder != null); if (noContainer) { browseButton.setVisible(false); containerLabel.setVisible(false); } else { browseButton.setVisible(showContainerLabel); containerLabel.setVisible(showContainerLabel); } } else { statusLabel.setVisible(false); fileNameLabel.setForeground(ERROR_COLOR); resultLabel.setText(IMAGE_CREATION_ERROR_TEXT); resultLabel.setToolTipText(UIUtilities.formatExceptionForToolTip(thumbnail.getError())); resultLabel.setVisible(true); errorButton.setVisible(false); errorBox.setVisible(false); groupLabel.setVisible(!singleGroup); } } else if (image instanceof PlateData) { imageLabel.setData((PlateData) image); statusLabel.setVisible(false); groupLabel.setVisible(!singleGroup); if (browsable) { resultLabel.setText(BROWSE_TEXT); resultLabel.setForeground(UIUtilities.HYPERLINK_COLOR); resultLabel.setToolTipText(ThumbnailLabel.PLATE_LABEL_TOOLTIP); resultLabel.setVisible(true); } fileNameLabel.addMouseListener(adapter); resultLabel.addMouseListener(adapter); showContainerLabel = containerObject instanceof ScreenData; if (noContainer || !browsable) { browseButton.setVisible(false); containerLabel.setVisible(false); } else { browseButton.setVisible(showContainerLabel); containerLabel.setVisible(showContainerLabel); } } else if (image instanceof List) { statusLabel.setVisible(false); groupLabel.setVisible(!singleGroup); List list = (List) image; int m = list.size(); imageLabel.setData(list.get(0)); list.remove(0); ThumbnailLabel label = imageLabels.get(0); label.setVisible(true); label.setData(list.get(0)); list.remove(0); if (list.size() > 0) { label = imageLabels.get(1); label.setVisible(true); label.setData(list.get(0)); list.remove(0); int n = statusLabel.getSeriesCount() - m; if (n > 0) { label = imageLabels.get(2); Font f = label.getFont(); label.setFont(f.deriveFont(f.getStyle(), f.getSize() - 2)); label.setVisible(true); String value = "... " + n + " more"; label.setText(value); } } resultLabel.setVisible(true); showContainerLabel = true; if (noContainer) { browseButton.setVisible(false); containerLabel.setVisible(false); } else { browseButton.setVisible(showContainerLabel); containerLabel.setVisible(showContainerLabel); } // control = resultLabel; } else if (image instanceof Boolean) { if (!statusLabel.isMarkedAsCancel()) { cancelButton.setVisible(false); if (statusLabel.isMarkedAsDuplicate()) { statusLabel.setVisible(false); setStatusText(StatusLabel.DUPLICATE); } else { statusLabel.setVisible(false); setStatusText(FILE_NOT_VALID_TEXT); } } else resultLabel.setText(""); } else { if (!status) { statusLabel.setVisible(false); resultLabel.setToolTipText(""); resultLabel.setEnabled(false); if (image == null) setStatusText(null); else if (image instanceof String) { setStatusText((String) image); } else if (image instanceof ImportException) { ImportException ie = (ImportException) image; fileNameLabel.setForeground(ERROR_COLOR); resultLabel.setVisible(false); toReImport = true; errorButton.setToolTipText(UIUtilities.formatExceptionForToolTip(ie)); exception = ie; errorButton.setVisible(false); int s = ie.getStatus(); if (s == ImportException.COMPRESSION) { resultLabel.setVisible(true); resultLabel.setText(COMPRESSION_ERROR_TEXT); resultLabel.setToolTipText(UIUtilities.formatExceptionForToolTip(ie)); } else if (s == ImportException.MISSING_LIBRARY) { resultLabel.setVisible(true); resultLabel.setText(MISSING_LIB_ERROR_TEXT); resultLabel.setToolTipText(UIUtilities.formatExceptionForToolTip(ie)); } else if (s == ImportException.FILE_ON_TAPE) { resultLabel.setVisible(true); resultLabel.setText(FILE_ON_TAPE_ERROR_TEXT); resultLabel.setToolTipText(UIUtilities.formatExceptionForToolTip(ie)); } else if (s == ImportException.NO_SPACE) { resultLabel.setVisible(true); resultLabel.setText(NO_SPACE_ERROR_TEXT); resultLabel.setToolTipText(UIUtilities.formatExceptionForToolTip(ie)); } else { errorButton.setVisible(true); errorBox.setVisible(true); errorBox.addChangeListener(this); } cancelButton.setVisible(false); } } } repaint(); }
/** 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; }