KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > ajde > ui > swing > UpdateConfigurationDialog


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the IDE support for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25
26 package org.aspectj.ajde.ui.swing;
27
28 import java.awt.*;
29 import javax.swing.*;
30 import java.awt.event.*;
31 import java.util.Vector JavaDoc;
32 import javax.swing.border.*;
33 import org.aspectj.ajde.Ajde;
34 import org.aspectj.ajde.internal.*;
35
36 /**
37  * Used for automatically updating build configuration files (".lst") when a
38  * project configuration has changed.
39  *
40  * @author Mik Kersten
41  */

42 public class UpdateConfigurationDialog extends JFrame {
43     private Vector JavaDoc buildConfigFiles;
44     private Vector JavaDoc filesToUpdate;
45     private boolean addToConfiguration;
46
47     private String JavaDoc message1 = " Project has been updated.";
48     private String JavaDoc message2 = " File list below.";
49     private Box box5;
50     private JButton cancel_button = new JButton();
51     private JButton ok_button = new JButton();
52     private FlowLayout flowLayout1 = new FlowLayout();
53     private JPanel globalButton_panel = new JPanel();
54     private JPanel jPanel1 = new JPanel();
55     private JPanel jPanel2 = new JPanel();
56     private TitledBorder titledBorder1;
57     private TitledBorder titledBorder2;
58     private BorderLayout borderLayout1 = new BorderLayout();
59     private BorderLayout borderLayout2 = new BorderLayout();
60     private BorderLayout borderLayout3 = new BorderLayout();
61     private JPanel jPanel3 = new JPanel();
62     private GridLayout gridLayout1 = new GridLayout();
63     private JScrollPane jScrollPane1 = new JScrollPane();
64     private JList updatedFilesList = new JList();
65     private JScrollPane jScrollPane2 = new JScrollPane();
66     private JList buildConfigList = new JList();
67     private Box box2;
68     private JLabel messageLabel1 = new JLabel();
69     private JLabel messageLabel2 = new JLabel();
70
71     public UpdateConfigurationDialog(Vector JavaDoc filesToUpdate, Vector JavaDoc buildConfigFiles, boolean addToConfiguration, Component parentComponent) {
72         try {
73             this.buildConfigFiles = buildConfigFiles;
74             this.filesToUpdate = filesToUpdate;
75             this.addToConfiguration = addToConfiguration;
76
77             updatedFilesList.setListData(filesToUpdate);
78             String JavaDoc action = "removed from";
79             if (addToConfiguration) action = "added to";
80             message1 = " Files have been " + action + " the project, which will affect the build configurations\n";
81             message2 = " listed below. These build configurations listed can be updated automatically.";
82
83             //buildConfigList.setCellRenderer(new CheckListCellRenderer());
84
//CheckListener listener = new CheckListener(buildConfigList);
85
buildConfigList.setListData(buildConfigFiles);
86
87             jbInit();
88
89             this.doLayout();
90             this.setTitle("Build Configuration Update");
91             this.setSize(500, 320);
92
93             // center it
94
int posX = parentComponent.getX() + 100;//(parentComponent.getWidth()/2);
95
int posY = parentComponent.getY() + 100;//(parentComponent.getHeight()/2);
96
this.setLocation(posX, posY);
97         }
98         catch(Exception JavaDoc e) {
99             Ajde.getDefault().getErrorHandler().handleError("Could not open configuration dialog", e);
100         }
101     }
102
103     void cancel_button_actionPerformed(ActionEvent e) {
104         this.dispose();
105     }
106     void ok_button_actionPerformed(ActionEvent e) {
107         Object JavaDoc[] selected = buildConfigList.getSelectedValues();
108         //LstBuildConfigFileUpdater.updateBuildConfigFiles(buildConfigFiles, filesToUpdate, addToConfiguration);
109
this.dispose();
110     }
111
112     private void jbInit() throws Exception JavaDoc {
113         box5 = Box.createVerticalBox();
114         titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)),"Project Files Added/Removed");
115         titledBorder2 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)),"Build Configurations Affected");
116         box2 = Box.createVerticalBox();
117         this.getContentPane().setLayout(borderLayout1);
118         cancel_button.setText("Cancel");
119         cancel_button.addActionListener(new java.awt.event.ActionListener JavaDoc() {
120
121             public void actionPerformed(ActionEvent e) {
122                 cancel_button_actionPerformed(e);
123             }
124         });
125         ok_button.setText("Update Selected Configurations");
126         ok_button.addActionListener(new java.awt.event.ActionListener JavaDoc() {
127
128             public void actionPerformed(ActionEvent e) {
129                 ok_button_actionPerformed(e);
130             }
131         });
132         globalButton_panel.setLayout(flowLayout1);
133         jPanel1.setLayout(borderLayout3);
134         jPanel1.setBorder(titledBorder1);
135         jPanel1.setMinimumSize(new Dimension(154, 20));
136         jPanel1.setPreferredSize(new Dimension(154, 50));
137         jPanel2.setBorder(titledBorder2);
138         jPanel2.setMinimumSize(new Dimension(36, 50));
139         jPanel2.setPreferredSize(new Dimension(272, 50));
140         jPanel2.setLayout(borderLayout2);
141         globalButton_panel.setMinimumSize(new Dimension(297, 37));
142         globalButton_panel.setPreferredSize(new Dimension(297, 37));
143         jPanel3.setLayout(gridLayout1);
144         jPanel3.setMinimumSize(new Dimension(154, 20));
145         jPanel3.setPreferredSize(new Dimension(154, 40));
146         buildConfigList.setBorder(BorderFactory.createLoweredBevelBorder());
147         messageLabel1.setText(message1);
148         messageLabel2.setText(message2);
149         updatedFilesList.setFont(new java.awt.Font JavaDoc("Dialog", 0, 10));
150         this.getContentPane().add(box5, BorderLayout.CENTER);
151         box5.add(jPanel3, null);
152         jPanel3.add(box2, null);
153         box2.add(messageLabel1, null);
154         box2.add(messageLabel2, null);
155         box5.add(jPanel1, null);
156         jPanel1.add(jScrollPane1, BorderLayout.CENTER);
157         jScrollPane1.getViewport().add(updatedFilesList, null);
158         box5.add(jPanel2, null);
159         jPanel2.add(jScrollPane2, BorderLayout.CENTER);
160         jScrollPane2.getViewport().add(buildConfigList, null);
161         box5.add(globalButton_panel, null);
162         globalButton_panel.add(ok_button, null);
163         globalButton_panel.add(cancel_button, null);
164     }
165 }
166
167 class CheckListCellRenderer extends JCheckBox implements ListCellRenderer {
168     public CheckListCellRenderer() {
169         super();
170         setOpaque(true);
171     }
172
173     public Component getListCellRendererComponent(JList list,
174                                                   Object JavaDoc value,
175                                                   int index,
176                                                   boolean isSelected,
177                                                   boolean cellHasFocus) {
178             setText(value.toString());
179             setFont(new java.awt.Font JavaDoc("Dialog", 0, 10));
180             setBackground(new Color(255, 255, 255));
181
182             setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());
183             setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());
184             setSelected(isSelected);
185
186             return this;
187     }
188 }
189
190 class CheckListener implements MouseListener, KeyListener {
191
192     protected JList list;
193
194     public CheckListener(JList list) {
195         this.list = list;
196     }
197
198     public void mouseClicked(MouseEvent e) {
199         doCheck();
200     }
201
202     public void keyPressed(KeyEvent e) {
203         if (e.getKeyChar() == ' ') doCheck();
204     }
205
206     protected void doCheck() {
207         int index = list.getSelectedIndex();
208         if (index < 0) {
209             return;
210         }
211         list.getModel().getElementAt(index);
212         list.repaint();
213     }
214
215     public void mousePressed(MouseEvent e) {}
216     public void mouseReleased(MouseEvent e) {}
217     public void mouseEntered(MouseEvent e) {}
218     public void mouseExited(MouseEvent e) {}
219     public void keyTyped(KeyEvent e) {}
220     public void keyReleased(KeyEvent e) { }
221 }
Popular Tags