H
hello_world
Hi,
I've developed an applet which enables multiple file uploads via http
using HttpClient 3.0. During the upload process, I would like to
display a non-modal dialog box with some text and an animation
(basically a message - "uploading" - and an animated GIF). As soon as
upload is over, the dialog box should disappear.
To achieve this, I use a JDialog, and within it, a JPanel containing 2
JLabels: one for the text message and the other for the GIF image. My
problem is I get a grey area, the size of my dialog, with no controls
whatsoever inside, when I try to display the dialog!
I would be grateful if someone could help me resolve this issue. Please
see code below:
-------- my dialog class --------
public class TransferProgressDialog extends javax.swing.JDialog{
private javax.swing.JLabel caption;
private javax.swing.JLabel progressImg;
private javax.swing.JPanel progressAnimJPanel;
private java.awt.Component component;
private int posX, posY;
public TransferProgressDialog(java.awt.Component component, String
folderName){
initComponents();
this.component = component;
this.setLocationRelativeTo(component);
caption.setText("Uploading " + folderName);
}
public void showDialog(){
this.setVisible(true);
component.setEnabled(false);
}
public void hideDialog(){
this.hide();
component.setEnabled(true);
}
private void dialogMousePressed(java.awt.event.MouseEvent evt) {
posX = evt.getX();
posY = evt.getY();
}
private void dialogMouseDragged(java.awt.event.MouseEvent evt) {
int deltaX = evt.getX() - posX;
int deltaY = evt.getY() - posY;
java.awt.Point pt = this.getLocation();
this.setLocation(pt.x + deltaX, pt.y + deltaY);
}
private void initComponents(){
java.awt.GridBagConstraints gridBagConstraints;
progressAnimJPanel = new javax.swing.JPanel();
caption = new javax.swing.JLabel();
progressImg = new javax.swing.JLabel();
progressAnimJPanel.setLayout(new java.awt.GridBagLayout());
progressAnimJPanel.setBorder(new
javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
caption.setFont(new java.awt.Font("Tahoma", 1, 10));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.ipady = 7;
progressAnimJPanel.add(caption, gridBagConstraints);
progressImg.setIcon(new
javax.swing.ImageIcon("./loading.gif"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.ipady = 7;
progressAnimJPanel.add(progressImg, gridBagConstraints);
this.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
dialogMousePressed(evt);
}
});
addMouseMotionListener(new java.awt.event.MouseMotionAdapter()
{
public void mouseDragged(java.awt.event.MouseEvent evt) {
dialogMouseDragged(evt);
}
});
this.setContentPane(progressAnimJPanel);
this.setSize(140, 80);
this.setUndecorated(true);
this.setAlwaysOnTop(true);
}
}
-------- end dialog class --------
-------- sample code where I make use of the dialog --------
public static boolean uploadFolder(File folder, String targetUrl,
java.awt.Component component){
boolean success = true;
PostMethod filePost = new PostMethod(targetUrl);
filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,
false);
TransferProgressDialog d = new
TransferProgressDialog(component, folder.getName());
try{
d.showDialog();
File[] files = folder.listFiles();
int numFiles = files.length;
Part[] parts = new Part[numFiles + 1];
parts[0] = new StringPart("folder_name", folder.getName());
for(int i=0; i<numFiles; i++){
parts[i+1] = new FilePart(files.getName(),
files);
}
filePost.setRequestEntity(new MultipartRequestEntity(parts,
filePost.getParams()));
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
int status = client.executeMethod(filePost);
if(status != HttpStatus.SC_OK){
success = false;
}
}catch(Exception ex){
success = false;
ex.printStackTrace();
}finally{
filePost.releaseConnection();
d.hideDialog();
return success;
}
}
-------- end sample code --------
I've developed an applet which enables multiple file uploads via http
using HttpClient 3.0. During the upload process, I would like to
display a non-modal dialog box with some text and an animation
(basically a message - "uploading" - and an animated GIF). As soon as
upload is over, the dialog box should disappear.
To achieve this, I use a JDialog, and within it, a JPanel containing 2
JLabels: one for the text message and the other for the GIF image. My
problem is I get a grey area, the size of my dialog, with no controls
whatsoever inside, when I try to display the dialog!
I would be grateful if someone could help me resolve this issue. Please
see code below:
-------- my dialog class --------
public class TransferProgressDialog extends javax.swing.JDialog{
private javax.swing.JLabel caption;
private javax.swing.JLabel progressImg;
private javax.swing.JPanel progressAnimJPanel;
private java.awt.Component component;
private int posX, posY;
public TransferProgressDialog(java.awt.Component component, String
folderName){
initComponents();
this.component = component;
this.setLocationRelativeTo(component);
caption.setText("Uploading " + folderName);
}
public void showDialog(){
this.setVisible(true);
component.setEnabled(false);
}
public void hideDialog(){
this.hide();
component.setEnabled(true);
}
private void dialogMousePressed(java.awt.event.MouseEvent evt) {
posX = evt.getX();
posY = evt.getY();
}
private void dialogMouseDragged(java.awt.event.MouseEvent evt) {
int deltaX = evt.getX() - posX;
int deltaY = evt.getY() - posY;
java.awt.Point pt = this.getLocation();
this.setLocation(pt.x + deltaX, pt.y + deltaY);
}
private void initComponents(){
java.awt.GridBagConstraints gridBagConstraints;
progressAnimJPanel = new javax.swing.JPanel();
caption = new javax.swing.JLabel();
progressImg = new javax.swing.JLabel();
progressAnimJPanel.setLayout(new java.awt.GridBagLayout());
progressAnimJPanel.setBorder(new
javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
caption.setFont(new java.awt.Font("Tahoma", 1, 10));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.ipady = 7;
progressAnimJPanel.add(caption, gridBagConstraints);
progressImg.setIcon(new
javax.swing.ImageIcon("./loading.gif"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.ipady = 7;
progressAnimJPanel.add(progressImg, gridBagConstraints);
this.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
dialogMousePressed(evt);
}
});
addMouseMotionListener(new java.awt.event.MouseMotionAdapter()
{
public void mouseDragged(java.awt.event.MouseEvent evt) {
dialogMouseDragged(evt);
}
});
this.setContentPane(progressAnimJPanel);
this.setSize(140, 80);
this.setUndecorated(true);
this.setAlwaysOnTop(true);
}
}
-------- end dialog class --------
-------- sample code where I make use of the dialog --------
public static boolean uploadFolder(File folder, String targetUrl,
java.awt.Component component){
boolean success = true;
PostMethod filePost = new PostMethod(targetUrl);
filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,
false);
TransferProgressDialog d = new
TransferProgressDialog(component, folder.getName());
try{
d.showDialog();
File[] files = folder.listFiles();
int numFiles = files.length;
Part[] parts = new Part[numFiles + 1];
parts[0] = new StringPart("folder_name", folder.getName());
for(int i=0; i<numFiles; i++){
parts[i+1] = new FilePart(files.getName(),
files);
}
filePost.setRequestEntity(new MultipartRequestEntity(parts,
filePost.getParams()));
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
int status = client.executeMethod(filePost);
if(status != HttpStatus.SC_OK){
success = false;
}
}catch(Exception ex){
success = false;
ex.printStackTrace();
}finally{
filePost.releaseConnection();
d.hideDialog();
return success;
}
}
-------- end sample code --------