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