/**
Further processes oj functions, but without limitation to string parameters
*/
package oj.macros;
import ij.ImageStack;
import ij.WindowManager;
import ij.gui.Roi;
import java.awt.Color;
import java.awt.Polygon;
import java.util.ArrayList;
import oj.util.UtilsOJ;
import oj.project.results.ColumnsOJ;
import oj.project.results.OperandOJ;
import oj.geometry.VertexCalculatorOJ;
import oj.processor.events.ColumnChangedEventOJ;
import oj.processor.events.YtemDefChangedEventOJ;
import oj.processor.events.StatisticsChangedEventOJ;
import oj.util.ImageJAccessOJ;
import oj.util.WildcardMatchOJ;
import ij.IJ;
import ij.ImagePlus;
import ij.gui.ImageCanvas;
import ij.gui.ImageWindow;
import ij.gui.Line;
import ij.gui.PointRoi;
import ij.gui.PolygonRoi;
import ij.gui.Toolbar;
import ij.macro.Interpreter;
import ij.process.FloatPolygon;
import java.awt.Rectangle;
import oj.OJ;
import oj.project.*;
import oj.project.results.ColumnDefOJ;
import oj.graphics.CustomCanvasOJ;
import oj.processor.state.CreateCellStateOJ;
import oj.gui.tools.ToolManagerOJ;
import oj.gui.results.ProjectResultsOJ;
import java.awt.Frame;//23.2.2009
import oj.project.results.ColumnOJ;
/*
import oj.project.results.ColumnsOJ;
import java.io.StringWriter;
import oj.io.InputOutputOJ;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.datatransfer.Clipboard;
import java.util.ArrayList;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import oj.OJ;
import oj.UtilsOJ;
*/
/**
*
* @author stelian
*/
public class MacroProcessorOJ {
private int imageWidth;
private int imageHeight;
private ColumnOJ newestColumn;//used for adding algorithms
final int one = 1;
public MacroProcessorOJ() {
this.imageHeight = 0;
this.imageWidth = 0;
}
/**
* if item was open, close item
* if maxClones is now reached, switch to next item
* if cell is full, close cell
* if cell was closed and CompositeObjects = true, switch to first item
*/
public void advance() {
if (!(OJ.getToolStateProcessor().getToolStateObject() instanceof CreateCellStateOJ)) {
ToolManagerOJ.getInstance().selectTool("Marker");
}
((CreateCellStateOJ) OJ.getToolStateProcessor().getToolStateObject()).advanceToNextYtemDef();
}
/**
* return the name of the active ytem definition
* @return name of the active ytem
*/
public String activeYtemName() {
return OJ.getData().getYtemDefs().getSelectedYtemDefName();
}
/**
* closes the current editing ytem
*/
public void closeYtem() {
if (OJ.getToolStateProcessor().getToolStateObject() instanceof CreateCellStateOJ) {
((CreateCellStateOJ) OJ.getToolStateProcessor().getToolStateObject()).closeYtem();
}
// if (!OJ.getData().getObjectDefs().isComposite()) {
// closeObject();
// }
}
/**
* closes the current editing cell
*/
public void closeObject() {
if (OJ.getToolStateProcessor().getToolStateObject() instanceof CreateCellStateOJ) {
((CreateCellStateOJ) OJ.getToolStateProcessor().getToolStateObject()).closeCell();
}
}
//linked, unlinked, images, unchanged, background, title=[blobs.gif]<br/>
public void closeImagesNotUsed(String conDitions) {
String conditions = conDitions.toLowerCase();
int bracket1 = conditions.indexOf("title=[");
int bracket2 = conditions.lastIndexOf("]");
String title = null;
if (bracket1 >= 0 && bracket2 > bracket1) {
title = conditions.substring(bracket1 + 7, bracket2);//remove title
conditions = conditions.substring(0, bracket1) + conditions.substring(bracket2 + 1);
}
boolean unchangedOnly = conditions.contains("unchanged");
boolean unlinkedOnly = conditions.contains("unlinked");
boolean linkedOnly = !unlinkedOnly && conditions.contains("linked");
boolean backgroundOnly = conditions.contains("background");
ImageWindow currentWindow = WindowManager.getCurrentWindow();
int[] idList = WindowManager.getIDList();
if (idList == null) {
return;
}
int nImages = idList.length;
int[] closeList = new int[nImages];
WildcardMatchOJ wm = new WildcardMatchOJ();
wm.setCaseSensitive(false);
ImagesOJ imgsOJ = oj.OJ.getData().getImages();
// if (includeImages)
//{
for (int jj = 0; jj < nImages; jj++) {//not executed if nImages == 0
ImagePlus ip = WindowManager.getImage(idList[jj]);
boolean linked = false;
for (int kk = 0; kk < imgsOJ.getImagesCount(); kk++) {
if (imgsOJ.getImageByIndex(kk).getID() == ip.getID()) {
linked = true;
}
}
boolean pass1 = (!unchangedOnly || !ip.changes);
boolean pass2 = (title == null) || wm.match(ip.getTitle(), title);
boolean pass3 = (!backgroundOnly || WindowManager.getCurrentImage() != ip);
boolean pass4 = (!linkedOnly || linked);
if (pass1 && pass2 && pass3 && pass4) {
closeList[jj] = idList[jj];
}
}
for (int jj = 0; jj < nImages; jj++) {
int theID = closeList[jj];
if (theID < 0) {
ImagePlus ip = WindowManager.getImage(theID);
if (ip != null) {
ip.changes = false;
ImageWindow imWindow = ip.getWindow();
if (imWindow != null) {
WindowManager.removeWindow(imWindow);
}
}
}
}
if (currentWindow != null) {
currentWindow.getImagePlus().show();
}
}
/**
* delete all cells
*/
public void deleteAllObjects() {
OJ.getDataProcessor().removeAllCells();
}
/**
* delete image witch match the name
* @param imageName the name of the image which must be deleted
*/
public void disposeImage(String imageName) {
for (int i = OJ.getData().getImages().getImagesCount(); i > 0; i--) {
String image_name = OJ.getData().getImages().getImageByIndex(i - 1).getName();
if (image_name.matches(imageName)) {
OJ.getData().getImages().removeImageByName(image_name);
}
}
}
public void disposeAllImages() {
OJ.getData().getImages().removeAllImages();
}
public int newestCell() {
return OJ.getData().getCells().getNewestCellIndex() + one;
}
public void setLocation(int xpos, int ypos, int width, int height) {
ImageWindow imgw = WindowManager.getCurrentWindow();
if (imgw != null) {
imgw.setBounds(xpos, ypos, width, height);
}
}
public void setYtemDefVisible(String ytemtype, boolean visible) {//3.6.2009
WildcardMatchOJ wm = new WildcardMatchOJ();
wm.setCaseSensitive(false);
for (int i = 0; i < OJ.getData().getYtemDefs().getYtemDefsCount(); i++) {
YtemDefOJ ytmDef = OJ.getData().getYtemDefs().getYtemDefByIndex(i);
String name = ytmDef.getYtemDefName();
if (wm.match(name, ytemtype)) {
ytmDef.setVisible(visible);
}
}
}
public void zoom(double factor, int xhook, int yhook) {
ImageWindow win = ij.WindowManager.getCurrentWindow();
if (win == null) {
return;
}
Rectangle rr = new Rectangle();
ImagePlus imp = ij.WindowManager.getCurrentImage();
if (imp == null) {
return;
}
ImageCanvas ic = imp.getCanvas();
if (ic == null) {
return;
}
if (ic instanceof CustomCanvasOJ) {
CustomCanvasOJ icoj = (CustomCanvasOJ) ic;
icoj.ojZoom(factor, xhook, yhook);
}
}
boolean selectWindowManagerImage(String imageName) {
//why don't we call WindowManager.selectWindow(imageName);
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 400) { // 0.4 sec timeout
int[] wList = WindowManager.getIDList();
int len = wList != null ? wList.length : 0;
for (int i = 0; i
< len; i++) {
ImagePlus imp = WindowManager.getImage(wList[i]);
if (imp != null) {
if (imp.getTitle().equals(imageName)) {
IJ.selectWindow(imp.getID());
return true;
}
}
}
IJ.wait(10);
}
return (false);
}
public void showImage(int imageIndex) {
ImagesOJ images = OJ.getData().getImages();
if ((imageIndex <= 0) || (imageIndex > images.getImagesCount())) {
ImageJAccessOJ.InterpreterAccess.interpError("Image number (" + imageIndex + ") out of range (1.." + images.getImagesCount() + ")");
return;
}
String image_name = images.getImageByIndex(imageIndex - one).getName();
ImageWindow imgw = OJ.getImageProcessor().getOpenLinkedImageWindow(image_name);
if (imgw != null) {
OJ.getImageProcessor().getOpenLinkedImageWindow(image_name).toFront();
ImagePlus imp = imgw.getImagePlus();
if (imp != null) {//7.9.2010
int ID = imp.getID();
IJ.selectWindow(ID);
}//n_24.9.2007
} else {
if (Interpreter.getInstance() != null) {
ImageJAccessOJ.FunctionsAccess.resetImage();
}
OJ.getImageProcessor().openImage(image_name);//19.10.2010
}
//OJ.getImageProcessor().openImage(image_name);//19.10.2010
}
// public void showImage(String imageName) {
// if (!((imageName == null) || (imageName.equals("")))) {
// OJ.getImageProcessor().openImage(imageName);
// }
//
// }
public void setTool(String tool) {
//Marker Pistol MoveObject SelectObject ObjectToRoi
//Rectangle Elliptical Brush Polygon FreehandRoi StraightLine SegmentedLine FreehandLine Angle Point Wand Text Zoom Scroll ColorPicker
boolean isNumber = true;
String imageJTools[] = {
"00=rectangle", "01=oval", "02=polygon", "03=freehand", "04=straightline",
"05=polyline", "06=freeline", "07=point", "08=wand", "09=text",
"10=spare", "11=zoom", "12=hand", "13=dropper", "14=angle",
"-1=Marker", "-2=Pistol", "-3=MoveObject",
"-4=SelectObject", "-5=ObjectToRoi"
};
int tool_index = -999;
try {
tool_index = Integer.parseInt(tool);
} catch (NumberFormatException e) {
isNumber = false;
}
if (!isNumber) {
for (int jj = 0; jj < imageJTools.length; jj++) {
String fragment = imageJTools[jj];
String name = fragment.substring(3);
int index = Integer.parseInt(fragment.substring(0, 2));
if (tool.equalsIgnoreCase(name)) {
tool_index = index;
break;
}
}
}
if (tool_index >= 0) {//it's an ImageJ tool
ToolManagerOJ.getInstance().selectTool("");
Toolbar.getInstance().setTool(tool_index);//is range-protected
} else {//it's an ObjectJ tool
ToolManagerOJ.getInstance().selectTool(Math.abs(tool_index));
}
}
public void openCell(int index) {
if (UtilsOJ.inRange(1, OJ.getData().getCells().getCellsCount(), index)) {
if (!(OJ.getToolStateProcessor().getToolStateObject() instanceof CreateCellStateOJ)) {
ToolManagerOJ.getInstance().selectTool("Marker");
}
((CreateCellStateOJ) OJ.getToolStateProcessor().getToolStateObject()).openCell(index - one);
}
}
public String ownerName(int cellIndex) {
CellsOJ cells = OJ.getData().getCells();
if (UtilsOJ.inRange(1, cells.getCellsCount(), cellIndex)) {
return cells.getCellByIndex(cellIndex - one).getImageName();
} else {
ImageJAccessOJ.InterpreterAccess.interpError("object number out of range");
}
return "";
}
public int ownerIndex(int cellIndex) {
CellsOJ cells = OJ.getData().getCells();
if (UtilsOJ.inRange(1, cells.getCellsCount(), cellIndex)) {
String imageName= cells.getCellByIndex(cellIndex - one).getImageName();
return one + OJ.getData().getImages().getIndexOfImage(imageName);
}
return 0;
}
public void putOperand(String itemType, int clone, int point) {
if (newestColumn != null) {
OperandOJ op = new OperandOJ();
op.setYtemName(itemType);
op.setYtemClone(clone - one);
op.setRelPosition(point - one);
newestColumn.getColumnDef().addOperand(op);
}
}
public void putAlgorithm(String algString) {
if (newestColumn != null) {
int algNum = ColumnDefOJ.getAlgorithm(newestColumn.getName(), algString);
newestColumn.getColumnDef().setAlgorithm(algNum);
}
}
public void showObject(int index) {
if (!cellInRange(index)) {
return;
}
ImageJAccessOJ.FunctionsAccess.resetImage();
OJ.getDataProcessor().showCell(index - one);
}
public void setNewSize(int width, int height) {
this.imageWidth = width;
this.imageHeight = height;
}
public void setMarker(double xpos, double ypos) {
String image_name = WindowManager.getCurrentImage().getTitle();
if (OJ.getData().getImages().getImageByName(image_name) == null) {
ImageJAccessOJ.InterpreterAccess.interpError("A marker can only be set into a linked image. Select the linked image before calling the ojSetMarker function.");
return;
}
int slice_index = WindowManager.getCurrentImage().getCurrentSlice();
if (!(OJ.getToolStateProcessor().getToolStateObject() instanceof CreateCellStateOJ)) {
ToolManagerOJ.getInstance().selectTool("Marker");
}
OJ.getToolStateProcessor().mousePressed(image_name, slice_index, xpos, ypos, 0);
}
/**
* activates item type in ObjectJ Tools window
*/
public void switchToItem(String name) {
if (null == OJ.getData().getYtemDefs().getYtemDefByName(name)) {
ImageJAccessOJ.InterpreterAccess.interpError("'" + name + "' is not a defined item");
return;
}
//
if (!(OJ.getToolStateProcessor().getToolStateObject() instanceof CreateCellStateOJ)) {
ToolManagerOJ.getInstance().selectTool("Marker");
}
OJ.getData().getYtemDefs().setSelectedYtemDef(name);
}
/**
* activates n-th item type in ObjectJ Tools window (1-based)
* use negative index to count from the back.
*/
public void switchToItem(int itemTypeNumber) {
String name = itemTypeNumberToName(itemTypeNumber);
if (name != null) {
switchToItem(name);
}
}
public String itemTypeNumberToName(int itemTypeNumber) {
int maxTypes = OJ.getData().getYtemDefs().getYtemDefsCount();
int jj = itemTypeNumber;
if (jj < 0) {
jj = maxTypes + jj + 1;
}
jj -= one;
if (jj < 0 || jj >= maxTypes) {
ImageJAccessOJ.InterpreterAccess.interpError("itemType number '" + itemTypeNumber + "' is out of range");
return null;
}
return OJ.getData().getYtemDefs().getYtemDefByIndex(jj).getYtemDefName();
}
/**
* it swaps the backgrounds of two slices
* @param sliceA first slice
* @param sliceB second slice
*/
public void swapSlices(int sliceA, int sliceB) {
if (sliceA == sliceB || sliceA < 1 || sliceB < 1
|| sliceA > IJ.getImage().getStackSize() || sliceB > IJ.getImage().getStackSize()) {
return;
}
ImagePlus imp = IJ.getImage();
ImageStack stack = imp.getStack();
String[] labels = ImageJAccessOJ.ImageStackAccess.getStackLabels(stack);
String labelA = labels[sliceA - 1];
String labelB = labels[sliceB - 1];
labels[sliceA - 1] = labelB;
labels[sliceB - 1] = labelA;
ImageJAccessOJ.ImageStackAccess.setStackLabels(stack, labels);
Object[] objects = ImageJAccessOJ.ImageStackAccess.getStackObjects(stack);
Object ipA = objects[sliceA - 1];
Object ipB = objects[sliceB - 1];
objects[sliceA - 1] = ipB;
objects[sliceB - 1] = ipA;
ImageJAccessOJ.ImageStackAccess.setStackObjects(stack, objects);
if (imp.getCurrentSlice() == sliceA) {
imp.setProcessor(imp.getTitle(), stack.getProcessor(sliceA));
} else if (imp.getCurrentSlice() == sliceB) {
imp.setProcessor(imp.getTitle(), stack.getProcessor(sliceB));
}
imp.repaintWindow();
}
public int getImageCount() {
return OJ.getData().getImages().getImagesCount();
}
public int getNCells() {
return OJ.getData().getCells().getCellsCount();
}
public void recalculate() {
ProjectResultsOJ.close();//23.2.2009 completely close results
OJ.getImageProcessor().updateImagesProperties();
OJ.getDataProcessor().recalculateResults();
new ProjectResultsOJ();
ProjectResultsOJ.getInstance().setVisible(true);//23.2.2009 re-open results
ProjectResultsOJ.getInstance().setState(Frame.NORMAL);//23.2.2009
}
public void closeResults() {
ProjectResultsOJ.close();//15.3.2009
}
public String getResult(String columnName, int index) {
ColumnOJ theColumn = OJ.getData().getResults().getColumns().getColumnByName(columnName);//n_ 11.9.2007
if (theColumn == null) {
ImageJAccessOJ.InterpreterAccess.interpError("Column '" + columnName + "' does not exist");
return "";
}
if ((index - one) < 0 || (index - one) >= theColumn.getResultCount()) {
ImageJAccessOJ.InterpreterAccess.interpError("Row number " + index + "out of range");
if (theColumn.getColumnDef().isTextMode()) {
return "";
} else {
return Double.toString(Double.NaN);
}
}
if (theColumn.getColumnDef().isTextMode()) {
return theColumn.getStringResult(index - 1);
} else {
return Double.toString(theColumn.getDoubleResult(index - one));
}
}
public int getFirstCell(int index) {
ImageOJ img = OJ.getData().getImages().getImageByIndex(index - one);
return img.getFirstCell() + one;
}
public int getLastCell(int index) {
ImageOJ img = OJ.getData().getImages().getImageByIndex(index - one);
int last = img.getLastCell() + one;
if (last == 0) {
last = -1;
} //return -1 if image is unmarked: convenient for-loop
return last;
}
public int getOpenCell() {
int index = OJ.getData().getCells().getOpenCellIndex();
return index + one;
}
public int getImageLink() {
if (WindowManager.getCurrentImage() == null) {
return 0;
}
ImagesOJ images = OJ.getData().getImages();
String dir1 = IJ.getImage().getOriginalFileInfo().directory;//24.10.2010
String dir2 = OJ.getData().getDirectory();
return images.getIndexOfImage(IJ.getImage().getTitle()) + one;
}
public void setResult(String columnName, int index, String value) {
ColumnOJ theColumn = OJ.getData().getResults().getColumns().getColumnByName(columnName);
if (theColumn == null) {
ImageJAccessOJ.InterpreterAccess.interpError("Column '" + columnName + "' does not exist");
return;
}
if ((index - one) >= theColumn.getResultCount()) {
if (theColumn.isUnlinkedColumn()) {
for (int i = (theColumn.getResultCount() - 1); i < (index - 2); i++) {
if (theColumn.getColumnDef().isTextMode()) {
OJ.getDataProcessor().addStringResult(columnName, "");
} else {
OJ.getDataProcessor().addDoubleResult(columnName, Double.NaN);
}
}
if (theColumn.getColumnDef().isTextMode()) {
OJ.getDataProcessor().addStringResult(columnName, value);
} else {
OJ.getDataProcessor().addDoubleResult(columnName, MacroProcessorOJ.parseDouble(value));
}
}
} else {
if (theColumn.isUnlinkedColumn()) {
if (UtilsOJ.inRange(1, theColumn.getResultCount(), index)) {
if (theColumn.getColumnDef().isTextMode()) {
OJ.getDataProcessor().setStringResult(columnName, index - one, value);
} else {
OJ.getDataProcessor().setDoubleResult(columnName, index - one, MacroProcessorOJ.parseDouble(value));
}
}
} else {
if (UtilsOJ.inRange(1, OJ.getData().getCells().getCellsCount(), index)) {
if (theColumn.getColumnDef().isTextMode()) {
OJ.getDataProcessor().setStringResult(columnName, index - one, value);
} else {
OJ.getDataProcessor().setDoubleResult(columnName, index - one, MacroProcessorOJ.parseDouble(value));
}
}
}
}
}
public void setImagePlusUnchanged() {
ImagePlus imp = IJ.getImage();
if (imp != null) {
imp.changes = false;
}
}
public void deleteCell(int index) {
if ((index > 0) && (index <= OJ.getData().getCells().getCellsCount())) {
OJ.getDataProcessor().removeCellByIndex(index - one);
} else {
ImageJAccessOJ.InterpreterAccess.interpError("ojDeleteObject - index out of range: " + index + "[0," + (OJ.getData().getCells().getCellsCount() - 1) + "]");
}
}
public void deleteYtem(int index) {//1-based
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell != null) {
OJ.getDataProcessor().removeYtemByIndex(cell, index - 1);
if (cell.getYtemsCount() == 0) {
OJ.getDataProcessor().removeCell(cell);
}
}
}
public void deleteYtem(String ytemType, int index) {
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell != null) {
WildcardMatchOJ wm = new WildcardMatchOJ();
wm.setCaseSensitive(false);
int hit = 0;
for (int jj = 0; jj
< cell.getYtemsCount(); jj++) {
YtemOJ ytem = cell.getYtemByIndex(jj);
if (wm.match(ytem.getYtemDef(), ytemType)) {
hit++;
}
if (hit == index) {
deleteYtem(jj + 1);//1-based
return;
}
}
}
}
public void qualifyCell(int index, int qq) {
if ((index) > 0) {
if (qq != 0) {
OJ.getDataProcessor().qualifyCell(index - 1, true);
} else {
OJ.getDataProcessor().qualifyCell(index - 1, false);
}
}
}
public boolean qualified(int index) {
int count = OJ.getData().getCells().getCellsCount();
if (index > 0 && index <= count) {
return OJ.getData().getCells().getCellByIndex(index - one).isQualified();
}
ImageJAccessOJ.InterpreterAccess.interpError("Object index " + index + " is out of range 1.." + count);
return false;
}
/**
* checks if cellindex is between 1 and nCells (i.e. 1-based)
* @return true if ok
*/
public boolean cellInRange(int index) {//1-based
int count = OJ.getData().getCells().getCellsCount();
boolean good = UtilsOJ.inRange(0, count, index);//0 is valid for unselecting a cell
if (!good) {
ImageJAccessOJ.InterpreterAccess.interpError("Object index " + index + " is out of range 1.." + count);
}
return good;
}
/**
* Rearranges an ytem as if ytems were clicked in a different order, but does not
* change any coordinates.
* @param fromIndex position of ytem to be moved (1-based)
* @param toIndex new position after movement
*/
public void repositionYtem(int fromIndex, int toIndex) {
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell != null) {
cell.repositionYtem(fromIndex - one, toIndex - one);
}
}
public int selectedCell() {
return one + OJ.getData().getCells().getSelectedCellIndex();
}
public String selectedYtemName() {
return OJ.getData().getCells().getSelectedCell().getSelectedYtem().getYtemDef();
}
public void selectCell(int index) {
if (!cellInRange(index)) {
return;
}
OJ.getDataProcessor().selectCell(index - one);
}
/**
* From a subset of those items in current cell whose names match <itemType>,
* the nn-th one is selected. nn can be negative to count from the back.
* item type can contain wildcards.
* @param itemType name of items that form the subset.
* @param index index of subset (1-based; use negative values to count from
* back)
*
*/
public void selectYtem(String ytemType, int index) {
//we must check what is happenning in the CellProcessor
WildcardMatchOJ wm = new WildcardMatchOJ();
wm.setCaseSensitive(false);
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell == null) {
ImageJAccessOJ.InterpreterAccess.interpError("No object is selected");
return;
}
int ix, count = 0;
int nYtems = cell.getYtemsCount();
boolean backwards = (index < 0);
if (backwards) {
index = -index;
}
boolean titleFound = false;
for (int jj = 0; jj
< nYtems; jj++) {
if (backwards) {
ix = nYtems - jj - 1;
} else {
ix = jj;
}
if (wm.match(cell.getYtemByIndex(ix).getYtemDef(), ytemType)) {
titleFound = true;
count +=
1;
if (count == index) {
cell.selectYtem(ix);
return;
}
}
}
if (!titleFound) {
ImageJAccessOJ.InterpreterAccess.interpError("Item type '" + ytemType + "' does not exist");
} else {
ImageJAccessOJ.InterpreterAccess.interpError("Item index " + index + " is out of range");
}
}
public void selectYtem(int itemNumber, int index) {
String name = itemTypeNumberToName(itemNumber);
if (name == null) {
ImageJAccessOJ.InterpreterAccess.interpError("Item type not found");
return;
}
}
/**
*returns the number of items in current cell whose name matches
*@param itemName can contain wildcards; all items whose name matches itemname are counted
*@return the number of the subset
*/
public int getNItems(String itemName) {
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell != null) {
int count = 0;
WildcardMatchOJ wm = new WildcardMatchOJ();
wm.setCaseSensitive(false);//n_27.3.2007
for (int i = 0; i
< cell.getYtemsCount(); i++) {
if (wm.match(cell.getYtemByIndex(i).getYtemDef(), itemName)) {
count = count + 1;
}
}
return count;
}
return 0;
}
public String getYtemName() {
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell != null) {
YtemOJ item = cell.getSelectedYtem();
if (item != null) {
return item.getYtemDef();
}
}
return "";
}
public int getNPoints() {
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell != null) {
YtemOJ ytem = cell.getSelectedYtem();
if (ytem != null) {
return ytem.getLocationsCount();
}
}
return 0;
}
public int getNColumns() {
return OJ.getData().getResults().getColumns().getAllColumnsCount();
}
public String getColumnTitle(int columnIndex) {
int count = OJ.getData().getResults().getColumns().getAllColumnsCount();
if (columnIndex < 1 || columnIndex > count) {
ImageJAccessOJ.InterpreterAccess.interpError("Column number " + columnIndex + " out of range");
return null;
}
String title = OJ.getData().getResults().getColumns().getColumnByIndex(columnIndex - one).getName();
return title;
}
public double getXPos(int index) {
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell != null) {
YtemOJ ytem = cell.getSelectedYtem();
if (ytem != null) {
return ytem.getLocation(index - 1).getX();
}
}
return -1;
}
public double getYPos(int index) {
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell != null) {
YtemOJ item = cell.getSelectedYtem();
if (item != null) {
return item.getLocation(index - 1).getY();
}
}
return -1;
}
public double getZPos(int index) {
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell != null) {
YtemOJ ytem = cell.getSelectedYtem();
if (ytem != null) {
return ytem.getLocation(index - 1).getZ();
}
}
return -1;
}
public void initColumn(String columnName, boolean isUnlinked, boolean isTextMode) {//10.5.2010synchronized
newestColumn = OJ.getData().getResults().getColumns().getColumnByName(columnName);
if (newestColumn != null) {
newestColumn.getColumnDef().clearOperands();
if (isUnlinked) {
if (isTextMode) {
newestColumn.getColumnDef().setAlgorithm(ColumnDefOJ.ALGORITHM_CALC_UNLINKED_TEXT);
} else {
newestColumn.getColumnDef().setAlgorithm(ColumnDefOJ.ALGORITHM_CALC_UNLINKED_NUMBER);
}
newestColumn.rows.clear();
}
if (!isUnlinked) {
if (isTextMode) {
newestColumn.getColumnDef().setAlgorithm(ColumnDefOJ.ALGORITHM_CALC_LINKED_TEXT);
} else {
newestColumn.getColumnDef().setAlgorithm(ColumnDefOJ.ALGORITHM_CALC_LINKED_NUMBER);
}
int cnt = newestColumn.getResultCount();
for (int jj = 0; jj < cnt; jj++) {
if (newestColumn.getColumnDef().isTextMode()) {
OJ.getDataProcessor().setStringResult(columnName, jj, "");
} else {
OJ.getDataProcessor().setDoubleResult(columnName, jj, Double.NaN);
}
}
}
}
if (newestColumn == null) {
newestColumn = new ColumnOJ();
newestColumn.getColumnDef().setName(columnName);
if (isUnlinked) {
if (isTextMode) {
newestColumn.getColumnDef().setAlgorithm(ColumnDefOJ.ALGORITHM_CALC_UNLINKED_TEXT);
} else {
newestColumn.getColumnDef().setAlgorithm(ColumnDefOJ.ALGORITHM_CALC_UNLINKED_NUMBER);
}
} else {
if (isTextMode) {
newestColumn.getColumnDef().setAlgorithm(ColumnDefOJ.ALGORITHM_CALC_LINKED_TEXT);
} else {
newestColumn.getColumnDef().setAlgorithm(ColumnDefOJ.ALGORITHM_CALC_LINKED_NUMBER);
}
}
OJ.getData().getResults().getColumns().addColumn(newestColumn, true);//15.3.2009
}
}
public void ytemToRoi() {
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell == null) {
ImageJAccessOJ.InterpreterAccess.interpError("No cell is selected");
return;
}
YtemOJ ytm = cell.getSelectedYtem();
YtemDefOJ ytem_def = OJ.getData().getYtemDefs().getYtemDefByName(ytm.getYtemDef());
int[] xcoords = ytm.toXArray();
int[] ycoords = ytm.toYArray();
Roi roi;
switch (ytem_def.getYtemType()) {
case YtemDefOJ.YTEM_TYPE_ANGLE:
roi = new PolygonRoi(xcoords, ycoords, xcoords.length, IJ.getImage(), Roi.POINT);
IJ.getImage().setRoi(roi);
break;
case YtemDefOJ.YTEM_TYPE_LINE:
roi = new Line(xcoords[0], ycoords[0], xcoords[1], ycoords[1], IJ.getImage());
IJ.getImage().setRoi(roi);
break;
case YtemDefOJ.YTEM_TYPE_POINT:
//this is a workaround - this is how should be also for the rest but it is a bug in creating the ROIs
//for the rest of the ROI types - the image is set after the x,y position are set so the image magnification is
//not used in creating a ROI of type LINE or POLYGON
roi = new PointRoi(IJ.getImage().getCanvas().screenX(xcoords[0]), IJ.getImage().getCanvas().screenY(ycoords[0]), IJ.getImage());
IJ.getImage().setRoi(roi);
break;
case YtemDefOJ.YTEM_TYPE_POLYGON:
roi = new PolygonRoi(xcoords, ycoords, xcoords.length, IJ.getImage(), Roi.POLYGON);
IJ.getImage().setRoi(roi);
break;
case YtemDefOJ.YTEM_TYPE_ROI:
roi = new PolygonRoi(xcoords, ycoords, xcoords.length, IJ.getImage(), Roi.FREEROI);
IJ.getImage().setRoi(roi);
break;
case YtemDefOJ.YTEM_TYPE_SEGLINE:
roi = new PolygonRoi(xcoords, ycoords, xcoords.length, IJ.getImage(), Roi.POLYLINE);
IJ.getImage().setRoi(roi);
break;
default:
}
}
/**
* deletes one or several columns whose names matches the pattern
* @param columnNamePattern
*/
public void deleteColumn(String columnNamePattern) {
WildcardMatchOJ wm = new WildcardMatchOJ();
wm.setCaseSensitive(false);
ColumnsOJ columns = OJ.getData().getResults().getColumns();
String[] columnNames = columns.columnNamesToArray();
for (int colIndex = columnNames.length - 1; colIndex >= 0; colIndex--) {
String thisName = columnNames[colIndex];
if (wm.match(thisName, columnNamePattern)) {
OJ.getData().getResults().getColumns().removeColumnByName(thisName);
}
}
newestColumn = null;
}
public double getStatistics(String columnName, String operation) {
String op = "";
if (operation.equalsIgnoreCase("mean")) {
op = "Mean";
} else if (operation.equalsIgnoreCase("min")) {
op = "Minimum";
} else if (operation.equalsIgnoreCase("max")) {
op = "Maximum";
} else if (operation.equalsIgnoreCase("count")) {
op = "Count";
} else if (operation.equalsIgnoreCase("stdev")) {
op = "StDev";
} else if (operation.equalsIgnoreCase("cv%")) {
op = "Cv";
} else if (operation.equalsIgnoreCase("sum")) {
op = "Sum";
} else {
ImageJAccessOJ.InterpreterAccess.interpError("expect mean, min, max, count, stdev, cv% or sum");
return Double.NaN;
}
ColumnOJ col = OJ.getData().getResults().getColumns().getColumnByName(columnName);
if (col == null) {
ImageJAccessOJ.InterpreterAccess.interpError("Column not found");
return Double.NaN;
}
return col.getStatistics().getStatisticsValueByName(op);
}
public String getVoxelSize(int imageIndex, String xyz) {//17.9.2009
imageIndex -= one;
ImagesOJ images = OJ.getData().getImages();
if (imageIndex >= 0 && imageIndex < images.getImagesCount()) {
ImageOJ theImage = images.getImageByIndex(imageIndex);
if (xyz.equalsIgnoreCase("x")) {
return Double.toString(theImage.getVoxelSizeX());
}
if (xyz.equalsIgnoreCase("y")) {
return Double.toString(theImage.getVoxelSizeY());
}
if (xyz.equalsIgnoreCase("z")) {
return Double.toString(theImage.getVoxelSizeZ());
}
if (xyz.equalsIgnoreCase("unit")) {
return theImage.getVoxelUnitX();
}
}
return "0";
}
public void movePoint(int index, double xPos, double yPos, double zPos) {
index = index - one;
LocationOJ loc = OJ.getData().getCells().getSelectedCell().getSelectedYtem().getLocation(index);
if (xPos >= 0) {
loc.setX(xPos);
}
if (yPos >= 0) {
loc.setY(yPos);
}
if (zPos >= 0) {
loc.setZ(zPos);
}
OJ.getDataProcessor().movePoint(index, loc);
}
//not used
public void setStatisticValue(String columnName, String statisticName, double value) {
OJ.getData().getResults().getColumns().getColumnByName(columnName).getStatistics().setStatisticsValueByName(statisticName, value);
OJ.getEventProcessor().fireStatisticsChangedEvent(statisticName, StatisticsChangedEventOJ.STATISTICS_VALUE_CHANGED);
}
public void roiToYtem() {//19.6.2009
ImagePlus imp = ij.WindowManager.getCurrentImage();
if (imp == null) {
return;
}
Roi roi = imp.getRoi();
if (roi == null) {
ImageJAccessOJ.InterpreterAccess.interpError("No roi exists");
return;
}
Polygon p = roi.getPolygon();
FloatPolygon fp = roi.getFloatPolygon();
double[] xpoints = new double[p.npoints];
double[] ypoints = new double[p.npoints];
if (fp != null) { //spline fit polygon
for (int i = 0; i < p.npoints; i++) {
xpoints[i] = fp.xpoints[i];
ypoints[i] = fp.ypoints[i];
}
} else {
for (int i = 0; i < p.npoints; i++) {
xpoints[i] = p.xpoints[i];
ypoints[i] = p.ypoints[i];
}
}
for (int jj = 0; jj < xpoints.length; jj++) {
setMarker(xpoints[jj], ypoints[jj]);
}
int rt = roi.getType();
if (rt == roi.RECTANGLE || rt == roi.OVAL || rt == roi.POLYGON || rt == roi.FREEROI || rt == roi.TRACED_ROI) { //21.8.2009
if (xpoints[p.npoints - 1] != xpoints[0] || ypoints[p.npoints - 1] != ypoints[0]) {
setMarker(xpoints[0], ypoints[0]);
}
}
}
public void roiToYtemOld() {//n_5.3.2007
ImagePlus imp = IJ.getImage();
Roi roi = imp.getRoi();
if (roi == null) {
return;
}
Polygon p = roi.getPolygon();
double[] xa = new double[p.npoints];
double[] ya = new double[p.npoints];
for (int i = 0; i
< p.npoints; i++) {
xa[i] = p.xpoints[i];
ya[i] = p.ypoints[i];
setMarker(xa[i], ya[i]);
}
if (xa[p.npoints - 1] != xa[0] || ya[p.npoints - 1] != ya[0]) {
setMarker(xa[0], ya[0]);
}//close the roi
}
public void selectClosestItem(double x, double y, double tolerance) {
ImagesOJ images = OJ.getData().getImages();
int linkNo = images.getIndexOfImage(IJ.getImage().getTitle());
for (int img = 0; img < images.getImagesCount(); img++) {
ImageOJ image = images.getImageByIndex(img);
}
}
public int getColumnNumber(String columnName) {
return OJ.getData().getResults().getColumns().getColumnIndexByName(columnName) + 1;
}
public void set3D(boolean d3) {
OJ.getData().getYtemDefs().set3DYtems(d3);
OJ.getEventProcessor().fireYtemDefChangedEvent(null, YtemDefChangedEventOJ.THREE_D_MODE_CHANGED);
}
public void setColumnProperty(String columnName, String property, String valueS) {
valueS = valueS.toLowerCase();//24.1.2010
String leftPart = "";
String rightPart = "";
if (valueS.contains("=")) {
int eqPos = valueS.indexOf("=");
leftPart = valueS.substring(0, eqPos);
rightPart = valueS.substring(eqPos + 1);
}
int value = Integer.parseInt(valueS);
ColumnsOJ columns = OJ.getData().getResults().getColumns();
ArrayList matchingColumns = columns.getColumnsByWildcard(columnName);
for (int jj = 0; jj
< matchingColumns.size(); jj++) {
ColumnOJ col = (ColumnOJ) matchingColumns.get(jj);
ColumnDefOJ colDef = col.getColumnDef();
if (property.equalsIgnoreCase("visible")) {
colDef.setHidden(value == 0);
} else if (property.equalsIgnoreCase("color")) {
colDef.setColumnColor(new Color(value));
} else if (property.equalsIgnoreCase("digits")) {
colDef.setColumnDigits(value);
} else if (property.equalsIgnoreCase("sort")) {
if (value >= 0 && value <= 2) {
columns.setColumnLinkedSortFlag(value);
columns.setColumnLinkedSortName(colDef.getName());
}
} else if (property.equalsIgnoreCase("width")) {
if (value >= 40 && value <= 200) {
colDef.setColumnWidth(value);
}
} else if (property.equalsIgnoreCase("histo")) {
double rightVal = Double.parseDouble(rightPart);
if (leftPart.equals("binwidth")) {
colDef.setHistoBinWidth(rightVal);
}
if (leftPart.equals("xmin")) {
colDef.setHistoXMin(rightVal);
}
if (leftPart.equals("xmax")) {
colDef.setHistoXMax(rightVal);
}
} else {
ImageJAccessOJ.InterpreterAccess.interpError("Allowed terms: visible, color, digits, sort, width");
return;
}
OJ.getEventProcessor().fireColumnChangedEvent(col.getName(), col.getName(), ColumnChangedEventOJ.COLUMN_EDITED);
}
}
public int cellID(int index) {
return OJ.getData().getCells().getCellByIndex(index - one).getID();
}
public void setComposite(boolean compositeFlag) {
OJ.getData().getYtemDefs().setComposite(compositeFlag);
OJ.getEventProcessor().fireYtemDefChangedEvent(null, YtemDefChangedEventOJ.COLLECT_MODE_CHANGED);
}
public int lastRow(String columnName) {
int last = 0;
ColumnsOJ columns = OJ.getData().getResults().getColumns();
ArrayList matchingColumns = columns.getColumnsByWildcard(columnName);
for (int jj = 0; jj
< matchingColumns.size(); jj++) {
ColumnOJ col = (ColumnOJ) matchingColumns.get(jj);
if (col.isUnlinkedColumn()) {
int value = col.getResultCount();
last =
value > last ? value : last;
}
}
return last;
}
public void extendVisibilityDepth(int lowValue, int highValue) {
OJ.getData().getYtemDefs().setVisRangeLow(lowValue, highValue);
ImagePlus imp = IJ.getImage();
if (imp != null) {
imp.repaintWindow();
}
}
public void showProject() {
ij.IJ.showStatus("ojShowProject is not implemented");
}
public void showResults() {
oj.gui.menuactions.ViewActionsOJ.ResultsViewAction.actionPerformed(null);
}
public void hideResults() {
oj.gui.menuactions.ViewActionsOJ.ResultsViewAction.actionPerformed(null);
}
public void showTools() {
oj.gui.menuactions.ViewActionsOJ.YtemListAction.actionPerformed(null);
}
public void initVertexStack(String dim) {
VertexCalculatorOJ vc = OJ.getVertexCalculator();
vc.init(dim);
}
public int ojvGetStackSize() {
VertexCalculatorOJ vc = OJ.getVertexCalculator();
return vc.size();
}
public double ojvGetResult(String str) {
str = str.toLowerCase();
VertexCalculatorOJ vc = OJ.getVertexCalculator();
if (str.indexOf("innercircle") >= 0) {
vc.calc("innerCircle");
if (str.indexOf("radius") >= 0) {
return vc.innerCircleRadius;
}
if (str.indexOf("centerx") >= 0) {
return vc.innerCircleCenterX;
}
if (str.indexOf("centery") >= 0) {
return vc.innerCircleCenterY;
}
} else if (str.indexOf("outercircle") >= 0) {
vc.calc("outerCircle");
if (str.indexOf("radius") >= 0) {
return vc.outerCircleRadius;
}
if (str.indexOf("centerx") >= 0) {
return vc.outerCircleCenterX;
}
if (str.indexOf("centery") >= 0) {
return vc.outerCircleCenterY;
}
} else if (str.indexOf("partialpath") >= 0) {
vc.calc("partialpath");
if (str.indexOf("impactx") >= 0) {
return vc.impactX;
}
if (str.indexOf("path", 10) >= 0) {
return vc.partialPath;
}
if (str.indexOf("impacty") >= 0) {
return vc.impactY;
}
if (str.indexOf("offset") >= 0) {
if (str.indexOf("signedoffset") >= 0) {
return vc.signedMinSpark;
}
return vc.minSpark;
}
if (str.indexOf("leftedge") >= 0) {
return vc.leftEdge;
}
if (str.indexOf("rightedge") >= 0) {
return vc.rightEdge;
}
if (str.equalsIgnoreCase("partialpath")) {
return vc.partialPath;
}
} else if (str.equalsIgnoreCase("totalpath")) {
vc.calc("totalpath");
return vc.totalLength;
} else if (str.equalsIgnoreCase("perimeter")) {
vc.calc("perimeter");
return vc.perimeter;
} else if (str.equalsIgnoreCase("crosspointx")) {
vc.calc("crosspoint");
return vc.crossPoint.x;
} else if (str.equalsIgnoreCase("crosspointy")) {
vc.calc("crosspoint");
return vc.crossPoint.y;
} else if (str.equalsIgnoreCase("height")) {
vc.calc("height");
return vc.height;
} else if (str.equalsIgnoreCase("deviation")) {
vc.calc("deviation");
return vc.deviation;
} else if (str.equalsIgnoreCase("angle")) {
vc.calc("angle");
return vc.angle;
} else if (str.equalsIgnoreCase("area")) {
vc.calc("area");
return vc.area;
} else if (str.equalsIgnoreCase("orientation")) {
vc.calc("orientation");
return vc.orientation;
} else if (str.startsWith("partialpositionx")) {
vc.calc(str);
return vc.partialPositionX;
} else if (str.startsWith("partialpositiony")) {
vc.calc(str);
return vc.partialPositionY;
} else {
ImageJAccessOJ.InterpreterAccess.interpError("Algorithm '" + str + "' not found");
}
return 0;
}
public void ojvPushRoi() {
VertexCalculatorOJ vc = OJ.getVertexCalculator();
ImagePlus imp = ij.WindowManager.getCurrentImage();
if (imp == null) {
return;
}
Roi roi = imp.getRoi();
if (roi == null) {
ImageJAccessOJ.InterpreterAccess.interpError("No roi exists");
return;
}
Polygon p = roi.getPolygon();
FloatPolygon fp = roi.getFloatPolygon();
double[] xpoints = new double[p.npoints];
double[] ypoints = new double[p.npoints];
if (fp != null) { //spline fit polygon
for (int i = 0; i
< p.npoints; i++) {
xpoints[i] = fp.xpoints[i];
ypoints[i] = fp.ypoints[i];
}
} else {
for (int i = 0; i
< p.npoints; i++) {
xpoints[i] = p.xpoints[i];
ypoints[i] = p.ypoints[i];
}
}
for (int jj = 0; jj
< xpoints.length; jj++) {
LocationOJ loc = new LocationOJ(xpoints[jj], ypoints[jj], 0);
vc.push((Object) loc);
}
}
public void pushYtem() {
VertexCalculatorOJ vc = OJ.getVertexCalculator();
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell == null) {
return;
}
YtemOJ ytem = cell.getSelectedYtem();
if (ytem == null) {
return;
}
for (int jj = 0; jj
< ytem.getLocationsCount(); jj++) {
LocationOJ loc = ytem.getLocation(jj);
vc.push((Object) loc);
}
}
public void pushPoint(int index) {
VertexCalculatorOJ vc = OJ.getVertexCalculator();
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell == null) {
return;
}
YtemOJ ytem = cell.getSelectedYtem();
if (ytem == null) {
return;
}
LocationOJ loc = ytem.getLocation(index - one);
vc.push((Object) loc);
}
public double[] xYZPos(int index) {
index = index - one;
double[] ar = new double[3];
ar[0] = ar[1] = ar[2] = Double.NaN;
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell == null) {
return ar;
}
YtemOJ ytem = cell.getSelectedYtem();
if (ytem == null) {
return ar;
}
if (index < 0 || index >= ytem.getLocationsCount()) {
return ar;
}
LocationOJ thisLoc = ytem.getLocation(index);
ar[0] = thisLoc.getX();
ar[1] = thisLoc.getY();
ar[2] = thisLoc.getZ();
return ar;
}
public double getVertexX(int index) {
int size = OJ.getVertexCalculator().size();
if (index >= 0 && index < size) {
LocationOJ loc = (LocationOJ) OJ.getVertexCalculator().get(index);
double x = loc.getX();
x +=
0;
return x;
}
return Double.NaN;
}
public double getVertexY(int index) {
int size = OJ.getVertexCalculator().size();
if (index >= 0 && index < size) {
LocationOJ loc = (LocationOJ) OJ.getVertexCalculator().get(index);
double y = loc.getY();
return y;
}
return Double.NaN;
}
public double getVertexZ(int index) {
int size = OJ.getVertexCalculator().size();
if (index >= 0 && index < size) {
LocationOJ loc = (LocationOJ) OJ.getVertexCalculator().get(index);
double z = loc.getZ();
return z;
}
return Double.NaN;
}
public void pushVertex(double[] fa) {
double zz = 0.0;
if (fa.length == 3) {
zz = fa[2];
} else if (fa.length != 2) {
ImageJAccessOJ.InterpreterAccess.interpError("vertex must be array with 2 (x,y) or 3 (x, y, z) elements");
return;
}
LocationOJ loc = new LocationOJ(fa[0], fa[1], zz);
OJ.getVertexCalculator().push((Object) loc);
}
public double[] invertFloatArray(double[] fa) {
for (int jj = 0; jj
< fa.length; jj++) {
fa[jj] = -fa[jj];
}
return (fa);
}
// converts eg "1.0" correctly to int
public static int parseInt(String value) {
int returnVal = 0;
try {
returnVal = (int) Math.round(Double.parseDouble(value));
} catch (IllegalArgumentException ex) {
ImageJAccessOJ.InterpreterAccess.interpError("\"" + value + "\" is not an integer");
}
return returnVal;
}
public static double parseDouble2(String value) {
double returnVal = Double.NaN;
try {
returnVal = Double.parseDouble(value);
} catch (IllegalArgumentException ex) {
}//without exception; n_ 29.5.2008
return returnVal;
}
public static double parseDouble(String value) {
double returnVal = Double.NaN;
try {
returnVal = Double.parseDouble(value);
} catch (IllegalArgumentException ex) {
ImageJAccessOJ.InterpreterAccess.interpError("\"" + value + "\" is not a float");
}
return returnVal;
}
public static boolean parseBoolean(String value) {
int intValue = MacroProcessorOJ.parseInt(value);
return intValue > 0 ? true : false;
}
public static void makeBoundingRoi(String value) {
value = value.toLowerCase();
boolean isCircle = value.indexOf("circle") >= 0;
boolean isObj = value.indexOf("object") >= 0;
boolean isRect = value.indexOf("rectangle") >= 0;
boolean isSquare = value.indexOf("square") >= 0;
CellOJ cell = OJ.getData().getCells().getSelectedCell();
if (cell != null) {
Rectangle rr = cell.getRectangle();
int dia = Math.max(rr.width, rr.height);
//to be continued, 10.7.2008, n_
}
}
public int rankToIndex(int rank) {
int[] indexes = OJ.getData().getResults().getSortedIndexes(false);
rank -= one;
if (rank >= 0 && rank < indexes.length) {
return indexes[rank] + one;
} else {
return 0;
}
}
public int indexToRank(int index) {
index -= one;
int[] indexes = OJ.getData().getResults().getSortedIndexes(false);
for (int rank = 0; rank < indexes.length; rank++) {
if (indexes[rank] == index) {
return rank + one;
}
}
return 0;
}
}
|