Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for adding images with GUI #492

Merged
merged 2 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/widoco/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class Configuration {
*/
private boolean includeDiagram;

private Properties propertyFile = null;
private Properties propertyFile;

// Lode configuration parameters
private boolean useOwlAPI;
Expand Down Expand Up @@ -672,6 +672,12 @@ private void completeOntologyMetadata(OWLAnnotation a, OWLOntology o) {
value = WidocoUtils.getValueAsLiteralOrURI(a.getValue());
mainOntologyMetadata.setIncompatibleWith(value);
break;
case Constants.PROP_SCHEMA_IMAGE:
case Constants.PROP_FOAF_IMAGE:
case Constants.PROP_FOAF_DEPICTION:
value = WidocoUtils.getValueAsLiteralOrURI(a.getValue());
mainOntologyMetadata.addImage(value);
break;
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/main/java/widoco/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class Constants {
public static final String PROP_SCHEMA_URL = NS_SCHEMA + "url";
public static final String PROP_SCHEMA_EMAIL = NS_SCHEMA + "email";
public static final String PROP_SCHEMA_AFFILIATION = NS_SCHEMA + "affiliation";
public static final String PROP_SCHEMA_IMAGE = NS_SCHEMA + "image";

public static final String PROP_OWL_VERSION_INFO = NS_OWL + "versionInfo";
public static final String PROP_OWL_PRIOR_VERSION = NS_OWL + "priorVersion";
Expand Down Expand Up @@ -157,6 +158,8 @@ public class Constants {
public static final String PROP_FOAF_FAMILY_NAME = NS_FOAF + "familyName";
public static final String PROP_FOAF_MBOX = NS_FOAF + "mbox";
public static final String PROP_FOAF_HOME_PAGE = NS_FOAF + "homepage";
public static final String PROP_FOAF_IMAGE = NS_FOAF + "img";
public static final String PROP_FOAF_DEPICTION = NS_FOAF + "depiction";

public static final String PROP_ORG_MEMBER_OF = NS_ORG + "memberOf";

Expand Down Expand Up @@ -958,14 +961,18 @@ public static String getOverviewSectionTitleAndPlaceHolder(Configuration c, Prop
}

public static String getDescriptionSectionTitleAndPlaceHolder(Configuration c, Properties lang) {
return "<h2 id=\"desc\" class=\"list\">" + c.getMainOntology().getName() + ": "
String descriptionString = "<h2 id=\"desc\" class=\"list\">" + c.getMainOntology().getName() + ": "
+ lang.getProperty(LANG_DESCRIPTION_PLACEHOLDER) + "\n";
for (String image: c.getMainOntology().getImages()){
descriptionString += "<img src=\""+image+"\">";
}
return descriptionString;
}

public static String getCrossReferenceSectionTitleAndPlaceHolder(Configuration c, Properties lang) {
return "<h2 id=\"crossreference\" class=\"list\">" + lang.getProperty(LANG_CROSS_REF_TITLE) + " "
+ c.getMainOntology().getName() + " " + lang.getProperty(LANG_CROSS_REF_TITLE2) + "</h2>" + "\n"
+ lang.getProperty(LANG_CROSS_REF_PLACEHOLDER) + c.getMainOntology().getName() + ".\n";
+ lang.getProperty(LANG_CROSS_REF_PLACEHOLDER) +" "+ c.getMainOntology().getName() + ".\n";
}

public static String getProvenanceHtml(Configuration c, Properties lang) {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/widoco/entities/Ontology.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,20 @@ public class Ontology {
*/
private String incompatibleWith;

/**
* images used to illustrate the ontology
*/
private ArrayList<String> images;

public Ontology() {
this.images = new ArrayList<>();
}

public Ontology(String name, String namespacePrefix, String namespaceURI) {
this.name = name;
this.namespacePrefix = namespacePrefix;
this.namespaceURI = namespaceURI;
this.images = new ArrayList<>();
}

public String getName() {
Expand Down Expand Up @@ -340,4 +347,16 @@ public String getIncompatibleWith() {
public void setIncompatibleWith(String incompatibleWith) {
this.incompatibleWith = incompatibleWith;
}

public ArrayList<String> getImages(){
return images;
}

public void addImage(String image){
this.images.add(image);
}

public void setImages(ArrayList<String> images){
this.images = images;
}
}
82 changes: 29 additions & 53 deletions src/main/java/widoco/gui/EditProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public class EditProperty extends javax.swing.JFrame {

public enum PropertyType{authors, contributors, publisher, extended, imported, license};
public enum PropertyType{authors, contributors, publisher, extended, imported, license, image};
private final GuiStep2 step2Gui;
private final Configuration c;
private final PropertyType type;
Expand All @@ -40,7 +40,7 @@ public EditProperty(GuiStep2 g, Configuration c, PropertyType p) {
this.step2Gui = g;
this.c = c; //needed because for authors/contributors we are going to load additional stuff
this.type = p;
//The properties have to correspon to those in the config
//The properties have to correspond to those in the config
switch(type){
case authors:
this.setTitle("Editing Authors");
Expand Down Expand Up @@ -86,6 +86,13 @@ public EditProperty(GuiStep2 g, Configuration c, PropertyType p) {
createTable(new String[]{"License Name","License URI", "License Logo URL"});
loadLicense(c.getMainOntology().getLicense());
break;
case image:
this.setTitle("Editing Images");
this.addRowButton.setText("Add image...");
this.deleteRowButton.setText("Delete image...");
createTable(new String[]{"Image URL"});
loadImages(c.getMainOntology().getImages());
break;
}
}

Expand Down Expand Up @@ -122,6 +129,13 @@ private void loadLicense (License l){
this.addRowButton.setEnabled(false);
this.deleteRowButton.setEnabled(false);
}

private void loadImages(ArrayList<String> images) {
for(String img:images){
Object[] row = new Object[]{img};
((DefaultTableModel)tableProperties.getModel()).addRow(row);
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
Expand Down Expand Up @@ -247,6 +261,8 @@ private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
case imported:this.c.getMainOntology().setImportedOntologies(getOntologiesFromTable());
break;
case license:this.c.getMainOntology().setLicense(getLicenseFromTable());
break;
case image:this.c.getMainOntology().setImages(getImagesFromTable());
}
this.step2Gui.refreshPropertyTable();
this.dispose();
Expand Down Expand Up @@ -293,6 +309,17 @@ private License getLicenseFromTable() {
String licLogo = (String)tableProperties.getValueAt(0,2);
return new License(licURI, licName, licLogo);
}

private ArrayList<String> getImagesFromTable() {
ArrayList<String> images = new ArrayList<String>();
for(int row = 0;row < tableProperties.getRowCount();row++) {
String imageURL = (String)tableProperties.getValueAt(row, 0);
if(!imageURL.equals("") || !imageURL.equals("")){
images.add(imageURL);
}
}
return images;
}

private void deleteRowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteRowButtonActionPerformed
if(tableProperties.getSelectedRow()!=-1){
Expand All @@ -310,57 +337,6 @@ private void deleteRowButtonActionPerformed(java.awt.event.ActionEvent evt) {//G
private void deleteSelectedRow(int rowNumber){
((DefaultTableModel)tableProperties.getModel()).removeRow(rowNumber);
}
/**
* @param args the command line arguments
*/
// public static void main(String args[]) {
// /* Set the Nimbus look and feel */
// //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
// /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
// * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
// */
// try {
// for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
// if ("Nimbus".equals(info.getName())) {
// javax.swing.UIManager.setLookAndFeel(info.getClassName());
// break;
// }
// }
// } catch (ClassNotFoundException ex) {
// java.util.logging.Logger.getLogger(EditProperty.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// } catch (InstantiationException ex) {
// java.util.logging.Logger.getLogger(EditProperty.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// } catch (IllegalAccessException ex) {
// java.util.logging.Logger.getLogger(EditProperty.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// } catch (javax.swing.UnsupportedLookAndFeelException ex) {
// java.util.logging.Logger.getLogger(EditProperty.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// }
// //</editor-fold>
//
// /* Create and display the form */
// java.awt.EventQueue.invokeLater(new Runnable() {
// public void run() {
// Configuration config = new Configuration();
// Agent a = new Agent("Dani","http://bananen", "oeg","");
// Agent a2 = new Agent("Dani2","http://bananen", "oeg","");
// Agent a3 = new Agent("Dani3","http://bananen", "oeg","");
//
// Ontology o1 = new Ontology("blah", "ble","bli");
//
// ArrayList<Agent> creators = new ArrayList();
//
// creators.add(a);
// creators.add(a2);
// creators.add(a3);
//
// ArrayList<Ontology> onto = new ArrayList();
// onto.add(o1);
// config.setCreators(creators);
// config.setExtendedOntologies(onto);
// new EditProperty(null, config, PropertyType.extended).setVisible(true);
// }
// });
// }

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addRowButton;
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/widoco/gui/GuiStep2.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public void mouseClicked(java.awt.event.MouseEvent evt) {
form = new EditProperty(gAux, conf, EditProperty.PropertyType.imported);
} else if (prop.equals("license")) {
form = new EditProperty(gAux, conf, EditProperty.PropertyType.license);
} else if (prop.equals("images")) {
form = new EditProperty(gAux, conf, EditProperty.PropertyType.image);
}
if (form != null) {
gAux.saveMetadata();
Expand Down Expand Up @@ -165,7 +167,7 @@ public void stopLoadingAnimation() {
}

private void refreshTable() {
String authors = "", contributors = "", imported = "", extended = "", publisher = "";
String authors = "", contributors = "", imported = "", extended = "", publisher = "", images ="";
for (Agent a : conf.getMainOntology().getCreators()) {
if (a.getName() == null || a.getName().equals("")) {
authors += "creator; ";
Expand Down Expand Up @@ -202,6 +204,13 @@ private void refreshTable() {
} else {
publisher += p.getName();
}
for (String img: conf.getMainOntology().getImages()){
if(!img.equals("")){
images +=img + ";";
}else{
images +="image;";
}
}
tableProperties.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {
{ "abstract", conf.getAbstractSection() }, { "ontology title", conf.getMainOntology().getTitle() },
{ "ontology name", conf.getMainOntology().getName() },
Expand All @@ -217,7 +226,8 @@ private void refreshTable() {
{ "cite as", conf.getMainOntology().getCiteAs() }, { "doi", conf.getMainOntology().getDoi() },
{ "status", conf.getMainOntology().getStatus() },
{ "backwards compatible with", conf.getMainOntology().getBackwardsCompatibleWith() },
{ "incompatible with", conf.getMainOntology().getIncompatibleWith()} },
{ "incompatible with", conf.getMainOntology().getIncompatibleWith()},
{ "images", images }},
new String[] { "Property", "Value" }) {
Class[] types = new Class[] { java.lang.String.class, java.lang.Object.class };
boolean[] canEdit = new boolean[] { false, true };
Expand All @@ -234,6 +244,7 @@ public boolean isCellEditable(int rowIndex, int columnIndex) {
|| getValueAt(rowIndex, 0).equals("publisher")
|| ((String) getValueAt(rowIndex, 0)).toLowerCase().contains("extended")
|| ((String) getValueAt(rowIndex, 0)).toLowerCase().contains("license")
|| ((String) getValueAt(rowIndex, 0)).toLowerCase().contains("images")
|| ((String) getValueAt(rowIndex, 0)).toLowerCase().contains("imported")) {
return false;
}
Expand Down Expand Up @@ -370,14 +381,14 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {

labelSteps.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
labelSteps.setText("Steps");

tableProperties.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] { { "abstract", "" }, { "ontology title", null }, { "ontology name", null },
{ "ontology prefix", null }, { "ontology ns URI", null }, { "date of release", null },
{ "this version URI", null }, { "latest version URI", null }, { "previous version URI", null },
{ "ontology revision", null }, { "authors", null }, { "contributors", null },
{ "publisher", null }, { "imported ontologies", null }, { "extended ontologies", null },
{ "license", null }, { "cite as", null }, { "doi", null }, { "status", null } },
{ "license", null }, { "cite as", null }, { "doi", null }, { "status", null },
{ "backwards compatible with", null },{ "incompatible with", null }},
new String[] { "Property", "Value" }) {
Class[] types = new Class[] { java.lang.String.class, java.lang.Object.class };
boolean[] canEdit = new boolean[] { false, false };
Expand Down
2 changes: 2 additions & 0 deletions test/example_annotated.owl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<http://purl.org/dc/elements/1.1/title> "The example ontology"@en ;
<http://purl.org/dc/terms/created> "February 5th, 2020"@en ;
<http://purl.org/dc/terms/creator> "Maria Poveda-Villalon"@en ;
schema:image <https://knowledgecaptureanddiscovery.github.io/SoftwareDescriptionOntology/release/1.9.0/images/overviewSDv5.png>;
foaf:img "https://knowledgecaptureanddiscovery.github.io/SoftwareDescriptionOntology/release/1.9.0/images/overviewSDv5.png";
<http://purl.org/dc/terms/creator> [
foaf:name "Oscar Corcho";
foaf:mbox "mailto:[email protected]";
Expand Down