Skip to content

Commit

Permalink
small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mukoki committed Mar 19, 2022
1 parent 6640d90 commit 1a50fe2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
11 changes: 6 additions & 5 deletions src/org/openjump/core/ui/plugin/queries/Function.java
Expand Up @@ -12,7 +12,7 @@

public class Function {
/** Function key is fully internationalized*/
private String key;
private final String key;

/** Returned type : B=boolean, N=numeric, S=string, E=enumeration, G=geometric*/
public char type;
Expand Down Expand Up @@ -93,10 +93,11 @@ public Function(String key, char type, double arg) {
}

public String toString() {
StringBuffer sb = new StringBuffer(I18N.getInstance().get("org.openjump.core.ui.plugin.queries.Function."+key));
if(this==BUFF) {return sb.toString() + " ("+arg+")";}
else if (this==SUBS && args.length==1) {return sb.toString() + " ("+args[0] + ")";}
else if (this==SUBS && args.length==2) {return sb.toString() + " ("+args[0]+","+args[1]+")";}
StringBuilder sb = new StringBuilder(I18N.getInstance()
.get("org.openjump.core.ui.plugin.queries.Function." + key));
if(this==BUFF) {return sb + " ("+arg+")";}
else if (this==SUBS && args.length==1) {return sb + " ("+args[0] + ")";}
else if (this==SUBS && args.length==2) {return sb + " ("+args[0]+","+args[1]+")";}
else {return sb.toString();}
}

Expand Down
60 changes: 26 additions & 34 deletions src/org/openjump/core/ui/plugin/queries/QueryDialog.java
Expand Up @@ -11,6 +11,7 @@
import com.vividsolutions.jump.workbench.model.*;
import com.vividsolutions.jump.workbench.plugin.PlugInContext;
import com.vividsolutions.jump.workbench.ui.*;
import org.locationtech.jts.geom.Geometry;

import javax.swing.*;
import javax.swing.border.Border;
Expand Down Expand Up @@ -42,7 +43,7 @@ public class QueryDialog extends BDialog {

private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat();

private PlugInContext context;
private final PlugInContext context;

// List of layers to search
List<Layer> layers = new ArrayList<>();
Expand All @@ -64,8 +65,8 @@ public class QueryDialog extends BDialog {
private static boolean runningQuery = false;
private static boolean cancelQuery = false;

// selected features initialized in execute query if "select" option is true
Collection selection;
// selected items initialized in execute query if "select" option is true
Collection<Geometry> selection;

BCheckBox charFilter;
BCheckBox caseSensitive;
Expand Down Expand Up @@ -244,27 +245,28 @@ private void initUI(PlugInContext context) {
layerCB = new BComboBox();
layerCB.addEventLink(ValueChangedEvent.class, this, "layerChanged");
queryConstructorPanel.add(layerCB, 1, 0, leftAlign);
// mmichaud 2008-11-13 limit the width to about 40 chars
((javax.swing.JComboBox)layerCB.getComponent())
// mmichaud 2008-11-13 limit the width to about 32 chars
layerCB.getComponent()
.setPrototypeDisplayValue("012345678901234567890123456789O1");
attributeCB = new BComboBox();
attributeCB.addEventLink(ValueChangedEvent.class, this, "attributeChanged");
queryConstructorPanel.add(attributeCB, 1, 1, leftAlign);
// mmichaud 2008-11-13 limit the width to about 40 chars
((javax.swing.JComboBox)attributeCB.getComponent())
// mmichaud 2008-11-13 limit the width to about 32 chars
attributeCB.getComponent()
.setPrototypeDisplayValue("01234567890123456789012345678901");
functionCB = new BComboBox();
functionCB.addEventLink(ValueChangedEvent.class, this, "functionChanged");
queryConstructorPanel.add(functionCB, 1, 2, leftAlignShort);

functionCB.getComponent().setPrototypeDisplayValue("012345678901234567890123");
operatorCB = new BComboBox();
operatorCB.addEventLink(ValueChangedEvent.class, this, "operatorChanged");
queryConstructorPanel.add(operatorCB, 1, 3, leftAlignShort);
operatorCB.getComponent().setPrototypeDisplayValue("012345678901234567890123");
valueCB = new BComboBox();
valueCB.addEventLink(ValueChangedEvent.class, this, "valueChanged");
queryConstructorPanel.add(valueCB, 1, 4, leftAlign);
// mmichaud 2008-11-13 limit the width to about 40 chars
((javax.swing.JComboBox)valueCB.getComponent())
// mmichaud 2008-11-13 limit the width to about 48 chars
valueCB.getComponent()
.setPrototypeDisplayValue("012345678901234567890123456789012345678901234567");

comments = new BLabel("<html>&nbsp;<br>&nbsp;</html>");
Expand Down Expand Up @@ -349,7 +351,7 @@ void initComboBoxes() {
for (Layer layer : layers) {
layerCB.add(layer);
}
((javax.swing.JComboBox)layerCB.getComponent()).setRenderer(layerListCellRenderer);
layerCB.getComponent().setRenderer(layerListCellRenderer);
this.layers = layers;
this.attributes = authorizedAttributes(layers);
attributeType = 'G';
Expand Down Expand Up @@ -432,8 +434,7 @@ private Set<String> authorizedAttributes(List<Layer> layers) {
}

private void charFilterChanged() {
if (charFilter.getState()) caseSensitive.setVisible(true);
else caseSensitive.setVisible(false);
caseSensitive.setVisible(charFilter.getState());
layerChanged();
}

Expand Down Expand Up @@ -502,7 +503,6 @@ private void updateFunctions() {
private void functionChanged() {
// if function is edited to change the parameter value by hand (buffer),
// functionCB.getSelectedValue() class changes from Function to String
//String ft = functionCB.getSelectedValue().toString();
try {
if (functionCB.getSelectedValue() instanceof Function) {
Function newfunction = (Function)functionCB.getSelectedValue();
Expand All @@ -512,15 +512,12 @@ private void functionChanged() {
updateValues();
}
function = (Function)functionCB.getSelectedValue();
if (function == Function.SUBS || function == Function.BUFF) {
functionCB.setEditable(true);
}
else functionCB.setEditable(false);
boolean editable = function == Function.SUBS || function == Function.BUFF;
functionCB.setEditable(editable);
}
else if (functionCB.getSelectedValue() instanceof String) {
// SET IF FUNCTION IS EDITABLE OR NOT
if(function==Function.SUBS) {
//functionCB.setEditable(true);
String f = functionCB.getSelectedValue().toString();
String sub = f.substring(f.lastIndexOf('(')+1, f.lastIndexOf(')'));
String[] ss = sub.split(",");
Expand All @@ -530,7 +527,6 @@ else if (functionCB.getSelectedValue() instanceof String) {
functionCB.setSelectedValue(Function.SUBS);
}
else if(function==Function.BUFF) {
//functionCB.setEditable(true);
String f = functionCB.getSelectedValue().toString();
String sub = f.substring(f.lastIndexOf('(')+1, f.lastIndexOf(')'));
Function.BUFF.arg = Double.parseDouble(sub);
Expand Down Expand Up @@ -584,12 +580,8 @@ private boolean operatorChanged() {
updateValues();
}
operator = newop;
if (operator == Operator.WDIST || operator == Operator.RELAT) {
operatorCB.setEditable(true);
}
else {
operatorCB.setEditable(false);
}
boolean editable = operator == Operator.WDIST || operator == Operator.RELAT;
operatorCB.setEditable(editable);
}
if (operatorCB.getSelectedValue() instanceof String) {
if (operator==Operator.WDIST) {
Expand All @@ -609,7 +601,7 @@ private boolean operatorChanged() {
// added on 2013-06-28
else if (operator==Operator.RELAT) {
String f = operatorCB.getSelectedValue().toString();
Pattern regex = Pattern.compile(".*\\(([012TFtf\\*]{9})\\)");
Pattern regex = Pattern.compile(".*\\(([012TFtf*]{9})\\)");
Matcher matcher = regex.matcher(f);
if (matcher.matches()) {
Operator.RELAT.arg = matcher.group(1);
Expand Down Expand Up @@ -692,15 +684,15 @@ private List<String> availableTargets() {
}

// attribute must be f type String
private Set availableStrings(String attribute, int maxsize) {
private Set<String> availableStrings(String attribute, int maxsize) {
Set<String> set = new TreeSet<>();
set.add("");
for (Layer layer : layers) {
FeatureCollection fc = layer.getFeatureCollectionWrapper();
if (!fc.getFeatureSchema().hasAttribute(attribute)) continue;
Iterator it = fc.iterator();
while (it.hasNext() && set.size()<maxsize) {
Feature f = (Feature)it.next();
Iterator<Feature> it = fc.iterator();
while (it.hasNext() && set.size() < maxsize) {
Feature f = it.next();
set.add(f.getString(attribute));
}
}
Expand Down Expand Up @@ -743,7 +735,7 @@ private void open() {
}
layerChanged();

int attributeIndex = Integer.parseInt(prop.getProperty("attribute_index"));
//int attributeIndex = Integer.parseInt(prop.getProperty("attribute_index"));
String attributeName = prop.getProperty("attribute_name");
attributeCB.setSelectedValue(attributeName);
if(!attributeName.equals(attributeCB.getSelectedValue().toString())) {
Expand Down Expand Up @@ -971,7 +963,7 @@ public void run() {
outputLayerName, dataset
);
}
if(display.getState()) {
if(display.getState() && info != null) {
info.getModel().add(layer, okFeatures);
}

Expand All @@ -997,7 +989,7 @@ public void run() {
selection = context.getLayerViewPanel().getSelectionManager().getSelectedItems();
}

if(display.getState()) {
if(display.getState() && info != null) {
info.pack();
context.getWorkbenchFrame().addInternalFrame(info);
}
Expand Down

0 comments on commit 1a50fe2

Please sign in to comment.