use of org.jabref.gui.PreviewPanel in project jabref by JabRef.
the class SearchResultFrame method init.
private void init(String title) {
searchResultFrame = new JFrame();
searchResultFrame.setTitle(title);
searchResultFrame.setIconImages(IconTheme.getLogoSet());
preview = new PreviewPanel(null, null);
sortedEntries = new SortedList<>(entries, new EntryComparator(false, true, FieldName.AUTHOR));
model = (DefaultEventTableModel<BibEntry>) GlazedListsSwing.eventTableModelWithThreadProxyList(sortedEntries, new EntryTableFormat());
entryTable = new JTable(model);
GeneralRenderer renderer = new GeneralRenderer(Color.white);
entryTable.setDefaultRenderer(JLabel.class, renderer);
entryTable.setDefaultRenderer(String.class, renderer);
setWidths();
TableComparatorChooser<BibEntry> tableSorter = TableComparatorChooser.install(entryTable, sortedEntries, AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD);
setupComparatorChooser(tableSorter);
JScrollPane sp = new JScrollPane(entryTable);
final DefaultEventSelectionModel<BibEntry> selectionModel = (DefaultEventSelectionModel<BibEntry>) GlazedListsSwing.eventSelectionModelWithThreadProxyList(sortedEntries);
entryTable.setSelectionModel(selectionModel);
selectionModel.getSelected().addListEventListener(new EntrySelectionListener());
entryTable.addMouseListener(new TableClickListener());
contentPane.setTopComponent(sp);
contentPane.setBottomComponent(preview);
// Key bindings:
AbstractAction closeAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
};
ActionMap actionMap = contentPane.getActionMap();
InputMap inputMap = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DATABASE), "close");
actionMap.put("close", closeAction);
actionMap = entryTable.getActionMap();
inputMap = entryTable.getInputMap();
//Override 'selectNextColumnCell' and 'selectPreviousColumnCell' to move rows instead of cells on TAB
actionMap.put("selectNextColumnCell", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectNextEntry();
}
});
actionMap.put("selectPreviousColumnCell", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectPreviousEntry();
}
});
actionMap.put("selectNextRow", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectNextEntry();
}
});
actionMap.put("selectPreviousRow", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectPreviousEntry();
}
});
String selectFirst = "selectFirst";
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_FIRST_ENTRY), selectFirst);
actionMap.put(selectFirst, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent event) {
selectFirstEntry();
}
});
String selectLast = "selectLast";
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_LAST_ENTRY), selectLast);
actionMap.put(selectLast, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent event) {
selectLastEntry();
}
});
actionMap.put("copy", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (!selectionModel.getSelected().isEmpty()) {
List<BibEntry> bes = selectionModel.getSelected();
TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes);
// ! look at ClipBoardManager
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trbe, frame.getCurrentBasePanel());
frame.output(Localization.lang("Copied") + ' ' + (bes.size() > 1 ? bes.size() + " " + Localization.lang("entries") : "1 " + Localization.lang("entry") + '.'));
}
}
});
// override standard enter-action; enter opens the selected entry
entryTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
actionMap.put("Enter", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent ae) {
BibEntry entry = sortedEntries.get(entryTable.getSelectedRow());
selectEntryInBasePanel(entry);
}
});
searchResultFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
contentPane.setDividerLocation(0.5f);
}
@Override
public void windowClosing(WindowEvent event) {
dispose();
}
});
searchResultFrame.getContentPane().add(contentPane, BorderLayout.CENTER);
// Remember and default to last size:
SearchPreferences searchPreferences = new SearchPreferences(Globals.prefs);
searchResultFrame.setSize(searchPreferences.getSeachDialogWidth(), searchPreferences.getSeachDialogHeight());
searchResultFrame.setLocation(searchPreferences.getSearchDialogPosX(), searchPreferences.getSearchDialogPosY());
searchResultFrame.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
new SearchPreferences(Globals.prefs).setSearchDialogWidth(searchResultFrame.getSize().width).setSearchDialogHeight(searchResultFrame.getSize().height);
}
@Override
public void componentMoved(ComponentEvent e) {
new SearchPreferences(Globals.prefs).setSearchDialogPosX(searchResultFrame.getLocation().x).setSearchDialogPosY(searchResultFrame.getLocation().y);
}
});
}
use of org.jabref.gui.PreviewPanel 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));
}
use of org.jabref.gui.PreviewPanel in project jabref by JabRef.
the class PreviewPrefsTab method setupLogic.
private void setupLogic() {
chosen.getSelectionModel().addListSelectionListener(event -> {
boolean selectionEmpty = ((ListSelectionModel) event.getSource()).isSelectionEmpty();
btnLeft.setEnabled(!selectionEmpty);
btnDown.setEnabled(!selectionEmpty);
btnUp.setEnabled(!selectionEmpty);
});
available.getSelectionModel().addListSelectionListener(e -> btnRight.setEnabled(!((ListSelectionModel) e.getSource()).isSelectionEmpty()));
btnRight.addActionListener(event -> {
for (Object object : available.getSelectedValuesList()) {
availableModel.removeElement(object);
chosenModel.addElement(object);
}
});
btnLeft.addActionListener(event -> {
for (Object object : chosen.getSelectedValuesList()) {
availableModel.addElement(object);
chosenModel.removeElement(object);
}
});
btnUp.addActionListener(event -> {
List<Integer> newSelectedIndices = new ArrayList<>();
for (int oldIndex : chosen.getSelectedIndices()) {
boolean alreadyTaken = newSelectedIndices.contains(oldIndex - 1);
int newIndex = (oldIndex > 0 && !alreadyTaken) ? oldIndex - 1 : oldIndex;
chosenModel.add(newIndex, chosenModel.remove(oldIndex));
newSelectedIndices.add(newIndex);
}
chosen.setSelectedIndices(ArrayUtils.toPrimitive(newSelectedIndices.toArray(new Integer[newSelectedIndices.size()])));
});
btnDown.addActionListener(event -> {
List<Integer> newSelectedIndices = new ArrayList<>();
int[] selectedIndices = chosen.getSelectedIndices();
for (int i = selectedIndices.length - 1; i >= 0; i--) {
int oldIndex = selectedIndices[i];
boolean alreadyTaken = newSelectedIndices.contains(oldIndex + 1);
int newIndex = (oldIndex < chosenModel.getSize() - 1 && !alreadyTaken) ? oldIndex + 1 : oldIndex;
chosenModel.add(newIndex, chosenModel.remove(oldIndex));
newSelectedIndices.add(newIndex);
}
chosen.setSelectedIndices(ArrayUtils.toPrimitive(newSelectedIndices.toArray(new Integer[newSelectedIndices.size()])));
});
btnDefault.addActionListener(event -> layout.setText(Globals.prefs.getPreviewPreferences().getPreviewStyleDefault().replace("__NEWLINE__", "\n")));
btnTest.addActionListener(event -> {
try {
PreviewPanel testPane = new PreviewPanel(null, TestEntry.getTestEntry(), null).setFixedLayout(layout.getText());
testPane.setPreferredSize(new Dimension(800, 350));
JOptionPane.showMessageDialog(PreviewPrefsTab.this, new JScrollPane(testPane), Localization.lang("Preview"), JOptionPane.PLAIN_MESSAGE);
} catch (StringIndexOutOfBoundsException exception) {
LOGGER.warn("Parsing error.", exception);
JOptionPane.showMessageDialog(null, Localization.lang("Parsing error") + ": " + Localization.lang("illegal backslash expression") + ".\n" + exception.getMessage(), Localization.lang("Parsing error"), JOptionPane.ERROR_MESSAGE);
}
});
}
use of org.jabref.gui.PreviewPanel in project jabref by JabRef.
the class StyleSelectDialog method init.
private void init() {
setupPopupMenu();
addButton.addActionListener(actionEvent -> {
AddFileDialog addDialog = new AddFileDialog();
addDialog.setDirectoryPath(preferences.getCurrentStyle());
addDialog.setVisible(true);
addDialog.getFileName().ifPresent(fileName -> {
if (loader.addStyleIfValid(fileName)) {
preferences.setCurrentStyle(fileName);
}
});
updateStyles();
});
addButton.setToolTipText(Localization.lang("Add style file"));
removeButton.addActionListener(removeAction);
removeButton.setToolTipText(Localization.lang("Remove style"));
// Create a preview panel for previewing styles
// Must be done before creating the table to avoid NPEs
preview = new PreviewPanel(null, null);
// Use the test entry from the Preview settings tab in Preferences:
preview.setEntry(prevEntry);
setupTable();
updateStyles();
// Build dialog
diag = new JDialog(frame, Localization.lang("Select style"), true);
FormBuilder builder = FormBuilder.create();
builder.layout(new FormLayout("fill:pref:grow, 4dlu, left:pref, 4dlu, left:pref", "pref, 4dlu, 100dlu:grow, 4dlu, pref, 4dlu, fill:100dlu"));
builder.add(Localization.lang("Select one of the available styles or add a style file from disk.")).xyw(1, 1, 5);
builder.add(new JScrollPane(table)).xyw(1, 3, 5);
builder.add(addButton).xy(3, 5);
builder.add(removeButton).xy(5, 5);
builder.add(preview).xyw(1, 7, 5);
builder.padding("5dlu, 5dlu, 5dlu, 5dlu");
diag.add(builder.getPanel(), BorderLayout.CENTER);
AbstractAction okListener = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent event) {
if ((table.getRowCount() == 0) || (table.getSelectedRowCount() == 0)) {
JOptionPane.showMessageDialog(diag, Localization.lang("You must select a valid style file."), Localization.lang("Style selection"), JOptionPane.ERROR_MESSAGE);
return;
}
okPressed = true;
storeSettings();
diag.dispose();
}
};
ok.addActionListener(okListener);
Action cancelListener = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent event) {
diag.dispose();
}
};
cancel.addActionListener(cancelListener);
ButtonBarBuilder bb = new ButtonBarBuilder();
bb.addGlue();
bb.addButton(ok);
bb.addButton(cancel);
bb.addGlue();
bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
diag.add(bb.getPanel(), BorderLayout.SOUTH);
ActionMap am = bb.getPanel().getActionMap();
InputMap im = bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
am.put("close", cancelListener);
im.put(KeyStroke.getKeyStroke("ENTER"), "enterOk");
am.put("enterOk", okListener);
diag.pack();
WindowLocation pw = new WindowLocation(diag, JabRefPreferences.STYLES_POS_X, JabRefPreferences.STYLES_POS_Y, JabRefPreferences.STYLES_SIZE_X, JabRefPreferences.STYLES_SIZE_Y);
pw.displayWindowAtStoredLocation();
}
Aggregations