001: package salomeTMF_plug.mantis;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Container;
005: import java.awt.Dialog;
006: import java.awt.Dimension;
007: import java.awt.FlowLayout;
008: import java.awt.GraphicsConfiguration;
009: import java.awt.GraphicsDevice;
010: import java.awt.GraphicsEnvironment;
011: import java.awt.Rectangle;
012: import java.awt.event.ActionEvent;
013: import java.awt.event.ActionListener;
014: import java.util.Enumeration;
015: import java.util.Hashtable;
016:
017: import javax.swing.JButton;
018: import javax.swing.JDialog;
019: import javax.swing.JPanel;
020:
021: import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
022:
023: import salomeTMF_plug.mantis.languages.Language;
024: import salomeTMF_plug.mantis.sqlWrapper.DefectWrapper;
025:
026: public class LinkDefectDialog extends JDialog implements ActionListener {
027:
028: JButton commitButton;
029: JButton cancelButton;
030:
031: DefectWrapper selectDefectWrapper;
032:
033: MantisPlugin pMantisPlugin;
034: DefectPanel pDefectPanel;
035:
036: public LinkDefectDialog(MantisPlugin pMantisPlugin,
037: Hashtable linkedDefects, String envRestrictionName) {
038: super (SalomeTMFContext.getInstance().getSalomeFrame(), true);
039: setModal(true);
040: this .pMantisPlugin = pMantisPlugin;
041: initComponent(envRestrictionName, linkedDefects);
042: makeDialog(Language.getInstance().getText("Lier_a_annomalie"));
043:
044: }
045:
046: public LinkDefectDialog(Dialog parent, MantisPlugin pMantisPlugin,
047: Hashtable linkedDefects, String envRestrictionName) {
048: super (parent, true);
049: setModal(true);
050: this .pMantisPlugin = pMantisPlugin;
051: initComponent(envRestrictionName, linkedDefects);
052: makeDialog(Language.getInstance().getText("Lier_a_annomalie"));
053:
054: }
055:
056: void initComponent(String envRestrictionName,
057: Hashtable linkedDefects) {
058: selectDefectWrapper = null;
059: commitButton = new JButton(
060: org.objectweb.salome_tmf.ihm.languages.Language
061: .getInstance().getText("Valider"));
062: commitButton.addActionListener(this );
063: cancelButton = new JButton(
064: org.objectweb.salome_tmf.ihm.languages.Language
065: .getInstance().getText("Annuler"));
066: cancelButton.addActionListener(this );
067: JPanel buttonPanel = new JPanel(new FlowLayout(
068: FlowLayout.CENTER));
069: buttonPanel.add(cancelButton);
070: buttonPanel.add(commitButton);
071: pDefectPanel = new DefectPanel(false, pMantisPlugin,
072: buttonPanel, envRestrictionName);
073: try {
074: Hashtable allDefects = pMantisPlugin
075: .getDefectsOfProject(false);
076: Enumeration enumLikeddefect = linkedDefects.keys();
077: while (enumLikeddefect.hasMoreElements()) {
078: Integer key = (Integer) enumLikeddefect.nextElement();
079: allDefects.remove(key);
080: }
081: pDefectPanel.loadData(allDefects);
082: } catch (Exception e) {
083: e.printStackTrace();
084: }
085: }
086:
087: public DefectWrapper getSelectedDefectWrapper() {
088: return selectDefectWrapper;
089: }
090:
091: void makeDialog(String title) {
092: int t_x = 1024 - 100;
093: int t_y = 768 - 50;
094: int t_x2 = 1024;
095: int t_y2 = 768;
096: try {
097: GraphicsEnvironment ge = GraphicsEnvironment
098: .getLocalGraphicsEnvironment();
099: GraphicsDevice[] gs = ge.getScreenDevices();
100: GraphicsDevice gd = gs[0];
101: GraphicsConfiguration[] gc = gd.getConfigurations();
102: Rectangle r = gc[0].getBounds();
103: t_x = r.width - 100;
104: t_y = r.height - 50;
105: t_x2 = r.width;
106: t_y2 = r.height;
107: } catch (Exception E) {
108:
109: }
110:
111: Container contentPane = this .getContentPane();
112: contentPane.setLayout(new BorderLayout());
113: contentPane.add(pDefectPanel, BorderLayout.CENTER);
114: pDefectPanel.setSize(new Dimension(t_x, t_y));
115: this .setTitle(title);
116: setSize(t_x, t_y);
117: /*this.pack();
118: this.setLocationRelativeTo(this.getParent());
119: this.setVisible(true);*/
120: centerScreen();
121: }
122:
123: void centerScreen() {
124: Dimension dim = getToolkit().getScreenSize();
125: this .pack();
126: Rectangle abounds = getBounds();
127: setLocation((dim.width - abounds.width) / 2,
128: (dim.height - abounds.height) / 2);
129: this .setVisible(true);
130: requestFocus();
131: }
132:
133: public void actionPerformed(ActionEvent e) {
134: if (e.getSource().equals(cancelButton)) {
135: selectDefectWrapper = null;
136: dispose();
137: } else if (e.getSource().equals(commitButton)) {
138: selectDefectWrapper = pDefectPanel.getSelectedDefect();
139: dispose();
140: }
141: }
142: }
|