Wednesday, June 19, 2013

Print Dialog in Java


PrinterJob job = PrinterJob.getPrinterJob();

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

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

Wednesday, June 12, 2013

Block JTextComponent Copy, Paste, Cut Action


JTextComponent.KeyBinding[] newBindings = {
         new JTextComponent.KeyBinding(
         KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK),
         DefaultEditorKit.beepAction),
         new JTextComponent.KeyBinding(
         KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK),
         DefaultEditorKit.beepAction),
         new JTextComponent.KeyBinding(
         KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK),
         DefaultEditorKit.beepAction)
         };

         Keymap k = documentTextPane.getKeymap();
         JTextComponent.loadKeymap(k, newBindings, documentTextPane.getActions());

Block Key input in JTextComponet



@Override
            protected void processKeyEvent(KeyEvent e) {
                int kc = e.getKeyCode();
                if (kc == KeyEvent.VK_HOME || kc == KeyEvent.VK_END
                        || kc == KeyEvent.VK_PAGE_UP || kc == KeyEvent.VK_PAGE_DOWN
                        || kc == KeyEvent.VK_UP || kc == KeyEvent.VK_DOWN
                        || kc == KeyEvent.VK_LEFT || kc == KeyEvent.VK_RIGHT
                        || kc == KeyEvent.CTRL_MASK || kc == KeyEvent.VK_C) {
                    super.processKeyEvent(e);
                } else {
                    e.consume();
                }
            }

Tuesday, June 11, 2013

Fixing Disappearing Text Selections when focus lost from JTextPane




public class SelectionPreservingCaret extends DefaultCaret {

    /**
     * The last SelectionPreservingCaret that lost focus
     */
    private static SelectionPreservingCaret last = null;
    /**
     * The last event that indicated loss of focus
     */
    private static FocusEvent lastFocusEvent = null;

    public SelectionPreservingCaret() {
        // The blink rate is set by BasicTextUI when the text component
        // is created, and is not (re-) set when a new Caret is installed.
        // This implementation attempts to pull a value from the UIManager,
        // and defaults to a 500ms blink rate. This assumes that the
        // look and feel uses the same blink rate for all text components
        // (and hence we just pull the value for TextArea). If you are
        // using a look and feel for which this is not the case, you may
        // need to set the blink rate after creating the Caret.
        int blinkRate = 500;
        Object o = UIManager.get("TextArea.caretBlinkRate");
        if ((o != null) && (o instanceof Integer)) {
            Integer rate = (Integer) o;
            blinkRate = rate.intValue();
        }
        setBlinkRate(blinkRate);
    }

    /**
     * Called when the component containing the caret gains focus. DefaultCaret
     * does most of the work, while the subclass checks to see if another
     * instance of SelectionPreservingCaret previously had focus.
     *
     * @param e the focus event
     * @see java.awt.event.FocusListener#focusGained
     */
    public void focusGained(FocusEvent evt) {
        super.focusGained(evt);

        // If another instance of SelectionPreservingCaret had focus and
        // we defered a focusLost event, deliver that event now.
        if ((last != null) && (last != this)) {
            last.hide();
        }
    }

    /**
     * Called when the component containing the caret loses focus. Instead of
     * hiding both the caret and the selection, the subclass only hides the
     * caret and saves a (static) reference to the event and this specific caret
     * instance so that the event can be delivered later if appropriate.
     *
     * @param e the focus event
     * @see java.awt.event.FocusListener#focusLost
     */
    public void focusLost(FocusEvent evt) {
        setVisible(false);
        last = this;
        lastFocusEvent = evt;
    }

    /**
     * Delivers a defered focusLost event to this caret.
     */
    protected void hide() {
        if (last == this) {
            super.focusLost(lastFocusEvent);
            last = null;
            lastFocusEvent = null;
        }
    }
}


Refer the below link
http://javatechniques.com/blog/fixing-disappearing-text-selections-when-a-menu-is-opened/

Tuesday, May 28, 2013

Image Cache for JEditorPane/JTextPane to avoid flickering




public static void doImageCahce(JEditorPane edit) {
        try {
            Dictionary cache = (Dictionary) edit.getDocument().getProperty("imageCache");
            if (cache == null) {
                cache = new Hashtable();
                edit.getDocument().putProperty("imageCache", cache);
            }
            List icons = new ArrayList();
            ImageIcon icon1 = UIStorage.getImageCollectionBean().get("1.png");
            icons.add(icon1);
            ImageIcon icon2 = UIStorage.getImageCollectionBean().get("2.png");
            icons.add(icon2);
            ImageIcon icon3 = UIStorage.getImageCollectionBean().get("3.jpg");
            icons.add(icon3);
            ImageIcon icon4 = UIStorage.getImageCollectionBean().get("4.png");
            icons.add(icon4);
           
            for (ImageIcon imageIcon : icons) {
                URL u = new URL(imageIcon.toString());
                cache.put(u, imageIcon.getImage());
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

Thursday, May 23, 2013

JasperReport HtmlComponent Real Size Issue Fixed












<![CDATA[]]>


<![CDATA[content]]>


<![CDATA[footNote]]>






<![CDATA["[See sub-section (3) of Section 1]
S.No.Name of DistrictArea
(1)(2)(3)
1.GwaliorGwalior Division
Gwalior Corporation Area
"]]>





<![CDATA[($F{footNote} != null && !$F{footNote}.trim().isEmpty())]]>








<![CDATA[$F{footNote}]]>






Wednesday, May 22, 2013

Apache Lucene Search Word Highlighter use LIKE wildcard




public static String highlightField(String searchField, String searchWord,  String text) throws Exception {
        QueryParser parser = new QueryParser(Version.LUCENE_42, searchField, analyzer);
        parser.setAllowLeadingWildcard(true);
        Query query = parser.parse("*"+searchWord+"*");

        TokenStream tokenStream = analyzer.tokenStream(searchField, new StringReader(text));

        // Assuming "", "" used to highlight
        SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("", ""); // #F8B270 - Orange
        //SimpleHTMLFormatter formatter = new SimpleHTMLFormatter();
        MyQueryScorer scorer = new MyQueryScorer(query, searchField, searchField);
        Highlighter highlighter = new Highlighter(formatter, scorer);
        highlighter.setTextFragmenter(new SimpleFragmenter(Integer.MAX_VALUE));

        String rv = highlighter.getBestFragments(tokenStream, text, 1, "");
        //String rv = highlighter.getBestFragments(tokenStream, text, 1, "(FIELD TEXT TRUNCATED)");
        return (rv == null || rv.trim().isEmpty()) ? text : rv;
    }


public static class MyWeightedSpanTermExtractor extends WeightedSpanTermExtractor {

        public MyWeightedSpanTermExtractor() {
            super();
        }

        public MyWeightedSpanTermExtractor(String defaultField) {
            super(defaultField);
        }

        @Override
        protected void extractUnknownQuery(Query query,
                Map terms) throws IOException {
            if (query instanceof CustomQuery) {
                extractWeightedTerms(terms, new TermQuery(((CustomQuery) query).term));
            }
        }
    }

    public static class MyQueryScorer extends QueryScorer {

        public MyQueryScorer(Query query, String field, String defaultField) {
            super(query, field, defaultField);
        }

        @Override
        protected WeightedSpanTermExtractor newTermExtractor(String defaultField) {
            return defaultField == null ? new MyWeightedSpanTermExtractor()
                    : new MyWeightedSpanTermExtractor(defaultField);
        }
    }

    public static class CustomQuery extends Query {

        private final Term term;

        public CustomQuery(Term term) {
            super();
            this.term = term;
        }

        @Override
        public String toString(String field) {
            return new TermQuery(term).toString(field);
        }

        @Override
        public Query rewrite(IndexReader reader) throws IOException {
            return new TermQuery(term);
        }

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = super.hashCode();
            result = prime * result + ((term == null) ? 0 : term.hashCode());
            return result;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!super.equals(obj)) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            CustomQuery other = (CustomQuery) obj;
            if (term == null) {
                if (other.term != null) {
                    return false;
                }
            } else if (!term.equals(other.term)) {
                return false;
            }
            return true;
        }
    }


Monday, May 20, 2013

GradientJTextPane as TableCellRenderer with HTML Tooltip




public class GradientTextPane extends JTextPane {

    private transient Position.Bias[] bias = new Position.Bias[1];

    /**
     * Creates new form GradientLabel
     */
    public GradientTextPane() {
        initComponents();
    }

    public void setBgColor(Color bgColor) {
        start = bgColor;
        repaint();
    }

    @Override
    public String getToolTipText(MouseEvent e) {
        String title = super.getToolTipText(e);
        JTextPane editor = (JTextPane) e.getSource();
        if (!editor.isEditable()) {
            Point pt = e.getPoint();
            int pos = editor.getUI().viewToModel(editor, pt, bias);
            if (bias[0] == Position.Bias.Backward && pos > 0) {
                pos--;
            }
            if (pos >= 0 && (editor.getDocument() instanceof HTMLDocument)) {
                HTMLDocument hdoc = (HTMLDocument) editor.getDocument();
                Element elem = hdoc.getCharacterElement(pos);
                if (elem != null) {
                    AttributeSet a = elem.getAttributes();
                    //AttributeSet span = (AttributeSet) a.getAttribute(HTML.Tag.SPAN);
                    if (a != null) {
                        title = (String) a.getAttribute(HTML.Attribute.TITLE);
                    }
                }
            }
        }
        return title;
    }

    @Override
    public void paint(Graphics g) {
        int width = getWidth();
        int height = getHeight();

        colors[0] = start;
        colors[1] = start.brighter();
        colors[2] = start;
        // Create the gradient paint
        //GradientPaint paint = new GradientPaint(0, 0, start, width, height, end, true);

        LinearGradientPaint paint = new LinearGradientPaint(0, 0, 0, getHeight(), dist, colors);

        // we need to cast to Graphics2D for this operation
        Graphics2D g2d = (Graphics2D) g;

        // save the old paint
        Paint oldPaint = g2d.getPaint();

        // set the paint to use for this operation
        g2d.setPaint(paint);

        // fill the background using the paint
        g2d.fillRect(0, 0, width, height);

        // restore the original paint
        g2d.setPaint(oldPaint);

        super.paint(g);
    }

    /**
     * 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() {

        setOpaque(true);
    }//
//GEN-END:initComponents    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    private Color start;
    float[] dist = {0.0f, 0.5f, 1.0f};
    private Color[] colors = new Color[3];
}



Sunday, May 19, 2013

Round Robin in JAVA




  1. package test;  
  2.    
  3. import java.util.ArrayList;  
  4. import java.util.Iterator;  
  5. import java.util.List;  
  6.    
  7. import junit.framework.TestCase;  
  8.    
  9. class Robin {  
  10. private int i;  
  11.    
  12. public Robin(int i) {  
  13. this.i = i;  
  14. }  
  15.    
  16. public int call() {  
  17. return i;  
  18. }  
  19. }  
  20.    
  21. class RoundRobin {  
  22. private Iterator it;  
  23. private List list;  
  24.    
  25. public RoundRobin(List list) {  
  26. this.list = list;  
  27. it = list.iterator();  
  28. }  
  29.   
  30. public int next() {  
  31. // if we get to the end, start again  
  32. if (!it.hasNext()) {  
  33. it = list.iterator();  
  34. }  
  35. Robin robin = it.next();  
  36.   
  37. return robin.call();  
  38. }  
  39. }  
  40.    
  41. public class RoundRobinTest extends TestCase {  
  42. List items = new ArrayList();  
  43. RoundRobin round;  
  44.   
  45. public void testOne() {  
  46. items.add(new Robin(1));  
  47. round = new RoundRobin(items);  
  48. assertEquals(1, round.next());  
  49. assertEquals(1, round.next());  
  50. }  
  51.   
  52. public void testTwo() {  
  53. items.add(new Robin(1));  
  54. items.add(new Robin(2));  
  55. round = new RoundRobin(items);  
  56. assertEquals(1, round.next());  
  57. assertEquals(2, round.next());  
  58. assertEquals(1, round.next());  
  59. assertEquals(2, round.next());  
  60. }  
  61.   
  62. public void testThree() {  
  63. items.add(new Robin(1));  
  64. items.add(new Robin(2));  
  65. items.add(new Robin(3));  
  66. round = new RoundRobin(items);  
  67. assertEquals(1, round.next());  
  68. assertEquals(2, round.next());  
  69. assertEquals(3, round.next());  
  70. assertEquals(1, round.next());  
  71. assertEquals(2, round.next());  
  72. assertEquals(3, round.next());  
  73. }  
  74. }  

Wednesday, May 8, 2013

JTextField Auto Completion






/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package text;


import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
import javax.swing.event.*;

public class TextFileAutoComplete {

    public static void main(String[] args) throws Exception {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        JFrame frame = new JFrame();
        frame.setTitle("Auto Completion Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBounds(200, 200, 500, 400);

        ArrayList items = new ArrayList();
        Locale[] locales = Locale.getAvailableLocales();
        for (int i = 0; i < locales.length; i++) {
            String item = locales[i].getDisplayName();
            items.add(item);
        }
        JTextField txtInput = new JTextField();
        setupAutoComplete(txtInput, items);
        txtInput.setColumns(30);
        frame.getContentPane().setLayout(new FlowLayout());
        frame.getContentPane().add(txtInput, BorderLayout.NORTH);
        frame.setVisible(true);
    }

    private static boolean isAdjusting(JComboBox cbInput) {
        if (cbInput.getClientProperty("is_adjusting") instanceof Boolean) {
            return (Boolean) cbInput.getClientProperty("is_adjusting");
        }
        return false;
    }

    private static void setAdjusting(JComboBox cbInput, boolean adjusting) {
        cbInput.putClientProperty("is_adjusting", adjusting);
    }

    public static void setupAutoComplete(final JTextField txtInput, final List items) {
        final DefaultComboBoxModel model = new DefaultComboBoxModel();
        final JComboBox cbInput = new JComboBox(model) {
            public Dimension getPreferredSize() {
                return new Dimension(super.getPreferredSize().width, 0);
            }
        };
        setAdjusting(cbInput, false);
        for (String item : items) {
            model.addElement(item);
        }
        cbInput.setSelectedItem(null);
        cbInput.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (!isAdjusting(cbInput)) {
                    if (cbInput.getSelectedItem() != null) {
                        txtInput.setText(cbInput.getSelectedItem().toString());
                    }
                }
            }
        });

        txtInput.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                setAdjusting(cbInput, true);
                if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                    if (cbInput.isPopupVisible()) {
                        e.setKeyCode(KeyEvent.VK_ENTER);
                    }
                }
                if (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_DOWN) {
                    e.setSource(cbInput);
                    cbInput.dispatchEvent(e);
                    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                        txtInput.setText(cbInput.getSelectedItem().toString());
                        cbInput.setPopupVisible(false);
                    }
                }
                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                    cbInput.setPopupVisible(false);
                }
                setAdjusting(cbInput, false);
            }
        });
        txtInput.getDocument().addDocumentListener(new DocumentListener() {
            public void insertUpdate(DocumentEvent e) {
                updateList();
            }

            public void removeUpdate(DocumentEvent e) {
                updateList();
            }

            public void changedUpdate(DocumentEvent e) {
                updateList();
            }

            private void updateList() {
                setAdjusting(cbInput, true);
                model.removeAllElements();
                String input = txtInput.getText();
                if (!input.isEmpty()) {
                    for (String item : items) {
                        if (item.toLowerCase().startsWith(input.toLowerCase())) {
                            model.addElement(item);
                        }
                    }
                }
                cbInput.setPopupVisible(model.getSize() > 0);
                setAdjusting(cbInput, false);
            }
        });
        txtInput.setLayout(new BorderLayout());
        txtInput.add(cbInput, BorderLayout.SOUTH);
    }
}

Monday, May 6, 2013

JTable with GradiantColorTableCellRenderer

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package text;


public class ResultViewTableJPanel extends javax.swing.JPanel {

    /**
     * Creates new form ResultViewTableJPanel
     */
    public ResultViewTableJPanel() {
        initComponents();
    }

    public void init() {
        for (int i = 0; i < resultTable.getColumnCount(); i++) {
            resultTable.getColumnModel().getColumn(i).setCellRenderer(new TableCellRenderer());
        }        
        resultTable.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                // Open popup
                            } catch (Exception ex) {
                                ex.printStackTrace();
                            }
                        }
                    });
                }
            }
        });
    }

    public void searchResult(final BasicSearchInfoParam basicSearchInfoParam) {
        resultList.clear();
        bottomPanel.removeAll();
        bottomPanel.add(progressPanel, BorderLayout.CENTER);
        bottomPanel.validate();
        bottomPanel.repaint();

        SwingWorker sw = new SwingWorker() {
            @Override
            protected Object doInBackground() throws Exception {
                Thread.sleep(200);
                // Fill resultList with beans
                int start = 0;
                if (!resultList.isEmpty()) {
                    start = QuickSearch.getFrom() + 1;

                    int count = quickSearch.getScoreDocsArray().length;
                    if (quickSearch.getPage() > 1) {
                        previousButton.setEnabled(true);
                    } else {
                        previousButton.setEnabled(false);
                    }
                    if ((quickSearch.getTotalPages() - quickSearch.getPage()) > 0) {
                        nextButton.setEnabled(true);
                    } else {
                        nextButton.setEnabled(false);
                    }

                    resultCountLabel.setText("Showing results from " + start + " to " + (caseQuickSearch.getEnd())
                            + " of " + count + "");
                } else {
                    resultCountLabel.setText(" No results found.");
                }
                return true;
            }

            @Override
            protected void done() {
                super.done();
                try {
                    get();
                } catch (Exception e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(IndLawExecutor.getSingleInstance(), "Exception : " + e.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
                } finally {
                    bottomPanel.removeAll();
                    bottomPanel.add(navigationPanel, BorderLayout.CENTER);
                    bottomPanel.validate();
                    bottomPanel.repaint();
                }
            }
        };
        Executors.newCachedThreadPool().submit(sw);
    }

    private void displayResult(final String action) {
        resultList.clear();
        bottomPanel.removeAll();
        bottomPanel.add(progressPanel, BorderLayout.CENTER);
        bottomPanel.validate();
        bottomPanel.repaint();

        SwingWorker sw = new SwingWorker() {
            @Override
            protected Object doInBackground() throws Exception {
                Thread.sleep(200);
                CaseQuickSearch caseQuickSearch = CaseQuickSearch.getInstance();
                caseQuickSearch.loadNavigationDocs(action, resultList);
                int start = 0;
                if (!resultList.isEmpty()) {
                    start = caseQuickSearch.getFrom() + 1;

                    int count = caseQuickSearch.getScoreDocsArray().length;
                    if (caseQuickSearch.getPage() > 1) {
                        previousButton.setEnabled(true);
                    } else {
                        previousButton.setEnabled(false);
                    }
                    if ((caseQuickSearch.getTotalPages() - caseQuickSearch.getPage()) > 0) {
                        nextButton.setEnabled(true);
                    } else {
                        nextButton.setEnabled(false);
                    }
                    resultCountLabel.setText("Showing results from " + start + " to " + (caseQuickSearch.getEnd())
                            + " of " + count + "");

                } else {
                    resultCountLabel.setText(" No results found.");
                }
                return true;
            }

            @Override
            protected void done() {
                super.done();
                try {
                    get();
                } catch (Exception e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(IndLawExecutor.getSingleInstance(), "Exception : " + e.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
                } finally {
                    bottomPanel.removeAll();
                    bottomPanel.add(navigationPanel, BorderLayout.CENTER);
                    bottomPanel.validate();
                    bottomPanel.repaint();
                }
            }
        };
        Executors.newCachedThreadPool().submit(sw);
    }

    /**
     * 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 _tableLayoutInstance2;
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        resultList = org.jdesktop.observablecollections.ObservableCollections.observableList(new ArrayList());
        progressPanel = new javax.swing.JPanel();
        progressLabel = new javax.swing.JLabel();
        navigationPanel = new javax.swing.JPanel();
        verticalDividerLabel = new javax.swing.JLabel();
        resultCountLabel = new javax.swing.JLabel();
        previousButton = new javax.swing.JButton();
        nextButton = new javax.swing.JButton();
        resultBasePanel = new javax.swing.JPanel();
        resultScrollPane = new javax.swing.JScrollPane();
        resultTable = new javax.swing.JTable();
        hDividerLabel = new javax.swing.JLabel();
        bottomPanel = new javax.swing.JPanel();

        progressPanel.setOpaque(false);
        progressPanel.setLayout(new java.awt.BorderLayout());

        progressLabel.setFont(new java.awt.Font("Times New Roman", 1, 16)); // NOI18N
        progressLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        progressLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/ajax-loader4_30x30.gif"))); // NOI18N
        progressLabel.setText("Processing...");
        progressPanel.add(progressLabel, java.awt.BorderLayout.CENTER);

        navigationPanel.setBackground(new java.awt.Color(192, 192, 192));
        _tableLayoutInstance2 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance2.setHGap(10);
        _tableLayoutInstance2.setVGap(0);
        _tableLayoutInstance2.setColumn(new double[]{1,info.clearthought.layout.TableLayout.PREFERRED,info.clearthought.layout.TableLayout.FILL,34,34,0});
        _tableLayoutInstance2.setRow(new double[]{info.clearthought.layout.TableLayout.FILL,28,info.clearthought.layout.TableLayout.FILL,7});
        navigationPanel.setLayout(_tableLayoutInstance2);

        verticalDividerLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/hori-dividerLong.png"))); // NOI18N
        navigationPanel.add(verticalDividerLabel, new info.clearthought.layout.TableLayoutConstraints(0, 3, 5, 3, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        resultCountLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        resultCountLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        navigationPanel.add(resultCountLabel, new info.clearthought.layout.TableLayoutConstraints(1, 1, 1, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        previousButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/previous_small.png"))); // NOI18N
        previousButton.setToolTipText("Previous");
        previousButton.setContentAreaFilled(false);
        previousButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        previousButton.setEnabled(false);
        previousButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                previousButtonActionPerformed(evt);
            }
        });
        navigationPanel.add(previousButton, new info.clearthought.layout.TableLayoutConstraints(3, 1, 3, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        nextButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/next_small.png"))); // NOI18N
        nextButton.setToolTipText("Next");
        nextButton.setContentAreaFilled(false);
        nextButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        nextButton.setEnabled(false);
        nextButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextButtonActionPerformed(evt);
            }
        });
        navigationPanel.add(nextButton, new info.clearthought.layout.TableLayoutConstraints(4, 1, 4, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        setOpaque(false);
        _tableLayoutInstance = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance.setHGap(0);
        _tableLayoutInstance.setVGap(0);
        _tableLayoutInstance.setColumn(new double[]{info.clearthought.layout.TableLayout.FILL});
        _tableLayoutInstance.setRow(new double[]{info.clearthought.layout.TableLayout.FILL});
        setLayout(_tableLayoutInstance);

        resultBasePanel.setOpaque(false);
        _tableLayoutInstance1 = new info.clearthought.layout.TableLayout();
        _tableLayoutInstance1.setHGap(0);
        _tableLayoutInstance1.setVGap(0);
        _tableLayoutInstance1.setColumn(new double[]{info.clearthought.layout.TableLayout.FILL});
        _tableLayoutInstance1.setRow(new double[]{info.clearthought.layout.TableLayout.FILL,info.clearthought.layout.TableLayout.PREFERRED,50});
        resultBasePanel.setLayout(_tableLayoutInstance1);

        Border empty = new EmptyBorder(0,0,0,0);
        //resultScrollPane.setBorder(empty);
        resultScrollPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        resultScrollPane.getViewport().setOpaque(false);
        //resultScrollPane.getViewport().setBorder(null);
        resultScrollPane.setOpaque(false);

        //resultTable.setShowGrid(false);
        resultTable.setBorder(null);
        resultTable.setTableHeader(null);
        resultTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        resultTable.setOpaque(false);
        resultTable.setRowHeight(70);
        resultTable.setShowVerticalLines(false);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, resultList, resultTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${caseId}"));
        columnBinding.setColumnName("Case Id");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        resultScrollPane.setViewportView(resultTable);

        resultBasePanel.add(resultScrollPane, new info.clearthought.layout.TableLayoutConstraints(0, 0, 0, 0, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        hDividerLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/hori-dividerLongR.png"))); // NOI18N
        resultBasePanel.add(hDividerLabel, new info.clearthought.layout.TableLayoutConstraints(0, 1, 0, 1, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

        bottomPanel.setOpaque(false);
        bottomPanel.setLayout(new java.awt.BorderLayout());
        resultBasePanel.add(bottomPanel, new info.clearthought.layout.TableLayoutConstraints(0, 2, 0, 2, info.clearthought.layout.TableLayout.FULL, info.clearthought.layout.TableLayout.FULL));

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

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

    private void previousButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_previousButtonActionPerformed
        // TODO add your handling code here:
        displayResult("previous");
    }//GEN-LAST:event_previousButtonActionPerformed

    private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextButtonActionPerformed
        // TODO add your handling code here:
        displayResult("next");
    }//GEN-LAST:event_nextButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel bottomPanel;
    private javax.swing.JLabel hDividerLabel;
    private javax.swing.JPanel navigationPanel;
    private javax.swing.JButton nextButton;
    private javax.swing.JButton previousButton;
    private javax.swing.JLabel progressLabel;
    private javax.swing.JPanel progressPanel;
    private javax.swing.JPanel resultBasePanel;
    private javax.swing.JLabel resultCountLabel;
    private java.util.List resultList;
    private javax.swing.JScrollPane resultScrollPane;
    private javax.swing.JTable resultTable;
    private javax.swing.JLabel verticalDividerLabel;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    private class CaseTableCellRenderer extends GradientLabel implements TableCellRenderer {

        private Color normalColor = new Color(211, 211, 211);
        public CaseTableCellRenderer() {
            setVerticalAlignment(JLabel.TOP);
            setOpaque(false);
            setBgColor(normalColor);
        }

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            SearchDisplayBean bean = resultList.get(table.convertRowIndexToModel(row));
            setText("" + bean.getDisplayText());
            if (isSelected) {
                setBgColor(table.getSelectionBackground());
            }else{
                setBgColor(normalColor);
            }
            if ((bean.getPetitioner().length() > 50) || (bean.getRespondent().length() > 50)) {
                setToolTipText(bean.getToolTipText());
            } else {
                setToolTipText(null);
            }
            return this;
        }
    }
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tr.indlaw.design.resultView;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.LinearGradientPaint;
import java.awt.Paint;
import javax.swing.JLabel;

public class GradientLabel extends JLabel {

    /**
     * Creates new form GradientLabel
     */
    public GradientLabel() {
        initComponents();
    }

    public void setBgColor(Color bgColor) {
        start = bgColor;
        repaint();
    }
    
    @Override
    public void paint(Graphics g) {
        int width = getWidth();
        int height = getHeight();
        
        colors[0] = start;
        colors[1] = start.brighter();
        colors[2] = start;
        // Create the gradient paint
        //GradientPaint paint = new GradientPaint(0, 0, start, width, height, end, true);

        LinearGradientPaint paint = new LinearGradientPaint(0, 0, 0, getHeight(), dist, colors);

        // we need to cast to Graphics2D for this operation
        Graphics2D g2d = (Graphics2D) g;

        // save the old paint
        Paint oldPaint = g2d.getPaint();

        // set the paint to use for this operation
        g2d.setPaint(paint);

        // fill the background using the paint
        g2d.fillRect(0, 0, width, height);

        // restore the original paint
        g2d.setPaint(oldPaint);

        super.paint(g);
    }

    /**
     * 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() {

        setOpaque(true);
    }// //GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    private Color start;
    float[] dist = {0.0f, 0.5f, 1.0f};
    private Color[] colors = new Color[3];
}

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; } } }