📄 pictureuploadpolicy.java
字号:
/**
* This method handles the clicks on the rotation buttons. All other actions
* are managed by the {@link DefaultUploadPolicy}.
*
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
displayInfo("Action : " + e.getActionCommand());
if (e.getActionCommand() == this.rotateLeftButton.getActionCommand()) {
this.picturePanel.rotate(-1);
} else if (e.getActionCommand() == this.rotateRightButton
.getActionCommand()) {
this.picturePanel.rotate(1);
}
}// actionPerformed
/**
* @see wjhk.jupload2.policies.UploadPolicy#onFileSelected(wjhk.jupload2.filedata.FileData)
*/
@Override
public void onFileSelected(FileData fileData) {
if (fileData != null) {
displayDebug("File selected: " + fileData.getFileName(), 30);
}
if (this.picturePanel != null) {
// If this file is a picture, we display it.
if (fileData instanceof PictureFileData) {
Cursor previousCursor = setWaitCursor();
this.picturePanel.setPictureFile((PictureFileData) fileData,
this.rotateLeftButton, this.rotateRightButton);
setCursor(previousCursor);
} else {
this.picturePanel.setPictureFile(null, this.rotateLeftButton,
this.rotateRightButton);
}
}
}
/**
* Open the 'big' preview dialog box. It allows the user to see a full
* screen preview of the choosen picture.<BR>
* This method does nothing if the panel has no selected picture, that is
* when pictureFileData is null.
*
* @see UploadPolicy#onFileDoubleClicked(FileData)
*/
@Override
public void onFileDoubleClicked(FileData pictureFileData) {
if (pictureFileData == null) {
// No action
} else if (!(pictureFileData instanceof PictureFileData)) {
displayWarn("PictureUploadPolicy: received a non PictureFileData in onFileDoubleClicked");
} else {
new PictureDialog(null, (PictureFileData) pictureFileData, this);
}
}
/** @see UploadPolicy#beforeUpload() */
@Override
public void beforeUpload() {
// We clear the current picture selection. This insures a correct
// managing of enabling/disabling of
// buttons, even if the user stops the upload.
getApplet().getUploadPanel().getFilePanel().clearSelection();
if (this.picturePanel != null) {
this.picturePanel.setPictureFile(null, this.rotateLeftButton,
this.rotateRightButton);
}
// Then, we call the standard action, if any.
super.beforeUpload();
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////// Getters and Setters
// ////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Getter for fileChooserImagePreview.
*
* @return Current value for the applet parameter: fileChooserImagePreview
* @see UploadPolicy#PROP_FILE_CHOOSER_IMAGE_PREVIEW
*/
public boolean getFileChooserImagePreview() {
return this.fileChooserImagePreview;
}
/**
* Setter for fileChooserIconFromFileContent. Current allowed values are:
* -1, 0, 1. Default value is 0.
*
* @param fileChooserImagePreview new value to store, for the applet
* parameter: fileChooserImagePreview.
* @see UploadPolicy#PROP_FILE_CHOOSER_IMAGE_PREVIEW
*/
public void setFileChooserImagePreview(boolean fileChooserImagePreview) {
this.fileChooserImagePreview = fileChooserImagePreview;
}
/** @return the applet parameter <I>highQualityPreview</I>. */
public boolean getHighQualityPreview() {
return this.highQualityPreview;
}
/** @param highQualityPreview the highQualityPreview to set */
void setHighQualityPreview(boolean highQualityPreview) {
this.highQualityPreview = highQualityPreview;
}
/**
* @return Returns the maxHeight, that should be used by pictures non
* transformed (rotated...) by the applet.
*/
public int getMaxHeight() {
return this.maxHeight;
}
/** @param maxHeight the maxHeight to set */
void setMaxHeight(int maxHeight) {
if (maxHeight <= 0) {
this.maxHeight = Integer.MAX_VALUE;
displayWarn("[setMaxHeight] maxHeight switched from " + maxHeight
+ " to " + this.maxHeight);
} else {
this.maxHeight = maxHeight;
}
}
/**
* @return Returns the maxWidth, that should be used by pictures non
* transformed (rotated...) by the applet.
*/
public int getMaxWidth() {
return this.maxWidth;
}
/** @param maxWidth the maxWidth to set */
void setMaxWidth(int maxWidth) {
if (maxWidth <= 0) {
this.maxWidth = Integer.MAX_VALUE;
displayWarn("[setMaxWidth] maxWidth switched from " + maxWidth
+ " to " + this.maxWidth);
} else {
this.maxWidth = maxWidth;
}
}
/**
* @return The current value for picture compression.
*/
public float getPictureCompressionQuality() {
return this.pictureCompressionQuality;
}
/**
* @see #pictureCompressionQuality
* @param pictureCompressionQuality The new value for picture compression.
*/
void setPictureCompressionQuality(float pictureCompressionQuality) {
this.pictureCompressionQuality = pictureCompressionQuality;
}
/**
* @return The current value for transmission (or no transmission) of
* picture metadata.
*/
public boolean getPictureTransmitMetadata() {
return this.pictureTransmitMetadata;
}
/**
* @see #pictureTransmitMetadata
* @param pictureTransmitMetadata The new value for this attribute.
*/
void setPictureTransmitMetadata(boolean pictureTransmitMetadata) {
this.pictureTransmitMetadata = pictureTransmitMetadata;
}
/**
* @return Returns the maxHeight, that should be used by pictures that are
* transformed (rotated...) by the applet.
*/
public int getRealMaxHeight() {
return (this.realMaxHeight == Integer.MAX_VALUE) ? this.maxHeight
: this.realMaxHeight;
}
/** @param realMaxHeight the realMaxHeight to set */
void setRealMaxHeight(int realMaxHeight) {
this.realMaxHeight = realMaxHeight;
}
/**
* @return Returns the maxWidth, that should be used by pictures that are
* transformed (rotated...) by the applet.
*/
public int getRealMaxWidth() {
return (this.realMaxWidth == Integer.MAX_VALUE) ? this.maxWidth
: this.realMaxWidth;
}
/** @param realMaxWidth the realMaxWidth to set */
void setRealMaxWidth(int realMaxWidth) {
this.realMaxWidth = realMaxWidth;
}
/** @return Returns the createBufferedImage. */
public boolean hasToStoreBufferedImage() {
return this.storeBufferedImage;
}
/** @param storeBufferedImage the storeBufferedImage to set */
void setStoreBufferedImage(boolean storeBufferedImage) {
this.storeBufferedImage = storeBufferedImage;
}
/** @return Returns the targetPictureFormat. */
public String getTargetPictureFormat() {
return this.targetPictureFormat;
}
/** @param targetPictureFormat the targetPictureFormat to set */
void setTargetPictureFormat(String targetPictureFormat) {
this.targetPictureFormat = targetPictureFormat;
}
/**
* This method manages the applet parameters that are specific to this
* class. The super.setProperty method is called for other properties.
*
* @param prop The property which value should change
* @param value The new value for this property. If invalid, the default
* value is used.
* @see wjhk.jupload2.policies.UploadPolicy#setProperty(java.lang.String,
* java.lang.String)
*/
@Override
public void setProperty(String prop, String value) throws JUploadException {
// The, we check the local properties.
if (prop.equals(PROP_FILE_CHOOSER_IMAGE_PREVIEW)) {
setFileChooserImagePreview(UploadPolicyFactory.parseBoolean(value,
getFileChooserImagePreview(), this));
} else if (prop.equals(PROP_STORE_BUFFERED_IMAGE)) {
setStoreBufferedImage(UploadPolicyFactory.parseBoolean(value,
this.storeBufferedImage, this));
} else if (prop.equals(PROP_HIGH_QUALITY_PREVIEW)) {
setHighQualityPreview(UploadPolicyFactory.parseBoolean(value,
this.highQualityPreview, this));
} else if (prop.equals(PROP_MAX_HEIGHT)) {
setMaxHeight(UploadPolicyFactory.parseInt(value, this.maxHeight,
this));
} else if (prop.equals(PROP_MAX_WIDTH)) {
setMaxWidth(UploadPolicyFactory
.parseInt(value, this.maxWidth, this));
} else if (prop.equals(PROP_PICTURE_COMPRESSION_QUALITY)) {
setPictureCompressionQuality(UploadPolicyFactory.parseFloat(value,
this.pictureCompressionQuality, this));
} else if (prop.equals(PROP_PICTURE_TRANSMIT_METADATA)) {
setPictureTransmitMetadata(UploadPolicyFactory.parseBoolean(value,
this.pictureTransmitMetadata, this));
} else if (prop.equals(PROP_REAL_MAX_HEIGHT)) {
setRealMaxHeight(UploadPolicyFactory.parseInt(value,
this.realMaxHeight, this));
} else if (prop.equals(PROP_REAL_MAX_WIDTH)) {
setRealMaxWidth(UploadPolicyFactory.parseInt(value,
this.realMaxWidth, this));
} else if (prop.equals(PROP_TARGET_PICTURE_FORMAT)) {
setTargetPictureFormat(value);
} else {
// Otherwise, transmission to the mother class.
super.setProperty(prop, value);
}
}
/** @see DefaultUploadPolicy#displayParameterStatus() */
@Override
public void displayParameterStatus() {
super.displayParameterStatus();
displayDebug("======= Parameters managed by PictureUploadPolicy", 30);
displayDebug(PROP_FILE_CHOOSER_IMAGE_PREVIEW + ": "
+ getFileChooserImagePreview(), 30);
displayDebug(PROP_HIGH_QUALITY_PREVIEW + " : "
+ this.highQualityPreview, 30);
displayDebug(PROP_PICTURE_COMPRESSION_QUALITY + " : "
+ getPictureCompressionQuality(), 30);
displayDebug(PROP_PICTURE_TRANSMIT_METADATA + " : "
+ getPictureTransmitMetadata(), 30);
displayDebug(PROP_MAX_WIDTH + " : " + this.maxWidth + ", "
+ PROP_MAX_HEIGHT + " : " + this.maxHeight, 30);
displayDebug(PROP_REAL_MAX_WIDTH + " : " + this.realMaxWidth + ", "
+ PROP_REAL_MAX_HEIGHT + " : " + this.realMaxHeight, 30);
displayDebug(PROP_STORE_BUFFERED_IMAGE + " : "
+ this.storeBufferedImage, 30);
displayDebug(PROP_TARGET_PICTURE_FORMAT + " : "
+ this.targetPictureFormat, 30);
displayDebug("", 30);
}
/**
* Calls the {@link DefaultUploadPolicy#setWaitCursor()} method, then erases
* the picture panel specific cursor.
*
* @see DefaultUploadPolicy#setCursor(Cursor)
*/
@Override
public Cursor setWaitCursor() {
Cursor previousCursor = super.setWaitCursor();
this.picturePanel.setCursor(null);
return previousCursor;
}
/**
* Calls the {@link DefaultUploadPolicy#setCursor(Cursor)} method, then set
* the picture panel specific cursor.
*
* @see DefaultUploadPolicy#setCursor(Cursor)
*/
@Override
public void setCursor(Cursor cursor) {
super.setCursor(null);
this.picturePanel.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
/**
* Creates the file chooser, from the default implementation, then add an
* accessory to preview pictures.
*
* @see UploadPolicy#createFileChooser()
*/
@Override
public JUploadFileChooser createFileChooser() {
JUploadFileChooser jufc = super.createFileChooser();
if (getFileChooserImagePreview()) {
jufc.setAccessory(new JUploadImagePreview(jufc, this));
}
return jufc;
}
/**
* Returns an icon, calculated from the image content. Currently only
* pictures managed by ImageIO can be displayed. Once upon a day, extracting
* the first picture of a video may become reality... ;-) <BR>
* Note: this method is called in a dedicated thread by the
* JUploadFileChooser, to avoid to calculate the icon for all pictures, when
* opening a new folder.
*
* @return The calculated ImageIcon, or null if no picture can be extracted.
* @see UploadPolicy#fileViewGetIcon(File)
* @see UploadPolicy#PROP_FILE_CHOOSER_ICON_FROM_FILE_CONTENT
*/
@Override
public Icon fileViewGetIcon(File file) {
return PictureFileData.getImageIcon(file, getFileChooserIconSize(),
getFileChooserIconSize());
}
/**
* Implementation of the ImageObserver interface
*
* @param arg0
* @param arg1
* @param arg2
* @param arg3
* @param arg4
* @param arg5
* @return true or false
*/
public boolean imageUpdate(Image arg0, int arg1, int arg2, int arg3,
int arg4, int arg5) {
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -