1 package net.sf.bibkeeper.export;
2
3 import javax.swing;
4 import java.awt;
5 import java.awt.event;
6 import java.io.File;
7 import net.sf.bibkeeper.Util;
8 import net.sf.bibkeeper.ExampleFileFilter;
9 import net.sf.bibkeeper.GUIGlobals;
10
11 public class SaveSpecialDialog extends JDialog {
12
13 public static final int SAVE_SEARCH = 1,
14 OPENOFFICE_EXPORT = 2;
15
16 private GridBagLayout gbl = new GridBagLayout();
17 private GridBagConstraints con = new GridBagConstraints();
18 JButton
19 ok = new JButton("Ok"),
20 cancel = new JButton("Cancel");
21 //browse = new JButton("Browse");
22 JPanel
23 main = new JPanel(),
24 opt = new JPanel();
25 private boolean ok_pressed = false;
26 private ButtonGroup choices = new ButtonGroup();
27 private JCheckBox saveSearch =
28 new JCheckBox("Save entries in current search and/or group", true),
29 openOffice =
30 new JCheckBox("Save to OpenOffice.org bibliography CSV file (experimental)", false);
31 //private JTextField filename = new JTextField("", 60);
32
33 private SaveSpecialDialog ths = this;
34
35 public SaveSpecialDialog(JFrame parent) {
36 super(parent, "Save special", true);
37
38 choices.add(saveSearch);
39 choices.add(openOffice);
40
41 ActionListener okListener = new ActionListener() {
42 public void actionPerformed(ActionEvent e) {
43 ok_pressed = true;
44 dispose();
45 }
46 };
47 ok.addActionListener(okListener);
48
49 AbstractAction cancelAction = new AbstractAction() {
50 public void actionPerformed(ActionEvent e) {
51 dispose();
52 }
53 };
54
55 cancel.addActionListener(cancelAction);
56
57 /*
58 browse.addActionListener(new ActionListener() {
59 public void actionPerformed(ActionEvent e) {
60 }
61 });*/
62
63 opt.setLayout(gbl);
64 main.setLayout(gbl);
65
66 // Option buttons:
67 con.weightx = 1;
68 con.gridwidth = 1;
69 con.anchor = GridBagConstraints.EAST;
70 con.fill = GridBagConstraints.NONE;
71 gbl.setConstraints(ok, con);
72 opt.add(ok);
73 con.anchor = GridBagConstraints.WEST;
74 con.gridwidth = GridBagConstraints.REMAINDER;
75 gbl.setConstraints(cancel, con);
76 opt.add(cancel);
77
78 // Main panel:
79 //con.anchor = GridBagConstraints.CENTER;
80 gbl.setConstraints(saveSearch, con);
81 main.add(saveSearch);
82 gbl.setConstraints(openOffice, con);
83 main.add(openOffice);
84 con.weightx = 0;
85 con.gridwidth = 1;
86 /*JLabel lab = new JLabel("Filename:");
87 gbl.setConstraints(lab, con);
88 main.add(lab);
89 con.weightx = 1;
90 con.fill = GridBagConstraints.BOTH;
91 gbl.setConstraints(filename, con);
92 main.add(filename);
93 con.gridwidth = GridBagConstraints.REMAINDER;
94 con.weightx = 0;
95 gbl.setConstraints(browse, con);
96 main.add(browse);
97 */
98
99 JSeparator js = new JSeparator();
100 con.weightx = 1;
101 con.fill = GridBagConstraints.BOTH;
102 //gbl.setConstraints(js, con);
103 //main.add(js);
104 main.setBorder(BorderFactory.createEtchedBorder());
105
106 getContentPane().add(main, BorderLayout.CENTER);
107 getContentPane().add(opt, BorderLayout.SOUTH);
108
109 // Key bindings:
110 ActionMap am = main.getActionMap();
111 InputMap im = main.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
112 im.put(GUIGlobals.exitDialog, "close");
113 am.put("close", cancelAction);
114
115 setSize(400, 125);
116 Util.placeDialog(this, parent);
117 }
118
119 public boolean okPressed() {
120 return ok_pressed;
121 }
122
123 public int getChoice() {
124 if (saveSearch.isSelected())
125 return SAVE_SEARCH;
126 if (openOffice.isSelected())
127 return OPENOFFICE_EXPORT;
128
129 return 0;
130 }
131
132 public String[] getFileType() {
133 if (saveSearch.isSelected())
134 return new String[] {"bib", "BibTeX database"};
135 if (openOffice.isSelected())
136 return new String[] {"csv", "OpenOffice.org CSV file"};
137
138 return null;
139 }
140
141 }