PageRenderTime 71ms CodeModel.GetById 40ms RepoModel.GetById 0ms app.codeStats 0ms

/Reha/src/patientenFenster/ArztNeuKurz.java

https://github.com/bomm/thera-pi-2
Java | 332 lines | 274 code | 40 blank | 18 comment | 18 complexity | bd98552f8597ef720bbba2230d9af6d2 MD5 | raw file
  1. package patientenFenster;
  2. import java.awt.BorderLayout;
  3. import java.awt.Point;
  4. import java.awt.Rectangle;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.awt.event.FocusEvent;
  8. import java.awt.event.FocusListener;
  9. import java.awt.event.KeyEvent;
  10. import java.awt.event.KeyListener;
  11. import javax.swing.JButton;
  12. import javax.swing.JComponent;
  13. import javax.swing.JLabel;
  14. import javax.swing.JOptionPane;
  15. import javax.swing.JScrollPane;
  16. import javax.swing.JViewport;
  17. import javax.swing.SwingUtilities;
  18. import org.jdesktop.swingworker.SwingWorker;
  19. import org.jdesktop.swingx.JXPanel;
  20. import CommonTools.SqlInfo;
  21. import systemEinstellungen.SystemConfig;
  22. import CommonTools.JCompTools;
  23. import CommonTools.JRtaComboBox;
  24. import CommonTools.JRtaTextField;
  25. import com.jgoodies.forms.builder.PanelBuilder;
  26. import com.jgoodies.forms.layout.CellConstraints;
  27. import com.jgoodies.forms.layout.FormLayout;
  28. public class ArztNeuKurz extends JXPanel implements ActionListener,KeyListener,FocusListener{
  29. /**
  30. *
  31. */
  32. private static final long serialVersionUID = -8412450784730057738L;
  33. public JRtaTextField tfs[] = {null,null,null,null,null,
  34. null,null,null,null,null,
  35. null,null,null,null,null};
  36. public JButton speichern;
  37. public JButton abbrechen;
  38. public ArztAuswahl eltern;
  39. public JScrollPane jscr;
  40. public JRtaComboBox arztgruppe;
  41. public ArztNeuKurz(ArztAuswahl eltern){
  42. super();
  43. this.eltern = eltern;
  44. setOpaque(false);
  45. setLayout(new BorderLayout());
  46. add(getFelderPanel(),BorderLayout.CENTER);
  47. add(getButtonPanel(),BorderLayout.SOUTH);
  48. validate();
  49. }
  50. public JScrollPane getFelderPanel(){
  51. FormLayout lay = new FormLayout(
  52. // 1 2 3 4 5 6
  53. "right:max(60dlu;p), 4dlu, 60dlu,right:max(60dlu;p), 4dlu, 60dlu",
  54. //"0dlu,right:max(50dlu;p),3dlu,150dlu,3dlu,p,fill:0:grow(1.00)",
  55. // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
  56. "3dlu,p,2dlu,p,2dlu,p,2dlu,p,2dlu,p,5dlu,p,5dlu,p,2dlu,p, 5dlu, p, 5dlu,p,2dlu,p,2dlu, p, 5dlu, p, 5dlu,p,2dlu,p,10dlu");
  57. PanelBuilder jpan = new PanelBuilder(lay);
  58. jpan.setDefaultDialogBorder();
  59. jpan.getPanel().setOpaque(false);
  60. jpan.getPanel().addKeyListener(this);
  61. CellConstraints cc = new CellConstraints();
  62. jpan.add(new JLabel("Anrede"),cc.xy(1,2));
  63. tfs[0] = new JRtaTextField("NORMAL",true);
  64. tfs[0].addKeyListener(this);
  65. tfs[0].addFocusListener(this);
  66. tfs[0].setName("anrede");
  67. jpan.add(tfs[0],cc.xy(3, 2));
  68. jpan.add(new JLabel("Titel"),cc.xy(4,2));
  69. tfs[1] = new JRtaTextField("NORMAL",true);
  70. tfs[1].addKeyListener(this);
  71. tfs[1].addFocusListener(this);
  72. tfs[1].setName("titel");
  73. jpan.add(tfs[1],cc.xy(6, 2));
  74. jpan.add(new JLabel("Nachname"),cc.xy(1,4));
  75. tfs[2] = new JRtaTextField("NORMAL",true);
  76. tfs[2].addKeyListener(this);
  77. tfs[2].addFocusListener(this);
  78. tfs[2].setName("nachname");
  79. jpan.add(tfs[2],cc.xyw(3, 4, 4));
  80. jpan.add(new JLabel("Vorname"),cc.xy(1,6));
  81. tfs[3] = new JRtaTextField("NORMAL",true);
  82. tfs[3].addKeyListener(this);
  83. tfs[3].addFocusListener(this);
  84. tfs[3].setName("vorname");
  85. jpan.add(tfs[3],cc.xyw(3, 6, 4));
  86. jpan.add(new JLabel("Strasse"),cc.xy(1, 8));
  87. tfs[4] = new JRtaTextField("NORMAL",true);
  88. tfs[4].addKeyListener(this);
  89. tfs[4].addFocusListener(this);
  90. tfs[4].setName("strasse");
  91. jpan.add(tfs[4],cc.xyw(3, 8,4));
  92. jpan.add(new JLabel("Plz/Ort"),cc.xy(1, 10));
  93. tfs[5] = new JRtaTextField("ZAHLEN",true);
  94. tfs[5].addKeyListener(this);
  95. tfs[5].addFocusListener(this);
  96. tfs[5].setName("plz");
  97. jpan.add(tfs[5],cc.xy(3, 10));
  98. tfs[6] = new JRtaTextField("NORMAL",true);
  99. tfs[6].addKeyListener(this);
  100. tfs[6].addFocusListener(this);
  101. tfs[6].setName("ort");
  102. jpan.add(tfs[6],cc.xyw(4, 10,3));
  103. jpan.addSeparator("Arztidentifikation",cc.xyw(1, 12, 6));
  104. jpan.add(new JLabel("LANR"),cc.xy(1, 14));
  105. tfs[7] = new JRtaTextField("ZAHLEN",true);
  106. tfs[7].addKeyListener(this);
  107. tfs[7].addFocusListener(this);
  108. tfs[7].setName("arztnum");
  109. jpan.add(tfs[7],cc.xyw(3, 14,4));
  110. jpan.add(new JLabel("Betriebsstätte"),cc.xy(1, 16));
  111. tfs[8] = new JRtaTextField("ZAHLEN",true);
  112. tfs[8].addKeyListener(this);
  113. tfs[8].addFocusListener(this);
  114. tfs[8].setName("bsnr");
  115. jpan.add(tfs[8],cc.xyw(3, 16,4));
  116. jpan.addSeparator("Kontakt",cc.xyw(1, 18, 6));
  117. jpan.add(new JLabel("Telefon"),cc.xy(1, 20));
  118. tfs[9] = new JRtaTextField("NORMAL",true);
  119. tfs[9].addKeyListener(this);
  120. tfs[9].addFocusListener(this);
  121. tfs[9].setName("telefon");
  122. jpan.add(tfs[9],cc.xyw(3, 20,4));
  123. jpan.add(new JLabel("Telefax"),cc.xy(1, 22));
  124. tfs[10] = new JRtaTextField("NORMAL",true);
  125. tfs[10].addKeyListener(this);
  126. tfs[10].addFocusListener(this);
  127. tfs[10].setName("fax");
  128. jpan.add(tfs[10],cc.xyw(3, 22,4));
  129. jpan.add(new JLabel("Email"),cc.xy(1, 24));
  130. tfs[11] = new JRtaTextField("NIX",true);
  131. tfs[11].addKeyListener(this);
  132. tfs[11].addFocusListener(this);
  133. tfs[11].setName("email1");
  134. jpan.add(tfs[11],cc.xyw(3, 24,4));
  135. jpan.addSeparator("Zusätze",cc.xyw(1, 26, 6));
  136. jpan.add(new JLabel("Facharzt"),cc.xy(1, 28));
  137. arztgruppe = new JRtaComboBox(SystemConfig.arztGruppen);
  138. arztgruppe.addFocusListener(this);
  139. jpan.add(arztgruppe,cc.xyw(3, 28,4));
  140. jpan.add(new JLabel("Klinik"),cc.xy(1, 30));
  141. tfs[12] = new JRtaTextField("NIX",true);
  142. tfs[12].addKeyListener(this);
  143. tfs[12].addFocusListener(this);
  144. tfs[12].setName("klinik");
  145. jpan.add(tfs[12],cc.xyw(3, 30,4));
  146. tfs[13] = new JRtaTextField("NIX",true);
  147. tfs[13].setName("facharzt");
  148. tfs[14] = new JRtaTextField("NIX",true);
  149. tfs[14].setName("id");
  150. jpan.getPanel().validate();
  151. jscr = JCompTools.getTransparentScrollPane(jpan.getPanel());
  152. jscr.getVerticalScrollBar().setUnitIncrement(15);
  153. jscr.validate();
  154. return jscr;
  155. }
  156. /**************************************************/
  157. public JXPanel getButtonPanel(){
  158. JXPanel jpan = JCompTools.getEmptyJXPanel();
  159. jpan.addKeyListener(this);
  160. jpan.setOpaque(false);
  161. FormLayout lay = new FormLayout(
  162. // 1 2 3 4 5
  163. "fill:0:grow(0.33),50dlu,fill:0:grow(0.33),50dlu,fill:0:grow(0.33)",
  164. // 1 2 3
  165. "5dlu,p,5dlu");
  166. CellConstraints cc = new CellConstraints();
  167. jpan.setLayout(lay);
  168. speichern = new JButton("speichern");
  169. speichern.setActionCommand("speichern");
  170. speichern.addActionListener(this);
  171. speichern.addKeyListener(this);
  172. speichern.setMnemonic(KeyEvent.VK_S);
  173. jpan.add(speichern,cc.xy(2,2));
  174. abbrechen = new JButton("abbrechen");
  175. abbrechen.setActionCommand("abbrechen");
  176. abbrechen.addActionListener(this);
  177. abbrechen.addKeyListener(this);
  178. abbrechen.setMnemonic(KeyEvent.VK_A);
  179. jpan.add(abbrechen,cc.xy(4,2));
  180. return jpan;
  181. }
  182. public JXPanel getNeuKurzPanel(){
  183. return this;
  184. }
  185. public void setzteFocus(){
  186. SwingUtilities.invokeLater(new Runnable(){
  187. public void run(){
  188. tfs[0].requestFocus();
  189. }
  190. });
  191. }
  192. @Override
  193. public void actionPerformed(ActionEvent arg0) {
  194. // TODO Auto-generated method stub
  195. String comm = arg0.getActionCommand();
  196. if(comm.equals("speichern")){
  197. panelWechsel(true);
  198. }
  199. if(comm.equals("abbrechen")){
  200. panelWechsel(false);
  201. }
  202. }
  203. public void allesAufNull(){
  204. for(int i = 0; i < 15; i++){
  205. tfs[i].setText("");
  206. }
  207. }
  208. public void panelWechsel(boolean uebernahme){
  209. if(uebernahme){
  210. new SwingWorker<Void,Void>(){
  211. @Override
  212. protected Void doInBackground() throws Exception {
  213. if(tfs[2].getText().trim().equals("")){
  214. JOptionPane.showMessageDialog(null, "Also der Name des Arztes sollte wenigstens angegeben werden!");
  215. return null;
  216. }
  217. int iid;
  218. tfs[13].setText((String)arztgruppe.getSelectedItem());
  219. tfs[14].setText(Integer.toString(iid = SqlInfo.holeId("arzt", "nachname")));
  220. String stmt = "update arzt set ";
  221. for(int i = 0; i < 14; i++){
  222. stmt = stmt+ (i==0 ? "" : ", ")+tfs[i].getName()+"='"+tfs[i].getText()+"'";
  223. }
  224. stmt = stmt + " where id ='"+Integer.toString(iid)+"'";
  225. //System.out.println(stmt);
  226. SqlInfo.sqlAusfuehren(stmt);
  227. //new ExUndHop().setzeStatement(stmt);
  228. eltern.zurueckZurTabelle(tfs);
  229. return null;
  230. }
  231. }.execute();
  232. }else{
  233. eltern.zurueckZurTabelle(null);
  234. }
  235. }
  236. @Override
  237. public void keyPressed(KeyEvent arg0) {
  238. // TODO Auto-generated method stub
  239. if(arg0.getKeyCode() == 27){
  240. arg0.consume();
  241. panelWechsel(false);
  242. eltern.zurueckZurTabelle(null);
  243. return;
  244. }
  245. try{
  246. if(arg0.getKeyCode() == 10){
  247. arg0.consume();
  248. if(((JComponent)arg0.getSource()).getName().equals("speichern")){
  249. arg0.consume();
  250. panelWechsel(true);
  251. }else if(((JComponent)arg0.getSource()).getName().equals("abbrechen")){
  252. arg0.consume();
  253. panelWechsel(true);
  254. }
  255. }
  256. }catch(java.lang.NullPointerException ex){
  257. arg0.consume();
  258. }
  259. }
  260. @Override
  261. public void keyReleased(KeyEvent arg0) {
  262. // TODO Auto-generated method stub
  263. if(arg0.getKeyCode() == 27){
  264. arg0.consume();
  265. }
  266. }
  267. @Override
  268. public void keyTyped(KeyEvent arg0) {
  269. // TODO Auto-generated method stub
  270. if(arg0.getKeyCode() == 27){
  271. arg0.consume();
  272. }
  273. }
  274. @Override
  275. public void focusGained(FocusEvent arg0) {
  276. // TODO Auto-generated method stub
  277. Rectangle rec1 =((JComponent)arg0.getSource()).getBounds();
  278. Rectangle rec2 = jscr.getViewport().getViewRect();
  279. JViewport vp = jscr.getViewport();
  280. //Rectangle rec3 = vp.getVisibleRect();
  281. if((rec1.y+((JComponent)arg0.getSource()).getHeight()) > (rec2.y+rec2.height)){
  282. vp.setViewPosition(new Point(0,(rec2.y+rec2.height)-rec1.height));
  283. }
  284. if(rec1.y < (rec2.y)){
  285. vp.setViewPosition(new Point(0,rec1.y));
  286. }
  287. }
  288. @Override
  289. public void focusLost(FocusEvent arg0) {
  290. // TODO Auto-generated method stub
  291. }
  292. }