/*
* DICOMImagePanel.java
*
* Created on July 17, 2008, 1:21 PM
*/
package clips.dicom.panels;
import clips.dicom.model.ImageModel;
import clips.dicom.Image.DICOMImage;
import clips.dicom.dicombaseclass.DICOMDeviceParam;
import clips.dicom.model.AgregatorItem;
import clips.dicom.model.ImageModel.Params;
import clips.dicom.model.ItemEvent;
import clips.dicom.model.ItemListener;
import clips.dicom.panels.BaseComboboxModel;
import framework.utils.events.TypedChangeEvent;
import framework.utils.events.TypedChangeListener;
import cli_fmw.main.MainWindow;
import java.awt.Dimension;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JComboBox;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
*
* @author finder
*/
public class DICOMImagePanel extends javax.swing.JPanel implements ChangeListener, ItemListener {
private static final long serialVersionUID = 123432454658l;
ImageModel imageModel = null;
double zoomFactor = 1;
ImageSliderModel zoomSliderModel;
LinkedList<TypedChangeListener<ImageModel.Params>> controlList = new LinkedList<TypedChangeListener<Params>>();
int curImageID;
boolean isLastId;
final List<Object> pacientOrentations;
abstract class ImageSliderModel extends BaseSliderMode implements TypedChangeListener<ImageModel.Params>{
private final ImageModel.Params type;
public ImageSliderModel(JSlider modelSlider, ImageModel.Params type, int minimum, int maximum) {
super(modelSlider, minimum, maximum);
this.type = type;
controlList.add(this);
//imageModel.addChangeListener(type, this);
}
@Override
public Params getType() {
return type;
}
}
abstract class ImageComboboxModel extends BaseComboboxModel implements TypedChangeListener<ImageModel.Params>{
private final ImageModel.Params type;
public ImageComboboxModel(JComboBox box, Params type) {
super(box);
this.type = type;
controlList.add(this);
}
@Override
public Params getType() {
return type;
}
}
/** Creates new form DICOMImagePanel */
public DICOMImagePanel() {
initComponents();
Object[] tmport = new Object[]{new stub(0, "<нет>")};//, new stub(1, "С пуза"), new stub(2, "С тыла")};
pacientOrentations = Arrays.asList(tmport);
initModels();
clear();
}
public DICOMImagePanel(boolean hideControls) {
this();
jPanel7.setVisible(!hideControls);
}
void initModels(){
brigthjSlider3.setModel(new ImageSliderModel(brigthjSlider3, ImageModel.Params.brigth, -100, +100) {
@Override
public int getValue() {
if (imageModel != null) {
return (int)Math.round(imageModel.getBright(curImageID) * 100);
}
else {
return 0;
}
}
@Override
public void setValue(int newValue) {
if (imageModel != null) {
imageModel.setBright(curImageID, (double)newValue / 100d);
}
}
@Override
public boolean isEnabled() {
return imageModel == null? false: imageModel.isValidImage(curImageID);
}
});
contrastjSlider.setModel(new ImageSliderModel(contrastjSlider, ImageModel.Params.contrast, -100, 100) {
@Override
public int getValue() {
if (imageModel != null) {
return (int)Math.round(imageModel.getContrast(curImageID) * 100);
}
else {
return 0;
}
}
@Override
public void setValue(int newValue) {
if (imageModel != null) {
imageModel.setContrast(curImageID, (double)newValue / 100d);
}
}
@Override
public boolean isEnabled() {
return imageModel == null? false: imageModel.isValidImage(curImageID);
}
});
gammajSlider.setModel(new ImageSliderModel(gammajSlider, ImageModel.Params.gamma, 1, 400) {
@Override
public int getValue() {
if (imageModel != null) {
return (int)Math.round(imageModel.getGamma(curImageID) * 100);
}
else {
return 0;
}
}
@Override
public void setValue(int newValue) {
if (imageModel != null) {
imageModel.setGamma(curImageID, (double)newValue / 100d);
}
}
@Override
public boolean isEnabled() {
return imageModel == null? false: imageModel.isValidImage(curImageID);
}
});
upLeveljSlider.setModel(new ImageSliderModel(upLeveljSlider, ImageModel.Params.minmax, 1, 255) {
@Override
public int getValue() {
if (imageModel != null) {
int val = (int)Math.round(255 - (imageModel.getMax(curImageID) / 257d));
return Math.max(Math.min(255,val), 0);
}
else {
return 0;
}
}
@Override
public void setValue(int newValue) {
if (imageModel != null) {
imageModel.setMinMax(curImageID, imageModel.getMin(curImageID), (255 - newValue) * 257);
}
}
@Override
public boolean isEnabled() {
return imageModel == null? false: imageModel.isValidImage(curImageID);
}
});
downLeveljSlider.setModel(new ImageSliderModel(downLeveljSlider, ImageModel.Params.minmax, 0, 254) {
@Override
public int getValue() {
if (imageModel != null) {
int val = (int)Math.round(imageModel.getMin(curImageID) / 257d);
return Math.max(Math.min(255,val), 0);
}
else {
return 0;
}
}
@Override
public void setValue(int newValue) {
if (imageModel != null) {
int newlow = newValue * 257;
double max = imageModel.getMax(curImageID);
if (max < newlow) {
imageModel.setMinMax(curImageID, newlow, newlow + 1);
}
else {
imageModel.setMinMax(curImageID, newlow, max);
}
}
}
@Override
public boolean isEnabled() {
return imageModel == null? false: imageModel.isValidImage(curImageID);
}
});
pictSellectjSlider.setModel(new ImageSliderModel(pictSellectjSlider, ImageModel.Params.imageChange, 1, 12) {
@Override
public int getMaximum() {
if (imageModel != null) {
return Math.max(imageModel.getImageCount(), 1);
}
else {
return 1;
}
}
@Override
public int getValue() {
return getCurImageID();
}
@Override
public void setValue(int newValue) {
setCurImageID(newValue - 1);
}
@Override
public boolean isEnabled() {
return getMaximum() > 1;
}
});
zoomSliderModel = new ImageSliderModel(pictSellectjSlider, ImageModel.Params.imageChange, 1, 100) {
@Override
public int getValue() {
return Math.max(Math.min((int)Math.round(getZoom() * 10), 100), 1);
}
@Override
public void setValue(int newValue) {
setZoom((double)newValue / 10d, true);
}
@Override
public boolean isEnabled() {
return imageModel == null? false: imageModel.isValidImage(curImageID);
}
};
ZoomjSlider.setModel(zoomSliderModel);
imageOrentationComboBox1.setModel(new ImageComboboxModel(imageOrentationComboBox1, Params.orentationChange) {
@Override
public boolean isEnabled() {
return imageModel == null? false: imageModel.isValidImage(curImageID);
}
public int getSize() {
return pacientOrentations.size();
}
public Object getElementAt(int index) {
return pacientOrentations.get(index);
}
public void setSelectedItem(Object anItem) {
if (imageModel != null) {
imageModel.setOrentationID(curImageID, ((stub) anItem).getId());
}
}
public Object getSelectedItem() {
int id = 0;
if (imageModel != null && imageModel.isValidImage(curImageID)) {
id = (int) imageModel.getOrentationID(curImageID);
}
id = pacientOrentations.indexOf(new stub(id, ""));
return id >= 0? pacientOrentations.get(id): null;
}
});
//imageOrentationComboBox1.setEditable(false);
}
/** 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() {
imagejScrollPane = new javax.swing.JScrollPane();
canvas = new DicomCanvas.DICOMCanvas();
jPanel6 = new javax.swing.JPanel();
pictSellectjSlider = new javax.swing.JSlider();
jPanel7 = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
brigthjSlider3 = new javax.swing.JSlider();
jLabel2 = new javax.swing.JLabel();
contrastjSlider = new javax.swing.JSlider();
jLabel3 = new javax.swing.JLabel();
gammajSlider = new javax.swing.JSlider();
jPanel4 = new javax.swing.JPanel();
leveljPanel = new javax.swing.JPanel();
upLeveljSlider = new javax.swing.JSlider();
downLeveljSlider = new javax.swing.JSlider();
jPanel5 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
imageOrentationComboBox1 = new javax.swing.JComboBox();
SetDefaultjButton = new javax.swing.JButton();
SaveDeviseParamjButton = new javax.swing.JButton();
zoomjPanel = new javax.swing.JPanel();
ZoomDecjButton = new javax.swing.JButton();
ZoomjSlider = new javax.swing.JSlider();
ZoomIncjButton = new javax.swing.JButton();
setMinimumSize(new java.awt.Dimension(200, 132));
setPreferredSize(new java.awt.Dimension(601, 563));
setLayout(new java.awt.BorderLayout());
imagejScrollPane.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(java.awt.event.ComponentEvent evt) {
imagejScrollPaneComponentResized(evt);
}
});
canvas.setPreferredSize(new java.awt.Dimension(90, 90));
javax.swing.GroupLayout canvasLayout = new javax.swing.GroupLayout(canvas);
canvas.setLayout(canvasLayout);
canvasLayout.setHorizontalGroup(
canvasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 599, Short.MAX_VALUE)
);
canvasLayout.setVerticalGroup(
canvasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 271, Short.MAX_VALUE)
);
imagejScrollPane.setViewportView(canvas);
add(imagejScrollPane, java.awt.BorderLayout.CENTER);
jPanel6.setLayout(new javax.swing.BoxLayout(jPanel6, javax.swing.BoxLayout.LINE_AXIS));
pictSellectjSlider.setMaximum(12);
pictSellectjSlider.setMinimum(1);
pictSellectjSlider.setPaintTicks(true);
pictSellectjSlider.setSnapToTicks(true);
pictSellectjSlider.setValue(4);
pictSellectjSlider.setEnabled(false);
jPanel6.add(pictSellectjSlider);
add(jPanel6, java.awt.BorderLayout.SOUTH);
jPanel7.setLayout(new javax.swing.BoxLayout(jPanel7, javax.swing.BoxLayout.LINE_AXIS));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Цвет"));
jLabel1.setText("Яркость");
brigthjSlider3.setMinimum(-100);
brigthjSlider3.setValue(0);
jLabel2.setText("Контраст");
contrastjSlider.setMaximum(200);
contrastjSlider.setValue(100);
jLabel3.setText("Гамма");
gammajSlider.setMaximum(400);
gammajSlider.setValue(100);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addContainerGap(81, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addContainerGap(106, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(brigthjSlider3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
.addComponent(contrastjSlider, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
.addComponent(gammajSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))
.addContainerGap())))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(brigthjSlider3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(contrastjSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(gammajSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel7.add(jPanel1);
jPanel4.setLayout(new java.awt.BorderLayout());
leveljPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Уровни"));
upLeveljSlider.setMaximum(255);
upLeveljSlider.setValue(0);
upLeveljSlider.setInverted(true);
downLeveljSlider.setMaximum(255);
downLeveljSlider.setValue(0);
javax.swing.GroupLayout leveljPanelLayout = new javax.swing.GroupLayout(leveljPanel);
leveljPanel.setLayout(leveljPanelLayout);
leveljPanelLayout.setHorizontalGroup(
leveljPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, leveljPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(leveljPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(upLeveljSlider, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
.addComponent(downLeveljSlider, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE))
.addContainerGap())
);
leveljPanelLayout.setVerticalGroup(
leveljPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(leveljPanelLayout.createSequentialGroup()
.addComponent(downLeveljSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(upLeveljSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel4.add(leveljPanel, java.awt.BorderLayout.CENTER);
jPanel3.setLayout(new java.awt.GridLayout(0, 1));
imageOrentationComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jPanel3.add(imageOrentationComboBox1);
SetDefaultjButton.setText("Автоопределение");
SetDefaultjButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SetDefaultjButtonActionPerformed(evt);
}
});
jPanel3.add(SetDefaultjButton);
SaveDeviseParamjButton.setText("Применять всегда");
SaveDeviseParamjButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SaveDeviseParamjButtonActionPerformed(evt);
}
});
jPanel3.add(SaveDeviseParamjButton);
zoomjPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Масштаб"));
ZoomDecjButton.setText("-");
ZoomDecjButton.setBorder(null);
ZoomDecjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
ZoomDecjButton.setMaximumSize(new java.awt.Dimension(29, 29));
ZoomDecjButton.setMinimumSize(new java.awt.Dimension(29, 29));
ZoomDecjButton.setPreferredSize(new java.awt.Dimension(29, 29));
ZoomDecjButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ZoomDecjButtonActionPerformed(evt);
}
});
ZoomjSlider.setMaximum(1000);
ZoomjSlider.setMinimum(1);
ZoomjSlider.setValue(100);
ZoomjSlider.setMaximumSize(new java.awt.Dimension(32767, 20));
ZoomIncjButton.setText("+");
ZoomIncjButton.setBorder(null);
ZoomIncjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
ZoomIncjButton.setMaximumSize(new java.awt.Dimension(29, 29));
ZoomIncjButton.setMinimumSize(new java.awt.Dimension(29, 29));
ZoomIncjButton.setPreferredSize(new java.awt.Dimension(29, 29));
ZoomIncjButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ZoomIncjButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout zoomjPanelLayout = new javax.swing.GroupLayout(zoomjPanel);
zoomjPanel.setLayout(zoomjPanelLayout);
zoomjPanelLayout.setHorizontalGroup(
zoomjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(zoomjPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(ZoomDecjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ZoomjSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ZoomIncjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
zoomjPanelLayout.setVerticalGroup(
zoomjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(zoomjPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(zoomjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(ZoomIncjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ZoomjSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ZoomDecjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addComponent(zoomjPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(zoomjPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
jPanel4.add(jPanel5, java.awt.BorderLayout.NORTH);
jPanel7.add(jPanel4);
add(jPanel7, java.awt.BorderLayout.NORTH);
}// </editor-fold>//GEN-END:initComponents
private void imagejScrollPaneComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_imagejScrollPaneComponentResized
updateZoom();
}//GEN-LAST:event_imagejScrollPaneComponentResized
private void ZoomDecjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ZoomDecjButtonActionPerformed
setZoom(getZoom() * 0.75d, false);
}//GEN-LAST:event_ZoomDecjButtonActionPerformed
private void ZoomIncjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ZoomIncjButtonActionPerformed
setZoom(getZoom() * (1d / 0.75d), false);
}//GEN-LAST:event_ZoomIncjButtonActionPerformed
private void SetDefaultjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SetDefaultjButtonActionPerformed
if (imageModel != null){
imageModel.autoWindow(curImageID, DICOMDeviceParam.AUTO_PROCENTAGE, DICOMDeviceParam.AUTO_PROCENTAGE);
}
}//GEN-LAST:event_SetDefaultjButtonActionPerformed
private void SaveDeviseParamjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveDeviseParamjButtonActionPerformed
if (imageModel != null){
DICOMImage img = imageModel.getImage(curImageID);
DICOMImage paramimg = imageModel.getImage(0);
if (img != null && paramimg != null) {
new DicomDeviseImageParamsDlg(MainWindow.mainWindow, paramimg.getDeviceParam(), img).setVisible(true);
}
}
}//GEN-LAST:event_SaveDeviseParamjButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton SaveDeviseParamjButton;
private javax.swing.JButton SetDefaultjButton;
private javax.swing.JButton ZoomDecjButton;
private javax.swing.JButton ZoomIncjButton;
private javax.swing.JSlider ZoomjSlider;
private javax.swing.JSlider brigthjSlider3;
private DicomCanvas.DICOMCanvas canvas;
private javax.swing.JSlider contrastjSlider;
private javax.swing.JSlider downLeveljSlider;
private javax.swing.JSlider gammajSlider;
private javax.swing.JComboBox imageOrentationComboBox1;
private javax.swing.JScrollPane imagejScrollPane;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JPanel leveljPanel;
private javax.swing.JSlider pictSellectjSlider;
private javax.swing.JSlider upLeveljSlider;
private javax.swing.JPanel zoomjPanel;
// End of variables declaration//GEN-END:variables
public void updateZoom(){
Dimension scrollSize = imagejScrollPane.getSize();
DICOMImage img = imageModel != null? imageModel.getImage(curImageID): null;
if (img != null){
Dimension imgSize = img.getImageSize();
double hzoom = (double)(scrollSize.width - 4) / (double)imgSize.width;
double vzoom = (double)(scrollSize.height - 4) / (double)imgSize.height;
double curzoom = Math.min(hzoom, vzoom) * zoomFactor;
Dimension newSize = new Dimension((int)(imgSize.width * curzoom), (int)(imgSize.height * curzoom));
canvas.setMaximumSize(new Dimension(newSize));
canvas.setSize(new Dimension(newSize));
canvas.setMinimumSize(new Dimension(newSize));
//imagejScrollPane.getViewport().setViewSize(newSize);
canvas.setPreferredSize(new Dimension(newSize));
//canvas.setMaximumSize(newSize);
//canvas.setPreferredSize(newSize);
canvas.setMySize(new Dimension(newSize));
}
else{
canvas.setSize(scrollSize.width - 4, scrollSize.height - 4);
canvas.setMySize(null);
}
}
void setZoom(double zoom, boolean foromSlider){
if (zoom != zoomFactor || !foromSlider){
zoomFactor = zoom;
if (!foromSlider) {
zoomSliderModel.stateChanged(new ChangeEvent(this));
}
updateZoom();
}
}
double getZoom(){
return zoomFactor;
}
public void onImageChanged(){
if (isLastId) {
setCurImageID(imageModel != null? imageModel.getImageCount(): 0);
}
setZoom(1d, false);
}
@Override
public void stateChanged(ChangeEvent e) {
ImageModel.Params eType = ImageModel.Params.gamma;
if (e instanceof TypedChangeEvent) {
if (((TypedChangeEvent) e).getEventType() instanceof ImageModel.Params) {
eType = (ImageModel.Params) ((TypedChangeEvent)e).getEventType();
}
}
if (imageModel != null) {
canvas.setImage(imageModel.getImage(curImageID));
}
else {
canvas.setImage(null);
}
if (eType == ImageModel.Params.imageChange){
onImageChanged();
}
}
@Override
public void itemStateChanged(ItemEvent e) {
}
public void setImages(AgregatorItem imgs){
ImageModel oldImageControl = imageModel;
if (imgs == null) {
imageModel = null;
}
else {
imageModel = imgs.getImageModel();
}
if (imageModel != oldImageControl){
for (TypedChangeListener<ImageModel.Params> listener: controlList) {
if (oldImageControl != null) {
oldImageControl.removeChangeListener(listener.getType(), listener);
}
if (imageModel != null) {
imageModel.addChangeListener(listener.getType(), listener);
}
listener.stateChanged(null);
}
if (oldImageControl != null) {
oldImageControl.removeChangeListener(null, this);
}
if (imageModel != null) {
imageModel.addChangeListener(null, this);
}
curImageID = -1;
setCurImageID(0);
onImageChanged();
}
}
public int getCurImageID() {
if (imageModel != null){
return Math.max(Math.min(curImageID, imageModel.getImageCount() - 1), 0);
}
else{
curImageID = 0;
isLastId = true;
return curImageID;
}
}
public void setCurImageID(int id){
if (imageModel != null) {
if (id < 0) {
id = 0;
}
if (id >= imageModel.getImageCount()) {
id = imageModel.getImageCount() - 1;
}
isLastId = imageModel.getImageCount() == id + 1;
if (curImageID != id) {
curImageID = id;
imageModel.notifyListeners(ImageModel.Params.imageChange);
}
}
else{
curImageID = 0;
isLastId = true;
}
}
public void clear(){
setImages(null);
}
public void dispose(){
clear();
}
}