Example usage for javax.swing JTextArea setWrapStyleWord

List of usage examples for javax.swing JTextArea setWrapStyleWord

Introduction

In this page you can find the example usage for javax.swing JTextArea setWrapStyleWord.

Prototype

@BeanProperty(description = "should wrapping occur at word boundaries")
public void setWrapStyleWord(boolean word) 

Source Link

Document

Sets the style of wrapping used if the text area is wrapping lines.

Usage

From source file:tvbrowser.ui.mainframe.MainFrame.java

private void showInfoTextMessage(String header, String infoText, int width) {
    JTextArea textArea = new JTextArea(infoText);
    textArea.setEditable(false);/*from  www.  j  av a2 s  .c  om*/
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);

    JScrollPane scrollPane = new JScrollPane(textArea);

    scrollPane.setPreferredSize(new Dimension(width, 150));

    Object[] msg = { header, scrollPane };
    JOptionPane.showMessageDialog(this, msg, Localizer.getLocalization(Localizer.I18N_INFO),
            JOptionPane.INFORMATION_MESSAGE);
}

From source file:us.ihmc.codecs.loader.OpenH264Downloader.java

private static void acceptLicenseGUI() {

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    JTextArea license = new JTextArea(getLicenseText());
    license.setEditable(false);/*from  w  w  w  . ja va2 s .c  o  m*/
    license.setLineWrap(true);
    license.setWrapStyleWord(true);
    JScrollPane scroll = new JScrollPane(license);
    scroll.setPreferredSize(new Dimension(500, 500));
    panel.add(scroll);
    panel.add(new JLabel("Do you accept the OpenH264 License?"));

    if (JOptionPane.showOptionDialog(null, panel, "OpenH264 Video Codec provided by Cisco Systems, Inc.",
            JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null) != JOptionPane.YES_OPTION) {
        JOptionPane.showMessageDialog(null, "User did not accept OpenH264 license", "License not accepted",
                JOptionPane.ERROR_MESSAGE);
        System.exit(-1);
    }

}

From source file:us.ihmc.codecs.loader.OpenH264Downloader.java

/**
 * Shows an about dialog for the license with disable button, as per license terms
 *///from www  .  j  a  va2s .c o  m
public static void showAboutCiscoDialog() {
    JPanel panel = new JPanel();
    panel.add(new JLabel("OpenH264 Video Codec provided by Cisco Systems, Inc."));
    panel.add(new JLabel("License terms"));

    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    JTextArea license = new JTextArea(getLicenseText());
    license.setEditable(false);
    license.setLineWrap(true);
    license.setWrapStyleWord(true);
    JScrollPane scroll = new JScrollPane(license);
    scroll.setPreferredSize(new Dimension(500, 500));
    panel.add(scroll);

    String[] options = new String[2];

    boolean enabled = isEnabled();
    if (enabled) {
        options[0] = "Disable Cisco OpenH264 plugin";
    } else {
        options[0] = "Enable Cisco OpenH264 plugin";
    }
    options[1] = "Close";

    int res = JOptionPane.showOptionDialog(null, panel, "OpenH264 Video Codec provided by Cisco Systems, Inc.",
            JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, null);

    if (res == 0) {
        if (enabled) {
            deleteOpenH264Library();
        } else {
            loadOpenH264(false);
        }
    }
}

From source file:util.ui.UiUtilities.java

/**
 * Creates a text area that holds a help text.
 *
 * @param msg/*from   w  ww .java 2  s . com*/
 *          The help text.
 * @return A text area containing the help text.
 */
public static JTextArea createHelpTextArea(String msg) {
    JTextArea descTA = new JTextArea(msg);
    descTA.setBorder(BorderFactory.createEmptyBorder());
    descTA.setFont(new JLabel().getFont());
    descTA.setEditable(false);
    descTA.setOpaque(false);
    descTA.setWrapStyleWord(true);
    descTA.setLineWrap(true);
    descTA.setFocusable(false);

    Color bg = new JPanel().getBackground();

    descTA.setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue()));

    return descTA;
}

From source file:utybo.branchingstorytree.swing.editor.StoryEditor.java

public StoryEditor(BranchingStory baseStory) throws BSTException {
    setLayout(new MigLayout("hidemode 3", "[grow]", "[][grow]"));

    JToolBar toolBar = new JToolBar();
    toolBar.setBorder(null);/* w w w  .j  av  a 2s  . c  o m*/
    toolBar.setFloatable(false);
    add(toolBar, "cell 0 0,growx");

    JButton btnSaveAs = new JButton(Lang.get("saveas"), new ImageIcon(Icons.getImage("Save As", 16)));
    btnSaveAs.addActionListener(e -> {
        saveAs();
    });
    toolBar.add(btnSaveAs);

    JButton btnSave = new JButton(Lang.get("save"), new ImageIcon(Icons.getImage("Save", 16)));
    btnSave.addActionListener(e -> {
        save();
    });
    toolBar.add(btnSave);

    JButton btnPlay = new JButton(Lang.get("play"), new ImageIcon(Icons.getImage("Circled Play", 16)));
    btnPlay.addActionListener(ev -> {
        try {
            String s = exportToString();
            File f = Files.createTempDirectory("openbst").toFile();
            File bstFile = new File(f, "expoted.bst");
            try (FileOutputStream fos = new FileOutputStream(bstFile);) {
                IOUtils.write(s, fos, StandardCharsets.UTF_8);
            }
            OpenBSTGUI.getInstance().openStory(bstFile);
        } catch (Exception e) {
            OpenBST.LOG.error("Export failed", e);
            Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("editor.exportfail"), e);
        }
    });
    toolBar.add(btnPlay);

    JButton btnFilePreview = new JButton(Lang.get("editor.exportpreview"),
            new ImageIcon(Icons.getImage("PreviewText", 16)));
    btnFilePreview.addActionListener(e -> {
        try {
            String s = exportToString();
            JDialog dialog = new JDialog(OpenBSTGUI.getInstance(), Lang.get("editor.exportpreview"));
            JTextArea jta = new JTextArea(s);
            jta.setLineWrap(true);
            jta.setWrapStyleWord(true);
            dialog.add(new JScrollPane(jta));

            dialog.setModalityType(ModalityType.APPLICATION_MODAL);
            dialog.setSize((int) (Icons.getScale() * 350), (int) (Icons.getScale() * 300));
            dialog.setLocationRelativeTo(OpenBSTGUI.getInstance());
            dialog.setVisible(true);
        } catch (Exception x) {
            OpenBST.LOG.error("Failed to preview", x);
            Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("editor.previewerror"), x);
        }
    });
    toolBar.add(btnFilePreview);

    Component horizontalGlue = Box.createHorizontalGlue();
    toolBar.add(horizontalGlue);

    JButton btnClose = new JButton(Lang.get("close"), new ImageIcon(Icons.getImage("Cancel", 16)));
    btnClose.addActionListener(e -> {
        askClose();
    });
    toolBar.add(btnClose);

    for (final Component component : toolBar.getComponents()) {
        if (component instanceof JButton) {
            ((JButton) component).setHideActionText(false);
            ((JButton) component).setToolTipText(((JButton) component).getText());
            ((JButton) component).setText("");
        }
    }

    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.setTabPlacement(JTabbedPane.LEFT);
    add(tabbedPane, "cell 0 1,grow");

    tabbedPane.addTab("Beta Warning", new StoryEditorWelcomeScreen());

    details = new StoryDetailsEditor(this);
    tabbedPane.addTab(Lang.get("editor.details"), details);

    nodesEditor = new StoryNodesEditor();
    tabbedPane.addTab(Lang.get("editor.nodes"), nodesEditor);

    this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("control S"),
            "doSave");
    this.getActionMap().put("doSave", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            save();
        }
    });

    importFrom(baseStory);
}

From source file:utybo.branchingstorytree.swing.OpenBSTGUI.java

private JMenu createShortMenu() {
    JMenu shortMenu = new JMenu();
    addDarkModeCallback(b -> {/*from w w w.  j  a  v a 2  s . co m*/
        shortMenu.setBackground(b ? OPENBST_BLUE.darker().darker() : OPENBST_BLUE.brighter());
        shortMenu.setForeground(b ? Color.WHITE : OPENBST_BLUE);
    });
    shortMenu.setBackground(OPENBST_BLUE.brighter());
    shortMenu.setForeground(OPENBST_BLUE);
    shortMenu.setText(Lang.get("banner.title"));
    shortMenu.setIcon(new ImageIcon(Icons.getImage("Logo", 16)));
    JMenuItem label = new JMenuItem(Lang.get("menu.title"));
    label.setEnabled(false);
    shortMenu.add(label);
    shortMenu.addSeparator();
    shortMenu.add(
            new JMenuItem(new AbstractAction(Lang.get("menu.open"), new ImageIcon(Icons.getImage("Open", 16))) {
                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    openStory(VisualsUtils.askForFile(OpenBSTGUI.this, Lang.get("file.title")));
                }
            }));

    shortMenu.addSeparator();

    shortMenu.add(new JMenuItem(
            new AbstractAction(Lang.get("menu.create"), new ImageIcon(Icons.getImage("Add Property", 16))) {
                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    doNewEditor();
                }
            }));

    JMenu additionalMenu = new JMenu(Lang.get("menu.advanced"));
    shortMenu.add(additionalMenu);

    additionalMenu.add(new JMenuItem(
            new AbstractAction(Lang.get("menu.package"), new ImageIcon(Icons.getImage("Open Archive", 16))) {
                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    new PackageDialog(instance).setVisible(true);
                }
            }));
    additionalMenu.add(new JMenuItem(
            new AbstractAction(Lang.get("langcheck"), new ImageIcon(Icons.getImage("LangCheck", 16))) {
                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    final Map<String, String> languages = new Gson()
                            .fromJson(new InputStreamReader(
                                    OpenBST.class.getResourceAsStream(
                                            "/utybo/branchingstorytree/swing/lang/langs.json"),
                                    StandardCharsets.UTF_8), new TypeToken<Map<String, String>>() {
                                    }.getType());
                    languages.remove("en");
                    languages.remove("default");
                    JComboBox<String> jcb = new JComboBox<>(new Vector<>(languages.keySet()));
                    JPanel panel = new JPanel();
                    panel.add(new JLabel(Lang.get("langcheck.choose")));
                    panel.add(jcb);
                    int result = JOptionPane.showOptionDialog(OpenBSTGUI.this, panel, Lang.get("langcheck"),
                            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
                    if (result == JOptionPane.OK_OPTION) {
                        Locale selected = new Locale((String) jcb.getSelectedItem());
                        if (!Lang.getMap().keySet().contains(selected)) {
                            try {
                                Lang.loadTranslationsFromFile(selected,
                                        OpenBST.class
                                                .getResourceAsStream("/utybo/branchingstorytree/swing/lang/"
                                                        + languages.get(jcb.getSelectedItem().toString())));
                            } catch (UnrespectedModelException | IOException e1) {
                                LOG.warn("Failed to load translation file", e1);
                            }
                        }
                        ArrayList<String> list = new ArrayList<>();
                        Lang.getLocaleMap(Locale.ENGLISH).forEach((k, v) -> {
                            if (!Lang.getLocaleMap(selected).containsKey(k)) {
                                list.add(k + "\n");
                            }
                        });
                        StringBuilder sb = new StringBuilder();
                        Collections.sort(list);
                        list.forEach(s -> sb.append(s));
                        JDialog dialog = new JDialog(OpenBSTGUI.this, Lang.get("langcheck"));
                        dialog.getContentPane().setLayout(new MigLayout());
                        dialog.getContentPane().add(new JLabel(Lang.get("langcheck.result")),
                                "pushx, growx, wrap");
                        JTextArea area = new JTextArea();
                        area.setLineWrap(true);
                        area.setWrapStyleWord(true);
                        area.setText(sb.toString());
                        area.setEditable(false);
                        area.setBorder(BorderFactory.createLoweredBevelBorder());
                        JScrollPane jsp = new JScrollPane(area);
                        jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
                        dialog.getContentPane().add(jsp, "pushx, pushy, growx, growy");
                        dialog.setSize((int) (Icons.getScale() * 300), (int) (Icons.getScale() * 300));
                        dialog.setLocationRelativeTo(OpenBSTGUI.this);
                        dialog.setModalityType(ModalityType.APPLICATION_MODAL);
                        dialog.setVisible(true);
                    }
                }
            }));

    additionalMenu.add(new JMenuItem(
            new AbstractAction(Lang.get("menu.debug"), new ImageIcon(Icons.getImage("Code", 16))) {
                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    DebugInfo.launch(OpenBSTGUI.this);
                }
            }));

    JMenu includedFiles = new JMenu("Included BST files");

    for (Entry<String, String> entry : OpenBST.getInternalFiles().entrySet()) {
        JMenuItem jmi = new JMenuItem(entry.getKey());
        jmi.addActionListener(ev -> {
            String path = "/bst/" + entry.getValue();
            InputStream is = OpenBSTGUI.class.getResourceAsStream(path);
            ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(OpenBSTGUI.this, "Extracting...",
                    is);
            new Thread(() -> {
                try {
                    File f = File.createTempFile("openbstinternal", ".bsp");
                    FileOutputStream fos = new FileOutputStream(f);
                    IOUtils.copy(pmis, fos);
                    openStory(f);
                } catch (final IOException e) {
                    LOG.error("IOException caught", e);
                    showException(Lang.get("file.error").replace("$e", e.getClass().getSimpleName())
                            .replace("$m", e.getMessage()), e);
                }

            }).start();

        });
        includedFiles.add(jmi);
    }
    additionalMenu.add(includedFiles);

    shortMenu.addSeparator();

    JMenu themesMenu = new JMenu(Lang.get("menu.themes"));
    shortMenu.add(themesMenu);
    themesMenu.setIcon(new ImageIcon(Icons.getImage("Color Wheel", 16)));
    ButtonGroup themesGroup = new ButtonGroup();
    JRadioButtonMenuItem jrbmi;

    jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.dark"));
    if (0 == selectedTheme) {
        jrbmi.setSelected(true);
    }
    jrbmi.addActionListener(e -> switchLaF(0, DARK_THEME));
    themesMenu.add(jrbmi);
    themesGroup.add(jrbmi);

    jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.light"));
    if (1 == selectedTheme) {
        jrbmi.setSelected(true);
    }
    jrbmi.addActionListener(e -> switchLaF(1, LIGHT_THEME));
    themesMenu.add(jrbmi);
    themesGroup.add(jrbmi);

    jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.debug"));
    if (2 == selectedTheme) {
        jrbmi.setSelected(true);
    }
    jrbmi.addActionListener(e -> switchLaF(2, DEBUG_THEME));
    themesMenu.add(jrbmi);
    themesGroup.add(jrbmi);

    JMenu additionalLightThemesMenu = new JMenu(Lang.get("menu.themes.morelight"));
    int j = 3;
    for (Map.Entry<String, LookAndFeel> entry : ADDITIONAL_LIGHT_THEMES.entrySet()) {
        int jf = j;
        jrbmi = new JRadioButtonMenuItem(entry.getKey());
        if (j == selectedTheme)
            jrbmi.setSelected(true);
        jrbmi.addActionListener(e -> switchLaF(jf, entry.getValue()));
        additionalLightThemesMenu.add(jrbmi);
        themesGroup.add(jrbmi);
        j++;
    }
    themesMenu.add(additionalLightThemesMenu);

    JMenu additionalDarkThemesMenu = new JMenu(Lang.get("menu.themes.moredark"));
    for (Map.Entry<String, LookAndFeel> entry : ADDITIONAL_DARK_THEMES.entrySet()) {
        int jf = j;
        jrbmi = new JRadioButtonMenuItem(entry.getKey());
        if (j == selectedTheme)
            jrbmi.setSelected(true);
        jrbmi.addActionListener(e -> switchLaF(jf, entry.getValue()));
        additionalDarkThemesMenu.add(jrbmi);
        themesGroup.add(jrbmi);
        j++;
    }
    themesMenu.add(additionalDarkThemesMenu);

    shortMenu.add(new JMenuItem(
            new AbstractAction(Lang.get("menu.about"), new ImageIcon(Icons.getImage("About", 16))) {
                /**
                 *
                 */
                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    new AboutDialog(instance).setVisible(true);
                }
            }));

    return shortMenu;
}

From source file:utybo.branchingstorytree.swing.visuals.AboutDialog.java

@SuppressWarnings("unchecked")
public AboutDialog(OpenBSTGUI parent) {
    super(parent);
    setTitle(Lang.get("about.title"));
    setModalityType(ModalityType.APPLICATION_MODAL);

    JPanel banner = new JPanel(new FlowLayout(FlowLayout.CENTER));
    banner.setBackground(OpenBSTGUI.OPENBST_BLUE);
    JLabel lblOpenbst = new JLabel(new ImageIcon(Icons.getImage("FullLogoWhite", 48)));
    lblOpenbst.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    banner.add(lblOpenbst, "flowx,cell 0 0,alignx center");
    getContentPane().add(banner, BorderLayout.NORTH);

    JPanel pan = new JPanel();
    pan.setLayout(new MigLayout("insets 10, gap 10px", "[grow]", "[][][grow]"));
    getContentPane().add(pan, BorderLayout.CENTER);

    JLabel lblWebsite = new JLabel("https://utybo.github.io/BST/");
    Font f = lblWebsite.getFont();
    @SuppressWarnings("rawtypes")
    Map attrs = f.getAttributes();
    attrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    lblWebsite.setFont(f.deriveFont(attrs));
    lblWebsite.setForeground(OpenBSTGUI.OPENBST_BLUE);
    lblWebsite.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    lblWebsite.addMouseListener(new MouseAdapter() {
        @Override//from  ww  w  .  j  a  v a 2s. co m
        public void mouseClicked(MouseEvent e) {
            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(new URL("https://utybo.github.io/BST/").toURI());
                } catch (IOException | URISyntaxException e1) {
                    OpenBST.LOG.warn("Exception when trying to open website", e1);
                }
            }
        }
    });
    pan.add(lblWebsite, "cell 0 0,alignx center");

    JLabel lblVersion = new JLabel(Lang.get("about.version").replace("$v", OpenBST.VERSION));
    pan.add(lblVersion, "flowy,cell 0 1");

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBorder(new LineBorder(pan.getBackground().darker(), 1, false));
    pan.add(scrollPane, "cell 0 2,grow");

    JTextArea textArea = new JTextArea();
    textArea.setMargin(new Insets(5, 5, 5, 5));
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setFont(new Font(textArea.getFont().getFontName(), Font.PLAIN, (int) (Icons.getScale() * 11)));

    try (InputStream in = getClass().getResourceAsStream("/utybo/branchingstorytree/swing/about.txt");) {
        textArea.setText(IOUtils.toString(in, StandardCharsets.UTF_8));
    } catch (IOException ex) {
        OpenBST.LOG.warn("Loading about information failed", ex);
    }
    textArea.setEditable(false);
    textArea.setCaretPosition(0);
    scrollPane.setViewportView(textArea);

    JLabel lblTranslatedBy = new JLabel(Lang.get("author"));
    pan.add(lblTranslatedBy, "cell 0 1");

    setSize((int) (Icons.getScale() * 450), (int) (Icons.getScale() * 400));
    setLocationRelativeTo(parent);
}