1 30 package com.genimen.djeneric.tools.modeler.dialogs; 31 32 import java.awt.BorderLayout ; 33 import java.awt.Dimension ; 34 import java.awt.Toolkit ; 35 import java.awt.event.ActionEvent ; 36 import java.awt.event.KeyEvent ; 37 import java.awt.event.MouseEvent ; 38 import java.util.Vector ; 39 40 import javax.swing.DefaultComboBoxModel ; 41 import javax.swing.JButton ; 42 import javax.swing.JDialog ; 43 import javax.swing.JList ; 44 import javax.swing.JPanel ; 45 import javax.swing.JScrollPane ; 46 import javax.swing.ListSelectionModel ; 47 48 import com.genimen.djeneric.language.Messages; 49 import com.genimen.djeneric.repository.DjModelView; 50 import com.genimen.djeneric.tools.modeler.ModelEditor; 51 import com.genimen.djeneric.ui.Util; 52 53 public class OpenDialog extends JDialog 54 { 55 private static final long serialVersionUID = 1L; 56 BorderLayout borderLayout1 = new BorderLayout (); 57 JScrollPane jScrollPane1 = new JScrollPane (); 58 JList _lstViews = new JList (); 59 JPanel jPanel1 = new JPanel (); 60 BorderLayout borderLayout2 = new BorderLayout (); 61 JPanel jPanel3 = new JPanel (); 62 BorderLayout borderLayout3 = new BorderLayout (); 63 JPanel jPanel4 = new JPanel (); 64 JButton _butOk = new JButton (); 65 JButton _butCancel = new JButton (); 66 67 boolean _canceled = true; 68 DjModelView[] _allViews; 69 DjModelView _excludeThis = null; 70 71 public OpenDialog(ModelEditor editor, String customTitle) throws Exception 72 { 73 super(editor, customTitle, true); 74 construct(editor); 75 } 76 77 public OpenDialog(ModelEditor editor, String customTitle, DjModelView excludeThis) throws Exception 78 { 79 super(editor, customTitle, true); 80 _excludeThis = excludeThis; 81 construct(editor); 82 } 83 84 public OpenDialog(ModelEditor editor) throws Exception 85 { 86 super(editor, Messages.getString("OpenDialog.OpenView"), true); 87 construct(editor); 88 } 89 90 protected void construct(ModelEditor editor) throws Exception 91 { 92 jbInit(); 93 94 _allViews = editor.getPersistenceManager().getViews(); 95 Vector vws = new Vector (); 96 for (int i = 0; i < _allViews.length; i++) 97 { 98 if (!_allViews[i].equals(_excludeThis)) vws.add(_allViews[i]); 99 } 100 101 _lstViews.setModel(new DefaultComboBoxModel (vws)); 102 setSize(290, 230); 103 104 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 105 Dimension frameSize = getSize(); 106 setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); 107 108 if (_allViews.length > 0) _lstViews.setSelectedIndex(0); 109 110 setVisible(true); 111 if (_canceled) throw new Exception (Messages.getString("OpenDialog.OpenAborted")); 112 } 113 114 void jbInit() throws Exception 115 { 116 this.getContentPane().setLayout(borderLayout1); 117 jPanel1.setLayout(borderLayout2); 118 jPanel3.setLayout(borderLayout3); 119 _butOk.setText(Messages.getString("global.Ok")); 120 _butOk.addActionListener(new java.awt.event.ActionListener () 121 { 122 public void actionPerformed(ActionEvent e) 123 { 124 _butOk_actionPerformed(e); 125 } 126 }); 127 _butCancel.setText(Messages.getString("global.Cancel")); 128 _butCancel.addActionListener(new java.awt.event.ActionListener () 129 { 130 public void actionPerformed(ActionEvent e) 131 { 132 _butCancel_actionPerformed(e); 133 } 134 }); 135 _lstViews.addMouseListener(new java.awt.event.MouseAdapter () 136 { 137 public void mouseClicked(MouseEvent e) 138 { 139 _lstViews_mouseClicked(e); 140 } 141 }); 142 _lstViews.addKeyListener(new java.awt.event.KeyAdapter () 143 { 144 public void keyPressed(KeyEvent e) 145 { 146 _lstViews_keyPressed(e); 147 } 148 }); 149 _lstViews.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 150 this.getContentPane().add(jScrollPane1, BorderLayout.CENTER); 151 this.getContentPane().add(jPanel1, BorderLayout.SOUTH); 152 jPanel1.add(jPanel3, BorderLayout.SOUTH); 153 jPanel3.add(jPanel4, BorderLayout.EAST); 154 jPanel4.add(_butCancel, null); 155 jPanel4.add(_butOk, null); 156 jScrollPane1.getViewport().add(_lstViews, null); 157 Util.sizeButtons(jPanel4); 158 } 159 160 void _butOk_actionPerformed(ActionEvent e) 161 { 162 if (_lstViews.getSelectedIndex() == -1) return; 163 _canceled = false; 164 setVisible(false); 165 } 166 167 void _butCancel_actionPerformed(ActionEvent e) 168 { 169 setVisible(false); 170 } 171 172 public DjModelView getModelView() 173 { 174 return (DjModelView) _lstViews.getSelectedValue(); 175 } 176 177 void _lstViews_mouseClicked(MouseEvent e) 178 { 179 if (e.getClickCount() > 1) _butOk_actionPerformed(null); 180 } 181 182 void _lstViews_keyPressed(KeyEvent e) 183 { 184 if (e.getKeyCode() == KeyEvent.VK_ENTER) _butOk_actionPerformed(null); 185 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) _butCancel_actionPerformed(null); 186 } 187 188 } | Popular Tags |