Example usage for javax.swing JEditorPane setBackground

List of usage examples for javax.swing JEditorPane setBackground

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.")
public void setBackground(Color bg) 

Source Link

Document

Sets the background color of this component.

Usage

From source file:Main.java

public static void displayEditorPaneWithNoBorderAndTranslucent(JEditorPane editorPane) {
    editorPane.setOpaque(false);/*w ww. j a v a 2s  .co m*/
    editorPane.setBorder(null);
    editorPane.setBorder(BorderFactory.createEmptyBorder());
    editorPane.setBackground(new Color(0, 0, 0, 0));
}

From source file:RTFView.java

public RTFView() {
    setTitle("RTF Text Application");
    setSize(400, 240);//from ww  w  .  j av  a 2s . c  o m
    setBackground(Color.gray);
    getContentPane().setLayout(new BorderLayout());

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());
    getContentPane().add(topPanel, BorderLayout.CENTER);

    // Create an RTF editor window
    RTFEditorKit rtf = new RTFEditorKit();
    JEditorPane editor = new JEditorPane();
    editor.setEditorKit(rtf);
    editor.setBackground(Color.white);

    // This text could be big so add a scroll pane
    JScrollPane scroller = new JScrollPane();
    scroller.getViewport().add(editor);
    topPanel.add(scroller, BorderLayout.CENTER);

    // Load an RTF file into the editor
    try {
        FileInputStream fi = new FileInputStream("test.rtf");
        rtf.read(fi, editor.getDocument(), 0);
    } catch (FileNotFoundException e) {
        System.out.println("File not found");
    } catch (IOException e) {
        System.out.println("I/O error");
    } catch (BadLocationException e) {
    }
}

From source file:net.sf.taverna.t2.workbench.ui.credentialmanager.WarnUserAboutJCEPolicyDialog.java

private void initComponents() {
    // Base font for all components on the form
    Font baseFont = new JLabel("base font").getFont().deriveFont(11f);

    // Message saying that updates are available
    JPanel messagePanel = new JPanel(new BorderLayout());
    messagePanel.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder(LOWERED)));

    JEditorPane message = new JEditorPane();
    message.setEditable(false);/*from  ww  w.  jav  a2  s . co m*/
    message.setBackground(this.getBackground());
    message.setFocusable(false);
    HTMLEditorKit kit = new HTMLEditorKit();
    message.setEditorKit(kit);
    StyleSheet styleSheet = kit.getStyleSheet();
    //styleSheet.addRule("body {font-family:"+baseFont.getFamily()+"; font-size:"+baseFont.getSize()+";}"); // base font looks bigger when rendered as HTML
    styleSheet.addRule("body {font-family:" + baseFont.getFamily() + "; font-size:10px;}");
    Document doc = kit.createDefaultDocument();
    message.setDocument(doc);
    message.setText(
            "<html><body>In order for Taverna's security features to function properly - you need to install<br>"
                    + "'Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy'. <br><br>"
                    + "If you do not already have it, for <b>Java 6</b> you can get it from:<br>"
                    + "<a href=\"http://www.oracle.com/technetwork/java/javase/downloads/index.html\">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a><br<br>"
                    + "Installation instructions are contained in the bundle you download." + "</body><html>");
    message.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent he) {
            HyperlinkEvent.EventType type = he.getEventType();
            if (type == ACTIVATED)
                // Open a Web browser
                try {
                    getDesktop().browse(he.getURL().toURI());
                    //                  BrowserLauncher launcher = new BrowserLauncher();
                    //                  launcher.openURLinBrowser(he.getURL().toString());
                } catch (Exception ex) {
                    logger.error("Failed to launch browser to fetch JCE " + he.getURL());
                }
        }
    });
    message.setBorder(new EmptyBorder(5, 5, 5, 5));
    messagePanel.add(message, CENTER);

    doNotWarnMeAgainCheckBox = new JCheckBox("Do not warn me again");
    doNotWarnMeAgainCheckBox.setFont(baseFont.deriveFont(12f));
    messagePanel.add(doNotWarnMeAgainCheckBox, SOUTH);

    // Buttons
    JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JButton okButton = new JButton("OK");
    okButton.setFont(baseFont);
    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            okPressed();
        }
    });

    buttonsPanel.add(okButton);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(messagePanel, CENTER);
    getContentPane().add(buttonsPanel, SOUTH);

    pack();
    setResizable(false);
    // Center the dialog on the screen (we do not have the parent)
    Dimension dimension = getToolkit().getScreenSize();
    Rectangle abounds = getBounds();
    setLocation((dimension.width - abounds.width) / 2, (dimension.height - abounds.height) / 2);
    setSize(getPreferredSize());
}

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

/**
 * @param bgColor//from  w w w .  java 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:com.evanbelcher.DrillBook.display.DBMenuBar.java

/**
 * Displays about window.//from   w  ww  .  jav  a2 s .  c o  m
 */
private void about() {
    String msg = "<html>DrillBook " + State.VERSION
            + "<br>Created by Evan Belcher, 2016<br><a href=\"https://github.com/EbMinor3/DrillBook\">GitHub</a><br><a href=\"http://evanbelcher.com\">Website</a><br><br><a href=\"https://icons8.com\">Icon pack by Icons8</a></html>";
    JEditorPane editorPane = new JEditorPane("text/html", msg);
    editorPane.setEditable(false);
    editorPane.setBackground(new JLabel().getBackground());
    editorPane.addHyperlinkListener(e -> {
        if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
            try {
                Desktop.getDesktop().browse(e.getURL().toURI());
            } catch (IOException | URISyntaxException e1) {
                e1.printStackTrace();
            }
        }
    });

    if (!(Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE))) {
        editorPane.setContentType("text");
        editorPane.setText("DrillBook " + State.VERSION
                + "\nCreated by Evan Belcher, 2016\nGitHub: https://github.com/EbMinor3/DrillBook\nWebsite: http://evanbelcher.com\n\nIcon pack by Icons8: https://icons8.com");
    }

    JOptionPane.showMessageDialog(this, editorPane, "About", JOptionPane.PLAIN_MESSAGE);
}

From source file:edu.ku.brc.specify.ui.AppBase.java

/**
 * Shows the About dialog./*ww  w .  j  a v a 2 s. c  o  m*/
 */
public void doAbout() {
    AppContextMgr acm = AppContextMgr.getInstance();
    boolean hasContext = acm.hasContext();

    int baseNumRows = 9;
    String serverName = AppPreferences.getLocalPrefs().get("login.servers_selected", null);
    if (serverName != null) {
        baseNumRows++;
    }

    CellConstraints cc = new CellConstraints();
    PanelBuilder infoPB = new PanelBuilder(new FormLayout("p,6px,f:p:g",
            "p,4px,p,4px," + UIHelper.createDuplicateJGoodiesDef("p", "2px", baseNumRows)));

    JLabel iconLabel = new JLabel(IconManager.getIcon("SpecifyLargeIcon"), SwingConstants.CENTER); //$NON-NLS-1$
    PanelBuilder iconPB = new PanelBuilder(new FormLayout("p", "20px,t:p,f:p:g"));
    iconPB.add(iconLabel, cc.xy(1, 2));

    if (hasContext) {
        DBTableIdMgr tableMgr = DBTableIdMgr.getInstance();
        boolean hasReged = !RegisterSpecify.isAnonymous() && RegisterSpecify.hasInstitutionRegistered();

        int y = 1;
        infoPB.addSeparator(getResourceString("Specify.SYS_INFO"), cc.xyw(1, y, 3));
        y += 2;

        JLabel lbl = UIHelper.createLabel(databaseName);
        infoPB.add(UIHelper.createI18NFormLabel("Specify.DB"), cc.xy(1, y));
        infoPB.add(lbl, cc.xy(3, y));
        y += 2;
        lbl.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    openLocalPrefs();
                }
            }
        });

        infoPB.add(UIHelper.createFormLabel(tableMgr.getTitleForId(Institution.getClassTableId())),
                cc.xy(1, y));
        infoPB.add(lbl = UIHelper.createLabel(acm.getClassObject(Institution.class).getName()), cc.xy(3, y));
        y += 2;
        lbl.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    openRemotePrefs();
                }
            }
        });
        infoPB.add(UIHelper.createFormLabel(tableMgr.getTitleForId(Division.getClassTableId())), cc.xy(1, y));
        infoPB.add(UIHelper.createLabel(acm.getClassObject(Division.class).getName()), cc.xy(3, y));
        y += 2;

        infoPB.add(UIHelper.createFormLabel(tableMgr.getTitleForId(Discipline.getClassTableId())), cc.xy(1, y));
        infoPB.add(UIHelper.createLabel(acm.getClassObject(Discipline.class).getName()), cc.xy(3, y));
        y += 2;

        infoPB.add(UIHelper.createFormLabel(tableMgr.getTitleForId(Collection.getClassTableId())), cc.xy(1, y));
        infoPB.add(UIHelper.createLabel(acm.getClassObject(Collection.class).getCollectionName()), cc.xy(3, y));
        y += 2;

        infoPB.add(UIHelper.createI18NFormLabel("Specify.BLD"), cc.xy(1, y));
        infoPB.add(UIHelper.createLabel(appBuildVersion), cc.xy(3, y));
        y += 2;

        infoPB.add(UIHelper.createI18NFormLabel("Specify.REG"), cc.xy(1, y));
        infoPB.add(UIHelper.createI18NLabel(hasReged ? "Specify.HASREG" : "Specify.NOTREG"), cc.xy(3, y));
        y += 2;

        String isaNumber = RegisterSpecify.getISANumber();
        infoPB.add(UIHelper.createI18NFormLabel("Specify.ISANUM"), cc.xy(1, y));
        infoPB.add(UIHelper.createLabel(StringUtils.isNotEmpty(isaNumber) ? isaNumber : ""), cc.xy(3, y));
        y += 2;

        if (serverName != null) {
            infoPB.add(UIHelper.createI18NFormLabel("Specify.SERVER"), cc.xy(1, y));
            infoPB.add(UIHelper.createLabel(StringUtils.isNotEmpty(serverName) ? serverName : ""), cc.xy(3, y));
            y += 2;
        }

        if (StringUtils.contains(DBConnection.getInstance().getConnectionStr(), "mysql")) {
            Vector<Object[]> list = BasicSQLUtils.query("select version() as ve");
            if (list != null && list.size() > 0) {
                infoPB.add(UIHelper.createFormLabel("MySQL Version"), cc.xy(1, y));
                infoPB.add(UIHelper.createLabel(list.get(0)[0].toString()), cc.xy(3, y));
                y += 2;
            }
        }

        infoPB.add(UIHelper.createFormLabel("Java Version"), cc.xy(1, y));
        infoPB.add(UIHelper.createLabel(System.getProperty("java.version")), cc.xy(3, y));
        y += 2;
    }

    String txt = getAboutText(appName, appVersion);
    JLabel txtLbl = createLabel(txt);
    txtLbl.setFont(UIRegistry.getDefaultFont());

    final JEditorPane txtPane = new JEditorPane("text/html", txt);
    txtPane.setEditable(false);
    txtPane.setBackground(new JPanel().getBackground());

    PanelBuilder pb = new PanelBuilder(new FormLayout("p,20px,f:min(400px;p):g,10px,8px,10px,p:g", "f:p:g"));

    pb.add(iconPB.getPanel(), cc.xy(1, 1));
    pb.add(txtPane, cc.xy(3, 1));
    Color bg = getBackground();

    if (hasContext) {
        pb.add(new VerticalSeparator(bg.darker(), bg.brighter()), cc.xy(5, 1));
        pb.add(infoPB.getPanel(), cc.xy(7, 1));
    }

    pb.setDefaultDialogBorder();

    String title = getResourceString("Specify.ABOUT");//$NON-NLS-1$
    CustomDialog aboutDlg = new CustomDialog(topFrame, title + " " + appName, true, CustomDialog.OK_BTN, //$NON-NLS-1$
            pb.getPanel());
    String okLabel = getResourceString("Specify.CLOSE");//$NON-NLS-1$
    aboutDlg.setOkLabel(okLabel);

    aboutDlg.createUI();
    aboutDlg.pack();

    // for some strange reason I can't get the dialog to size itself correctly
    Dimension size = aboutDlg.getSize();
    size.height += 120;
    aboutDlg.setSize(size);

    txtPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    AttachmentUtils.openURI(event.getURL().toURI());

                } catch (Exception e) {
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                }
            }
        }
    });

    UIHelper.centerAndShow(aboutDlg);
}

From source file:com.ejie.uda.jsonI18nEditor.Editor.java

public void showVersionDialog() {
    GithubReleaseData data = GithubRepoUtils.getLatestRelease(GITHUB_REPO);
    String content = "";
    if (data != null && !VERSION.equals(data.getTagName())) {
        content = MessageBundle.get("dialogs.version.new", data.getTagName()) + "<br>" + "<a href=\""
                + data.getHtmlUrl() + "\">" + MessageBundle.get("dialogs.version.link") + "</a>";
    } else {/* w ww. j  a  v  a2 s.c  om*/
        content = MessageBundle.get("dialogs.version.uptodate");
    }
    Font font = getFont();
    JEditorPane pane = new JEditorPane("text/html",
            "<html><body style=\"font-family:" + font.getFamily() + ";font-size:" + font.getSize()
                    + "pt;text-align:center;width:200px;\">" + content + "</body></html>");
    pane.addHyperlinkListener(e -> {
        if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
            try {
                Desktop.getDesktop().browse(e.getURL().toURI());
            } catch (Exception e1) {
                //
            }
        }
    });
    pane.setBackground(getBackground());
    pane.setEditable(false);
    showMessage(MessageBundle.get("dialogs.version.title"), pane);
}

From source file:net.sf.taverna.t2.workbench.ui.impl.UserRegistrationForm.java

private void initComponents() {
    JPanel mainPanel = new JPanel(new GridBagLayout());

    // Base font for all components on the form
    Font baseFont = new JLabel("base font").getFont().deriveFont(11f);

    // Title panel
    JPanel titlePanel = new JPanel(new FlowLayout(LEFT));
    titlePanel.setBackground(WHITE);/*from www .ja  v a  2 s  .  co m*/
    // titlePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
    JLabel titleLabel = new JLabel(WELCOME);
    titleLabel.setFont(baseFont.deriveFont(BOLD, 13.5f));
    // titleLabel.setBorder(new EmptyBorder(10, 10, 0, 10));
    JLabel titleIcon = new JLabel(tavernaCogs32x32Icon);
    // titleIcon.setBorder(new EmptyBorder(10, 10, 10, 10));
    DialogTextArea titleMessage = new DialogTextArea(PLEASE_FILL_IN_THIS_REGISTRATION_FORM);
    titleMessage.setMargin(new Insets(0, 20, 0, 10));
    titleMessage.setFont(baseFont);
    titleMessage.setEditable(false);
    titleMessage.setFocusable(false);
    // titlePanel.setBorder( new EmptyBorder(10, 10, 0, 10));
    JPanel messagePanel = new JPanel(new BorderLayout());
    messagePanel.add(titleLabel, NORTH);
    messagePanel.add(titleMessage, CENTER);
    messagePanel.setBackground(WHITE);
    titlePanel.add(titleIcon);
    titlePanel.add(messagePanel);
    addDivider(titlePanel, BOTTOM, true);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = HORIZONTAL;
    gbc.anchor = WEST;
    gbc.gridwidth = 2;
    // gbc.insets = new Insets(5, 10, 0, 0);
    mainPanel.add(titlePanel, gbc);

    // Registration messages
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = NONE;
    gbc.anchor = WEST;
    gbc.gridwidth = 2;
    // gbc.insets = new Insets(5, 0, 0, 10);
    DialogTextArea registrationMessage1 = new DialogTextArea(WHY_REGISTER);
    registrationMessage1.setMargin(new Insets(0, 10, 0, 0));
    registrationMessage1.setFont(baseFont);
    registrationMessage1.setEditable(false);
    registrationMessage1.setFocusable(false);
    registrationMessage1.setBackground(getBackground());

    DialogTextArea registrationMessage2 = new DialogTextArea(WE_DO);
    registrationMessage2.setMargin(new Insets(0, 10, 0, 10));
    registrationMessage2.setFont(baseFont);
    registrationMessage2.setEditable(false);
    registrationMessage2.setFocusable(false);
    registrationMessage2.setBackground(getBackground());
    JPanel registrationMessagePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    registrationMessagePanel.add(registrationMessage1);
    registrationMessagePanel.add(registrationMessage2);
    addDivider(registrationMessagePanel, BOTTOM, true);
    mainPanel.add(registrationMessagePanel, gbc);

    // Mandatory label
    // JLabel mandatoryLabel = new JLabel("* Mandatory fields");
    // mandatoryLabel.setFont(baseFont);
    // gbc.weightx = 0.0;
    // gbc.weighty = 0.0;
    // gbc.gridx = 0;
    // gbc.gridy = 3;
    // gbc.fill = NONE;
    // gbc.anchor = GridBagConstraints.EAST;
    // gbc.gridwidth = 2;
    // gbc.insets = new Insets(0, 10, 0, 20);
    // mainPanel.add(mandatoryLabel, gbc);

    // First name
    JLabel firstNameLabel = new JLabel(FIRST_NAME);
    firstNameLabel.setFont(baseFont);
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.gridx = 0;
    gbc.gridy = 4;
    gbc.fill = NONE;
    gbc.anchor = WEST;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(0, 10, 0, 10);
    mainPanel.add(firstNameLabel, gbc);

    firstNameTextField = new JTextField();
    firstNameTextField.setFont(baseFont);
    if (previousRegistrationData != null)
        firstNameTextField.setText(previousRegistrationData.getFirstName());
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.gridx = 1;
    gbc.gridy = 4;
    gbc.fill = HORIZONTAL;
    gbc.anchor = WEST;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(5, 10, 0, 10);
    mainPanel.add(firstNameTextField, gbc);

    // Last name
    JLabel lastNameLabel = new JLabel(LAST_NAME);
    lastNameLabel.setFont(baseFont);
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.gridx = 0;
    gbc.gridy = 5;
    gbc.fill = NONE;
    gbc.anchor = WEST;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(0, 10, 0, 10);
    mainPanel.add(lastNameLabel, gbc);

    lastNameTextField = new JTextField();
    lastNameTextField.setFont(baseFont);
    if (previousRegistrationData != null)
        lastNameTextField.setText(previousRegistrationData.getLastName());
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.gridx = 1;
    gbc.gridy = 5;
    gbc.fill = HORIZONTAL;
    gbc.anchor = WEST;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(5, 10, 0, 10);
    mainPanel.add(lastNameTextField, gbc);

    // Email address
    JLabel emailLabel = new JLabel(EMAIL_ADDRESS);
    emailLabel.setFont(baseFont);
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.gridx = 0;
    gbc.gridy = 6;
    gbc.fill = NONE;
    gbc.anchor = WEST;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(5, 10, 0, 10);
    mainPanel.add(emailLabel, gbc);

    emailTextField = new JTextField();
    emailTextField.setFont(baseFont);
    if (previousRegistrationData != null)
        emailTextField.setText(previousRegistrationData.getEmailAddress());
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.gridx = 1;
    gbc.gridy = 6;
    gbc.fill = HORIZONTAL;
    gbc.anchor = WEST;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(5, 10, 0, 10);
    mainPanel.add(emailTextField, gbc);

    // Keep me informed
    keepMeInformedCheckBox = new JCheckBox(KEEP_ME_INFORMED);
    keepMeInformedCheckBox.setFont(baseFont);
    if (previousRegistrationData != null)
        keepMeInformedCheckBox.setSelected(previousRegistrationData.getKeepMeInformed());
    keepMeInformedCheckBox.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent evt) {
            if (evt.getKeyCode() == VK_ENTER) {
                evt.consume();
                keepMeInformedCheckBox.setSelected(!keepMeInformedCheckBox.isSelected());
            }
        }
    });
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.gridx = 1;
    gbc.gridy = 7;
    gbc.fill = NONE;
    gbc.anchor = WEST;
    gbc.gridwidth = 2;
    gbc.insets = new Insets(5, 10, 0, 10);
    mainPanel.add(keepMeInformedCheckBox, gbc);

    // Institution name
    JLabel institutionLabel = new JLabel(INSTITUTION_COMPANY_NAME);
    institutionLabel.setFont(baseFont);
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.gridx = 0;
    gbc.gridy = 8;
    gbc.fill = NONE;
    gbc.anchor = WEST;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(5, 10, 0, 10);
    mainPanel.add(institutionLabel, gbc);

    institutionOrCompanyTextField = new JTextField();
    institutionOrCompanyTextField.setFont(baseFont);
    if (previousRegistrationData != null)
        institutionOrCompanyTextField.setText(previousRegistrationData.getInstitutionOrCompanyName());
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.gridx = 1;
    gbc.gridy = 8;
    gbc.fill = HORIZONTAL;
    gbc.anchor = WEST;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(5, 10, 0, 10);
    mainPanel.add(institutionOrCompanyTextField, gbc);

    // Industry type
    JLabel industryLabel = new JLabel(" Industry type:");
    industryLabel.setFont(baseFont);
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.gridx = 0;
    gbc.gridy = 9;
    gbc.fill = NONE;
    gbc.anchor = WEST;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(5, 10, 0, 10);
    mainPanel.add(industryLabel, gbc);

    industryTypeTextField = new JComboBox<>(industryTypes);
    industryTypeTextField.setFont(baseFont);
    if (previousRegistrationData != null)
        industryTypeTextField.setSelectedItem(previousRegistrationData.getIndustry());
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.gridx = 1;
    gbc.gridy = 9;
    gbc.fill = HORIZONTAL;
    gbc.anchor = WEST;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(5, 10, 0, 10);
    mainPanel.add(industryTypeTextField, gbc);

    // Field of investigation
    JTextArea fieldLabel = new JTextArea(FIELD_OF_INVESTIGATION);
    fieldLabel.setFont(baseFont);
    fieldLabel.setEditable(false);
    fieldLabel.setFocusable(false);
    fieldLabel.setBackground(getBackground());
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.gridx = 0;
    gbc.gridy = 10;
    gbc.fill = NONE;
    gbc.anchor = LINE_START;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(5, 10, 0, 10);
    mainPanel.add(fieldLabel, gbc);

    fieldTextField = new JTextField();
    fieldTextField.setFont(baseFont);
    if (previousRegistrationData != null)
        fieldTextField.setText(previousRegistrationData.getField());
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.gridx = 1;
    gbc.gridy = 10;
    gbc.fill = HORIZONTAL;
    gbc.anchor = FIRST_LINE_START;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(5, 10, 0, 10);
    mainPanel.add(fieldTextField, gbc);

    // Purpose of using Taverna
    JTextArea purposeLabel = new JTextArea(WHY_YOU_INTEND_TO_USE_TAVERNA);
    purposeLabel.setFont(baseFont);
    purposeLabel.setEditable(false);
    purposeLabel.setFocusable(false);
    purposeLabel.setBackground(getBackground());
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.gridx = 0;
    gbc.gridy = 11;
    gbc.fill = NONE;
    gbc.anchor = LINE_START;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(5, 10, 0, 10);
    mainPanel.add(purposeLabel, gbc);

    purposeTextArea = new JTextArea(4, 30);
    purposeTextArea.setFont(baseFont);
    purposeTextArea.setLineWrap(true);
    purposeTextArea.setAutoscrolls(true);
    if (previousRegistrationData != null)
        purposeTextArea.setText(previousRegistrationData.getPurposeOfUsingTaverna());
    purposeTextArea.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent evt) {
            if (evt.getKeyCode() == VK_TAB) {
                if (evt.getModifiers() > 0)
                    purposeTextArea.transferFocusBackward();
                else
                    purposeTextArea.transferFocus();
                evt.consume();
            }
        }
    });
    JScrollPane purposeScrollPane = new JScrollPane(purposeTextArea);
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.gridx = 1;
    gbc.gridy = 11;
    gbc.fill = HORIZONTAL;
    gbc.anchor = FIRST_LINE_START;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(5, 10, 0, 10);
    mainPanel.add(purposeScrollPane, gbc);

    // Terms and conditions
    termsAndConditionsCheckBox = new JCheckBox(I_AGREE_TO_THE_TERMS_AND_CONDITIONS);
    termsAndConditionsCheckBox.setFont(baseFont);
    termsAndConditionsCheckBox.setBorder(null);
    termsAndConditionsCheckBox.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent evt) {
            if (evt.getKeyCode() == VK_ENTER) {
                evt.consume();
                termsAndConditionsCheckBox.setSelected(!termsAndConditionsCheckBox.isSelected());
            }
        }
    });
    // gbc.weightx = 0.0;
    // gbc.weighty = 0.0;
    // gbc.gridx = 0;
    // gbc.gridy = 12;
    // gbc.fill = NONE;
    // gbc.anchor = WEST;
    // gbc.gridwidth = 2;
    // gbc.insets = new Insets(10, 10, 0, 0);
    // mainPanel.add(termsAndConditionsCheckBox, gbc);

    // Terms and conditions link
    JEditorPane termsAndConditionsURL = new JEditorPane();
    termsAndConditionsURL.setEditable(false);
    termsAndConditionsURL.setBackground(getBackground());
    termsAndConditionsURL.setFocusable(false);
    HTMLEditorKit kit = new HTMLEditorKit();
    termsAndConditionsURL.setEditorKit(kit);
    StyleSheet styleSheet = kit.getStyleSheet();
    // styleSheet.addRule("body {font-family:"+baseFont.getFamily()+"; font-size:"+baseFont.getSize()+";}");
    // // base font looks bigger when rendered as HTML
    styleSheet.addRule("body {font-family:" + baseFont.getFamily() + "; font-size:9px;}");
    Document doc = kit.createDefaultDocument();
    termsAndConditionsURL.setDocument(doc);
    termsAndConditionsURL.setText("<html><body><a href=\"" + TERMS_AND_CONDITIONS_URL + "\">"
            + TERMS_AND_CONDITIONS_URL + "</a></body></html>");
    termsAndConditionsURL.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent he) {
            if (he.getEventType() == ACTIVATED)
                followHyperlinkToTandCs();
        }
    });
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.gridx = 0;
    gbc.gridy = 13;
    gbc.fill = NONE;
    gbc.anchor = WEST;
    gbc.gridwidth = 2;
    gbc.insets = new Insets(5, 10, 0, 10);
    JPanel termsAndConditionsPanel = new JPanel(new FlowLayout(LEFT));
    termsAndConditionsPanel.add(termsAndConditionsCheckBox);
    termsAndConditionsPanel.add(termsAndConditionsURL);
    mainPanel.add(termsAndConditionsPanel, gbc);

    // Button panel
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JButton registerButton = new JButton("Register");
    registerButton.setFont(baseFont);
    registerButton.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent evt) {
            if (evt.getKeyCode() == VK_ENTER) {
                evt.consume();
                register();
            }
        }
    });
    registerButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            register();
        }
    });
    JButton doNotRegisterButton = new JButton("Do not ask me again");
    doNotRegisterButton.setFont(baseFont);
    doNotRegisterButton.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent evt) {
            if (evt.getKeyCode() == VK_ENTER) {
                evt.consume();
                doNotRegister();
            }
        }
    });
    doNotRegisterButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doNotRegister();
        }
    });
    JButton remindMeLaterButton = new JButton("Remind me later"); // in 2 weeks
    remindMeLaterButton.setFont(baseFont);
    remindMeLaterButton.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent evt) {
            if (evt.getKeyCode() == VK_ENTER) {
                evt.consume();
                remindMeLater();
            }
        }
    });
    remindMeLaterButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            remindMeLater();
        }
    });
    buttonPanel.add(registerButton);
    buttonPanel.add(remindMeLaterButton);
    buttonPanel.add(doNotRegisterButton);
    addDivider(buttonPanel, TOP, true);
    gbc.gridx = 0;
    gbc.gridy = 14;
    gbc.fill = HORIZONTAL;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.insets = new Insets(5, 10, 0, 10);
    gbc.gridwidth = 2;
    mainPanel.add(buttonPanel, gbc);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(mainPanel, CENTER);

    pack();
    setResizable(false);
    // Center the dialog on the screen (we do not have the parent)
    Dimension dimension = getToolkit().getScreenSize();
    Rectangle abounds = getBounds();
    setLocation((dimension.width - abounds.width) / 2, (dimension.height - abounds.height) / 2);
    setSize(getPreferredSize());
}

From source file:Main.Interface_Main.java

private void btnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutActionPerformed

    // for copying style
    JLabel label = new JLabel();
    Font font = label.getFont();//from  www.j av a 2 s . c o m

    // create some css from the label's font
    StringBuffer style = new StringBuffer("font-family:" + font.getFamily() + ";");
    style.append("font-weight:" + (font.isBold() ? "bold" : "normal") + ";");
    style.append("font-size:" + font.getSize() + "pt;");

    // html content
    JEditorPane ep = new JEditorPane("text/html", "<html><body style=\"" + style + "\">" //
            + "This application was designed by <A HREF=http://www.friedcircuits.us>FriedCircuits</A> for the USB Tester." //
            + "<br><br><center>App Version: " + appVersion + "<br>FW Version: " + FW_VERSION
            + "</center><br><br>*Connect once to get FW version.</body></html>");

    // handle link events
    ep.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                java.awt.Desktop desktop = java.awt.Desktop.getDesktop();

                URI uri;
                try {
                    uri = new java.net.URI("www.friedcircuits.us");
                    if (desktop.isSupported(Desktop.Action.BROWSE)) {
                        try {
                            desktop.browse(uri);
                        } catch (IOException ex) {
                            Logger.getLogger(Interface_Main.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                } catch (URISyntaxException ex) {
                    Logger.getLogger(Interface_Main.class.getName()).log(Level.SEVERE, null, ex);
                }

            } // roll your own link launcher or use Desktop if J6+
        }
    });
    Color bgColor = label.getBackground();
    UIDefaults defaults = new UIDefaults();
    defaults.put("EditorPane[Enabled].backgroundPainter", bgColor);
    ep.putClientProperty("Nimbus.Overrides", defaults);
    ep.putClientProperty("Nimbus.Overrides.InheritDefaults", true);
    ep.setEditable(false);
    ep.setBackground(bgColor);

    // show
    ImageIcon myCustomIcon = new ImageIcon(getClass().getResource("/faviconbot2edit.png"));
    JOptionPane.showMessageDialog(plCurrent, ep, "About", JOptionPane.INFORMATION_MESSAGE, myCustomIcon);
}

From source file:userinterface.properties.GUIGraphHandler.java

public void plotNewFunction() {

    JDialog dialog;/*  w ww  .j a  v a  2s.  com*/
    JRadioButton radio2d, radio3d, newGraph, existingGraph;
    JTextField functionField, seriesName;
    JButton ok, cancel;
    JComboBox<String> chartOptions;
    JLabel example;

    //init all the fields of the dialog
    dialog = new JDialog(GUIPrism.getGUI());
    radio2d = new JRadioButton("2D");
    radio3d = new JRadioButton("3D");
    newGraph = new JRadioButton("New Graph");
    existingGraph = new JRadioButton("Exisiting");
    chartOptions = new JComboBox<String>();
    functionField = new JTextField();
    ok = new JButton("Plot");
    cancel = new JButton("Cancel");
    seriesName = new JTextField();
    example = new JLabel("<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>");
    example.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            example.setCursor(new Cursor(Cursor.HAND_CURSOR));
            example.setForeground(Color.BLUE);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            example.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            example.setForeground(Color.BLACK);
        }

        @Override
        public void mouseClicked(MouseEvent e) {

            if (e.getButton() == MouseEvent.BUTTON1) {

                if (radio2d.isSelected()) {
                    functionField.setText("x/2 + 5");
                } else {
                    functionField.setText("x+y+5");
                }

                functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15));
                functionField.setForeground(Color.BLACK);

            }
        }

    });

    //set dialog properties
    dialog.setSize(400, 350);
    dialog.setTitle("Plot a new function");
    dialog.setModal(true);
    dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS));
    dialog.setLocationRelativeTo(GUIPrism.getGUI());

    //add every component to their dedicated panels
    JPanel graphTypePanel = new JPanel(new FlowLayout());
    graphTypePanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function type"));
    graphTypePanel.add(radio2d);
    graphTypePanel.add(radio3d);

    JPanel functionFieldPanel = new JPanel(new BorderLayout());
    functionFieldPanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function"));
    functionFieldPanel.add(functionField, BorderLayout.CENTER);
    functionFieldPanel.add(example, BorderLayout.SOUTH);

    JPanel chartSelectPanel = new JPanel();
    chartSelectPanel.setLayout(new BoxLayout(chartSelectPanel, BoxLayout.Y_AXIS));
    chartSelectPanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Plot function to"));
    JPanel radioPlotPanel = new JPanel(new FlowLayout());
    radioPlotPanel.add(newGraph);
    radioPlotPanel.add(existingGraph);
    JPanel chartOptionsPanel = new JPanel(new FlowLayout());
    chartOptionsPanel.add(chartOptions);
    chartSelectPanel.add(radioPlotPanel);
    chartSelectPanel.add(chartOptionsPanel);

    JPanel bottomControlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    bottomControlPanel.add(ok);
    bottomControlPanel.add(cancel);

    JPanel seriesNamePanel = new JPanel(new BorderLayout());
    seriesNamePanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Series name"));
    seriesNamePanel.add(seriesName, BorderLayout.CENTER);

    // add all the panels to the dialog

    dialog.add(graphTypePanel);
    dialog.add(functionFieldPanel);
    dialog.add(chartSelectPanel);
    dialog.add(seriesNamePanel);
    dialog.add(bottomControlPanel);

    // do all the enables and set properties

    radio2d.setSelected(true);
    newGraph.setSelected(true);
    chartOptions.setEnabled(false);
    functionField.setText("Add function expression here....");
    functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15));
    functionField.setForeground(Color.GRAY);
    seriesName.setText("New function");
    ok.setMnemonic('P');
    cancel.setMnemonic('C');
    example.setToolTipText("click to try out");

    ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok");
    ok.getActionMap().put("ok", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ok.doClick();
        }
    });

    cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            "cancel");
    cancel.getActionMap().put("cancel", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            cancel.doClick();
        }
    });

    boolean found = false;

    for (int i = 0; i < theTabs.getTabCount(); i++) {

        if (theTabs.getComponentAt(i) instanceof Graph) {
            chartOptions.addItem(getGraphName(i));
            found = true;
        }
    }

    if (!found) {

        existingGraph.setEnabled(false);
        chartOptions.setEnabled(false);
    }

    //add all the action listeners

    radio2d.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (radio2d.isSelected()) {

                radio3d.setSelected(false);

                if (chartOptions.getItemCount() > 0) {
                    existingGraph.setEnabled(true);
                    chartOptions.setEnabled(true);
                }

                example.setText(
                        "<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>");
            }
        }
    });

    radio3d.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (radio3d.isSelected()) {

                radio2d.setSelected(false);
                newGraph.setSelected(true);
                existingGraph.setEnabled(false);
                chartOptions.setEnabled(false);
                example.setText("<html><font size=3 color=red>Example:</font><font size=3>x+y+5</font></html>");

            }

        }
    });

    newGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (newGraph.isSelected()) {
                existingGraph.setSelected(false);
                chartOptions.setEnabled(false);
            }
        }
    });

    existingGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (existingGraph.isSelected()) {

                newGraph.setSelected(false);
                chartOptions.setEnabled(true);
            }
        }
    });

    ok.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            String function = functionField.getText();

            Expression expr = null;

            try {

                expr = GUIPrism.getGUI().getPrism().parseSingleExpressionString(function);
                expr = (Expression) expr.accept(new ASTTraverseModify() {

                    @Override
                    public Object visit(ExpressionIdent e) throws PrismLangException {
                        return new ExpressionConstant(e.getName(), TypeDouble.getInstance());
                    }

                });

                expr.typeCheck();
                expr.semanticCheck();

            } catch (PrismLangException e1) {

                // for copying style
                JLabel label = new JLabel();

                // html content in our case the error we want to show
                JEditorPane ep = new JEditorPane("text/html",
                        "<html> There was an error parsing the function. To read about what built-in"
                                + " functions are supported <br>and some more information on the functions, visit "
                                + "<a href='http://www.prismmodelchecker.org/manual/ThePRISMLanguage/Expressions'>Prism expressions site</a>."
                                + "<br><br><font color=red>Error: </font>" + e1.getMessage() + " </html>");

                // handle link events
                ep.addHyperlinkListener(new HyperlinkListener() {
                    @Override
                    public void hyperlinkUpdate(HyperlinkEvent e) {
                        if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                            try {
                                Desktop.getDesktop().browse(e.getURL().toURI());
                            } catch (IOException | URISyntaxException e1) {

                                e1.printStackTrace();
                            }
                        }
                    }
                });
                ep.setEditable(false);
                ep.setBackground(label.getBackground());

                // show the error dialog
                JOptionPane.showMessageDialog(dialog, ep, "Parse Error", JOptionPane.ERROR_MESSAGE);
                return;
            }

            if (radio2d.isSelected()) {

                ParametricGraph graph = null;

                if (newGraph.isSelected()) {

                    graph = new ParametricGraph("");
                } else {

                    for (int i = 0; i < theTabs.getComponentCount(); i++) {

                        if (theTabs.getTitleAt(i).equals(chartOptions.getSelectedItem())) {

                            graph = (ParametricGraph) theTabs.getComponent(i);
                        }
                    }

                }

                dialog.dispose();
                defineConstantsAndPlot(expr, graph, seriesName.getText(), newGraph.isSelected(), true);

            } else if (radio3d.isSelected()) {

                try {

                    expr = (Expression) expr.accept(new ASTTraverseModify() {
                        @Override
                        public Object visit(ExpressionIdent e) throws PrismLangException {
                            return new ExpressionConstant(e.getName(), TypeDouble.getInstance());
                        }

                    });

                    expr.semanticCheck();
                    expr.typeCheck();

                } catch (PrismLangException e1) {
                    e1.printStackTrace();
                }

                if (expr.getAllConstants().size() < 2) {

                    JOptionPane.showMessageDialog(dialog,
                            "There are not enough variables in the function to plot a 3D chart!", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }

                // its always a new graph
                ParametricGraph3D graph = new ParametricGraph3D(expr);
                dialog.dispose();
                defineConstantsAndPlot(expr, graph, seriesName.getText(), true, false);
            }

            dialog.dispose();
        }
    });

    cancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });

    // we will show info about the function when field is out of focus
    functionField.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {

            if (!functionField.getText().equals("")) {
                return;
            }

            functionField.setText("Add function expression here....");
            functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15));
            functionField.setForeground(Color.GRAY);
        }

        @Override
        public void focusGained(FocusEvent e) {

            if (!functionField.getText().equals("Add function expression here....")) {
                return;
            }

            functionField.setForeground(Color.BLACK);
            functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15));
            functionField.setText("");
        }
    });

    // show the dialog
    dialog.setVisible(true);
}