private void initGui() {
    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());

    biblatexMode = Globals.prefs.getBoolean("biblatexMode");

    JPanel main = new JPanel(), buttons = new JPanel(), right = new JPanel();
    main.setLayout(new BorderLayout());
    right.setLayout(new GridLayout(biblatexMode ? 2 : 1, 2));

    java.util.List<String> entryTypes = new ArrayList<String>();
    for (String s : BibtexEntryType.ALL_TYPES.keySet()) {
      entryTypes.add(s);
    }

    typeComp = new EntryTypeList(entryTypes);
    typeComp.addListSelectionListener(this);
    typeComp.addAdditionActionListener(this);
    typeComp.addDefaultActionListener(new DefaultListener());
    typeComp.setListSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    // typeComp.setEnabled(false);
    reqComp =
        new FieldSetComponent(
            Globals.lang("Required fields"), new ArrayList<String>(), preset, true, true);
    reqComp.setEnabled(false);
    reqComp.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    ListDataListener dataListener = new DataListener();
    reqComp.addListDataListener(dataListener);
    optComp =
        new FieldSetComponent(
            Globals.lang("Optional fields"), new ArrayList<String>(), preset, true, true);
    optComp.setEnabled(false);
    optComp.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    optComp.addListDataListener(dataListener);
    right.add(reqComp);
    right.add(optComp);

    if (biblatexMode) {
      optComp2 =
          new FieldSetComponent(
              Globals.lang("Optional fields") + " 2", new ArrayList<String>(), preset, true, true);
      optComp2.setEnabled(false);
      optComp2.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
      optComp2.addListDataListener(dataListener);
      right.add(new JPanel());
      right.add(optComp2);
    }

    // right.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
    // Globals.lang("Fields")));
    right.setBorder(BorderFactory.createEtchedBorder());
    ok = new JButton("Ok");
    cancel = new JButton(Globals.lang("Cancel"));
    apply = new JButton(Globals.lang("Apply"));
    ok.addActionListener(this);
    apply.addActionListener(this);
    cancel.addActionListener(this);
    ButtonBarBuilder bb = new ButtonBarBuilder(buttons);
    buttons.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(apply);
    bb.addButton(cancel);
    bb.addGlue();

    AbstractAction closeAction =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        };
    ActionMap am = main.getActionMap();
    InputMap im = main.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.prefs.getKey("Close dialog"), "close");
    am.put("close", closeAction);

    // con.fill = GridBagConstraints.BOTH;
    // con.weightx = 0.3;
    // con.weighty = 1;
    // gbl.setConstraints(typeComp, con);
    main.add(typeComp, BorderLayout.WEST);
    main.add(right, BorderLayout.CENTER);
    main.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    pane.add(main, BorderLayout.CENTER);
    pane.add(buttons, BorderLayout.SOUTH);
    pack();
  }
예제 #2
0
  public PreviewPrefsTab(JabRefPreferences prefs) {
    this.prefs = prefs;

    JPanel firstPanel = new JPanel();
    GridBagLayout layout = new GridBagLayout();
    firstPanel.setLayout(layout);
    JPanel secondPanel = new JPanel();
    secondPanel.setLayout(layout);

    setLayout(layout);
    JLabel lab;
    lab = new JLabel(Globals.lang("Preview") + " 1");
    GridBagConstraints layoutConstraints = new GridBagConstraints();
    layoutConstraints.anchor = GridBagConstraints.WEST;
    layoutConstraints.gridwidth = GridBagConstraints.REMAINDER;
    layoutConstraints.fill = GridBagConstraints.BOTH;
    layoutConstraints.weightx = 1;
    layoutConstraints.weighty = 0;
    layoutConstraints.insets = new Insets(2, 2, 2, 2);
    layout.setConstraints(lab, layoutConstraints);
    layoutConstraints.weighty = 1;
    JScrollPane firstScrollPane = new JScrollPane(layout1);
    layout.setConstraints(firstScrollPane, layoutConstraints);
    firstPanel.add(firstScrollPane);
    layoutConstraints.weighty = 0;
    layoutConstraints.gridwidth = 1;
    layoutConstraints.weightx = 0;
    layoutConstraints.fill = GridBagConstraints.NONE;
    layoutConstraints.anchor = GridBagConstraints.WEST;
    JButton testButton = new JButton(Globals.lang("Test"));
    layout.setConstraints(testButton, layoutConstraints);
    firstPanel.add(testButton);
    JButton defaultButton = new JButton(Globals.lang("Default"));
    layout.setConstraints(defaultButton, layoutConstraints);
    firstPanel.add(defaultButton);
    layoutConstraints.gridwidth = GridBagConstraints.REMAINDER;
    JPanel pan = new JPanel();
    layoutConstraints.weightx = 1;
    layout.setConstraints(pan, layoutConstraints);
    firstPanel.add(pan);
    lab = new JLabel(Globals.lang("Preview") + " 2");
    layout.setConstraints(lab, layoutConstraints);
    // p2.add(lab);
    layoutConstraints.weighty = 1;
    layoutConstraints.fill = GridBagConstraints.BOTH;
    JScrollPane secondScrollPane = new JScrollPane(layout2);
    layout.setConstraints(secondScrollPane, layoutConstraints);
    secondPanel.add(secondScrollPane);
    layoutConstraints.weighty = 0;
    layoutConstraints.weightx = 0;
    layoutConstraints.fill = GridBagConstraints.NONE;
    layoutConstraints.gridwidth = 1;
    JButton testButton2 = new JButton(Globals.lang("Test"));
    layout.setConstraints(testButton2, layoutConstraints);
    secondPanel.add(testButton2);
    JButton defaultButton2 = new JButton(Globals.lang("Default"));
    layout.setConstraints(defaultButton2, layoutConstraints);
    secondPanel.add(defaultButton2);
    layoutConstraints.gridwidth = 1;
    pan = new JPanel();
    layoutConstraints.weightx = 1;
    layout.setConstraints(pan, layoutConstraints);
    secondPanel.add(pan);

    layoutConstraints.weightx = 1;
    layoutConstraints.weighty = 0;
    layoutConstraints.fill = GridBagConstraints.BOTH;
    layoutConstraints.gridwidth = GridBagConstraints.REMAINDER;
    lab = new JLabel(Globals.lang("Preview") + " 1");
    layout.setConstraints(lab, layoutConstraints);
    add(lab);
    layoutConstraints.weighty = 1;
    layout.setConstraints(firstPanel, layoutConstraints);
    add(firstPanel);
    lab = new JLabel(Globals.lang("Preview") + " 2");
    layoutConstraints.weighty = 0;
    JSeparator sep = new JSeparator(SwingConstants.HORIZONTAL);
    layout.setConstraints(sep, layoutConstraints);
    add(sep);
    layout.setConstraints(lab, layoutConstraints);
    add(lab);
    layoutConstraints.weighty = 1;
    layout.setConstraints(secondPanel, layoutConstraints);
    add(secondPanel);

    // PDF Preview button
    JPanel pdfPreviewPanel = new JPanel(new BorderLayout());
    pdfPreviewPanel.add(pdfPreview, BorderLayout.WEST);

    { // Help Button
      HelpAction helpAction =
          new HelpAction(
              Globals.helpDiag,
              GUIGlobals.previewHelp,
              Globals.lang("Help on Preview Settings"),
              GUIGlobals.getIconUrl("helpSmall"));
      JButton help = helpAction.getIconButton();
      pdfPreviewPanel.add(help, BorderLayout.EAST);
    }

    layoutConstraints.weighty = 0;
    layout.setConstraints(pdfPreviewPanel, layoutConstraints);
    add(pdfPreviewPanel);

    defaultButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            String tmp = layout1.getText().replaceAll("\n", "__NEWLINE__");
            PreviewPrefsTab.this.prefs.remove(JabRefPreferences.PREVIEW_0);
            layout1.setText(
                PreviewPrefsTab.this
                    .prefs
                    .get(JabRefPreferences.PREVIEW_0)
                    .replaceAll("__NEWLINE__", "\n"));
            PreviewPrefsTab.this.prefs.put(JabRefPreferences.PREVIEW_0, tmp);
          }
        });
    defaultButton2.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            String tmp = layout2.getText().replaceAll("\n", "__NEWLINE__");
            PreviewPrefsTab.this.prefs.remove(JabRefPreferences.PREVIEW_1);
            layout2.setText(
                PreviewPrefsTab.this
                    .prefs
                    .get(JabRefPreferences.PREVIEW_1)
                    .replaceAll("__NEWLINE__", "\n"));
            PreviewPrefsTab.this.prefs.put(JabRefPreferences.PREVIEW_1, tmp);
          }
        });

    testButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            PreviewPrefsTab.getTestEntry();
            try {
              PreviewPanel testPanel =
                  new PreviewPanel(
                      null, PreviewPrefsTab.entry, null, new MetaData(), layout1.getText());
              testPanel.setPreferredSize(new Dimension(800, 350));
              JOptionPane.showMessageDialog(
                  null, testPanel, Globals.lang("Preview"), JOptionPane.PLAIN_MESSAGE);
            } catch (StringIndexOutOfBoundsException ex) {
              ex.printStackTrace();
              JOptionPane.showMessageDialog(
                  null,
                  Globals.lang("Parsing error")
                      + ": "
                      + Globals.lang("illegal backslash expression")
                      + ".\n"
                      + ex.getMessage()
                      + '\n'
                      + Globals.lang("Look at stderr for details")
                      + '.',
                  Globals.lang("Parsing error"),
                  JOptionPane.ERROR_MESSAGE);
            }
          }
        });

    testButton2.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            PreviewPrefsTab.getTestEntry();
            try {
              PreviewPanel testPanel =
                  new PreviewPanel(
                      null, PreviewPrefsTab.entry, null, new MetaData(), layout2.getText());
              testPanel.setPreferredSize(new Dimension(800, 350));
              JOptionPane.showMessageDialog(
                  null,
                  new JScrollPane(testPanel),
                  Globals.lang("Preview"),
                  JOptionPane.PLAIN_MESSAGE);
            } catch (StringIndexOutOfBoundsException ex) {
              ex.printStackTrace();
              JOptionPane.showMessageDialog(
                  null,
                  "Parsing error: illegal backslash expression.\n"
                      + ex.getMessage()
                      + "\nLook at stderr for details.",
                  "Parsing error",
                  JOptionPane.ERROR_MESSAGE);
            }
          }
        });
  }