View Javadoc

1   package sk.stuba.fiit.foo07.genex.gui;
2   
3   import java.awt.AlphaComposite;
4   import java.awt.BorderLayout;
5   import java.awt.Color;
6   import java.awt.Graphics2D;
7   import java.awt.Rectangle;
8   import java.awt.SplashScreen;
9   import java.awt.event.ActionEvent;
10  import java.awt.event.ActionListener;
11  import java.awt.event.ComponentAdapter;
12  import java.awt.event.ComponentEvent;
13  import java.awt.event.FocusAdapter;
14  import java.awt.event.FocusEvent;
15  import java.awt.event.KeyEvent;
16  import java.awt.event.MouseAdapter;
17  import java.awt.event.MouseEvent;
18  import java.awt.event.MouseListener;
19  import java.io.File;
20  import java.io.IOException;
21  import java.io.InputStream;
22  import java.io.UnsupportedEncodingException;
23  import java.sql.Connection;
24  import java.sql.DriverManager;
25  import java.sql.SQLException;
26  import java.util.ArrayList;
27  import java.util.Properties;
28  
29  import javax.swing.ImageIcon;
30  import javax.swing.JButton;
31  import javax.swing.JFileChooser;
32  import javax.swing.JMenu;
33  import javax.swing.JMenuBar;
34  import javax.swing.JMenuItem;
35  import javax.swing.JOptionPane;
36  import javax.swing.JPopupMenu;
37  import javax.swing.JScrollPane;
38  import javax.swing.JSeparator;
39  import javax.swing.JSplitPane;
40  import javax.swing.JTabbedPane;
41  import javax.swing.JTable;
42  import javax.swing.JTextArea;
43  import javax.swing.JTextPane;
44  import javax.swing.JToolBar;
45  import javax.swing.JTree;
46  import javax.swing.KeyStroke;
47  import javax.swing.SwingConstants;
48  import javax.swing.SwingUtilities;
49  import javax.swing.ToolTipManager;
50  import javax.swing.WindowConstants;
51  import javax.swing.event.ChangeEvent;
52  import javax.swing.event.ChangeListener;
53  import javax.swing.event.ListSelectionEvent;
54  import javax.swing.event.ListSelectionListener;
55  import javax.swing.event.TreeSelectionEvent;
56  import javax.swing.event.TreeSelectionListener;
57  import javax.swing.filechooser.FileNameExtensionFilter;
58  import javax.swing.tree.DefaultMutableTreeNode;
59  import javax.swing.tree.DefaultTreeCellRenderer;
60  import javax.swing.tree.TreeNode;
61  import javax.swing.tree.TreePath;
62  import javax.swing.tree.TreeSelectionModel;
63  
64  import sk.stuba.fiit.foo07.genex.beans.Category;
65  import sk.stuba.fiit.foo07.genex.beans.Question;
66  import sk.stuba.fiit.foo07.genex.beans.Test;
67  import sk.stuba.fiit.foo07.genex.common.ConnectionHelper;
68  import sk.stuba.fiit.foo07.genex.common.DerbyDBTools;
69  import sk.stuba.fiit.foo07.genex.common.ResourceHelper;
70  import sk.stuba.fiit.foo07.genex.dao.CategoryDao;
71  import sk.stuba.fiit.foo07.genex.dao.CategoryDaoDerby;
72  import sk.stuba.fiit.foo07.genex.dao.QuestionDao;
73  import sk.stuba.fiit.foo07.genex.dao.QuestionDaoDerby;
74  import sk.stuba.fiit.foo07.genex.dao.QuestionTypeDaoDerby;
75  import sk.stuba.fiit.foo07.genex.dao.TestDao;
76  import sk.stuba.fiit.foo07.genex.dao.TestDaoDerby;
77  import sk.stuba.fiit.foo07.genex.dao.UserDao;
78  import sk.stuba.fiit.foo07.genex.dao.UserDaoDerby;
79  import sk.stuba.fiit.foo07.genex.export.Export;
80  import sk.stuba.fiit.foo07.genex.export.ExportMoodle;
81  
82  /**
83   * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
84   * Builder, which is free for non-commercial use. If Jigloo is being used
85   * commercially (ie, by a corporation, company or business for any purpose
86   * whatever) then you should purchase a license for each developer using Jigloo.
87   * Please visit www.cloudgarden.com for details. Use of Jigloo implies
88   * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
89   * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
90   * ANY CORPORATE OR COMMERCIAL PURPOSE.
91   */
92  public class GenexGUI extends javax.swing.JFrame implements
93          ListSelectionListener, ActionListener, MouseListener,
94          TreeSelectionListener, ChangeListener {
95  
96      /**
97       * 
98       */
99  
100     public static final Color COMB1_FOREGROUND_COLOR = new java.awt.Color(0, 0,
101             255);
102     public static final Color COMB1_BACKGROUND_COLOR = new java.awt.Color(255,
103             255, 190);
104     public static final Color COMB2_FOREGROUND_COLOR = new java.awt.Color(255,
105             255, 255);
106     public static final Color COMB2_BACKGROUND_COLOR = new java.awt.Color(0, 0,
107             0);
108 
109     private static final long serialVersionUID = 5089384553716451243L;
110 
111     private Connection connection;
112     private ResourceHelper resHelp;
113     private ImageIcon categoryIcon;
114     private ImageIcon questionIcon;
115     private GenexTableModel genexTableModel;
116     private DefaultMutableTreeNode rootQuestionCategoryNode;
117     private DefaultMutableTreeNode rootTestCategoryNode;
118     private CategoryDao categoryDao;
119     private QuestionDao questionDao;
120     private UserDao userDao;
121     private TestDao testDao;
122     private static String version;
123     private NewTestDialog ntd;
124 
125     private JScrollPane jScrollTab2;
126     private JScrollPane jScrollTab1;
127     private JTabbedPane jTabPane;
128     private JToolBar jToolBar;
129     private JSplitPane jSplitToolbar;
130     private JButton jBtnFind;
131     private JScrollPane jSrcollHint;
132     private JButton jBtnNewTest;
133     private JButton jBtnNewQCategory;
134     private JTextArea jTxtQuestionText;
135     private JScrollPane jScrollQuestionText;
136     private JScrollPane jScrollTable;
137     private JTree jTreeTCategories;
138     private JTree jTreeQCategories;
139     private JMenuBar jMbrMainMenu;
140     private JMenu jMnuFile;
141     private JMenu jMnuTest;
142     private JMenuItem jMtmPaste;
143     private JMenuItem jMtmFind;
144     private JSeparator jSprFind;
145     private JTextPane jTxtHint;
146     private JButton jBtnGenTest;
147     private JButton jBtnDelete;
148     private JMenuItem jMtmExport;
149     private JMenuItem jMtmExportMoodle;
150     private JSeparator jSprImportexport;
151     private JButton jBtnCopy;
152     private JButton jBtnCut;
153     private JButton jBtnPaste;
154     private JPopupMenu jTablePopup;
155     private JPopupMenu jTestCategoriesPopup;
156     private JPopupMenu jQuestionCategoriesPopupMenu;
157     private JButton jBtnNewQuestion;
158     private JTable jTblQuestions;
159     private JSplitPane jSplitCenter;
160     private JSplitPane jSplitLeftRight;
161     private JSeparator jSprSettings;
162     private JMenuItem jMtmNewQuestion;
163     private JMenuItem jMtmNewCategory;
164     private JMenuItem jMtmAbout;
165     private JSeparator jSprAbout;
166     private JMenuItem jMtmHelp;
167     private JMenuItem jMtmGenerateTest;
168     private JMenuItem jMtmNewTest;
169     private JMenuItem jMtmDelete;
170     private JSeparator jSprDelete;
171     private JSeparator jSprAddQuestions;
172     private JMenuItem jMtmCopy;
173     private JMenuItem jMtmAddQuestions;
174     private JMenuItem jMtmCut;
175     private JMenuItem jMtmEdit;
176     private JMenuItem jMtmQuit;
177     private JMenuItem jMtmSettings;
178     private JSeparator jSprQuit;
179     private JMenu jMnuHelp;
180     private JMenu jMnuEdit;
181     private JButton jBtnEdit;
182     private JButton jBtnUp;
183 
184     /**
185      * Auto-generated main method to display this JFrame
186      */
187     public static void main(String[] args) {
188         SwingUtilities.invokeLater(new Runnable() {
189             public void run() {
190 
191                 try {
192                     InputStream dataStream = getClass().getResourceAsStream(
193                             "/app.properties");
194                     Properties prop = new Properties();
195                     prop.load(dataStream);
196                     version = prop.getProperty("application.version");
197 
198                     SplashScreen splash = SplashScreen.getSplashScreen();
199                     if (splash != null) {
200                         splashScreenWrite("Starting Genex", splash);
201                     }
202                     // load derby embedded driver
203                     if (splash != null) {
204                         splashScreenWrite("Loading database driver", splash);
205                     }
206                     Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
207 
208                     if (splash != null) {
209                         splashScreenWrite("Connecting to database", splash);
210                     }
211                     // create and connect to new derby database
212                     Connection con = DriverManager.getConnection("jdbc:derby:"
213                             + "genexdb" + ";create=true");
214 
215                     if (!DerbyDBTools.databaseInitialized(con)) {
216                         if (splash != null) {
217                             splashScreenWrite("Initializing database", splash);
218                         }
219                         DerbyDBTools.runScript(con, "/ddl/ddl.sql");
220                         DerbyDBTools.runScript(con, "/ddl/commonData.sql");
221                         DerbyDBTools.loadData(con, "/data.xml");
222                     }
223                     if (splash != null) {
224                         splashScreenWrite("Ready", splash);
225                     }
226 
227                     GenexGUI inst = new GenexGUI(con);
228                     inst.setLocationRelativeTo(null);
229                     inst.setVisible(true);
230 
231                 } catch (ClassNotFoundException e) {
232                     e.printStackTrace();
233                     System.err
234                             .println("Apache derby library not found in classpath");
235                 } catch (SQLException e) {
236                     System.err.println("Connection to database failed " + e);
237                 } catch (UnsupportedEncodingException e) {
238                     System.err.println("Initialization scripts failed");
239                 } catch (IOException ex) {
240                     System.err
241                             .println("Loading basic app configuration failed");
242                 }
243 
244             }
245         });
246     }
247 
248     private static void splashScreenWrite(String text, SplashScreen splash) {
249         Graphics2D g = splash.createGraphics();
250 
251         Rectangle size = splash.getBounds();
252 
253         g.drawString(version, size.width - 150, 10);
254         g.setComposite(AlphaComposite.Clear);
255         g.setPaintMode();
256         g.setBackground(Color.WHITE);
257 
258         g.fillRect(30, size.height - 40, 200, 20);
259         g.setColor(Color.BLACK);
260         g.drawString(text, 50, size.height - 25);
261         splash.update();
262     }
263 
264     public GenexGUI(Connection con) {
265         super();
266 
267         this.connection = con;
268         ConnectionHelper.setConnection(con);
269 
270         resHelp = new ResourceHelper();
271         categoryIcon = new ImageIcon(resHelp
272                 .getResourceBytes("/icons/closedcat.png"));
273         questionIcon = new ImageIcon(resHelp
274                 .getResourceBytes("/icons/questionicon.png"));
275 
276         categoryDao = new CategoryDaoDerby(connection);
277         questionDao = new QuestionDaoDerby(connection);
278         userDao = new UserDaoDerby(connection);
279         testDao = new TestDaoDerby(connection);
280 
281         // kategorie otazok
282         //TODO
283         //pridane odchytavanie vynimiek (palo)
284         try {
285             Category root = categoryDao.getRootCategories().get(0);
286             rootQuestionCategoryNode = new DefaultMutableTreeNode(root);
287             ArrayList<Category> cats = null; //pozor mozna chyba
288 
289             cats = categoryDao.getCategoriesByParentID(root.getCategoryID());
290 
291             for (Category c : cats) {
292                 DefaultMutableTreeNode node = new DefaultMutableTreeNode(c);
293                 rootQuestionCategoryNode.add(node);
294                 if (categoryDao.hasSubcategories(c.getCategoryID()))
295                     node.add(new DefaultMutableTreeNode("camuflage"));
296             }
297 
298             root = categoryDao.getRootTestCategories().get(0);
299             rootTestCategoryNode = new DefaultMutableTreeNode(root);
300             cats = categoryDao
301                     .getTestCategoriesByParentID(root.getCategoryID());
302             for (Category c : cats) {
303                 DefaultMutableTreeNode node = new DefaultMutableTreeNode(c);
304                 rootTestCategoryNode.add(node);
305                 if (categoryDao.hasTestSubcategories(c.getCategoryID())
306                         || testDao.getTestsByCategoryID(c.getCategoryID())
307                                 .size() > 0)
308                     node.add(new DefaultMutableTreeNode("camuflage"));
309             }
310             ArrayList<Test> tests = testDao.getTestsByCategoryID(root
311                     .getCategoryID());
312             for (Test test : tests)
313                 rootTestCategoryNode.add(new DefaultMutableTreeNode(test));
314 
315             genexTableModel = new GenexTableModel(categoryIcon, questionIcon,
316                     categoryDao, questionDao, new QuestionTypeDaoDerby(
317                             connection));
318         } catch (Exception e) {
319         }
320         initGUI();
321         ntd = new NewTestDialog();
322         jTreeQCategories.setSelectionRow(0);
323         jTreeTCategories.setSelectionRow(0);
324         setTreesIcons();
325         ToolTipManager.sharedInstance().unregisterComponent(jTblQuestions);
326         ToolTipManager.sharedInstance().unregisterComponent(
327                 jTblQuestions.getTableHeader());
328 
329         initPopups();
330     }
331 
332     private void initPopups() {
333         // TODO doplnit init popup okien
334         JMenuItem item;
335 
336         item = new JMenuItem(jMtmNewCategory.getText());
337         item.addActionListener(this);
338         jTablePopup.add(item);
339         item = new JMenuItem(jMtmNewQuestion.getText());
340         item.addActionListener(this);
341         jTablePopup.add(item);
342 
343         jTablePopup.add(new JSeparator());
344 
345         item = new JMenuItem(jMtmEdit.getText());
346         item.addActionListener(this);
347         jTablePopup.add(item);
348         item = new JMenuItem(jMtmCut.getText());
349         item.addActionListener(this);
350         jTablePopup.add(item);
351         item = new JMenuItem(jMtmCopy.getText());
352         item.addActionListener(this);
353         jTablePopup.add(item);
354         item = new JMenuItem(jMtmPaste.getText());
355         item.addActionListener(this);
356         jTablePopup.add(item);
357         item = new JMenuItem(jMtmDelete.getText());
358         item.addActionListener(this);
359         jTablePopup.add(item);
360 
361         jTablePopup.add(new JSeparator());
362 
363         item = new JMenuItem("Pridať do testu");
364         item.addActionListener(this);
365         jTablePopup.add(item);
366     }
367 
368     private void setTreesIcons() {
369         DefaultTreeCellRenderer cellRenderer = new DefaultTreeCellRenderer();
370         ImageIcon icon1 = new ImageIcon(resHelp
371                 .getResourceBytes("/icons/closedcat.png"));
372         ImageIcon icon2 = new ImageIcon(resHelp
373                 .getResourceBytes("/icons/opencat.png"));
374         ImageIcon icon3 = new ImageIcon(resHelp
375                 .getResourceBytes("/icons/leafcat.png"));
376         if (icon1 != null && icon2 != null && icon3 != null) {
377             cellRenderer.setClosedIcon(icon1);
378             cellRenderer.setOpenIcon(icon2);
379             cellRenderer.setLeafIcon(icon3);
380         }
381 
382         jTreeQCategories.setCellRenderer(cellRenderer);
383 
384         DefaultTreeCellRenderer cellRenderer2 = new TreeIconRenderer();
385         icon1 = new ImageIcon(resHelp.getResourceBytes("/icons/closedcat.png"));
386         icon2 = new ImageIcon(resHelp.getResourceBytes("/icons/opencat.png"));
387         icon3 = new ImageIcon(resHelp.getResourceBytes("/icons/leaftest.png"));
388         if (icon1 != null && icon2 != null && icon3 != null) {
389             cellRenderer2.setClosedIcon(icon1);
390             cellRenderer2.setOpenIcon(icon2);
391             cellRenderer2.setLeafIcon(icon3);
392         }
393 
394         jTreeTCategories.setCellRenderer(cellRenderer2);
395     }
396 
397     private void initGUI() {
398 
399         try {
400             {
401                 this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
402                 this.setTitle("GenEx - Tvorba testov");
403                 this.addComponentListener(new ComponentAdapter() {
404                     @Override
405                     public void componentResized(ComponentEvent evt) {
406                         jSplitCenter.setDividerLocation(0.75);
407                     }
408                 });
409                 this.addFocusListener(new FocusAdapter() {
410                     @Override
411                     public void focusGained(FocusEvent e) {
412                         genexTableModel.fireTableDataChanged();
413                     }
414                 });
415             }
416             {
417                 QuestionCategoryTreeListener listener1 = new QuestionCategoryTreeListener(
418                         connection, genexTableModel);
419                 jSplitToolbar = new JSplitPane();
420                 getContentPane().add(jSplitToolbar, BorderLayout.CENTER);
421                 jSplitToolbar.setOrientation(JSplitPane.VERTICAL_SPLIT);
422                 {
423                     jSplitLeftRight = new JSplitPane();
424                     jSplitToolbar.add(jSplitLeftRight, JSplitPane.RIGHT);
425                     jSplitLeftRight.setPreferredSize(new java.awt.Dimension(
426                             875, 472));
427                     {
428                         jTabPane = new JTabbedPane();
429                         jTabPane.addChangeListener(this);
430                         jSplitLeftRight.add(jTabPane, JSplitPane.LEFT);
431                         jTabPane.setPreferredSize(new java.awt.Dimension(159,
432                                 488));
433                         {
434                             jScrollTab1 = new JScrollPane();
435                             jTabPane.addTab("Otázky", null, jScrollTab1, null);
436                             {
437                                 jTreeQCategories = new JTree(
438                                         rootQuestionCategoryNode);
439                                 jScrollTab1.setViewportView(jTreeQCategories);
440                                 jTreeQCategories.setShowsRootHandles(true);
441                                 jTreeQCategories.setRootVisible(true);
442                                 jTreeQCategories
443                                         .setToolTipText("Kategórie otázok");
444                                 jTreeQCategories
445                                         .getSelectionModel()
446                                         .setSelectionMode(
447                                                 TreeSelectionModel.SINGLE_TREE_SELECTION);
448                                 jTreeQCategories
449                                         .setBackground(new java.awt.Color(255,
450                                                 255, 240));
451                                 jTreeQCategories.setDragEnabled(true);
452                                 {
453                                     jQuestionCategoriesPopupMenu = new JPopupMenu();
454                                     setComponentPopupMenu(jTreeQCategories,
455                                             jQuestionCategoriesPopupMenu);
456                                 }
457                                 jTreeQCategories
458                                         .addTreeSelectionListener(listener1);
459                                 jTreeQCategories
460                                         .addTreeWillExpandListener(listener1);
461                             }
462                         }
463                         {
464                             jScrollTab2 = new JScrollPane();
465                             jTabPane.addTab("Testy", null, jScrollTab2, null);
466                             {
467                                 jTreeTCategories = new JTree(
468                                         rootTestCategoryNode);
469                                 jScrollTab2.setViewportView(jTreeTCategories);
470                                 jTreeTCategories.setShowsRootHandles(true);
471                                 jTreeTCategories.setRootVisible(true);
472                                 jTreeTCategories
473                                         .setToolTipText("Kategórie testov");
474                                 jTreeTCategories
475                                         .setPreferredSize(new java.awt.Dimension(
476                                                 151, 392));
477                                 jTreeTCategories
478                                         .getSelectionModel()
479                                         .setSelectionMode(
480                                                 TreeSelectionModel.SINGLE_TREE_SELECTION);
481                                 jTreeTCategories
482                                         .setBackground(new java.awt.Color(255,
483                                                 255, 240));
484                                 jTreeTCategories
485                                         .addMouseListener(new MouseAdapter() {
486                                             @Override
487                                             public void mouseClicked(
488                                                     MouseEvent evt) {
489                                                 jTreeTCategoriesMouseClicked(evt);
490                                             }
491                                         });
492                                 {
493                                     jTestCategoriesPopup = new JPopupMenu();
494                                     setComponentPopupMenu(jTreeTCategories,
495                                             jTestCategoriesPopup);
496                                 }
497                                 TestCategoryTreeListener listener = new TestCategoryTreeListener(
498                                         connection);
499                                 jTreeTCategories
500                                         .addTreeWillExpandListener(listener);
501                                 jTreeTCategories.addTreeSelectionListener(this);
502                             }
503                         }
504                     }
505                     {
506                         jSplitCenter = new JSplitPane();
507                         jSplitLeftRight.add(jSplitCenter, JSplitPane.RIGHT);
508                         jSplitCenter.setOrientation(JSplitPane.VERTICAL_SPLIT);
509                         {
510                             jScrollTable = new JScrollPane();
511                             jSplitCenter.add(jScrollTable, JSplitPane.LEFT);
512                             jScrollTable
513                                     .setPreferredSize(new java.awt.Dimension(
514                                             694, 340));
515                             jScrollTable.getViewport().setBackground(
516                                     new Color(255, 255, 240));
517                             {
518                                 jTablePopup = new JPopupMenu();
519                                 setComponentPopupMenu(jScrollTable, jTablePopup);
520                             }
521                             {
522                                 jTblQuestions = new JTable();
523                                 jScrollTable.setViewportView(jTblQuestions);
524                                 jTblQuestions.setModel(genexTableModel);
525                                 jTblQuestions.setShowGrid(false);
526                                 jTblQuestions.setBackground(new java.awt.Color(
527                                         255, 255, 240));
528                                 jTblQuestions
529                                         .setToolTipText("Otázky a kategórie");
530                                 //jTblQuestions.setAutoCreateRowSorter(true);
531                                 jTblQuestions.setDragEnabled(true);
532 
533                                 jTblQuestions
534                                         .getColumnModel()
535                                         .getColumn(0)
536                                         .setCellRenderer(new IconCellRenderer());
537                                 jTblQuestions.getColumnModel().getColumn(0)
538                                         .setMinWidth(20);
539                                 jTblQuestions.getColumnModel().getColumn(0)
540                                         .setMaxWidth(20);
541                                 jTblQuestions.getColumnModel().getColumn(0)
542                                         .setPreferredWidth(20);
543                                 jTblQuestions.getColumnModel().getColumn(0)
544                                         .setResizable(false);
545                                 jTblQuestions.getColumnModel().getColumn(1)
546                                         .setPreferredWidth(320);
547                                 jTblQuestions.getColumnModel().getColumn(2)
548                                         .setPreferredWidth(10);
549                                 jTblQuestions.getColumnModel().getColumn(2)
550                                         .setCellRenderer(
551                                                 new ColoredTextRenderer());
552                                 jTblQuestions.getColumnModel().getColumn(3)
553                                         .setPreferredWidth(100);
554                                 jTblQuestions.getColumnModel().getColumn(3)
555                                         .setCellRenderer(
556                                                 new ProgressCellRenderer());
557                                 jTblQuestions.getColumnModel().getColumn(4)
558                                         .setPreferredWidth(100);
559                                 jTblQuestions.getColumnModel().getColumn(4)
560                                         .setCellRenderer(
561                                                 new ColoredTextRenderer());
562                                 jTblQuestions.getSelectionModel()
563                                         .addListSelectionListener(this);
564                                 listener1.setGenexTable(jTblQuestions);
565                                 jTblQuestions.addMouseListener(this);
566                                 {
567                                     setComponentPopupMenu(jTblQuestions,
568                                             jTablePopup);
569                                 }
570                             }
571                         }
572                         {
573                             jScrollQuestionText = new JScrollPane();
574                             jSplitCenter.add(jScrollQuestionText,
575                                     JSplitPane.RIGHT);
576                             jScrollQuestionText
577                                     .setPreferredSize(new java.awt.Dimension(
578                                             647, 103));
579                             {
580                                 jTxtQuestionText = new JTextArea();
581                                 jScrollQuestionText
582                                         .setViewportView(jTxtQuestionText);
583                                 jTxtQuestionText.setText("Text otázky.");
584                                 jTxtQuestionText
585                                         .setBackground(new java.awt.Color(255,
586                                                 255, 240));
587                                 jTxtQuestionText
588                                         .setForeground(new java.awt.Color(100,
589                                                 0, 0));
590                                 jTxtQuestionText
591                                         .setToolTipText("Text vybranej otázky");
592                                 jTxtQuestionText.setEditable(false);
593                                 jTxtQuestionText.setDragEnabled(true);
594                             }
595                         }
596                     }
597                 }
598                 {
599                     jToolBar = new JToolBar();
600                     jSplitToolbar.add(jToolBar, JSplitPane.LEFT);
601                     jToolBar.setPreferredSize(new java.awt.Dimension(875, 34));
602                     jToolBar.setFloatable(false);
603                     {
604                         jBtnNewQCategory = new JButton();
605                         jToolBar.add(jBtnNewQCategory);
606                         jBtnNewQCategory.setIcon(new ImageIcon(resHelp
607                                 .getResourceBytes("/icons/newcat.png")));
608                         jBtnNewQCategory
609                                 .setVerticalTextPosition(SwingConstants.BOTTOM);
610                         jBtnNewQCategory
611                                 .setHorizontalTextPosition(SwingConstants.CENTER);
612                         jBtnNewQCategory.setToolTipText("Nová kategória");
613                         jBtnNewQCategory.setActionCommand("Nová kategória");
614                         jBtnNewQCategory.addActionListener(this);
615                     }
616                     {
617                         jBtnNewQuestion = new JButton();
618                         jToolBar.add(jBtnNewQuestion);
619                         jBtnNewQuestion.setIcon(new ImageIcon(resHelp
620                                 .getResourceBytes("/icons/newquestion.png")));
621                         jBtnNewQuestion
622                                 .setVerticalTextPosition(SwingConstants.BOTTOM);
623                         jBtnNewQuestion
624                                 .setHorizontalTextPosition(SwingConstants.CENTER);
625                         jBtnNewQuestion.setToolTipText("Nová otázka");
626                         jBtnNewQuestion.setActionCommand("Nová otázka");
627                         jBtnNewQuestion.addActionListener(this);
628                     }
629                     {
630                         jBtnEdit = new JButton();
631                         jToolBar.add(jBtnEdit);
632                         jBtnEdit.setIcon(new ImageIcon(resHelp
633                                 .getResourceBytes("/icons/edit.png")));
634                         jBtnEdit.setVerticalTextPosition(SwingConstants.BOTTOM);
635                         jBtnEdit
636                                 .setHorizontalTextPosition(SwingConstants.CENTER);
637                         jBtnEdit.setToolTipText("Upraviť");
638                         jBtnEdit.setActionCommand("Upraviť");
639                         jBtnEdit.addActionListener(this);
640                     }
641                     {
642                         jBtnCut = new JButton();
643                         jToolBar.add(jBtnCut);
644                         jBtnCut.setIcon(new ImageIcon(resHelp
645                                 .getResourceBytes("/icons/cut.png")));
646                         jBtnCut.setVerticalTextPosition(SwingConstants.BOTTOM);
647                         jBtnCut
648                                 .setHorizontalTextPosition(SwingConstants.CENTER);
649                         jBtnCut.setToolTipText("Vystrihnúť");
650                         jBtnCut.setActionCommand("Vystrihnúť");
651                         jBtnCut.addActionListener(this);
652                     }
653                     {
654                         jBtnCopy = new JButton();
655                         jToolBar.add(jBtnCopy);
656                         jBtnCopy.setIcon(new ImageIcon(resHelp
657                                 .getResourceBytes("/icons/copy.png")));
658                         jBtnCopy.setVerticalTextPosition(SwingConstants.BOTTOM);
659                         jBtnCopy
660                                 .setHorizontalTextPosition(SwingConstants.CENTER);
661                         jBtnCopy.setToolTipText("Kopírovať");
662                         jBtnCopy.setActionCommand("Kopírovať");
663                         jBtnCopy.addActionListener(this);
664                     }
665                     {
666                         jBtnPaste = new JButton();
667                         jToolBar.add(jBtnPaste);
668                         jBtnPaste.setIcon(new ImageIcon(resHelp
669                                 .getResourceBytes("/icons/paste.png")));
670                         jBtnPaste
671                                 .setVerticalTextPosition(SwingConstants.BOTTOM);
672                         jBtnPaste
673                                 .setHorizontalTextPosition(SwingConstants.CENTER);
674                         jBtnPaste.setToolTipText("Vložiť");
675                         jBtnPaste.setActionCommand("Vložiť");
676                         jBtnPaste.addActionListener(this);
677                     }
678                     {
679                         jBtnDelete = new JButton();
680                         jToolBar.add(jBtnDelete);
681                         jBtnDelete.setIcon(new ImageIcon(resHelp
682                                 .getResourceBytes("/icons/delete.png")));
683                         jBtnDelete
684                                 .setVerticalTextPosition(SwingConstants.BOTTOM);
685                         jBtnDelete
686                                 .setHorizontalTextPosition(SwingConstants.CENTER);
687                         jBtnDelete.setToolTipText("Odstrániť");
688                         jBtnDelete.setActionCommand("Odstrániť");
689                         jBtnDelete.addActionListener(this);
690                     }
691                     {
692                         jBtnNewTest = new JButton();
693                         jToolBar.add(jBtnNewTest);
694                         jBtnNewTest.setIcon(new ImageIcon(resHelp
695                                 .getResourceBytes("/icons/newtest.png")));
696                         jBtnNewTest
697                                 .setVerticalTextPosition(SwingConstants.BOTTOM);
698                         jBtnNewTest
699                                 .setHorizontalTextPosition(SwingConstants.CENTER);
700                         jBtnNewTest.setToolTipText("Nový test");
701                         jBtnNewTest.setActionCommand("Nový");
702                         jBtnNewTest.addActionListener(this);
703                     }
704                     {
705                         jBtnGenTest = new JButton();
706                         jToolBar.add(jBtnGenTest);
707                         jBtnGenTest.setIcon(new ImageIcon(resHelp
708                                 .getResourceBytes("/icons/gentest.png")));
709                         jBtnGenTest
710                                 .setVerticalTextPosition(SwingConstants.BOTTOM);
711                         jBtnGenTest
712                                 .setHorizontalTextPosition(SwingConstants.CENTER);
713                         jBtnGenTest.setToolTipText("Generova\u0165 test");
714                         jBtnGenTest.setActionCommand("Generova\u0165");
715                         jBtnGenTest.addActionListener(this);
716                     }
717                     {
718                         jBtnUp = new JButton();
719                         jToolBar.add(jBtnUp);
720                         jBtnUp.setIcon(new ImageIcon(resHelp
721                                 .getResourceBytes("/icons/bigup.png")));
722                         jBtnUp.setVerticalTextPosition(SwingConstants.BOTTOM);
723                         jBtnUp.setHorizontalTextPosition(SwingConstants.CENTER);
724                         jBtnUp.setToolTipText("O úroveň vyššie");
725                         jBtnUp.setActionCommand("O úroveň vyššie");
726                         jBtnUp.addActionListener(this);
727                     }
728                     {
729                         jSrcollHint = new JScrollPane();
730                         jToolBar.add(jSrcollHint);
731                         {
732                             jTxtHint = new JTextPane();
733                             jSrcollHint.setViewportView(jTxtHint);
734                             hint("Info: Ukoncit aplikaciu mozete kliknutim na krizik v pravom hornom rohu.");
735                             jTxtHint.setBackground(COMB1_BACKGROUND_COLOR);
736                             jTxtHint.setForeground(COMB1_FOREGROUND_COLOR);
737                             jTxtHint.setToolTipText("Rýchla pomoc");
738                             jTxtHint.setEditable(false);
739                         }
740                     }
741                     {
742                         jBtnFind = new JButton();
743                         jToolBar.add(jBtnFind);
744                         jBtnFind.setIcon(new ImageIcon(resHelp
745                                 .getResourceBytes("/icons/find.png")));
746                         jBtnFind.setVerticalTextPosition(SwingConstants.BOTTOM);
747                         jBtnFind
748                                 .setHorizontalTextPosition(SwingConstants.CENTER);
749                         jBtnFind.setToolTipText("H\u013eada\u0165");
750                         jBtnFind.setActionCommand("H\u013eada\u0165");
751                         jBtnFind.addActionListener(this);
752                     }
753                 }
754             }
755             this.setSize(885, 611);
756             // START >> jMbrMainMenu
757             jMbrMainMenu = new JMenuBar();
758             setJMenuBar(jMbrMainMenu);
759             jMbrMainMenu.setToolTipText("Hlavná ponuka");
760             // START >> jMnuSubor
761             jMnuFile = new JMenu();
762             jMbrMainMenu.add(jMnuFile);
763             jMnuFile.setText("Súbor");
764             jMnuFile.setMnemonic(java.awt.event.KeyEvent.VK_S);
765             // START >> jMtmNovaKategoria
766             jMtmNewCategory = new JMenuItem();
767             jMnuFile.add(jMtmNewCategory);
768             jMtmNewCategory.setText("Nová kategória");
769             jMtmNewCategory.setActionCommand("Nová kategória");
770             jMtmNewCategory.addActionListener(this);
771             jMtmNewCategory.setIcon(new ImageIcon(resHelp
772                     .getResourceBytes("/icons/menunewcat.png")));
773             jMtmNewCategory.setAccelerator(KeyStroke.getKeyStroke(
774                     KeyEvent.VK_K, ActionEvent.CTRL_MASK));
775             jMtmNewCategory.setMnemonic(java.awt.event.KeyEvent.VK_K);
776             // END << jMtmNovaKategoria
777             // START >> jMtmNovaOtazka
778             jMtmNewQuestion = new JMenuItem();
779             jMnuFile.add(jMtmNewQuestion);
780             jMtmNewQuestion.setText("Nová otázka");
781             jMtmNewQuestion.setActionCommand("Nová otázka");
782             jMtmNewQuestion.addActionListener(this);
783             jMtmNewQuestion.setIcon(new ImageIcon(resHelp
784                     .getResourceBytes("/icons/menunewquestion.png")));
785             jMtmNewQuestion.setAccelerator(KeyStroke.getKeyStroke(
786                     KeyEvent.VK_O, ActionEvent.CTRL_MASK));
787             jMtmNewQuestion.setMnemonic(java.awt.event.KeyEvent.VK_O);
788             // END << jMtmNovaOtazka
789             {
790                 jSprImportexport = new JSeparator();
791                 jMnuFile.add(jSprImportexport);
792             }
793             {
794                 jMtmExport = new JMenuItem();
795                 jMnuFile.add(jMtmExport);
796                 jMtmExport.setText("Export testu do LaTeXu");
797                 jMtmExport.setActionCommand("Export testu");
798                 jMtmExport.addActionListener(this);
799                 jMtmExport.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,
800                         ActionEvent.CTRL_MASK));
801                 jMtmExport.setMnemonic(java.awt.event.KeyEvent.VK_E);
802             }
803             {
804                 jMtmExportMoodle = new JMenuItem();
805                 jMnuFile.add(jMtmExportMoodle);
806                 jMtmExportMoodle.setText("Export testu do Moodle");
807                 jMtmExportMoodle.setActionCommand("Export testu do Moodle");
808                 jMtmExportMoodle.addActionListener(this);
809                 jMtmExportMoodle.setAccelerator(KeyStroke.getKeyStroke(
810                         KeyEvent.VK_M, ActionEvent.CTRL_MASK));
811                 jMtmExportMoodle.setMnemonic(java.awt.event.KeyEvent.VK_M);
812             }
813             // START >> jSprNastavenia
814             jSprSettings = new JSeparator();
815             jMnuFile.add(jSprSettings);
816             // END << jSprNastavenia
817             // START >> jMtmNastavenia
818             jMtmSettings = new JMenuItem();
819             jMnuFile.add(jMtmSettings);
820             jMtmSettings.setText("Nastavenia");
821             jMtmSettings.setActionCommand("Nastavenia");
822             jMtmSettings.addActionListener(this);
823             jMtmSettings.setIcon(new ImageIcon(resHelp
824                     .getResourceBytes("/icons/menusettings.png")));
825             jMtmSettings.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,
826                     ActionEvent.CTRL_MASK));
827             jMtmSettings.setMnemonic(java.awt.event.KeyEvent.VK_N);
828             // END << jMtmNastavenia
829             // START >> jSprUkoncit
830             jSprQuit = new JSeparator();
831             jMnuFile.add(jSprQuit);
832             // END << jSprUkoncit
833             // START >> jMtmUkoncit
834             jMtmQuit = new JMenuItem();
835             jMnuFile.add(jMtmQuit);
836             jMtmQuit.setText("Ukon\u010di\u0165");
837             jMtmQuit.setActionCommand("Ukon\u010di\u0165");
838             jMtmQuit.addActionListener(this);
839             jMtmQuit.setIcon(new ImageIcon(resHelp
840                     .getResourceBytes("/icons/menuexit.png")));
841             jMtmQuit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
842                     ActionEvent.CTRL_MASK));
843             jMtmQuit.setMnemonic(java.awt.event.KeyEvent.VK_U);
844             // END << jMtmUkoncit
845             // END << jMnuSubor
846             // START >> jMnuUpravy
847             jMnuEdit = new JMenu();
848             jMbrMainMenu.add(jMnuEdit);
849             jMnuEdit.setText("Úpravy");
850             jMnuEdit.setMnemonic(java.awt.event.KeyEvent.VK_P);
851             // START >> jMtmFind
852             jMtmEdit = new JMenuItem();
853             jMnuEdit.add(jMtmEdit);
854             jMtmEdit.setText("Upraviť");
855             jMtmEdit.setActionCommand("Upraviť");
856             jMtmEdit.addActionListener(this);
857             jMtmEdit.setIcon(new ImageIcon(resHelp
858                     .getResourceBytes("/icons/menuedit.png")));
859             jMtmEdit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D,
860                     ActionEvent.CTRL_MASK));
861             jMtmEdit.setMnemonic(java.awt.event.KeyEvent.VK_U);
862             // END << jMtmFind
863             // START >> jSprFind
864             jSprFind = new JSeparator();
865             jMnuEdit.add(jSprFind);
866             // END << jSprFind
867             // START >> jMtmVystrihnut
868             jMtmCut = new JMenuItem();
869             jMnuEdit.add(jMtmCut);
870             jMtmCut.setText("Vystrihnúť");
871             jMtmCut.setActionCommand("Vystrihnúť");
872             jMtmCut.addActionListener(this);
873             jMtmCut.setIcon(new ImageIcon(resHelp
874                     .getResourceBytes("/icons/menucut.png")));
875             jMtmCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
876                     ActionEvent.CTRL_MASK));
877             jMtmCut.setMnemonic(java.awt.event.KeyEvent.VK_S);
878             // END << jMtmVystrihnut
879             // START >> jMtmKopirovat
880             jMtmCopy = new JMenuItem();
881             jMnuEdit.add(jMtmCopy);
882             jMtmCopy.setText("Kopírovať");
883             jMtmCopy.setActionCommand("Kopírovať");
884             jMtmCopy.addActionListener(this);
885             jMtmCopy.setIcon(new ImageIcon(resHelp
886                     .getResourceBytes("/icons/menucopy.png")));
887             jMtmCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
888                     ActionEvent.CTRL_MASK));
889             jMtmCopy.setMnemonic(java.awt.event.KeyEvent.VK_K);
890             // END << jMtmKopirovat
891             // START >> jMtmVlozit
892             jMtmPaste = new JMenuItem();
893             jMnuEdit.add(jMtmPaste);
894             jMtmPaste.setText("Vložiť");
895             jMtmPaste.setActionCommand("Vložiť");
896             jMtmPaste.addActionListener(this);
897             jMtmPaste.setIcon(new ImageIcon(resHelp
898                     .getResourceBytes("/icons/menupaste.png")));
899             jMtmPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
900                     ActionEvent.CTRL_MASK));
901             jMtmPaste.setMnemonic(java.awt.event.KeyEvent.VK_V);
902             // END << jMtmVlozit
903             // START >> jMtmOdstranit
904             jMtmDelete = new JMenuItem();
905             jMnuEdit.add(jMtmDelete);
906             jMtmDelete.setText("Odstrániť");
907             jMtmDelete.setActionCommand("Odstrániť");
908             jMtmDelete.addActionListener(this);
909             jMtmDelete.setIcon(new ImageIcon(resHelp
910                     .getResourceBytes("/icons/menudelete.png")));
911             jMtmDelete.setAccelerator(KeyStroke.getKeyStroke(
912                     KeyEvent.VK_DELETE, 0));
913             jMtmDelete.setMnemonic(java.awt.event.KeyEvent.VK_O);
914             // END << jMtmOdstranit
915             // START >> jSprVymazat
916             jSprDelete = new JSeparator();
917             jMnuEdit.add(jSprDelete);
918             // END << jSprVymazat
919             // START >> jMtmFind
920             jMtmFind = new JMenuItem();
921             jMnuEdit.add(jMtmFind);
922             jMtmFind.setText("H\u013eada\u0165");
923             jMtmFind.setActionCommand("H\u013eada\u0165");
924             jMtmFind.addActionListener(this);
925             jMtmFind.setIcon(new ImageIcon(resHelp
926                     .getResourceBytes("/icons/menusearch.png")));
927             jMtmFind.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,
928                     ActionEvent.CTRL_MASK));
929             jMtmFind.setMnemonic(java.awt.event.KeyEvent.VK_H);
930             // END << jMtmFind
931             // END << jMnuUpravy
932             // START >> jMnuTest
933             jMnuTest = new JMenu();
934             jMbrMainMenu.add(jMnuTest);
935             jMnuTest.setText("Test");
936             jMnuTest.setMnemonic(java.awt.event.KeyEvent.VK_T);
937             // START >> jMtmVytvorit
938             jMtmNewTest = new JMenuItem();
939             jMnuTest.add(jMtmNewTest);
940             jMtmNewTest.setText("Nový");
941             jMtmNewTest.setActionCommand("Nový");
942             jMtmNewTest.addActionListener(this);
943             jMtmNewTest.setIcon(new ImageIcon(resHelp
944                     .getResourceBytes("/icons/menucreatetest.png")));
945             jMtmNewTest.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
946                     ActionEvent.CTRL_MASK));
947             jMtmNewTest.setMnemonic(java.awt.event.KeyEvent.VK_N);
948             // END << jMtmVytvorit
949             // START >> jMnuVygenerovat
950             jMtmGenerateTest = new JMenuItem();
951             jMnuTest.add(jMtmGenerateTest);
952             jMtmGenerateTest.setText("Generovať");
953             jMtmGenerateTest.setActionCommand("Generovať");
954             jMtmGenerateTest.addActionListener(this);
955             jMtmGenerateTest.setIcon(new ImageIcon(resHelp
956                     .getResourceBytes("/icons/menugentest.png")));
957             jMtmGenerateTest.setAccelerator(KeyStroke.getKeyStroke(
958                     KeyEvent.VK_G, ActionEvent.CTRL_MASK));
959             jMtmGenerateTest.setMnemonic(java.awt.event.KeyEvent.VK_G);
960             // END << jMnuVygenerovat
961             //START >> jSprAddQuestions
962             jSprAddQuestions = new JSeparator();
963             jMnuTest.add(jSprAddQuestions);
964             // END << jSprAddQuestions
965             // START >> jMtmAddQuestions
966             jMtmAddQuestions = new JMenuItem();
967             jMnuTest.add(jMtmAddQuestions);
968             jMtmAddQuestions.setText("Pridať otázky do testu");
969             jMtmAddQuestions.setActionCommand("Pridať do testu");
970             jMtmAddQuestions.addActionListener(this);
971             jMtmAddQuestions.setAccelerator(KeyStroke.getKeyStroke(
972                     KeyEvent.VK_R, ActionEvent.CTRL_MASK));
973             jMtmAddQuestions.setMnemonic(java.awt.event.KeyEvent.VK_P);
974             // END << jMtmAddQuestions
975             // END << jMnuTest
976             // START >> jMnuNapoveda
977             jMnuHelp = new JMenu();
978             jMbrMainMenu.add(jMnuHelp);
979             jMnuHelp.setText("Nápoveda");
980             jMnuHelp.setMnemonic(java.awt.event.KeyEvent.VK_N);
981             // START >> jMtmPomoc
982             jMtmHelp = new JMenuItem();
983             jMnuHelp.add(jMtmHelp);
984             jMtmHelp.setText("Pomoc");
985             jMtmHelp.setActionCommand("Pomoc");
986             jMtmHelp.addActionListener(this);
987             jMtmHelp.setIcon(new ImageIcon(resHelp
988                     .getResourceBytes("/icons/menuhelp.png")));
989             jMtmHelp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
990             jMtmHelp.setMnemonic(java.awt.event.KeyEvent.VK_P);
991             // END << jMtmPomoc
992             // START >> JSprOPrograme
993             jSprAbout = new JSeparator();
994             jMnuHelp.add(jSprAbout);
995             // END << JSprOPrograme
996             // START >> jMtmOPrograme
997             jMtmAbout = new JMenuItem();
998             jMnuHelp.add(jMtmAbout);
999             jMtmAbout.setText("O programe ...");
1000             jMtmAbout.setActionCommand("O programe ...");
1001             jMtmAbout.addActionListener(this);
1002             jMtmAbout.setIcon(new ImageIcon(resHelp
1003                     .getResourceBytes("/icons/menuabout.png")));
1004             jMtmAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1,
1005                     ActionEvent.SHIFT_MASK));
1006             jMtmAbout.setMnemonic(java.awt.event.KeyEvent.VK_O);
1007             // END << jMtmOPrograme
1008             // END << jMnuNapoveda
1009             // END << jMbrMainMenu
1010         } catch (Exception e) {
1011             e.printStackTrace();
1012         }
1013     }
1014 
1015     /**
1016      * @return the jTreeTCategories
1017      */
1018     public JTree getJTreeTCategories() {
1019         return jTreeTCategories;
1020     }
1021 
1022     /**
1023      * @return the jTreeQCategories
1024      */
1025     public JTree getJTreeQCategories() {
1026         return jTreeQCategories;
1027     }
1028 
1029     @Override
1030     public void valueChanged(ListSelectionEvent evt) {
1031         int index = jTblQuestions.getSelectedRow();
1032         if (index == -1)
1033             return;
1034         Object item = genexTableModel.getValueAt(index, 1);
1035         if (item instanceof Question)
1036             jTxtQuestionText.setText(item.toString());
1037         else
1038             jTxtQuestionText.setText(((Category) item).getDescription());
1039 
1040         jTxtQuestionText.setCaretPosition(0);
1041     }
1042 
1043     public GenexTableModel getTableModel() {
1044         return genexTableModel;
1045     }
1046 
1047     @Override
1048     public void actionPerformed(ActionEvent e) {
1049         String command = e.getActionCommand();
1050 
1051         if ("Nová kategória".equals(command)) {
1052             if (jTabPane.getSelectedIndex() == 0)
1053                 newCategory();
1054             else
1055                 newTestCategory();
1056         } else if ("Nová otázka".equals(command)) {
1057             editQuestion(null);
1058         } else if ("Nastavenia".equals(command)) {
1059             PropertiesDialog pd = new PropertiesDialog(this);
1060             pd.setLocationRelativeTo(null);
1061             pd.setVisible(true);
1062         } else if ("Odstrániť".equals(command)) {
1063             deleteSelectedItems();
1064         } else if ("Upraviť".equals(command)) {
1065             int sel = jTblQuestions.getSelectedRow();
1066             if (sel == -1) {
1067                 hint("Warning: Najprv si musíte vybrať kategóriu alebo otázku, ktorú chcete upraviť.");
1068                 return;
1069             }
1070             Object obj = genexTableModel.getValue(sel);
1071             if (obj instanceof Category) {
1072                 editCategory((Category) obj, sel);
1073             } else
1074                 editQuestion((Question) obj);
1075 
1076         } else if ("Nový".equals(command)) {
1077             newTest();
1078         } else if ("Generovať".equals(command)) {
1079             generateTest();
1080         } else if ("Pridať do testu".equals(command)) {
1081             if (ntd.isVisible()) {
1082                 addQuestionToTest();
1083             } else {
1084                 newTest();
1085             }
1086         } else if ("Export testu".equals(command)) {
1087             exportTest();
1088         } else if ("Export testu do Moodle".equals(command)) {
1089             exportTestMoodle();
1090         } else if ("O úroveň vyššie".equals(command)) {
1091             upDir();
1092         } else if ("Ukončiť".equals(command)) {
1093             this.setVisible(false);
1094             this.dispose();
1095             System.exit(0);
1096         } else if ("Kopírovať".equals(command)) {
1097             genexTableModel.copyData(jTblQuestions.getSelectedRows());
1098         } else if ("Vystrihnúť".equals(command)) {
1099             genexTableModel.cutData(jTblQuestions.getSelectedRows());
1100         } else if ("Vložiť".equals(command)) {
1101             pasteData();
1102         } else {
1103             System.out.println("Unknown command: " + command);
1104         }
1105     }
1106 
1107     private void addQuestionToTest() {
1108         int[] sel = jTblQuestions.getSelectedRows();
1109         if (sel.length > 0) {
1110             for (int i = 0; i < sel.length; i++) {
1111                 if (genexTableModel.getValue(sel[i]) instanceof Category)
1112                     continue;
1113 
1114                 Question q = (Question) genexTableModel.getValue(sel[i]);
1115                 ntd.getModel().addQuestion(q, new Float(q.getDifficulty()));
1116             }
1117         }
1118     }
1119 
1120     private Test assertTestChoosen() {
1121         if (jTabPane.getSelectedIndex() == 0) {
1122             hint("Info: Musíte vybrať test v ľavom paneli");
1123             return null;
1124         }
1125         DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeTCategories
1126                 .getLastSelectedPathComponent();
1127         if (node == null) {
1128             hint("Info: Pred exportovaním vyberte test ktorý sa bude exportovať");
1129             return null;
1130         }
1131         Test test = null;
1132         if (node.getUserObject() instanceof Test) {
1133             test = (Test) node.getUserObject();
1134         } else {
1135             hint("Info: Exportovať je možné jedine testy");
1136             return null;
1137         }
1138         return test;
1139     }
1140 
1141     private void exportTestMoodle() {
1142 
1143         Test test = assertTestChoosen();
1144         if (test == null) {
1145             return;
1146         }
1147 
1148         JFileChooser jfc = new JFileChooser(".");
1149         jfc.setFileFilter(new FileNameExtensionFilter("XML súbory", "xml"));
1150         int state = jfc.showSaveDialog(this);
1151         if (state == JFileChooser.CANCEL_OPTION)
1152             return;
1153 
1154         File f = jfc.getSelectedFile();
1155         if (f == null)
1156             return;
1157 
1158         Export exp = new ExportMoodle();
1159         exp.setOutputFilename(f.getAbsolutePath());
1160         try {
1161             exp.exportQuestions(questionDao.getQuestionsByTestID(test
1162                     .getTestID()), connection);
1163             hint("Info: Export dokončený úspešne");
1164         } catch (Exception e) {
1165             hint("Error:" + e.getLocalizedMessage());
1166         }
1167         // TODO export do suboru f.getAbsoluteFile() abo tak dajak
1168     }
1169 
1170     private void exportTest() {
1171         Test test = assertTestChoosen();
1172         if (test == null) {
1173             return;
1174         }
1175 
1176         ExportTestDialog etd = new ExportTestDialog(this, test);
1177         etd.setLocationRelativeTo(null);
1178         etd.showDialog();
1179         if (etd.cancel)
1180             hint("Info: Export bol zrušený používaťeľom");
1181         else
1182             hint("Info: Export dokončený úspešne");
1183     }
1184 
1185     private void upDir() {
1186         TreePath path = (TreePath) jTblQuestions.getColumnModel().getColumn(1)
1187                 .getHeaderValue();
1188         if (path == null || path.getParentPath() == null)
1189             return;
1190         jTreeQCategories.setSelectionPath(path.getParentPath());
1191     }
1192 
1193     private void newTestCategory() {
1194         TreePath path = jTreeTCategories.getSelectionPath();
1195         if (path == null)
1196             return;
1197 
1198         DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
1199                 .getLastPathComponent();
1200         if (node == null)
1201             return;
1202         Category cat = (Category) node.getUserObject();
1203         NewCategoryDialog ncd = new NewCategoryDialog(this, null);
1204         ncd.setLocationRelativeTo(null);
1205         Category toAdd = ncd.showDialog();
1206         if (toAdd == null)
1207             return;
1208 
1209         try {
1210             toAdd.setUserTD(new UserDaoDerby(connection).getDefaultTUser()
1211                     .getUserID());
1212 
1213             categoryDao.addTestCategory(cat.getCategoryID(), toAdd);
1214             node.add(new DefaultMutableTreeNode("camuflage"));
1215 
1216             jTreeTCategories.collapsePath(path);
1217             jTreeTCategories.expandPath(path);
1218             jTreeTCategories.updateUI();
1219             hint("Info: Kategória pridaná úspešne");
1220         } catch (Exception e) {
1221             hint("Error: " + e.getMessage());
1222             e.printStackTrace();
1223         }
1224     }
1225 
1226     public void setNewTestButton(boolean enabled) {
1227         jBtnNewTest.setEnabled(enabled);
1228     }
1229 
1230     private void newTest() {
1231         ArrayList<Question> list;
1232         int[] sel = jTblQuestions.getSelectedRows();
1233         if (sel.length > 0) {
1234             list = new ArrayList<Question>(sel.length);
1235             for (int i = 0; i < sel.length; i++) {
1236                 if (genexTableModel.getValue(sel[i]) instanceof Category)
1237                     continue;
1238                 list.add((Question) genexTableModel.getValue(sel[i]));
1239             }
1240         } else
1241             list = new ArrayList<Question>();
1242         NewTestTableModel testModel = new NewTestTableModel(connection);
1243         try {
1244             testModel.setQuestions(list, null);
1245         } catch (Exception e) {
1246             hint("Error: " + e.getLocalizedMessage());
1247             e.printStackTrace();
1248         }
1249         TreePath path = jTreeTCategories.getSelectionPath();
1250         if (path == null) {
1251             hint("Warning: Musíte si vybrať kategóriu testu.");
1252             return;
1253         }
1254         DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
1255                 .getLastPathComponent();
1256         Object obj = node.getUserObject();
1257         if (obj instanceof Test) {
1258             hint("Warning: Musíte si vybrať kategóriu testu.");
1259             return;
1260         }
1261         Category testCat = (Category) obj;
1262         ntd = new NewTestDialog(this, testModel, genexTableModel, testCat, null);
1263         ntd.setLocationRelativeTo(null);
1264         ntd.setVisible(true);
1265     }
1266 
1267     public void updateTestTree() {
1268         TreePath path = jTreeTCategories.getSelectionPath();
1269         DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
1270                 .getLastPathComponent();
1271         node.add(new DefaultMutableTreeNode("camuflage"));
1272         jTreeTCategories.collapsePath(path);
1273         jTreeTCategories.expandPath(path);
1274         jTreeTCategories.updateUI();
1275         hint("Info: Nový test vytvorený úspešne");
1276     }
1277 
1278     private void generateTest() {
1279 
1280         DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeTCategories
1281                 .getLastSelectedPathComponent();
1282         if (node == null) {
1283             hint("Warning: Musíte si vybrať kategóriu testu.");
1284             return;
1285         }
1286         Object obj = node.getUserObject();
1287         if (obj instanceof Test) {
1288             hint("Warning: Musíte si vybrať kategóriu testu.");
1289             return;
1290         }
1291         Category testCat = (Category) obj;
1292         GenerateTestDialog gtd = new GenerateTestDialog(this, connection);
1293         gtd.setLocationRelativeTo(null);
1294         try {
1295             if (gtd.showDialog() == JOptionPane.OK_OPTION) {
1296 
1297                 NewTestTableModel nttm = new NewTestTableModel(connection, gtd
1298                         .getGeneratedTest());
1299 
1300                 NewTestDialog ntd = new NewTestDialog(this, nttm,
1301                         this.genexTableModel, testCat, null);
1302                 ntd.setLocationRelativeTo(null);
1303                 ntd.setTitle("Vygenerovaný test");
1304                 ntd.setVisible(true);
1305             }
1306         } catch (SQLException e) {
1307             hint("Error: " + e.getMessage());
1308         }
1309 
1310         node.add(new DefaultMutableTreeNode("camuflage"));
1311         TreePath path = new TreePath(node.getPath());
1312         if (path.getParentPath() == null) {
1313             jTreeTCategories.collapsePath(path);
1314             jTreeTCategories.expandPath(path);
1315         } else {
1316             jTreeTCategories.collapsePath(path.getParentPath());
1317             jTreeTCategories.expandPath(path.getParentPath());
1318         }
1319         jTreeTCategories.updateUI();
1320         hint("Info: Bol vygenerovaný nový test v kategórii " + testCat);
1321     }
1322 
1323     private void deleteSelectedItems() {
1324         // TODO zmazu sa vybrane polozky z tabulky
1325         int[] selIndices = jTblQuestions.getSelectedRows();
1326         if (selIndices.length == 0) {
1327             hint("Warning: Najprv vyberte z tabuľky položky, ktoré chcete odstrániť.");
1328             return;
1329         }
1330 
1331         int choice = JOptionPane.showConfirmDialog(this,
1332                 "Naozaj chcete odstrániť vybrané položky?", "Odstrániť",
1333                 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
1334         if (choice == JOptionPane.NO_OPTION)
1335             return;
1336 
1337         genexTableModel.deleteItems(selIndices);
1338         TreePath tp = (TreePath) jTblQuestions.getColumnModel().getColumn(1)
1339                 .getHeaderValue();
1340 
1341         jTreeQCategories.collapsePath(tp);
1342         jTreeQCategories.expandPath(tp);
1343 
1344         jTreeQCategories.updateUI();
1345     }
1346 
1347     public void editCategory(Category toEdit, int selected) {
1348         if (toEdit.getName().equals("Kôš")
1349                 || toEdit.getName().equals("Konflikty")) {
1350             hint("Info: Túto kategóriu nemôžete upravovať ani zmazať.");
1351             return;
1352         }
1353         NewCategoryDialog ncd = new NewCategoryDialog(this, toEdit);
1354         ncd.setLocationRelativeTo(null);
1355         Category c = ncd.showDialog();
1356         if (c == null)
1357             return;
1358         //TODO
1359         //pridane odchytavanie vynimiek (palo)
1360         try {
1361             categoryDao.updateCategory(c);
1362         } catch (Exception e) {
1363             hint("Error: " + e.getMessage());
1364         }
1365         genexTableModel.fireTableDataChanged();
1366         DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeQCategories
1367                 .getLastSelectedPathComponent();
1368         if (node == null)
1369             return;
1370         DefaultMutableTreeNode child = (DefaultMutableTreeNode) node
1371                 .getChildAt(selected);
1372         child.setUserObject(c);
1373         jTreeQCategories.updateUI();
1374     }
1375 
1376     /**
1377      * Zobrazi dialog na vytvorenie novej otazky
1378      */
1379     private void editQuestion(Question question) {
1380         TreePath path = jTreeQCategories.getSelectionPath();
1381         if (path == null) {
1382             hint("Warning: Najprv si musíte vybrať ketgóriu, v ktorej chcete otázku vytvoriť.");
1383             return;
1384         }
1385         DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
1386                 .getLastPathComponent();
1387         Category parent = (Category) node.getUserObject();
1388         ArrayList<Category> arr_categories = new ArrayList<Category>();
1389         arr_categories.add(parent);
1390         NewQuestionDialog nqd = new NewQuestionDialog(this, arr_categories,
1391                 question, connection);
1392         nqd.setLocationRelativeTo(null);
1393         Question q = nqd.showDialog();
1394         if (q == null)
1395             return;
1396 
1397         genexTableModel.fireTableDataChanged();
1398     }
1399 
1400     /**
1401      * Zobrazi dialog na vytvorenie novej kategorie
1402      */
1403     private void newCategory() {
1404         NewCategoryDialog d = new NewCategoryDialog(this, null);
1405         d.setLocationRelativeTo(null);
1406         Category toAdd = d.showDialog();
1407         if (toAdd == null)
1408             return;
1409         //TODO
1410         //pridane odchytavanie vynimiek (palo)
1411         try {
1412             toAdd.setUserTD(userDao.getDefaultTUser().getUserID());
1413         } catch (Exception e) {
1414             hint("Error: " + e.getMessage());
1415         }
1416         DefaultMutableTreeNode node;
1417         TreePath path = jTreeQCategories.getSelectionPath();
1418         node = null; //pozor mozna chyba
1419         //TODO
1420         //pridane odchytavanie vynimiek (palo)
1421         try {
1422             if (path == null) {
1423                 node = rootQuestionCategoryNode;
1424                 categoryDao.addRootCategory(toAdd);
1425             } else {
1426                 node = (DefaultMutableTreeNode) path.getLastPathComponent();
1427                 Category parent = (Category) node.getUserObject();
1428                 categoryDao.addCategory(parent.getCategoryID(), toAdd);
1429             }
1430         } catch (Exception e) {
1431             hint("Error: " + e.getMessage());
1432         }
1433         node.add(new DefaultMutableTreeNode(toAdd));
1434         jTreeQCategories.updateUI();
1435         genexTableModel.fireTableDataChanged();
1436     }
1437 
1438     private void hint(String text) {
1439         if (jTxtHint.getBackground() == COMB1_BACKGROUND_COLOR) {
1440             jTxtHint.setBackground(COMB2_BACKGROUND_COLOR);
1441             jTxtHint.setForeground(COMB2_FOREGROUND_COLOR);
1442         } else {
1443             jTxtHint.setBackground(COMB1_BACKGROUND_COLOR);
1444             jTxtHint.setForeground(COMB1_FOREGROUND_COLOR);
1445         }
1446         if (text.startsWith("Error:")) {
1447             jTxtHint.setText(text.substring(6));
1448             jTxtHint.setCaretPosition(0);
1449             jTxtHint.insertIcon(new ImageIcon(resHelp
1450                     .getResourceBytes("/icons/error.png")));
1451         } else if (text.startsWith("Warning:")) {
1452             jTxtHint.setText(text.substring(8));
1453             jTxtHint.setCaretPosition(0);
1454             jTxtHint.insertIcon(new ImageIcon(resHelp
1455                     .getResourceBytes("/icons/warning.png")));
1456         } else if (text.startsWith("Info:")) {
1457             jTxtHint.setText(text.substring(5));
1458             jTxtHint.setCaretPosition(0);
1459             jTxtHint.insertIcon(new ImageIcon(resHelp
1460                     .getResourceBytes("/icons/info.png")));
1461         } else {
1462             jTxtHint.setText(text);
1463         }
1464     }
1465 
1466     @Override
1467     public void mouseClicked(MouseEvent e) {
1468         if (e.getClickCount() != 2)
1469             return;
1470 
1471         int index = jTblQuestions.getSelectedRow();
1472         if (index == -1)
1473             return;
1474         Object item = genexTableModel.getValueAt(index, 1);
1475 
1476         if (item instanceof Category) {
1477             changeCategory(index);
1478         } else if (item instanceof Question) {
1479             editQuestion((Question) item);
1480         } else {
1481             hint("Warning: Neznámy objekt " + item.getClass());
1482         }
1483     }
1484 
1485     public void changeCategory(int index) {
1486         TreePath lastSel = (TreePath) jTblQuestions.getColumnModel().getColumn(
1487                 1).getHeaderValue();
1488         if (lastSel == null)
1489             return;
1490         jTreeQCategories.expandPath(lastSel);
1491 
1492         DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) lastSel
1493                 .getLastPathComponent();
1494         if (dmtn == null)
1495             return;
1496         TreeNode tn = dmtn.getChildAt(index);
1497 
1498         TreePath tp = lastSel.pathByAddingChild(tn);
1499         jTreeQCategories.setSelectionPath(tp);
1500     }
1501 
1502     public void pasteData() {
1503         try {
1504             genexTableModel.pasteData();
1505             genexTableModel.fireTableDataChanged();
1506             TreePath tp = (TreePath) jTblQuestions.getColumnModel()
1507                     .getColumn(1).getHeaderValue();
1508 
1509             if (tp.getParentPath() == null) {
1510                 jTreeQCategories.collapsePath(tp);
1511                 jTreeQCategories.expandPath(tp);
1512             } else {
1513                 jTreeQCategories.collapsePath(tp.getParentPath());
1514                 jTreeQCategories.expandPath(tp.getParentPath());
1515             }
1516             jTreeQCategories.updateUI();
1517         } catch (SQLException sex) {
1518             hint("Error: " + sex.getLocalizedMessage());
1519         }
1520     }
1521 
1522     @Override
1523     public void mouseEntered(MouseEvent arg0) {
1524         // TODO Auto-generated method stub
1525 
1526     }
1527 
1528     @Override
1529     public void mouseExited(MouseEvent arg0) {
1530         // TODO Auto-generated method stub
1531 
1532     }
1533 
1534     @Override
1535     public void mousePressed(MouseEvent arg0) {
1536         // TODO Auto-generated method stub
1537 
1538     }
1539 
1540     @Override
1541     public void mouseReleased(MouseEvent arg0) {
1542         // TODO Auto-generated method stub
1543 
1544     }
1545 
1546     /**
1547      * Auto-generated method for setting the popup menu for a component
1548      */
1549     private void setComponentPopupMenu(final java.awt.Component parent,
1550             final javax.swing.JPopupMenu menu) {
1551         parent.addMouseListener(new java.awt.event.MouseAdapter() {
1552             @Override
1553             public void mousePressed(java.awt.event.MouseEvent e) {
1554                 if (e.isPopupTrigger())
1555                     menu.show(parent, e.getX(), e.getY());
1556             }
1557 
1558             @Override
1559             public void mouseReleased(java.awt.event.MouseEvent e) {
1560                 if (e.isPopupTrigger())
1561                     menu.show(parent, e.getX(), e.getY());
1562             }
1563         });
1564     }
1565 
1566     @Override
1567     public void valueChanged(TreeSelectionEvent e) {
1568         TreePath path = e.getPath();
1569         DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
1570                 .getLastPathComponent();
1571 
1572         if (node.getUserObject() instanceof Test) {
1573             jBtnNewQCategory.setEnabled(false);
1574         } else {
1575             jBtnNewQCategory.setEnabled(true);
1576         }
1577 
1578     }
1579 
1580     @Override
1581     public void stateChanged(ChangeEvent e) {
1582         if (jBtnNewQCategory == null)
1583             return;
1584         if (jTabPane.getSelectedIndex() == 0) {
1585             jBtnNewQCategory.setEnabled(true);
1586         } else {
1587             TreePath path = jTreeTCategories.getSelectionPath();
1588             DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
1589                     .getLastPathComponent();
1590 
1591             if (node.getUserObject() instanceof Test) {
1592                 jBtnNewQCategory.setEnabled(false);
1593             } else {
1594                 jBtnNewQCategory.setEnabled(true);
1595             }
1596         }
1597     }
1598 
1599     private void jTreeTCategoriesMouseClicked(MouseEvent evt) {
1600         if (evt.getClickCount() != 2)
1601             return;
1602         TreePath path = jTreeTCategories.getSelectionPath();
1603         if (path == null)
1604             return;
1605         DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
1606                 .getLastPathComponent();
1607         Object obj = node.getUserObject();
1608         if (obj instanceof Category)
1609             return;
1610         Test test = (Test) obj;
1611         Category category = (Category) (((DefaultMutableTreeNode) node
1612                 .getParent()).getUserObject());
1613         try {
1614             ntd = new NewTestDialog(this, new NewTestTableModel(connection,
1615                     test), genexTableModel, category, test);
1616             ntd.setLocationRelativeTo(null);
1617             ntd.setVisible(true);
1618             jTreeTCategories.updateUI();
1619         } catch (SQLException e) {
1620             hint("Error:" + e.getMessage());
1621         }
1622     }
1623 }