/*
* DICOMWavePanel.java
*
* Created on July 19, 2008, 1:24 PM
*/
package clips.dicom.panels;
import clips.dicom.model.AgregatorItem;
import clips.dicom.model.WaveModel;
import clips.dicom.waveform.WaveDrawer;
import clips.dicom.panels.BaseComboboxModel;
import framework.utils.events.TypedChangeListener;
import java.awt.Rectangle;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JSlider;
import javax.swing.JToggleButton.ToggleButtonModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
*
* @author finder
*/
public class DICOMWavePanel extends javax.swing.JPanel implements ChangeListener {
private static final long serialVersionUID = 065743543257l;
WaveModel waveModel = null;
LinkedList<TypedChangeListener<WaveModel.Params>> controlList = new LinkedList<TypedChangeListener<WaveModel.Params>>();
final List<Object> waveTypes;
abstract class WaveSliderModel extends BaseSliderMode implements TypedChangeListener<WaveModel.Params>{
private final WaveModel.Params type;
public WaveSliderModel(JComponent modelSlider, WaveModel.Params type, int minimum, int maximum) {
super(modelSlider, minimum, maximum);
this.type = type;
controlList.add(this);
//imageModel.addChangeListener(type, this);
}
public WaveModel.Params getType() {
return type;
}
}
abstract class WaveComboboxModel extends BaseComboboxModel implements TypedChangeListener<WaveModel.Params>{
private final WaveModel.Params type;
public WaveComboboxModel(JComboBox box, WaveModel.Params type) {
super(box);
this.type = type;
controlList.add(this);
}
public WaveModel.Params getType() {
return type;
}
}
/** Creates new form DICOMWavePanel */
public DICOMWavePanel() {
initComponents();
Object[] newstubs = new Object[] {new stub(0, "<нету>"), new stub(1, "экг"), new stub(2, "ээг")};
waveTypes = Arrays.asList(newstubs);
initModels();
}
public DICOMWavePanel(boolean hideControls) {
this();
topjPanel.setVisible(!hideControls);
}
private void initModels(){
hZoomjSlider.setModel(new WaveSliderModel(hZoomjSlider, WaveModel.Params.horizontalZoom, 10, 1000) {
@Override
public boolean isEnabled() {
return (waveModel != null)? waveModel.getWaveCount() > 0: false;
}
@Override
public int getValue() {
if (waveModel != null){
return (int)Math.round(waveModel.getHorizontalZoom() * 100);
}
else{
return 100;
}
}
@Override
public void setValue(int newValue) {
if (waveModel != null) {
waveModel.setHorizontalZoom((double) newValue / 100d);
}
}
});
vertZoomjSlider1.setModel(new WaveSliderModel(vertZoomjSlider1, WaveModel.Params.vertiaclZoom, 1, 1000) {
@Override
public boolean isEnabled() {
return (waveModel != null)? waveModel.getWaveCount() > 0: false;
}
public int getValue() {
if (waveModel != null){
return (int)Math.round(waveModel.getVerticalZoom() * 100);
}
else{
return 100;
}
}
public void setValue(int newValue) {
if (waveModel != null) {
waveModel.setVerticalZoom((double) newValue / 100d);
}
}
});
sourcejComboBox.setModel(new WaveComboboxModel(sourcejComboBox, WaveModel.Params.wavesType) {
@Override
public boolean isEnabled() {
return (waveModel != null)? waveModel.getWaveCount() > 0: false;
}
public int getSize() {
return waveTypes.size();
}
public Object getElementAt(int index) {
return waveTypes.get(index);
}
public void setSelectedItem(Object anItem) {
if (waveModel != null) {
waveModel.setWavesTypeID(((stub)anItem).getId());
}
}
public Object getSelectedItem() {
if (waveModel != null) {
int id = waveTypes.indexOf(new stub((int)waveModel.getWavesTypeID(), ""));
return id >= 0? waveTypes.get(id): null;
}
else {
return waveTypes.get(0);
}
}
});
mainScrollBar.setModel(new WaveSliderModel(mainScrollBar, WaveModel.Params.scroolPosition, 0, 0) {
@Override
public boolean isEnabled() {
return getMaximum() > 0;
}
@Override
public int getMaximum() {
return (int)Math.round((waveModel != null)? waveModel.getMaxScrolPosition(new Rectangle(canvas.getSize())) * 100: 0d);
}
public int getValue() {
if (waveModel != null){
int pos = (int)Math.round(waveModel.getScrolPosition() * 100);
if (pos > getMaximum()){
setValue(getMaximum());
return getMaximum();
}
return pos;
}
else{
return 0;
}
}
public void setValue(int newValue) {
if (waveModel != null) {
waveModel.setScrollPosition((double) newValue / 100d);
}
}
});
}
/** 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() {
java.awt.GridBagConstraints gridBagConstraints;
contentjPanel = new javax.swing.JPanel();
hZoomjSlider = new javax.swing.JSlider();
vertZoomjSlider1 = new javax.swing.JSlider();
canvas = new DicomCanvas.DICOMCanvas();
topjPanel = new javax.swing.JPanel();
editDeviceParamjButton = new javax.swing.JButton();
sourcejComboBox = new javax.swing.JComboBox();
jLabel1 = new javax.swing.JLabel();
filreDownZoomjCheckBox = new javax.swing.JCheckBox();
normalZoomjButton = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
legendjLabel = new javax.swing.JLabel();
mainScrollBar = new javax.swing.JScrollBar();
setLayout(new java.awt.BorderLayout());
contentjPanel.setLayout(new java.awt.BorderLayout());
contentjPanel.add(hZoomjSlider, java.awt.BorderLayout.NORTH);
vertZoomjSlider1.setMaximum(150);
vertZoomjSlider1.setMinimum(50);
vertZoomjSlider1.setOrientation(javax.swing.JSlider.VERTICAL);
vertZoomjSlider1.setValue(100);
contentjPanel.add(vertZoomjSlider1, java.awt.BorderLayout.WEST);
canvas.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseExited(java.awt.event.MouseEvent evt) {
canvasMouseExited(evt);
}
});
canvas.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseMoved(java.awt.event.MouseEvent evt) {
canvasMouseMoved(evt);
}
});
javax.swing.GroupLayout canvasLayout = new javax.swing.GroupLayout(canvas);
canvas.setLayout(canvasLayout);
canvasLayout.setHorizontalGroup(
canvasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 925, Short.MAX_VALUE)
);
canvasLayout.setVerticalGroup(
canvasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 502, Short.MAX_VALUE)
);
contentjPanel.add(canvas, java.awt.BorderLayout.CENTER);
add(contentjPanel, java.awt.BorderLayout.CENTER);
editDeviceParamjButton.setText("Настроить отображение");
sourcejComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jLabel1.setText("Тип");
filreDownZoomjCheckBox.setText("Фильтрация");
filreDownZoomjCheckBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
filreDownZoomjCheckBoxActionPerformed(evt);
}
});
normalZoomjButton.setText("Нормальный маштаб");
normalZoomjButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
normalZoomjButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout topjPanelLayout = new javax.swing.GroupLayout(topjPanel);
topjPanel.setLayout(topjPanelLayout);
topjPanelLayout.setHorizontalGroup(
topjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, topjPanelLayout.createSequentialGroup()
.addComponent(normalZoomjButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(filreDownZoomjCheckBox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(sourcejComboBox, 0, 449, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(editDeviceParamjButton))
);
topjPanelLayout.setVerticalGroup(
topjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(topjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(editDeviceParamjButton)
.addComponent(sourcejComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)
.addComponent(filreDownZoomjCheckBox)
.addComponent(normalZoomjButton))
);
add(topjPanel, java.awt.BorderLayout.PAGE_START);
legendjLabel.setText("1");
mainScrollBar.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(33, 33, 33)
.addComponent(mainScrollBar, javax.swing.GroupLayout.DEFAULT_SIZE, 774, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(legendjLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(legendjLabel)
.addComponent(mainScrollBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
add(jPanel1, java.awt.BorderLayout.PAGE_END);
}// </editor-fold>//GEN-END:initComponents
private void canvasMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_canvasMouseMoved
if (waveModel != null){
String note = waveModel.setMousePoint(canvas.getGraphics(), evt.getX(), evt.getY());
legendjLabel.setText(": " + note);
}
else {
legendjLabel.setText(": ");
}
}//GEN-LAST:event_canvasMouseMoved
private void canvasMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_canvasMouseExited
if (waveModel != null){
waveModel.setMousePoint(canvas.getGraphics(), Integer.MIN_VALUE, Integer.MIN_VALUE);
}
}//GEN-LAST:event_canvasMouseExited
private void filreDownZoomjCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filreDownZoomjCheckBoxActionPerformed
if (waveModel != null){
waveModel.setFiltreDownZoomWaves(filreDownZoomjCheckBox.isSelected());
}
}//GEN-LAST:event_filreDownZoomjCheckBoxActionPerformed
private void normalZoomjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_normalZoomjButtonActionPerformed
if (waveModel != null){
waveModel.setVerticalZoom(1);
waveModel.setHorizontalZoom(1);
}
}//GEN-LAST:event_normalZoomjButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private DicomCanvas.DICOMCanvas canvas;
private javax.swing.JPanel contentjPanel;
private javax.swing.JButton editDeviceParamjButton;
private javax.swing.JCheckBox filreDownZoomjCheckBox;
private javax.swing.JSlider hZoomjSlider;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel legendjLabel;
private javax.swing.JScrollBar mainScrollBar;
private javax.swing.JButton normalZoomjButton;
private javax.swing.JComboBox sourcejComboBox;
private javax.swing.JPanel topjPanel;
private javax.swing.JSlider vertZoomjSlider1;
// End of variables declaration//GEN-END:variables
void onWaveChanged(){
}
public void stateChanged(ChangeEvent e) {
if (waveModel != null) {
canvas.setImage(waveModel.getDrawer());
}
onWaveChanged();
if (waveModel != null){
filreDownZoomjCheckBox.setEnabled(waveModel.getWaveCount() > 0);
filreDownZoomjCheckBox.setSelected(waveModel.getFiltreDownZoomWaves());
}
else{
filreDownZoomjCheckBox.setSelected(false);
filreDownZoomjCheckBox.setEnabled(false);
}
}
public void setWaves(AgregatorItem waves){
WaveModel oldWaveModel = waveModel;
if (waves == null) {
waveModel = null;
}
else {
waveModel = waves.getWaveModel();
}
if (waveModel != oldWaveModel){
for (TypedChangeListener<WaveModel.Params> listener: controlList) {
if (oldWaveModel != null) {
oldWaveModel.removeChangeListener(listener.getType(), listener);
}
if (waveModel != null) {
waveModel.addChangeListener(listener.getType(), listener);
}
listener.stateChanged(null);
}
if (oldWaveModel != null) {
oldWaveModel.removeChangeListener(null, this);
}
if (waveModel != null) {
waveModel.addChangeListener(null, this);
}
stateChanged(null);
}
}
public void clear(){
setWaves(null);
}
public void dispose(){
clear();
}
}