Introduction to the code, part 1

If you want to continue the MionChrom project I will give you a helpful introduction to the code in this post.

If you are not familiar with Java, you should learn it first. Learn yourself: datatypes, for, while, if, arrays, methods, inheritance, object-orientation, interfaces, ArrayList, HashMap, Swing-components, Layouthandlers. Java is very much like the C-class of programming languages, with some differences. One difference is the use of interfaces. Java is a cross-plattform language thanks to Java Virtual Machine (JVM) and should be working on Linux, Mac OS and Windows. You could use the softwares Eclipse or Netbeans to program Java. But if you want to go hardcore try Notepad or Notepad++ and compile the code with the “Javac” command in a console. I will recommend Eclipse in this project.

MionChrom is using Java.awt.Swing components for displaying the content (Genuine User Interface, GUI). Make yourself familiar with JComponent, JPanel, JTextArea, JLabel etc. A Layoutmanagers like BoxLayout is controlling how the components is arranged. ActionListeners, ChangeListeners, MouseListeners and other touch and feel interfaces is controlling interactions. Also make yourself familiar with the use of the paintComponent-method in combination with the Graphics-class. You can draw graphs, points, lines and text in different colors and styles on a JComponent by overriding this method. Image handling is also very useful to learn yourself. Especially how to draw images from file and BufferedImages.

For displaying the chromatograms MionChrom is using class called Dots which extends JPanel. It is override paintComponent and patched together two BufferedImages on top of each other and then draws selections like the rectangles that appears on the chromatogram when you click and drags the mouse. One BufferedImage holds the data and is redrawn when absolutely necessary like zooming and recentering as this is very resource demanding. The other information like text and lines and is redrawn on top of the other more frequently.

Each layer of chromatograms (like mass 44, 45 and 46) is represented as a “DataSer”-class (as in a dataseries). They holds the data in a double[][] array, where the first index is the axis, X is 0 and Y is 1. The second index is the datapoint number. To draw the data DataSer is converting the human number (I call them orga-numbers) to machine (mecha) numbers. Mecha-numbers are the coordinates on the JPanel as represented in Graphics. A frame-array is controlling what is shown as the user is centering and zooming. By storing the frame-array in a ArrayList you can enable the user to retrieve an earlier viewing point of the data. By storing the DataSer in the Dots-class in the same fashion the user can undo any changes in integration.