Search in sources :

Example 61 with JTextArea

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

the class DroppedFileHandler method tryXmpImport.

// Done by MrDlib
private boolean tryXmpImport(String fileName, ExternalFileType fileType, NamedCompound edits) {
    if (!"pdf".equals(fileType.getExtension())) {
        return false;
    }
    List<BibEntry> xmpEntriesInFile;
    try {
        xmpEntriesInFile = XMPUtil.readXMP(fileName, Globals.prefs.getXMPPreferences());
    } catch (IOException e) {
        LOGGER.warn("Problem reading XMP", e);
        return false;
    }
    if ((xmpEntriesInFile == null) || xmpEntriesInFile.isEmpty()) {
        return false;
    }
    JLabel confirmationMessage = new JLabel(Localization.lang("The PDF contains one or several BibTeX-records.") + "\n" + Localization.lang("Do you want to import these as new entries into the current library?"));
    JPanel entriesPanel = new JPanel();
    entriesPanel.setLayout(new BoxLayout(entriesPanel, BoxLayout.Y_AXIS));
    xmpEntriesInFile.forEach(entry -> {
        JTextArea entryArea = new JTextArea(entry.toString());
        entryArea.setEditable(false);
        entriesPanel.add(entryArea);
    });
    JPanel contentPanel = new JPanel(new BorderLayout());
    contentPanel.add(confirmationMessage, BorderLayout.NORTH);
    contentPanel.add(entriesPanel, BorderLayout.CENTER);
    int reply = JOptionPane.showConfirmDialog(frame, contentPanel, Localization.lang("XMP-metadata found in PDF: %0", fileName), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (reply == JOptionPane.CANCEL_OPTION) {
        // The user canceled thus that we are done.
        return true;
    }
    if (reply == JOptionPane.NO_OPTION) {
        return false;
    }
    // reply == JOptionPane.YES_OPTION)
    /*
         * TODO Extract Import functionality from ImportMenuItem then we could
         * do:
         *
         * ImportMenuItem importer = new ImportMenuItem(frame, (mainTable ==
         * null), new PdfXmpImporter());
         *
         * importer.automatedImport(new String[] { fileName });
         */
    boolean isSingle = xmpEntriesInFile.size() == 1;
    BibEntry single = isSingle ? xmpEntriesInFile.get(0) : null;
    boolean success = true;
    String destFilename;
    if (linkInPlace.isSelected()) {
        destFilename = FileUtil.shortenFileName(Paths.get(fileName), panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences())).toString();
    } else {
        if (renameCheckBox.isSelected() || (single == null)) {
            destFilename = fileName;
        } else {
            destFilename = single.getCiteKey() + "." + fileType.getExtension();
        }
        if (copyRadioButton.isSelected()) {
            success = doCopy(fileName, destFilename, edits);
        } else if (moveRadioButton.isSelected()) {
            success = doMove(fileName, destFilename, edits);
        }
    }
    if (success) {
        for (BibEntry aXmpEntriesInFile : xmpEntriesInFile) {
            aXmpEntriesInFile.setId(IdGenerator.next());
            edits.addEdit(new UndoableInsertEntry(panel.getDatabase(), aXmpEntriesInFile, panel));
            panel.getDatabase().insertEntry(aXmpEntriesInFile);
            doLink(aXmpEntriesInFile, fileType, destFilename, true, edits);
        }
        panel.markBaseChanged();
        panel.updateEntryEditorIfShowing();
    }
    return true;
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) BorderLayout(java.awt.BorderLayout) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) IOException(java.io.IOException) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry)

Example 62 with JTextArea

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

the class MergeEntries method initialize.

/**
     * Main function for building the merge entry JPanel
     */
private void initialize() {
    doneBuilding = false;
    setupFields();
    fillDiffModes();
    // Create main layout
    String colSpecMain = "left:pref, 5px, center:3cm:grow, 5px, center:pref, 3px, center:pref, 3px, center:pref, 5px, center:3cm:grow";
    String colSpecMerge = "left:pref, 5px, fill:3cm:grow, 5px, center:pref, 3px, center:pref, 3px, center:pref, 5px, fill:3cm:grow";
    String rowSpec = "pref, pref, 10px, fill:5cm:grow, 10px, pref, 10px, fill:3cm:grow";
    StringBuilder rowBuilder = new StringBuilder("");
    for (int i = 0; i < allFields.size(); i++) {
        rowBuilder.append("pref, 2dlu, ");
    }
    rowBuilder.append("pref");
    JPanel mergePanel = new JPanel();
    FormLayout mainLayout = new FormLayout(colSpecMain, rowSpec);
    FormLayout mergeLayout = new FormLayout(colSpecMerge, rowBuilder.toString());
    mainPanel.setLayout(mainLayout);
    mergePanel.setLayout(mergeLayout);
    setupHeadingRows();
    mainPanel.add(new JSeparator(), CELL_CONSTRAINTS.xyw(1, 3, 11));
    setupEntryTypeRow(mergePanel);
    int maxLabelWidth = setupFieldRows(mergePanel);
    // Create and add scrollpane
    scrollPane = new JScrollPane(mergePanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    updateTextPanes(allFields);
    mainPanel.add(scrollPane, CELL_CONSTRAINTS.xyw(1, 4, 11));
    mainPanel.add(new JSeparator(), CELL_CONSTRAINTS.xyw(1, 5, 11));
    synchronizeColumnWidths(mainLayout, mergeLayout, maxLabelWidth);
    // Setup a PreviewPanel and a Bibtex source box for the merged entry
    mainPanel.add(boldFontLabel(Localization.lang("Merged entry")), CELL_CONSTRAINTS.xyw(1, 6, 6));
    entryPreview = new PreviewPanel(null, mergedEntry, null);
    mainPanel.add(entryPreview, CELL_CONSTRAINTS.xyw(1, 8, 6));
    mainPanel.add(boldFontLabel(Localization.lang("Merged BibTeX source code")), CELL_CONSTRAINTS.xyw(8, 6, 4));
    sourceView = new JTextArea();
    sourceView.setLineWrap(true);
    sourceView.setFont(new Font("Monospaced", Font.PLAIN, Globals.prefs.getInt(JabRefPreferences.FONT_SIZE)));
    mainPanel.add(new JScrollPane(sourceView), CELL_CONSTRAINTS.xyw(8, 8, 4));
    sourceView.setEditable(false);
    // Add some margin around the layout
    mainLayout.appendRow(RowSpec.decode(MARGIN));
    mainLayout.appendColumn(ColumnSpec.decode(MARGIN));
    mainLayout.insertRow(1, RowSpec.decode(MARGIN));
    mainLayout.insertColumn(1, ColumnSpec.decode(MARGIN));
    // Everything done, allow any action to actually update the merged entry
    doneBuilding = true;
    updateAll();
    // Show what we've got
    mainPanel.setVisible(true);
    SwingUtilities.invokeLater(() -> scrollPane.getVerticalScrollBar().setValue(0));
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) PreviewPanel(org.jabref.gui.PreviewPanel) JSeparator(javax.swing.JSeparator) Font(java.awt.Font)

Example 63 with JTextArea

use of javax.swing.JTextArea in project JMRI by JMRI.

the class Maintenance method deviceReportPressed.

/**
     * Find references of a System or User name in the various Manager Objects.
     *
     * @param devName name to look for
     * @param parent Frame calling this method
     */
public static void deviceReportPressed(String devName, Frame parent) {
    JTextArea text = null;
    JScrollPane scrollPane = null;
    text = new javax.swing.JTextArea(25, 50);
    text.setEditable(false);
    text.setTabSize(4);
    search(devName, text);
    scrollPane = new JScrollPane(text);
    makeDialog(scrollPane, null, parent, rbm.getString("CrossReferenceTitle"));
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) JTextArea(javax.swing.JTextArea)

Example 64 with JTextArea

use of javax.swing.JTextArea in project JMRI by JMRI.

the class SwitchboardEditor method setupToolBar.

private void setupToolBar() {
    //Initial setup for both horizontal and vertical
    Container contentPane = getContentPane();
    //remove these (if present) so we can add them back (without duplicates)
    if (editToolBarContainer != null) {
        editToolBarContainer.setVisible(false);
        contentPane.remove(editToolBarContainer);
    }
    //        if (helpBarPanel != null) {
    //            contentPane.remove(helpBarPanel);
    //        }
    editToolBarPanel = new JPanel();
    editToolBarPanel.setLayout(new BoxLayout(editToolBarPanel, BoxLayout.PAGE_AXIS));
    JPanel innerBorderPanel = new JPanel();
    innerBorderPanel.setLayout(new BoxLayout(innerBorderPanel, BoxLayout.PAGE_AXIS));
    TitledBorder TitleBorder = BorderFactory.createTitledBorder(Bundle.getMessage("SwitchboardHelpTitle"));
    innerBorderPanel.setBorder(TitleBorder);
    innerBorderPanel.add(new JTextArea(Bundle.getMessage("Help1")));
    if (!hideUnconnected()) {
        innerBorderPanel.add(new JTextArea(Bundle.getMessage("Help2")));
    // TODO hide this panel when hideUnconnected() is set to false from menu or checkbox
    }
    contentPane.add(innerBorderPanel);
    //Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
    editToolBarScroll = new JScrollPane(editToolBarPanel);
    //editToolBarScroll.getPreferredSize().height;
    height = 60;
    editToolBarContainer = new JPanel();
    editToolBarContainer.setLayout(new BoxLayout(editToolBarContainer, BoxLayout.PAGE_AXIS));
    editToolBarContainer.add(editToolBarScroll);
    editToolBarContainer.setMinimumSize(new Dimension(width, height));
    editToolBarContainer.setPreferredSize(new Dimension(width, height));
//        helpBarPanel = new JPanel();
//        helpBarPanel.add(helpBar);
//        for (Component c : helpBar.getComponents()) {
//            if (c instanceof JTextArea) {
//                JTextArea j = (JTextArea) c;
//                //j.setSize(new Dimension(width, j.getSize().height));
//                j.setLineWrap(true);
//                j.setWrapStyleWord(true);
//            }
//        }
//        contentPane.setLayout(new BoxLayout(contentPane, false ? BoxLayout.LINE_AXIS : BoxLayout.PAGE_AXIS));
//        contentPane.add(editToolBarContainer);
//        contentPane.add(helpBarPanel);
//helpBarPanel.setVisible(isEditable() && showHelpBar);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) Container(java.awt.Container) JTextArea(javax.swing.JTextArea) BoxLayout(javax.swing.BoxLayout) Dimension(java.awt.Dimension) TitledBorder(javax.swing.border.TitledBorder)

Example 65 with JTextArea

use of javax.swing.JTextArea in project JMRI by JMRI.

the class CheckForUpdateAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent ev) {
    final JFrame frame = new JmriJFrame(Bundle.getMessage("TitleUpdate"), false, false);
    frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
    JTextArea text = new JTextArea();
    text.setEditable(false);
    frame.add(text);
    String productionrelease = "";
    String testrelease = "";
    InputStream in = null;
    try {
        String urlname = "http://jmri.org/releaselist";
        URL url = new URL(urlname);
        in = url.openConnection().getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        // search for releases
        String line;
        while ((line = reader.readLine()) != null) {
            if (line.startsWith("production")) {
                productionrelease = getNumber(reader);
            }
            if (line.startsWith("test")) {
                testrelease = getNumber(reader);
            }
        }
    } catch (java.net.MalformedURLException e) {
        log.error("Unexpected failure in URL parsing", e);
        return;
    } catch (FileNotFoundException e) {
        log.debug("Unable to get version info from web" + e);
    } catch (IOException e) {
        log.debug("Unexpected failure during reading" + e);
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException e1) {
            log.error("Exception closing input stream", e1);
        }
    }
    // add content here!
    text.append("Most recent production release: " + productionrelease + "\n");
    text.append("Most recent test release: " + testrelease + "\n");
    // cleaner form is getCanonicalVersion()
    text.append("You have: " + jmri.Version.name() + "\n");
    JPanel p = new JPanel();
    p.setLayout(new FlowLayout());
    JButton go = new JButton(Bundle.getMessage("ButtonDownloadPage"));
    go.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            try {
                Desktop.getDesktop().browse(new URI("http://jmri.org/download"));
            } catch (java.net.URISyntaxException e) {
                log.error("Invalid page requested", e);
            } catch (java.io.IOException e) {
                log.error("Could no load page", e);
            }
        }
    });
    p.add(go);
    JButton close = new JButton(Bundle.getMessage("ButtonClose"));
    close.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            frame.setVisible(false);
            frame.dispose();
        }
    });
    p.add(close);
    frame.add(p);
    frame.pack();
    // show
    frame.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) FlowLayout(java.awt.FlowLayout) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) FileNotFoundException(java.io.FileNotFoundException) JButton(javax.swing.JButton) IOException(java.io.IOException) URI(java.net.URI) URL(java.net.URL) ActionListener(java.awt.event.ActionListener) JmriJFrame(jmri.util.JmriJFrame) JFrame(javax.swing.JFrame) JmriJFrame(jmri.util.JmriJFrame) BufferedReader(java.io.BufferedReader)

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