View Javadoc

1   
2   package org.xrn.gui;
3   
4   import java.awt.Color;
5   import java.awt.Font;
6   import java.awt.event.ActionEvent;
7   import java.awt.event.ActionListener;
8   import java.util.List;
9   import java.util.Vector;
10  
11  import javax.swing.JButton;
12  import javax.swing.JComponent;
13  import javax.swing.JPanel;
14  import javax.swing.JScrollPane;
15  import javax.swing.JTable;
16  import javax.swing.ListSelectionModel;
17  import javax.swing.border.TitledBorder;
18  import javax.swing.event.ListSelectionEvent;
19  import javax.swing.event.ListSelectionListener;
20  
21  import org.xrn.xsd2java.Requirements;
22  import org.xrn.xsd2java.impl.ComponentImpl;
23  import org.xrn.xsd2java.impl.RequirementsImpl;
24  
25  /***
26   * 
27   * The dependencies panel - dependencies (a list of components)
28   * @author Carsten Maneg
29   * Date Nov 13, 2004
30   * Time 11:34:26 PM
31   */
32  public class RequirementsPanel extends JPanel implements ActionListener, ListSelectionListener{
33      private Font schriftTyp;
34      
35      private JPanel panelOwner;
36      private OneReleaseComponentPanel componentPanel = null;
37      private SummaryPanel summaryPanel = null;
38      private JTable table = null;
39      private MyTableModel tableModel = null;
40  	private JScrollPane scrollPane = null;
41      private JButton removeButton = new JButton( "Remove" );
42      private JButton addButton = new JButton( "Add" );
43  	
44  	private Requirements requirements = new RequirementsImpl();
45  	private List componentList = null;
46                      
47  	/***
48  	 * Constructor
49  	 * @param owner
50  	 */
51      public RequirementsPanel( JPanel owner ){
52    	
53          setBorder( new TitledBorder( "" ) );
54          schriftTyp =  new Font( "newFont", Font.BOLD, 14 );
55          setFont( schriftTyp );
56          setLayout( null );
57          
58          panelOwner = owner;
59          
60          componentPanel = new OneReleaseComponentPanel( this );
61          dlgObjHinzufuegen( componentPanel, 200, 25, 300, 150 );
62          
63          summaryPanel = new SummaryPanel( this, "normal" );
64          dlgObjHinzufuegen( summaryPanel, 200, 185, 300, 160 );
65          
66      	createTable();	
67      	dlgObjHinzufuegen( scrollPane, 25, 25, 165, 150 );
68      	
69      	addButton.addActionListener( this );
70          dlgObjHinzufuegen( addButton, 25, 185, 80, 20 );
71          removeButton.addActionListener( this );
72          dlgObjHinzufuegen( removeButton, 110, 185, 80, 20 );    	
73      }
74  
75      /***
76       * 
77       * @param c - The component to add
78       * @param x0
79       * @param y0
80       * @param width
81       * @param height
82       */
83      public void dlgObjHinzufuegen( JComponent c, int x0, int y0, int breite, int hoehe ){
84          c.setBounds( x0, y0, breite, hoehe );
85          c.setForeground( Color.black );
86          add(c);
87      }
88      
89      /***
90       * Creates the component table to show the components of the release notes
91       *
92       */
93      public void createTable( ){
94      	
95      	Vector columnName = new Vector( 1 );
96      	columnName.addElement( "Component" );
97  
98      	tableModel = new MyTableModel( columnName, 0 );
99      	table = new JTable( tableModel );
100     	
101     	//tradeDT.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
102     	
103     	table.getColumnModel().getColumn( 0 ).setPreferredWidth( 100 );
104     	table.getSelectionModel().addListSelectionListener( this );
105     	table.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
106     	scrollPane = new JScrollPane( table );
107     }
108     
109     /***
110      * Delete the table input
111      *
112      */
113     public void resetTable( ){
114 //        int i = 0;
115         for ( int i = tableModel.getRowCount() - 1; i >= 0 ; i-- )
116     		tableModel.removeRow( i );        
117     }
118     
119     /***
120      * Write the releases list to the table
121      *
122      */
123     private void writeTable(){
124     	int i = 0;
125     	Vector sv = new Vector();
126     	ComponentImpl component = null;
127     	
128     	resetTable();
129     	for( i=0; i < requirements.getComponent().size(); i++ ){
130     		component = (ComponentImpl)requirements.getComponent().get( i );
131     		sv = new Vector();
132     		sv.addElement( component.getID() );
133     		tableModel.addRow( sv );
134     	}
135     	if( requirements.getComponent().size() > 0 )
136     	    table.setRowSelectionInterval( 0, 0 );
137     }
138     
139     /***
140      * 
141      */
142     public void actionPerformed( ActionEvent e ){
143         if ( e.getSource() == addButton ){
144             requirements.getComponent().add( componentPanel.getFeatureComponent() );
145             writeTable();
146         }
147         if ( e.getSource() == removeButton ){
148             if( table.getSelectedRow() > -1 ){
149                 requirements.getComponent().remove( table.getSelectedRow() );
150                 writeTable();
151                 resetFields();
152             }
153             else{
154                 MessageWindow.mitteilung( "No component selected !" );
155             }            
156         }  	
157     }
158     
159     /***
160      * Handle the table selection events
161      */
162     public void valueChanged( ListSelectionEvent e ){
163         if( requirements.getComponent().size() > 0 && table.getSelectedRow() > -1 ){
164             ComponentImpl component = (ComponentImpl)requirements.getComponent().get( table.getSelectedRow() );
165         	componentPanel.setFeatureComponent( component );
166         }
167     }
168 
169     /***
170      * Reset the input fields.
171      *
172      */
173     public void resetFields( ){
174         componentPanel.resetFields();
175         summaryPanel.resetFields();
176     }
177     
178     /***
179      * 
180      * @return
181      */
182     public Requirements getRequirements(){
183 //        requirements.getComponent().add();
184         requirements.setSummary( summaryPanel.getSummary() );
185         return this.requirements;
186     }
187     
188     /***
189      * 
190      * @param dependencies
191      */
192     public void setRequirements( Requirements requirements ){
193         this.requirements = requirements;
194         if( requirements != null ){
195             componentList = requirements.getComponent();
196             writeTable();            
197             summaryPanel.setSummary( requirements.getSummary() );
198         }            
199     }
200 
201 }