Friday, April 26, 2013

Java Swing JTextPane Highlighting with word, pharse and proximty search

public class DocumentViewerJPanel extends javax.swing.JPanel {

    /**
     * Creates new form DocumentViewerJPanel
     */
    private DocumentViewerJPanel() {
        initComponents();
    }

    public static DocumentViewerJPanel getInstance() {
        if (instance == null) {
            instance = new DocumentViewerJPanel();
            instance.init();
        }
        return instance;
    }

    private void init() {
        findTextField.getDocument().addDocumentListener(new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                currentPosition = 0;
                highLight = false;
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                currentPosition = 0;
                highLight = false;
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                currentPosition = 0;
                highLight = false;
            }
        });

        documentViewDialog = new JDialog(Bugger.getSingleInstance());
        documentViewDialog.setTitle("Document View");
        documentViewDialog.setModal(true);
        documentViewDialog.setUndecorated(true);
        documentViewDialog.setLocationRelativeTo(Bugger.getSingleInstance());
        //documentViewDialog.setModalityType(Dialog.ModalityType.MODELESS);
        documentViewDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        documentViewDialog.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                closeDocumentViewer();
            }
        });
        Dimension scSize = Toolkit.getDefaultToolkit().getScreenSize();
        int w = scSize.width - 150;
        int h = scSize.height - 100;
        documentViewDialog.setBounds((scSize.width - w) / 2, (scSize.height - h) / 2, w, h);

        previewDialog = new JDialog(documentViewDialog);
        previewDialog.setTitle("Print Preview");
        previewDialog.setModal(true);
        previewDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        int w1 = scSize.width - 220;
        int h1 = scSize.height - 140;
        previewDialog.setBounds((scSize.width - w1) / 2, (scSize.height - h1) / 2, w1, h1);

        findDialog = new javax.swing.JDialog(documentViewDialog);
        findDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
        findDialog.setTitle("Find");
        findDialog.setResizable(false);
        findDialog.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                closeFindDialog();
            }
        });
        findDialog.getContentPane().add(findBasePanel);

        fontFaceDialog = new javax.swing.JDialog(documentViewDialog);
        fontFaceDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
        fontFaceDialog.setTitle("Font Face");
        fontFaceDialog.setResizable(false);
        fontFaceDialog.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                closeFontFaceDialog();
            }
        });
        fontFaceDialog.getContentPane().add(fontFaceBasePanel);

        saveDialog = new javax.swing.JDialog(documentViewDialog);
        saveDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
        saveDialog.setTitle("Save Document");
        saveDialog.setResizable(false);
        saveDialog.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                closeSaveDialog();
            }
        });
        saveDialog.getContentPane().add(saveBasePanel);

        notesDialog = new javax.swing.JDialog(documentViewDialog);
        notesDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
        notesDialog.setTitle("Notes");
        notesDialog.setResizable(false);
        notesDialog.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                closeNoteDialog();
            }
        });
        notesDialog.getContentPane().add(notesBasePanel);

        smsDialog = new javax.swing.JDialog(documentViewDialog);
        smsDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
        smsDialog.setTitle("SMS");
        smsDialog.setResizable(false);
        smsDialog.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                closeNoteDialog();
            }
        });
        smsDialog.getContentPane().add(smsBasePanel);

        notesDialog.pack();
        fontFaceDialog.pack();
        findDialog.pack();
        saveDialog.pack();
        smsDialog.pack();;

        notesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    notesTextArea.setText(null);
                }
            }
        });

        loadFontFamilies();
    }

    private void showDocument(String searchWord, String id) {
        ArrayList words = new ArrayList();
        searchWord = searchWord.trim();
        while (searchWord.length() > 0) {
            if (searchWord.contains(" ")) {
                String word = searchWord.substring(0, searchWord.indexOf(" "));
                System.out.println("word : " + word);
                searchWord = searchWord.substring(searchWord.indexOf(" "), searchWord.length());
                System.out.println("searchWord 1 : " + searchWord);
                if (!word.trim().isEmpty() && !word.equals("AND") && !word.equals("OR") && !word.equals("NOT")) {
                    word = word.trim();
                    if (word.startsWith("\"")) {
                        if (searchWord.indexOf("~") > 0) {
                            String word1 = searchWord.substring(0, searchWord.indexOf("~"));
                            searchWord = searchWord.substring(0, searchWord.indexOf("~"));
                            String word2 = searchWord.substring(searchWord.indexOf(" "));
                            searchWord = searchWord.substring(0, searchWord.indexOf(" "));
                            words.add(word + word1 + "~" + word2);
                        } else if (searchWord.indexOf("\"") > 0) {
                            String word1 = searchWord.substring(0, searchWord.indexOf("\"") + 1);
                            System.out.println("word1\" : " + word1);
                            words.add(word + word1);
                            searchWord = searchWord.substring(searchWord.indexOf(word1) + word1.length(), searchWord.length());
                            System.out.println("searchWord 3 : " + searchWord);
                        }
                    } else {
                        words.add(word);
                    }
                }
                searchWord = searchWord.trim();
                System.out.println("searchWord 2 : " + searchWord);
            } else {
                words.add(searchWord);
                break;
            }
        }

        final String[] pattern = new String[words.size()];
        words.toArray(pattern);
        System.out.println("words : " + words);
        
        prepareHTML();

        //System.out.println("html : " + html);
        documentTextPane.setText(html);
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                if (highLight(documentTextPane, pattern) == -1) {
                    documentScrollPane.scrollRectToVisible(new Rectangle(0, 0));
                }
                findButton.requestFocusInWindow();
            }
        });
    }

    private void prepareHTML() {
        html = "";}

    private void showHTML() {
        Point point = documentScrollPane.getViewport().getViewPosition();
        final int pos = documentTextPane.viewToModel(point);
        documentTextPane.setText(html);
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    documentTextPane.scrollRectToVisible(documentTextPane.modelToView(pos));
                } catch (Exception e) {
                }
            }
        });
    }

    private void showDocumentPreView(JRViewer jRViewer) {
        previewDialog.getContentPane().removeAll();
        previewDialog.getContentPane().add(jRViewer);
        previewDialog.setVisible(true);
    }

    public void showDocumentViewer(String searchWord, String id) {
        currentSearchWord = searchWord;
        showDocument(searchWord, idd);
        //Bugger.getSingleInstance().showOverlay();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                documentViewDialog.getContentPane().removeAll();
                documentViewDialog.getContentPane().add(DocumentViewerJPanel.getInstance());
                documentViewDialog.setVisible(true);
            }
        });
    }

    public void closeDocumentViewer() {
        html = "";
        currentPosition = 0;
        previousPosition = 0;
        lastPosition = 0;
        fontSize = 14;
        exporting = false;
        noteSaving = false;
        removeFindHighlights(documentTextPane);
        removeSearchHighlights(documentTextPane);
        closeFindDialog();
        Bugger.getSingleInstance().hideOverlay();
        DocumentViewerJFrame.getInstance().closeDocumentViewer();
        documentViewDialog.dispose();
        idd = null;
    }

    // Creates highlights around all occurrences of pattern in textComp
    public int highLight(JTextComponent textComp, String[] pattern) {
        // First remove all old highlights
        removeSearchHighlights(textComp);
        int firstPos = -1;
        try {
            Highlighter hilite = textComp.getHighlighter();
            Document doc = textComp.getDocument();
            String text = doc.getText(0, doc.getLength());
            if (!matchCaseCheckBox.isSelected()) {
                text = text.toLowerCase();
            }
            //System.out.println("text = " + text);
            for (int i = 0; i < pattern.length; i++) {
                int pos = 0;
                String word = pattern[i];
                if (!matchCaseCheckBox.isSelected()) {
                    word = word.toLowerCase();
                }
                String tempWord = word;
                try {
                    if (word.contains("~") || tempWord.startsWith("\"")) {
                        word = word.split(" ")[0].replace("\"", "");
                    }
                } catch (Exception e) {
                }
                System.out.println("tempWord 1 -- > " + tempWord + " : word --> " + word);
                // Search for pattern
                doc:
                while ((pos = text.indexOf(word, pos)) >= 0) {
                    if (firstPos == -1) {
                        firstPos = pos;
                    }
                    System.out.println("tempWord 2 -- > " + tempWord);
                    if (tempWord.contains("~")) {
                        tempWord = tempWord.replace("\"", "");
                        try {
                            String[] fsplit = tempWord.split("~");
                            String[] ssplit = fsplit[0].split(" ");
                            ssplit[ssplit.length - 1] = ssplit[ssplit.length - 1].replace("\"", "");
                            System.out.println("ssplit[0] : " + ssplit[0]);
                            System.out.println("ssplit[1] : " + ssplit[1]);
                            int length = Integer.parseInt(fsplit[1]);
                            int secPos = 0;
                            if ((secPos = text.indexOf(ssplit[ssplit.length - 1], pos)) >= 0) {
                                String tempText = text.substring(pos, secPos + ssplit[ssplit.length - 1].length());
                                System.out.println("tempText : " + tempText);
                                String bta[] = tempText.split(" ");
                                if (bta.length > 0 && bta.length <= length) {
                                    hilite.addHighlight(pos, pos + ssplit[0].length(), searchHighlighter);
                                    hilite.addHighlight(secPos, secPos + ssplit[ssplit.length - 1].length(), searchHighlighter);
                                    System.out.println("Highlighted");
                                }
                            }
                        } catch (Exception e) {
                        }
                    } else if (tempWord.endsWith("\"")) {
                        tempWord = tempWord.replace("\"", "");
                        System.out.println("tempWord 3 -- > " + tempWord);
                        try {
                            String[] fsplit = tempWord.split(" ");
                            System.out.println("sec Text --> " + fsplit[fsplit.length - 1]);
                            int secPos = 0;
                            pharse:
                            while ((secPos = text.indexOf(fsplit[fsplit.length - 1], pos + fsplit[0].length())) >= 0) {
                                String middleText = text.substring(pos, secPos + fsplit[fsplit.length - 1].length());
                                System.out.println("middleText -- > " + middleText);
                                String mt[] = middleText.split(" ");
                                System.out.println("mt.length : " + mt.length + " -- fsplit.length : " + fsplit.length);
                                if (mt.length == fsplit.length) {
                                    hilite.addHighlight(pos - 1, secPos + fsplit[fsplit.length - 1].length(), searchHighlighter);
                                    break pharse;
                                } else {
                                    pos = pos + fsplit[0].length();
                                }
                            }
                        } catch (Exception e) {
                        }
                    } else {
                        if (word.equalsIgnoreCase(tempWord)) {
                            hilite.addHighlight(pos, pos + word.length(), searchHighlighter);
                        }
                    }
                    pos += tempWord.length();
                }
            }
        } catch (BadLocationException e) {
        }
        //System.out.println(firstPos);
        if (firstPos > -1) {
            currentPosition = firstPos;
            highLight = true;
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        documentTextPane.scrollRectToVisible(documentTextPane.modelToView(currentPosition));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        return firstPos;
    }

    // Removes only our private highlights
    public void removeSearchHighlights(JTextComponent textComp) {

        Highlighter hilite = textComp.getHighlighter();

        Highlighter.Highlight[] hilites = hilite.getHighlights();

        for (int i = 0; i < hilites.length; i++) {

            if (hilites[i].getPainter() instanceof SearchHighlightPainter) {

                hilite.removeHighlight(hilites[i]);
            }
        }
    }

    // Removes only our private highlights
    public void removeFindHighlights(JTextComponent textComp) {

        Highlighter hilite = textComp.getHighlighter();

        Highlighter.Highlight[] hilites = hilite.getHighlights();

        for (int i = 0; i < hilites.length; i++) {

            if (hilites[i].getPainter() instanceof FindHighlightPainter) {

                hilite.removeHighlight(hilites[i]);
            }
        }
    }

    private void findWord(String word) {
        documentTextPane.select(0, 0);
        boolean find = false;
        try {
            Highlighter hilite = documentTextPane.getHighlighter();
            Document doc = documentTextPane.getDocument();
            String text = doc.getText(0, doc.getLength());
            int pos = 0;
            if (!matchCaseCheckBox.isSelected()) {
                text = text.toLowerCase();
                word = word.toLowerCase();
            }
            // Search for pattern
            while ((pos = text.indexOf(word, pos)) >= 0) {
                if (currentPosition == 0 && pos > previousPosition) {
                    currentPosition = pos;
                }
                if (currentPosition > previousPosition) {
                    hilite.addHighlight(currentPosition, currentPosition + word.length(), findHighlighter);
                    find = true;
                }
                if (highlightCheckBox.isSelected()) {
                    hilite.addHighlight(pos, pos + word.length(), searchHighlighter);
                }
                pos += word.length();
                lastPosition = pos;
            }
            previousPosition = currentPosition + word.length();
            if (find) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            documentTextPane.scrollRectToVisible(documentTextPane.modelToView(currentPosition));
                        } catch (Exception e) {
                        }
                    }
                });
            } else {
                JOptionPane.showMessageDialog(findDialog, "Word not found.");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void showFindDialog() {
        findDialog.setLocationRelativeTo(documentViewDialog);
        findDialog.setModalityType(Dialog.ModalityType.MODELESS);
        Dimension parentSize = getSize();
        findDialog.setLocation((parentSize.width - findDialog.getWidth()) / 2, (parentSize.height - findDialog.getHeight()) / 2);
        findDialog.setVisible(true);
    }

    private void closeFindDialog() {
        findDialog.setVisible(false);
        findTextField.setText(null);
    }

    private void loadFontFamilies() {
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fontFamilyNames = env.getAvailableFontFamilyNames();
        for (int i = 0; i < fontFamilyNames.length; i++) {
            String fontFamily = fontFamilyNames[i];
            ((DefaultListModel) fontFaceList.getModel()).addElement(fontFamily);
        }
    }

    private void showFontFaceDialog() {
        int index = 0;
        for (int i = 0; i < ffListModel.getSize(); i++) {
            if (defaultFonName.equalsIgnoreCase((String) ffListModel.get(i))) {
                index = i;
                break;
            }
        }
        fontFaceList.setSelectedIndex(index);
        fontFaceDialog.setLocationRelativeTo(documentViewDialog);
        fontFaceDialog.setModalityType(Dialog.ModalityType.MODELESS);
        Dimension parentSize = getSize();
        fontFaceDialog.setLocation((parentSize.width - fontFaceDialog.getWidth()) / 2, (parentSize.height - fontFaceDialog.getHeight()) / 2);
        fontFaceDialog.setVisible(true);
    }

    private void closeFontFaceDialog() {
        fontFaceDialog.setVisible(false);
        fontFaceList.clearSelection();
    }

    private int getPositionOfWord(String word) {
        int pos = 0;
        try {
            Document doc = documentTextPane.getDocument();
            String text = doc.getText(0, doc.getLength());
            pos = text.indexOf(word, pos);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pos;
    }

    private void showSaveDialog() {
        docNameTextField.setText(docObj.getNo().replaceAll(" ", ""));
        saveDialog.setLocationRelativeTo(documentViewDialog);
        saveDialog.setModalityType(Dialog.ModalityType.MODELESS);
        Dimension parentSize = getSize();
        saveDialog.setLocation((parentSize.width - saveDialog.getWidth()) / 2, (parentSize.height - saveDialog.getHeight()) / 2);
        saveDialog.setGlassPane(glassPanel);
        saveDialog.setVisible(true);
    }

    private void closeSaveDialog() {
        if (!exporting) {
            saveDialog.setVisible(false);
            docNameTextField.setText(null);
            docFileTextField.setText(null);
            saveButtonGroup.clearSelection();
            saveNotesCheckBox.setSelected(false);
        }
    }

    private void showNoteDialog() {
        notesDialog.setLocationRelativeTo(documentViewDialog);
        notesDialog.setModalityType(Dialog.ModalityType.MODELESS);
        Dimension parentSize = getSize();
        notesDialog.setLocation((parentSize.width - notesDialog.getWidth()) / 2, (parentSize.height - notesDialog.getHeight()) / 2);
        notesDialog.setGlassPane(glassPanel);
        notesDialog.setVisible(true);

        loadNotes();
    }

    private void loadNotes() {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    notesList.clear();
                    NotesDB.getInstance().loadNotes(id, notesList);
                } catch (Exception e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(notesDialog, "ERROR", "Exception : " + e.getMessage(), JOptionPane.ERROR_MESSAGE);
                }
            }
        });
    }

    private void closeNoteDialog() {
        if (!noteSaving) {
            notesDialog.setVisible(false);
            notesTextArea.setText(null);
            notesList.clear();
        }
    }

    private void showSMSDialog() {
        mobileTextField.setText(null);
        titleComboBox.setSelectedIndex(0);
        smsDialog.setLocationRelativeTo(documentViewDialog);
        smsDialog.setModalityType(Dialog.ModalityType.MODELESS);
        Dimension parentSize = getSize();
        smsDialog.setLocation((parentSize.width - saveDialog.getWidth()) / 2, (parentSize.height - saveDialog.getHeight()) / 2);
        smsDialog.setGlassPane(glassPanel);
        smsDialog.setVisible(true);
    }

    private void closeSMSDialog() {
        smsDialog.setVisible(false);
        mobileTextField.setText(null);
        titleComboBox.setSelectedIndex(0);
    }

    public JasperPrint mergerJasperPrints(JasperPrint jp1, JasperPrint jp2) {
        List jps = jp2.getPages();
        for (JRPrintPage jRPrintPage : jps) {
            jp1.addPage(jRPrintPage);
        }
        return jp1;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // //GEN-BEGIN:initComponents
    private void initComponents() {
        info.clearthought.layout.TableLayout _tableLayoutInstance;
        info.clearthought.layout.TableLayout _tableLayoutInstance1;
        info.clearthought.layout.TableLayout _tableLayoutInstance10;
        info.clearthought.layout.TableLayout _tableLayoutInstance11;
        info.clearthought.layout.TableLayout _tableLayoutInstance12;
        info.clearthought.layout.TableLayout _tableLayoutInstance13;
        info.clearthought.layout.TableLayout _tableLayoutInstance2;
        info.clearthought.layout.TableLayout _tableLayoutInstance3;
        info.clearthought.layout.TableLayout _tableLayoutInstance4;
        info.clearthought.layout.TableLayout _tableLayoutInstance5;
        info.clearthought.layout.TableLayout _tableLayoutInstance6;
        info.clearthought.layout.TableLayout _tableLayoutInstance7;
        info.clearthought.layout.TableLayout _tableLayoutInstance8;
        info.clearthought.layout.TableLayout _tableLayoutInstance9;
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        notesList = org.jdesktop.observablecollections.ObservableCollections.observableList(new ArrayList());
        glassPanel = new javax.swing.JPanel();
        loadingLabel = new javax.swing.JLabel();
        findBasePanel = new javax.swing.JPanel();
        findTextField = new javax.swing.JTextField();
        findSubButton = new javax.swing.JButton();
        findCancelButton = new javax.swing.JButton();
        matchCaseCheckBox = new javax.swing.JCheckBox();
        highlightCheckBox = new javax.swing.JCheckBox();
        previewButton = new javax.swing.JButton();
        fontFaceBasePanel = new javax.swing.JPanel();
        fontFaceScrollPane = new javax.swing.JScrollPane();
        fontFaceList = new javax.swing.JList();
        fontFaceControlPanel = new javax.swing.JPanel();
        ffOkButton = new javax.swing.JButton();
        ffCancelButton = new javax.swing.JButton();
        saveBasePanel = new javax.swing.JPanel();
        saveDocAsLabel = new javax.swing.JLabel();
        docSaveAsPanel = new javax.swing.JPanel();
        pdfRadioButton = new javax.swing.JRadioButton();
        msWordRadioButton = new javax.swing.JRadioButton();
        odtWordRadioButton = new javax.swing.JRadioButton();
        docNameLabel = new javax.swing.JLabel();
        docNameTextField = new javax.swing.JTextField();
        saveNotesCheckBox = new javax.swing.JCheckBox();
        locationLabel = new javax.swing.JLabel();
        browsePanel = new javax.swing.JPanel();
        docFileTextField = new javax.swing.JTextField();
        browseButton = new javax.swing.JButton();
        docSaveButton = new javax.swing.JButton();
        docSaveCancelButton = new javax.swing.JButton();
        saveButtonGroup = new javax.swing.ButtonGroup();
        notesBasePanel = new javax.swing.JPanel();
        notesTextScrollPane = new javax.swing.JScrollPane();
        notesTextArea = new javax.swing.JTextArea();
        notesControlPanel = new javax.swing.JPanel();
        notesSaveButton = new javax.swing.JButton();
        notesCancelButton = new javax.swing.JButton();
        notesTableScrollPane = new javax.swing.JScrollPane();
        notesTable = new javax.swing.JTable(){
            public void changeSelection(int row, int column, boolean toggle, boolean extend){
                super.changeSelection(row, column, toggle, extend);
                if (editCellAt(row, 2)){
                    Component editor = getEditorComponent();
                    editor.requestFocusInWindow();
                }
            }
        };
        smsBasePanel = new javax.swing.JPanel();
        selectLabel = new javax.swing.JLabel();
        titleComboBox = new javax.swing.JComboBox();
        mobileLabel = new javax.swing.JLabel();
        mobileTextField = new javax.swing.JTextField();
        smsControlPanel = new javax.swing.JPanel();
        sendButton = new javax.swing.JButton();
        smsCancelButton = new javax.swing.JButton();
        basePanel = new javax.swing.JPanel();
        titlePanel = new javax.swing.JPanel();
        titleLabel = new javax.swing.JLabel();
        closeButton = new javax.swing.JButton();
        controlPanel = new javax.swing.JPanel();
        printButton = new javax.swing.JButton();
        findButton = new javax.swing.JButton();
        fontIncreaseButton = new javax.swing.JButton();
        fontDecreaseButton = new javax.swing.JButton();
        addToFolderButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        defineButton = new javax.swing.JButton();
        sendSMSButton = new javax.swing.JButton();
        fontFaceButton = new javax.swing.JButton();
        noteButton = new javax.swing.JButton();
        documentScrollPane = new javax.swing.JScrollPane();
        documentTextPane = new javax.swing.JTextPane(){
            public void copy(){
                JOptionPane.showMessageDialog(documentViewDialog, "Copy not allowed.");
                select(getSelectionStart(), getSelectionStart());
            }
        }
        ;

        glassPanel.setBackground(new java.awt.Color(0, 0, 0, 28));
        _tableLayoutInstance11 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance11.setHGap(0);
        _tableLayoutInstance11.setVGap(0);
        _tableLayoutInstance11.setColumn(new double[]{info.clearthought.layout.TableLayout.FILL,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.FILL});
        _tableLayoutInstance11.setRow(new double[]{info.clearthought.layout.TableLayout.FILL,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.FILL});
        glassPanel.setLayout(_tableLayoutInstance11);

        loadingLabel.setBackground(new java.awt.Color(255, 255, 255));
        loadingLabel.setFont(new java.awt.Font("Times New Roman", 1, 17)); // NOI18N
        loadingLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        loadingLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/ajax-loader4.gif"))); // NOI18N
        loadingLabel.setText("Processing... ");
        loadingLabel.setOpaque(true);
        glassPanel.add(loadingLabel, new info.clearthought.layout.TableLayoutConstraints(1, 1, 1, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        _tableLayoutInstance2 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance2.setHGap(5);
        _tableLayoutInstance2.setVGap(5);
        _tableLayoutInstance2.setColumn(new double[]{0,100,10,100,100,0});
        _tableLayoutInstance2.setRow(new double[]{0,25,info.clearthought.layout.TableLayout.PREFERRED,0});
        findBasePanel.setLayout(_tableLayoutInstance2);

        findTextField.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        findBasePanel.add(findTextField, new info.clearthought.layout.TableLayoutConstraints(1, 1, 3, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        findSubButton.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        findSubButton.setText("Find");
        findSubButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findSubButtonActionPerformed(evt);
            }
        });
        findBasePanel.add(findSubButton, new info.clearthought.layout.TableLayoutConstraints(1, 2, 1, 2, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.CENTER));

        findCancelButton.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        findCancelButton.setText("Cancel");
        findCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findCancelButtonActionPerformed(evt);
            }
        });
        findBasePanel.add(findCancelButton, new info.clearthought.layout.TableLayoutConstraints(3, 2, 3, 2, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.CENTER));

        matchCaseCheckBox.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        matchCaseCheckBox.setText("Match Case");
        matchCaseCheckBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                matchCaseCheckBoxItemStateChanged(evt);
            }
        });
        findBasePanel.add(matchCaseCheckBox, new info.clearthought.layout.TableLayoutConstraints(4, 1, 4, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        highlightCheckBox.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        highlightCheckBox.setText("Keep 
Highlighting");
        highlightCheckBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                highlightCheckBoxItemStateChanged(evt);
            }
        });
        findBasePanel.add(highlightCheckBox, new info.clearthought.layout.TableLayoutConstraints(4, 2, 4, 2, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        previewButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        previewButton.setText("Preview");
        previewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                previewButtonActionPerformed(evt);
            }
        });

        _tableLayoutInstance3 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance3.setHGap(5);
        _tableLayoutInstance3.setVGap(5);
        _tableLayoutInstance3.setColumn(new double[]{0,350,0});
        _tableLayoutInstance3.setRow(new double[]{0,250,28,0});
        fontFaceBasePanel.setLayout(_tableLayoutInstance3);

        ffListModel = new DefaultListModel();
        fontFaceList.setModel(ffListModel);
        fontFaceList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        fontFaceList.setCellRenderer(new FontListCellRenderer());
        fontFaceScrollPane.setViewportView(fontFaceList);

        fontFaceBasePanel.add(fontFaceScrollPane, new info.clearthought.layout.TableLayoutConstraints(1, 1, 1, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        _tableLayoutInstance4 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance4.setHGap(10);
        _tableLayoutInstance4.setVGap(10);
        _tableLayoutInstance4.setColumn(new double[]{info.clearthought.layout.TableLayout.FILL,80,80,info.clearthought.layout.TableLayout.FILL});
        _tableLayoutInstance4.setRow(new double[]{info.clearthought.layout.TableLayout.FILL});
        fontFaceControlPanel.setLayout(_tableLayoutInstance4);

        ffOkButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        ffOkButton.setText("Ok");
        ffOkButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ffOkButtonActionPerformed(evt);
            }
        });
        fontFaceControlPanel.add(ffOkButton, new info.clearthought.layout.TableLayoutConstraints(1, 0, 1, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        ffCancelButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        ffCancelButton.setText("Cancel");
        ffCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ffCancelButtonActionPerformed(evt);
            }
        });
        fontFaceControlPanel.add(ffCancelButton, new info.clearthought.layout.TableLayoutConstraints(2, 0, 2, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        fontFaceBasePanel.add(fontFaceControlPanel, new info.clearthought.layout.TableLayoutConstraints(1, 2, 1, 2, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        _tableLayoutInstance6 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance6.setHGap(5);
        _tableLayoutInstance6.setVGap(5);
        _tableLayoutInstance6.setColumn(new double[]{0,170,170,0});
        _tableLayoutInstance6.setRow(new double[]{0,30,30,30,30,30,30,30,3,30,0});
        saveBasePanel.setLayout(_tableLayoutInstance6);

        saveDocAsLabel.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        saveDocAsLabel.setText("Save document as");
        saveBasePanel.add(saveDocAsLabel, new info.clearthought.layout.TableLayoutConstraints(1, 1, 2, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        _tableLayoutInstance8 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance8.setHGap(0);
        _tableLayoutInstance8.setVGap(0);
        _tableLayoutInstance8.setColumn(new double[]{info.clearthought.layout.TableLayout.FILL,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.FILL});
        _tableLayoutInstance8.setRow(new double[]{info.clearthought.layout.TableLayout.FILL});
        docSaveAsPanel.setLayout(_tableLayoutInstance8);

        saveButtonGroup.add(pdfRadioButton);
        pdfRadioButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        pdfRadioButton.setText("PDF");
        pdfRadioButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/radio.png"))); // NOI18N
        pdfRadioButton.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/radio_sel.png"))); // NOI18N
        pdfRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                pdfRadioButtonItemStateChanged(evt);
            }
        });
        docSaveAsPanel.add(pdfRadioButton, new info.clearthought.layout.TableLayoutConstraints(1, 0, 1, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        saveButtonGroup.add(msWordRadioButton);
        msWordRadioButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        msWordRadioButton.setText("Microsoft Word");
        msWordRadioButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/radio.png"))); // NOI18N
        msWordRadioButton.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/radio_sel.png"))); // NOI18N
        msWordRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                msWordRadioButtonItemStateChanged(evt);
            }
        });
        docSaveAsPanel.add(msWordRadioButton, new info.clearthought.layout.TableLayoutConstraints(2, 0, 2, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        saveButtonGroup.add(odtWordRadioButton);
        odtWordRadioButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        odtWordRadioButton.setText("Open Office Word");
        odtWordRadioButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/radio.png"))); // NOI18N
        odtWordRadioButton.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/radio_sel.png"))); // NOI18N
        odtWordRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                odtWordRadioButtonItemStateChanged(evt);
            }
        });
        docSaveAsPanel.add(odtWordRadioButton, new info.clearthought.layout.TableLayoutConstraints(3, 0, 3, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        saveBasePanel.add(docSaveAsPanel, new info.clearthought.layout.TableLayoutConstraints(1, 2, 2, 2, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        docNameLabel.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        docNameLabel.setText("Document Name");
        saveBasePanel.add(docNameLabel, new info.clearthought.layout.TableLayoutConstraints(1, 3, 2, 3, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));
        saveBasePanel.add(docNameTextField, new info.clearthought.layout.TableLayoutConstraints(1, 4, 2, 4, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        saveNotesCheckBox.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        saveNotesCheckBox.setText("Save with notes");
        saveNotesCheckBox.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/checkbox.png"))); // NOI18N
        saveNotesCheckBox.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/checkbox_sel.png"))); // NOI18N
        saveBasePanel.add(saveNotesCheckBox, new info.clearthought.layout.TableLayoutConstraints(1, 5, 2, 5, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        locationLabel.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        locationLabel.setText("Location");
        saveBasePanel.add(locationLabel, new info.clearthought.layout.TableLayoutConstraints(1, 6, 1, 6, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        _tableLayoutInstance7 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance7.setHGap(0);
        _tableLayoutInstance7.setVGap(0);
        _tableLayoutInstance7.setColumn(new double[]{info.clearthought.layout.TableLayout.FILL,info.clearthought.layout.TableLayout.PREFERRED});
        _tableLayoutInstance7.setRow(new double[]{info.clearthought.layout.TableLayout.FILL});
        browsePanel.setLayout(_tableLayoutInstance7);

        docFileTextField.setEditable(false);
        browsePanel.add(docFileTextField, new info.clearthought.layout.TableLayoutConstraints(0, 0, 0, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        browseButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        browseButton.setText("Browse");
        browseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseButtonActionPerformed(evt);
            }
        });
        browsePanel.add(browseButton, new info.clearthought.layout.TableLayoutConstraints(1, 0, 1, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        saveBasePanel.add(browsePanel, new info.clearthought.layout.TableLayoutConstraints(1, 7, 2, 7, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        docSaveButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        docSaveButton.setText("Save");
        docSaveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                docSaveButtonActionPerformed(evt);
            }
        });
        saveBasePanel.add(docSaveButton, new info.clearthought.layout.TableLayoutConstraints(1, 9, 1, 9, info.clearthought.layout.TableLayout.TRAILING, info.clearthought.layout.TableLayout.CENTER));

        docSaveCancelButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        docSaveCancelButton.setText("Cancel");
        docSaveCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                docSaveCancelButtonActionPerformed(evt);
            }
        });
        saveBasePanel.add(docSaveCancelButton, new info.clearthought.layout.TableLayoutConstraints(2, 9, 2, 9, info.clearthought.layout.TableLayout.LEFT, info.clearthought.layout.TableLayout.CENTER));

        _tableLayoutInstance9 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance9.setHGap(5);
        _tableLayoutInstance9.setVGap(5);
        _tableLayoutInstance9.setColumn(new double[]{0,600,0});
        _tableLayoutInstance9.setRow(new double[]{0,100,30,300,0});
        notesBasePanel.setLayout(_tableLayoutInstance9);

        notesTextArea.setColumns(20);
        notesTextArea.setLineWrap(true);
        notesTextArea.setRows(5);
        notesTextScrollPane.setViewportView(notesTextArea);

        notesBasePanel.add(notesTextScrollPane, new info.clearthought.layout.TableLayoutConstraints(1, 1, 1, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        _tableLayoutInstance10 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance10.setHGap(20);
        _tableLayoutInstance10.setVGap(10);
        _tableLayoutInstance10.setColumn(new double[]{info.clearthought.layout.TableLayout.FILL,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.FILL});
        _tableLayoutInstance10.setRow(new double[]{info.clearthought.layout.TableLayout.FILL});
        notesControlPanel.setLayout(_tableLayoutInstance10);

        notesSaveButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        notesSaveButton.setText("Save");
        notesSaveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                notesSaveButtonActionPerformed(evt);
            }
        });
        notesControlPanel.add(notesSaveButton, new info.clearthought.layout.TableLayoutConstraints(1, 0, 1, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        notesCancelButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        notesCancelButton.setText("Cancel");
        notesCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                notesCancelButtonActionPerformed(evt);
            }
        });
        notesControlPanel.add(notesCancelButton, new info.clearthought.layout.TableLayoutConstraints(2, 0, 2, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        notesBasePanel.add(notesControlPanel, new info.clearthought.layout.TableLayoutConstraints(1, 2, 1, 2, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        notesTable.setRowHeight(50);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, notesList, notesTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${note}"));
        columnBinding.setColumnName("Note");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${createdOn}"));
        columnBinding.setColumnName("Created On");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${noteId}"));
        columnBinding.setColumnName("Action");
        columnBinding.setColumnClass(Integer.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        notesTableScrollPane.setViewportView(notesTable);
        notesTable.getColumnModel().getColumn(0).setResizable(false);
        notesTable.getColumnModel().getColumn(0).setCellRenderer(new NoteTextCellRenderer());
        notesTable.getColumnModel().getColumn(1).setMinWidth(120);
        notesTable.getColumnModel().getColumn(1).setPreferredWidth(120);
        notesTable.getColumnModel().getColumn(1).setMaxWidth(120);
        notesTable.getColumnModel().getColumn(1).setCellRenderer(new NoteDateCellRenderer());
        notesTable.getColumnModel().getColumn(2).setMinWidth(100);
        notesTable.getColumnModel().getColumn(2).setPreferredWidth(100);
        notesTable.getColumnModel().getColumn(2).setMaxWidth(100);
        notesTable.getColumnModel().getColumn(2).setCellEditor(new NoteActionCellRendererAndEditor());
        notesTable.getColumnModel().getColumn(2).setCellRenderer(new NoteActionCellRendererAndEditor());

        notesBasePanel.add(notesTableScrollPane, new info.clearthought.layout.TableLayoutConstraints(1, 3, 1, 3, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        _tableLayoutInstance12 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance12.setHGap(5);
        _tableLayoutInstance12.setVGap(15);
        _tableLayoutInstance12.setColumn(new double[]{50,70,250,50});
        _tableLayoutInstance12.setRow(new double[]{50,30,30,10,30,50});
        smsBasePanel.setLayout(_tableLayoutInstance12);

        selectLabel.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        selectLabel.setText("Select");
        smsBasePanel.add(selectLabel, new info.clearthought.layout.TableLayoutConstraints(1, 1, 1, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        caseTitleComboBox.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        caseTitleComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select Case Title" }));
        smsBasePanel.add(caseTitleComboBox, new info.clearthought.layout.TableLayoutConstraints(2, 1, 2, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        mobileLabel.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        mobileLabel.setText("Mobile");
        smsBasePanel.add(mobileLabel, new info.clearthought.layout.TableLayoutConstraints(1, 2, 1, 2, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));
        smsBasePanel.add(mobileTextField, new info.clearthought.layout.TableLayoutConstraints(2, 2, 2, 2, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        _tableLayoutInstance13 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance13.setHGap(10);
        _tableLayoutInstance13.setVGap(10);
        _tableLayoutInstance13.setColumn(new double[]{info.clearthought.layout.TableLayout.FILL,100,100,info.clearthought.layout.TableLayout.FILL});
        _tableLayoutInstance13.setRow(new double[]{info.clearthought.layout.TableLayout.FILL});
        smsControlPanel.setLayout(_tableLayoutInstance13);

        sendButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        sendButton.setText("Send");
        sendButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sendButtonActionPerformed(evt);
            }
        });
        smsControlPanel.add(sendButton, new info.clearthought.layout.TableLayoutConstraints(1, 0, 1, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        smsCancelButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        smsCancelButton.setText("Cancel");
        smsCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smsCancelButtonActionPerformed(evt);
            }
        });
        smsControlPanel.add(smsCancelButton, new info.clearthought.layout.TableLayoutConstraints(2, 0, 2, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        smsBasePanel.add(smsControlPanel, new info.clearthought.layout.TableLayoutConstraints(1, 4, 2, 4, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153), 2));
        setLayout(new java.awt.BorderLayout());

        _tableLayoutInstance = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance.setHGap(5);
        _tableLayoutInstance.setVGap(5);
        _tableLayoutInstance.setColumn(new double[]{info.clearthought.layout.TableLayout.FILL});
        _tableLayoutInstance.setRow(new double[]{30,40,info.clearthought.layout.TableLayout.FILL});
        basePanel.setLayout(_tableLayoutInstance);

        titlePanel.setBackground(new java.awt.Color(102, 102, 102));
        _tableLayoutInstance5 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance5.setHGap(0);
        _tableLayoutInstance5.setVGap(0);
        _tableLayoutInstance5.setColumn(new double[]{info.clearthought.layout.TableLayout.FILL,24,5});
        _tableLayoutInstance5.setRow(new double[]{info.clearthought.layout.TableLayout.FILL,24,info.clearthought.layout.TableLayout.FILL});
        titlePanel.setLayout(_tableLayoutInstance5);

        titleLabel.setFont(new java.awt.Font("Times New Roman", 1, 17)); // NOI18N
        titleLabel.setForeground(new java.awt.Color(255, 255, 255));
        titleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        titleLabel.setText("Document Viewer");
        titlePanel.add(titleLabel, new info.clearthought.layout.TableLayoutConstraints(0, 1, 0, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        closeButton.setFont(new java.awt.Font("Times New Roman", 1, 17)); // NOI18N
        closeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/close_24.png"))); // NOI18N
        closeButton.setToolTipText("Close");
        closeButton.setContentAreaFilled(false);
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });
        titlePanel.add(closeButton, new info.clearthought.layout.TableLayoutConstraints(1, 1, 1, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        basePanel.add(titlePanel, new info.clearthought.layout.TableLayoutConstraints(0, 0, 0, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        _tableLayoutInstance1 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance1.setHGap(5);
        _tableLayoutInstance1.setVGap(0);
        _tableLayoutInstance1.setColumn(new double[]{info.clearthought.layout.TableLayout.FILL,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.FILL});
        _tableLayoutInstance1.setRow(new double[]{info.clearthought.layout.TableLayout.FILL,28,info.clearthought.layout.TableLayout.FILL});
        controlPanel.setLayout(_tableLayoutInstance1);

        printButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        printButton.setText("Print");
        printButton.setToolTipText("Print");
        printButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printButtonActionPerformed(evt);
            }
        });
        controlPanel.add(printButton, new info.clearthought.layout.TableLayoutConstraints(8, 1, 8, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        findButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        findButton.setText("Find");
        findButton.setToolTipText("Find");
        findButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findButtonActionPerformed(evt);
            }
        });
        controlPanel.add(findButton, new info.clearthought.layout.TableLayoutConstraints(4, 1, 4, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        fontIncreaseButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        fontIncreaseButton.setText("AAA");
        fontIncreaseButton.setToolTipText("Increase Font Size");
        fontIncreaseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fontIncreaseButtonActionPerformed(evt);
            }
        });
        controlPanel.add(fontIncreaseButton, new info.clearthought.layout.TableLayoutConstraints(2, 1, 2, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        fontDecreaseButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        fontDecreaseButton.setText("AAA");
        fontDecreaseButton.setToolTipText("Decrease Font Size");
        fontDecreaseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fontDecreaseButtonActionPerformed(evt);
            }
        });
        controlPanel.add(fontDecreaseButton, new info.clearthought.layout.TableLayoutConstraints(3, 1, 3, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        addToFolderButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        addToFolderButton.setText("Add to Folder");
        addToFolderButton.setToolTipText("Add to Folder");
        controlPanel.add(addToFolderButton, new info.clearthought.layout.TableLayoutConstraints(6, 1, 6, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        saveButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        saveButton.setText("Save");
        saveButton.setToolTipText("Save");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });
        controlPanel.add(saveButton, new info.clearthought.layout.TableLayoutConstraints(7, 1, 7, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        defineButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        defineButton.setText("Define");
        defineButton.setToolTipText("Define");
        controlPanel.add(defineButton, new info.clearthought.layout.TableLayoutConstraints(9, 1, 9, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        sendSMSButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        sendSMSButton.setText("Send SMS");
        sendSMSButton.setToolTipText("Send SMS");
        sendSMSButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sendSMSButtonActionPerformed(evt);
            }
        });
        controlPanel.add(sendSMSButton, new info.clearthought.layout.TableLayoutConstraints(10, 1, 10, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        fontFaceButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        fontFaceButton.setText("Font");
        fontFaceButton.setToolTipText("Change Font Face");
        fontFaceButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fontFaceButtonActionPerformed(evt);
            }
        });
        controlPanel.add(fontFaceButton, new info.clearthought.layout.TableLayoutConstraints(1, 1, 1, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        noteButton.setFont(new java.awt.Font("Times New Roman", 0, 16)); // NOI18N
        noteButton.setText("Note");
        noteButton.setToolTipText("Note");
        noteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                noteButtonActionPerformed(evt);
            }
        });
        controlPanel.add(noteButton, new info.clearthought.layout.TableLayoutConstraints(5, 1, 5, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        basePanel.add(controlPanel, new info.clearthought.layout.TableLayoutConstraints(0, 1, 0, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        documentTextPane.setEditable(false);
        documentTextPane.setContentType("text/html"); // NOI18N
        documentTextPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
            public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {
                documentTextPaneHyperlinkUpdate(evt);
            }
        });
        documentScrollPane.setViewportView(documentTextPane);

        basePanel.add(documentScrollPane, new info.clearthought.layout.TableLayoutConstraints(0, 2, 0, 2, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        add(basePanel, java.awt.BorderLayout.CENTER);

        bindingGroup.bind();
    }// //GEN-END:initComponents

    private void printButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printButtonActionPerformed
        // TODO add your handling code here:
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    InputStream jin = getClass().getResource("/com/xxx/htmlDocReport.jasper").openStream();
                    Map paramMap = new HashMap();
                    paramMap.put("docBean", docObj);

                    JasperPrint jasperPrint = JasperFillManager.fillReport(jin, paramMap);

                    PrinterJob job = PrinterJob.getPrinterJob();
                    PrintService service = PrintServiceLookup.lookupDefaultPrintService();
                    job.setPrintService(service);

                    PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
                    //printRequestAttributeSet.add(new sun.print.DialogOwner(Bugger.getSingleInstance()));
                    MediaSizeName mediaSizeName = MediaSize.findMedia(4, 4, MediaPrintableArea.INCH);
                    printRequestAttributeSet.add(mediaSizeName);
                    printRequestAttributeSet.add(new Copies(1));

                    JRPrintServiceExporter exporter;
                    exporter = new JRPrintServiceExporter();
                    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
                    /* We set the selected service and pass it as a paramenter */
                    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, service);
                    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, service.getAttributes());
                    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
                    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
                    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
                    exporter.exportReport();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }//GEN-LAST:event_printButtonActionPerformed

    private void previewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_previewButtonActionPerformed
        // TODO add your handling code here:
        SwingWorker sw = new SwingWorker() {
            @Override
            protected Object doInBackground() throws Exception {
                InputStream jin = getClass().getResource("/com/xxx/htmlDocReport.jasper").openStream();
                Map paramMap = new HashMap();
                paramMap.put("docBean", docObj);

                JasperPrint jasperPrint = JasperFillManager.fillReport(jin, paramMap);
                return jasperPrint;
            }

            @Override
            protected void done() {
                super.done();
                try {
                    JRSaveContributor jasperPrintContrinutor = null;
                    Object obj = get();
                    if (obj instanceof JasperPrint) {
                        JasperPrint jasperPrint = (JasperPrint) obj;
                        JRViewer jRViewer = new JRViewer(jasperPrint);
                        JRSaveContributor jRSaveContributors[] = jRViewer.getSaveContributors();
                        for (int i = 0; i < jRSaveContributors.length; i++) {
                            JRSaveContributor jRSaveContributor = jRSaveContributors[i];
                            //System.out.println("Desc : " + jRSaveContributor.getDescription());
                            if (jRSaveContributor.getDescription().contains("jrprint")) {
                                jasperPrintContrinutor = jRSaveContributor;
                            }
                        }
                        if (jasperPrintContrinutor != null) {
                            jRViewer.removeSaveContributor(jasperPrintContrinutor);
                        }
                        showDocumentPreView(jRViewer);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        Executors.newCachedThreadPool().submit(sw);
    }//GEN-LAST:event_previewButtonActionPerformed

    private void documentTextPaneHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {//GEN-FIRST:event_documentTextPaneHyperlinkUpdate
        // TODO add your handling code here:
        if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            //JOptionPane.showMessageDialog(null, evt.getDescription());
            final String description = evt.getDescription();
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        
                    } catch (IOException io) {
                        io.printStackTrace();
                        JOptionPane.showMessageDialog(documentViewDialog, "ERROR", "Document not found.", JOptionPane.ERROR_MESSAGE);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    }//GEN-LAST:event_documentTextPaneHyperlinkUpdate

    private void findButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findButtonActionPerformed
        // TODO add your handling code here:
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                showFindDialog();
            }
        });
    }//GEN-LAST:event_findButtonActionPerformed

    private void findSubButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findSubButtonActionPerformed
        // TODO add your handling code here:
        final String findText = findTextField.getText().trim();
        removeSearchHighlights(documentTextPane);
        removeFindHighlights(documentTextPane);
        if (!findText.isEmpty()) {
            currentPosition = 0;
            if (previousPosition == lastPosition) {
                previousPosition = 0;
            }
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    findWord(findText);
                }
            });
        }
    }//GEN-LAST:event_findSubButtonActionPerformed

    private void findCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findCancelButtonActionPerformed
        // TODO add your handling code here:
        closeFindDialog();
    }//GEN-LAST:event_findCancelButtonActionPerformed

    private void highlightCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_highlightCheckBoxItemStateChanged
        // TODO add your handling code here:
        removeSearchHighlights(documentTextPane);
        findWord(findTextField.getText().trim());
    }//GEN-LAST:event_highlightCheckBoxItemStateChanged

    private void matchCaseCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_matchCaseCheckBoxItemStateChanged
        // TODO add your handling code here:
        currentPosition = 0;
        previousPosition = 0;
        lastPosition = 0;
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                removeFindHighlights(documentTextPane);
                removeSearchHighlights(documentTextPane);
                findWord(findTextField.getText().trim());
            }
        });
    }//GEN-LAST:event_matchCaseCheckBoxItemStateChanged

    private void fontIncreaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontIncreaseButtonActionPerformed
        // TODO add your handling code here:
        if (fontSize < maxFontSize) {
            fontSize = fontSize + fontIncrementSize;
            prepareHTML();
            showHTML();
        }
    }//GEN-LAST:event_fontIncreaseButtonActionPerformed

    private void fontDecreaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontDecreaseButtonActionPerformed
        // TODO add your handling code here:
        System.out.println(fontSize);
        if (fontSize > minFontSize) {
            fontSize = fontSize - fontDecrementSize;
            prepareHTML();
            showHTML();
        }
    }//GEN-LAST:event_fontDecreaseButtonActionPerformed

    private void fontFaceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontFaceButtonActionPerformed
        // TODO add your handling code here:
        showFontFaceDialog();
    }//GEN-LAST:event_fontFaceButtonActionPerformed

    private void ffOkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ffOkButtonActionPerformed
        // TODO add your handling code here:
        defaultFonName = (String) fontFaceList.getSelectedValue();
        prepareHTML();
        showHTML();
        closeFontFaceDialog();
    }//GEN-LAST:event_ffOkButtonActionPerformed

    private void ffCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ffCancelButtonActionPerformed
        // TODO add your handling code here:
        closeFontFaceDialog();
    }//GEN-LAST:event_ffCancelButtonActionPerformed

    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
        // TODO add your handling code here:
        closeDocumentViewer();
    }//GEN-LAST:event_closeButtonActionPerformed

    private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
        // TODO add your handling code here:
        JFileChooser fileChooser = new JFileChooser(currentSaveDir);
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (fileChooser.showOpenDialog(saveDialog) == JFileChooser.APPROVE_OPTION) {
            File selectedDir = fileChooser.getSelectedFile();
            docFileTextField.setText(selectedDir.getAbsolutePath());
        }
    }//GEN-LAST:event_browseButtonActionPerformed

    private void docSaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_docSaveButtonActionPerformed
        // TODO add your handling code here:
        if (!exporting) {
            if (saveButtonGroup.getSelection() != null) {
                String docName = docNameTextField.getText().trim();
                if (!docName.isEmpty()) {
                    String docPath = docFileTextField.getText().trim();
                    if (!docPath.isEmpty()) {
                        SwingWorker sw = new SwingWorker() {
                            @Override
                            protected Object doInBackground() throws Exception {
                                saveDialog.getGlassPane().setVisible(true);
                                //Thread.sleep(10000);
                                //saveDialog.getContentPane().validate();
                                //ProcessingJDialog.getInstance(saveDialog).showDialog();

                                exporting = true;
                                InputStream jinDoc = getClass().getResource("/com/xx/xx.jasper").openStream();
                                InputStream jinNote = getClass().getResource("/com/xx/xx.jasper").openStream();

                                Map paramMap = new HashMap();
                                paramMap.put("docBean", docObj);

                                JasperPrint jasperPrint1 = JasperFillManager.fillReport(jinDoc, paramMap);

                                if (saveNotesCheckBox.isSelected()) {
                                    List notes = new ArrayList();
                                    dB.getInstance().loadNotes(id, notes);
                                    String noteText = "
    "; for (int i = 0; i < caseNotes.size(); i++) { CaseNote cn = caseNotes.get(i); caseNoteText += "
  1. " + cn.getNote() + "
  2. "; } caseNoteText += "
"; Map paramMap1 = new HashMap(); paramMap1.put("notes", noteText); JasperPrint jasperPrint2 = JasperFillManager.fillReport(jinNote, paramMap1); jasperPrint1 = mergerJasperPrints(jasperPrint1, jasperPrint2); System.out.println("notes --> " + paramMap1.get("notes")); } String saveType = "pdf"; if (msWordRadioButton.isSelected()) { saveType = "docx"; } else if (odtWordRadioButton.isSelected()) { saveType = "odt"; } JRExporter exporter = null; if (saveType.equalsIgnoreCase("pdf")) { exporter = new JRPdfExporter(); } else if (saveType.equalsIgnoreCase("docx")) { exporter = new JRDocxExporter(); } else if (saveType.equalsIgnoreCase("odt")) { exporter = new JROdtExporter(); } if (exporter != null) { String docName = docNameTextField.getText(); if (docName.lastIndexOf(".") > 0) { docName = docName.substring(0, docName.lastIndexOf(".")); } String fileName = docFileTextField.getText() + File.separator + docName + "." + saveType; FileOutputStream fout = new FileOutputStream(fileName); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint1); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fout); exporter.exportReport(); fout.flush(); fout.close(); } return true; } @Override protected void done() { super.done(); saveDialog.getGlassPane().setVisible(false); //ProcessingJDialog.getInstance(saveDialog).showDialog(); try { get(); JOptionPane.showMessageDialog(saveDialog, "Save completed."); } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(saveDialog, "Exception : " + e.getMessage()); } finally { exporting = false; } closeSaveDialog(); } }; Executors.newCachedThreadPool().execute(sw); } else { JOptionPane.showMessageDialog(saveDialog, "Select document save location."); } } else { JOptionPane.showMessageDialog(saveDialog, "Enter document name to save."); } } else { JOptionPane.showMessageDialog(saveDialog, "Select document save as type."); } } }//GEN-LAST:event_docSaveButtonActionPerformed private void docSaveCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_docSaveCancelButtonActionPerformed // TODO add your handling code here: closeSaveDialog(); }//GEN-LAST:event_docSaveCancelButtonActionPerformed private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed // TODO add your handling code here: showSaveDialog(); }//GEN-LAST:event_saveButtonActionPerformed private void noteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noteButtonActionPerformed // TODO add your handling code here: showNoteDialog(); }//GEN-LAST:event_noteButtonActionPerformed private void notesSaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_notesSaveButtonActionPerformed // TODO add your handling code here: final String notes = notesTextArea.getText().trim(); if (!notes.isEmpty()) { SwingWorker sw = new SwingWorker() { @Override protected Object doInBackground() throws Exception { notesDialog.getGlassPane().setVisible(true); //ProcessingJDialog.getInstance(notesDialog).showDialog(); int row = notesTable.getSelectedRow(); Note note = null; if (row > -1) { note = notesList.get(notesTable.convertRowIndexToModel(row)); } else { note = new Note(); } if (note != null) { notesTextArea.setText(note.getNote()); note.setId(Integer.parseInt(iId)); note.setNote(notes); dB.getInstance().saveNote(note); } return note; } @Override protected void done() { super.done(); notesDialog.getGlassPane().setVisible(false); //ProcessingJDialog.getInstance(notesDialog).hideDialog(); try { Object obj = get(); if (obj instanceof note) { //final Note noteBean = (Note) obj; JOptionPane.showMessageDialog(notesDialog, "Note successfully saved."); notesTextArea.setText(null); loadNotes(); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(notesDialog, "ERROR", "Exception : " + e.getMessage(), JOptionPane.ERROR_MESSAGE); } notesTable.removeEditor(); } }; Executors.newCachedThreadPool().submit(sw); } else { JOptionPane.showMessageDialog(saveDialog, "Enter note text."); } }//GEN-LAST:event_notesSaveButtonActionPerformed private void notesCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_notesCancelButtonActionPerformed // TODO add your handling code here: closeNoteDialog(); }//GEN-LAST:event_notesCancelButtonActionPerformed private void pdfRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_pdfRadioButtonItemStateChanged // TODO add your handling code here: if (evt.getStateChange() == ItemEvent.SELECTED) { String docName = docNameTextField.getText(); if (docName.lastIndexOf(".") > 0) { docName = docName.substring(0, docName.lastIndexOf(".")); } docNameTextField.setText(docName + ".pdf"); } }//GEN-LAST:event_pdfRadioButtonItemStateChanged private void msWordRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_msWordRadioButtonItemStateChanged // TODO add your handling code here: if (evt.getStateChange() == ItemEvent.SELECTED) { String docName = docNameTextField.getText(); if (docName.lastIndexOf(".") > 0) { docName = docName.substring(0, docName.lastIndexOf(".")); } docNameTextField.setText(docName + ".docx"); } }//GEN-LAST:event_msWordRadioButtonItemStateChanged private void odtWordRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_odtWordRadioButtonItemStateChanged // TODO add your handling code here: if (evt.getStateChange() == ItemEvent.SELECTED) { String docName = docNameTextField.getText(); if (docName.lastIndexOf(".") > 0) { docName = docName.substring(0, docName.lastIndexOf(".")); } docNameTextField.setText(docName + ".odt"); } }//GEN-LAST:event_odtWordRadioButtonItemStateChanged private void sendSMSButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendSMSButtonActionPerformed // TODO add your handling code here: showSMSDialog(); }//GEN-LAST:event_sendSMSButtonActionPerformed private void sendButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendButtonActionPerformed // TODO add your handling code here: }//GEN-LAST:event_sendButtonActionPerformed private void smsCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smsCancelButtonActionPerformed // TODO add your handling code here: closeSMSDialog(); }//GEN-LAST:event_smsCancelButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addToFolderButton; private javax.swing.JPanel basePanel; private javax.swing.JButton browseButton; private javax.swing.JPanel browsePanel; private javax.swing.JComboBox titleComboBox; private javax.swing.JButton closeButton; private javax.swing.JPanel controlPanel; private javax.swing.JButton defineButton; private javax.swing.JTextField docFileTextField; private javax.swing.JLabel docNameLabel; private javax.swing.JTextField docNameTextField; private javax.swing.JPanel docSaveAsPanel; private javax.swing.JButton docSaveButton; private javax.swing.JButton docSaveCancelButton; private javax.swing.JScrollPane documentScrollPane; private javax.swing.JTextPane documentTextPane; private javax.swing.JButton ffCancelButton; private javax.swing.JButton ffOkButton; private javax.swing.JPanel findBasePanel; private javax.swing.JButton findButton; private javax.swing.JButton findCancelButton; private javax.swing.JButton findSubButton; private javax.swing.JTextField findTextField; private javax.swing.JButton fontDecreaseButton; private javax.swing.JPanel fontFaceBasePanel; private javax.swing.JButton fontFaceButton; private javax.swing.JPanel fontFaceControlPanel; private javax.swing.JList fontFaceList; private javax.swing.JScrollPane fontFaceScrollPane; private javax.swing.JButton fontIncreaseButton; private javax.swing.JPanel glassPanel; private javax.swing.JCheckBox highlightCheckBox; private javax.swing.JLabel loadingLabel; private javax.swing.JLabel locationLabel; private javax.swing.JCheckBox matchCaseCheckBox; private javax.swing.JLabel mobileLabel; private javax.swing.JTextField mobileTextField; private javax.swing.JRadioButton msWordRadioButton; private javax.swing.JButton noteButton; private javax.swing.JPanel notesBasePanel; private javax.swing.JButton notesCancelButton; private javax.swing.JPanel notesControlPanel; private java.util.List notesList; private javax.swing.JButton notesSaveButton; private javax.swing.JTable notesTable; private javax.swing.JScrollPane notesTableScrollPane; private javax.swing.JTextArea notesTextArea; private javax.swing.JScrollPane notesTextScrollPane; private javax.swing.JRadioButton odtWordRadioButton; private javax.swing.JRadioButton pdfRadioButton; private javax.swing.JButton previewButton; private javax.swing.JButton printButton; private javax.swing.JPanel saveBasePanel; private javax.swing.JButton saveButton; private javax.swing.ButtonGroup saveButtonGroup; private javax.swing.JLabel saveDocAsLabel; private javax.swing.JCheckBox saveNotesCheckBox; private javax.swing.JLabel selectLabel; private javax.swing.JButton sendButton; private javax.swing.JButton sendSMSButton; private javax.swing.JPanel smsBasePanel; private javax.swing.JButton smsCancelButton; private javax.swing.JPanel smsControlPanel; private javax.swing.JLabel titleLabel; private javax.swing.JPanel titlePanel; private org.jdesktop.beansbinding.BindingGroup bindingGroup; // End of variables declaration//GEN-END:variables private JDialog documentViewDialog; private JDialog previewDialog; private JDialog findDialog, fontFaceDialog, saveDialog, notesDialog, smsDialog; private static DocumentViewerJPanel instance; private String html, id, currentSearchWord; private DocumentViewerBean docObj; private boolean highLight = false; private int currentPosition = 0, previousPosition = 0, lastPosition = 0; private int fontSize = 14; private int maxFontSize = 18; private int minFontSize = 10; private int fontIncrementSize = 1; private int fontDecrementSize = 1; private String defaultFonName = "Arial"; private DefaultListModel ffListModel; private String currentSaveDir = ""; private boolean exporting = false, noteSaving = false; public static String DOC_FOLDER = "Files" + File.separator; public static String IMAGE_FOLDER = "Images" + File.separator; // An instance of the private subclass of the default highlight painter // 236, 235, 163 - light yellow // 176, 197, 227 - lignt blue // 148, 255, 148 - light green Highlighter.HighlightPainter searchHighlighter = new SearchHighlightPainter(new Color(236, 235, 163)); // A class of the default highlight painter private class SearchHighlightPainter extends DefaultHighlighter.DefaultHighlightPainter { public SearchHighlightPainter(Color color) { super(color); } } Highlighter.HighlightPainter findHighlighter = new FindHighlightPainter(new Color(148, 255, 148)); // A class of the default highlight painter private class FindHighlightPainter extends DefaultHighlighter.DefaultHighlightPainter { public FindHighlightPainter(Color color) { super(color); } } class FontListCellRenderer extends DefaultListCellRenderer { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { DefaultListCellRenderer comp = (DefaultListCellRenderer) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); Font f = new Font((String) value, Font.PLAIN, 18); comp.setFont(f); comp.setText("
" + (String) value); return comp; } } class NoteTextCellRenderer extends DefaultTableCellRenderer { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { DefaultTableCellRenderer comp = (DefaultTableCellRenderer) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); comp.setVerticalAlignment(JLabel.TOP); comp.setText("" + comp.getText()); comp.setToolTipText("
" + comp.getText()); return comp; } } class NoteDateCellRenderer extends DefaultTableCellRenderer { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { DefaultTableCellRenderer comp = (DefaultTableCellRenderer) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); comp.setHorizontalAlignment(JLabel.CENTER); return comp; } } class NoteActionCellRendererAndEditor extends AbstractCellEditor implements TableCellRenderer, TableCellEditor { private JPanel panel; private Object value; private int row = -1; public NoteActionCellRendererAndEditor() { panel = new JPanel(); info.clearthought.layout.TableLayout _tableLayoutInstance12 = new info.clearthought.layout.TableLayout(); _tableLayoutInstance12.setHGap(0); _tableLayoutInstance12.setVGap(0); _tableLayoutInstance12.setColumn(new double[]{info.clearthought.layout.TableLayout.FILL, info.clearthought.layout.TableLayout.PREFERRED, info.clearthought.layout.TableLayout.FILL, info.clearthought.layout.TableLayout.PREFERRED, info.clearthought.layout.TableLayout.FILL}); _tableLayoutInstance12.setRow(new double[]{info.clearthought.layout.TableLayout.FILL}); panel.setLayout(_tableLayoutInstance12); JLabel editLabel = new JLabel("Edit"); editLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); editLabel.setHorizontalAlignment(JLabel.CENTER); editLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { CaseNote caseNote = notesList.get(notesTable.convertRowIndexToModel(row)); notesTextArea.setText(caseNote.getNote()); } }); panel.add(editLabel, new info.clearthought.layout.TableLayoutConstraints(1, 0, 1, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.CENTER)); JLabel deleteLabel = new JLabel("Delete"); deleteLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); deleteLabel.setHorizontalAlignment(JLabel.CENTER); deleteLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int confirm = JOptionPane.showConfirmDialog(notesDialog, "Do you want to delete this note?", "DELETE", JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { SwingWorker sw = new SwingWorker() { @Override protected Object doInBackground() throws Exception { notesDialog.getGlassPane().setVisible(true); CaseNote caseNote = notesList.get(notesTable.convertRowIndexToModel(row)); NotesDB.getInstance().deleteNote(caseNote); return caseNote; } @Override protected void done() { super.done(); notesDialog.getGlassPane().setVisible(false); try { Object obj = get(); if (obj instanceof CaseNote) { final CaseNote noteBean = (CaseNote) obj; notesList.remove(noteBean); JOptionPane.showMessageDialog(notesDialog, "Note successfully deleted."); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(notesDialog, "ERROR", "Exception : " + e.getMessage(), JOptionPane.ERROR_MESSAGE); } } }; Executors.newCachedThreadPool().submit(sw); } } }); panel.add(deleteLabel, new info.clearthought.layout.TableLayoutConstraints(3, 0, 3, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.CENTER)); } @Override public Object getCellEditorValue() { return value; } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { this.value = value; this.row = row; if (isSelected) { panel.setBackground(table.getSelectionBackground()); } else { panel.setBackground(table.getBackground()); } return panel; } @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { this.value = value; this.row = row; if (isSelected) { panel.setBackground(table.getSelectionBackground()); } else { panel.setBackground(table.getBackground()); } return panel; } } }

No comments: