Skip to content

Commit

Permalink
Add a Viewer of Integer2DMatrix #56
Browse files Browse the repository at this point in the history
  • Loading branch information
zjzxiaohei committed Oct 20, 2024
1 parent 35244a7 commit 536738d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion phylonco-lphy-studio/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import readcountmodel.lphystudio.viewer.Integer2DMatrixViewer;
import readcountmodel.lphystudio.viewer.ReadCountModelViewer;

module popsizefunc.lphy.studio {
Expand All @@ -8,7 +9,7 @@
// Viewer SPI
uses lphystudio.app.graphicalmodelpanel.viewer.Viewer;
// declare what service interface the provider intends to use
provides lphystudio.app.graphicalmodelpanel.viewer.Viewer with ReadCountModelViewer;
provides lphystudio.app.graphicalmodelpanel.viewer.Viewer with ReadCountModelViewer, Integer2DMatrixViewer;

// Note: to adapt with the system not using Java module but using class path,
// they need to be declared inside META-INF/services/lphystudio.app.graphicalmodelpanel.viewer.Viewer as well.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package readcountmodel.lphystudio.viewer;

import lphy.core.model.Value;
import lphystudio.app.graphicalmodelpanel.viewer.Viewer;
import phylonco.lphy.evolution.readcountmodel.Integer2DMatrix;

import javax.swing.*;

public class Integer2DMatrixViewer implements Viewer {
public Integer2DMatrixViewer() {}
@Override
public boolean match(Object value) {
return value instanceof Integer2DMatrix ||
(value instanceof Value && ((Value) value).value() instanceof Integer2DMatrix);
}

@Override
public JComponent getViewer(Object value) {
if (match(value)) {
return new JTextArea(value.toString());
}
String text = ((Value<Integer2DMatrix>) value).value().toString();
return new JTextArea(text);
}

@Override
public String toString() {
return "Integer 2D Matrix Viewer";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,15 @@ public Integer getState (int taxon, int position) {

public Integer nchar () {return matrix[0].length;}

public String toString () {
String string = "\n";
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
string += String.format("%d ", matrix[i][j]);
}
string += "\n";
}
return string;
}

}

0 comments on commit 536738d

Please sign in to comment.