import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
private Map<String, FeatureMatcherSetI> originalFilters;
+ private List<String> originalVisibleGroups;
+
+ private List<String> originalHiddenGroups;
+
final JInternalFrame frame;
JScrollPane scrollPane = new JScrollPane();
originalFilters = new HashMap<>(fr.getFeatureFilters()); // shallow copy
+ originalVisibleGroups = new ArrayList<>(fr.getGroups(true));
+
+ originalHiddenGroups = new ArrayList<>(fr.getGroups(false));
+
try
{
jbInit();
@Override
public void actionPerformed(ActionEvent e)
{
- fr.setTransparency(originalTransparency);
- fr.setFeatureFilters(originalFilters);
- updateFeatureRenderer(originalData);
- close();
+ cancel();
}
});
this.add(settingsPane);
}
+ /**
+ * Restores feature type and group visibility, and any filters and
+ * transparency setting, to the values when this dialog was opened. Note this
+ * won't affect any feature types or groups which were added while the dialog
+ * was open.
+ */
+ void cancel()
+ {
+ fr.setTransparency(originalTransparency);
+ fr.setFeatureFilters(originalFilters);
+ fr.setGroupVisibility(originalVisibleGroups, true);
+ fr.setGroupVisibility(originalHiddenGroups, false);
+ updateFeatureRenderer(originalData);
+ close();
+ }
+
// ///////////////////////////////////////////////////////////////////////
// http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
// ///////////////////////////////////////////////////////////////////////
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
}
/**
- * get visible or invisible groups
+ * Answers a (possibly empty) list of visible or invisible feature groups
*
* @param visible
- * true to return visible groups, false to return hidden ones.
- * @return list of groups
+ * true to return visible groups, false to return hidden ones
+ * @return
*/
@Override
public List<String> getGroups(boolean visible)
{
+ List<String> groups = new ArrayList<>();
if (featureGroups != null)
{
- List<String> gp = new ArrayList<>();
-
- for (String grp : featureGroups.keySet())
+ for (Entry<String, Boolean> grp : featureGroups.entrySet())
{
- Boolean state = featureGroups.get(grp);
- if (state.booleanValue() == visible)
+ if (grp.getValue() == visible)
{
- gp.add(grp);
+ groups.add(grp.getKey());
}
}
- return gp;
}
- return null;
+ return groups;
}
@Override