コード例 #1
0
 /** Creates a new instance of SaveAllAction */
 public SaveAllAction(JabRefFrame frame) {
   super(IconTheme.getImage("saveAll"));
   this.frame = frame;
   putValue(Action.ACCELERATOR_KEY, Globals.prefs.getKey("Save all"));
   putValue(Action.SHORT_DESCRIPTION, Localization.lang("Save all open databases"));
   putValue(Action.NAME, Localization.menuTitle("Save all"));
 }
コード例 #2
0
  private void storeSettings(ExternalFileType entry) {
    entry.setName(name.getText().trim());
    entry.setMimeType(mimeType.getText().trim());
    // Set extension, but remove initial dot if user has added that:
    String ext = extension.getText().trim();
    if (!ext.isEmpty() && ext.charAt(0) == '.') {
      entry.setExtension(ext.substring(1));
    } else {
      entry.setExtension(ext);
    }

    if (selectedIcon != null) {
      entry.setIconName(selectedIcon);
      entry.setIcon(IconTheme.getImage(entry.getIconName()));
    }
    if (!OS.WINDOWS) {
      entry.setOpenWith(application.getText().trim());
    } else {
      // On Windows, store application as empty if the "Default" option is selected,
      // or if the application name is empty:
      if (useDefault.isSelected() || application.getText().trim().isEmpty()) {
        entry.setOpenWith("");
      } else {
        entry.setOpenWith(application.getText().trim());
      }
    }
  }
コード例 #3
0
ファイル: PushToLyx.java プロジェクト: GHenry10/jabref
 @Override
 public Icon getIcon() {
   return IconTheme.getImage("lyx");
 }
コード例 #4
0
/** This class produces a dialog box for editing an external file type. */
public class ExternalFileTypeEntryEditor {

  private JFrame fParent;
  private JDialog dParent;
  private JDialog diag;
  private final JTextField extension = new JTextField();
  private final JTextField name = new JTextField();
  private final JTextField mimeType = new JTextField();
  private final JTextField application = new JTextField();
  private String selectedIcon;
  private final JButton icon = new JButton(IconTheme.getImage("picture"));
  private final JButton ok = new JButton(Localization.lang("Ok"));
  private final JButton cancel = new JButton(Localization.lang("Cancel"));
  private final JRadioButton useDefault = new JRadioButton(Localization.lang("Default"));
  private final JRadioButton other = new JRadioButton("");
  final String emptyMessage = "<" + Localization.lang("Use default viewer") + ">";
  private final String editFileTitle = Localization.lang("Edit file type");
  private final String newFileTitle = Localization.lang("Add new file type");
  boolean applicationFieldEmpty;

  private ExternalFileType entry;
  private boolean okPressed;

  public ExternalFileTypeEntryEditor(JFrame parent, ExternalFileType entry) {
    fParent = parent;
    init(entry);
  }

  public ExternalFileTypeEntryEditor(JDialog parent, ExternalFileType entry) {
    dParent = parent;
    init(entry);
  }

  private void init(ExternalFileType entry) {
    this.entry = entry;
    icon.setText(null);

    ButtonGroup bg = new ButtonGroup();
    bg.add(useDefault);
    bg.add(other);

    FormBuilder builder = FormBuilder.create();
    builder.layout(
        new FormLayout(
            "left:pref, 4dlu, fill:150dlu, 4dlu, fill:pref",
            "p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p"));
    builder.add(Localization.lang("Icon")).xy(1, 1);
    builder.add(icon).xy(3, 1);
    builder.add(Localization.lang("Name")).xy(1, 3);
    builder.add(name).xy(3, 3);
    builder.add(Localization.lang("Extension")).xy(1, 5);
    builder.add(extension).xy(3, 5);
    builder.add(Localization.lang("MIME type")).xy(1, 7);
    builder.add(mimeType).xy(3, 7);
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    builder.add(Localization.lang("Application")).xy(1, 9);
    JButton browseBut = new JButton(Localization.lang("Browse"));
    if (OS.WINDOWS) {
      builder.add(useDefault).xy(3, 9);
      builder.appendRows("2dlu, p");
      JPanel p1 = new JPanel();
      builder.add(p1).xy(1, 11);
      JPanel p2 = new JPanel();
      application.setPreferredSize(new Dimension(300, application.getPreferredSize().height));
      BorderLayout bl = new BorderLayout();
      bl.setHgap(4);
      p2.setLayout(bl);
      p2.add(other, BorderLayout.WEST);
      p2.add(application, BorderLayout.CENTER);
      builder.add(p2).xy(3, 11);
      builder.add(browseBut).xy(5, 11);
    } else {
      builder.add(application).xy(3, 9);
      builder.add(browseBut).xy(5, 9);
    }
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();

    ok.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            okPressed = true;
            storeSettings(ExternalFileTypeEntryEditor.this.entry);
            diag.dispose();
          }
        });
    cancel.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            diag.dispose();
          }
        });

    icon.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            String initSel = ExternalFileTypeEntryEditor.this.entry.getIconName();
            if (selectedIcon != null) {
              initSel = selectedIcon;
            }
            IconSelection ic = new IconSelection(diag, initSel);
            ic.setVisible(true);
            if (ic.isOkPressed()) {
              selectedIcon = ic.getSelectedIconKey();
              icon.setIcon(IconTheme.getImage(selectedIcon));
            }
            // JOptionPane.showMessageDialog(null, "Sorry, the icon can unfortunately not be changed
            // in this version of JabRef");
          }
        });

    if (OS.WINDOWS) {
      application
          .getDocument()
          .addDocumentListener(
              new DocumentListener() {

                private void handle(DocumentEvent e) {
                  if (application.getText().isEmpty()) {
                    useDefault.setSelected(true);
                  } else {
                    other.setSelected(true);
                  }
                }

                @Override
                public void insertUpdate(DocumentEvent e) {
                  handle(e);
                }

                @Override
                public void removeUpdate(DocumentEvent documentEvent) {
                  handle(documentEvent);
                }

                @Override
                public void changedUpdate(DocumentEvent documentEvent) {
                  handle(documentEvent);
                }
              });
    }

    String title = editFileTitle;

    if (entry.getName().isEmpty()) {
      title = newFileTitle;
    }

    if (dParent != null) {
      diag = new JDialog(dParent, title, true);
    } else {
      diag = new JDialog(fParent, title, true);
    }
    diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    diag.pack();

    BrowseListener browse = new BrowseListener(diag, application);
    browseBut.addActionListener(browse);

    if (dParent != null) {
      diag.setLocationRelativeTo(dParent);
    } else {
      diag.setLocationRelativeTo(fParent);
      // Util.placeDialog(diag, parent);
    }

    setValues(entry);
  }

  public void setEntry(ExternalFileType entry) {
    this.entry = entry;
    if (entry.getName().isEmpty()) {
      diag.setTitle(newFileTitle);
    } else {
      diag.setTitle(editFileTitle);
    }
    setValues(entry);
  }

  public void setVisible(boolean visible) {
    if (visible) {
      okPressed = false;
    }
    diag.setVisible(visible);
  }

  private void setValues(ExternalFileType entry) {
    name.setText(entry.getName());
    extension.setText(entry.getExtension());
    mimeType.setText(entry.getMimeType());
    application.setText(entry.getOpenWith());
    icon.setIcon(entry.getIcon());
    if (application.getText().isEmpty()) {
      useDefault.setSelected(true);
    } else {
      other.setSelected(true);
    }
    selectedIcon = null;
  }

  private void storeSettings(ExternalFileType entry) {
    entry.setName(name.getText().trim());
    entry.setMimeType(mimeType.getText().trim());
    // Set extension, but remove initial dot if user has added that:
    String ext = extension.getText().trim();
    if (!ext.isEmpty() && ext.charAt(0) == '.') {
      entry.setExtension(ext.substring(1));
    } else {
      entry.setExtension(ext);
    }

    if (selectedIcon != null) {
      entry.setIconName(selectedIcon);
      entry.setIcon(IconTheme.getImage(entry.getIconName()));
    }
    if (!OS.WINDOWS) {
      entry.setOpenWith(application.getText().trim());
    } else {
      // On Windows, store application as empty if the "Default" option is selected,
      // or if the application name is empty:
      if (useDefault.isSelected() || application.getText().trim().isEmpty()) {
        entry.setOpenWith("");
      } else {
        entry.setOpenWith(application.getText().trim());
      }
    }
  }

  public boolean okPressed() {
    return okPressed;
  }

  class BrowseListener implements ActionListener {

    private final JTextField comp;

    public BrowseListener(JDialog parent, JTextField comp) {
      this.comp = comp;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
      File initial = new File(comp.getText().trim());
      if (comp.getText().trim().isEmpty()) {
        // Nothing in the field. Go to the last file dir used:
        initial = new File(Globals.prefs.get(JabRefPreferences.FILE_WORKING_DIRECTORY));
      }
      String chosen =
          FileDialogs.getNewFile(
              /*parent*/ null, initial, Globals.NONE, JFileChooser.OPEN_DIALOG, false);
      if (chosen != null) {
        File newFile = new File(chosen);
        // Store the directory for next time:
        Globals.prefs.put(JabRefPreferences.FILE_WORKING_DIRECTORY, newFile.getParent());
        comp.setText(newFile.getPath());
        comp.requestFocus();
      }
    }
  }
}