Search in sources :

Example 56 with JTextArea

use of javax.swing.JTextArea in project jgnash by ccavanaugh.

the class RecurringEntryDialog method createTransactionPanel.

private JPanel createTransactionPanel() {
    FormLayout layout = new FormLayout("left:p, 4dlu, p:g, 4dlu, p", "f:p, 3dlu, f:p, 3dlu, f:p, 3dlu, f:40dlu:g");
    layout.setRowGroups(new int[][] { { 1, 3, 5 } });
    CellConstraints cc = new CellConstraints();
    JPanel p = new JPanel(layout);
    descriptionField = new JTextFieldEx();
    accountCombo = new AccountListComboBox();
    notesArea = new JTextArea(5, 20);
    notesArea.setLineWrap(true);
    notesArea.setAutoscrolls(true);
    JScrollPane pane = new JScrollPane(notesArea);
    pane.setAutoscrolls(true);
    transactionField = new JTextFieldEx();
    transactionField.setEditable(false);
    editButton = new JButton(rb.getString("Button.Edit"));
    deleteButton = new JButton(rb.getString("Button.Delete"));
    p.add(new JLabel(rb.getString("Label.Account")), cc.xy(1, 1));
    p.add(accountCombo, cc.xywh(3, 1, 3, 1));
    p.add(new JLabel(rb.getString("Label.Description")), cc.xy(1, 3));
    p.add(descriptionField, cc.xywh(3, 3, 3, 1));
    p.add(new JLabel(rb.getString("Label.Transaction")), cc.xy(1, 5));
    p.add(transactionField, cc.xy(3, 5));
    p.add(new ButtonBarBuilder().addButton(editButton, deleteButton).build(), cc.xy(5, 5));
    p.add(new JLabel(rb.getString("Label.Notes")), cc.xy(1, 7));
    p.add(pane, cc.xywh(3, 7, 3, 1));
    return p;
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JTextFieldEx(jgnash.ui.components.JTextFieldEx) AccountListComboBox(jgnash.ui.components.AccountListComboBox) CellConstraints(com.jgoodies.forms.layout.CellConstraints)

Example 57 with JTextArea

use of javax.swing.JTextArea in project jdk8u_jdk by JetBrains.

the class XSheet method handleNotification.

/**
     * Notification listener: handles asynchronous reception
     * of MBean operation results and MBean notifications.
     */
// Call on EDT
public void handleNotification(Notification e, Object handback) {
    // Operation result
    if (e.getType().equals(XOperations.OPERATION_INVOCATION_EVENT)) {
        final Object message;
        if (handback == null) {
            JTextArea textArea = new JTextArea("null");
            textArea.setEditable(false);
            textArea.setEnabled(true);
            textArea.setRows(textArea.getLineCount());
            message = textArea;
        } else {
            Component comp = mbeansTab.getDataViewer().createOperationViewer(handback, mbean);
            if (comp == null) {
                JTextArea textArea = new JTextArea(handback.toString());
                textArea.setEditable(false);
                textArea.setEnabled(true);
                textArea.setRows(textArea.getLineCount());
                JScrollPane scrollPane = new JScrollPane(textArea);
                Dimension d = scrollPane.getPreferredSize();
                if (d.getWidth() > 400 || d.getHeight() > 250) {
                    scrollPane.setPreferredSize(new Dimension(400, 250));
                }
                message = scrollPane;
            } else {
                if (!(comp instanceof JScrollPane)) {
                    comp = new JScrollPane(comp);
                }
                Dimension d = comp.getPreferredSize();
                if (d.getWidth() > 400 || d.getHeight() > 250) {
                    comp.setPreferredSize(new Dimension(400, 250));
                }
                message = comp;
            }
        }
        new ThreadDialog((Component) e.getSource(), message, Messages.OPERATION_RETURN_VALUE, JOptionPane.INFORMATION_MESSAGE).run();
    } else // Got notification
    if (e.getType().equals(XMBeanNotifications.NOTIFICATION_RECEIVED_EVENT)) {
        DefaultMutableTreeNode emitter = (DefaultMutableTreeNode) handback;
        Long received = (Long) e.getUserData();
        updateReceivedNotifications(emitter, received.longValue(), true);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Dimension(java.awt.Dimension) Component(java.awt.Component)

Example 58 with JTextArea

use of javax.swing.JTextArea in project jabref by JabRef.

the class FromAuxDialog method initPanels.

private void initPanels() {
    // collect the names of all open databases
    int len = parentTabbedPane.getTabCount();
    int toSelect = -1;
    for (int i = 0; i < len; i++) {
        dbChooser.addItem(parentTabbedPane.getTitleAt(i));
        if (parentFrame.getBasePanelAt(i) == parentFrame.getCurrentBasePanel()) {
            toSelect = i;
        }
    }
    if (toSelect >= 0) {
        dbChooser.setSelectedIndex(toSelect);
    }
    auxFileField = new JTextField("", 25);
    JButton browseAuxFileButton = new JButton(Localization.lang("Browse"));
    FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilter(FileExtensions.AUX).withDefaultExtension(FileExtensions.AUX).withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
    DialogService ds = new FXDialogService();
    browseAuxFileButton.addActionListener(e -> {
        Optional<Path> file = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration));
        file.ifPresent(f -> auxFileField.setText(f.toAbsolutePath().toString()));
    });
    notFoundList = new JList<>();
    JScrollPane listScrollPane = new JScrollPane(notFoundList);
    statusInfos = new JTextArea("", 5, 20);
    JScrollPane statusScrollPane = new JScrollPane(statusInfos);
    statusInfos.setEditable(false);
    DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, left:pref", ""), buttons);
    b.appendSeparator(Localization.lang("Options"));
    b.append(Localization.lang("Reference library") + ":");
    b.append(dbChooser, 3);
    b.nextLine();
    b.append(Localization.lang("LaTeX AUX file") + ":");
    b.append(auxFileField);
    b.append(browseAuxFileButton);
    b.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    b = new DefaultFormBuilder(new FormLayout("fill:pref:grow, 4dlu, fill:pref:grow", "pref, pref, fill:pref:grow"), statusPanel);
    b.appendSeparator(Localization.lang("Result"));
    b.append(Localization.lang("Unknown BibTeX entries") + ":");
    b.append(Localization.lang("Messages") + ":");
    b.nextLine();
    b.append(listScrollPane);
    b.append(statusScrollPane);
    b.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}
Also used : Path(java.nio.file.Path) JScrollPane(javax.swing.JScrollPane) FormLayout(com.jgoodies.forms.layout.FormLayout) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) JTextArea(javax.swing.JTextArea) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) JTextField(javax.swing.JTextField) FXDialogService(org.jabref.gui.FXDialogService) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder)

Example 59 with JTextArea

use of javax.swing.JTextArea in project jabref by JabRef.

the class SaveDatabaseAction method saveDatabase.

private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) throws SaveException {
    SaveSession session;
    // block user input
    frame.block();
    try {
        SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withEncoding(encoding);
        BibtexDatabaseWriter<SaveSession> databaseWriter = new BibtexDatabaseWriter<>(FileSaveSession::new);
        if (selectedOnly) {
            session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), panel.getSelectedEntries(), prefs);
        } else {
            session = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs);
        }
        panel.registerUndoableChanges(session);
    } catch (UnsupportedCharsetException ex) {
        JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + Localization.lang("Character encoding '%0' is not supported.", encoding.displayName()), Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE);
        // FIXME: rethrow anti-pattern
        throw new SaveException("rt");
    } catch (SaveException ex) {
        if (ex == SaveException.FILE_LOCKED) {
            throw ex;
        }
        if (ex.specificEntry()) {
            BibEntry entry = ex.getEntry();
            // Error occured during processing of an entry. Highlight it!
            panel.highlightEntry(entry);
        } else {
            LOGGER.error("A problem occured when trying to save the file", ex);
        }
        JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + ".\n" + ex.getMessage(), Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE);
        // FIXME: rethrow anti-pattern
        throw new SaveException("rt");
    } finally {
        // re-enable user input
        frame.unblock();
    }
    // handle encoding problems
    boolean success = true;
    if (!session.getWriter().couldEncodeAll()) {
        FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref"));
        JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters());
        ta.setEditable(false);
        builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:", session.getEncoding().displayName())).xy(1, 1);
        builder.add(ta).xy(3, 1);
        builder.add(Localization.lang("What do you want to do?")).xy(1, 3);
        String tryDiff = Localization.lang("Try different encoding");
        int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Localization.lang("Save library"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[] { Localization.lang("Save"), tryDiff, Localization.lang("Cancel") }, tryDiff);
        if (answer == JOptionPane.NO_OPTION) {
            // The user wants to use another encoding.
            Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"), Localization.lang("Save library"), JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, encoding);
            if (choice == null) {
                success = false;
            } else {
                Charset newEncoding = Charset.forName((String) choice);
                return saveDatabase(file, selectedOnly, newEncoding);
            }
        } else if (answer == JOptionPane.CANCEL_OPTION) {
            success = false;
        }
    }
    // backup file?
    try {
        if (success) {
            session.commit(file.toPath());
            // Make sure to remember which encoding we used.
            panel.getBibDatabaseContext().getMetaData().setEncoding(encoding, ChangePropagation.DO_NOT_POST_EVENT);
        } else {
            session.cancel();
        }
    } catch (SaveException e) {
        int ans = JOptionPane.showConfirmDialog(null, Localization.lang("Save failed during backup creation") + ". " + Localization.lang("Save without backup?"), Localization.lang("Unable to create backup"), JOptionPane.YES_NO_OPTION);
        if (ans == JOptionPane.YES_OPTION) {
            session.setUseBackup(false);
            session.commit(file.toPath());
            panel.getBibDatabaseContext().getMetaData().setEncoding(encoding, ChangePropagation.DO_NOT_POST_EVENT);
        } else {
            success = false;
        }
    }
    return success;
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) BibEntry(org.jabref.model.entry.BibEntry) FormBuilder(com.jgoodies.forms.builder.FormBuilder) SaveException(org.jabref.logic.exporter.SaveException) JTextArea(javax.swing.JTextArea) BibtexDatabaseWriter(org.jabref.logic.exporter.BibtexDatabaseWriter) FileSaveSession(org.jabref.logic.exporter.FileSaveSession) Charset(java.nio.charset.Charset) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) SavePreferences(org.jabref.logic.exporter.SavePreferences) SaveSession(org.jabref.logic.exporter.SaveSession) FileSaveSession(org.jabref.logic.exporter.FileSaveSession)

Example 60 with JTextArea

use of javax.swing.JTextArea in project jabref by JabRef.

the class FieldFormatterCleanupsPanel method makeDescriptionTextAreaLikeJLabel.

/**
     * Create a TextArea that looks and behaves like a JLabel. Has the advantage of supporting multine and wordwrap
     */
private void makeDescriptionTextAreaLikeJLabel() {
    descriptionAreaText = new JTextArea(DESCRIPTION);
    descriptionAreaText.setLineWrap(true);
    descriptionAreaText.setWrapStyleWord(true);
    descriptionAreaText.setColumns(6);
    descriptionAreaText.setEditable(false);
    descriptionAreaText.setOpaque(false);
    descriptionAreaText.setFocusable(false);
    descriptionAreaText.setCursor(null);
    descriptionAreaText.setFont(UIManager.getFont("Label.font"));
}
Also used : JTextArea(javax.swing.JTextArea)

Aggregations

JTextArea (javax.swing.JTextArea)182 JScrollPane (javax.swing.JScrollPane)104 JPanel (javax.swing.JPanel)79 BorderLayout (java.awt.BorderLayout)60 JButton (javax.swing.JButton)59 JLabel (javax.swing.JLabel)59 Dimension (java.awt.Dimension)36 JTextField (javax.swing.JTextField)35 JFrame (javax.swing.JFrame)33 ActionEvent (java.awt.event.ActionEvent)26 Font (java.awt.Font)24 GridBagLayout (java.awt.GridBagLayout)23 GridBagConstraints (java.awt.GridBagConstraints)22 Insets (java.awt.Insets)22 ActionListener (java.awt.event.ActionListener)21 FlowLayout (java.awt.FlowLayout)20 Color (java.awt.Color)18 JCheckBox (javax.swing.JCheckBox)18 JSplitPane (javax.swing.JSplitPane)16 EmptyBorder (javax.swing.border.EmptyBorder)16