Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /antelope/src/com/wutka/dtd/, /antelope/src/ise/antelope/common/builder/

antelope
Discussion topic

Back to topic list

CVS update: /antelope/src/com/wutka/dtd/, /antelope/src/ise/antelope/common/builder/

Author danson
Full name Dale Anson
Date 2004-03-02 20:45:29 PST
Message User: danson
Date: 04/03/02 20:45:29

Modified:
 /antelope/src/com/wutka/dtd/
  DTDAttribute.java, DTDContainer.java, DTDDecl.java, DTDItem.java
 /antelope/src/ise/an​telope/common/builde​r/
  AntTransferable.java, AttributeViewer.java, ElementFlavor.java,
  ElementPanel.java, ElementTransferHandler.java, ProjectBuilder.java,
  TreeTransferHandler.java

Log:
 general commit
 

File Changes:

Directory: /antelope/src/com/wutka/dtd/
====================​===================

File [changed]: DTDAttribute.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/com/wu​tka/dtd/DTDAttribute​.java?r1=1.1&r2=​1.2
Delta lines: +142 -160
-----------------------
--- DTDAttribute.java 26 Feb 2004 05:12:41 -0000 1.1
+++ DTDAttribute.java 3 Mar 2004 04:45:27 -0000 1.2
@@ -5,166 +5,148 @@
 /** Represents a DTD Attribute in an ATTLIST declaration
  *
  * @author Mark Wutka
- * @version $Revision: 1.1 $ $Date: 2004/02/26 05:12:41 $ by $Author: danson $
+ * @version $Revision: 1.2 $ $Date: 2004/03/03 04:45:27 $ by $Author: danson $
  */
 
-public class DTDAttribute implements DTDOutput
-{
-/** The name of the attribute */
+public class DTDAttribute implements DTDOutput {
+ /** The name of the attribute */
     public String name;
 
-/** The type of the attribute (either String, DTDEnumeration or
+ /** The type of the attribute (either String, DTDEnumeration or
     DTDNotationList) */
     public Object type;
 
-/** The attribute's declaration (required, fixed, implied) */
+ /** The attribute's declaration (required, fixed, implied) */
     public DTDDecl decl;
 
-/** The attribute's default value (null if not declared) */
+ /** The attribute's default value (null if not declared) */
     public String defaultValue;
 
- public DTDAttribute()
- {
- }
+ public DTDAttribute() {}
 
- public DTDAttribute(String aName)
- {
+ public DTDAttribute( String aName ) {
         name = aName;
     }
 
-/** Writes this attribute to an output stream */
- public void write(PrintWriter out)
- throws IOException
- {
- out.print(name+" ");
- if (type instanceof String)
- {
- out.print(type);
- }
- else if (type instanceof DTDEnumeration)
- {
- DTDEnumeration dtdEnum = (DTDEnumeration) type;
- dtdEnum.write(out);
- }
- else if (type instanceof DTDNotationList)
- {
- DTDNotationList dtdnl = (DTDNotationList) type;
- dtdnl.write(out);
- }
-
- if (decl != null)
- {
- decl.write(out);
- }
-
- if (defaultValue != null)
- {
- out.print(" \"");
- out.print(defaultValue);
- out.print("\"");
+ /** Writes this attribute to an output stream */
+ public void write( PrintWriter out )
+ throws IOException {
+ out.print( name + " " );
+ if ( type instanceof String ) {
+ out.print( type );
+ }
+ else if ( type instanceof DTDEnumeration ) {
+ DTDEnumeration dtdEnum = ( DTDEnumeration ) type;
+ dtdEnum.write( out );
+ }
+ else if ( type instanceof DTDNotationList ) {
+ DTDNotationList dtdnl = ( DTDNotationList ) type;
+ dtdnl.write( out );
+ }
+
+ if ( decl != null ) {
+ decl.write( out );
+ }
+
+ if ( defaultValue != null ) {
+ out.print( " \"" );
+ out.print( defaultValue );
+ out.print( "\"" );
         }
         //out.println(">"); Bug!
     }
 
- public boolean equals(Object ob)
- {
- if (ob == this) return true;
- if (!(ob instanceof DTDAttribute)) return false;
+ public boolean equals( Object ob ) {
+ if ( ob == this )
+ return true;
+ if ( !( ob instanceof DTDAttribute ) )
+ return false;
 
- DTDAttribute other = (DTDAttribute) ob;
+ DTDAttribute other = ( DTDAttribute ) ob;
 
- if (name == null)
- {
- if (other.name != null) return false;
+ if ( name == null ) {
+ if ( other.name != null )
+ return false;
         }
- else
- {
- if (!name.equals(other.name)) return false;
+ else {
+ if ( !name.equals( other.name ) )
+ return false;
         }
 
- if (type == null)
- {
- if (other.type != null) return false;
+ if ( type == null ) {
+ if ( other.type != null )
+ return false;
         }
- else
- {
- if (!type.equals(other.type)) return false;
+ else {
+ if ( !type.equals( other.type ) )
+ return false;
         }
 
- if (decl == null)
- {
- if (other.decl != null) return false;
+ if ( decl == null ) {
+ if ( other.decl != null )
+ return false;
         }
- else
- {
- if (!decl.equals(other.decl)) return false;
+ else {
+ if ( !decl.equals( other.decl ) )
+ return false;
         }
 
- if (defaultValue == null)
- {
- if (other.defaultValue != null) return false;
+ if ( defaultValue == null ) {
+ if ( other.defaultValue != null )
+ return false;
         }
- else
- {
- if (!defaultValue.equal​s(other.defaultValue​)) return false;
+ else {
+ if ( !defaultValue.equals( other.defaultValue ) )
+ return false;
         }
 
         return true;
     }
 
-/** Sets the name of the attribute */
- public void setName(String aName)
- {
+ /** Sets the name of the attribute */
+ public void setName( String aName ) {
         name = aName;
     }
 
-/** Returns the attribute name */
- public String getName()
- {
+ /** Returns the attribute name */
+ public String getName() {
         return name;
     }
 
-/** Sets the type of the attribute */
- public void setType(Object aType)
- {
- if (!(aType instanceof String) &&
- !(aType instanceof DTDEnumeration) &&
- !(aType instanceof DTDNotationList))
- {
+ /** Sets the type of the attribute */
+ public void setType( Object aType ) {
+ if ( !( aType instanceof String ) &&
+ !( aType instanceof DTDEnumeration ) &&
+ !( aType instanceof DTDNotationList ) ) {
             throw new IllegalArgumentException(
- "Must be String, DTDEnumeration or DTDNotationList");
+ "Must be String, DTDEnumeration or DTDNotationList" );
         }
 
         type = aType;
     }
 
-/** Gets the type of the attribute */
- public Object getType()
- {
+ /** Gets the type of the attribute */
+ public Object getType() {
         return type;
     }
 
-/** Sets the declaration (fixed, required, implied) */
- public void setDecl(DTDDecl aDecl)
- {
+ /** Sets the declaration (fixed, required, implied) */
+ public void setDecl( DTDDecl aDecl ) {
         decl = aDecl;
     }
 
-/** Returns the declaration */
- public DTDDecl getDecl()
- {
+ /** Returns the declaration */
+ public DTDDecl getDecl() {
         return decl;
     }
 
-/** Sets the default value */
- public void setDefaultValue(String aDefaultValue)
- {
+ /** Sets the default value */
+ public void setDefaultValue( String aDefaultValue ) {
         defaultValue = aDefaultValue;
     }
 
-/** Returns the default value */
- public String getDefaultValue()
- {
+ /** Returns the default value */
+ public String getDefaultValue() {
         return defaultValue;
     }
 }

File [changed]: DTDContainer.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/com/wu​tka/dtd/DTDContainer​.java?r1=1.1&r2=​1.2
Delta lines: +72 -81
---------------------
--- DTDContainer.java 26 Feb 2004 05:12:41 -0000 1.1
+++ DTDContainer.java 3 Mar 2004 04:45:27 -0000 1.2
@@ -7,87 +7,78 @@
  * DTDChoice or a DTDSequence)
  *
  * @author Mark Wutka
- * @version $Revision: 1.1 $ $Date: 2004/02/26 05:12:41 $ by $Author: danson $
+ * @version $Revision: 1.2 $ $Date: 2004/03/03 04:45:27 $ by $Author: danson $
  */
-public abstract class DTDContainer extends DTDItem
-{
+public abstract class DTDContainer extends DTDItem {
     protected Vector items;
 
-/** Creates a new DTDContainer */
- public DTDContainer()
- {
+ /** Creates a new DTDContainer */
+ public DTDContainer() {
         items = new Vector();
     }
 
-/** Adds an element to the container */
- public void add(DTDItem item)
- {
- items.addElement(item);
+ /** Adds an element to the container */
+ public void add( DTDItem item ) {
+ items.addElement( item );
     }
 
-/** Removes an element from the container */
- public void remove(DTDItem item)
- {
- items.removeElement(item);
+ /** Removes an element from the container */
+ public void remove( DTDItem item ) {
+ items.removeElement( item );
     }
 
-/** Returns the elements as a vector (not a clone!) */
- public Vector getItemsVec()
- {
+ /** Returns the elements as a vector (not a clone!) */
+ public Vector getItemsVec() {
         return items;
     }
 
-/** Returns the elements as an array of items */
- public DTDItem[] getItems()
- {
- DTDItem[] retval = new DTDItem[items.size()];
- items.copyInto(retval);
+ /** Returns the elements as an array of items */
+ public DTDItem[] getItems() {
+ DTDItem[] retval = new DTDItem[ items.size() ];
+ items.copyInto( retval );
         return retval;
     }
 
- public boolean equals(Object ob)
- {
- if (ob == this) return true;
- if (!(ob instanceof DTDContainer)) return false;
+ public boolean equals( Object ob ) {
+ if ( ob == this )
+ return true;
+ if ( !( ob instanceof DTDContainer ) )
+ return false;
 
- if (!super.equals(ob)) return false;
+ if ( !super.equals( ob ) )
+ return false;
 
- DTDContainer other = (DTDContainer) ob;
+ DTDContainer other = ( DTDContainer ) ob;
 
- return items.equals(other.items);
+ return items.equals( other.items );
     }
 
-/** Stores items in the container */
- public void setItem(DTDItem[] newItems)
- {
- items = new Vector(newItems.length);
- for (int i=0; i < newItems.length; i++)
- {
- items.addElement(newItems[i]);
+ /** Stores items in the container */
+ public void setItem( DTDItem[] newItems ) {
+ items = new Vector( newItems.length );
+ for ( int i = 0; i < newItems.length; i++ ) {
+ items.addElement( newItems[ i ] );
         }
     }
 
-/** Retrieves the items in the container */
- public DTDItem[] getItem()
- {
- DTDItem[] retval = new DTDItem[items.size()];
- items.copyInto(retval);
+ /** Retrieves the items in the container */
+ public DTDItem[] getItem() {
+ DTDItem[] retval = new DTDItem[ items.size() ];
+ items.copyInto( retval );
 
         return retval;
     }
 
-/** Stores an item in the container */
- public void setItem(DTDItem anItem, int i)
- {
- items.setElementAt(anItem, i);
+ /** Stores an item in the container */
+ public void setItem( DTDItem anItem, int i ) {
+ items.setElementAt( anItem, i );
     }
 
-/** Retrieves an item from the container */
- public DTDItem getItem(int i)
- {
- return (DTDItem) items.elementAt(i);
+ /** Retrieves an item from the container */
+ public DTDItem getItem( int i ) {
+ return ( DTDItem ) items.elementAt( i );
     }
 
- public abstract void write(PrintWriter out)
+ public abstract void write( PrintWriter out )
         throws IOException;
 }

File [changed]: DTDDecl.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/com/wu​tka/dtd/DTDDecl.java​?r1=1.1&r2=1.2
Delta lines: +33 -39
---------------------
--- DTDDecl.java 26 Feb 2004 05:12:41 -0000 1.1
+++ DTDDecl.java 3 Mar 2004 04:45:27 -0000 1.2
@@ -5,48 +5,42 @@
 /** Represents the possible values for an attribute declaration
  *
  * @author Mark Wutka
- * @version $Revision: 1.1 $ $Date: 2004/02/26 05:12:41 $ by $Author: danson $
+ * @version $Revision: 1.2 $ $Date: 2004/03/03 04:45:27 $ by $Author: danson $
  */
-public class DTDDecl implements DTDOutput
-{
- public static final DTDDecl FIXED = new DTDDecl(0, "FIXED");
- public static final DTDDecl REQUIRED = new DTDDecl(1, "REQUIRED");
- public static final DTDDecl IMPLIED = new DTDDecl(2, "IMPLIED");
- public static final DTDDecl VALUE = new DTDDecl(3, "VALUE");
+public class DTDDecl implements DTDOutput {
+ public static final DTDDecl FIXED = new DTDDecl( 0, "FIXED" );
+ public static final DTDDecl REQUIRED = new DTDDecl( 1, "REQUIRED" );
+ public static final DTDDecl IMPLIED = new DTDDecl( 2, "IMPLIED" );
+ public static final DTDDecl VALUE = new DTDDecl( 3, "VALUE" );
 
     public int type;
     public String name;
 
- public DTDDecl(int aType, String aName)
- {
+ public DTDDecl( int aType, String aName ) {
             type = aType;
             name = aName;
     }
 
- public boolean equals(Object ob)
- {
- if (ob == this) return true;
- if (!(ob instanceof DTDDecl)) return false;
-
- DTDDecl other = (DTDDecl) ob;
- if (other.type == type) return true;
+ public boolean equals( Object ob ) {
+ if ( ob == this )
+ return true;
+ if ( !( ob instanceof DTDDecl ) )
         return false;
+
+ DTDDecl other = ( DTDDecl ) ob;
+ return other.type == type;
     }
 
- public void write(PrintWriter out)
- throws IOException
- {
- if (this == FIXED)
- {
- out.print(" #FIXED");
- }
- else if (this == REQUIRED)
- {
- out.print(" #REQUIRED");
- }
- else if (this == IMPLIED)
- {
- out.print(" #IMPLIED");
+ public void write( PrintWriter out )
+ throws IOException {
+ if ( this == FIXED ) {
+ out.print( " #FIXED" );
+ }
+ else if ( this == REQUIRED ) {
+ out.print( " #REQUIRED" );
+ }
+ else if ( this == IMPLIED ) {
+ out.print( " #IMPLIED" );
         }
         // Don't do anything for value since there is no associated DTD keyword
     }

File [changed]: DTDItem.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/com/wu​tka/dtd/DTDItem.java​?r1=1.1&r2=1.2
Delta lines: +46 -50
---------------------
--- DTDItem.java 26 Feb 2004 05:12:41 -0000 1.1
+++ DTDItem.java 3 Mar 2004 04:45:27 -0000 1.2
@@ -5,55 +5,51 @@
 /** Represents any item in the DTD
  *
  * @author Mark Wutka
- * @version $Revision: 1.1 $ $Date: 2004/02/26 05:12:41 $ by $Author: danson $
+ * @version $Revision: 1.2 $ $Date: 2004/03/03 04:45:27 $ by $Author: danson $
  */
-public abstract class DTDItem implements DTDOutput
-{
-/** Indicates how often the item may occur */
+public abstract class DTDItem implements DTDOutput {
+ /** Indicates how often the item may occur */
     public DTDCardinal cardinal;
 
- public DTDItem()
- {
+ public DTDItem() {
         cardinal = DTDCardinal.NONE;
     }
 
- public DTDItem(DTDCardinal aCardinal)
- {
+ public DTDItem( DTDCardinal aCardinal ) {
         cardinal = aCardinal;
     }
 
-/** Writes out a declaration for this item */
- public abstract void write(PrintWriter out)
+ /** Writes out a declaration for this item */
+ public abstract void write( PrintWriter out )
         throws IOException;
 
- public boolean equals(Object ob)
- {
- if (ob == this) return true;
- if (!(ob instanceof DTDItem)) return false;
-
- DTDItem other = (DTDItem) ob;
-
- if (cardinal == null)
- {
- if (other.cardinal != null) return false;
- }
- else
- {
- if (!cardinal.equals(ot​her.cardinal)) return false;
+ public boolean equals( Object ob ) {
+ if ( ob == this )
+ return true;
+ if ( !( ob instanceof DTDItem ) )
+ return false;
+
+ DTDItem other = ( DTDItem ) ob;
+
+ if ( cardinal == null ) {
+ if ( other.cardinal != null )
+ return false;
+ }
+ else {
+ if ( !cardinal.equals( other.cardinal ) )
+ return false;
         }
 
         return true;
     }
 
-/** Sets the cardinality of the item */
- public void setCardinal(DTDCardinal aCardinal)
- {
+ /** Sets the cardinality of the item */
+ public void setCardinal( DTDCardinal aCardinal ) {
         cardinal = aCardinal;
     }
 
-/** Retrieves the cardinality of the item */
- public DTDCardinal getCardinal()
- {
+ /** Retrieves the cardinality of the item */
+ public DTDCardinal getCardinal() {
         return cardinal;
     }
 }

Directory: /antelope/src/ise/an​telope/common/builde​r/
====================​====================​=============

File [changed]: AntTransferable.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/builde​r/AntTransferable.ja​va?r1=1.1&r2=1.2​
Delta lines: +26 -13
---------------------
--- AntTransferable.java 2 Mar 2004 06:38:41 -0000 1.1
+++ AntTransferable.java 3 Mar 2004 04:45:27 -0000 1.2
@@ -5,21 +5,29 @@
 /**
  * Package Ant objects for movement.
  */
-public class AntTransferable extends StringSelection {
+public class AntTransferable implements Transferable {
 
    private static DataFlavor[] flavors = null;
- private String type = null;
+ private ElementPanel data = null;
 
    /**
- * @param type the type of Ant element being transfered, e.g., target, task,
- * type, etc.
+ * @param an ElementPanel to drag
     */
- public AntTransferable( String type ) {
- super( type );
- this.type = type;
+ public AntTransferable( ElementPanel data ) {
+ this.data = data;
+ init();
+ }
+
+
+ /**
+ * Set up the supported flavors: DataFlavor.stringFlavor for a raw string containing
+ * an Ant element name (e.g. task, target, etc), or an ElementFlavor containing
+ * an ElementPanel.
+ */
+ private void init() {
       try {
          flavors = new DataFlavor[ 1 ];
- flavors[ 0 ] = new ElementFlavor(type);
+ flavors[ 0 ] = new ElementFlavor( );
       }
       catch ( Exception e ) {
          e.printStackTrace();
@@ -27,12 +35,17 @@
    }
 
    /**
- * @param df ignored
- * @return regardless of the requested DataFlavor, the returned object is
- * always a string containing the type passed to the constructor.
+ * @param df the flavor type desired for the data. Acceptable values are
+ * DataFlavor.stringFlavor or ElementFlavor.
+ * @return if df is DataFlavor.stringFlavor, returns a raw string containing
+ * an Ant element name, if ElementFlavor, returns an ElementPanel.
     */
    public Object getTransferData( DataFlavor df ) {
- return type;
+ if ( df == null )
+ return null;
+ if ( df instanceof ElementFlavor )
+ return data;
+ return null;
    }
 
    /**
@@ -48,7 +61,7 @@
     */
    public boolean isDataFlavorSupported( DataFlavor df ) {
       if ( df == null )
- throw new IllegalArgumentException( "flavor cannot be null" );
+ return false;
       for ( int i = 0; i < flavors.length; i++ ) {
          if ( df.equals( flavors[ i ] ) ) {
             return true;

File [changed]: AttributeViewer.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/builde​r/AttributeViewer.ja​va?r1=1.1&r2=1.2​
Delta lines: +61 -85
---------------------
--- AttributeViewer.java 2 Mar 2004 06:38:41 -0000 1.1
+++ AttributeViewer.java 3 Mar 2004 04:45:27 -0000 1.2
@@ -32,73 +32,50 @@
    }
    private void doPopup( MouseEvent me ) {
       if ( me.isPopupTrigger() ) {
- // from ElementTransferHandler:
- // 'data' is one of two things -- 1) it is a single word, which means
- // it is a raw element name, or 2) it is already formatted as html.
- // Determine the second case by checking for <html> at the start of the
- // string, if not, assume the first case. The html has the element name
- // surrounded by <b> tags. Element attributes are separated by <br>,
- // with attribute name and value enclosed individually in <span> tags.
- // Enumerations or lists have the individual value items wrapped in a
- // <ul> with individual items separated by <li>. There are no line-
- // enders (\n, \r).
- //
- // Everything handled by this handler is already in html format.
 
- // get the selected item from the JList
+ // get the selected item from the JList, it should be an ElementPanel
          Object o = parent.getSelectedValue();
          if ( o == null )
             return ;
- String data = o.toString();
- if ( data.length() == 0 )
- return ;
- if ( !data.startsWith( "<html>" ) )
+ if ( !( o instanceof ElementPanel ) )
             return ;
+ final ElementPanel ep = ( ElementPanel ) o;
 
- // get ready to layout
          final JPanel top = new JPanel( new KappaLayout() );
          KappaLayout.Constraints c = KappaLayout.createConstraint();
          c.p = 3;
          c.a = KappaLayout.W;
 
- // get the name of the element
- int start = "<html><b​>".length();
- int end = data.indexOf( "</b>" );
- element_name = data.substring( start, end );
- top.add( new JLabel( "<html><b>" + element_name + "</b>" ), c );
-
- // parse the rest of the html
- start = end + "</b>".length();
- data = data.substring( start );
-
- Pattern p = Pattern.compile( "<br>" );
- String[] attrs = p.split( data );
-
+ top.add( new JLabel( "<html><b>" + ep.getName() + "</b></html>" ), c );
          c.a = KappaLayout.E;
          ++ c.y;
 
- Pattern div_pattern = Pattern.compile( "</span>" );
- for ( int i = 0; i < attrs.length; i++ ) {
- if (attrs[i].length() == 0)
- continue;
- String[] pair = div_pattern.split( attrs[ i ] );
- if (pair.length != 2)
- break;
-
- String name = pair[ 0 ];
- if (!name.startsWith("​<span>"))
- continue;
- String value = pair[ 1 ];
-
- name = name.substring("<​span>".length());​
- value = value.substring("​<span>".length())​;
-
- if ( name.equals( "taskname" ) )
+ final Map attributes = ep.getAttributes();
+ Iterator it = attributes.keySet().iterator();
+ while ( it.hasNext() ) {
+ String name = it.next().toString();
+ if ( name.equals( "taskname" ) && ep.isTask() )
                continue;
 
- JLabel label = new JLabel( name + ":" );
- JTextField comp = new JTextField( 25 );
- comp.setText( value );
+ DTDAttribute attribute = ( DTDAttribute ) attributes.get( name );
+ DTDDecl decl = attribute.getDecl();
+ boolean required = decl.equals( DTDDecl.REQUIRED );
+ Object type = attribute.getType();
+
+ JLabel label = new JLabel( "<html>" + ( required ? "<font color=red>*</font>" : "" ) + name + ":" );
+
+ JComponent comp = null;
+ if ( type instanceof DTDEnumeration || type instanceof DTDNotationList ) {
+ String[] items = ( ( DTDEnumeration ) type ).getItem();
+ comp = new JComboBox( items );
+ ( ( JComboBox ) comp ).setEditable( false );
+ }
+ else {
+ // assume String type
+ comp = new JTextField( 25 );
+ ( ( JTextField ) comp ).setText( attribute.getDefaultValue() );
+ }
+ comp.setName( name );
 
             top.add( label, c );
             c.x = 1;
@@ -107,45 +84,44 @@
             ++c.y;
          }
          
+ // button panel
          KappaLayout kl = new KappaLayout();
- JPanel btn_panel = new JPanel(kl);
- JButton ok_btn = new JButton("OK");
- JButton cancel_btn = new JButton("Cancel");
- btn_panel.add(ok_btn, "0, 0, 1, 1, 0, wh, 3");
- btn_panel.add(cancel_btn, "1, 0, 1, 1, 0, wh, 3");
- kl.makeColumnsSameWidth(0, 1);
+ JPanel btn_panel = new JPanel( kl );
+ JButton ok_btn = new JButton( "OK" );
+ JButton cancel_btn = new JButton( "Cancel" );
+ btn_panel.add( ok_btn, "0, 0, 1, 1, 0, wh, 3" );
+ btn_panel.add( cancel_btn, "1, 0, 1, 1, 0, wh, 3" );
+ kl.makeColumnsSameWidth( 0, 1 );
          c.x = 0;
          ++c.y;
          c.w = 2;
          c.p = 6;
- top.add(btn_panel, c);
+ top.add( btn_panel, c );
+
+ ok_btn.addActionListener( new ActionListener() {
+ public void actionPerformed( ActionEvent ae ) {
+ pm.setVisible( false );
          
- ok_btn.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent ae) {
- pm.setVisible(false);
- StringBuffer sb = new StringBuffer();
                int cnt = top.getComponentCount();
- JLabel label = (JLabel)top.getComponent(0);
- sb.append(label.getT​ext()).append("<b​r>");
+ for ( int i = 0; i < cnt; i++ ) {
+ Component c = top.getComponent( i );
+ if ( c instanceof JTextField ) {
+ JTextField tf = ( JTextField ) c;
+ DTDAttribute attr = ( DTDAttribute ) attributes.get( tf.getName() );
+ attr.setDefaultValue( tf.getText() );
+ }
+ }
+ ep.setAttributes( attributes );
+ }
+ }
+ );
                
- JTextField tf;
- for (int i = 1; i < cnt - 2; i += 2) {
- label = (JLabel)top.getComponent(i);
- tf = (JTextField)top.getComponent(i + 1);
- String label_text = label.getText();
- sb.append("<span​>").append(label_t​ext.substring(0, label_text.length() - 1)).append("</span>");
- sb.append("<span​>").append(tf.getT​ext()).append("</​span>").append("​<br>");
- }
- sb.append("</html>");
- ((DefaultListModel)p​arent.getModel()).se​t(parent.getSelected​Index(), sb.toString());
- }
- });
-
- cancel_btn.addAction​Listener(new ActionListener(){
- public void actionPerformed(ActionEvent ae) {
- pm.setVisible(false);
+ cancel_btn.addActionListener( new ActionListener() {
+ public void actionPerformed( ActionEvent ae ) {
+ pm.setVisible( false );
+ }
             }
- });
+ );
 
          pm = new JPopupMenu();
          pm.add( new JScrollPane( top ) );

File [changed]: ElementFlavor.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/builde​r/ElementFlavor.java​?r1=1.1&r2=1.2
Delta lines: +0 -10
--------------------
--- ElementFlavor.java 2 Mar 2004 06:38:41 -0000 1.1
+++ ElementFlavor.java 3 Mar 2004 04:45:27 -0000 1.2
@@ -4,19 +4,9 @@
 
 public class ElementFlavor extends DataFlavor {
    
- private String type = null;
    
    public ElementFlavor() {
- this("");
- }
-
- public ElementFlavor(String type) {
       super(ise.antelope.c​ommon.builder.Elemen​tPanel.class, "ElementPanel");
- this.type = type;
- }
-
- public String getType() {
- return type;
    }
    
 }

File [changed]: ElementPanel.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/builde​r/ElementPanel.java?​r1=1.1&r2=1.2
Delta lines: +86 -8
--------------------
--- ElementPanel.java 2 Mar 2004 06:38:41 -0000 1.1
+++ ElementPanel.java 3 Mar 2004 04:45:27 -0000 1.2
@@ -2,28 +2,106 @@
 
 import java.awt.*;
 import java.awt.event.*;
+import java.util.*;
 import javax.swing.*;
+import javax.swing.tree.TreePath;
 import ise.library.*;
+import com.wutka.dtd.*;
+
 
 public class ElementPanel extends JPanel implements java.io.Serializable {
 
    private JList list = null;
+ private TreePath tree_path = null;
+ private String element_name = null;
+ private String xml = null;
+ private boolean isTask = false;
+ private DTDElement element = null;
+
+ private TreeMap attributes = null;
+
+ public ElementPanel( TreePath tp ) {
+ tree_path = tp;
+ element_name = tree_path.getLastPat​hComponent().toStrin​g();
+ isTask = tp.getPathCount() == 3;
+
+ element = ( DTDElement ) DNDConstants.ANT_DTD​.elements.get( element_name );
+ if ( element != null ) {
+ attributes = new TreeMap( element.attributes );
+ }
+
 
- public ElementPanel( String type ) {
       setLayout( new BorderLayout() );
       setBorder( new DropShadowBorder() );
       setTransferHandler( new ElementTransferHandler() );
- add( new JLabel( type ), BorderLayout.NORTH );
+ add( new JLabel( element_name ), BorderLayout.NORTH );
       list = new JList( new DefaultListModel() );
       add( list, BorderLayout.CENTER );
- list.setTransferHandler(new ElementTransferHandler());
- list.setDragEnabled(true);
- list.addMouseListener(new AttributeViewer(list));
+ list.setTransferHandler( new ElementTransferHandler() );
+ list.setDragEnabled( true );
+ list.addMouseListener( new AttributeViewer( list ) );
+ }
+
+ public String getName() {
+ return element_name;
+ }
+
+ public boolean isTask() {
+ return isTask;
+ }
+
+ public TreePath getTreePath() {
+ return tree_path;
+ }
+
+ /**
+ * @return a Map containing the DTD attributes for this element. The map keys
+ * are the names of the attributes, the values are DTDAttributes.
+ */
+ public Map getAttributes() {
+ return attributes;
+ }
+
+ public void setAttributes(Map attrs) {
+ attributes = attrs == null ? null : new TreeMap(attrs);
+ }
+
+ public void setXML( String xml ) {}
+
+ public String toString() {
+ if ( attributes == null )
+ return element_name;
+
+ StringBuffer sb = new StringBuffer();
+ sb.append( "<html><b>" + element_name + "</b><br>" );
+ Iterator it = attributes.keySet().iterator();
+ while ( it.hasNext() ) {
+ String name = it.next().toString();
+ if (name.equals("taskname") && isTask())
+ continue;
+ DTDAttribute attribute = ( DTDAttribute ) attributes.get( name );
+ DTDDecl decl = attribute.getDecl();
+ boolean required = decl.equals( DTDDecl.REQUIRED );
+ sb.append( "<span>&nb​sp;&nbsp;" );
+ if ( required )
+ sb.append( "<font color=red>*</font>" );
+ String value = attribute.getDefaultValue();
+ sb.append( name ).append( ":&nbsp&nbsp​;</span><sp​an>").append(valu​e == null ? "" : value).append("</​span><br>" );
+ Object type = attribute.getType();
+ if ( type instanceof DTDEnumeration || type instanceof DTDNotationList ) {
+ String[] items = ( ( DTDEnumeration ) type ).getItem();
+ sb.append( "<span><ul>" );
+ for ( int j = 0; j < items.length; j++ )
+ sb.append( "<li>" ).append( items[ j ].toString() );
+ sb.append( "</ul></span>" );
+ }
+ }
+ sb.append( "<html>" );
+ return sb.toString();
    }
 
- Dimension my_size = new Dimension( 200, 100 );
- public Dimension getPreferredSize() {
- return my_size;
+ public String toXML() {
+ return toString();
    }
 
    protected JList getList() {

File [changed]: ElementTransferHandler.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/builde​r/ElementTransferHan​dler.java?r1=1.1​&r2=1.2
Delta lines: +34 -70
---------------------
--- ElementTransferHandler.java 2 Mar 2004 06:38:41 -0000 1.1
+++ ElementTransferHandler.java 3 Mar 2004 04:45:27 -0000 1.2
@@ -1,6 +1,7 @@
 package ise.antelope.common.builder;
 
 import javax.swing.*;
+import javax.swing.tree.TreePath;
 import java.awt.datatransfer.*;
 import com.wutka.dtd.*;
 import java.util.*;
@@ -10,32 +11,26 @@
    private int addIndex = -1; //Location where items were added
    private int addCount = 0; //Number of items added.
 
+ /**
+ * @param c the component containing the data to transfer. If the component is
+ * an ElementPanel, the panel is the data, if the component is a JList, get
+ * the selected item, which should be an ElementPanel, and use it as the data.
+ */
    protected Transferable createTransferable( JComponent c ) {
       JList list = null;
       if ( c instanceof ElementPanel ) {
          ElementPanel ep = ( ElementPanel ) c;
- list = ep.getList();
+ return new AntTransferable( ep );
       }
       else if ( c instanceof JList ) {
          list = ( JList ) c;
+ Object o = list.getSelectedValue();
+ if ( o instanceof ElementPanel ) {
+ ElementPanel ep = ( ElementPanel ) list.getSelectedValue();
+ return new AntTransferable( ep );
       }
- else {
- return null;
       }
- indices = list.getSelectedIndices();
- Object[] values = list.getSelectedValues();
-
- StringBuffer buff = new StringBuffer();
-
- for ( int i = 0; i < values.length; i++ ) {
- Object val = values[ i ];
- buff.append( val == null ? "" : val.toString() );
- if ( i != values.length - 1 ) {
- buff.append( "\n" );
- }
- }
- System.out.println( buff.toString() );
- return new AntTransferable( buff.toString() );
+ return null;
    }
 
    /**
@@ -47,6 +42,7 @@
    }
 
    /**
+ * @param c the component to receive the data
     * @param df an array of data flavors
     * @return true if any of the flavors is an ElementFlavor
     */
@@ -54,72 +50,39 @@
       for ( int i = 0; i < df.length; i++ ) {
          if ( df[ i ] instanceof ElementFlavor )
             return true;
+ if (df[i] instanceof TreePathFlavor)
+ return true;
       }
       return false;
    }
 
    /**
- * @param c the component to receive the data
+ * @param c the component to receive the data, must be an ElementPanel or a JList
     * @param t the data to import
     * @return true if the data was inserted into the component
     */
    public boolean importData( JComponent c, Transferable t ) {
       try {
- // 'data' is one of two things -- 1) it is a single word, which means
- // it is a raw element name, or 2) it is already formatted as html.
- // Determine the second case by checking for <html> at the start of the
- // string, if not, assume the first case. The html has the element name
- // surrounded by <b> tags. Element attributes are separated by <br>,
- // with attribute name and value enclosed individually in <span> tags.
- // Enumerations or lists have the individual value items wrapped in a
- // <ul> with individual items separated by <li>. There are no line-
- // enders (\n, \r).
- String data = (String)t.getTransferData( new ElementFlavor() );
- if (data != null && data.startsWith("​<html>")) {
- int start = "<html><b​>".length();
- int end = data.indexOf("</b>");
- System.out.println(start + " : " + end);
- data = data.substring(start, end);
- }
- DTDElement el = ( DTDElement ) DNDConstants.ANT_DTD​.elements.get( data.toString() );
-
- StringBuffer sb = new StringBuffer();
- if ( el != null ) {
- Hashtable attrs = el.attributes;
- Object[] attr_names = attrs.keySet().toArray();
- Arrays.sort( attr_names );
- String item_name = data.toString();
-
- sb.append( "<html><b>" + item_name + "</b><br>" );
- for ( int i = 0; i < attr_names.length; i++ ) {
- String name = attr_names[ i ].toString();
- if ( name.equals( "taskname" ) )
- continue;
- DTDAttribute attribute = ( DTDAttribute ) attrs.get( name );
- Object type = attribute.getType();
- if ( type instanceof DTDEnumeration || type instanceof DTDNotationList ) {
- String[] items = ( ( DTDEnumeration ) type ).getItem();
- sb.append( "<span><ul>" );
- for ( int j = 0; j < items.length; j++ )
- sb.append( "<li>" ).append( items[ j ].toString() );
- sb.append( "</ul></span>" );
- }
+ // get the data, it will either be a string or an ElementPanel
+ ElementPanel ep = null;
+ Object data = t.getTransferData( new ElementFlavor() );
+ if(data != null)
+ ep = (ElementPanel)data;
                else {
- // assume String type
- sb.append( "<span>" ).append( name ).append( "</span><sp​an></span>​<br>" );
- }
+ data = t.getTransferData(new TreePathFlavor());
+ if (data != null){
+ TreePath tp = (TreePath)data;
+ ep = new ElementPanel(tp);
             }
- sb.append( "<html>" );
+ else
+ return false;
          }
- System.out.println( "ElementTransferhandler: " + sb.toString() );
- if ( data != null ) {
- /// need to add a child component to c based on the element type.
- /// the element type is the data
- ///c.add( ( JComponent ) data );
+
+ if ( ep != null ) {
             JList list = null;
             if ( c instanceof ElementPanel ) {
- ElementPanel ep = ( ElementPanel ) c;
- list = ep.getList();
+ ElementPanel parent = ( ElementPanel ) c;
+ list = parent.getList();
             }
             else if ( c instanceof JList ) {
                list = ( JList ) c;
@@ -127,6 +90,7 @@
             else {
                return false;
             }
+
             DefaultListModel listModel = ( DefaultListModel ) list.getModel();
             int index = list.getSelectedIndex();
 
@@ -152,7 +116,7 @@
                }
             }
             addIndex = index;
- listModel.add( index++, sb.toString() );
+ listModel.add( index++, ep );
 
             return true;
          }

File [changed]: ProjectBuilder.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/builde​r/ProjectBuilder.jav​a?r1=1.1&r2=1.2
Delta lines: +2 -2
-------------------
--- ProjectBuilder.java 2 Mar 2004 06:38:41 -0000 1.1
+++ ProjectBuilder.java 3 Mar 2004 04:45:27 -0000 1.2
@@ -104,11 +104,11 @@
          //project_tree.addMo​useListener( new AttributeViewer( project_tree ) );
          project_tree.setDragEnabled( true );
 
- ElementPanel project_panel = new ElementPanel(DNDCons​tants.PROJECT);
+ ElementPanel project_panel = new ElementPanel(project​_tree.getPathForRow(​0));
          JSplitPane splitpane = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT,
                true,
                new JScrollPane( project_tree ),
- project_panel );
+ new JScrollPane( project_panel ) );
          setLayout( new LambdaLayout() );
          add( splitpane, "0, 0, 1, 1, 0, wh, 3" );
          project_tree.setDrag​Enabled(true);

File [changed]: TreeTransferHandler.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/builde​r/TreeTransferHandle​r.java?r1=1.1&r2​=1.2
Delta lines: +11 -27
---------------------
--- TreeTransferHandler.java 2 Mar 2004 06:38:41 -0000 1.1
+++ TreeTransferHandler.java 3 Mar 2004 04:45:27 -0000 1.2
@@ -5,31 +5,23 @@
 import java.awt.datatransfer.*;
 import javax.swing.tree.*;
 
-/**
- * Modeled after code from Sun's java tutorial.
- */
+
 public class TreeTransferHandler extends TransferHandler {
 
    protected Transferable createTransferable( JComponent c ) {
+ try {
       TreePath tp = ( ( JTree ) c ).getSelectionPath();
- Object[] steps = tp.getPath();
- if ( steps.length == 0 || steps.length == 1 )
+ if ( tp == null )
          return null;
- if ( !steps[ 0 ].toString().equals( DNDConstants.PROJECT ) )
+ String leaf = tp.getLastPathCompon​ent().toString();
+ if (leaf.equals(DNDConstants.TASK) || leaf.equals(DNDConstants.TYPE))
          return null;
-
-
- if ( steps[ 1 ].toString().equals( DNDConstants.TARGET ) ) {
- return new AntTransferable( steps[ 1 ].toString() );
- }
- if ( steps.length > 2 ) {
- if ( steps[ 1 ].toString().equals( DNDConstants.TASK ) ||
- steps[ 1 ].toString().equals( DNDConstants.TYPE ) ) {
- return new AntTransferable( steps[ steps.length - 1 ].toString() );
- }
+ return new TreeTransferable( tp );
       }
+ catch ( ClassCastException cce ) {
       return null;
    }
+ }
 
    public int getSourceActions( JComponent c ) {
       return COPY_OR_MOVE;
@@ -37,13 +29,5 @@
 
    public boolean canImport( JComponent c, DataFlavor[] df ) {
       return false;
- }
-
- protected String exportString( JComponent c ) {
- JTree tree = ( JTree ) c;
- TreePath tp = tree.getSelectionPath();
- if ( tp == null )
- return null;
- return "node: " + tp.toString();
    }
 }




--------------------​--------------------​--------------------​---------
To unsubscribe, e-mail: cvs-unsubscribe@ante​lope.tigris.org
For additional commands, e-mail: cvs-help at antelope dot tigris dot org

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /antelope/src/com/wutka/dtd/, /antelope/src/ise/antelope/common/builder/ danson Dale Anson 2004-03-02 20:45:29 PST
Messages per page: