Skip to content

Commit

Permalink
Added config entry for parsing URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsegbert committed Feb 12, 2015
1 parent 123d81e commit bf89153
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 19 deletions.
3 changes: 2 additions & 1 deletion META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
<li>Added config to Settings -> Other Settings:</li>
<ul>
<li>Limit the matching of very long lines by a specific length. This may increase performance.</li>
<li>Continue matching after the limit chunk by chunk, so links after the limit may also be found.</li>
<li>Continue matching after the limit chunk by chunk, so links after the limit may also be found. This affects performance.</li>
<li>Match URLs (file, ftp, http(s)). Unchecking may increase performance.</li>
</ul>
</ul>
<b>0.1337.3</b><br/>
Expand Down
4 changes: 3 additions & 1 deletion src/awesome/console/AwesomeLinkFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public Result applyFilter(final String line, final int endPoint) {
final List<String> chunks = splitLine(line);
int offset = 0;
for (final String chunk : chunks) {
results.addAll(getResultItemsUrl(chunk, startPoint + offset));
if (config.SEARCH_URLS) {
results.addAll(getResultItemsUrl(chunk, startPoint + offset));
}
results.addAll(getResultItemsFile(chunk, startPoint + offset));
offset += chunk.length();
}
Expand Down
14 changes: 7 additions & 7 deletions src/awesome/console/config/AwesomeConsoleConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
}
)
public class AwesomeConsoleConfig implements PersistentStateComponent<AwesomeConsoleConfig>, Configurable, ApplicationComponent {
public static final boolean DEFAULT_SPLIT_ON_LIMIT = false;
public static final boolean DEFAULT_LIMIT_LINE_LENGTH = true;
public static final int DEFAULT_LINE_MAX_LENGTH = 1024;

public boolean SPLIT_ON_LIMIT = false;
public boolean LIMIT_LINE_LENGTH = true;
public int LINE_MAX_LENGTH = 1024;
public boolean SEARCH_URLS = true;

@Transient
private AwesomeConsoleConfigForm form;
Expand Down Expand Up @@ -56,6 +53,7 @@ private void initFromConfig() {
form.maxLengthTextField.setText(String.valueOf(LINE_MAX_LENGTH));
form.maxLengthTextField.setEditable(LIMIT_LINE_LENGTH);
form.matchLinesLongerThanCheckBox.setSelected(SPLIT_ON_LIMIT);
form.searchForURLsFileCheckBox.setSelected(SEARCH_URLS);

form.maxLengthTextField.setEnabled(LIMIT_LINE_LENGTH);
form.maxLengthTextField.setEditable(LIMIT_LINE_LENGTH);
Expand Down Expand Up @@ -95,15 +93,16 @@ public boolean isModified() {
if (text.length() < 1) {
return true;
}
int len = -1;
int len;
try {
len = Integer.parseInt(text);
} catch (NumberFormatException nfe) {
return true;
}
return form.limitLineMatchingByCheckBox.isSelected() != LIMIT_LINE_LENGTH
|| len != LINE_MAX_LENGTH
|| form.matchLinesLongerThanCheckBox.isSelected() != SPLIT_ON_LIMIT;
|| form.matchLinesLongerThanCheckBox.isSelected() != SPLIT_ON_LIMIT
|| form.searchForURLsFileCheckBox.isSelected() != SEARCH_URLS;
}

@Override
Expand All @@ -113,7 +112,7 @@ public void apply() throws ConfigurationException {
showErrorDialog();
return;
}
int i = -1;
int i;
try {
i = Integer.parseInt(text);
} catch (NumberFormatException nfe) {
Expand All @@ -127,6 +126,7 @@ public void apply() throws ConfigurationException {
LIMIT_LINE_LENGTH = form.limitLineMatchingByCheckBox.isSelected();
LINE_MAX_LENGTH = i;
SPLIT_ON_LIMIT = form.matchLinesLongerThanCheckBox.isSelected();
SEARCH_URLS = form.searchForURLsFileCheckBox.isSelected();
loadState(this);
}

Expand Down
22 changes: 15 additions & 7 deletions src/awesome/console/config/AwesomeConsoleConfigForm.form
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<grid id="27dc6" binding="mainpanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
<xy x="20" y="20" width="605" height="400"/>
</constraints>
<properties/>
<border type="none"/>
Expand All @@ -17,7 +17,7 @@
<text value="Awesome Console Config"/>
</properties>
</component>
<grid id="1a8bc" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="1a8bc" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand All @@ -27,28 +27,28 @@
<children>
<component id="75378" class="javax.swing.JCheckBox" binding="limitLineMatchingByCheckBox" custom-create="true" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Limit line matching by"/>
</properties>
</component>
<vspacer id="c4d64">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="b5933" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="chars."/>
</properties>
</component>
<component id="c1442" class="javax.swing.JFormattedTextField" binding="maxLengthTextField" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
Expand All @@ -58,12 +58,20 @@
</component>
<component id="e75fa" class="javax.swing.JCheckBox" binding="matchLinesLongerThanCheckBox" custom-create="true" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Match lines longer than the limit chunk by chunk."/>
</properties>
</component>
<component id="8b692" class="javax.swing.JCheckBox" binding="searchForURLsFileCheckBox" custom-create="true" default-binding="true">
<constraints>
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Match URLs (file, ftp, http(s))."/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
29 changes: 26 additions & 3 deletions src/awesome/console/config/AwesomeConsoleConfigForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
import java.text.DecimalFormat;

public class AwesomeConsoleConfigForm {
private static final boolean DEFAULT_SPLIT_ON_LIMIT = false;
private static final boolean DEFAULT_LIMIT_LINE_LENGTH = true;
private static final int DEFAULT_LINE_MAX_LENGTH = 1024;
private static final boolean DEFAULT_SEARCH_URLS = true;

public JPanel mainpanel;
public JCheckBox limitLineMatchingByCheckBox;
public JFormattedTextField maxLengthTextField;
public JCheckBox matchLinesLongerThanCheckBox;
public JCheckBox searchForURLsFileCheckBox;

private void createUIComponents() {
setupLineLimit();
setupSplitLineIntoChunk();
setupMatchURLs();
}

private void setupLineLimit() {
Expand Down Expand Up @@ -45,10 +52,10 @@ public void actionPerformed(final ActionEvent e) {
itm.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
maxLengthTextField.setText(String.valueOf(AwesomeConsoleConfig.DEFAULT_LINE_MAX_LENGTH));
maxLengthTextField.setText(String.valueOf(DEFAULT_LINE_MAX_LENGTH));
maxLengthTextField.setEnabled(true);
maxLengthTextField.setEditable(true);
limitLineMatchingByCheckBox.setSelected(AwesomeConsoleConfig.DEFAULT_LIMIT_LINE_LENGTH);
limitLineMatchingByCheckBox.setSelected(DEFAULT_LIMIT_LINE_LENGTH);
matchLinesLongerThanCheckBox.setEnabled(true);
}
});
Expand All @@ -65,7 +72,23 @@ private void setupSplitLineIntoChunk() {
itm.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
matchLinesLongerThanCheckBox.setSelected(AwesomeConsoleConfig.DEFAULT_SPLIT_ON_LIMIT);
matchLinesLongerThanCheckBox.setSelected(DEFAULT_SPLIT_ON_LIMIT);
}
});
}

private void setupMatchURLs() {
searchForURLsFileCheckBox = new JCheckBox("searchForURLsFileCheckBox");
searchForURLsFileCheckBox.setToolTipText("Uncheck if you do not want URLs parsed from the console.");
JPopupMenu popup = new JPopupMenu("Defaults");
searchForURLsFileCheckBox.setComponentPopupMenu(popup);

final JMenuItem itm = popup.add("Restore defaults");
itm.setMnemonic(KeyEvent.VK_R);
itm.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
searchForURLsFileCheckBox.setSelected(DEFAULT_SEARCH_URLS);
}
});
}
Expand Down

0 comments on commit bf89153

Please sign in to comment.