Package clips.dicom.dicom_emc

Source Code of clips.dicom.dicom_emc.DICOMView

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* DICOMView.java
*
* Created on 12.09.2009, 10:43:56
*/

package clips.dicom.dicom_emc;

import DicomCanvas.Paintable;
import clips.dicom.model.AgregatorItem;
import java.awt.Dimension;

/**
*
* @author petr
*/
public class DICOMView extends javax.swing.JPanel {

    private AgregatorItem item = null;

    /** Creates new form DICOMView
     * @param agregator
     */
    public DICOMView(AgregatorItem agregator) {
        initComponents();
        setImage(agregator);
    }

    public DICOMView(){
        this(null);
    }

    /** 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() {

        lblTitle = new javax.swing.JLabel();
        pnlView = new javax.swing.JPanel();
        canvas = new DicomCanvas.DICOMCanvas();

        setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        setMaximumSize(new java.awt.Dimension(200, 200));
        setPreferredSize(new java.awt.Dimension(100, 100));
        setLayout(new java.awt.BorderLayout(1, 1));

        lblTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblTitle.setText("title");
        add(lblTitle, java.awt.BorderLayout.SOUTH);

        pnlView.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                pnlViewComponentResized(evt);
            }
        });
        pnlView.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        javax.swing.GroupLayout canvasLayout = new javax.swing.GroupLayout(canvas);
        canvas.setLayout(canvasLayout);
        canvasLayout.setHorizontalGroup(
            canvasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        canvasLayout.setVerticalGroup(
            canvasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        pnlView.add(canvas, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        add(pnlView, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void pnlViewComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_pnlViewComponentResized
        canvas.setIgnoreRepaint(true);
        calculateCanvasSize(item);
        canvas.setIgnoreRepaint(false);
    }//GEN-LAST:event_pnlViewComponentResized


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private DicomCanvas.DICOMCanvas canvas;
    private javax.swing.JLabel lblTitle;
    private javax.swing.JPanel pnlView;
    // End of variables declaration//GEN-END:variables

    public void setImage(AgregatorItem agregator) {
        this.item = agregator;
        calculateCanvasSize(agregator);
        if (agregator != null){
            lblTitle.setText(agregator.getName());
            Paintable image = null;

            if (agregator.getItemsType() == AgregatorItem.ItemsType.image && agregator.getImageModel().getImageCount() > 0) {
                image = agregator.getImageModel().getImage(0);
            } else if (agregator.getItemsType() == AgregatorItem.ItemsType.waveform) {
                image = agregator.getWaveModel().getDrawer();
            }

            canvas.setImage(image);
        }else{
            canvas.setImage(null);
            lblTitle.setText("нет изображения");
        }
        pnlView.revalidate();
        pnlView.repaint();
    }

    private void calculateCanvasSize(AgregatorItem agregator){
        canvas.setIgnoreRepaint(true);
        pnlView.setIgnoreRepaint(true);
        if (agregator != null
                && agregator.getItemsType() == AgregatorItem.ItemsType.image
                && agregator.getImageModel().getImageCount() > 0) {
            Dimension imageSize = agregator.getImageModel().getImage(0).getImageSize();
            int h = pnlView.getSize().height;
            int w = pnlView.getSize().width;
            int H = imageSize.height;
            int W = imageSize.width;
            double kw = (double) w / (double) W;
            double kh = (double) h / (double) H;
            double k = kw < kh ? kw : kh;
            int cw = (int) (W * k);
            int ch = (int) (H * k);
            canvas.setSize(cw, ch);
            canvas.setLocation((w - cw) / 2, (h - ch) / 2);
        } else {
            canvas.setSize(pnlView.getSize());
            canvas.setLocation(0, 0);
        }

        canvas.setIgnoreRepaint(false);
        pnlView.setIgnoreRepaint(false);
    }

}
TOP

Related Classes of clips.dicom.dicom_emc.DICOMView

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.