Example usage for javax.swing JEditorPane setEditable

List of usage examples for javax.swing JEditorPane setEditable

Introduction

In this page you can find the example usage for javax.swing JEditorPane setEditable.

Prototype

@BeanProperty(description = "specifies if the text can be edited")
public void setEditable(boolean b) 

Source Link

Document

Sets the specified boolean to indicate whether or not this TextComponent should be editable.

Usage

From source file:de.jakop.ngcalsync.application.TrayStarter.java

private JFrame createAboutWindow() {
    final JFrame aboutWindow = new JFrame(UserMessage.get().TITLE_ABOUT_WINDOW());
    final JEditorPane textarea = new JEditorPane("text/html", getApplicationInformation()); //$NON-NLS-1$
    textarea.setEditable(false);
    aboutWindow.getContentPane().add(new JScrollPane(textarea));
    aboutWindow.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    aboutWindow.pack();// w w w.ja  v a 2  s. co m
    aboutWindow.setSize(500, 400);
    return aboutWindow;
}

From source file:edu.ku.brc.specify.config.SpecifyExceptionTracker.java

@Override
protected FeedBackSenderItem getFeedBackSenderItem(final Class<?> cls, final Exception exception) {
    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,p,f:p:g", "p,8px,p,2px, p,4px,p,2px,f:p:g"));

    Vector<Taskable> taskItems = new Vector<Taskable>(TaskMgr.getInstance().getAllTasks());
    Collections.sort(taskItems, new Comparator<Taskable>() {
        @Override/*from   w  w w. j  a  v  a2  s.  c  om*/
        public int compare(Taskable o1, Taskable o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });

    final JTextArea commentsTA = createTextArea(3, 60);
    final JTextArea stackTraceTA = createTextArea(15, 60);
    final JCheckBox moreBtn;

    commentsTA.setWrapStyleWord(true);
    commentsTA.setLineWrap(true);

    //JLabel desc = createI18NLabel("UNHDL_EXCP", SwingConstants.LEFT);
    JEditorPane desc = new JEditorPane("text/html", getResourceString("UNHDL_EXCP"));
    desc.setEditable(false);
    desc.setOpaque(false);
    //desc.setFont(new Font(Font.SANS_SERIF, Font.BOLD, (new JLabel("X")).getFont().getSize()));

    JScrollPane sp = new JScrollPane(stackTraceTA, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    int y = 1;
    pb.add(desc, cc.xyw(1, y, 4));
    y += 2;
    pb.add(createI18NFormLabel("UNHDL_EXCP_CMM"), cc.xy(1, y));
    y += 2;
    pb.add(createScrollPane(commentsTA, true), cc.xyw(1, y, 4));
    y += 2;

    forwardImgIcon = IconManager.getIcon("Forward"); //$NON-NLS-1$
    downImgIcon = IconManager.getIcon("Down"); //$NON-NLS-1$
    moreBtn = new JCheckBox(getResourceString("LOGIN_DLG_MORE"), forwardImgIcon); //$NON-NLS-1$
    setControlSize(moreBtn);
    JButton copyBtn = createI18NButton("UNHDL_EXCP_COPY");

    PanelBuilder innerPB = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,2px,p:g,2px,p"));
    innerPB.add(createI18NLabel("UNHDL_EXCP_STK"), cc.xy(1, 1));
    innerPB.add(sp, cc.xyw(1, 3, 3));
    innerPB.add(copyBtn, cc.xy(1, 5));
    stackTracePanel = innerPB.getPanel();
    stackTracePanel.setVisible(false);

    pb.add(moreBtn, cc.xyw(1, y, 4));
    y += 2;
    pb.add(stackTracePanel, cc.xyw(1, y, 4));
    y += 2;

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    exception.printStackTrace(new PrintStream(baos));

    stackTraceTA.setText(baos.toString());

    moreBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (stackTracePanel.isVisible()) {
                stackTracePanel.setVisible(false);
                moreBtn.setIcon(forwardImgIcon);
            } else {
                stackTracePanel.setVisible(true);
                moreBtn.setIcon(downImgIcon);
            }
            if (dlg != null) {
                dlg.pack();
            }
        }
    });

    copyBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String taskName = getTaskName();
            FeedBackSenderItem item = new FeedBackSenderItem(taskName, "", "", commentsTA.getText(),
                    stackTraceTA.getText(), cls.getName());
            NameValuePair[] pairs = createPostParameters(item);

            StringBuilder sb = new StringBuilder();
            for (NameValuePair pair : pairs) {
                if (!pair.getName().equals("bug")) {
                    sb.append(pair.getName());
                    sb.append(": ");
                    if (pair.getName().equals("comments") || pair.getName().equals("stack_trace")) {
                        sb.append("\n");
                    }
                    sb.append(pair.getValue());
                    sb.append("\n");
                }
            }

            // Copy to Clipboard
            UIHelper.setTextToClipboard(sb.toString());
        }
    });

    pb.setDefaultDialogBorder();
    dlg = new CustomDialog((Frame) null, getResourceString("UnhandledExceptionTitle"), true,
            CustomDialog.OK_BTN, pb.getPanel());
    dlg.setOkLabel(getResourceString("UNHDL_EXCP_SEND"));

    dlg.createUI();
    stackTracePanel.setVisible(false);

    centerAndShow(dlg);

    String taskName = getTaskName();
    FeedBackSenderItem item = new FeedBackSenderItem(taskName, "", "", commentsTA.getText(),
            stackTraceTA.getText(), cls.getName());
    return item;
}

From source file:com.mirth.connect.plugins.rtfviewer.RTFViewer.java

@Override
public void viewAttachments(List<String> attachmentIds) {
    // do viewing code

    Frame frame = new Frame("RTF Viewer");

    frame.setLayout(new BorderLayout());

    try {/*from w  ww .  j  ava2s. co  m*/

        Attachment attachment = parent.mirthClient.getAttachment(attachmentIds.get(0));
        byte[] rawRTF = Base64.decodeBase64(attachment.getData());
        JEditorPane jEditorPane = new JEditorPane("text/rtf", new String(rawRTF));

        if (jEditorPane.getDocument().getLength() == 0) {
            // decoded when it should not have been.  i.e.) the attachment data was not encoded.
            jEditorPane.setText(new String(attachment.getData()));
        }

        jEditorPane.setEditable(false);
        JScrollPane scrollPane = new javax.swing.JScrollPane();
        scrollPane.setViewportView(jEditorPane);
        frame.add(scrollPane);
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        frame.setSize(600, 800);

        Dimension dlgSize = frame.getSize();
        Dimension frmSize = parent.getSize();
        Point loc = parent.getLocation();

        if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) {
            frame.setLocationRelativeTo(null);
        } else {
            frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                    (frmSize.height - dlgSize.height) / 2 + loc.y);
        }

        frame.setVisible(true);
    } catch (Exception e) {
        parent.alertException(parent, e.getStackTrace(), e.getMessage());
    }
}

From source file:com.mirth.connect.plugins.textviewer.TextViewer.java

@Override
public void viewAttachments(String channelId, Long messageId, String attachmentId) {
    // do viewing code
    Frame frame = new Frame("Text Viewer");
    frame.setLayout(new BorderLayout());

    try {/*  w w  w.j a  v a2 s. c o  m*/
        Attachment attachment = parent.mirthClient.getAttachment(channelId, messageId, attachmentId);
        byte[] content = Base64.decodeBase64(attachment.getContent());

        boolean isRTF = attachment.getType().toLowerCase().contains("rtf");
        //TODO set character encoding
        JEditorPane jEditorPane = new JEditorPane(isRTF ? "text/rtf" : "text/plain", new String(content));

        if (jEditorPane.getDocument().getLength() == 0) {
            // decoded when it should not have been.  i.e.) the attachment data was not encoded.
            jEditorPane.setText(new String(attachment.getContent()));
        }

        jEditorPane.setEditable(false);
        JScrollPane scrollPane = new javax.swing.JScrollPane();
        scrollPane.setViewportView(jEditorPane);
        frame.add(scrollPane);
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        frame.setSize(600, 800);

        Dimension dlgSize = frame.getSize();
        Dimension frmSize = parent.getSize();
        Point loc = parent.getLocation();

        if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) {
            frame.setLocationRelativeTo(null);
        } else {
            frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                    (frmSize.height - dlgSize.height) / 2 + loc.y);
        }

        frame.setVisible(true);
    } catch (Exception e) {
        parent.alertThrowable(parent, e);
    }
}

From source file:edu.ku.brc.specify.config.init.secwiz.DatabasePanel.java

/**
 * @param bgColor/*w  w  w  . j ava  2  s  .  c  o m*/
 * @param htmlFileName
 * @return
 */
public static JComponent createHelpPanel(final Color bgColor, final String htmlFileName) {
    Locale currLocale = Locale.getDefault();

    String helpMasterPath = (new File(".")).getAbsolutePath() + File.separator + "../" + "help/securitywiz/"
            + htmlFileName;
    String fullHelpMasterPath = UIHelper.createLocaleName(currLocale, helpMasterPath, "html");

    JEditorPane htmlPane = null;
    try {
        File file = new File(fullHelpMasterPath);
        if (!file.exists()) // for testing
        {
            helpMasterPath = (new File(".")).getAbsolutePath() + File.separator + "help/securitywiz/"
                    + htmlFileName;
            fullHelpMasterPath = UIHelper.createLocaleName(currLocale, helpMasterPath, "html");
            file = new File(fullHelpMasterPath);
            System.out.println(file.getCanonicalPath());
        }
        URI url = file.toURI();

        htmlPane = new JEditorPane(url.toURL()); //$NON-NLS-1$
        htmlPane.setEditable(false);
        htmlPane.setBackground(bgColor);

    } catch (IOException ex) {
        File file = new File(fullHelpMasterPath);
        String htmlDesc = "";
        try {
            htmlDesc = "Error loading help: " + file.getCanonicalPath();
        } catch (IOException e) {
            e.printStackTrace();
        }
        htmlPane = new JEditorPane("text/plain", htmlDesc); //$NON-NLS-1$
    }

    JScrollPane scrollPane = UIHelper.createScrollPane(htmlPane, true);
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    scrollPane.getViewport().setPreferredSize(new Dimension(400, 400));

    return scrollPane;
}

From source file:eu.apenet.dpt.standalone.gui.APETabbedPane.java

public JComponent createMsgEditionTree(String msg) {
    JEditorPane waitMessagePane = new JEditorPane();
    waitMessagePane.setEditable(false);
    waitMessagePane.setContentType("text/plain");
    waitMessagePane.setText(msg);//from w  w w  . java2s.  c o  m
    waitMessagePane.setCaretPosition(0);
    return waitMessagePane;
}

From source file:net.ontopia.topicmaps.viz.AboutFrame.java

private JEditorPane createAboutTextPanel() {

    JEditorPane about = new JEditorPane("text/html", "<html>" + "<body><center>"
            + "<h1>Vizigator&#8482;: VizDesktop&#8482;</h1>" + "<h3>Version: " + Ontopia.getInfo() + "</h3>"
            + "<p>Topic Map visualization and configuration tool based on the graphic visualization product, TouchGraph </p>"
            + "<p>Copyright &#0169; 2004-2007 Ontopia AS</p>"
            + "<p>The Ontopians wish you Happy Vizigating</p><br></center></body></html>");

    about.setEditable(false);
    return about;
}

From source file:net.sf.jasperreports.engine.util.JEditorPaneHtmlMarkupProcessor.java

@Override
public String convert(String srcText) {
    JEditorPane editorPane = new JEditorPane("text/html", srcText);
    editorPane.setEditable(false);

    List<Element> elements = new ArrayList<Element>();

    Document document = editorPane.getDocument();

    Element root = document.getDefaultRootElement();
    if (root != null) {
        addElements(elements, root);//from  w  ww . j a va2s. c o m
    }

    int startOffset = 0;
    int endOffset = 0;
    int crtOffset = 0;
    String chunk = null;
    JRPrintHyperlink hyperlink = null;
    Element element = null;
    Element parent = null;
    boolean bodyOccurred = false;
    int[] orderedListIndex = new int[elements.size()];
    String whitespace = "    ";
    String[] whitespaces = new String[elements.size()];
    for (int i = 0; i < elements.size(); i++) {
        whitespaces[i] = "";
    }

    StringBuilder text = new StringBuilder();
    List<JRStyledText.Run> styleRuns = new ArrayList<>();

    for (int i = 0; i < elements.size(); i++) {
        if (bodyOccurred && chunk != null) {
            text.append(chunk);
            Map<Attribute, Object> styleAttributes = getAttributes(element.getAttributes());
            if (hyperlink != null) {
                styleAttributes.put(JRTextAttribute.HYPERLINK, hyperlink);
                hyperlink = null;
            }
            if (!styleAttributes.isEmpty()) {
                styleRuns.add(
                        new JRStyledText.Run(styleAttributes, startOffset + crtOffset, endOffset + crtOffset));
            }
        }

        chunk = null;
        element = elements.get(i);
        parent = element.getParentElement();
        startOffset = element.getStartOffset();
        endOffset = element.getEndOffset();
        AttributeSet attrs = element.getAttributes();

        Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute);
        Object object = (elementName != null) ? null : attrs.getAttribute(StyleConstants.NameAttribute);
        if (object instanceof HTML.Tag) {

            HTML.Tag htmlTag = (HTML.Tag) object;
            if (htmlTag == Tag.BODY) {
                bodyOccurred = true;
                crtOffset = -startOffset;
            } else if (htmlTag == Tag.BR) {
                chunk = "\n";
            } else if (htmlTag == Tag.OL) {
                orderedListIndex[i] = 0;
                String parentName = parent.getName().toLowerCase();
                whitespaces[i] = whitespaces[elements.indexOf(parent)] + whitespace;
                if (parentName.equals("li")) {
                    chunk = "";
                } else {
                    chunk = "\n";
                    ++crtOffset;
                }
            } else if (htmlTag == Tag.UL) {
                whitespaces[i] = whitespaces[elements.indexOf(parent)] + whitespace;

                String parentName = parent.getName().toLowerCase();
                if (parentName.equals("li")) {
                    chunk = "";
                } else {
                    chunk = "\n";
                    ++crtOffset;
                }

            } else if (htmlTag == Tag.LI) {

                whitespaces[i] = whitespaces[elements.indexOf(parent)];
                if (element.getElement(0) != null && (element.getElement(0).getName().toLowerCase().equals("ol")
                        || element.getElement(0).getName().toLowerCase().equals("ul"))) {
                    chunk = "";
                } else if (parent.getName().equals("ol")) {
                    int index = elements.indexOf(parent);
                    Object type = parent.getAttributes().getAttribute(HTML.Attribute.TYPE);
                    Object startObject = parent.getAttributes().getAttribute(HTML.Attribute.START);
                    int start = startObject == null ? 0
                            : Math.max(0, Integer.valueOf(startObject.toString()) - 1);
                    String suffix = "";

                    ++orderedListIndex[index];

                    if (type != null) {
                        switch (((String) type).charAt(0)) {
                        case 'A':
                            suffix = getOLBulletChars(orderedListIndex[index] + start, true);
                            break;
                        case 'a':
                            suffix = getOLBulletChars(orderedListIndex[index] + start, false);
                            break;
                        case 'I':
                            suffix = JRStringUtil.getRomanNumeral(orderedListIndex[index] + start, true);
                            break;
                        case 'i':
                            suffix = JRStringUtil.getRomanNumeral(orderedListIndex[index] + start, false);
                            break;
                        case '1':
                        default:
                            suffix = String.valueOf(orderedListIndex[index] + start);
                            break;
                        }
                    } else {
                        suffix += orderedListIndex[index] + start;
                    }
                    chunk = whitespaces[index] + suffix + DEFAULT_BULLET_SEPARATOR + "  ";

                } else {
                    chunk = whitespaces[elements.indexOf(parent)] + DEFAULT_BULLET_CHARACTER + "  ";
                }
                crtOffset += chunk.length();
            } else if (element instanceof LeafElement) {
                if (element instanceof RunElement) {
                    RunElement runElement = (RunElement) element;
                    AttributeSet attrSet = (AttributeSet) runElement.getAttribute(Tag.A);
                    if (attrSet != null) {
                        hyperlink = new JRBasePrintHyperlink();
                        hyperlink.setHyperlinkType(HyperlinkTypeEnum.REFERENCE);
                        hyperlink.setHyperlinkReference((String) attrSet.getAttribute(HTML.Attribute.HREF));
                        hyperlink.setLinkTarget((String) attrSet.getAttribute(HTML.Attribute.TARGET));
                    }
                }
                try {
                    chunk = document.getText(startOffset, endOffset - startOffset);
                } catch (BadLocationException e) {
                    if (log.isDebugEnabled()) {
                        log.debug("Error converting markup.", e);
                    }
                }
            }
        }
    }

    if (chunk != null) {
        if (!"\n".equals(chunk)) {
            text.append(chunk);
            Map<Attribute, Object> styleAttributes = getAttributes(element.getAttributes());
            if (hyperlink != null) {
                styleAttributes.put(JRTextAttribute.HYPERLINK, hyperlink);
                hyperlink = null;
            }
            if (!styleAttributes.isEmpty()) {
                styleRuns.add(
                        new JRStyledText.Run(styleAttributes, startOffset + crtOffset, endOffset + crtOffset));
            }
        } else {
            //final newline, not appending
            //check if there's any style run that would have covered it, that can happen if there's a <li> tag with style
            int length = text.length();
            for (ListIterator<JRStyledText.Run> it = styleRuns.listIterator(); it.hasNext();) {
                JRStyledText.Run run = it.next();
                //only looking at runs that end at the position where the newline should have been
                //we don't want to hide bugs in which runs that span after the text length are created
                if (run.endIndex == length + 1) {
                    if (run.startIndex < run.endIndex - 1) {
                        it.set(new JRStyledText.Run(run.attributes, run.startIndex, run.endIndex - 1));
                    } else {
                        it.remove();
                    }
                }
            }
        }
    }

    JRStyledText styledText = new JRStyledText(null, text.toString());
    for (JRStyledText.Run run : styleRuns) {
        styledText.addRun(run);
    }
    styledText.setGlobalAttributes(new HashMap<Attribute, Object>());

    return JRStyledTextParser.getInstance().write(styledText);
}

From source file:edu.ku.brc.specify.config.FixDBAfterLogin.java

/**
 * //from  w ww  .ja  v  a  2  s . com
 */
public static void fixUserPermissions(final boolean doSilently) {
    final String FIXED_USER_PERMS = "FIXED_USER_PERMS";
    boolean isAlreadyFixed = AppPreferences.getRemote().getBoolean(FIXED_USER_PERMS, false);
    if (isAlreadyFixed) {
        return;
    }

    String whereStr = " WHERE p.GroupSubClass = 'edu.ku.brc.af.auth.specify.principal.UserPrincipal' ";
    String whereStr2 = "AND p.userGroupScopeID IS NULL";

    String postSQL = " FROM specifyuser su "
            + "INNER JOIN specifyuser_spprincipal ss ON su.SpecifyUserID = ss.SpecifyUserID "
            + "INNER JOIN spprincipal p ON ss.SpPrincipalID = p.SpPrincipalID "
            + "LEFT JOIN spprincipal_sppermission pp ON p.SpPrincipalID = pp.SpPrincipalID "
            + "LEFT OUTER JOIN sppermission pm ON pp.SpPermissionID = pm.SpPermissionID " + whereStr;

    String sql = "SELECT COUNT(*)" + postSQL + whereStr2;
    log.debug(sql);
    if (BasicSQLUtils.getCountAsInt(sql) < 1) {
        sql = "SELECT COUNT(*)" + postSQL;
        log.debug(sql);
        if (BasicSQLUtils.getCountAsInt(sql) > 0) {
            return;
        }
    }

    final String updatePermSQL = "DELETE FROM %s WHERE SpPermissionID = %d";
    final String updatePrinSQL = "DELETE FROM %s WHERE SpPrincipalID = %d";

    sql = "SELECT p.SpPrincipalID, pp.SpPermissionID" + postSQL;
    log.debug(sql);

    HashSet<Integer> prinIds = new HashSet<Integer>();
    for (Object[] row : query(sql)) {
        Integer prinId = (Integer) row[0];
        if (prinId != null) {
            prinIds.add(prinId);
        }

        Integer permId = (Integer) row[1];
        if (permId != null) {
            update(String.format(updatePermSQL, "spprincipal_sppermission", permId));
            update(String.format(updatePermSQL, "sppermission", permId));
            log.debug("Removing PermId: " + permId);
        }
    }

    StringBuilder sb1 = new StringBuilder();
    for (Integer prinId : prinIds) {
        update(String.format(updatePrinSQL, "specifyuser_spprincipal", prinId));
        update(String.format(updatePrinSQL, "spprincipal", prinId));
        log.debug("Removing PrinId: " + prinId);
        if (sb1.length() > 0)
            sb1.append(",");
        sb1.append(prinId.toString());
    }
    log.debug("(" + sb1.toString() + ")");

    // Create all the necessary UperPrincipal records
    // Start by figuring out what group there are and then create one UserPrincipal record
    // for each one

    TreeSet<String> nameSet = new TreeSet<String>();
    sql = "SELECT su.Name, su.SpecifyUserID, p.userGroupScopeID, p.SpPrincipalID FROM specifyuser su "
            + "INNER JOIN specifyuser_spprincipal sp ON su.SpecifyUserID = sp.SpecifyUserID "
            + "INNER JOIN spprincipal p ON sp.SpPrincipalID = p.SpPrincipalID "
            + "WHERE p.GroupSubClass = 'edu.ku.brc.af.auth.specify.principal.GroupPrincipal'";

    String fields = "TimestampCreated, TimestampModified, Version, GroupSubClass, groupType, Name, Priority, Remarks, userGroupScopeID, CreatedByAgentID, ModifiedByAgentID";
    String insertSQL = "INSERT INTO spprincipal (" + fields + ") VALUES(?,?,?,?,?,?,?,?,?,?,?)";
    String insertSQL2 = "INSERT INTO specifyuser_spprincipal (SpecifyUserID, SpPrincipalID) VALUES(?,?)";

    String searchSql = "SELECT " + fields + " FROM spprincipal WHERE SpPrincipalID = ?";

    sb1 = new StringBuilder();

    PreparedStatement selStmt = null;
    PreparedStatement pStmt = null;
    PreparedStatement pStmt2 = null;
    try {
        Connection conn = DBConnection.getInstance().getConnection();

        pStmt = conn.prepareStatement(insertSQL, Statement.RETURN_GENERATED_KEYS);
        pStmt2 = conn.prepareStatement(insertSQL2);
        selStmt = conn.prepareStatement(searchSql);

        String adtSQL = "SELECT DISTINCT ca.AgentID FROM specifyuser AS su INNER Join agent AS ca ON su.CreatedByAgentID = ca.AgentID";
        Integer createdById = BasicSQLUtils.getCount(conn, adtSQL);
        if (createdById == null) {
            createdById = BasicSQLUtils.getCount(conn,
                    "SELECT AgentID FROM agent ORDER BY AgentID ASC LIMIT 0,1");
            if (createdById == null) {
                UIRegistry.showError("The permissions could not be fixed because there were no agents.");
                AppPreferences.shutdownAllPrefs();
                DBConnection.shutdownFinalConnection(true, true);
                return;
            }
        }

        for (Object[] row : query(sql)) {
            String usrName = (String) row[0];
            Integer userId = (Integer) row[1];
            Integer collId = (Integer) row[2];
            Integer prinId = (Integer) row[3];

            nameSet.add(usrName);

            log.debug("usrName: " + usrName + "  prinId: " + prinId);
            if (sb1.length() > 0)
                sb1.append(",");
            sb1.append(prinId.toString());

            selStmt.setInt(1, prinId);
            ResultSet rs = selStmt.executeQuery();
            if (rs.next()) {
                log.debug(String.format("%s - adding UserPrincipal for Collection  %d / %d", usrName,
                        rs.getInt(9), collId));
                Integer createdByAgentID = (Integer) rs.getObject(10);
                Integer modifiedByAgentID = (Integer) rs.getObject(11);

                pStmt.setTimestamp(1, rs.getTimestamp(1));
                pStmt.setTimestamp(2, rs.getTimestamp(2));
                pStmt.setInt(3, 1); // Version
                pStmt.setString(4, "edu.ku.brc.af.auth.specify.principal.UserPrincipal"); // GroupSubClass
                pStmt.setString(5, null); // groupType
                pStmt.setString(6, rs.getString(6)); // Name
                pStmt.setInt(7, 80); // Priority
                pStmt.setString(8, rs.getString(8)); // Remarks
                pStmt.setInt(9, rs.getInt(9)); // userGroupScopeID
                pStmt.setInt(10, createdByAgentID != null ? createdByAgentID : createdById);
                pStmt.setInt(11, modifiedByAgentID != null ? modifiedByAgentID : createdById);

                // Create UserPrincipal
                pStmt.executeUpdate();

                int newPrinId = BasicSQLUtils.getInsertedId(pStmt);

                // Join the new Principal to the SpecifyUser record
                pStmt2.setInt(1, userId);
                pStmt2.setInt(2, newPrinId);
                pStmt2.executeUpdate();

            } else {
                // error
            }
            rs.close();
        }

        log.debug("(" + sb1.toString() + ")");

        AppPreferences.getRemote().putBoolean(FIXED_USER_PERMS, true);

    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (pStmt != null)
                pStmt.close();
            if (pStmt2 != null)
                pStmt2.close();
            if (selStmt != null)
                selStmt.close();
        } catch (Exception ex) {
        }
    }

    final StringBuilder sb = new StringBuilder();
    for (String nm : nameSet) {
        if (sb.length() > 0)
            sb.append('\n');
        sb.append(nm);
    }

    if (!doSilently) {
        JTextArea ta = UIHelper.createTextArea(15, 30);
        ta.setText(sb.toString());
        ta.setEditable(false);

        JEditorPane htmlPane = new JEditorPane("text/html", //$NON-NLS-1$
                UIRegistry.getResourceString("FDBAL_PERMFIXEDDESC"));
        htmlPane.setEditable(false);
        htmlPane.setOpaque(false);

        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p:g,8px,f:p:g"));
        pb.add(htmlPane, cc.xy(1, 1));
        pb.add(UIHelper.createScrollPane(ta), cc.xy(1, 3));
        pb.setDefaultDialogBorder();

        CustomDialog dlg = new CustomDialog((Frame) UIRegistry.getMostRecentWindow(),
                UIRegistry.getResourceString("FDBAL_PERMFIXED"), true, CustomDialog.OK_BTN, pb.getPanel());
        dlg.setOkLabel(UIRegistry.getResourceString("CLOSE"));
        UIHelper.centerAndShow(dlg);
    }
}

From source file:com.enderville.enderinstaller.ui.Installer.java

private void loadModDescription(String modName) {
    JPanel p = getModDescriptionPane();
    p.removeAll();//from w  w w.j  a  v a 2s  . c om
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));

    final String extras = InstallerConfig.getExtraModsFolder();
    final String modFolderName = FilenameUtils.concat(extras, modName);
    File modFolder = new File(modFolderName);
    if (!modFolder.exists()) {
        LOGGER.error("Mod folder for " + modName + " does not exist.");
    }
    File descrFile = new File(FilenameUtils.concat(modFolderName, "description.txt"));
    File imgFile = new File(FilenameUtils.concat(modFolderName, "image.png"));
    if (!descrFile.exists() && !imgFile.exists()) {
        p.add(new JLabel("<html>No description for:<br>" + modName + "</html>"));
    } else {
        if (imgFile.exists()) {
            try {
                JLabel label = new JLabel();
                BufferedImage img = ImageIO.read(imgFile);
                label.setIcon(new ImageIcon(img));
                p.add(label);
            } catch (IOException e) {
                LOGGER.error("Error reading image file: " + imgFile.getPath(), e);
            }
        }
        if (descrFile.exists()) {
            StringBuilder buffer = new StringBuilder();
            try {
                BufferedReader r = new BufferedReader(new FileReader(descrFile));
                String l = null;
                while ((l = r.readLine()) != null) {
                    buffer.append(l + "\n");
                }
                r.close();
                JEditorPane area = new JEditorPane();
                area.setContentType("text/html");
                area.setText(buffer.toString());
                area.setEditable(false);
                area.addHyperlinkListener(this);
                area.setCaretPosition(0);
                p.add(new JScrollPane(area));
            } catch (IOException e) {
                LOGGER.error("Error reading description file: " + descrFile.getPath(), e);
            }
        }
    }

    p.validate();
    p.repaint();
}