//
// CBROWMOFStatus.java
//
// The contents of this file are subject to the SNIA Public License Version 1.0
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
//	http://www.snia.org/resources/openSource.html
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is CBROWMOFStatus.java
// 
// The Initial Developer of the Original Code is David Simons.
//
// Contributor(s):
//
//
// This source uses the Solaris WBEM APIs version 2.2. 
// Synchronization will be maintained with the Solaris WBEM APIS,
// which are being standardized through the Java Community Process.
//
//
// $Id: CBROWMOFStatus.java,v 1.1 2003/07/17 18:32:55 kumpf Exp $
//
// $Log: CBROWMOFStatus.java,v $
// Revision 1.1  2003/07/17 18:32:55  kumpf
// HP-BAPU: PEP-64 CIM Client and CIM Listener Java Interface
//
// Revision 1.1.1.1  2001/10/31 18:15:00  karl
// import of SNIA 0_7
//
// Revision 1.9  2001/03/20 13:13:40  davidsi
// - Try to get the dialog and status to remain the same size.
//
// Revision 1.8  2000/08/16 05:59:55  shawn
// merge P_TOMCAT31 branch
//
// Revision 1.7.8.1  2000/08/10 00:03:31  shawn
// head merge
//
// Revision 1.7  2000/05/12 12:07:20  davidsi
// - Fixed string that contains spaces (tabs were inserted when using expand).
//
// Revision 1.6  2000/05/12 11:24:36  davidsi
// - Fixed bug in fileOpened() for pathnames > 60 chars.
//
// Revision 1.5  2000/05/11 10:11:55  davidsi
// - Fixed tabs.
//
// Revision 1.4  2000/05/06 17:13:50  davidsi
// - Brought in line with SUN WBEM APIs 2.2
//
// Revision 1.3  2000/04/09 13:34:47  davidsi
// - Added spacing to improve look on display.
//
// Revision 1.2  2000/02/13 15:09:40  davidsi
// - Added text to cover re-use of Solaris WBEM APIs.
//
// Revision 1.1.1.1  2000/02/06 16:41:03  davidsi
// Initial version.
//
//
//
package org.snia.wbemcmd.browser;

import java.awt.*;
import javax.swing.*;
import javax.swing.SwingUtilities;
import org.snia.wbemcmd.mof.MOFStatus;

//
// Dialog displaying status of MOF download
//
class CBROWMOFStatus extends JDialog implements MOFStatus   {
    static int WIDTH=400;
    static int HEIGHT=150;
    JLabel lbl1;
    JLabel lbl2;
    JPanel jp;
    String fileName;
    JProgressBar pbar;
    Frame origParent;
    static String blank="                                                     ";
    
    CBROWMOFStatus(Frame parent) {
	
	super(parent,"Loading MOF...",false);

	origParent=parent;
	
	jp=new JPanel();
	jp.setLayout(new BoxLayout(jp,BoxLayout.Y_AXIS));
	jp.setMaximumSize(new Dimension(WIDTH,200));
	jp.setMinimumSize(new Dimension(WIDTH,200));	    
	
	
	jp.add( new JLabel(" "));
	
	lbl1=new JLabel("File:");
	lbl1.setFont(new Font("SansSerif", Font.BOLD, 14));
	lbl1.setForeground(Color.black);
	lbl1.setAlignmentX(Component.LEFT_ALIGNMENT );

	
	jp.add(lbl1);
	
	lbl2=new JLabel("Complete: ");
	lbl2.setFont(new Font("SansSerif", Font.BOLD, 14));
	lbl2.setForeground(Color.black);
	
	pbar=new JProgressBar(0,100);
	pbar.setValue(0);
	pbar.setMaximumSize(new Dimension(WIDTH-95,20));
	pbar.setMinimumSize(new Dimension(WIDTH-95,20));
	
	JPanel jp3=new JPanel();
	jp3.setLayout(new BoxLayout(jp3,BoxLayout.X_AXIS));
	jp3.setAlignmentX(Component.LEFT_ALIGNMENT);
	jp3.add(lbl2);
	jp3.add(pbar);
	jp3.setMaximumSize(new Dimension(WIDTH,20));
	jp3.setMinimumSize(new Dimension(WIDTH,20));
	jp3.setBounds(0,0,WIDTH,20);
	
	jp.add(Box.createRigidArea(new Dimension(0,30)));
	jp.add(jp3);	
	jp.add(Box.createRigidArea(new Dimension(0,10)));
	Container cp=getContentPane();
	cp.add(jp,BorderLayout.WEST);
	
	//
	// Position in middle of screen
	//
	Toolkit tk=Toolkit.getDefaultToolkit();
	Dimension screenDim=tk.getScreenSize();

	Dimension windowDim=getSize();
	setLocation((screenDim.width-windowDim.width)/2,
		    (screenDim.height-windowDim.height)/2);
    
	pack(); 
	setSize(WIDTH,HEIGHT);

	show();
    }	
    
    public void fileOpened(String ifileName) {
	int len=ifileName.length();
	if (len<60) {
	    len=60-len;
	    String newName=ifileName.concat(blank.substring(1,len));
	    lbl1.setText("File:"+newName);
	} else
	    lbl1.setText("File:"+ifileName);
    }
    
    // Pam Wright, Imation Try to get the dialog and status to remain the same size
    public void setMessage(String msg) {
        int len=msg.length();
	if (len<60) {
	    len=60-len;
	    String newMsg=msg.concat(blank.substring(1,len));
	    lbl1.setText(newMsg);
	} else
	    lbl1.setText(msg);
    }
    
    public void removePercentage() {
	pbar.setVisible(false);
	lbl2.setVisible(false);
    }
    
    public void filePercent(int perc)
    {
	pbar.setValue(perc);
    }
    
    //
    // Return -1 to abort, 1 to continue ignoring error
    //
    public int errorHandler(String error)
    {
	Object[] opts={"Abort","Ignore"};
	
	int ret=JOptionPane.showOptionDialog(origParent,
		error,
		"MOF Parse Error",
		JOptionPane.YES_NO_CANCEL_OPTION,
		JOptionPane.ERROR_MESSAGE,
		null,
		opts,
		opts[0]);
	
	if (ret==0)
	    return(-1);
		
	return(1);
    }
    
    
}
