Wednesday, April 25, 2012

How to get different random numbers?

I have a String array with many elements (as I haven't still finished the Application, I don't know exactly the number), maybe about 200. I would like to get 20 random elements of this array, but being certain that every random element occurs only once, like, I don't want to get in those 20 elements the 5th element (for example) twice. How can I do this?





Pruning a AbstractTableModel without getValueAt() complications

Is there a way to derive a pruned AbstractTableModel from a full AbstractTableModel without getValueAt() complications?



My full data (including userIds) is loaded into a JTable AbstractTableModel. However, for display purposes, I wish to derive a pruned AbstractTableModel of data associated with a particular userId.



I am beginning to think this is not possible because getValueAt intervenes and throws IndexOutOfBounds exceptions? These exceptions seem to occur becuase the pruned Data is not populated.



public class PrunedUserIdTableModel extends AbstractTableModel {

TableModel fullModel;
List columnIdentifiers;
List tempDatum;
List tempData; // holds tempDatums
int rowCount; // reports pruned rowCount through getRowCount() method
List prunedData; // intended to hold data of matched userId rows

public PrunedUserIdTableModel(JTable fullTable, String userId) {
fullModel = fullTable.getModel();
columnIdentifiers = new ArrayList();
tempDatum = new ArrayList();
tempData = new ArrayList();
rowCount = 0;

List<Integer> userCount = new ArrayList<>();

// Load columnIdentifiers from fullModel; omitted here

// Go through fullModel searching for rows with matching userIds

for (int i = 0; i < fullModel.getRowCount(); i++) {
for (int k = 0; k < fullModel.getColumnCount(); k++) {
tempDatum.add(fullModel.getValueAt(i,k);
if ((fullModel.getValueAt(i,k).equals(userId)) {
// Matching userId found; record relevant row
userCount.add(g);
}
}
tempData.add(tempDatum);
tempDatum.clear();
}

// Now populate prunedData
for (int j = 0; j < userCount.size(); j++) {
prunedData.add(tempData.get(userCount.get(j)));
rowCount=rowCount+1;
}

fireTableChanged(null);
}
@Override
public int getRowCount() {
return rowCount;
}
@Override
public int getColumnCount() {
return fullModel.getColumnCount();
}
@Override
public int getValueAt(int rowIndex, int columnIndex) {
// THROWS INDEX OUT OF BOUNDS EXCEPTION: Index 0; size 0
List rowList = (List)prunedData.get(rowIndex);
return rowList.get(columnIndex);
}
}




CSS3 transitions want to add a colour and fade it away

I want to make a DIV background (which doesn't have a background color) flash red then ease out to blank again. now I have used JS to add a new CLASS (which adds the red) to the DIV in question and CSS3 to add an easing to the background color. but it eases it IN, what I want is it to go RED then ease out. I guess I could do this by using JS to add multiple CLasss after a delay. but can CSS3 be used to do this entirely?



cheers





Dom parsing in android

i have parsed xml using dom parser,but when the xml element contains no value it throws null pointer Exception.how to check this?...
here my code



NodeList TrackName1 = fstElmnt2.getElementsByTagName("Artist_Name");    


Element TrackElement1 = (Element) TrackName1.item(0);

TrackName1 = TrackElement1.getChildNodes();
result=result+((Node) TrackName1.item(0)).getNodeValue()

String Artistname=((Node)TrackName1.item(0)).getNodeValue();



}




Combotree in javascript (jquery)

I'm looking for a component which enable display tree in combo (select).
Something like that: http://www.jeasyui.com/demo/index.php



But this component doesn't allow import JSON directly, only from file.



It works in that way:



$('#cc').combotree({  
url:'tree_data.json'
});


I need (pseudocode):



$('#cc').combotree({  
data:'[{"id":1,"text":"City","children":[{"id":11,"text":"Wyoming","children":[{"id":111,"text":"Albin"}]}]}]'
});


Or (pseudocode):



$('#cc').combotree({  
data:'<?php $json_string; ?>'
});


Is it possible? Or maybe do you know any components which enable to do that?



Regards,
Chris





Frame with 50 png in iPhone

I have a ViewController with 16 buttons. Each button loads a popover that show 50 frames renders in moving.



What is the best form to do it?



I know that imageWithName is bad because it load all images in cache, and for this reason im doing it with:



myAnimatedView.animationImages=[NSArray arrayWithObjects:
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@0000",nombrePieza]ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@0001",nombrePieza]ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@0002",nombrePieza]ofType:@"png"]],
...
...
... [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@0050",nombrePieza]ofType:@"png"]],nil];


But when i load about 10 times the popover with differents frames, i have a leak of memory only on my device, but not in the simulator.



For this reason, i want know which is the best form to do it?



With a video? or with CAAnimation?



Thanks for help.





How to hide the code of firefox extension

I made an IE toolbar by BHO with C#. And now I want to make a firefox version.
I planned to use xul but it will show the source code to the user.
Seems DLL is not a good way in firefox.



I tried some toolbar like yahoo, google which will not create files in extension folder.
How can I make something like that?