/** * Listens to property fired by the <code>StatusLabel</code>. * * @see PropertyChangeListener#propertyChange(PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); if (StatusLabel.FILES_SET_PROPERTY.equals(name)) { if (isCancelled()) { statusLabel.setText(CANCEL_TEXT); busyLabel.setBusy(false); busyLabel.setVisible(false); return; } Map<File, StatusLabel> files = (Map<File, StatusLabel>) evt.getNewValue(); insertFiles((Map<File, StatusLabel>) evt.getNewValue()); firePropertyChange(IMPORT_FILES_NUMBER_PROPERTY, null, files.size()); } else if (StatusLabel.FILE_IMPORT_STARTED_PROPERTY.equals(name)) { StatusLabel sl = (StatusLabel) evt.getNewValue(); if (sl == statusLabel && busyLabel != null) { busyLabel.setBusy(true); busyLabel.setVisible(true); cancelButton.setVisible(sl.isCancellable()); } } else if (StatusLabel.CANCELLABLE_IMPORT_PROPERTY.equals(name)) { StatusLabel sl = (StatusLabel) evt.getNewValue(); cancelButton.setVisible(sl.isCancellable()); } else if (StatusLabel.FILE_IMPORTED_PROPERTY.equals(name)) { Object[] results = (Object[]) evt.getNewValue(); File f = (File) results[0]; if (f.getAbsolutePath().equals(file.getAbsolutePath())) { setStatus(false, results[1]); if (f.isFile()) { if (hasImportFailed()) firePropertyChange(IMPORT_STATUS_CHANGE_PROPERTY, null, FAILURE); else if (isCancelled()) firePropertyChange(IMPORT_STATUS_CHANGE_PROPERTY, null, PARTIAL); else firePropertyChange(IMPORT_STATUS_CHANGE_PROPERTY, null, SUCCESS); } } } else if (StatusLabel.FILE_RESET_PROPERTY.equals(name)) { file = (File) evt.getNewValue(); fileNameLabel.setText(file.getName()); } else if (ThumbnailLabel.BROWSE_PLATE_PROPERTY.equals(name)) { firePropertyChange(BROWSE_PROPERTY, evt.getOldValue(), evt.getNewValue()); } else if (StatusLabel.CONTAINER_FROM_FOLDER_PROPERTY.equals(name)) { containerFromFolder = (DataObject) evt.getNewValue(); if (containerFromFolder instanceof DatasetData) { containerLabel.setText(TEXT_IMPORTED); browseButton.setText(((DatasetData) containerFromFolder).getName()); containerObject = containerFromFolder; } else if (containerFromFolder instanceof ScreenData) { containerLabel.setText(TEXT_IMPORTED); browseButton.setText(((ScreenData) containerFromFolder).getName()); containerObject = containerFromFolder; } } else if (StatusLabel.NO_CONTAINER_PROPERTY.equals(name)) { containerLabel.setText(""); noContainer = true; } else if (StatusLabel.DEBUG_TEXT_PROPERTY.equals(name)) { firePropertyChange(name, evt.getOldValue(), evt.getNewValue()); } }
public BusyGlass() { JXBusyLabel busy = new JXBusyLabel(); add(busy); busy.setBusy(true); setAlpha(0.7f); setOpaque(true); setVisible(false); setBackground(Color.gray); // setBackgroundPainter(new Gr); }
/** * Indicates on-going loading or not. * * @param load Pass <code>true</code> to load, <code>false</code> otherwise. */ public void notifyLoading(boolean load) { removeAll(); if (load) { JXBusyLabel label = new JXBusyLabel(SIZE); label.setBusy(true); label.setEnabled(true); add(label); add(cancelButton); } else { // resultsButton.setEnabled(false); add(resultsButton); add(menuButton); } revalidate(); repaint(); }
/** * Overridden to make sure that all the components have the correct background. * * @see JPanel#setBackground(Color) */ public void setBackground(Color color) { if (busyLabel != null) busyLabel.setBackground(color); if (namePane != null) { namePane.setBackground(color); for (int i = 0; i < namePane.getComponentCount(); i++) namePane.getComponent(i).setBackground(color); } super.setBackground(color); }
/** * Indicates that the file will not be imported. * * @param fire Pass <code>true</code> to fire a property, <code>false</code> otherwise. */ private void cancel(boolean fire) { if (busyLabel.isBusy() && !statusLabel.isCancellable()) return; String s = CANCEL_TEXT; if (file.isDirectory()) { busyLabel.setBusy(true); busyLabel.setVisible(true); s += " waiting on scanning to finish"; } else { busyLabel.setBusy(false); busyLabel.setVisible(false); } statusLabel.setText(s); statusLabel.markedAsCancel(); cancelButton.setEnabled(false); cancelButton.setVisible(false); if (image == null && file.isFile()) firePropertyChange(IMPORT_STATUS_CHANGE_PROPERTY, null, PARTIAL); if (fire) firePropertyChange(CANCEL_IMPORT_PROPERTY, null, this); }
private void blockLoad() { Runnable acaoOk = () -> { glasses.setVisible(false); glasses = new Carregar(); }; // ---- USAR A INDICAÇÃO DE PROGRESSO. JXBusyLabel busy = new JXBusyLabel(); busy.setBusy(true); glasses = new Carregar(busy); // ----------------------------------- // ---- USAR O PAINEL DE LOGIN. // PainelLogin painelLogin = new PainelLogin(acaoOk); // glass = new BlockPanel(painelLogin); // ----------------------------------- setGlassPane(glasses); glasses.setVisible(true); new Thread( new Runnable() { @Override public void run() { for (int i = 0; i < 5; i++) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } glasses.setVisible(false); } }) .start(); }
/** * 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; }