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.Vector;
9   
10  import javax.swing.JButton;
11  import javax.swing.JComponent;
12  import javax.swing.JLabel;
13  import javax.swing.JPanel;
14  import javax.swing.JScrollPane;
15  import javax.swing.JTable;
16  import javax.swing.JTextField;
17  import javax.swing.JTextPane;
18  import javax.swing.ListSelectionModel;
19  import javax.swing.border.TitledBorder;
20  import javax.swing.event.ListSelectionEvent;
21  import javax.swing.event.ListSelectionListener;
22  
23  import org.xrn.xsd2java.Deliveries;
24  import org.xrn.xsd2java.ReleaseNotesType.DeliveriesType;
25  import org.xrn.xsd2java.impl.DeliveriesImpl;
26  import org.xrn.xsd2java.impl.DeliveryImpl;
27  
28  /***
29   * 
30   * The release deliveries panel in the release tabbed pane
31   * @author Carsten Maneg
32   * Date Nov 14, 2004
33   * Time 10:17:26 PM
34   */
35  public class ReleaseDeliveriesPanel extends JPanel implements ActionListener, ListSelectionListener{
36      private Font schriftTyp;
37      
38      private JButton removeButton = new JButton( "Remove" );
39      private JButton addButton = new JButton( "Add" );
40      private JLabel hrefLabel = new JLabel( "HREF" );
41      private JTextField hrefField = new JTextField();
42      private JLabel contentLabel = new JLabel( "Content" );
43      private JTextPane contentField = new JTextPane();
44      private SummaryPanel summaryPanel = null;
45      private JTable table = null;
46      private MyTableModel tableModel = null;
47  	private JScrollPane scrollPane = null;
48  	private JScrollPane contentScrollPane = null;
49   
50      private JPanel panelOwner = null;
51      
52      private DeliveriesType deliveries = null;
53      private Deliveries releaseDeliveries = new DeliveriesImpl();
54      private DeliveryImpl delivery = new DeliveryImpl();
55                      
56      public ReleaseDeliveriesPanel( JPanel owner, String title ){
57    	
58          if( title == null )
59              title = "";
60          setBorder( new TitledBorder( title ) );
61          schriftTyp =  new Font( "newFont", Font.BOLD, 14 );
62          setFont( schriftTyp );
63          setLayout( null );
64          
65          panelOwner = owner;
66          
67          summaryPanel = new SummaryPanel( this, "small" );
68          dlgObjHinzufuegen( summaryPanel, 410, 25, 250, 160 );
69          
70      	createTable();	
71      	dlgObjHinzufuegen( scrollPane, 25, 25, 165, 150 );  	
72          
73          dlgObjHinzufuegen( hrefLabel, 200, 25, 50, 20 );
74          dlgObjHinzufuegen( hrefField, 200, 50, 200, 20 );
75          
76          dlgObjHinzufuegen( contentLabel, 200, 80, 50, 20 );
77          contentScrollPane = new JScrollPane( contentField );
78          dlgObjHinzufuegen( contentScrollPane, 200, 105, 200, 70 );  
79          
80      	addButton.addActionListener( this );
81          dlgObjHinzufuegen( addButton, 25, 185, 80, 20 );
82          removeButton.addActionListener( this );
83          dlgObjHinzufuegen( removeButton, 110, 185, 80, 20 );    	
84      }
85  
86      /***
87       * 
88       * @param c
89       * @param x0
90       * @param y0
91       * @param breite
92       * @param hoehe
93       */
94      public void dlgObjHinzufuegen( JComponent c, int x0, int y0, int breite, int hoehe ){
95          c.setBounds( x0, y0, breite, hoehe );
96          c.setForeground( Color.black );
97          add(c);
98      }
99      
100     /***
101      * Creates the component table to show the components of the release notes
102      *
103      */
104     public void createTable( ){
105     	
106     	Vector columnName = new Vector( 1 );
107     	columnName.addElement( "Delivery" );
108 
109     	tableModel = new MyTableModel( columnName, 0 );
110     	table = new JTable( tableModel );
111     	
112     	//tradeDT.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
113     	
114     	table.getColumnModel().getColumn( 0 ).setPreferredWidth( 100 );
115     	table.getSelectionModel().addListSelectionListener( this );
116     	table.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
117     	scrollPane = new JScrollPane( table );
118     }
119     
120     /***
121      * Write the releases list to the table
122      *
123      */
124     private void writeTable(){
125     	int i = 0;
126     	Vector sv = new Vector();
127     	DeliveryImpl delivery = null;
128     	
129     	resetTable();
130     	for( i=0; i < releaseDeliveries.getDelivery().size(); i++ ){
131     		delivery = (DeliveryImpl)releaseDeliveries.getDelivery().get( i );
132     		sv = new Vector();
133     	  sv.addElement( delivery.getHref() );
134     	  tableModel.addRow( sv );
135     	}
136     	if( releaseDeliveries.getDelivery().size() > 0 )
137     	    table.setRowSelectionInterval( 0, 0 );
138     }
139     
140     /***
141      * 
142      */
143     public void actionPerformed( ActionEvent e ){
144         if ( e.getSource() == addButton ){
145             releaseDeliveries.getDelivery().add( getDelivery() );
146             writeTable();
147         }
148         if ( e.getSource() == removeButton ){
149             if( table.getSelectedRow() > -1 ){
150                 releaseDeliveries.getDelivery().remove( table.getSelectedRow() );
151                 writeTable();
152                 resetFields();
153             }
154             else{
155                 MessageWindow.mitteilung( "No component selected !" );
156             }            
157         }  	
158     }
159 
160     /***
161      * Handle the table selection events
162      */
163     public void valueChanged( ListSelectionEvent e ){
164         if( releaseDeliveries.getDelivery().size() > 0 && table.getSelectedRow() > -1 ){
165             DeliveryImpl delivery = (DeliveryImpl)releaseDeliveries.getDelivery().get( table.getSelectedRow() );
166         	hrefField.setText( delivery.getHref() );
167         	if( delivery.getContent().size() >0 )
168         	    contentField.setText( (String)delivery.getContent().get( 0 ) );
169         }
170     }
171 
172     /***
173      * Delete the input and set the default value if necessary
174      *
175      */
176     public void resetFields( ){
177         hrefField.setText( "" );
178         summaryPanel.resetFields();
179         contentField.setText( "" );
180     }
181     
182     /***
183      * Delete the table input
184      *
185      */
186     public void resetTable( ){
187         for ( int i = tableModel.getRowCount() - 1; i >= 0 ; i-- )
188     		tableModel.removeRow( i );        
189     }
190     
191     /***
192      * 
193      * @return
194      */
195     private DeliveryImpl getDelivery(){
196         delivery.setHref( hrefField.getText( ) );
197         delivery.setContentType( contentField.getText( ) );
198         return delivery;
199     }
200     
201     /***
202      * 
203      * @return the deliveries
204      */
205     public DeliveriesType getDeliveries(){
206         deliveries.setHref( hrefField.getText() );
207         return this.deliveries;
208     }
209     
210     /***
211      * 
212      * @param deliveries
213      */
214     public void setDeliveries( DeliveriesType deliveries ){
215         this.deliveries = deliveries;
216         hrefField.setText( deliveries.getHref() );
217     }    
218 
219     /***
220      * 
221      * @return the delivery
222      */
223     public Deliveries getReleaseDeliveries(){
224         releaseDeliveries.setSummary( summaryPanel.getSummary() );
225         return this.releaseDeliveries;
226     }
227     
228     /***
229      * 
230      * @param deliveries
231      */
232     public void setReleaseDeliveries( Deliveries releaseDeliveries ){
233         this.releaseDeliveries = releaseDeliveries;
234         if( releaseDeliveries != null ){
235             writeTable();
236             summaryPanel.setSummary( releaseDeliveries.getSummary() );
237         }        
238     }    
239 }