< prev index next >

src/java.desktop/share/classes/javax/print/attribute/standard/MediaSize.java

Print this page




 151         if (media != null && mediaMap.get(media) == null) {
 152             mediaName = media;
 153             mediaMap.put(mediaName, this);
 154         }
 155         sizeVector.add(this);
 156     }
 157 
 158     /**
 159      * Get the media name, if any, for this size.
 160      *
 161      * @return the name for this media size, or null if no name was
 162      * associated with this size (an anonymous size).
 163      */
 164     public MediaSizeName getMediaSizeName() {
 165         return mediaName;
 166     }
 167 
 168     /**
 169      * Get the MediaSize for the specified named media.
 170      *
 171      * @param media - the name of the media for which the size is sought
 172      * @return size of the media, or null if this media is not associated
 173      * with any size.
 174      */
 175     public static MediaSize getMediaSizeForName(MediaSizeName media) {
 176         return mediaMap.get(media);
 177     }
 178 
 179     /**
 180      * The specified dimensions are used to locate a matching MediaSize
 181      * instance from amongst all the standard MediaSize instances.
 182      * If there is no exact match, the closest match is used.
 183      * <p>
 184      * The MediaSize is in turn used to locate the MediaSizeName object.
 185      * This method may return null if the closest matching MediaSize
 186      * has no corresponding Media instance.
 187      * <p>
 188      * This method is useful for clients which have only dimensions and
 189      * want to find a Media which corresponds to the dimensions.
 190      * @param x - X dimension
 191      * @param y - Y dimension.
 192      * @param  units
 193      *     Unit conversion factor, e.g. <CODE>Size2DSyntax.INCH</CODE> or
 194      *     <CODE>Size2DSyntax.MM</CODE>
 195      * @return MediaSizeName matching these dimensions, or null.
 196      * @exception IllegalArgumentException if {@code x <= 0},
 197      *      {@code y <= 0}, or {@code units < 1}.
 198      *
 199      */
 200     public static MediaSizeName findMedia(float x, float y, int units) {
 201 
 202         MediaSize match = MediaSize.ISO.A4;
 203 
 204         if (x <= 0.0f || y <= 0.0f || units < 1) {
 205             throw new IllegalArgumentException("args must be +ve values");
 206         }
 207 
 208         double ls = x * x + y * y;
 209         double tmp_ls;
 210         float []dim;
 211         float diffx = x;




 151         if (media != null && mediaMap.get(media) == null) {
 152             mediaName = media;
 153             mediaMap.put(mediaName, this);
 154         }
 155         sizeVector.add(this);
 156     }
 157 
 158     /**
 159      * Get the media name, if any, for this size.
 160      *
 161      * @return the name for this media size, or null if no name was
 162      * associated with this size (an anonymous size).
 163      */
 164     public MediaSizeName getMediaSizeName() {
 165         return mediaName;
 166     }
 167 
 168     /**
 169      * Get the MediaSize for the specified named media.
 170      *
 171      * @param media  the name of the media for which the size is sought
 172      * @return size of the media, or null if this media is not associated
 173      * with any size.
 174      */
 175     public static MediaSize getMediaSizeForName(MediaSizeName media) {
 176         return mediaMap.get(media);
 177     }
 178 
 179     /**
 180      * The specified dimensions are used to locate a matching MediaSize
 181      * instance from amongst all the standard MediaSize instances.
 182      * If there is no exact match, the closest match is used.
 183      * <p>
 184      * The MediaSize is in turn used to locate the MediaSizeName object.
 185      * This method may return null if the closest matching MediaSize
 186      * has no corresponding Media instance.
 187      * <p>
 188      * This method is useful for clients which have only dimensions and
 189      * want to find a Media which corresponds to the dimensions.
 190      * @param x  X dimension
 191      * @param y  Y dimension.
 192      * @param  units
 193      *     Unit conversion factor, e.g. <CODE>Size2DSyntax.INCH</CODE> or
 194      *     <CODE>Size2DSyntax.MM</CODE>
 195      * @return MediaSizeName matching these dimensions, or null.
 196      * @exception IllegalArgumentException if {@code x <= 0},
 197      *      {@code y <= 0}, or {@code units < 1}.
 198      *
 199      */
 200     public static MediaSizeName findMedia(float x, float y, int units) {
 201 
 202         MediaSize match = MediaSize.ISO.A4;
 203 
 204         if (x <= 0.0f || y <= 0.0f || units < 1) {
 205             throw new IllegalArgumentException("args must be +ve values");
 206         }
 207 
 208         double ls = x * x + y * y;
 209         double tmp_ls;
 210         float []dim;
 211         float diffx = x;


< prev index next >