From 536738d925d6f7213916aa2c85b940f499fc1c2f Mon Sep 17 00:00:00 2001 From: zjzxiaohei <108013625+zjzxiaohei@users.noreply.github.com> Date: Mon, 21 Oct 2024 12:30:18 +1300 Subject: [PATCH] Add a Viewer of Integer2DMatrix #56 --- .../src/main/java/module-info.java | 3 +- .../viewer/Integer2DMatrixViewer.java | 30 +++++++++++++++++++ .../readcountmodel/Integer2DMatrix.java | 11 +++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 phylonco-lphy-studio/src/main/java/readcountmodel/lphystudio/viewer/Integer2DMatrixViewer.java diff --git a/phylonco-lphy-studio/src/main/java/module-info.java b/phylonco-lphy-studio/src/main/java/module-info.java index edfd7a2..5ff98e3 100644 --- a/phylonco-lphy-studio/src/main/java/module-info.java +++ b/phylonco-lphy-studio/src/main/java/module-info.java @@ -1,3 +1,4 @@ +import readcountmodel.lphystudio.viewer.Integer2DMatrixViewer; import readcountmodel.lphystudio.viewer.ReadCountModelViewer; module popsizefunc.lphy.studio { @@ -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. diff --git a/phylonco-lphy-studio/src/main/java/readcountmodel/lphystudio/viewer/Integer2DMatrixViewer.java b/phylonco-lphy-studio/src/main/java/readcountmodel/lphystudio/viewer/Integer2DMatrixViewer.java new file mode 100644 index 0000000..3028bd5 --- /dev/null +++ b/phylonco-lphy-studio/src/main/java/readcountmodel/lphystudio/viewer/Integer2DMatrixViewer.java @@ -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) value).value().toString(); + return new JTextArea(text); + } + + @Override + public String toString() { + return "Integer 2D Matrix Viewer"; + } +} diff --git a/phylonco-lphy/src/main/java/phylonco/lphy/evolution/readcountmodel/Integer2DMatrix.java b/phylonco-lphy/src/main/java/phylonco/lphy/evolution/readcountmodel/Integer2DMatrix.java index 7a67a01..14f2613 100644 --- a/phylonco-lphy/src/main/java/phylonco/lphy/evolution/readcountmodel/Integer2DMatrix.java +++ b/phylonco-lphy/src/main/java/phylonco/lphy/evolution/readcountmodel/Integer2DMatrix.java @@ -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; + } + }