FileDocCategorySizeDatePackage
MediaPlayerMediaLocationEditor.javaAPI DocJMF 2.1.1e10577Mon May 12 12:20:42 BST 2003javax.media.bean.playerbean

MediaPlayerMediaLocationEditor

public class MediaPlayerMediaLocationEditor extends Panel implements PropertyEditor, ActionListener, ItemListener
Special case property editor for the media location property of a MediaPlayer bean. Invoked by Java Beans application builders.
version
1.0

Fields Summary
PropertyChangeSupport
support
String
mediaLocationString
TextField
mediaLocationTextField
private String
browseString
private Button
browseB
private Choice
protocolChooser
private String
httpString
private String
httpsString
private String
fileString
private String
rtpString
private String
ftpString
private String
codeString
private String
chooseOneString
private boolean
isFile
Panel
editPanel
Constructors Summary
public MediaPlayerMediaLocationEditor()
Default constructor that adds the KeyListener for the visual text field.

  
	               	  
    
  
    setLayout(new BorderLayout());
    editPanel.setLayout(new BorderLayout());
    editPanel.add("Center", mediaLocationTextField);
    editPanel.add("East", browseB);
    browseB.addActionListener(this);
    browseB.setEnabled(false);
    protocolChooser.add(chooseOneString);
    protocolChooser.add(fileString);
    protocolChooser.add(httpString);
    protocolChooser.add(httpsString);
    protocolChooser.add(rtpString);
    protocolChooser.add(ftpString);
    protocolChooser.add(codeString);
    protocolChooser.addItemListener(this);
    editPanel.add("West", protocolChooser);
    
    //Ready button originally was designed for WebRunner's BeanTool.  
    //For other IDEs, when OK button is clicked, the event will be
    //generated, and MediaLocation value will get set.  This is true
    //for Symantec Cafe, VisualAge for Java, and JBuilder.  For other
    //IDEs, if event doesn't get generated, it is user's responsibility
    //to make sure the value will be set when OK button is clicked.
    
    //   editPanel.add("South",readyB);
    //   readyB.addActionListener(this);
    //   readyB.setEnabled(false);
    
    add("Center", editPanel);
    KeyListener l = new KeyAdapter()
    {
    
      /**
      *   The actions to take when a key is typed in the
      *   medial location property.
      *   
      * @param keyEvent The <CODE>KeyEvent</CODE> for the key just typed.
      *
      */
      public void keyReleased(KeyEvent keyEvent)
      {
	      mediaLocationString = mediaLocationTextField.getText();
	      /*
	      if (mediaLocationString.length()==0)
	        readyB.setEnabled(false);
	      else  
	        readyB.setEnabled(true);
	      */
      }   
    };
  
		mediaLocationTextField.addKeyListener(l);
		mediaLocationTextField.setEnabled(false);
  
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent evt)
Determines which controls have had the specified action performed and acts accordingly.

param
evt The ActionEvent.

    String command = evt.getActionCommand();
    String filename;
    if (command.equals(browseString))
    {
      if (isFile==true)
      {
        FileDialog fd = new FileDialog(getFrame(editPanel), 
                        MediaPlayerResource.getString("SET_MEDIA_LOCATION"),
                        FileDialog.LOAD);
        fd.setDirectory("c:\\");
        fd.setTitle(MediaPlayerResource.getString("SET_MEDIA_LOCATION"));
        fd.show();
        filename = fd.getFile();
        if (filename != null && fd.getDirectory() != null) 
        {
          filename = fd.getDirectory() + filename;
        }
        if (filename != null) {
          filename = filename.replace('\\", '/");
          String tmp = "file:///"+filename;
          mediaLocationTextField.setText(tmp);
          setAsText(tmp);
      //   readyB.setEnabled(true);
        }
      }
      else
      {
        MediaPlayerRTPDialog rtpDlg= new MediaPlayerRTPDialog(getFrame(editPanel));
        rtpDlg.show();
        filename = rtpDlg.getRTPAdr(); 
        if (filename !=null) 
        {
          String tmp = "rtp://"+filename;
          mediaLocationTextField.setText(tmp);
          setAsText(tmp);
        }
      }
    }
    //The code below is to handle Ready button
    /*
    else if (command.equals(readyString))
    {
      String tmp = mediaLocationString;  
      String choiceSelection = protocolChooser.getSelectedItem();
      setAsText(tmp);
		  support.firePropertyChange("mediaLocation",
									null,
									mediaLocationString);
    } 
    */
  
public voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)
Registers a listener for the PropertyChangeEvent .

param
listener An object to be invoked when a PropertyChangeEvent is fired.

		support.addPropertyChangeListener(listener);
  
public java.lang.StringgetAsText()
Gets the mediaLocation property.

return
The value of the media location property as a String.

		return this.mediaLocationString;
	
public java.awt.ComponentgetCustomEditor()
Gets the panel that supports the media location editing.

param
The panel as a Component.

	  return editPanel;
	
java.awt.FramegetFrame(java.awt.Component comp)
Sets up a Frame at the position where the specified Component located.

param
comp The Component where the Frame will be located.

    Point p = comp.getLocationOnScreen();
    Frame f = new Frame();
    f.setLocation(p);
    return f;
  
public java.lang.StringgetJavaInitializationString()
Generates a code fragment that can be used to initialize a variable with the current mediaLocation property value.

return
The initialization String.

		String initString;
		
		if (mediaLocationString.length() == 0) 
		{
			initString = "new java.lang.String(\"\\\")";
		}
		else 
		{
			initString = "new java.lang.String(\""
						+ mediaLocationString
						+ "\")";
		}
		return initString;
  
public java.awt.DimensiongetPreferredSize()
Gets the preferred dimensions for this media location editor.

return
A Dimension that contains the preferred dimensions.

		return new Dimension(400, 100); 
  
public java.lang.String[]getTags()
Determines whether or not this is a tagged value.

return
null to tell the bean builder that this is not a tagged value property.

		return null;
	
public java.lang.ObjectgetValue()
Gets the value from the media location property.

return
The media location property value.

    return getAsText();
	
public booleanisPaintable()
Determines whether or not this class honors the paintValue method. Used by bean builders.

return
true if it honors the paintValue method, false if it does not.

		return true;
  
public voiditemStateChanged(java.awt.event.ItemEvent evt)
Determines which protocol is selected and acts accordingly.

param
evt The ItemEvent.

    String item = (String)evt.getItem();
    if (!item.equals(chooseOneString) ) 
    {
      mediaLocationTextField.setEnabled(true);
      if (item.equals(fileString))
      {
        browseB.setEnabled(true);
        isFile=true;
      }
      else if (item.equals(rtpString))
      {
        browseB.setEnabled(true);
      }
      else
      {
        browseB.setEnabled(false);
      }
      if (!item.equals(codeString))
      {
        mediaLocationTextField.setText(item);
	    }
	    else
	    {
	      mediaLocationTextField.setText("");
	    }
      //    readyB.setEnabled(false);
	    mediaLocationString = mediaLocationTextField.getText();
	   }
    else
    {
      mediaLocationTextField.setEnabled(false);
      browseB.setEnabled(false);
      //    readyB.setEnabled(false);
    }
  
public voidpaintValue(java.awt.Graphics g, java.awt.Rectangle area)
Paints the media location's editor box.

param
g The graphics context in which to paint the editor box.
param
area The area in which the editor box should be rendered.

		Color c = g.getColor();
		g.setColor(Color.black);
		g.drawString(mediaLocationString,
					area.x, area.y + area.height - 6);
		g.setColor(c);
	
public voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes the specified listener from the property change listener list.

param
listener The PropertyChangeListener to be removed.

		support.removePropertyChangeListener(listener);
  
public voidsetAsText(java.lang.String s)
Sets the property value to the specified string.

param
s The String to set the media location property value to.

 
		mediaLocationString = s;
	
public voidsetValue(java.lang.Object o)
Sets the value for the media location property.

param
o The new media location property object.

    setAsText(o.toString());
	
public booleansupportsCustomEditor()
Determines whether or not this property editor supports a custom editor.

return
true since the media location property can provide a custom editor.

		return true;