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