Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Mollik2019-04-25 08:47:53 -0400
committerRalf Mollik2019-04-25 08:47:53 -0400
commitb3e6329f762b49adcdb787ece573dd9f66deeed9 (patch)
tree9ce462128c08e25fca45f27dbc9ab525207b6bd3
parentba7350b9b5142dfc44ce1ba10484a3bfe98f8830 (diff)
downloadorg.eclipse.osbp.fork.mihalis.opal.imageSelector.osgi-b3e6329f762b49adcdb787ece573dd9f66deeed9.tar.gz
org.eclipse.osbp.fork.mihalis.opal.imageSelector.osgi-b3e6329f762b49adcdb787ece573dd9f66deeed9.tar.xz
org.eclipse.osbp.fork.mihalis.opal.imageSelector.osgi-b3e6329f762b49adcdb787ece573dd9f66deeed9.zip
enable image selector to filter the icons by the first char of their name
Signed-off-by: Ralf Mollik <ramollik@compex-commerce.com>
-rw-r--r--org.eclipse.osbp.fork.mihalis.opal.imageSelector.osgi/src/org/eclipse/osbp/fork/mihalis/opal/imageSelector/ISItem.java11
-rw-r--r--org.eclipse.osbp.fork.mihalis.opal.imageSelector.osgi/src/org/eclipse/osbp/fork/mihalis/opal/imageSelector/ImageSelector.java47
2 files changed, 34 insertions, 24 deletions
diff --git a/org.eclipse.osbp.fork.mihalis.opal.imageSelector.osgi/src/org/eclipse/osbp/fork/mihalis/opal/imageSelector/ISItem.java b/org.eclipse.osbp.fork.mihalis.opal.imageSelector.osgi/src/org/eclipse/osbp/fork/mihalis/opal/imageSelector/ISItem.java
index c9b892b..807edc4 100644
--- a/org.eclipse.osbp.fork.mihalis.opal.imageSelector.osgi/src/org/eclipse/osbp/fork/mihalis/opal/imageSelector/ISItem.java
+++ b/org.eclipse.osbp.fork.mihalis.opal.imageSelector.osgi/src/org/eclipse/osbp/fork/mihalis/opal/imageSelector/ISItem.java
@@ -13,21 +13,15 @@ package org.eclipse.osbp.fork.mihalis.opal.imageSelector;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
import java.net.URL;
import org.apache.commons.io.FilenameUtils;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.mihalis.opal.OpalItem;
-import org.osgi.framework.Bundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.eclipse.osbp.fork.mihalis.opal.imageSelector.ISItem;
/**
* Instances of this class represents items manipulated by the ImageSelector
@@ -190,8 +184,9 @@ public class ISItem extends OpalItem implements Comparable<ISItem> {
*/
@Override
public int compareTo(final ISItem o) {
- return new Double(Math.abs(this.zPosition)).compareTo(Math.abs(o
- .getzPosition())) * -1;
+// return new Double(Math.abs(this.zPosition)).compareTo(Math.abs(o
+// .getzPosition())) * -1;
+ return this.getText().compareTo(o.getText());
}
/**
diff --git a/org.eclipse.osbp.fork.mihalis.opal.imageSelector.osgi/src/org/eclipse/osbp/fork/mihalis/opal/imageSelector/ImageSelector.java b/org.eclipse.osbp.fork.mihalis.opal.imageSelector.osgi/src/org/eclipse/osbp/fork/mihalis/opal/imageSelector/ImageSelector.java
index c114c0b..69dd4a5 100644
--- a/org.eclipse.osbp.fork.mihalis.opal.imageSelector.osgi/src/org/eclipse/osbp/fork/mihalis/opal/imageSelector/ImageSelector.java
+++ b/org.eclipse.osbp.fork.mihalis.opal.imageSelector.osgi/src/org/eclipse/osbp/fork/mihalis/opal/imageSelector/ImageSelector.java
@@ -15,24 +15,17 @@ import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URI;
-import java.net.URL;
//import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-
-
-
import java.util.Set;
-
-
-
//import org.eclipse.core.internal.runtime.PlatformURLConverter;
import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
+import org.eclipse.osbp.utils.themes.ui.VaaclipseUiTheme;
+import org.eclipse.osbp.utils.themes.ui.VaaclipseUiTheme.ThemeList;
//import org.eclipse.emf.common.util.URI;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
@@ -57,13 +50,8 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.mihalis.opal.utils.SWTGraphicUtil;
-import org.osgi.framework.Bundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.eclipse.osbp.fork.mihalis.opal.imageSelector.ISItem;
-import org.eclipse.osbp.fork.mihalis.opal.imageSelector.ImageSelector;
-import org.eclipse.osbp.utils.themes.ui.VaaclipseUiTheme;
-import org.eclipse.osbp.utils.themes.ui.VaaclipseUiTheme.ThemeList;
/**
* Instances of this class are controls that allow the user to select images.
@@ -318,7 +306,6 @@ public class ImageSelector extends Canvas {
if (this.animationStep < 0d) {
this.items.clear();
-// clearItems();
this.items.addAll(this.originalItems);
for (int i = 0; i < this.items.size(); i++) {
final ISItem item = this.items.get(i);
@@ -474,6 +461,7 @@ public class ImageSelector extends Canvas {
selectImage();
}
break;
+ default: scrollToItem(Character.toString(e.character));
}
firstAction = false;
}
@@ -521,7 +509,6 @@ public class ImageSelector extends Canvas {
public void run() {
ImageSelector.this.items.clear();
-// clearItems();
ImageSelector.this.items
.addAll(ImageSelector.this.originalItems);
for (int i = 0; i < ImageSelector.this.items.size(); i++) {
@@ -550,6 +537,34 @@ public class ImageSelector extends Canvas {
});
}
+
+ /**
+ * Scrolls to an item in {@link #items} whose name
+ * starts with the given prefix.
+ * @param prefix the prefix
+ */
+ private void scrollToItem(String prefix){
+ int idx = findIndexOfFirstItemWithStartingName(prefix);
+ if(idx != -1) {
+ this.index = idx;
+ redraw();
+ }
+ }
+
+ /**
+ * Returns the index of the first item element whose names
+ * starts with the given prefix.
+ * @param prefix the prefix
+ * @return the item index or -1 if none is found
+ */
+ private int findIndexOfFirstItemWithStartingName(String prefix){
+ for(ISItem item : ImageSelector.this.items){
+ if(item.getText().startsWith(prefix)){
+ return ImageSelector.this.items.indexOf(item);
+ }
+ }
+ return -1;
+ }
/**
* Add mouse listeners.

Back to the top