Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jmmv/progs/DiskCat/FormArchiver.java


1   /*
2    * DiskCat - Disk Cataloguer
3    * Copyright (C) 2002 Julio Merino <slink@unixbsd.org>
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License as
7    * published by the Free Software Foundation; either version 2 of the
8    * License, or (at your option) any later version.
9   
10   * This program is distributed in the hope that it will be useful, but
11   * WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * General Public License for more details.
14  
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18   * USA
19   */
20  
21  package jmmv.progs.DiskCat;
22  
23  import jmmv.Global;
24  import jmmv.db.LangTable;
25  import jmmv.db.InvalidDataException;
26  import jmmv.db.Register;
27  import jmmv.ui.Form;
28  import jmmv.ui.LangCompFactory;
29  
30  import java.sql.SQLException;
31  import javax.swing.JComboBox;
32  import javax.swing.JTextField;
33  
34  final class FormArchiver extends Form {
35      private JTextField fIDArchiver;
36      private JTextField fName;
37      private JComboBox  fType;
38      private JTextField fCapacity;
39  
40      private RegisterArchiver reg;
41      private LangTable lang_archtypes;
42      
43      public FormArchiver() {
44    // Initialize basic data
45    reg = new RegisterArchiver();
46    lang_archtypes = new LangTable("lang_archtypes");
47  
48    // Create form fields
49    fIDArchiver = new JTextField();
50    fName = new JTextField();
51    fCapacity = new JTextField();
52    fType = (JComboBox) LangCompFactory.getComponent(lang_archtypes, LangCompFactory.JCOMBOBOX);
53  
54    // Add form entries
55    addEntry(Global.getResources().getString("ARCHIVERS_MAINTAINMENT_IDARCH"), fIDArchiver, true);
56    addEntry(Global.getResources().getString("ARCHIVERS_MAINTAINMENT_NAME"), fName, false);
57    addEntry(Global.getResources().getString("ARCHIVERS_MAINTAINMENT_TYPE"), fType, true);
58    addEntry(Global.getResources().getString("ARCHIVERS_MAINTAINMENT_CAPACITY"), fCapacity, true);
59      }
60  
61      protected final void showRegister() {
62    ignoreEvents = true;
63    fIDArchiver.setText(new Long(reg.getIDArchiver()).toString());
64    fName.setText(reg.getName());
65    fType.setSelectedItem(lang_archtypes.getLocalOf(reg.getType()));
66    fCapacity.setText(new Integer(reg.getCapacity()).toString());
67    ignoreEvents = false;
68      }
69  
70      public final void emptyFields() {
71    reg = new RegisterArchiver();
72    reg.setNewValues();
73    showRegister();
74      }
75      
76      public final Register getRegister() throws InvalidDataException, SQLException {
77    reg = new RegisterArchiver();
78  
79    if (fIDArchiver.getText().equals(""))
80        throw new InvalidDataException(Global.getResources().getString("ARCHIVER_INVALIDDATA_IDARCH"));
81    reg.setIDArchiver(Long.parseLong(fIDArchiver.getText()));
82    reg.setName(fName.getText());
83    reg.setType(lang_archtypes.getDefaultOf((String) fType.getSelectedItem()));
84    if (fCapacity.getText().length() == 0)
85        reg.setCapacity(0);
86    else
87        reg.setCapacity(Integer.parseInt(fCapacity.getText()));
88    return reg;
89      }
90  
91      public final void setRegister(Register r) {
92    reg = (RegisterArchiver) r;
93    showRegister();
94      }
95  }
96