From: tcofoegbu Date: Mon, 9 May 2016 16:36:10 +0000 (+0100) Subject: JAL-2102 implemented improvement to round FTS's numberic data columns to a configurab... X-Git-Tag: Release_2_10_0~229 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b577ea70f354225426c5a5ecb8def7261e1cd3aa;p=jalview.git JAL-2102 implemented improvement to round FTS's numberic data columns to a configurable number of significant figures, and added Jalview licence header to the PDB FTS data column config file --- diff --git a/resources/fts/pdb_data_columns.txt b/resources/fts/pdb_data_columns.txt index 95f2dd1..1827a85 100644 --- a/resources/fts/pdb_data_columns.txt +++ b/resources/fts/pdb_data_columns.txt @@ -1,3 +1,24 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ + pdb_data_columns # _group.id @@ -6,7 +27,7 @@ _group.sort_order g1;Quality Measures;1 g2;Cross References;2 g3;Names & Taxonomy;3 -g4;Procedures & Softwares;4 +g4;Procedures & Software;4 g5;Date Of;5 g6;Miscellenous;6 # @@ -16,7 +37,7 @@ _data_column.default_response_page_size;100 _data_column.name _data_column.code _data_column.group_id -_data_column.data_type +_data_column.data_type | _data_column.isFormated | _data_column.significantDigit _data_column.min_col_width _data_column.max_col_width _data_column.preferred_col_width @@ -35,17 +56,17 @@ UniProt Id;uniprot_id;String;g2;50;400;95;false;true UniProt Accession;uniprot_accession;String;g2;50;400;95;false;false UniProt Coverage;uniprot_coverage;String;g6;50;400;95;false;false Uniprot Features;uniprot_features;String;g6;50;400;95;false;false -R Factor;r_factor;Double;g1;50;150;85;false;false -Resolution;resolution;Double;g1;50;150;85;true;false -Data Quality;data_quality;Double;g1;50;150;85;false;false -Overall Quality;overall_quality;Double;g1;50;150;85;false;false +R Factor;r_factor;Double|T|3;g1;50;150;85;false;false +Experimental Method;experimental_method;String;g4;50;400;105;true;false +Resolution;resolution;Double|T|3;g1;50;150;85;true;false +Data Quality;data_quality;Double|T|2;g1;50;150;85;false;false +Overall Quality;overall_quality;Double|T|1;g1;50;150;85;false;false Number of Polymers;number_of_polymers;int;g6;50;400;95;false;false Number of Protein Chains;number_of_protein_chains;int;g6;50;400;95;false;false Number of Bound Molecule;number_of_bound_molecules;int;g6;50;400;95;false;false Number of Polymer Residue;number_of_polymer_residues;int;g6;50;400;95;false;false GENUS;genus;String;g3;50;400;95;false;true Gene Name;gene_name;String;g3;50;400;95;false;true -Experimental Method;experimental_method;String;g4;50;400;95;false;false GO Id;go_id;String;g2;50;400;95;false;false Assembly Id;assembly_id;String;g2;50;400;95;false;false Assembly Form;assembly_form;String;g6;50;400;95;false;false @@ -58,8 +79,8 @@ Interacting Entity Id;interacting_entity_id;String;g2;50;400;95;false;false Interacting Molecules;interacting_molecules;String;g6;50;400;95;false;false Pubmed Id;pubmed_id;int;g2;50;400;95;false;false Status;status;String;g6;50;400;95;false;false -Model Quality;model_quality;Double;g1;50;150;85;false;false -Pivot Resolution;pivot_resolution;Double;g1;50;150;85;false;false +Model Quality;model_quality;Double|T|2;g1;50;150;85;false;false +Pivot Resolution;pivot_resolution;Double|T|3;g1;50;150;85;false;false Data reduction software;data_reduction_software;String;g4;50;400;95;false;false Max observed residues;max_observed_residues;String;g6;50;400;95;false;false Organism scientific name;organism_scientific_name;String;g3;50;400;95;false;false @@ -86,7 +107,7 @@ Entry Authors;entry_authors;String;g6;50;400;95;false;false Citation Title;citation_title;String;g6;50;400;95;false;false Structure Solution Software;structure_solution_software;String;g4;50;400;95;false;false Entry Entity;entry_entity;String;g6;50;400;95;false;false -R Free;r_free;Double;g1;50;150;85;false;false +R Free;r_free;Double|T|3;g1;50;150;85;false;false Number of Polymer Entities;number_of_polymer_entities;int;g6;50;400;95;false;false Number of Bound Entities;number_of_bound_entities;int;g6;50;400;95;false;false Crystallisation Reservoir;crystallisation_reservoir;String;g6;50;400;95;false;false @@ -103,7 +124,7 @@ Synchrotron Beamline;synchrotron_beamline;String;g6;50;400;95;false;false Entity Id; entity_id;String;g2;50;400;95;false;false Beam Source Name;beam_source_name;String;g3;50;400;95;false;false Processing Site;processing_site;String;g6;50;400;95;false;false -Entity Weight;entity_weight;Double;g6;50;400;95;false;false -Version;_version_;String;g6;50;400;95;false;false +Entity Weight;entity_weight;Double|T|0;g6;50;400;95;false;false +Version;_version_;Double|F|0;g6;50;400;95;false;false ALL;text;String;g6;50;400;95;false;true # diff --git a/src/jalview/fts/api/FTSDataColumnI.java b/src/jalview/fts/api/FTSDataColumnI.java index 7741d73..80990b4 100644 --- a/src/jalview/fts/api/FTSDataColumnI.java +++ b/src/jalview/fts/api/FTSDataColumnI.java @@ -93,18 +93,18 @@ public interface FTSDataColumnI public boolean isVisibleByDefault(); /** - * Returns the data column's data type class + * Returns the data column's FTS data column group * - * @return the Class for the data column's data type + * @return the FTSDataColumnGroupI for the column */ - public Class getDataColumnClass(); + public FTSDataColumnGroupI getGroup(); /** - * Returns the data colum's FTS data column group + * Returns the data columns data type POJO * - * @return the FTSDataColumnGroupI for the column + * @return the DataTypeI for the column */ - public FTSDataColumnGroupI getGroup(); + public DataTypeI getDataType(); /** * This interface provides a model for the dynamic data column group @@ -133,4 +133,29 @@ public interface FTSDataColumnI */ public int getSortOrder(); } + + public interface DataTypeI + { + /** + * Returns the data column's data type class + * + * @return the Class for the data column's data type + */ + public Class getDataTypeClass(); + + /** + * Checks if the numeric data column's data will be formated + * + * @return true means the numeric data column shall be formatted + */ + public boolean isFormtted(); + + /** + * Returns the number of significant figure to be used for the numeric value + * formatting + * + * @return the number of significant figures + */ + public int getSignificantFigures(); + } } diff --git a/src/jalview/fts/core/DecimalFormatTableCellRenderer.java b/src/jalview/fts/core/DecimalFormatTableCellRenderer.java new file mode 100644 index 0000000..3642721 --- /dev/null +++ b/src/jalview/fts/core/DecimalFormatTableCellRenderer.java @@ -0,0 +1,60 @@ +package jalview.fts.core; + +import java.awt.Component; +import java.text.DecimalFormat; + +import javax.swing.JLabel; +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; + +/** + * The class to handle the formatting of the double values for JTable cells. + */ +public class DecimalFormatTableCellRenderer extends + DefaultTableCellRenderer +{ + private DecimalFormat formatter; + + public DecimalFormatTableCellRenderer(boolean isFormated, + int significantFigures) + { + String integerFormater = isFormated ? "###,##0" : "0"; + String fractionFormater = isFormated ? "###,##0." : "0."; + if (significantFigures > 0) + { + StringBuilder significantFigureBuilder = new StringBuilder(); + for (int x = 1; x <= significantFigures; ++x) + { + significantFigureBuilder.append("0"); + } + formatter = new DecimalFormat(fractionFormater + + significantFigureBuilder.toString()); + } + else + { + formatter = new DecimalFormat(integerFormater); + } + super.setHorizontalAlignment(JLabel.RIGHT); + } + + public DecimalFormatTableCellRenderer() + { + super.setHorizontalAlignment(JLabel.RIGHT); + } + + @Override + public Component getTableCellRendererComponent(JTable table, + Object value, boolean isSelected, boolean hasFocus, int row, + int column) + { + if (value == null) + { + return null; + } + + value = formatter.format(value); + + return super.getTableCellRendererComponent(table, value, isSelected, + hasFocus, row, column); + } +} \ No newline at end of file diff --git a/src/jalview/fts/core/FTSRestClient.java b/src/jalview/fts/core/FTSRestClient.java index 2f24a01..f2df461 100644 --- a/src/jalview/fts/core/FTSRestClient.java +++ b/src/jalview/fts/core/FTSRestClient.java @@ -143,21 +143,62 @@ public abstract class FTSRestClient implements FTSRestClientI } @Override - public Class getDataColumnClass() + public DataTypeI getDataType() { - String classString = lineData[2]; - classString = classString.toUpperCase(); - switch (classString) + final String[] dataTypeString = lineData[2].split("\\|"); + final String classString = dataTypeString[0].toUpperCase(); + + return new DataTypeI() { - case "INT": - case "INTEGER": - return Integer.class; - case "DOUBLE": - return Double.class; - case "STRING": - default: - return String.class; - } + + @Override + public boolean isFormtted() + { + if (dataTypeString.length > 1 + && dataTypeString[1] != null) + { + switch (dataTypeString[1].toUpperCase()) + { + case "T": + case "TRUE": + return true; + case "F": + case "False": + default: + return false; + } + } + return false; + } + + @Override + public int getSignificantFigures() + { + if (dataTypeString.length > 2 + && dataTypeString[2] != null) + { + return Integer.valueOf(dataTypeString[2]); + } + return 0; + } + + @Override + public Class getDataTypeClass() + { + switch (classString) + { + case "INT": + case "INTEGER": + return Integer.class; + case "DOUBLE": + return Double.class; + case "STRING": + default: + return String.class; + } + } + }; + } @Override @@ -228,6 +269,7 @@ public abstract class FTSRestClient implements FTSRestClientI && this.getGroup().equals(that.getGroup()); } + }; dataColumns.add(dataCol); diff --git a/src/jalview/fts/core/FTSRestResponse.java b/src/jalview/fts/core/FTSRestResponse.java index 6cce2c4..8078d43 100644 --- a/src/jalview/fts/core/FTSRestResponse.java +++ b/src/jalview/fts/core/FTSRestResponse.java @@ -107,7 +107,8 @@ public class FTSRestResponse { return String.class; } - return cols[columnIndex - colOffset].getDataColumnClass(); + return cols[columnIndex - colOffset].getDataType() + .getDataTypeClass(); } }; @@ -149,6 +150,20 @@ public class FTSRestResponse { e.printStackTrace(); } + if (wantedField.getDataType().getDataTypeClass() == Double.class) + { + DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer( + wantedField.getDataType().isFormtted(), + wantedField.getDataType().getSignificantFigures()); + tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr); + } + else if (wantedField.getDataType().getDataTypeClass() == Integer.class) + { + DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer( + wantedField.getDataType().isFormtted(), + wantedField.getDataType().getSignificantFigures()); + tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr); + } } }