/**
*
*/
package org.drk.ov.test.progs.view;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.border.Border;
import org.drk.ov.all.sub.SpringUtilities;
import org.drk.ov.all.sub.SpringUtilities_button;
import org.drk.ov.test.subs.Att_rec;
/**
* @author khm
*
* Inventare Verwaltung - Attribute Pflege
*
*/
public class AttPflView extends JDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
private boolean DEBUG = false;
String sPrg = this.getClass().getSimpleName();
String sPrgTxt = " - Inventar Verwaltung Attribut Plege";
String sSvol = "_PDFs\\";
String sPrgNme = sPrg + sPrgTxt;
String sIcon = "../../../images/RK.gif";
JPanel mainPane;
JPanel bearbeitungsPane;
JPanel buttonPane;
JPanel outputPane;
JTextField tF_Output;
// Ein- / Ausgabefelder
public JTextField tF_Id;
public JTextField tF_Wert;
public JTextField tF_Ts;
public JTextField tF_Wer;
// Buttons
private JButton btnAen = new JButton("ändern");
public static final String cmdAen = "chg";
private JButton btnDel = new JButton("löschen");
public static final String cmdDel = "del";
private JButton btnAbb = new JButton("abbrechen");
public static final String cmdAbb = "abbruch";
public AttPflView() {
if (DEBUG) System.out.println("<AttPflView()>" );
if (DEBUG) System.out.println( sPrgNme );
setModal(true);
setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
setSize(600,350);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setLocation( (d.width - getSize().width ) / 2,
(d.height - getSize().height) / 2 );
URL url = getClass().getResource(sIcon);
if(url != null) { setIconImage((new ImageIcon(url)).getImage()); }
setTitle("DRK OV Pfeddersheim - " + sPrgNme);
//A border that puts 10 extra pixels at the sides and
//bottom of each pane.
Border paneEdge = BorderFactory.createEmptyBorder(20,20,20,20);
mainPane = new JPanel();
mainPane.setBorder(paneEdge);
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
// - - - Bearbeitungsfläche - - -
bearbeitungsPane = new JPanel();
bearbeitungsPane.add(erzeugeBearbeitungsfläche());
mainPane.add(bearbeitungsPane,BorderLayout.NORTH);
// - - - Buttonfläche - - -
// erst einem horizontalen separator
mainPane.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.LINE_START);
buttonPane = new JPanel();
buttonPane.add(erzeugeButtonfläche());
mainPane.add(buttonPane,BorderLayout.SOUTH);
// - - - Ausgabefläche - - -
// erst einem horizontalen separator
mainPane.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.LINE_START);
outputPane = new JPanel(new SpringLayout());
outputPane.setBounds(1, 1, 600, 20);
{
tF_Output = new JTextField();
tF_Output.setEditable(false);
tF_Output.setFont(new java.awt.Font("Arial",0,12));
tF_Output.setSize(600,40);
outputPane.add(tF_Output);
//Lay out the panel.
SpringUtilities.makeCompactGrid(outputPane,
1, 1, //rows, cols
10, 10, //initX, initY
10, 10); //xPad, yPad
}
mainPane.add(outputPane,BorderLayout.NORTH);
add(mainPane);
}
/**
*
* @return
*/
protected JComponent erzeugeBearbeitungsfläche() {
if (DEBUG) System.out.println("- JComponent erzeugeBearbeitungsfläche()" );
String[] labelsStr = {"Rec-Nr", "Wert:", "Timestamp"};
int numPairs = labelsStr.length;
//Create and populate the panel.
JPanel p = new JPanel(new SpringLayout());
JLabel[] labels = new JLabel[labelsStr.length];
JComponent[] fields = new JComponent[labelsStr.length];
int fieldNum = 0;
// - 0 -
tF_Id = new JTextField(5);
tF_Id.setEditable(false);
fields[fieldNum++] = tF_Id;
// - 1 -
tF_Wert = new JTextField(5);
fields[fieldNum++] = tF_Wert;
// - 2 -
tF_Ts = new JTextField(15);
tF_Ts.setEditable(false);
fields[fieldNum++] = tF_Ts;
for (int i = 0; i < numPairs; i++) {
labels[i] = new JLabel(labelsStr[i], JLabel.TRAILING);
labels[i].setLabelFor(fields[i]);
p.add(labels[i]);
p.add(fields[i]);
}
//Lay out the panel.
SpringUtilities.makeCompactGrid(p,
labelsStr.length, 2, //rows, cols
10, 10, //initX, initY
10, 10); //xPad, yPad
return p;
}
/**
*
* @return
*/
protected JComponent erzeugeButtonfläche() {
if (DEBUG) System.out.println("- JComponent erzeugeButtonfläche()" );
//Create and populate the panel.
JPanel p = new JPanel(new SpringLayout());
btnAen.setActionCommand(cmdAen);
btnAen.setFont(new java.awt.Font("Arial",0,12));
btnAen.setSize(200,30);
p.add(btnAen);
btnAbb.setActionCommand(cmdAbb);
btnAbb.setFont(new java.awt.Font("Arial",0,12));
btnAbb.setSize(200,30);
p.add(btnAbb);
btnDel.setActionCommand(cmdDel);
btnDel.setFont(new java.awt.Font("Arial",0,12));
btnDel.setSize(200,30);
p.add(btnDel);
//Layout the panel.
SpringUtilities_button.makeCompactGrid(p,
1, 3, //rows, cols
10, 10, //initX, initY
40, 10); //xPad, yPad
return p;
}
/**
*
* @param l
*/
public void setListener(ActionListener l) {
if (DEBUG) System.out.println("- void setListener(ActionListener al) " + l.toString() );
this.btnAen.addActionListener(l);
this.btnDel.addActionListener(l);
this.btnAbb.addActionListener(l);
}
/**
*
* @param rec
*/
public void anzeigen(Att_rec rec) {
if (DEBUG) System.out.println("- void anzeigen(AttPflRec_ rec) " + rec.toString() );
tF_Id.setText(String.valueOf(rec.getWid()));
tF_Wert.setText(rec.getWert());
tF_Output.setText(rec.getOutput());
}
public String getWert() {
return tF_Wert.getText();
}
}