Example usage for java.awt Cursor Cursor

List of usage examples for java.awt Cursor Cursor

Introduction

In this page you can find the example usage for java.awt Cursor Cursor.

Prototype

protected Cursor(String name) 

Source Link

Document

Creates a new custom cursor object with the specified name.

Note: this constructor should only be used by AWT implementations as part of their support for custom cursors.

Usage

From source file:com.josescalia.tumblr.form.PreferenceForm.java

private void btnCleanLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCleanLogActionPerformed
    frame = (MainFrame) this.getTopLevelAncestor();
    if (UIAlert.showConfirm(this, "Are you sure ?") == JOptionPane.OK_OPTION) {
        logger.info("deleting log file");
        //busy cursor and progress bar
        frame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
        frame.startProgressBar("Deleting");

        //background process
        new SwingWorker<String, String>() {
            @Override//from w w  w. ja  v a  2 s  .  c  om
            protected String doInBackground() throws Exception {
                int successDeleteCount = 0;
                int failedDeleteCount = 0;
                for (File file : logFile.getFileList()) {
                    logger.info(file.getName());
                    if (!file.getName().equalsIgnoreCase(Bootstrap.applicationLog)
                            && !file.getName().equalsIgnoreCase(Bootstrap.applicationErrorLog)) {
                        if (file.delete()) {
                            successDeleteCount++;
                        } else {
                            failedDeleteCount++;
                        }
                    }
                }
                return "Done\n " + successDeleteCount + " log file(s) deleted\n" + failedDeleteCount
                        + " log file(s) not deleted";
            }

            @Override
            protected void done() {
                try {
                    UIAlert.showInformation(null, get());
                } catch (InterruptedException e) {
                    logger.error(e);
                } catch (ExecutionException e) {
                    logger.error(e);
                }
                setupLogFileInfo();
                frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                frame.stopProgressBar("");
            }
        }.execute();
    }

}

From source file:us.paulevans.basicxslt.BasicXSLTFrame.java

/**
 * Entry point of threads.//from   w w w.j  a v a2  s  .  c  o  m
 */
public void run() {

    String sresultsFile;
    File xmlFile, resultsFile;
    byte results[];

    try {
        switch (threadMode) {
        case THREADMODE_DO_TRANSFORM:
            executeTransform();
            break;
        case THREADMODE_DO_VALIDATE:
            validateXml(label, textField, suppressSuccessDialog);
            break;
        case THREADMODE_DO_XML_IDENTITY_TRANSFORM:
            xmlFile = new File(identityTransformSourceXmlFile);
            sresultsFile = (String) JOptionPane.showInputDialog(this, identityTransformMessage,
                    stringFactory.getString(LabelStringFactory.MAIN_FRAME_IDENTITY_TRANSFORM),
                    JOptionPane.QUESTION_MESSAGE, null, null, identityTransformResultXmlFile);
            if (sresultsFile != null) {
                resultsFile = new File(sresultsFile);
                resultsFile.getParentFile().mkdirs();
                results = XMLUtils.transform(xmlFile, xmlIdentityTransformOutputProps);
                IOUtils.writeFile(resultsFile, results);
            }
            break;
        }
    } catch (Throwable aAny) {
        logger.error(ExceptionUtils.getFullStackTrace(aAny));
        Utils.showErrorDialog(this, aAny);
    } finally {
        Utils.setEnabled(components, true);
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}

From source file:simMPLS.ui.simulator.JVentanaHija.java

/**
 * Este mtodo se llama cuando se presiona un botn del ratn en el panel de
 * simulacin. Si se hace sobre un elemento de la topologa, lo marca como
 * seleccionado.//from  w w w  . ja v a2 s. com
 * When the mouse button is pressed on a node
 * @since 1.0
 * @param evt El evento que provoca la llamada.
 */
private void clicEnPanelSimulacion(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clicEnPanelSimulacion
    if (evt.getButton() == MouseEvent.BUTTON1) {
        TTopology topo = escenario.getTopology();
        TTopologyElement et = topo.obtenerElementoEnPosicion(evt.getPoint());
        if (et != null) {
            this.setCursor(new Cursor(Cursor.HAND_CURSOR));
            if (et.getElementType() == TTopologyElement.NODO) {
                TNode nt = (TNode) et;
                nodoSeleccionado = nt;
                if (nodoSeleccionado != null) {
                    nodoSeleccionado.setStatus(TNode.SELECCIONADO);
                    this.escenario.setModified(true);
                }
            }
        } else {
            this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            this.setToolTipText(null);
        }
        panelSimulacion.repaint();
    }
}

From source file:com.josescalia.tumblr.form.PreferenceForm.java

private void btnSelectLFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectLFActionPerformed
    this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    LookAndFeelDialog dlg = new LookAndFeelDialog(null, true);
    dlg.showDialog();//  w  w w.j  a  va2  s.c  o m
    dlg.setVisible(true);
    this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    String lAndF = dlg.getLookAndFeel().getLookAndFeelValue();
    if (lAndF != null) {
        txtAppLookAndFeel.setText(lAndF);
    }

}

From source file:com.josescalia.tumblr.form.PreferenceForm.java

private void btnDeleteCacheActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteCacheActionPerformed
    frame = (MainFrame) this.getTopLevelAncestor();

    if (UIAlert.showConfirm(this, "Are you sure ?") == JOptionPane.OK_OPTION) {
        logger.info("deleting cache");

        //busy cursor and frame progress bar
        frame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
        frame.startProgressBar("Deleting");
        new SwingWorker<String, String>() {
            @Override// ww  w. j  av a 2  s  . c o m
            protected String doInBackground() throws Exception {
                int successDeleteCount = 0;
                int failedDeleteCount = 0;
                for (File file : cacheFile.getFileList()) {
                    if (!file.getName().contains("ImageNotFound")) {
                        logger.info("deleting file " + file.getName());
                        if (file.delete()) {
                            successDeleteCount++;
                        } else {
                            failedDeleteCount++;
                        }
                    }
                }
                return "Done\n " + successDeleteCount + " cache file(s) deleted\n" + failedDeleteCount
                        + " cache  file(s) not deleted";
            }

            @Override
            protected void done() {
                try {
                    UIAlert.showInformation(null, get());
                    getCacheFileInfo();
                } catch (InterruptedException e) {
                    logger.error(e);
                } catch (ExecutionException e) {
                    logger.error(e);
                }
                frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                frame.stopProgressBar("");
            }
        }.execute();

    }

}

From source file:org.earthtime.UPb_Redux.dateInterpretation.WeightedMeanGraphPanel.java

/**
 *
 * @param imageMode//from  w ww .j  av a2  s  . co  m
 */
public void setImageMode(String imageMode) {
    this.imageMode = imageMode;
    if (imageMode.equalsIgnoreCase("PAN")) {
        weightedMeanCursor = new Cursor((Cursor.HAND_CURSOR));
    } else if (imageMode.equalsIgnoreCase("ZOOM")) {
        weightedMeanCursor = new Cursor((Cursor.CROSSHAIR_CURSOR));
    }
    // force issue
    setCursor(weightedMeanCursor);
}

From source file:Installer.java

public static JLabel linkify(final String text, String URL, String toolTip) {
    URI temp = null;//from  w  w  w  . jav  a 2s  .  c  o m
    try {
        temp = new URI(URL);
    } catch (Exception e) {
        e.printStackTrace();
    }
    final URI uri = temp;
    final JLabel link = new JLabel();
    link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>");
    if (!toolTip.equals(""))
        link.setToolTipText(toolTip);
    link.setCursor(new Cursor(Cursor.HAND_CURSOR));
    link.addMouseListener(new MouseListener() {
        public void mouseExited(MouseEvent arg0) {
            link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>");
        }

        public void mouseEntered(MouseEvent arg0) {
            link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>");
        }

        public void mouseClicked(MouseEvent arg0) {
            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(uri);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                JOptionPane pane = new JOptionPane("Could not open link.");
                JDialog dialog = pane.createDialog(new JFrame(), "");
                dialog.setVisible(true);
            }
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseReleased(MouseEvent e) {
        }
    });
    return link;
}

From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equalsIgnoreCase("Rename ...")) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) {

            QueryMasterData ndata = (QueryMasterData) node.getUserObject();
            Object inputValue = JOptionPane.showInputDialog(this, "Rename this query to: ",
                    "Rename Query Dialog", JOptionPane.PLAIN_MESSAGE, null, null,
                    ndata.name().substring(0, ndata.name().indexOf("[") - 1));

            if (inputValue != null) {
                String newQueryName = (String) inputValue;
                String requestXml = ndata.writeRenameQueryXML(newQueryName);

                setCursor(new Cursor(Cursor.WAIT_CURSOR));

                String response = null;
                if (System.getProperty("webServiceMethod").equals("SOAP")) {
                    // TO DO
                    // response =
                    // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
                } else {
                    response = QueryListNamesClient.sendQueryRequestREST(requestXml);
                }/*from  w w  w.j a v a 2  s .c om*/

                if (response.equalsIgnoreCase("CellDown")) {
                    final JPanel parent = this;
                    java.awt.EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            JOptionPane.showMessageDialog(parent,
                                    "Trouble with connection to the remote server, "
                                            + "this is often a network error, please try again",
                                    "Network Error", JOptionPane.INFORMATION_MESSAGE);
                        }
                    });
                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                    return;
                }

                if (response != null) {
                    JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                    try {
                        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                        StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                        String status = statusType.getType();

                        if (status.equalsIgnoreCase("DONE")) {
                            // XMLGregorianCalendar cldr =
                            // //queryMasterType.getCreateDate();
                            Calendar cldr = Calendar.getInstance(Locale.getDefault());
                            ndata.name(newQueryName + " [" + addZero(cldr.get(Calendar.MONTH) + 1) + "-"
                                    + addZero(cldr.get(Calendar.DAY_OF_MONTH)) + "-"
                                    + addZero(cldr.get(Calendar.YEAR)) + " ]" + " [" + ndata.userId() + "]");
                            // ndata.name(newQueryName + " [" +
                            // ndata.userId()
                            // + "]");
                            node.setUserObject(ndata);
                            // DefaultMutableTreeNode parent =
                            // (DefaultMutableTreeNode) node.getParent();

                            jTree1.repaint();
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryResultData")) {

            QueryResultData rdata = (QueryResultData) node.getUserObject();
            // if(!rdata.type().equalsIgnoreCase("PatientSet")) {
            // return;
            // }

            Object inputValue1 = JOptionPane.showInputDialog(this, "Rename this to: ", "Renaming Dialog",
                    JOptionPane.PLAIN_MESSAGE, null, null, rdata.name());
            // .substring(0, rdata.name().lastIndexOf("[") - 1));

            if (inputValue1 != null) {
                String newQueryName = (String) inputValue1;
                String requestXml = rdata.writeRenameQueryXML(newQueryName);

                setCursor(new Cursor(Cursor.WAIT_CURSOR));

                String response = null;
                if (System.getProperty("webServiceMethod").equals("SOAP")) {
                    // TO DO
                    // response =
                    // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
                } else {
                    response = QueryListNamesClient.sendQueryRequestREST(requestXml);
                }

                if (response.equalsIgnoreCase("CellDown")) {
                    final JPanel parent = this;
                    java.awt.EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            JOptionPane.showMessageDialog(parent,
                                    "Trouble with connection to the remote server, "
                                            + "this is often a network error, please try again",
                                    "Network Error", JOptionPane.INFORMATION_MESSAGE);

                        }
                    });
                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                    return;
                }

                if (response != null) {
                    JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                    try {
                        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                        StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                        String status = statusType.getType();

                        if (status.equalsIgnoreCase("DONE")) {
                            rdata.name(newQueryName);// + " [" +
                            // rdata.userId()
                            // + "]");
                            node.setUserObject(rdata);
                            // DefaultMutableTreeNode parent =
                            // (DefaultMutableTreeNode) node.getParent();

                            jTree1.repaint();
                        } else {
                            final String tmp = response;
                            final JPanel parent = this;
                            java.awt.EventQueue.invokeLater(new Runnable() {
                                public void run() {
                                    JOptionPane.showMessageDialog(parent,
                                            "Error message delivered from the remote server, "
                                                    + "you may wish to retry your last action",
                                            "Server Error", JOptionPane.INFORMATION_MESSAGE);
                                    log.error(tmp);
                                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                                }

                            });

                            return;
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    } else if (e.getActionCommand().equalsIgnoreCase("Cancel")) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) {
            DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getFirstChild();
            if (node1.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent, "Please expand this node then try to cancel it.",
                                "Message", JOptionPane.INFORMATION_MESSAGE);

                    }
                });
                return;
            }
            QueryInstanceData rdata = (QueryInstanceData) node1.getUserObject();

            String requestXml = rdata.writeCancelQueryXML();

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            String response = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                // TO DO
                // response =
                // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
            } else {
                response = QueryListNamesClient.sendQueryRequestREST(requestXml);
            }

            if (response.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);

                    }
                });
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }

            if (response != null) {
                JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();
                    final JPanel parent = this;
                    if (status.equalsIgnoreCase("DONE")) {
                        java.awt.EventQueue.invokeLater(new Runnable() {
                            public void run() {
                                JOptionPane.showMessageDialog(parent, "The query is finished.", "Message",
                                        JOptionPane.INFORMATION_MESSAGE);
                                // log.error(tmp);
                                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                            }

                        });
                        rdata.name(rdata.name().substring(0, rdata.name().indexOf("-")));// + " [" +
                        // rdata
                        // .userId()
                        // + "]");
                        node.setUserObject(rdata);
                        // DefaultMutableTreeNode parent =
                        // (DefaultMutableTreeNode) node.getParent();

                        jTree1.repaint();
                    } else {
                        final String tmp = response;
                        // final JPanel parent = this;
                        java.awt.EventQueue.invokeLater(new Runnable() {
                            public void run() {
                                JOptionPane.showMessageDialog(parent,
                                        "Error message delivered from the remote server, "
                                                + "you may wish to retry your last action",
                                        "Server Error", JOptionPane.INFORMATION_MESSAGE);
                                log.error(tmp);
                                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                            }

                        });

                        return;
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                // }
            }
        } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryInstanceData")) {

            QueryInstanceData rdata = (QueryInstanceData) node.getUserObject();

            String requestXml = rdata.writeCancelQueryXML();

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            String response = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                // TO DO
                // response =
                // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
            } else {
                response = QueryListNamesClient.sendQueryRequestREST(requestXml);
            }

            if (response.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);

                    }
                });
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }

            if (response != null) {
                JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();
                    final JPanel parent = this;
                    if (status.equalsIgnoreCase("DONE")) {
                        java.awt.EventQueue.invokeLater(new Runnable() {
                            public void run() {
                                JOptionPane.showMessageDialog(parent, "The query is finished.", "Message",
                                        JOptionPane.INFORMATION_MESSAGE);
                                // log.error(tmp);
                                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                            }

                        });
                        rdata.name(rdata.name().substring(0, rdata.name().indexOf("-")));// + " [" +
                        // rdata
                        // .userId()
                        // + "]");
                        node.setUserObject(rdata);
                        // DefaultMutableTreeNode parent =
                        // (DefaultMutableTreeNode) node.getParent();

                        jTree1.repaint();
                    } else {
                        final String tmp = response;
                        // final JPanel parent = this;
                        java.awt.EventQueue.invokeLater(new Runnable() {
                            public void run() {
                                JOptionPane.showMessageDialog(parent,
                                        "Error message delivered from the remote server, "
                                                + "you may wish to retry your last action",
                                        "Server Error", JOptionPane.INFORMATION_MESSAGE);
                                log.error(tmp);
                                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                            }

                        });

                        return;
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                // }
            }
        } else {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {

                public void run() {
                    JOptionPane.showMessageDialog(parent, "Cancel action is not supported on this level",
                            "Message", JOptionPane.INFORMATION_MESSAGE);
                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                }

            });
        }
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    } else if (e.getActionCommand().equalsIgnoreCase("Delete")) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        QueryMasterData ndata = (QueryMasterData) node.getUserObject();
        Object selectedValue = JOptionPane.showConfirmDialog(this, "Delete Query \"" + ndata.name() + "\"?",
                "Delete Query Dialog", JOptionPane.YES_NO_OPTION);
        if (selectedValue.equals(JOptionPane.YES_OPTION)) {
            System.out.println("delete " + ndata.name());
            String requestXml = ndata.writeDeleteQueryXML();
            // System.out.println(requestXml);

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            String response = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                // TO DO
                // response =
                // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
            } else {
                response = QueryListNamesClient.sendQueryRequestREST(requestXml);
            }

            if (response.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);
                    }
                });
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }

            if (response != null) {
                JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();

                    if (status.equalsIgnoreCase("DONE")) {
                        treeModel.removeNodeFromParent(node);

                        // jTree1.repaint();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
    } else if (e.getActionCommand().equalsIgnoreCase("Refresh All")) {
        String status = "";
        if (isManager) {
            status = loadPreviousQueries("all users");
        } else {
            status = loadPreviousQueries(UserInfoBean.getInstance().getUserName());
        }
        if (status.equalsIgnoreCase("")) {
            reset(200, false, false);
        } else if (status.equalsIgnoreCase("CellDown")) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent,
                            "Trouble with connection to the remote server, "
                                    + "this is often a network error, please try again",
                            "Network Error", JOptionPane.INFORMATION_MESSAGE);
                }
            });
        }
    }
}

From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java

public void setPick3DActive(boolean pick3DActive) {

    if (!pick3DActive) {
        this.removeChild(pickObject.getOutObject());
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    } else {//from  w  w  w  . j  a  v  a2s  .  co  m
        this.addChild(pickObject.getOutObject());
        //            setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); // not needed?
        initializeOnceCrosshairCursor();
        setCursor(crosshairCursor);
    }

    this.pickObject.setActive(pick3DActive);

}

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplatePanel.java

private void initComponents() {
    splitPane = new JSplitPane();
    splitPane.setBackground(getBackground());
    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splitPane.setBorder(BorderFactory.createEmptyBorder());
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(//from w  w  w  .j a va  2s .  c  o  m
            Preferences.userNodeForPackage(Mirth.class).getInt("height", UIConstants.MIRTH_HEIGHT) / 3);
    splitPane.setResizeWeight(0.5);

    topPanel = new JPanel();
    topPanel.setBackground(UIConstants.COMBO_BOX_BACKGROUND);

    final CodeTemplateTreeTableCellEditor templateCellEditor = new CodeTemplateTreeTableCellEditor(this);

    templateTreeTable = new MirthTreeTable("CodeTemplate", new HashSet<String>(
            Arrays.asList(new String[] { "Name", "Description", "Revision", "Last Modified" }))) {

        private TreeTableNode selectedNode;

        @Override
        public boolean isCellEditable(int row, int column) {
            return column == TEMPLATE_NAME_COLUMN;
        }

        @Override
        public TableCellEditor getCellEditor(int row, int column) {
            if (isHierarchical(column)) {
                return templateCellEditor;
            } else {
                return super.getCellEditor(row, column);
            }
        }

        @Override
        protected void beforeSort() {
            updateCurrentNode();
            updateCurrentNode.set(false);

            int selectedRow = templateTreeTable.getSelectedRow();
            selectedNode = selectedRow >= 0
                    ? (TreeTableNode) templateTreeTable.getPathForRow(selectedRow).getLastPathComponent()
                    : null;
        }

        @Override
        protected void afterSort() {
            final TreePath selectedPath = selectPathFromNodeId(selectedNode,
                    (CodeTemplateRootTreeTableNode) templateTreeTable.getTreeTableModel().getRoot());
            if (selectedPath != null) {
                selectTemplatePath(selectedPath);
            }

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    if (selectedPath != null) {
                        selectTemplatePath(selectedPath);
                    }
                    updateCurrentNode.set(true);
                }
            });
        }
    };

    DefaultTreeTableModel model = new CodeTemplateTreeTableModel();
    model.setColumnIdentifiers(
            Arrays.asList(new String[] { "Name", "Id", "Type", "Description", "Revision", "Last Modified" }));

    CodeTemplateRootTreeTableNode rootNode = new CodeTemplateRootTreeTableNode();
    model.setRoot(rootNode);

    fullModel = new CodeTemplateTreeTableModel();
    fullModel.setColumnIdentifiers(
            Arrays.asList(new String[] { "Name", "Id", "Type", "Description", "Revision", "Last Modified" }));

    CodeTemplateRootTreeTableNode fullRootNode = new CodeTemplateRootTreeTableNode();
    fullModel.setRoot(fullRootNode);

    templateTreeTable.setColumnFactory(new CodeTemplateTableColumnFactory());
    templateTreeTable.setTreeTableModel(model);
    templateTreeTable.setOpenIcon(null);
    templateTreeTable.setClosedIcon(null);
    templateTreeTable.setLeafIcon(null);
    templateTreeTable.setRootVisible(false);
    templateTreeTable.setDoubleBuffered(true);
    templateTreeTable.setDragEnabled(false);
    templateTreeTable.setRowSelectionAllowed(true);
    templateTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    templateTreeTable.setRowHeight(UIConstants.ROW_HEIGHT);
    templateTreeTable.setFocusable(true);
    templateTreeTable.setOpaque(true);
    templateTreeTable.getTableHeader().setReorderingAllowed(true);
    templateTreeTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    templateTreeTable.setEditable(true);
    templateTreeTable.setSortable(true);
    templateTreeTable.setAutoCreateColumnsFromModel(false);
    templateTreeTable.setShowGrid(true, true);
    templateTreeTable.restoreColumnPreferences();
    templateTreeTable.setMirthColumnControlEnabled(true);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        templateTreeTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    templateTreeTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent evt) {
            checkSelection(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            checkSelection(evt);
        }

        private void checkSelection(MouseEvent evt) {
            int row = templateTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY()));

            if (row < 0) {
                templateTreeTable.clearSelection();
            }

            if (evt.isPopupTrigger()) {
                if (row != -1) {
                    if (!templateTreeTable.isRowSelected(row)) {
                        templateTreeTable.setRowSelectionInterval(row, row);
                    }
                }
                codeTemplatePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
            }
        }
    });

    templateTreeTable.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                TreePath selectedPath = templateTreeTable.getTreeSelectionModel().getSelectionPath();
                if (selectedPath != null) {
                    MutableTreeTableNode selectedNode = (MutableTreeTableNode) selectedPath
                            .getLastPathComponent();
                    if (selectedNode instanceof CodeTemplateLibraryTreeTableNode && codeTemplateTasks
                            .getContentPane().getComponent(TASK_CODE_TEMPLATE_LIBRARY_DELETE).isVisible()) {
                        doDeleteLibrary();
                    } else if (selectedNode instanceof CodeTemplateTreeTableNode && codeTemplateTasks
                            .getContentPane().getComponent(TASK_CODE_TEMPLATE_DELETE).isVisible()) {
                        doDeleteCodeTemplate();
                    }
                }
            }
        }
    });

    templateTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting() && !templateTreeTable.getSelectionModel().getValueIsAdjusting()) {
                int selectedRow = templateTreeTable.getSelectedRow();

                boolean saveEnabled = isSaveEnabled();
                boolean adjusting = saveAdjusting.getAndSet(true);

                printTreeTable();

                updateCurrentNode();
                currentSelectedRow = selectedRow;

                if (selectedRow < 0) {
                    if (!adjusting) {
                        switchSplitPaneComponent(blankPanel);
                    }
                } else {
                    TreePath path = templateTreeTable.getPathForRow(selectedRow);
                    if (path != null) {
                        TreeTableNode node = (TreeTableNode) path.getLastPathComponent();

                        if (node instanceof CodeTemplateLibraryTreeTableNode) {
                            setLibraryProperties((CodeTemplateLibraryTreeTableNode) node);
                            switchSplitPaneComponent(libraryPanel);
                        } else if (node instanceof CodeTemplateTreeTableNode) {
                            setCodeTemplateProperties((CodeTemplateTreeTableNode) node);
                            switchSplitPaneComponent(templatePanel);
                        }
                    }
                }

                updateTasks();

                setSaveEnabled(saveEnabled);
                if (!adjusting) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            saveAdjusting.set(false);
                        }
                    });
                }
            }
        }
    });

    templateTreeTable.addTreeWillExpandListener(new TreeWillExpandListener() {
        @Override
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            treeExpansionChanged();
        }

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
            treeExpansionChanged();
        }

        private void treeExpansionChanged() {
            updateCurrentNode();
            updateCurrentNode.set(false);
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    updateCurrentNode.set(true);
                }
            });
        }
    });

    templateTreeTableScrollPane = new JScrollPane(templateTreeTable);
    templateTreeTableScrollPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(0x6E6E6E)));

    templateFilterNotificationLabel = new JLabel();

    templateFilterLabel = new JLabel("Filter:");

    templateFilterField = new JTextField();
    templateFilterField.setToolTipText(
            "Filters (by name) the code templates and libraries that show up in the table above.");

    templateFilterField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent evt) {
            filterChanged(evt);
        }

        @Override
        public void insertUpdate(DocumentEvent evt) {
            filterChanged(evt);
        }

        @Override
        public void changedUpdate(DocumentEvent evt) {
            filterChanged(evt);
        }

        private void filterChanged(DocumentEvent evt) {
            try {
                updateTemplateFilter(evt.getDocument().getText(0, evt.getLength()));
            } catch (BadLocationException e) {
            }
        }
    });

    templateFilterField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent evt) {
            updateTemplateFilter(templateFilterField.getText());
        }
    });

    blankPanel = new JPanel();

    libraryPanel = new JPanel();
    libraryPanel.setBackground(splitPane.getBackground());

    libraryLeftPanel = new JPanel();
    libraryLeftPanel.setBackground(libraryPanel.getBackground());

    librarySummaryLabel = new JLabel("Summary:");
    librarySummaryValue = new JLabel();

    libraryDescriptionLabel = new JLabel("Description:");
    libraryDescriptionScrollPane = new MirthRTextScrollPane(null, false, SyntaxConstants.SYNTAX_STYLE_NONE,
            false);

    DocumentListener codeChangeListener = new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent evt) {
            codeChanged();
        }

        @Override
        public void insertUpdate(DocumentEvent evt) {
            codeChanged();
        }

        @Override
        public void changedUpdate(DocumentEvent evt) {
            codeChanged();
        }

        private void codeChanged() {
            if (codeChangeWorker != null) {
                codeChangeWorker.cancel(true);
            }

            int selectedRow = templateTreeTable.getSelectedRow();
            if (selectedRow >= 0) {
                TreePath selectedPath = templateTreeTable.getPathForRow(selectedRow);
                if (selectedPath != null) {
                    codeChangeWorker = new CodeChangeWorker(
                            (String) ((TreeTableNode) selectedPath.getLastPathComponent())
                                    .getValueAt(TEMPLATE_ID_COLUMN));
                    codeChangeWorker.execute();
                }
            }
        }
    };
    libraryDescriptionScrollPane.getDocument().addDocumentListener(codeChangeListener);

    libraryRightPanel = new JPanel();
    libraryRightPanel.setBackground(libraryPanel.getBackground());

    libraryChannelsSelectPanel = new JPanel();
    libraryChannelsSelectPanel.setBackground(libraryRightPanel.getBackground());

    libraryChannelsLabel = new JLabel("<html><b>Channels</b></html>");
    libraryChannelsLabel.setForeground(new Color(64, 64, 64));

    libraryChannelsSelectAllLabel = new JLabel("<html><u>Select All</u></html>");
    libraryChannelsSelectAllLabel.setForeground(Color.BLUE);
    libraryChannelsSelectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    libraryChannelsSelectAllLabel.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent evt) {
            if (evt.getComponent().isEnabled()) {
                for (int row = 0; row < libraryChannelsTable.getRowCount(); row++) {
                    ChannelInfo channelInfo = (ChannelInfo) libraryChannelsTable.getValueAt(row,
                            LIBRARY_CHANNELS_NAME_COLUMN);
                    channelInfo.setEnabled(true);
                    libraryChannelsTable.setValueAt(channelInfo, row, LIBRARY_CHANNELS_NAME_COLUMN);
                }
                setSaveEnabled(true);
            }
        }
    });

    libraryChannelsDeselectAllLabel = new JLabel("<html><u>Deselect All</u></html>");
    libraryChannelsDeselectAllLabel.setForeground(Color.BLUE);
    libraryChannelsDeselectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    libraryChannelsDeselectAllLabel.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent evt) {
            if (evt.getComponent().isEnabled()) {
                for (int row = 0; row < libraryChannelsTable.getRowCount(); row++) {
                    ChannelInfo channelInfo = (ChannelInfo) libraryChannelsTable.getValueAt(row,
                            LIBRARY_CHANNELS_NAME_COLUMN);
                    channelInfo.setEnabled(false);
                    libraryChannelsTable.setValueAt(channelInfo, row, LIBRARY_CHANNELS_NAME_COLUMN);
                }
                setSaveEnabled(true);
            }
        }
    });

    libraryChannelsFilterLabel = new JLabel("Filter:");
    libraryChannelsFilterField = new JTextField();
    libraryChannelsFilterField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent evt) {
            libraryChannelsTable.getRowSorter().allRowsChanged();
        }

        @Override
        public void insertUpdate(DocumentEvent evt) {
            libraryChannelsTable.getRowSorter().allRowsChanged();
        }

        @Override
        public void changedUpdate(DocumentEvent evt) {
            libraryChannelsTable.getRowSorter().allRowsChanged();
        }
    });

    libraryChannelsTable = new MirthTable();
    libraryChannelsTable.setModel(new RefreshTableModel(new Object[] { "Name", "Id" }, 0));
    libraryChannelsTable.setDragEnabled(false);
    libraryChannelsTable.setRowSelectionAllowed(false);
    libraryChannelsTable.setRowHeight(UIConstants.ROW_HEIGHT);
    libraryChannelsTable.setFocusable(false);
    libraryChannelsTable.setOpaque(true);
    libraryChannelsTable.getTableHeader().setReorderingAllowed(false);
    libraryChannelsTable.setEditable(true);

    OffsetRowSorter libraryChannelsRowSorter = new OffsetRowSorter(libraryChannelsTable.getModel(), 1);
    libraryChannelsRowSorter.setRowFilter(new RowFilter<TableModel, Integer>() {
        @Override
        public boolean include(Entry<? extends TableModel, ? extends Integer> entry) {
            String name = entry.getStringValue(LIBRARY_CHANNELS_NAME_COLUMN);
            return name.equals(NEW_CHANNELS) || StringUtils.containsIgnoreCase(name,
                    StringUtils.trim(libraryChannelsFilterField.getText()));
        }
    });
    libraryChannelsTable.setRowSorter(libraryChannelsRowSorter);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        libraryChannelsTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    libraryChannelsTable.getColumnExt(LIBRARY_CHANNELS_NAME_COLUMN)
            .setCellRenderer(new ChannelsTableCellRenderer());
    libraryChannelsTable.getColumnExt(LIBRARY_CHANNELS_NAME_COLUMN)
            .setCellEditor(new ChannelsTableCellEditor());

    // Hide ID column
    libraryChannelsTable.getColumnExt(LIBRARY_CHANNELS_ID_COLUMN).setVisible(false);

    libraryChannelsScrollPane = new JScrollPane(libraryChannelsTable);

    templatePanel = new JPanel();
    templatePanel.setBackground(splitPane.getBackground());

    templateLeftPanel = new JPanel();
    templateLeftPanel.setBackground(templatePanel.getBackground());

    templateLibraryLabel = new JLabel("Library:");
    templateLibraryComboBox = new JComboBox<String>();
    templateLibraryComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            libraryComboBoxActionPerformed();
        }
    });

    templateTypeLabel = new JLabel("Type:");
    templateTypeComboBox = new JComboBox<CodeTemplateType>(CodeTemplateType.values());
    templateTypeComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            setSaveEnabled(true);
        }
    });

    templateCodeLabel = new JLabel("Code:");
    templateCodeTextArea = new MirthRTextScrollPane(ContextType.GLOBAL_DEPLOY);
    templateCodeTextArea.getDocument().addDocumentListener(codeChangeListener);

    templateAutoGenerateDocumentationButton = new JButton("Update JSDoc");
    templateAutoGenerateDocumentationButton.setToolTipText(
            "<html>Generates/updates a JSDoc at the beginning of your<br/>code, with parameter/return annotations as needed.</html>");
    templateAutoGenerateDocumentationButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            String currentText = templateCodeTextArea.getText();
            String newText = CodeTemplateUtil.updateCode(templateCodeTextArea.getText());
            templateCodeTextArea.setText(newText, false);
            if (!currentText.equals(newText)) {
                setSaveEnabled(true);
            }
        }
    });

    templateRightPanel = new JPanel();
    templateRightPanel.setBackground(templatePanel.getBackground());

    templateContextSelectPanel = new JPanel();
    templateContextSelectPanel.setBackground(templateRightPanel.getBackground());

    templateContextLabel = new JLabel("<html><b>Context</b></html>");
    templateContextLabel.setForeground(new Color(64, 64, 64));

    templateContextSelectAllLabel = new JLabel("<html><u>Select All</u></html>");
    templateContextSelectAllLabel.setForeground(Color.BLUE);
    templateContextSelectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    templateContextSelectAllLabel.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent evt) {
            TreeTableNode root = (TreeTableNode) templateContextTreeTable.getTreeTableModel().getRoot();
            for (Enumeration<? extends TreeTableNode> groups = root.children(); groups.hasMoreElements();) {
                TreeTableNode group = groups.nextElement();
                ((MutablePair<Integer, String>) group.getUserObject()).setLeft(MirthTriStateCheckBox.CHECKED);
                for (Enumeration<? extends TreeTableNode> children = group.children(); children
                        .hasMoreElements();) {
                    ((MutablePair<Integer, String>) children.nextElement().getUserObject())
                            .setLeft(MirthTriStateCheckBox.CHECKED);
                }
            }
            templateContextTreeTable.updateUI();
            setSaveEnabled(true);
        }
    });

    templateContextDeselectAllLabel = new JLabel("<html><u>Deselect All</u></html>");
    templateContextDeselectAllLabel.setForeground(Color.BLUE);
    templateContextDeselectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    templateContextDeselectAllLabel.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent evt) {
            TreeTableNode root = (TreeTableNode) templateContextTreeTable.getTreeTableModel().getRoot();
            for (Enumeration<? extends TreeTableNode> groups = root.children(); groups.hasMoreElements();) {
                TreeTableNode group = groups.nextElement();
                ((MutablePair<Integer, String>) group.getUserObject()).setLeft(MirthTriStateCheckBox.UNCHECKED);
                for (Enumeration<? extends TreeTableNode> children = group.children(); children
                        .hasMoreElements();) {
                    ((MutablePair<Integer, String>) children.nextElement().getUserObject())
                            .setLeft(MirthTriStateCheckBox.UNCHECKED);
                }
            }
            templateContextTreeTable.updateUI();
            setSaveEnabled(true);
        }
    });

    final TableCellEditor contextCellEditor = new ContextTreeTableCellEditor(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            setSaveEnabled(true);
        }
    });

    templateContextTreeTable = new MirthTreeTable() {
        @Override
        public TableCellEditor getCellEditor(int row, int column) {
            if (isHierarchical(column)) {
                return contextCellEditor;
            } else {
                return super.getCellEditor(row, column);
            }
        }
    };

    DefaultMutableTreeTableNode rootContextNode = new DefaultMutableTreeTableNode();
    DefaultMutableTreeTableNode globalScriptsNode = new DefaultMutableTreeTableNode(
            new MutablePair<Integer, String>(MirthTriStateCheckBox.CHECKED, "Global Scripts"));
    globalScriptsNode.add(new DefaultMutableTreeTableNode(
            new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.GLOBAL_DEPLOY)));
    globalScriptsNode.add(new DefaultMutableTreeTableNode(
            new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.GLOBAL_UNDEPLOY)));
    globalScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.GLOBAL_PREPROCESSOR)));
    globalScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.GLOBAL_POSTPROCESSOR)));
    rootContextNode.add(globalScriptsNode);
    DefaultMutableTreeTableNode channelScriptsNode = new DefaultMutableTreeTableNode(
            new MutablePair<Integer, String>(MirthTriStateCheckBox.CHECKED, "Channel Scripts"));
    channelScriptsNode.add(new DefaultMutableTreeTableNode(
            new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_DEPLOY)));
    channelScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_UNDEPLOY)));
    channelScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_PREPROCESSOR)));
    channelScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_POSTPROCESSOR)));
    channelScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_ATTACHMENT)));
    channelScriptsNode.add(new DefaultMutableTreeTableNode(
            new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_BATCH)));
    rootContextNode.add(channelScriptsNode);
    DefaultMutableTreeTableNode sourceConnectorNode = new DefaultMutableTreeTableNode(
            new MutablePair<Integer, String>(MirthTriStateCheckBox.CHECKED, "Source Connector"));
    sourceConnectorNode.add(new DefaultMutableTreeTableNode(
            new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.SOURCE_RECEIVER)));
    sourceConnectorNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.SOURCE_FILTER_TRANSFORMER)));
    rootContextNode.add(sourceConnectorNode);
    DefaultMutableTreeTableNode destinationConnectorNode = new DefaultMutableTreeTableNode(
            new MutablePair<Integer, String>(MirthTriStateCheckBox.CHECKED, "Destination Connector"));
    destinationConnectorNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.DESTINATION_FILTER_TRANSFORMER)));
    destinationConnectorNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.DESTINATION_DISPATCHER)));
    destinationConnectorNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>(
            MirthTriStateCheckBox.CHECKED, ContextType.DESTINATION_RESPONSE_TRANSFORMER)));
    rootContextNode.add(destinationConnectorNode);

    DefaultTreeTableModel contextModel = new SortableTreeTableModel(rootContextNode);
    contextModel.setColumnIdentifiers(Arrays.asList(new String[] { "Context" }));
    templateContextTreeTable.setTreeTableModel(contextModel);

    templateContextTreeTable.setRootVisible(false);
    templateContextTreeTable.setDragEnabled(false);
    templateContextTreeTable.setRowSelectionAllowed(false);
    templateContextTreeTable.setRowHeight(UIConstants.ROW_HEIGHT);
    templateContextTreeTable.setFocusable(false);
    templateContextTreeTable.setOpaque(true);
    templateContextTreeTable.getTableHeader().setReorderingAllowed(false);
    templateContextTreeTable.setEditable(true);
    templateContextTreeTable.setSortable(false);
    templateContextTreeTable.setShowGrid(true, true);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        templateContextTreeTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    templateContextTreeTable.setTreeCellRenderer(new ContextTreeTableCellRenderer());
    templateContextTreeTable.setOpenIcon(null);
    templateContextTreeTable.setClosedIcon(null);
    templateContextTreeTable.setLeafIcon(null);

    templateContextTreeTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent evt) {
            checkSelection(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            checkSelection(evt);
        }

        private void checkSelection(MouseEvent evt) {
            if (templateContextTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY())) < 0) {
                templateContextTreeTable.clearSelection();
            }
        }
    });

    templateContextTreeTable.getTreeTableModel().addTreeModelListener(new TreeModelListener() {
        @Override
        public void treeNodesChanged(TreeModelEvent evt) {
            if (ArrayUtils.isNotEmpty(evt.getChildren())) {
                TreeTableNode node = (TreeTableNode) evt.getChildren()[0];

                if (evt.getTreePath().getPathCount() == 2) {
                    boolean allChildren = true;
                    boolean noChildren = true;
                    for (Enumeration<? extends TreeTableNode> children = node.getParent().children(); children
                            .hasMoreElements();) {
                        TreeTableNode child = children.nextElement();
                        if (((Pair<Integer, ContextType>) child.getUserObject())
                                .getLeft() == MirthTriStateCheckBox.UNCHECKED) {
                            allChildren = false;
                        } else {
                            noChildren = false;
                        }
                    }

                    int value;
                    if (allChildren) {
                        value = MirthTriStateCheckBox.CHECKED;
                    } else if (noChildren) {
                        value = MirthTriStateCheckBox.UNCHECKED;
                    } else {
                        value = MirthTriStateCheckBox.PARTIAL;
                    }

                    ((MutablePair<Integer, String>) node.getParent().getUserObject()).setLeft(value);
                } else if (evt.getTreePath().getPathCount() == 1) {
                    int value = ((Pair<Integer, String>) node.getUserObject()).getLeft();

                    for (Enumeration<? extends TreeTableNode> children = node.children(); children
                            .hasMoreElements();) {
                        ((MutablePair<Integer, ContextType>) children.nextElement().getUserObject())
                                .setLeft(value);
                    }
                }
            }
        }

        @Override
        public void treeNodesInserted(TreeModelEvent evt) {
        }

        @Override
        public void treeNodesRemoved(TreeModelEvent evt) {
        }

        @Override
        public void treeStructureChanged(TreeModelEvent evt) {
        }
    });

    templateContextTreeTableScrollPane = new JScrollPane(templateContextTreeTable);
}