Skip to content

Commit

Permalink
Merge branch 'jfsanin_pull_request'
Browse files Browse the repository at this point in the history
  • Loading branch information
dj3500 committed Feb 19, 2017
2 parents efb3072 + c9e2ba2 commit 296dd83
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 19 deletions.
3 changes: 2 additions & 1 deletion Hightail/src/org/hightail/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ static protected void setIfUnset(String key, String value) {
}
}

static protected void fillInUnsetValuesWithDefaults() {
static public void fillInUnsetValuesWithDefaults() {
setIfUnset("workingDirectory", new File("").getAbsolutePath());
setIfUnset("pathFromWorkingDirToExec", "%P.exe");
// TODO: if under Unix, this better be "%L"
setIfUnset("prependingCommand", "");
setIfUnset("checkExistence", "1");
setIfUnset("putWholeName", "0");
}

static public boolean load() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.hightail.Config;
import org.hightail.Problem;
import org.hightail.SupportedSites;
import org.hightail.Testcase;
import org.hightail.TestcaseSet;
import org.hightail.util.ProblemNameFormatter;
import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.beans.FilterBean;
Expand Down Expand Up @@ -82,7 +84,13 @@ public Problem parse(String URL) throws ParserException, InterruptedException {
if (problemName.isEmpty()) {
throw new ParserException("Problem name not extracted (probably incorrect url).");
}
problemName = String.valueOf(problemName.charAt(0));

if (!Config.getBoolean("putWholeName")) {
problemName = String.valueOf(problemName.charAt(0));
} else {
// delete some annoying special characters that show up in the title
problemName = ProblemNameFormatter.getFormattedName(problemName);
}

if (Thread.interrupted()) {
throw new InterruptedException();
Expand Down
31 changes: 22 additions & 9 deletions Hightail/src/org/hightail/ui/ConfigJDialog.form
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.8" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<NonVisualComponents>
<Component class="javax.swing.ButtonGroup" name="optionNameGroup">
</Component>
</NonVisualComponents>
<Properties>
<Property name="defaultCloseOperation" type="int" value="0"/>
<Property name="title" type="java.lang.String" value="Settings"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="formWindowClosing"/>
Expand Down Expand Up @@ -44,8 +49,8 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="pathsAndDirectoriesPanel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="pathsAndDirectoriesPanel" max="32767" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="saveButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cancelButton" alignment="3" min="-2" max="-2" attributes="0"/>
Expand All @@ -68,7 +73,7 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
Expand All @@ -78,13 +83,13 @@
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="workingDirectoryBrowseButton" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="pathFromWorkingDirToExecLabel2" max="32767" attributes="0"/>
<Component id="pathFromWorkingDirToExecLabel2" pref="682" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="pathFromWorkingDirToExecLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="10" max="-2" attributes="0"/>
<Component id="pathFromWorkingDirToExecTextField" max="32767" attributes="0"/>
</Group>
<Component id="checkExistenceCheckBox" alignment="0" max="32767" attributes="0"/>
<Component id="jLabel4" alignment="0" pref="0" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
Expand All @@ -94,10 +99,11 @@
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="prependingCommandTextField" min="-2" pref="329" max="-2" attributes="0"/>
</Group>
<Component id="wholeNameCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Component id="jLabel4" alignment="0" pref="0" max="32767" attributes="0"/>
<Component id="checkExistenceCheckBox" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
Expand Down Expand Up @@ -130,9 +136,11 @@
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="checkExistenceCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="jLabel4" min="-2" pref="92" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="wholeNameCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="jLabel4" min="-2" pref="92" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand Down Expand Up @@ -196,6 +204,11 @@
<Property name="text" type="java.lang.String" value="&lt;html&gt;Setup tips for Java: let&apos;s say you keep the main class of your compiled solution to problem B at &quot;d:\u005calgo\u005ctaskB\u005cMain.class&quot;. In this case you want to execute &quot;java -classpath d:\u005calgo\u005ctaskB Main&quot;, so you should set the working directory to &quot;d:\u005calgo&quot;, path from working directory to executable to &quot;task%P Main&quot; and the prepending command to &quot;java -classpath&quot;. If you had just &quot;d:\u005calgo\u005cMain.class&quot;, you would need to set the path from working directory to executable to &quot; Main&quot; (note the space at the beginning).&lt;br&gt;You must also uncheck &quot;check whether executable file exists&quot;." containsInvalidXMLChars="true"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="wholeNameCheckBox">
<Properties>
<Property name="text" type="java.lang.String" value="In CodeForces, use the problem&apos;s full name (instead of first letter), like B. Sereja and numbers"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="saveButton">
Expand Down
31 changes: 23 additions & 8 deletions Hightail/src/org/hightail/ui/ConfigJDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public ConfigJDialog(JFrame parent) {
prependingCommandTextField.setText(Config.get("prependingCommand"));

checkExistenceCheckBox.setSelected(Config.getBoolean("checkExistence"));

wholeNameCheckBox.setSelected(Config.getBoolean("putWholeName"));
}

/** This method is called from within the constructor to
Expand All @@ -52,6 +54,7 @@ public ConfigJDialog(JFrame parent) {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

optionNameGroup = new javax.swing.ButtonGroup();
pathsAndDirectoriesPanel = new javax.swing.JPanel();
workingDirectoryLabel = new javax.swing.JLabel();
workingDirectoryTextField = new javax.swing.JTextField();
Expand All @@ -65,6 +68,7 @@ private void initComponents() {
prependingCommandTextField = new javax.swing.JTextField();
checkExistenceCheckBox = new javax.swing.JCheckBox();
jLabel4 = new javax.swing.JLabel();
wholeNameCheckBox = new javax.swing.JCheckBox();
saveButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();

Expand Down Expand Up @@ -103,6 +107,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {

jLabel4.setText("<html>Setup tips for Java: let's say you keep the main class of your compiled solution to problem B at \"d:\\algo\\taskB\\Main.class\". In this case you want to execute \"java -classpath d:\\algo\\taskB Main\", so you should set the working directory to \"d:\\algo\", path from working directory to executable to \"task%P Main\" and the prepending command to \"java -classpath\". If you had just \"d:\\algo\\Main.class\", you would need to set the path from working directory to executable to \" Main\" (note the space at the beginning).<br>You must also uncheck \"check whether executable file exists\".");

wholeNameCheckBox.setText("In CodeForces, use the problem's full name (instead of first letter), like B. Sereja and numbers");

javax.swing.GroupLayout pathsAndDirectoriesPanelLayout = new javax.swing.GroupLayout(pathsAndDirectoriesPanel);
pathsAndDirectoriesPanel.setLayout(pathsAndDirectoriesPanelLayout);
pathsAndDirectoriesPanelLayout.setHorizontalGroup(
Expand All @@ -116,22 +122,23 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(workingDirectoryTextField)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(workingDirectoryBrowseButton))
.addComponent(pathFromWorkingDirToExecLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pathFromWorkingDirToExecLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 682, Short.MAX_VALUE)
.addGroup(pathsAndDirectoriesPanelLayout.createSequentialGroup()
.addComponent(pathFromWorkingDirToExecLabel)
.addGap(10, 10, 10)
.addComponent(pathFromWorkingDirToExecTextField))
.addComponent(checkExistenceCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(pathsAndDirectoriesPanelLayout.createSequentialGroup()
.addGroup(pathsAndDirectoriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel3)
.addGroup(pathsAndDirectoriesPanelLayout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(prependingCommandTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 329, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(prependingCommandTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 329, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(wholeNameCheckBox))
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addComponent(checkExistenceCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
pathsAndDirectoriesPanelLayout.setVerticalGroup(
Expand All @@ -158,9 +165,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(checkExistenceCheckBox)
.addGap(18, 18, 18)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(wholeNameCheckBox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);

saveButton.setText("Save settings");
Expand Down Expand Up @@ -195,8 +204,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(pathsAndDirectoriesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pathsAndDirectoriesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(saveButton)
.addComponent(cancelButton))
Expand Down Expand Up @@ -238,6 +247,9 @@ private boolean unsavedChanges() {
if (Config.getBoolean("checkExistence") != checkExistenceCheckBox.isSelected()) {
return true;
}
if (Config.getBoolean("putWholeName") != wholeNameCheckBox.isSelected()) {
return true;
}
return false;
}

Expand Down Expand Up @@ -273,6 +285,7 @@ private void save() {
Config.set("pathFromWorkingDirToExec", pathFromWorkingDirToExecTextField.getText());
Config.set("prependingCommand", prependingCommandTextField.getText());
Config.setBoolean("checkExistence", checkExistenceCheckBox.isSelected());
Config.setBoolean("putWholeName", wholeNameCheckBox.isSelected());
try {
Config.save();
JOptionPane.showMessageDialog(this, "The configuration file has been saved.");
Expand Down Expand Up @@ -304,12 +317,14 @@ private void workingDirectoryBrowseButtonActionPerformed(java.awt.event.ActionEv
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.ButtonGroup optionNameGroup;
private javax.swing.JLabel pathFromWorkingDirToExecLabel;
private javax.swing.JLabel pathFromWorkingDirToExecLabel2;
private javax.swing.JTextField pathFromWorkingDirToExecTextField;
private javax.swing.JPanel pathsAndDirectoriesPanel;
private javax.swing.JTextField prependingCommandTextField;
private javax.swing.JButton saveButton;
private javax.swing.JCheckBox wholeNameCheckBox;
private javax.swing.JButton workingDirectoryBrowseButton;
private javax.swing.JLabel workingDirectoryLabel;
private javax.swing.JTextField workingDirectoryTextField;
Expand Down
12 changes: 12 additions & 0 deletions Hightail/src/org/hightail/util/ProblemNameFormatter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.hightail.util;

/**
*
* @author Joseph
*/
public class ProblemNameFormatter {
// gets rid of weird special characters
public static String getFormattedName (String originalName) {
return originalName.replaceAll("[^A-Za-z0-9 ._-]", "");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.hightail.parsers.task;

import org.hightail.Config;
import org.hightail.Problem;
import org.hightail.SupportedSites;
import org.htmlparser.util.ParserException;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Joseph
*/
public class CodeForcesTaskParserTest {

private final String URL = "http://codeforces.com/problemset/problem/744/E";
private final String COMPLETE_PROBLEM_NAME = "E. Hongcow Masters the Cyclic Shift";
private final String SHORT_PROBLEM_NAME = "E";


@BeforeClass
public static void setUpClass() {
Config.fillInUnsetValuesWithDefaults();
}

/**
* Putting the first problem's name letter as the name of the problem
*/
@Test
public void testParseShortName() {
try {
TaskParser parser = SupportedSites.getTaskParser(URL);
Problem problem = parser.parse(URL);
assertEquals(SHORT_PROBLEM_NAME, problem.getName());
} catch (ParserException ex) {
fail("thrown exception ParserException");
} catch (InterruptedException ex) {
fail("thrown exception InterruptedException");
}
}

/**
* Putting the whole problem's name as the name of the problem
*/
@Test
public void testParseWholeName() {
try {
Config.setBoolean("putWholeName", true);
TaskParser parser = SupportedSites.getTaskParser(URL);
Problem problem = parser.parse(URL);
assertEquals(COMPLETE_PROBLEM_NAME, problem.getName());
} catch (ParserException ex) {
fail("thrown exception ParserException");
} catch (InterruptedException ex) {
fail("thrown exception InterruptedException");
}
}

}
26 changes: 26 additions & 0 deletions Hightail/test/org/hightail/util/ProblemNameFormatterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.hightail.util;

import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Joseph
*/
public class ProblemNameFormatterTest {
private final String PROBLEM_NAME_A = "E. 09 - _ .test";
private final String PROBLEM_NAME_B = "+T?E]S'T";
private final String PROBLEM_NAME_EXPECTED_B = "TEST";

@Test
public void testGetFormattedNameAllowedCharacters() {
String formattedName = ProblemNameFormatter.getFormattedName(PROBLEM_NAME_A);
assertEquals(PROBLEM_NAME_A, formattedName);
}

@Test
public void testGetFormattedNameNotAllowedCharacters() {
String formattedName = ProblemNameFormatter.getFormattedName(PROBLEM_NAME_B);
assertEquals(PROBLEM_NAME_EXPECTED_B, formattedName);
}
}

0 comments on commit 296dd83

Please sign in to comment.