package cz.muni.fi.bronchus.gui; /* * MyUtilities.java * * Created on May 25, 2004, 3:43 PM */ import cz.muni.fi.bronchus.questions.*; import java.awt.Dimension; import javax.swing.*; import javax.swing.text.*; import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * * @author xudrzal */ public class MyUtilities { private MyResources myResources; public static String[] answerLetters={"A","B","C","D","E","F","G","H","I","J", "K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; public static String[] QuestionType={"True/False","Multiple Choice","Multiple Response", "Fill-In-Blank","Short Answer","Ordering Objects","Connecting Objects", "Combined"}; /* public String[] SAO; public String[] SAO={ myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Sequential_from_all"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Random_from_all"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Random_'X'_from_all"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Random_from_all_+_fixed_positions"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Random_'X'_from_all_+_fixed_positions"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Random_from_all_with_specified_Topic"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Random_'X'_from_all_with_specified_Topic"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Grouping_into_Sections_according_to_Topic;_Random_'X'_from_'Y'_selection") }; */ /* public String[] algDesc={ myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Alg_0_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Alg_1_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Alg_2_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Alg_3_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Alg_4_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Alg_5_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Alg_6_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Alg_7_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Alg_8_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Alg_9_Desc") }; public String[] SAODesc = { myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_0_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_1_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_2_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_3_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_4_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_5_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_6_Desc"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_7_Desc") }; public String[] SAOExample={ myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_0_Example"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_1_Example"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_2_Example"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_3_Example"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_4_Example"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_5_Example"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_6_Example"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_7_Example") };*/ public Vector numbers; public Vector letters; public String getSAO(int x) { String sao=""; switch (x) { case 0: sao=myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Sequential_from_all"); break; case 1: sao=myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Random_from_all"); break; case 2: sao=myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Random_'X'_from_all"); break; case 3: sao=myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Random_from_all_+_fixed_positions"); break; case 4: sao=myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Random_'X'_from_all_+_fixed_positions"); break; case 5: sao=myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Random_from_all_with_specified_Topic"); break; case 6: sao=myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Random_'X'_from_all_with_specified_Topic"); break; case 7: sao=myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Grouping_into_Sections_according_to_Topic;_Random_'X'_from_'Y'_selection"); break; } return sao; } public String getSAODesc(int x) { return myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_"+String.valueOf(x)+"_Desc"); } public String getSAOExample(int x) { return myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","SAO_"+String.valueOf(x)+"_Example"); } public String getAlgDesc(int x) { return myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Alg_"+String.valueOf(x)+"_Desc"); } /** Creates a new instance of MyUtilities */ public MyUtilities(MyResources res) { myResources = res; numbers=new Vector(); for (int i=1; i<27; i++) numbers.add(String.valueOf(i)); letters=new Vector(); for (int i=0; i<26; i++) letters.add(answerLetters[i]); } /*Create JOptionPane with two buttons */ public int showAnswerDialog(java.awt.Component parentComponent, String title, String question) { JLabel label=new JLabel(); label.setText(question); label.setFont(new java.awt.Font("Dialog", 0, 11)); Object[] buttons={myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","html_Yes_button"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","html_No_button")}; int i=JOptionPane.showOptionDialog(parentComponent, label, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, buttons, null); return i; } public int showMessageDialog(java.awt.Component parentComponent, String title, String message, int messageType) { if (message!=null) { if (message.length()<200) { JLabel label=new JLabel(); label.setText(message); label.setFont(new java.awt.Font("Dialog", 0, 11)); Object[] button={myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","html_OK_button")}; int i=JOptionPane.showOptionDialog(parentComponent, label, title, JOptionPane.OK_OPTION, messageType, null, button, null); return i; } else { JScrollPane pane=new JScrollPane(); pane.setPreferredSize(new Dimension(300,150)); pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); JTextArea textarea=new JTextArea(); pane.setViewportView(textarea); textarea.setText(message); textarea.setFont(new java.awt.Font("Dialog", 0, 11)); Object[] button={myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","html_OK_button")}; int i=JOptionPane.showOptionDialog(parentComponent, pane, title, JOptionPane.OK_OPTION, messageType, null, button, null); return i; } } return -1; } public int showErrorDialog(java.awt.Component parentComponent, String title, String message) { JScrollPane pane=new JScrollPane(); pane.setPreferredSize(new Dimension(300,150)); pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); JTextArea textarea=new JTextArea(); pane.setViewportView(textarea); textarea.setWrapStyleWord(true); textarea.setLineWrap(true); textarea.setText(message); textarea.setFont(new java.awt.Font("Dialog", 0, 11)); Object[] button={myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","html_OK_button")}; int i=JOptionPane.showOptionDialog(parentComponent, pane, title, JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE, null, button, null); return i; } public int showErrorDialogYesNo(java.awt.Component parentComponent, String title, String message) { JScrollPane scrollpane=new JScrollPane(); scrollpane.setPreferredSize(new Dimension(300,150)); scrollpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scrollpane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); JTextArea textarea=new JTextArea(); scrollpane.setViewportView(textarea); textarea.setWrapStyleWord(true); textarea.setLineWrap(true); textarea.setText(message); textarea.setFont(new java.awt.Font("Dialog", 0, 11)); JPanel panel = new JPanel(); panel.setLayout(new javax.swing.BoxLayout(panel, javax.swing.BoxLayout.Y_AXIS)); JLabel label = new JLabel(myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Cannot_save_file_because_of_following_errors:")); label.setFont(new java.awt.Font("Dialog", 0, 11)); label.setPreferredSize(new Dimension(label.getWidth(),40)); JLabel label2 = new JLabel(myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","Try_to_save_anyway?")); label2.setPreferredSize(new Dimension(label2.getWidth(),40)); label2.setFont(new java.awt.Font("Dialog", 0, 11)); panel.add(label); panel.add(scrollpane); panel.add(label2); Object[] buttons={myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","html_Yes_button"), myResources.getBundle("cz/muni/fi/bronchus/bundles/MyUtilitiesBundle","html_No_button")}; int i=JOptionPane.showOptionDialog(parentComponent, panel, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, buttons, null); /* Object[] button={"