Skip to content
Browse files

AutoCompleteUI now uses a comparator to sort the values whilst consid…

…ering their numeric values. Closes #122
  • Loading branch information...
1 parent ce5616d commit 253f1e31c40f079a2b156ffacd55cfce190cab14 @eamonnmag eamonnmag committed Apr 16, 2012
View
2 pom.xml
@@ -342,7 +342,7 @@
<dependency>
<groupId>uk.ac.ebi</groupId>
<artifactId>jutils</artifactId>
- <version>1.2</version>
+ <version>1.3.1</version>
</dependency>
<dependency>
View
23 src/main/java/org/isatools/isacreator/autofilterfield/AutoCompleteUI.java
@@ -7,23 +7,20 @@
import org.isatools.isacreator.autofilteringlist.FilterableListCellRenderer;
import org.isatools.isacreator.common.UIHelper;
import org.isatools.isacreator.effects.GraphicsUtils;
-import org.isatools.isacreator.effects.borders.RoundedBorder;
+import uk.ac.ebi.utils.collections.AlphaNumComparator;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
+import java.util.List;
import java.awt.*;
import java.awt.event.*;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
+import java.util.Collections;
/**
* The AutoCompleteUI class provides the user interface to allow users to select study samples from an autocompleting list
* of Study sample ids. It also allows the user to propagate metadata from the study sample file directly into the Assay file.
*/
-public class AutoCompleteUI<T> extends JWindow implements ActionListener {
+public class AutoCompleteUI<T extends Comparable> extends JWindow implements ActionListener {
public static final int INCOMING = 1;
public static final int OUTGOING = -1;
@@ -43,17 +40,17 @@
public static final int WIDTH = 230;
private FilterField filterField;
- private Collection<T> filterableContent;
+ private List<T> filterableContent;
private ListCellRenderer cellRenderer;
private ExtendedJList filterList;
- public AutoCompleteUI(FilterField filterField, Collection<T> filterableContent) {
+ public AutoCompleteUI(FilterField filterField, List<T> filterableContent) {
this(filterField, filterableContent, new FilterableListCellRenderer());
}
- public AutoCompleteUI(FilterField filterField, Collection<T> filterableContent, ListCellRenderer cellRenderer) {
+ public AutoCompleteUI(FilterField filterField, List<T> filterableContent, ListCellRenderer cellRenderer) {
this.filterField = filterField;
this.filterableContent = filterableContent;
this.cellRenderer = cellRenderer;
@@ -249,11 +246,11 @@ private void stopAnimation() {
repaint();
}
- public void updateContent(Collection<T> studySampleInformation) {
- filterableContent = studySampleInformation;
+ public void updateContent(List<T> content) {
+ filterableContent = content;
filterList.clearItems();
-
+ Collections.sort(filterableContent, new AlphaNumComparator<T>());
for (T item : filterableContent) {
filterList.addItem(item);
}
View
7 src/main/java/org/isatools/isacreator/autofilterfield/DefaultAutoFilterCellEditor.java
@@ -22,7 +22,7 @@
import java.util.EventObject;
import java.util.List;
-public abstract class DefaultAutoFilterCellEditor<T> extends FilterField
+public abstract class DefaultAutoFilterCellEditor<T extends Comparable> extends FilterField
implements TableCellEditor, DocumentListener, FocusListener, KeyListener {
protected transient List<CellEditorListener> listeners;
@@ -240,9 +240,7 @@ public void removeUpdate(DocumentEvent event) {
}
private void showSelector() {
-
try {
-
if (selector == null) {
instantiateSelectorIfRequired();
selector.fadeInWindow();
@@ -254,7 +252,7 @@ private void showSelector() {
}
}
} catch (Exception e) {
- System.out.println(e.getMessage());
+ // do nothing
}
}
@@ -263,7 +261,6 @@ private void showSelector() {
protected abstract void updateContent();
private void hideSelector() {
-
if (selector.isShowing()) {
selector.fadeOutWindow();
}
View
6 src/main/java/org/isatools/isacreator/model/Protocol.java
@@ -47,7 +47,7 @@ The ISA Team and the ISA software suite have been funded by the EU Carcinogenomi
*
* @author Eamonn Maguire
*/
-public class Protocol extends ISASection implements StudySubData, Serializable {
+public class Protocol extends ISASection implements StudySubData, Serializable, Comparable<Protocol> {
public static final String PROTOCOL_NAME = "Study Protocol Name";
public static final String PROTOCOL_TYPE = "Study Protocol Type";
@@ -200,4 +200,8 @@ public String getProtocolComponentTypeSource() {
public String toString() {
return getProtocolName();
}
+
+ public int compareTo(Protocol protocol) {
+ return getProtocolName().compareToIgnoreCase(protocol.getProtocolName());
+ }
}
View
6 src/main/java/org/isatools/isacreator/sampleselection/SampleInformation.java
@@ -46,7 +46,7 @@ The ISA Team and the ISA software suite have been funded by the EU Carcinogenomi
* Date: 29/07/2011
* Time: 16:48
*/
-public class SampleInformation {
+public class SampleInformation implements Comparable<SampleInformation> {
private int rowNumber;
private String sampleName;
@@ -94,4 +94,8 @@ private String extractSampleCharacteristics() {
public String toString() {
return sampleName;
}
+
+ public int compareTo(SampleInformation o) {
+ return sampleName.compareToIgnoreCase(o.getSampleName());
+ }
}
View
7 src/main/java/org/isatools/isacreator/sampleselection/SampleSelectorCellEditor.java
@@ -60,7 +60,7 @@ public SampleSelectorCellEditor(Spreadsheet spreadsheet) {
protected void updateContent() {
if (StudyUtils.shouldRunUpdate(getStudyFromSpreadsheet().getStudyId())) {
try {
- selector.updateContent(StudyUtils.getStudySampleInformation(getStudyFromSpreadsheet()).values());
+ selector.updateContent((List<SampleInformation>) StudyUtils.getStudySampleInformation(getStudyFromSpreadsheet()).values());
} catch (Exception e) {
System.out.println("Problem encountered when updating study sample list.");
}
@@ -177,7 +177,10 @@ private void propagateFactorsToAssay(String selectedSampleName) {
public void instantiateSelectorIfRequired() {
if (selector == null) {
try {
- selector = new AutoCompleteUI<SampleInformation>(this, StudyUtils.getStudySampleInformation(getStudyFromSpreadsheet()).values(), new SampleSelectionListCellRenderer());
+ List<SampleInformation> sampleInformation = new ArrayList<SampleInformation>();
+ sampleInformation.addAll(StudyUtils.getStudySampleInformation(getStudyFromSpreadsheet()).values());
+
+ selector = new AutoCompleteUI<SampleInformation>(this, sampleInformation, new SampleSelectionListCellRenderer());
selector.createGUI();
selector.setLocation(calculateDisplayLocation(currentTable, currentRow, currentColumn));
} catch (Exception e) {
View
5 src/main/java/org/isatools/isacreator/spreadsheet/SpreadsheetCell.java
@@ -51,11 +51,6 @@ The ISA Team and the ISA software suite have been funded by the EU Carcinogenomi
private Object value;
- public SpreadsheetCell() {
- value = null;
-
- }
-
public SpreadsheetCell(Object datum) {
value = datum;
}
View
2 src/main/java/org/isatools/isacreator/spreadsheet/SpreadsheetFunctions.java
@@ -197,15 +197,13 @@ public void performMultipleSort(int primaryColumn,
while (columns.hasMoreElements()) {
TableColumn tc = columns.nextElement();
-
if (spreadsheet.getTableReferenceObject().acceptsFileLocations(tc.getHeaderValue().toString())) {
int colIndex = Utils.convertModelIndexToView(spreadsheet.getTable(), tc.getModelIndex());
for (int row = 0; row < spreadsheet.getTable().getRowCount(); row++) {
String s = (spreadsheet.getTable().getValueAt(row, colIndex) == null) ? ""
: spreadsheet.getTable().getValueAt(row,
colIndex).toString();
-
if (s != null && !s.trim().equals("")) {
files.add(s);
}
View
133 src/main/java/org/isatools/isacreator/spreadsheet/SpreadsheetModel.java
@@ -312,41 +312,6 @@ public SpreadsheetCell getCellAt(int aRow, int aColumn) {
}
/**
- * This method copies the cells in a range into a two-dimensional array of
- * cells.
- *
- * @param range range of cells to copy
- * @return copy of range
- */
- public SpreadsheetCell[][] getRange(SpreadsheetCellRange range) {
- //get dimensions of range
- SpreadsheetCell[][] board = new SpreadsheetCell[range.getHeight()][range.getWidth()];
-
- //copy the cells
- for (int i = range.getStartRow(); i <= range.getEndRow(); i++) {
- for (int j = range.getStartCol(); j <= range.getEndCol(); j++) {
- //translate to coordinates in copy array
- int x = i - range.getStartRow();
- int y = j - range.getStartCol();
-
- SpreadsheetCell field = getCellAt(i, j);
-
- /*
- * if it is a formula copy both the value and the formula The
- * value will be useful with a paste by value
- */
-
- //value cells have immutable objects
- board[x][y] = new SpreadsheetCell(field.getValue());
-
- }
- }
-
- return board;
- }
-
-
- /**
* set table selection to the range sel
*
* @param sel the range to be selected
@@ -457,17 +422,6 @@ static public SpreadsheetCellPoint getSize(String input, char delim) {
}
/**
- * Determines if a cell is empty
- *
- * @param row row coordinate of cell
- * @param col column coordinate of cell
- * @return true if cell is empty
- */
- public boolean isEmptyCell(int row, int col) {
- return getCellAt(row, col).getValue().equals("");
- }
-
- /**
* Returns JTable
*
* @return JTable
@@ -540,70 +494,6 @@ public void setCellAt(Object input, int aRow, int aColumn) {
}
/**
- * This method sets the cells given by the range to the cooresponding value
- * in the Object array. In other words, this method pastes the object array
- * onto the range. It is assumed that the range and Object array have the
- * same dimensions. (a "placeAt" method for ranges)
- *
- * @param range the range of cells to paste to
- * @param data the data to paste
- */
- public void setRange(SpreadsheetCellRange range, Object[][] data) {
- /* Loop through the paste range */
- for (int i = range.getStartRow(); i <= range.getEndRow(); i++) {
- for (int j = range.getStartCol(); j <= range.getEndCol(); j++) {
- //calculate the corresponding entry in data array
- int x = i - range.getStartRow();
- int y = j - range.getStartCol();
-
- //place data entry at that place
- doSetValueAt(data[x][y], i, j);
- }
- }
- }
-
- /**
- * This is a method used to paste cells onto the table. This method is used
- * by the SharpClipboard class. It's feature is that it can paste only the
- * old evaluated values or it can be told to paste the data cells and
- * formulas.
- *
- * @param range range to paste to
- * @param data cells that need to be pasted
- * @param byValue true if only paste values if there are formula
- */
- public void setRange(SpreadsheetCellRange range, SpreadsheetCell[][] data, boolean byValue) {
- /*
- * there may be formula so if byValue is true paste evaluated formula
- * value into the range as a data cell
- */
- if (byValue) {
- for (int i = range.getStartRow(); i <= range.getEndRow(); i++) {
- for (int j = range.getStartCol(); j <= range.getEndCol(); j++) {
- int x = i - range.getStartRow();
- int y = j - range.getStartCol();
-
- //get only value of a formula cell not formula
- doSetValueAt(data[x][y].getValue(), i, j);
- }
- }
- } else {
- for (int i = range.getStartRow(); i <= range.getEndRow(); i++) {
- for (int j = range.getStartCol(); j <= range.getEndCol(); j++) {
- int x = i - range.getStartRow();
- int y = j - range.getStartCol();
- SpreadsheetCell info = data[x][y];
-
- //paste new formula to recalculate
-
- doSetValueAt(info.getValue(), i, j);
-
- }
- }
- }
- }
-
- /**
* Sets the value of the cell. It takes care of formulas and data. If aValue
* is a string, it parses it to see if it is a formula (begins with an "=")
* or a number. It then sets the value of the cell accordingly.
@@ -650,17 +540,13 @@ public void doSetValueAt(Object aValue, int aRow, int aColumn) {
aValue = "";
}
-
if (aValue instanceof String) {
String input = (String) aValue;
- /* try making it a formula */
-
try {
if (input.contains(".")) {
Double data = new Double(input);
setCellAt(data, aRow, aColumn);
- System.out.println("Value was a double, so set it as a double value");
} else {
Integer data = new Integer(input);
setCellAt(data, aRow, aColumn);
@@ -670,14 +556,8 @@ public void doSetValueAt(Object aValue, int aRow, int aColumn) {
/* all else fails treat as string */
setCellAt(aValue, aRow, aColumn);
}
-
-
} else {
- System.out.println("aValue was instance of " + aValue.getClass().toString());
- System.out.println("In else clause. Setting value: " + aValue);
-
setCellAt(aValue, aRow, aColumn);
-
}
}
@@ -691,14 +571,11 @@ public void doSetValueAt(Object aValue, int aRow, int aColumn) {
* @see SpreadsheetClipboard
*/
public String toString(SpreadsheetCellRange range, char delim) {
- StringBuffer sbf = new StringBuffer();
+ StringBuilder sbf = new StringBuilder();
for (int i = range.getStartRow(); i <= range.getEndRow(); i++) {
for (int j = range.getStartCol(); j <= range.getEndCol(); j++) {
-
sbf.append(getValueAt(i, j));
-
-
if (j < range.getEndCol()) {
sbf.append(delim);
}
@@ -719,7 +596,7 @@ public String toString(SpreadsheetCellRange range, char delim) {
* @see SpreadsheetClipboard
*/
public String extendedToString(SpreadsheetCellRange range, char delim) {
- StringBuffer sbf = new StringBuffer();
+ StringBuilder sbf = new StringBuilder();
int[] columns = range.getColumnList();
if (columns != null) {
@@ -845,6 +722,7 @@ void fromString(String text, char delim, SpreadsheetCellRange range) {
row++;
}
} catch (Exception e) {
+ // do nothing
}
}
@@ -902,6 +780,7 @@ void extendedFromString(String text, char delim, SpreadsheetCellRange range) {
}
}
} catch (Exception e) {
+ // do nothing
}
}
@@ -920,6 +799,4 @@ public void addToColumns(String headerLabel) {
}
}
-}
-
-
+}

0 comments on commit 253f1e3

Please sign in to comment.
Something went wrong with that request. Please try again.