/*
* DicomDeviseImageParamsDlg.java
*
* Created on October 3, 2008, 3:55 PM
*/
package clips.dicom.panels;
import clips.dicom.Image.DICOMImage;
import clips.dicom.Image.DICOMWindowParam;
import clips.dicom.dicombaseclass.DICOMDeviceParam;
import clips.dicom.utils.Pair;
/**
*
* @author finder
*/
public class DicomDeviseImageParamsDlg extends javax.swing.JDialog {
/** A return status code - returned if Cancel button has been pressed */
public static final int RET_CANCEL = 0;
/** A return status code - returned if OK button has been pressed */
public static final int RET_OK = 1;
public static final int EXPLICT = 0;
public static final int AUTO = 1;
public static final int OFFSET = 2;
public static final int AUTO_AND_OFFSET = 3;
public static final int AUTO_IF_NOT_SET = 4;
DICOMDeviceParam param;
DICOMImage img;
/** Creates new form DicomDeviseImageParamsDlg
* @param parent
* @param param
* @param img
*/
public DicomDeviseImageParamsDlg(java.awt.Frame parent, DICOMDeviceParam param, DICOMImage img) {
super(parent, true);
initComponents();
this.param = param;
this.img = img;
switch (param.getWindowType()){
case auto:
if (Math.abs(param.getWindowBegin() - DICOMDeviceParam.AUTO_PROCENTAGE) < 0.001d
&& Math.abs(param.getWindowEnd() - DICOMDeviceParam.AUTO_PROCENTAGE) < 0.001d) {
jComboBox1.setSelectedIndex(AUTO);
}
else {
jComboBox1.setSelectedIndex(AUTO_AND_OFFSET);
}
break;
case autoIfNotSet:
jComboBox1.setSelectedIndex(AUTO_IF_NOT_SET);
break;
case expict:
jComboBox1.setSelectedIndex(EXPLICT);
break;
case modify:
jComboBox1.setSelectedIndex(OFFSET);
break;
}
}
/** @return the return status of this dialog - one of RET_OK or RET_CANCEL */
public int getReturnStatus() {
return returnStatus;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jTextPane1 = new javax.swing.JTextPane();
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
jComboBox1 = new javax.swing.JComboBox();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Настройки яркости и контраста");
setModal(true);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
jTextPane1.setBackground(getBackground());
jTextPane1.setBorder(null);
jTextPane1.setEditable(false);
jTextPane1.setText("Выберете метод по которому будут устанавливаться яркость и контраст у следующих изображении.");
okButton.setText("OK");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Непосредственно текущие установки", "Подбирать автоматически", "Смещать на такое же значение, как у текущего рисунка", "Подбирать автоматически, и смещать на такое же значение", "Подбирать автоматически если не установлено" }));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton))
.addComponent(jComboBox1, 0, 382, Short.MAX_VALUE))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jTextPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cancelButton)
.addComponent(okButton))
.addContainerGap())
);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-426)/2, (screenSize.height-185)/2, 426, 185);
}// </editor-fold>//GEN-END:initComponents
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
doClose(RET_OK);
}//GEN-LAST:event_okButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
doClose(RET_CANCEL);
}//GEN-LAST:event_cancelButtonActionPerformed
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
doClose(RET_CANCEL);
}//GEN-LAST:event_closeDialog
private void doClose(int retStatus) {
returnStatus = retStatus;
/*public static final int EXPLICT = 0;
public static final int AUTO = 1;
public static final int OFFSET = 2;
public static final int AUTO_AND_OFFSET = 3;
public static final int AUTO_IF_NOT_SET = 4;*/
if (retStatus == RET_OK){
int idx = jComboBox1.getSelectedIndex();
DICOMWindowParam wp = img.getWindowParams();
switch (idx){
case EXPLICT:
param.setWindowType(DICOMDeviceParam.WindowingType.expict);
param.setWindowBegin(wp.windowCenter - wp.windowSize / 2);
param.setWindowEnd(wp.windowCenter - wp.windowSize / 2);
break;
case AUTO:
param.setWindowType(DICOMDeviceParam.WindowingType.auto);
param.setWindowBegin(DICOMDeviceParam.AUTO_PROCENTAGE);
param.setWindowEnd(DICOMDeviceParam.AUTO_PROCENTAGE);
break;
case OFFSET:
param.setWindowType(DICOMDeviceParam.WindowingType.modify);
param.setWindowBegin(img.getWindowCenter() - img.getWindowSize() / 2);
param.setWindowEnd(img.getWindowCenter() + img.getWindowSize() / 2);
break;
case AUTO_AND_OFFSET:
Pair<Double, Double> pair = img.calcCurAutoWindow();
param.setWindowType(DICOMDeviceParam.WindowingType.auto);
param.setWindowBegin(pair.first);
param.setWindowEnd(pair.second);
break;
case AUTO_IF_NOT_SET:
param.setWindowType(DICOMDeviceParam.WindowingType.autoIfNotSet);
param.setWindowBegin(DICOMDeviceParam.AUTO_PROCENTAGE);
param.setWindowEnd(DICOMDeviceParam.AUTO_PROCENTAGE);
break;
}
}
setVisible(false);
dispose();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JTextPane jTextPane1;
private javax.swing.JButton okButton;
// End of variables declaration//GEN-END:variables
private int returnStatus = RET_CANCEL;
}