package osp.ui; import java.awt.BorderLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JDialog; import jsky.image.BasicImageReadableProcessor; import jsky.image.gui.OSPE_ImageCutLevelsPanel; import osp.Image; /** * Dialog to display and to modify image Cuts Levels. * Call OSPE_imageCutlevel panel implemented from the JSky's imageCutLevel one. * * @author SB * Modifications EB, JMG */ public class OSPE_ImageCutLevelsDialog extends JDialog { private static final long serialVersionUID = 1L; private BasicImageReadableProcessor navigatorImageDisplay; private OSPE_ImageCutLevelsPanel imageCutLevelsPanel; private Image image; /** * Constructor of OSPE_ImageCutLevelsPanel. * * This is to change the image's cuts levels and to save them at window's * close action * @param ospe_NavigatorImageDisplay */ public OSPE_ImageCutLevelsDialog(OSPE_NavigatorImageDisplay ospe_NavigatorImageDisplay) { navigatorImageDisplay = ospe_NavigatorImageDisplay; this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); // On close, if the image's cuts levels have changed, save them this.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { saveParamCuts(); super.windowClosed(e); } }); } public void saveParamCuts() { double hiIm, loIm; // get the original Cuts levels. if (image != null) { hiIm = image.getHighCut(); loIm = image.getLowCut(); // Get the current cuts levels on display double highCutLevel = navigatorImageDisplay.getImageProcessor().getHighCut(); double lowCutLevel = navigatorImageDisplay.getImageProcessor().getLowCut(); imageCutLevelsPanel.setValues(lowCutLevel, highCutLevel); imageCutLevelsPanel.updateCutLevels(); if ((hiIm != highCutLevel) || (loIm != lowCutLevel)) { // save the change image.setHighCut(highCutLevel); image.setLowCut(lowCutLevel); image.cutsChanged = true; } } } /** * Create the cut levels for the display in the OSPE_NavigatorImageDisplay * interface. * * @param navImageDisplay * : OSPE_NavigatorImageDisplay, the display windows for the * image displayed. * @param im * : Image, the image displayed. * */ public void setDisplay(Image image) { this.image = image; if (imageCutLevelsPanel !=null){ this.getContentPane().remove(imageCutLevelsPanel); } if (image == null) { imageCutLevelsPanel = null; } else { imageCutLevelsPanel = new OSPE_ImageCutLevelsPanel(navigatorImageDisplay, this); this.getContentPane().add(imageCutLevelsPanel, BorderLayout.CENTER); pack(); setVisible(true); updateCutLevels(image.getLowCut(), image.getHighCut()); } } /** * Test if the cuts levels panel is displayed. * * @return true/false */ public boolean hasDisplay() { return imageCutLevelsPanel != null; } public void updateCutLevels(double lo, double hi) { if (hasDisplay()){ imageCutLevelsPanel.setValues(lo, hi); imageCutLevelsPanel.updateCutLevels(); } } public Image getImage(){ return image; } }