PageRenderTime 447ms CodeModel.GetById 151ms app.highlight 106ms RepoModel.GetById 185ms app.codeStats 1ms

/src/mpv5/ui/panels/StartPage.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 366 lines | 296 code | 53 blank | 17 comment | 7 complexity | d48a01b9204bb7e7908836e25880b591 MD5 | raw file
  1package mpv5.ui.panels;
  2
  3import java.awt.Component;
  4import java.awt.event.ActionEvent;
  5import java.io.File;
  6import java.io.FileOutputStream;
  7import java.io.InputStream;
  8import java.io.OutputStream;
  9import java.util.Arrays;
 10import java.util.Collections;
 11import java.util.Enumeration;
 12import java.util.List;
 13import java.util.Properties;
 14import javax.swing.AbstractAction;
 15import javax.swing.DefaultListModel;
 16import javax.swing.JComponent;
 17import javax.swing.JTable;
 18import javax.swing.ListModel;
 19import javax.swing.table.TableCellRenderer;
 20import mpv5.Main;
 21import mpv5.db.common.Context;
 22import mpv5.db.common.DatabaseObject;
 23import mpv5.db.objects.Contact;
 24import mpv5.globals.Constants;
 25import mpv5.globals.Headers;
 26import mpv5.globals.LocalSettings;
 27import mpv5.globals.Messages;
 28import mpv5.handler.Scheduler;
 29import mpv5.logging.Log;
 30import mpv5.ui.dialogs.Search2;
 31import mpv5.ui.frames.MPView;
 32import mpv5.utils.files.FileReaderWriter;
 33import mpv5.utils.images.MPIcon;
 34import mpv5.utils.models.MPTableModel;
 35import mpv5.utils.tables.TableFormat;
 36
 37/**
 38 *
 39 * 
 40 */
 41public class StartPage extends javax.swing.JPanel {
 42
 43    private java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
 44    /** Creates new form ListPanel */
 45    public StartPage() {
 46        initComponents();
 47        setName("startpage");
 48        jTextArea1.setText(Messages.START_MESSAGE.getValue().replace("*", ""));
 49
 50        Runnable runnable = new Runnable() {
 51
 52            public void run() {
 53                fillFiles();
 54            }
 55        };
 56        new Thread(runnable).start();
 57
 58        Runnable runnable1 = new Runnable() {
 59
 60            public void run() {
 61                syst.setModel(getSysInfo());
 62            }
 63        };
 64        new Thread(runnable1).start();
 65    }
 66
 67    /** This method is called from within the constructor to
 68     * initialize the form.
 69     * WARNING: Do NOT modify this code. The content of this method is
 70     * always regenerated by the Form Editor.
 71     *
 72     *  DatabaseObject d = DatabaseObject.getObject(Context.getCustomer());
 73    ((mpv5.db.objects.Contact) d).setisCustomer(true);
 74    mpv5.YabsViewProxy.instance().getIdentifierView().addTab(d, Messages.NEW_CUSTOMER);
 75     */
 76    @SuppressWarnings("unchecked")
 77    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 78    private void initComponents() {
 79
 80        jTabbedPane1 = new javax.swing.JTabbedPane();
 81        jScrollPane1 = new javax.swing.JScrollPane();
 82        jTextArea1 = new javax.swing.JTextArea();
 83        jPanel2 = new javax.swing.JPanel();
 84        jLabel1 = new javax.swing.JLabel();
 85        jScrollPane3 = new javax.swing.JScrollPane();
 86        jTextArea2 = new javax.swing.JTextArea();
 87        jScrollPane2 = new javax.swing.JScrollPane();
 88        licensetable = new JTable() {
 89            public Component prepareRenderer(TableCellRenderer renderer,
 90                int rowIndex, int vColIndex) {
 91                Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
 92                if (c instanceof JComponent) {
 93                    JComponent jc = (JComponent)c;
 94                    jc.setToolTipText(String.valueOf(getValueAt(rowIndex, vColIndex)));
 95                }
 96                return c;
 97            }
 98        };
 99        jPanel3 = new javax.swing.JPanel();
100        jLabel3 = new javax.swing.JLabel();
101        jScrollPane5 = new javax.swing.JScrollPane();
102        images = new javax.swing.JList();
103        jScrollPane4 = new javax.swing.JScrollPane();
104        jTextArea3 = new javax.swing.JTextArea();
105        jPanel1 = new javax.swing.JPanel();
106        jScrollPane6 = new javax.swing.JScrollPane();
107        syst = new javax.swing.JList();
108
109        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
110        setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("StartPage.border.title"))); // NOI18N
111        setName("Form"); // NOI18N
112
113        jTabbedPane1.setName("jTabbedPane1"); // NOI18N
114
115        jScrollPane1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
116        jScrollPane1.setName("jScrollPane1"); // NOI18N
117
118        jTextArea1.setColumns(20);
119        jTextArea1.setLineWrap(true);
120        jTextArea1.setRows(5);
121        jTextArea1.setText(bundle.getString("StartPage.jTextArea1.text")); // NOI18N
122        jTextArea1.setWrapStyleWord(true);
123        jTextArea1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
124        jTextArea1.setName("jTextArea1"); // NOI18N
125        jScrollPane1.setViewportView(jTextArea1);
126
127        jTabbedPane1.addTab(bundle.getString("StartPage.jScrollPane1.TabConstraints.tabTitle"), jScrollPane1); // NOI18N
128
129        jPanel2.setName("jPanel2"); // NOI18N
130        jPanel2.setLayout(new java.awt.BorderLayout());
131
132        jLabel1.setText(bundle.getString("StartPage.jLabel1.text")); // NOI18N
133        jLabel1.setName("jLabel1"); // NOI18N
134        jPanel2.add(jLabel1, java.awt.BorderLayout.PAGE_START);
135
136        jScrollPane3.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
137        jScrollPane3.setName("jScrollPane3"); // NOI18N
138
139        jTextArea2.setColumns(20);
140        jTextArea2.setLineWrap(true);
141        jTextArea2.setRows(5);
142        jTextArea2.setText(bundle.getString("StartPage.jTextArea2.text")); // NOI18N
143        jTextArea2.setWrapStyleWord(true);
144        jTextArea2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
145        jTextArea2.setName("jTextArea2"); // NOI18N
146        jScrollPane3.setViewportView(jTextArea2);
147
148        jPanel2.add(jScrollPane3, java.awt.BorderLayout.PAGE_END);
149
150        jScrollPane2.setName("jScrollPane2"); // NOI18N
151
152        licensetable.setAutoCreateRowSorter(true);
153        licensetable.setModel(new javax.swing.table.DefaultTableModel(
154            new Object [][] {
155
156            },
157            new String [] {
158
159            }
160        ));
161        licensetable.setName("licensetable"); // NOI18N
162        jScrollPane2.setViewportView(licensetable);
163
164        jPanel2.add(jScrollPane2, java.awt.BorderLayout.CENTER);
165
166        jTabbedPane1.addTab(bundle.getString("StartPage.jPanel2.TabConstraints.tabTitle"), jPanel2); // NOI18N
167
168        jPanel3.setName("jPanel3"); // NOI18N
169
170        jLabel3.setText(bundle.getString("StartPage.jLabel3.text")); // NOI18N
171        jLabel3.setName("jLabel3"); // NOI18N
172
173        jScrollPane5.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
174        jScrollPane5.setName("jScrollPane5"); // NOI18N
175
176        images.setBorder(javax.swing.BorderFactory.createEtchedBorder());
177        images.setFont(new java.awt.Font("Dialog", 0, 12));
178        images.setModel(new javax.swing.AbstractListModel() {
179            String[] strings = { "KDE Crystal Diamond Icons set compiled by Paolo Campitelli:", " ", "(Based on \"Crystal Project\", \"Human Kanpio Mod\", \"Vista Inspirate\",  \"Crystal Clear\", \"Nuove XT\", \"OSX\" , \"SnowIsh\", \"Debian Icon\", \"Firefox Alternative\" )", " ", " ", "YaBS Logo by  Jean-Christoph von Oertzen" };
180            public int getSize() { return strings.length; }
181            public Object getElementAt(int i) { return strings[i]; }
182        });
183        images.setName("images"); // NOI18N
184        jScrollPane5.setViewportView(images);
185
186        jScrollPane4.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
187        jScrollPane4.setName("jScrollPane4"); // NOI18N
188
189        jTextArea3.setColumns(20);
190        jTextArea3.setLineWrap(true);
191        jTextArea3.setRows(5);
192        jTextArea3.setText(bundle.getString("StartPage.jTextArea3.text")); // NOI18N
193        jTextArea3.setWrapStyleWord(true);
194        jTextArea3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
195        jTextArea3.setName("jTextArea3"); // NOI18N
196        jScrollPane4.setViewportView(jTextArea3);
197
198        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
199        jPanel3.setLayout(jPanel3Layout);
200        jPanel3Layout.setHorizontalGroup(
201            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
202            .addGroup(jPanel3Layout.createSequentialGroup()
203                .addContainerGap()
204                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
205                    .addGroup(jPanel3Layout.createSequentialGroup()
206                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 438, Short.MAX_VALUE)
207                        .addGap(22, 22, 22))
208                    .addGroup(jPanel3Layout.createSequentialGroup()
209                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
210                            .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
211                            .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 447, Short.MAX_VALUE))
212                        .addGap(13, 13, 13))))
213        );
214        jPanel3Layout.setVerticalGroup(
215            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
216            .addGroup(jPanel3Layout.createSequentialGroup()
217                .addContainerGap()
218                .addComponent(jLabel3)
219                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
220                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
221                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
222                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
223        );
224
225        jTabbedPane1.addTab(bundle.getString("StartPage.jPanel3.TabConstraints.tabTitle"), jPanel3); // NOI18N
226
227        jPanel1.setName("jPanel1"); // NOI18N
228
229        jScrollPane6.setName("jScrollPane6"); // NOI18N
230
231        syst.setName("syst"); // NOI18N
232        jScrollPane6.setViewportView(syst);
233
234        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
235        jPanel1.setLayout(jPanel1Layout);
236        jPanel1Layout.setHorizontalGroup(
237            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
238            .addGroup(jPanel1Layout.createSequentialGroup()
239                .addContainerGap()
240                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE)
241                .addContainerGap())
242        );
243        jPanel1Layout.setVerticalGroup(
244            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
245            .addGroup(jPanel1Layout.createSequentialGroup()
246                .addContainerGap()
247                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE)
248                .addContainerGap())
249        );
250
251        jTabbedPane1.addTab(bundle.getString("StartPage.jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N
252
253        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
254        this.setLayout(layout);
255        layout.setHorizontalGroup(
256            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
257            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 480, Short.MAX_VALUE)
258        );
259        layout.setVerticalGroup(
260            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
261            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE)
262        );
263    }// </editor-fold>//GEN-END:initComponents
264    // Variables declaration - do not modify//GEN-BEGIN:variables
265    private javax.swing.JList images;
266    private javax.swing.JLabel jLabel1;
267    private javax.swing.JLabel jLabel3;
268    private javax.swing.JPanel jPanel1;
269    private javax.swing.JPanel jPanel2;
270    private javax.swing.JPanel jPanel3;
271    private javax.swing.JScrollPane jScrollPane1;
272    private javax.swing.JScrollPane jScrollPane2;
273    private javax.swing.JScrollPane jScrollPane3;
274    private javax.swing.JScrollPane jScrollPane4;
275    private javax.swing.JScrollPane jScrollPane5;
276    private javax.swing.JScrollPane jScrollPane6;
277    private javax.swing.JTabbedPane jTabbedPane1;
278    private javax.swing.JTextArea jTextArea1;
279    private javax.swing.JTextArea jTextArea2;
280    private javax.swing.JTextArea jTextArea3;
281    private javax.swing.JTable licensetable;
282    private javax.swing.JList syst;
283    // End of variables declaration//GEN-END:variables
284
285    @SuppressWarnings("unchecked")
286    private ListModel getSysInfo() {
287
288        DefaultListModel m = new DefaultListModel();
289        m.addElement("YaBS Version: " + Constants.VERSION + " " + Constants.TITLE);
290        m.addElement("Database: " + LocalSettings.getProperty(LocalSettings.DBPATH));
291        m.addElement("Database type: " + LocalSettings.getProperty(LocalSettings.DBTYPE));
292        m.addElement("Database driver: " + LocalSettings.getProperty(LocalSettings.DBDRIVER));
293        m.addElement("Database minimal version: " + Constants.DATABASE_VERSION);
294        m.addElement("Cache directory: " + LocalSettings.getProperty(LocalSettings.CACHE_DIR));
295        m.addElement("Use OpenOffice: " + LocalSettings.getProperty(LocalSettings.OFFICE_USE));
296        m.addElement("");
297        m.addElement("");
298
299        Properties sysprops = System.getProperties();
300        Enumeration propn = sysprops.propertyNames();
301        List v = Collections.list(propn);
302        Collections.sort(v);
303        Enumeration p = Collections.enumeration(v);
304
305        while (p.hasMoreElements()) {
306            String propname = (String) p.nextElement();
307            m.addElement("System env: " + propname.toLowerCase() + ": " + System.getProperty(propname));
308        }
309
310        return m;
311    }
312
313    private void fillFiles() {
314        if (Main.INSTANTIATED) {
315            final DefaultListModel m = new DefaultListModel();
316            Runnable runnable = new Runnable() {
317
318                public void run() {
319                    try {
320                        try {
321                            File licenses = new File("licenses-list.txt");
322                            if (!licenses.exists()) {
323                                InputStream inputStream = Main.class.getResourceAsStream("/mpv5/resources/license/licenses-list");
324                                OutputStream out = new FileOutputStream(licenses);
325                                byte buf[] = new byte[1024];
326                                int len;
327                                while ((len = inputStream.read(buf)) > 0) {
328                                    out.write(buf, 0, len);
329                                }
330                                out.close();
331                                inputStream.close();
332                            }
333
334                            String[] data = (new FileReaderWriter(licenses).readLines());
335                            Arrays.sort(data);
336                            String[][] model = new String[data.length][];
337                            for (int i = 0; i < data.length; i++) {
338                                String string = data[i];
339                                model[i] = string.split(";");
340                            }
341
342                            licensetable.setModel(new MPTableModel(model, Headers.LIBRARIEST ));
343                        } catch (Exception ex) {
344                            Log.Debug(this, ex.getLocalizedMessage());
345                        }
346
347                        DefaultListModel d = new DefaultListModel();
348                        ListModel list = images.getModel();
349
350                        for (int i = 0; i < list.getSize(); i++) {
351                            d.addElement(list.getElementAt(i));
352                        }
353                        d.addElement(new MPIcon("/mpv5/resources/images/icon.png"));
354                        images.setModel(d);
355                    } catch (Exception exception) {
356                        Log.Debug(exception);
357                    }
358                }
359            };
360            new Thread(runnable).start();
361        }
362
363    }
364
365
366}