[Biojava-l] Change the height of the peaks in a chromatogram

community at struck.lu community at struck.lu
Tue Nov 4 16:20:09 UTC 2008


Thanks, that did point me in the right direction.

This did the trick:
#########################
        // zoom it
        g2.translate(0, -OUT_HEIGHT * (zoom - 1));
        g2.scale(1, zoom);
#########################

This is my test class if anyone wants to try it out:
#########################
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package trace;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.File;
import java.io.IOException;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.biojava.bio.chromatogram.Chromatogram;
import org.biojava.bio.chromatogram.UnsupportedChromatogramFormatException;
import org.biojava.bio.chromatogram.graphic.ChromatogramGraphic;
import org.biojava.bio.program.scf.SCF;

/**
 *
 * @author Daniel Struck
 */
public class TracePanel_test extends JPanel implements ChangeListener {

    private final int OUT_HEIGHT = 50;
    private Chromatogram c;
    private double zoom;

    public TracePanel_test(Chromatogram c, double zoom) {
        this.c = c;
        this.zoom = zoom;
    }

    @Override
    public void paintComponent(Graphics g) {

        Graphics2D g2 = (Graphics2D) g;

        /* create ChromatogramGraphic */
        ChromatogramGraphic gfx = new ChromatogramGraphic(c);
        gfx.setHeight(OUT_HEIGHT);
        gfx.setHorizontalScale(1.0f);

        gfx.setOption(ChromatogramGraphic.Option.USE_PER_SHAPE_TRANSFORM,
Boolean.TRUE);

        // zoom it
        g2.translate(0, -OUT_HEIGHT * (zoom - 1));
        g2.scale(1, zoom);

        gfx.drawTo(g2);

    }

    public static void main(String[] args) {
        try {

            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            SCF chroma = SCF.create(new File("someTraceFileSomeWhere.scf"));

            TracePanel_test test1 = new TracePanel_test(chroma, 1);

            JPanel panel = new JPanel();
            panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

            JSlider zoomSlider = new JSlider(JSlider.VERTICAL, 1, 20, 1);
            zoomSlider.addChangeListener(test1);

            panel.add(zoomSlider);
            panel.add(test1);

            frame.getContentPane().add(panel);

            frame.setSize(800, 80);
            frame.setVisible(true);

        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (UnsupportedChromatogramFormatException ex) {
            ex.printStackTrace();
        }


    }

    public void stateChanged(ChangeEvent e) {

        JSlider source = (JSlider) e.getSource();
        zoom = source.getValue();
        this.repaint();

    }
}
#########################

Greetings,
Daniel Struck


"Richard Holland" <holland at eaglegenomics.com> wrote:

> Could you use some kind of scale transformation on the chromatogram's
> Graphics2D object, rather than modifying the data?
> 
>
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Graphics2D.html#scale(double,%20double)
> 
> cheers,
> Richard
> 
> 2008/11/3 community at struck.lu <community at struck.lu>:
> > Hello,
> >
> >
> > I want to provide a slider where the user can change dynamically the
height
> of
> > the peaks of a chromatogram. To do this I change the maxTraceValue
variable
> > and set the maximum values lower than they are in reality.
> > Does there exist a better method do this?
> >
> >
> > Best regards,
> > Daniel Struck
> > _________________________________________________________
> > Mail sent using root eSolutions Webmailer - www.root.lu
> >
> >
> > _______________________________________________
> > Biojava-l mailing list  -  Biojava-l at lists.open-bio.org
> > http://lists.open-bio.org/mailman/listinfo/biojava-l
> >
> 
> 


_________________________________________________________
Mail sent using root eSolutions Webmailer - www.root.lu





More information about the Biojava-l mailing list