Skip to content

Commit

Permalink
Merge pull request #12 from argrecsys/dev
Browse files Browse the repository at this point in the history
Update Arg-IR solution
  • Loading branch information
ansegura7 authored Feb 15, 2022
2 parents 71cd53d + bb45a49 commit b74a7d7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
8 changes: 4 additions & 4 deletions code/ArgumentIR/src/es/uam/irg/ir/ArgumentIR.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public static void main(String[] args) {
showWinform();
}

/**
* Creates and displays the Argument-IR form.
*/
private static void showWinform() {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
Expand All @@ -48,10 +51,7 @@ private static void showWinform() {
/* Create and display the form */
java.awt.EventQueue.invokeLater(() -> {
FunctionUtils.printWithDatestamp(">> ARG-IR BEGINS");

ArgumentIRForm form = new ArgumentIRForm();
form.setVisible(true);

new ArgumentIRForm();
FunctionUtils.printWithDatestamp(">> ARG-IR ENDS");
});
}
Expand Down
8 changes: 7 additions & 1 deletion code/ArgumentIR/src/es/uam/irg/ir/gui/ArgumentIRForm.form
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</Menu>
</NonVisualComponents>
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="defaultCloseOperation" type="int" value="0"/>
<Property name="title" type="java.lang.String" value="Argument-enhanced Information Retrieval"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[800, 400]"/>
Expand Down Expand Up @@ -175,6 +175,12 @@
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JEditorPane" name="txtResult">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="contentType" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="HTML_CONTENT_TYPE" type="code"/>
</Property>
</Properties>
<Events>
<EventHandler event="hyperlinkUpdate" listener="javax.swing.event.HyperlinkListener" parameters="javax.swing.event.HyperlinkEvent" handler="txtResultHyperlinkUpdate"/>
</Events>
Expand Down
44 changes: 24 additions & 20 deletions code/ArgumentIR/src/es/uam/irg/ir/gui/ArgumentIRForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.text.BadLocationException;
Expand All @@ -53,10 +52,8 @@ public class ArgumentIRForm extends javax.swing.JFrame {
*/
public ArgumentIRForm() {
initComponents();
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.txtResult.setContentType(HTML_CONTENT_TYPE);
this.txtResult.setEditable(false);
this.model = new ArgumentIRModel(DECIMAL_FORMAT, DATE_FORMAT);
this.setVisible(true);
}

/**
Expand All @@ -73,6 +70,22 @@ private void closeForm() {
System.exit(0);
}

/**
*
* @param type
*/
private void exportReportToFile(String type) {
try {
String filepath = selectFileToExport(type);
String header = getReportHeader(type);
String text = header + (type.equals("html") ? this.txtResult.getText() : this.txtResult.getDocument().getText(0, this.txtResult.getDocument().getLength()));
FunctionUtils.writeStringToFile(filepath, text);

} catch (BadLocationException ex) {
Logger.getLogger(ArgumentIRForm.class.getName()).log(Level.SEVERE, null, ex);
}
}

/**
*
* @param type
Expand Down Expand Up @@ -166,7 +179,7 @@ private void initComponents() {

fileChooser.setDialogTitle("Export report");

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setTitle("Argument-enhanced Information Retrieval");
setMinimumSize(new java.awt.Dimension(800, 400));
addWindowListener(new java.awt.event.WindowAdapter() {
Expand All @@ -187,6 +200,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});

txtResult.setEditable(false);
txtResult.setContentType(HTML_CONTENT_TYPE);
txtResult.addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {
txtResultHyperlinkUpdate(evt);
Expand Down Expand Up @@ -333,10 +348,7 @@ private void mItemCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
*/
private void mItemExportHtmlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mItemExportHtmlActionPerformed
// TODO add your handling code here:
String filepath = selectExportFile("html");
String header = getReportHeader("html");
String html = header + this.txtResult.getText();
FunctionUtils.writeStringToFile(filepath, html);
exportReportToFile("html");
}//GEN-LAST:event_mItemExportHtmlActionPerformed

/**
Expand All @@ -345,16 +357,8 @@ private void mItemExportHtmlActionPerformed(java.awt.event.ActionEvent evt) {//G
* @param evt
*/
private void mItemExportTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mItemExportTextActionPerformed
try {
// TODO add your handling code here:
String filepath = selectExportFile("txt");
String header = getReportHeader("txt");
String text = header + this.txtResult.getDocument().getText(0, this.txtResult.getDocument().getLength());
FunctionUtils.writeStringToFile(filepath, text);

} catch (BadLocationException ex) {
Logger.getLogger(ArgumentIRForm.class.getName()).log(Level.SEVERE, null, ex);
}
// TODO add your handling code here:
exportReportToFile("txt");
}//GEN-LAST:event_mItemExportTextActionPerformed

/**
Expand Down Expand Up @@ -412,7 +416,7 @@ private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:even
*
* @return
*/
private String selectExportFile(String ext) {
private String selectFileToExport(String ext) {
String filepath = fileChooser.getCurrentDirectory() + "\\report N." + ext;
fileChooser.setSelectedFile(new java.io.File(filepath));
if (fileChooser.showDialog(this, "Save") == JFileChooser.APPROVE_OPTION) {
Expand Down
4 changes: 2 additions & 2 deletions code/ArgumentIR/src/es/uam/irg/ir/gui/ArgumentIRModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void updateModelLabel(String argumentId, String label) {
}

/**
*
* Creates an Apache Lucene index of the data.
*/
private void createIndex() {
FunctionUtils.printWithDatestamp(">> Creating Lucene index");
Expand All @@ -179,7 +179,7 @@ private void createIndex() {
}

/**
*
* Loads all data (proposals, comments, arguments, labels).
*/
private void loadData() {
try {
Expand Down

0 comments on commit b74a7d7

Please sign in to comment.