use of org.jabref.gui.JabRefFrame in project jabref by JabRef.
the class JabRefGUI method openWindow.
private void openWindow() {
// This property is set to make the Mac OSX Java VM move the menu bar to the top of the screen
if (OS.OS_X) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
}
// Set antialiasing on everywhere. This only works in JRE >= 1.5.
// Or... it doesn't work, period.
// TODO test and maybe remove this! I found this commented out with no additional info ( payload@lavabit.com )
// Enabled since JabRef 2.11 beta 4
System.setProperty("swing.aatext", "true");
// Default is "on".
// "lcd" instead of "on" because of http://wiki.netbeans.org/FaqFontRendering and http://docs.oracle.com/javase/6/docs/technotes/guides/2d/flags.html#aaFonts
System.setProperty("awt.useSystemAAFontSettings", "lcd");
// look and feel. This MUST be the first thing to do before loading any Swing-specific code!
setLookAndFeel();
// If the option is enabled, open the last edited libraries, if any.
if (!isBlank && Globals.prefs.getBoolean(JabRefPreferences.OPEN_LAST_EDITED)) {
openLastEditedDatabases();
}
GUIGlobals.init();
LOGGER.debug("Initializing frame");
JabRefGUI.mainFrame = new JabRefFrame();
// Add all bibDatabases databases to the frame:
boolean first = false;
if (!bibDatabases.isEmpty()) {
for (Iterator<ParserResult> parserResultIterator = bibDatabases.iterator(); parserResultIterator.hasNext(); ) {
ParserResult pr = parserResultIterator.next();
// Define focused tab
if (pr.getFile().get().getAbsolutePath().equals(focusedFile)) {
first = true;
}
if (pr.isInvalid()) {
failed.add(pr);
parserResultIterator.remove();
} else if (pr.getDatabase().isShared()) {
try {
new SharedDatabaseUIManager(mainFrame).openSharedDatabaseFromParserResult(pr);
} catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException | NotASharedDatabaseException e) {
// do not open the original file
pr.getDatabaseContext().clearDatabaseFile();
pr.getDatabase().clearSharedDatabaseID();
LOGGER.error("Connection error", e);
JOptionPane.showMessageDialog(mainFrame, e.getMessage() + "\n\n" + Localization.lang("A local copy will be opened."), Localization.lang("Connection error"), JOptionPane.WARNING_MESSAGE);
}
toOpenTab.add(pr);
} else if (pr.toOpenTab()) {
// things to be appended to an opened tab should be done after opening all tabs
// add them to the list
toOpenTab.add(pr);
} else {
JabRefGUI.getMainFrame().addParserResult(pr, first);
first = false;
}
}
}
// finally add things to the currently opened tab
for (ParserResult pr : toOpenTab) {
JabRefGUI.getMainFrame().addParserResult(pr, first);
first = false;
}
// do it here:
if (Globals.prefs.getBoolean(JabRefPreferences.WINDOW_MAXIMISED)) {
JabRefGUI.getMainFrame().setExtendedState(Frame.MAXIMIZED_BOTH);
}
JabRefGUI.getMainFrame().setVisible(true);
for (ParserResult pr : failed) {
String message = "<html>" + Localization.lang("Error opening file '%0'.", pr.getFile().get().getName()) + "<p>" + pr.getErrorMessage() + "</html>";
JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(), message, Localization.lang("Error opening file"), JOptionPane.ERROR_MESSAGE);
}
// Display warnings, if any
int tabNumber = 0;
for (ParserResult pr : bibDatabases) {
ParserResultWarningDialog.showParserResultWarningDialog(pr, JabRefGUI.getMainFrame(), tabNumber++);
}
for (int i = 0; (i < bibDatabases.size()) && (i < JabRefGUI.getMainFrame().getBasePanelCount()); i++) {
ParserResult pr = bibDatabases.get(i);
BasePanel panel = JabRefGUI.getMainFrame().getBasePanelAt(i);
OpenDatabaseAction.performPostOpenActions(panel, pr);
}
LOGGER.debug("Finished adding panels");
if (!bibDatabases.isEmpty()) {
JabRefGUI.getMainFrame().getCurrentBasePanel().getMainTable().requestFocus();
}
}
use of org.jabref.gui.JabRefFrame in project jabref by JabRef.
the class SharedDatabaseUIManager method openNewSharedDatabaseTab.
/**
* Opens a new shared database tab with the given {@link DBMSConnectionProperties}.
*
* @param dbmsConnectionProperties Connection data
* @param raiseTab If <code>true</code> the new tab gets selected.
* @return BasePanel which also used by {@link SaveDatabaseAction}
*/
public BasePanel openNewSharedDatabaseTab(DBMSConnectionProperties dbmsConnectionProperties) throws SQLException, DatabaseNotSupportedException, InvalidDBMSConnectionPropertiesException {
JabRefFrame frame = JabRefGUI.getMainFrame();
BibDatabaseMode selectedMode = Globals.prefs.getDefaultBibDatabaseMode();
BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode), DatabaseLocation.SHARED, Globals.prefs.getKeywordDelimiter(), Globals.prefs.getKeyPattern());
dbmsSynchronizer = bibDatabaseContext.getDBMSSynchronizer();
dbmsSynchronizer.openSharedDatabase(dbmsConnectionProperties);
dbmsSynchronizer.registerListener(this);
frame.output(Localization.lang("Connection_to_%0_server_established.", dbmsConnectionProperties.getType().toString()));
return frame.addTab(bibDatabaseContext, true);
}
use of org.jabref.gui.JabRefFrame in project jabref by JabRef.
the class ExportAction method getExportAction.
/**
* Create an AbstractAction for performing an export operation.
*
* @param frame
* The JabRefFrame of this JabRef instance.
* @param selectedOnly
* true indicates that only selected entries should be exported,
* false indicates that all entries should be exported.
* @return The action.
*/
public static AbstractAction getExportAction(JabRefFrame frame, boolean selectedOnly) {
class InternalExportAction extends MnemonicAwareAction {
private final JabRefFrame frame;
private final boolean selectedOnly;
public InternalExportAction(JabRefFrame frame, boolean selectedOnly) {
this.frame = frame;
this.selectedOnly = selectedOnly;
putValue(Action.NAME, selectedOnly ? Localization.menuTitle("Export selected entries") : Localization.menuTitle("Export"));
}
@Override
public void actionPerformed(ActionEvent e) {
Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs, Globals.journalAbbreviationLoader);
LayoutFormatterPreferences layoutPreferences = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);
JFileChooser fc = ExportAction.createExportFileChooser(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY));
fc.showSaveDialog(frame);
File file = fc.getSelectedFile();
if (file == null) {
return;
}
FileFilter ff = fc.getFileFilter();
if (ff instanceof ExportFileFilter) {
ExportFileFilter eff = (ExportFileFilter) ff;
String path = file.getPath();
if (!path.endsWith(eff.getExtension())) {
path = path + eff.getExtension();
}
file = new File(path);
if (file.exists()) {
// Warn that the file exists:
if (JOptionPane.showConfirmDialog(frame, Localization.lang("'%0' exists. Overwrite file?", file.getName()), Localization.lang("Export"), JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION) {
return;
}
}
final IExportFormat format = eff.getExportFormat();
List<BibEntry> entries;
if (selectedOnly) {
// Selected entries
entries = frame.getCurrentBasePanel().getSelectedEntries();
} else {
// All entries
entries = frame.getCurrentBasePanel().getDatabase().getEntries();
}
// Set the global variable for this database's file directory before exporting,
// so formatters can resolve linked files correctly.
// (This is an ugly hack!)
Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectories(Globals.prefs.getFileDirectoryPreferences());
// Make sure we remember which filter was used, to set
// the default for next time:
Globals.prefs.put(JabRefPreferences.LAST_USED_EXPORT, format.getConsoleName());
Globals.prefs.put(JabRefPreferences.EXPORT_WORKING_DIRECTORY, file.getParent());
final File finFile = file;
final List<BibEntry> finEntries = entries;
AbstractWorker exportWorker = new AbstractWorker() {
String errorMessage;
@Override
public void run() {
try {
format.performExport(frame.getCurrentBasePanel().getBibDatabaseContext(), finFile.getPath(), frame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getEncoding().orElse(Globals.prefs.getDefaultEncoding()), finEntries);
} catch (Exception ex) {
LOGGER.warn("Problem exporting", ex);
if (ex.getMessage() == null) {
errorMessage = ex.toString();
} else {
errorMessage = ex.getMessage();
}
}
}
@Override
public void update() {
// No error message. Report success:
if (errorMessage == null) {
frame.output(Localization.lang("%0 export successful", format.getDisplayName()));
} else // ... or show an error dialog:
{
frame.output(Localization.lang("Could not save file.") + " - " + errorMessage);
// Need to warn the user that saving failed!
JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + "\n" + errorMessage, Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE);
}
}
};
// Run the export action in a background thread:
exportWorker.getWorker().run();
// Run the update method:
exportWorker.update();
}
}
}
return new InternalExportAction(frame, selectedOnly);
}
use of org.jabref.gui.JabRefFrame in project jabref by JabRef.
the class SharedDatabaseUIManager method openSharedDatabaseFromParserResult.
public void openSharedDatabaseFromParserResult(ParserResult parserResult) throws SQLException, DatabaseNotSupportedException, InvalidDBMSConnectionPropertiesException, NotASharedDatabaseException {
Optional<String> sharedDatabaseIDOptional = parserResult.getDatabase().getSharedDatabaseID();
if (!sharedDatabaseIDOptional.isPresent()) {
throw new NotASharedDatabaseException();
}
String sharedDatabaseID = sharedDatabaseIDOptional.get();
DBMSConnectionProperties dbmsConnectionProperties = new DBMSConnectionProperties(new SharedDatabasePreferences(sharedDatabaseID));
JabRefFrame frame = JabRefGUI.getMainFrame();
BibDatabaseMode selectedMode = Globals.prefs.getDefaultBibDatabaseMode();
BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode), DatabaseLocation.SHARED, Globals.prefs.getKeywordDelimiter(), Globals.prefs.getKeyPattern());
bibDatabaseContext.getDatabase().setSharedDatabaseID(sharedDatabaseID);
bibDatabaseContext.setDatabaseFile(parserResult.getDatabaseContext().getDatabaseFile().orElse(null));
dbmsSynchronizer = bibDatabaseContext.getDBMSSynchronizer();
dbmsSynchronizer.openSharedDatabase(dbmsConnectionProperties);
dbmsSynchronizer.registerListener(this);
parserResult.setDatabaseContext(bibDatabaseContext);
frame.output(Localization.lang("Connection_to_%0_server_established.", dbmsConnectionProperties.getType().toString()));
}
Aggregations