enableMargins(isMarginsEnabled);
if (firstUse) {
/* set margins at first time */
MediaMargins margins = null; // Margins for the dialog Margins fields
if (isMarginsEnabled) { // Margins fields are enabled and can be edited
Media selectedMedia = (Media) sizeBox.getSelectedItem();
boolean isMediaSizeSelected = (selectedMedia == null)
? false :
selectedMedia.getClass().isAssignableFrom(MediaSizeName.class);
MediaSize selectedSize = isMediaSizeSelected
? MediaSize.getMediaSizeForName((MediaSizeName) selectedMedia)
: null;
if (isMediaSupported
&& isPaSupported
&& attrs.containsKey(Media.class)
&& attrs.containsKey(MediaPrintableArea.class)
&& attrs.get(Media.class).equals(selectedMedia)
&& isMediaSizeSelected) {
/* p.1 - see fillMarginsFields() comments above*/
try {
MediaPrintableArea attrsPA = (MediaPrintableArea)
attrs.get(MediaPrintableArea.class);
margins = new MediaMargins(selectedSize, attrsPA);
} catch(IllegalArgumentException e) {
/*
* If we are unable to get correct margins values from the
* given MediaPrintableArea (attrsPA) and MediaSize
* (selectedSize), we just ignore this case
*/
}
}
if ((margins == null)
&& (isMarginsSupported || (dialogType == PAGE_DIALOG))) {
/* p.2 - see fillMarginsFields() comments above*/
margins = (MediaMargins) (attrs.containsKey(MediaMargins.class)
? attrs.get(MediaMargins.class)
: myService.getDefaultAttributeValue(MediaMargins.class));
}
if ((margins == null)
&& isPaSupported
&& isMediaSupported
&& isMediaSizeSelected) {
/* p.3 - see fillMarginsFields() comments above*/
try {
MediaPrintableArea defaultPA = (MediaPrintableArea)
myService.getDefaultAttributeValue(
MediaPrintableArea.class);
if ((defaultPA != null) && (selectedSize != null)) {
margins = new MediaMargins(selectedSize, defaultPA);
}
} catch (IllegalArgumentException e) {
/*
* If we are unable to get correct margins value from the
* default MediaPrintableArea (defPA) for this service and
* MediaSize (selectedSize), we just ignoew this case.
*/
}
}
if (margins == null) {
/* Just 25.4 mm margins! */
margins = new MediaMargins(25.4F, 25.4F, 25.4F, 25.4F,
MediaMargins.MM);
}
} else {
/* Margins fields are disabled, but we always set them to some
default meanings (25.4 mm) */
margins = (attrs.containsKey(MediaMargins.class)
? (MediaMargins) attrs.get(MediaMargins.class)
: new MediaMargins(25.4F, 25.4F, 25.4F, 25.4F,
MediaMargins.MM));
}
setMargins(margins);
}
}