private MediaSize[] getMediaSizes(ArrayList idList, int[] media) {
String prnPort = getPort();
int[] mediaSz = getAllMediaSizes(printer, prnPort);
String[] winMediaNames = getAllMediaNames(printer, prnPort);
MediaSizeName msn = null;
MediaSize ms = null;
float wid, ht;
if ((mediaSz == null) || (winMediaNames == null)) {
return null;
}
int nMedia = mediaSz.length/2;
ArrayList msList = new ArrayList();
for (int i = 0; i < nMedia; i++, ms=null) {
wid = mediaSz[i*2]/10f;
ht = mediaSz[i*2+1]/10f;
// Make sure to validate wid & ht.
// HP LJ 4050 (german) causes IAE in Sonderformat paper, wid & ht
// returned is not constant.
if ((wid <= 0) || (ht <= 0)) {
//Remove corresponding ID from list
if (nMedia == media.length) {
Integer remObj = new Integer(media[i]);
idList.remove(idList.indexOf(remObj));
}
continue;
}
// Find matching media using dimensions.
// This call matches only with our own predefined sizes.
msn = findMatchingMediaSizeNameMM(wid, ht);
if (msn != null) {
ms = MediaSize.getMediaSizeForName(msn);
}
if (ms != null) {
msList.add(ms);
} else {
Win32MediaSize wms =
new Win32MediaSize(winMediaNames[i], media[i]);
try {
ms = new MediaSize(wid, ht, MediaSize.MM, wms);
msList.add(ms);
} catch(IllegalArgumentException e) {
if (nMedia == media.length) {
Integer remObj = new Integer(media[i]);
idList.remove(idList.indexOf(remObj));