Exemplo n.º 1
0
  public int showDialog() {
    panel = new JPanel(new GridBagLayout());

    double lower = Double.NEGATIVE_INFINITY;
    double upper = Double.POSITIVE_INFINITY;

    if (parameter.isZeroOne) {
      lower = 0.0;
      upper = 1.0;
    } else if (parameter.isNonNegative) {
      lower = 0.0;
    }

    panel = new JPanel(new GridBagLayout());

    setupComponents();

    JOptionPane optionPane =
        new JOptionPane(
            panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, null);
    optionPane.setBorder(new EmptyBorder(12, 12, 12, 12));

    final JDialog dialog = optionPane.createDialog(frame, "Linked Parameter Setup");

    priorSettingsPanel.setDialog(dialog);
    priorSettingsPanel.setParameter(parameter);

    if (OSType.isMac()) {
      dialog.setMinimumSize(new Dimension(dialog.getBounds().width, 300));
    } else {
      Toolkit tk = Toolkit.getDefaultToolkit();
      Dimension d = tk.getScreenSize();
      if (d.height < 700 && panel.getHeight() > 450) {
        dialog.setSize(new Dimension(panel.getWidth() + 100, 550));
      } else {
        // setSize because optionsPanel is shrunk in dialog
        dialog.setSize(new Dimension(panel.getWidth() + 100, panel.getHeight() + 100));
      }

      //            System.out.println("panel width = " + panel.getWidth());
      //            System.out.println("panel height = " + panel.getHeight());
    }

    dialog.pack();
    dialog.setResizable(true);
    dialog.setVisible(true);

    int result = JOptionPane.CANCEL_OPTION;
    Integer value = (Integer) optionPane.getValue();
    if (value != null && value != -1) {
      result = value;
    }

    return result;
  }
Exemplo n.º 2
0
  protected void populateDialog(JDialog dlg) {
    dlg.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dlg.setResizable(false);
    dlg.setSize(new Dimension(350, 135));
    dlg.setTitle("New TurboVNC Connection");

    dlg.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            if (VncViewer.nViewers == 1) {
              if (cc.viewer instanceof VncViewer) {
                ((VncViewer) cc.viewer).exit(1);
              }
            } else {
              ret = false;
              endDialog();
            }
          }
        });

    dlg.getContentPane().setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.LINE_START;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.gridheight = 1;
    gbc.insets = new Insets(0, 0, 0, 0);
    gbc.ipadx = 0;
    gbc.ipady = 0;
    gbc.weightx = 1;
    gbc.weighty = 1;

    dlg.getContentPane().add(topPanel, gbc);
    dlg.getContentPane().add(buttonPanel);
    dlg.pack();
  }
  public ManageJournalsPanel(final JabRefFrame frame) {
    this.frame = frame;

    personalFile.setEditable(false);

    ButtonGroup group = new ButtonGroup();
    group.add(newFile);
    group.add(oldFile);
    addExtPan.setLayout(new BorderLayout());
    JButton addExt = new JButton(IconTheme.JabRefIcon.ADD.getIcon());
    addExtPan.add(addExt, BorderLayout.EAST);
    addExtPan.setToolTipText(Localization.lang("Add"));
    // addExtPan.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red));
    FormLayout layout =
        new FormLayout(
            "1dlu, 8dlu, left:pref, 4dlu, fill:200dlu:grow, 4dlu, fill:pref", // 4dlu, left:pref,
                                                                              // 4dlu",
            "pref, pref, pref, 20dlu, 20dlu, fill:200dlu, 4dlu, pref"); // 150dlu");
    FormBuilder builder = FormBuilder.create().layout(layout);

    /*JLabel description = new JLabel("<HTML>"+Glbals.lang("JabRef can switch journal names between "
    +"abbreviated and full form. Since it knows only a limited number of journal names, "
    +"you may need to add your own definitions.")+"</HTML>");*/
    builder.addSeparator(Localization.lang("Built-in journal list")).xyw(2, 1, 6);
    JLabel description =
        new JLabel(
            "<HTML>"
                + Localization.lang("JabRef includes a built-in list of journal abbreviations.")
                + "<br>"
                + Localization.lang(
                    "You can add additional journal names by setting up a personal journal list,<br>as "
                        + "well as linking to external journal lists.")
                + "</HTML>");
    description.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    builder.add(description).xyw(2, 2, 6);
    JButton viewBuiltin = new JButton(Localization.lang("View"));
    builder.add(viewBuiltin).xy(7, 2);
    builder.addSeparator(Localization.lang("Personal journal list")).xyw(2, 3, 6);

    // builder.add(description).xyw(2,1,6));
    builder.add(newFile).xy(3, 4);
    builder.add(newNameTf).xy(5, 4);
    JButton browseNew = new JButton(Localization.lang("Browse"));
    builder.add(browseNew).xy(7, 4);
    builder.add(oldFile).xy(3, 5);
    builder.add(personalFile).xy(5, 5);
    // BrowseAction action = new BrowseAction(personalFile, false);
    // JButton browse = new JButton(Globals.lang("Browse"));
    // browse.addActionListener(action);
    JButton browseOld = new JButton(Localization.lang("Browse"));
    builder.add(browseOld).xy(7, 5);

    userPanel.setLayout(new BorderLayout());
    // builtInTable = new JTable(Globals.journalAbbrev.getTableModel());
    builder.add(userPanel).xyw(2, 6, 4);
    ButtonStackBuilder butBul = new ButtonStackBuilder();
    butBul.addButton(add);
    butBul.addButton(remove);

    butBul.addGlue();
    builder.add(butBul.getPanel()).xy(7, 6);

    builder.addSeparator(Localization.lang("External files")).xyw(2, 8, 6);
    externalFilesPanel.setLayout(new BorderLayout());
    // builder.add(/*new JScrollPane(*/externalFilesPanel/*)*/).xyw(2,8,6);

    setLayout(new BorderLayout());
    builder
        .getPanel()
        .setBorder(
            BorderFactory.createEmptyBorder(
                5, 5, 5, 5)); // createMatteBorder(1,1,1,1,Color.green));
    add(builder.getPanel(), BorderLayout.NORTH);
    add(externalFilesPanel, BorderLayout.CENTER);
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    JButton ok = new JButton(Localization.lang("OK"));
    bb.addButton(ok);
    JButton cancel = new JButton(Localization.lang("Cancel"));
    bb.addButton(cancel);
    bb.addUnrelatedGap();

    JButton help = new HelpAction(HelpFiles.journalAbbrHelp).getHelpButton();
    bb.addButton(help);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    dialog = new JDialog(frame, Localization.lang("Journal abbreviations"), false);
    dialog.getContentPane().add(this, BorderLayout.CENTER);
    dialog.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);

    // add(new JScrollPane(builtInTable), BorderLayout.CENTER);

    // Set up panel for editing a single journal, to be used in a dialog box:
    FormLayout layout2 = new FormLayout("right:pref, 4dlu, fill:180dlu", "p, 2dlu, p");
    FormBuilder builder2 = FormBuilder.create().layout(layout2);
    builder2.add(Localization.lang("Journal name")).xy(1, 1);
    builder2.add(nameTf).xy(3, 1);
    builder2.add(Localization.lang("ISO abbreviation")).xy(1, 3);
    builder2.add(abbrTf).xy(3, 3);
    journalEditPanel = builder2.getPanel();

    viewBuiltin.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            JournalAbbreviationRepository abbr = new JournalAbbreviationRepository();
            abbr.readJournalListFromResource(Abbreviations.JOURNALS_FILE_BUILTIN);
            JTable table =
                new JTable(JournalAbbreviationsUtil.getTableModel(Abbreviations.journalAbbrev));
            JScrollPane pane = new JScrollPane(table);
            JOptionPane.showMessageDialog(
                null,
                pane,
                Localization.lang("Journal list preview"),
                JOptionPane.INFORMATION_MESSAGE);
          }
        });

    browseNew.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            File old = null;
            if (!"".equals(newNameTf.getText())) {
              old = new File(newNameTf.getText());
            }
            String name = FileDialogs.getNewFile(frame, old, null, JFileChooser.SAVE_DIALOG, false);
            if (name != null) {
              newNameTf.setText(name);
              newFile.setSelected(true);
            }
          }
        });
    browseOld.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            File old = null;
            if (!"".equals(personalFile.getText())) {
              old = new File(personalFile.getText());
            }
            String name = FileDialogs.getNewFile(frame, old, null, JFileChooser.OPEN_DIALOG, false);
            if (name != null) {
              personalFile.setText(name);
              oldFile.setSelected(true);
              oldFile.setEnabled(true);
              setupUserTable();
            }
          }
        });

    ok.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (readyToClose()) {
              try {
                storeSettings();
                dialog.dispose();
              } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(
                    null,
                    Localization.lang("Error opening file") + ": " + ex.getMessage(),
                    Localization.lang("Error opening file"),
                    JOptionPane.ERROR_MESSAGE);
              }
            }
          }
        });

    AbstractAction cancelAction =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {
            dialog.dispose();
          }
        };
    cancel.addActionListener(cancelAction);

    add.addActionListener(tableModel);
    remove.addActionListener(tableModel);
    addExt.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            externals.add(new ExternalFileEntry());
            buildExternalsPanel();
          }
        });

    // Key bindings:
    ActionMap am = getActionMap();
    InputMap im = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelAction);

    // dialog.pack();
    int xSize = getPreferredSize().width;
    dialog.setSize(xSize + 10, 700);
  }