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:org.isatools.isacreator.visualization.InvestigationInfoPanel.java

private JPanel prepareInvestigationInformation() {

    investigationInformation.removeAll();

    JEditorPane currentlyShowingInfo = new JEditorPane();
    currentlyShowingInfo.setContentType("text/html");
    currentlyShowingInfo.setEditable(false);
    currentlyShowingInfo.setBackground(UIHelper.BG_COLOR);

    JScrollPane infoScroller = new JScrollPane(currentlyShowingInfo, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    infoScroller.setBackground(UIHelper.BG_COLOR);
    infoScroller.getViewport().setBackground(UIHelper.BG_COLOR);
    infoScroller.setPreferredSize(new Dimension(width - 10, height - 50));
    infoScroller.setBorder(null);/*  w w  w .j  a  v a  2s .  c o  m*/

    IAppWidgetFactory.makeIAppScrollPane(infoScroller);

    Map<String, String> data = getInvestigationDetails();

    String labelContent = "<html>" + "<head>" + "<style type=\"text/css\">" + "<!--" + ".bodyFont {"
            + "   font-family: Verdana;" + "   font-size: 9px;" + "   color: #006838;" + "}" + "-->"
            + "</style>" + "</head>" + "<body class=\"bodyFont\">";

    for (Object key : data.keySet()) {
        labelContent += ("<p><b>" + ((String) key).trim() + ": </b>");
        labelContent += (data.get(key) + "</font></p>");
    }

    labelContent += "</body></html>";

    currentlyShowingInfo.setText(labelContent);

    investigationInformation.add(infoScroller);

    return investigationInformation;
}

From source file:org.isatools.isacreator.visualization.StudyInfoPanel.java

private JPanel prepareStudyInformation() {

    studyInformation.removeAll();//from   w  ww  .  jav  a 2 s . c om

    JEditorPane currentlyShowingInfo = new JEditorPane();
    currentlyShowingInfo.setContentType("text/html");
    currentlyShowingInfo.setEditable(false);
    currentlyShowingInfo.setBackground(UIHelper.BG_COLOR);
    currentlyShowingInfo.setPreferredSize(new Dimension(width - 10, height - 30));

    JScrollPane infoScroller = new JScrollPane(currentlyShowingInfo, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    infoScroller.setBackground(UIHelper.BG_COLOR);
    infoScroller.getViewport().setBackground(UIHelper.BG_COLOR);
    infoScroller.setPreferredSize(new Dimension(width - 10, height - 50));
    infoScroller.setBorder(null);

    IAppWidgetFactory.makeIAppScrollPane(infoScroller);

    Map<String, String> data = getStudyDetails();

    String labelContent = "<html>" + "<head>" + "<style type=\"text/css\">" + "<!--" + ".bodyFont {"
            + "   font-family: Verdana;" + "   font-size: 9px;" + "   color: #006838;" + "}" + "-->"
            + "</style>" + "</head>" + "<body class=\"bodyFont\">";

    for (Object key : data.keySet()) {
        labelContent += ("<p><b>" + ((String) key).trim() + ": </b>");
        labelContent += (data.get(key) + "</font></p>");
    }

    labelContent += "</body></html>";

    currentlyShowingInfo.setText(labelContent);

    studyInformation.add(infoScroller);

    return studyInformation;
}

From source file:org.nuclos.client.dbtransfer.DBTransferImport.java

private PanelWizardStep newStep1(final MainFrameTab ifrm) {
    final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate();
    final PanelWizardStep step = new PanelWizardStep(
            localeDelegate.getMessage("dbtransfer.import.step1.1", "Konfigurationsdatei"),
            localeDelegate.getMessage("dbtransfer.import.step1.2",
                    "Bitte w\u00e4hlen Sie eine Konfigurationsdatei aus."));

    final JLabel lbFile = new JLabel(localeDelegate.getMessage("dbtransfer.import.step1.3", "Datei"));

    utils.initJPanel(step,/*from w w  w  .  ja  va  2 s.com*/
            new double[] { TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED,
                    TableLayout.FILL },
            new double[] { 20, TableLayout.PREFERRED, lbFile.getPreferredSize().height, TableLayout.FILL });

    final JButton btnBrowse = new JButton("...");
    //final JProgressBar progressBar = new JProgressBar(0, 230);
    final JCheckBox chbxImportAsNuclon = new JCheckBox(
            localeDelegate.getMessage("configuration.transfer.import.as.nuclon", "Import als Nuclon"));
    chbxImportAsNuclon.setEnabled(false);
    final JEditorPane editWarnings = new JEditorPane();
    editWarnings.setContentType("text/html");
    editWarnings.setEditable(false);
    editWarnings.setBackground(Color.WHITE);

    final JScrollPane scrollWarn = new JScrollPane(editWarnings);
    scrollWarn.setPreferredSize(new Dimension(680, 250));
    scrollWarn.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    scrollWarn.getVerticalScrollBar().setUnitIncrement(20);
    scrollWarn.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollWarn.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    final JScrollPane scrollPrev = new JScrollPane(jpnPreviewContent);
    scrollPrev.setPreferredSize(new Dimension(680, 250));
    scrollPrev.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));
    scrollPrev.getVerticalScrollBar().setUnitIncrement(20);
    scrollPrev.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPrev.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    final JPanel jpnPreview = new JPanel(new BorderLayout());
    jpnPreview.add(jpnPreviewHeader, BorderLayout.NORTH);
    jpnPreview.add(scrollPrev, BorderLayout.CENTER);
    jpnPreview.add(jpnPreviewFooter, BorderLayout.SOUTH);
    jpnPreview.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    jpnPreview.setBackground(Color.WHITE);
    jpnPreviewHeader.setBackground(Color.WHITE);
    jpnPreviewContent.setBackground(Color.WHITE);
    jpnPreviewFooter.setBackground(Color.WHITE);

    final JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab(localeDelegate.getMessage("configuration.transfer.prepare.warnings.tab", "Warnungen"),
            scrollWarn);
    final String sDefaultPreparePreviewTabText = localeDelegate
            .getMessage("configuration.transfer.prepare.preview.tab", "Vorschau der Schema Aenderungen");
    tabbedPane.addTab(sDefaultPreparePreviewTabText, jpnPreview);

    final JLabel lbNewUser = new JLabel();

    step.add(lbFile, "0,0");
    step.add(tfTransferFile, "1,0");
    step.add(btnBrowse, "2,0");
    step.add(chbxImportAsNuclon, "1,1");//step.add(progressBar, "1,1");
    step.add(lbNewUser, "0,2,3,2");
    step.add(tabbedPane, "0,3,3,3");

    tfTransferFile.setEditable(false);

    final ActionListener prepareImportAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            ifrm.lockLayerWithProgress(Transfer.TOPIC_CORRELATIONID_PREPARE);

            Thread t = new Thread() {
                @Override
                public void run() {
                    step.setComplete(false);
                    boolean blnTransferWithWarnings = false;
                    //progressBar.setValue(0);
                    //progressBar.setVisible(true);
                    try {
                        String fileName = tfTransferFile.getText();
                        if (StringUtils.isNullOrEmpty(fileName)) {
                            return;
                        }
                        File f = new File(fileName);
                        long size = f.length();

                        final InputStream fin = new BufferedInputStream(new FileInputStream(f));
                        final byte[] transferFile;
                        try {
                            transferFile = utils.getBytes(fin, (int) size);
                        } finally {
                            fin.close();
                        }

                        resetStep2();
                        importTransferObject = getTransferFacadeRemote().prepareTransfer(isNuclon,
                                transferFile);
                        chbxImportAsNuclon.setEnabled(importTransferObject.getTransferOptions()
                                .containsKey(TransferOption.IS_NUCLON_IMPORT_ALLOWED));

                        step.setComplete(!importTransferObject.result.hasCriticals());

                        if (!importTransferObject.result.hasCriticals()
                                && !importTransferObject.result.hasWarnings()) {
                            editWarnings.setText(localeDelegate.getMessage(
                                    "configuration.transfer.prepare.no.warnings", "Keine Warnungen"));
                        } else {
                            editWarnings.setText("<html><body><font color=\"#800000\">"
                                    + importTransferObject.result.getCriticals() + "</font>"
                                    + (importTransferObject.result.hasCriticals() ? "<br />" : "")
                                    + importTransferObject.result.getWarnings() + "</body></html>");
                        }

                        int iPreviewSize = importTransferObject.getPreviewParts().size();
                        blnTransferWithWarnings = setupPreviewPanel(importTransferObject.getPreviewParts());
                        tabbedPane.setTitleAt(1, sDefaultPreparePreviewTabText
                                + (iPreviewSize == 0 ? "" : " (" + iPreviewSize + ")"));
                        lbNewUser.setText(
                                "Neue Benutzer" + ": " + (importTransferObject.getNewUserCount() == 0 ? "keine"
                                        : importTransferObject.getNewUserCount()));
                    } catch (Exception e) {
                        //                              progressBar.setVisible(false);
                        Errors.getInstance().showExceptionDialog(ifrm, e);
                    } finally {
                        btnBrowse.setEnabled(true);
                        //                              progressBar.setVisible(false);
                        ifrm.unlockLayer();
                    }
                    if (blnTransferWithWarnings) {
                        JOptionPane.showMessageDialog(jpnPreviewContent, localeDelegate.getMessage(
                                "dbtransfer.import.step1.19",
                                "Nicht alle Statements knnen durchgefhrt werden!\nBitte kontrollieren Sie die mit rot markierten Eintrge!",
                                "Warning", JOptionPane.WARNING_MESSAGE));
                    }
                }

            };

            t.start();
        }
    };
    final ActionListener browseAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            final JFileChooser filechooser = utils.getFileChooser(
                    localeDelegate.getMessage("configuration.transfer.file.nuclet", "Nuclet-Dateien"),
                    ".nuclet");
            final int iBtn = filechooser.showOpenDialog(ifrm);

            if (iBtn == JFileChooser.APPROVE_OPTION) {

                final File file = filechooser.getSelectedFile();
                if (file != null) {
                    tfTransferFile.setText("");
                    btnBrowse.setEnabled(false);
                    //progressBar.setVisible(true);

                    String fileName = file.getPath();
                    if (StringUtils.isNullOrEmpty(fileName)) {
                        return;
                    }

                    tfTransferFile.setText(fileName);

                    prepareImportAction.actionPerformed(new ActionEvent(this, 0, "prepare"));
                }
            }
        }
    };
    final ActionListener importAsNuclonAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            isNuclon = chbxImportAsNuclon.isSelected();
            prepareImportAction.actionPerformed(new ActionEvent(this, 0, "prepare"));
        }
    };
    btnBrowse.addActionListener(browseAction);
    chbxImportAsNuclon.addActionListener(importAsNuclonAction);

    //      progressBar.setVisible(false);

    return step;
}

From source file:uk.ac.ucl.cs.cmic.giftcloud.uploadapp.GiftCloudDialogs.java

public void showMessage(final String message) throws HeadlessException {

    final JPanel messagePanel = new JPanel(new GridBagLayout());
    final JEditorPane textField = new JEditorPane();
    textField.setContentType("text/html");
    textField.setText(message);//from w  w  w . j  a  v a2 s  .c  o  m
    textField.setEditable(false);
    textField.setBackground(null);
    textField.setBorder(null);
    textField.setEditable(false);
    textField.setForeground(UIManager.getColor("Label.foreground"));
    textField.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
    textField.setFont(UIManager.getFont("Label.font"));
    textField.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(e.getURL().toURI());
                    } catch (IOException e1) {
                        // Ignore failure to launch URL
                    } catch (URISyntaxException e1) {
                        // Ignore failure to launch URL
                    }
                }
            }
        }
    });

    messagePanel.add(textField);
    textField.setAlignmentX(SwingConstants.CENTER);

    JOptionPane.showMessageDialog(mainFrame.getContainer(), messagePanel, applicationName,
            JOptionPane.INFORMATION_MESSAGE, icon);
}

From source file:VASSAL.launch.ModuleManagerWindow.java

public ModuleManagerWindow() {
    setTitle("VASSAL");
    setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));

    ApplicationIcons.setFor(this);

    final AbstractAction shutDownAction = new AbstractAction() {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            if (!AbstractLaunchAction.shutDown())
                return;

            final Prefs gl = Prefs.getGlobalPrefs();
            try {
                gl.write();/*from w  w w  .  j av  a  2 s.  c  o m*/
                gl.close();
            } catch (IOException ex) {
                WriteErrorDialog.error(ex, gl.getFile());
            } finally {
                IOUtils.closeQuietly(gl);
            }

            logger.info("Exiting");
            System.exit(0);
        }
    };
    shutDownAction.putValue(Action.NAME, Resources.getString(Resources.QUIT));

    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            shutDownAction.actionPerformed(null);
        }
    });

    // setup menubar and actions
    final MenuManager mm = MenuManager.getInstance();
    final MenuBarProxy mb = mm.getMenuBarProxyFor(this);

    // file menu
    final MenuProxy fileMenu = new MenuProxy(Resources.getString("General.file"));
    fileMenu.setMnemonic(Resources.getString("General.file.shortcut").charAt(0));

    fileMenu.add(mm.addKey("Main.play_module"));
    fileMenu.add(mm.addKey("Main.edit_module"));
    fileMenu.add(mm.addKey("Main.new_module"));
    fileMenu.add(mm.addKey("Main.import_module"));
    fileMenu.addSeparator();

    if (!SystemUtils.IS_OS_MAC_OSX) {
        fileMenu.add(mm.addKey("Prefs.edit_preferences"));
        fileMenu.addSeparator();
        fileMenu.add(mm.addKey("General.quit"));
    }

    // tools menu
    final MenuProxy toolsMenu = new MenuProxy(Resources.getString("General.tools"));

    // Initialize Global Preferences
    Prefs.getGlobalPrefs().getEditor().initDialog(this);
    Prefs.initSharedGlobalPrefs();

    final BooleanConfigurer serverStatusConfig = new BooleanConfigurer(SHOW_STATUS_KEY, null, Boolean.FALSE);
    Prefs.getGlobalPrefs().addOption(null, serverStatusConfig);

    dividerLocationConfig = new IntConfigurer(DIVIDER_LOCATION_KEY, null, -10);
    Prefs.getGlobalPrefs().addOption(null, dividerLocationConfig);

    toolsMenu.add(new CheckBoxMenuItemProxy(new AbstractAction(Resources.getString("Chat.server_status")) {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            serverStatusView.toggleVisibility();
            serverStatusConfig.setValue(serverStatusConfig.booleanValue() ? Boolean.FALSE : Boolean.TRUE);
            if (serverStatusView.isVisible()) {
                setDividerLocation(getPreferredDividerLocation());
            }
        }
    }, serverStatusConfig.booleanValue()));

    // help menu
    final MenuProxy helpMenu = new MenuProxy(Resources.getString("General.help"));
    helpMenu.setMnemonic(Resources.getString("General.help.shortcut").charAt(0));

    helpMenu.add(mm.addKey("General.help"));
    helpMenu.add(mm.addKey("Main.tour"));
    helpMenu.addSeparator();
    helpMenu.add(mm.addKey("UpdateCheckAction.update_check"));
    helpMenu.add(mm.addKey("Help.error_log"));

    if (!SystemUtils.IS_OS_MAC_OSX) {
        helpMenu.addSeparator();
        helpMenu.add(mm.addKey("AboutScreen.about_vassal"));
    }

    mb.add(fileMenu);
    mb.add(toolsMenu);
    mb.add(helpMenu);

    // add actions
    mm.addAction("Main.play_module", new Player.PromptLaunchAction(this));
    mm.addAction("Main.edit_module", new Editor.PromptLaunchAction(this));
    mm.addAction("Main.new_module", new Editor.NewModuleLaunchAction(this));
    mm.addAction("Main.import_module", new Editor.PromptImportLaunchAction(this));
    mm.addAction("Prefs.edit_preferences", Prefs.getGlobalPrefs().getEditor().getEditAction());
    mm.addAction("General.quit", shutDownAction);

    URL url = null;
    try {
        url = new File(Documentation.getDocumentationBaseDir(), "README.html").toURI().toURL();
    } catch (MalformedURLException e) {
        ErrorDialog.bug(e);
    }
    mm.addAction("General.help", new ShowHelpAction(url, null));

    mm.addAction("Main.tour", new LaunchTourAction(this));
    mm.addAction("AboutScreen.about_vassal", new AboutVASSALAction(this));
    mm.addAction("UpdateCheckAction.update_check", new UpdateCheckAction(this));
    mm.addAction("Help.error_log", new ShowErrorLogAction(this));

    setJMenuBar(mm.getMenuBarFor(this));

    // Load Icons
    moduleIcon = new ImageIcon(getClass().getResource("/images/mm-module.png"));
    activeExtensionIcon = new ImageIcon(getClass().getResource("/images/mm-extension-active.png"));
    inactiveExtensionIcon = new ImageIcon(getClass().getResource("/images/mm-extension-inactive.png"));
    openGameFolderIcon = new ImageIcon(getClass().getResource("/images/mm-gamefolder-open.png"));
    closedGameFolderIcon = new ImageIcon(getClass().getResource("/images/mm-gamefolder-closed.png"));
    fileIcon = new ImageIcon(getClass().getResource("/images/mm-file.png"));

    // build module controls
    final JPanel moduleControls = new JPanel(new BorderLayout());
    modulePanelLayout = new CardLayout();
    moduleView = new JPanel(modulePanelLayout);
    buildTree();
    final JScrollPane scroll = new JScrollPane(tree);
    moduleView.add(scroll, "modules");

    final JEditorPane l = new JEditorPane("text/html", Resources.getString("ModuleManager.quickstart"));
    l.setEditable(false);

    // Try to get background color and font from LookAndFeel;
    // otherwise, use dummy JLabel to get color and font.
    Color bg = UIManager.getColor("control");
    Font font = UIManager.getFont("Label.font");

    if (bg == null || font == null) {
        final JLabel dummy = new JLabel();
        if (bg == null)
            bg = dummy.getBackground();
        if (font == null)
            font = dummy.getFont();
    }

    l.setBackground(bg);
    ((HTMLEditorKit) l.getEditorKit()).getStyleSheet()
            .addRule("body { font: " + font.getFamily() + " " + font.getSize() + "pt }");

    l.addHyperlinkListener(BrowserSupport.getListener());

    // FIXME: use MigLayout for this!
    // this is necessary to get proper vertical alignment
    final JPanel p = new JPanel(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    p.add(l, c);

    moduleView.add(p, "quickStart");
    modulePanelLayout.show(moduleView, getModuleCount() == 0 ? "quickStart" : "modules");
    moduleControls.add(moduleView, BorderLayout.CENTER);
    moduleControls.setBorder(new TitledBorder(Resources.getString("ModuleManager.recent_modules")));

    add(moduleControls);

    // build server status controls
    final ServerStatusView serverStatusControls = new ServerStatusView(new CgiServerStatus());
    serverStatusControls.setBorder(new TitledBorder(Resources.getString("Chat.server_status")));

    serverStatusView = new ComponentSplitter().splitRight(moduleControls, serverStatusControls, false);
    serverStatusView.revalidate();

    // show the server status controls according to the prefs
    if (serverStatusConfig.booleanValue()) {
        serverStatusView.showComponent();
    }

    setDividerLocation(getPreferredDividerLocation());
    serverStatusView.addPropertyChangeListener("dividerLocation", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            setPreferredDividerLocation((Integer) e.getNewValue());
        }
    });

    final Rectangle r = Info.getScreenBounds(this);
    serverStatusControls.setPreferredSize(new Dimension((int) (r.width / 3.5), 0));

    setSize(3 * r.width / 4, 3 * r.height / 4);

    // Save/load the window position and size in prefs
    final PositionOption option = new PositionOption(PositionOption.key + "ModuleManager", this);
    Prefs.getGlobalPrefs().addOption(option);
}