Commit d7c356f0ab00f16330b21db2f220a094bf5166b7
1 parent
b1d9e731d4
Exists in
master
Export Bibtex support added
Showing 2 changed files with 76 additions and 10 deletions
org/wheel/gui/Wheel.form
View file @
d7c356f
... | ... | @@ -54,10 +54,12 @@ |
54 | 54 | <Component id="configButton" min="-2" max="-2" attributes="0"/> |
55 | 55 | <EmptySpace min="-2" max="-2" attributes="0"/> |
56 | 56 | <Component id="dbManagementButton" min="-2" max="-2" attributes="0"/> |
57 | - <EmptySpace min="-2" max="-2" attributes="0"/> | |
57 | + <EmptySpace max="-2" attributes="0"/> | |
58 | + <Component id="exportButton" min="-2" max="-2" attributes="0"/> | |
59 | + <EmptySpace max="-2" attributes="0"/> | |
58 | 60 | <Component id="jSeparator1" min="-2" pref="10" max="-2" attributes="0"/> |
59 | 61 | <EmptySpace max="-2" attributes="0"/> |
60 | - <Component id="searchFieldText" pref="308" max="32767" attributes="0"/> | |
62 | + <Component id="searchFieldText" pref="243" max="32767" attributes="0"/> | |
61 | 63 | <EmptySpace max="-2" attributes="0"/> |
62 | 64 | <Component id="searchButton" min="-2" max="-2" attributes="0"/> |
63 | 65 | <EmptySpace max="-2" attributes="0"/> |
... | ... | @@ -87,7 +89,10 @@ |
87 | 89 | </Group> |
88 | 90 | <Component id="openButton" alignment="0" max="32767" attributes="0"/> |
89 | 91 | <Component id="configButton" alignment="0" max="32767" attributes="0"/> |
90 | - <Component id="dbManagementButton" alignment="0" max="32767" attributes="0"/> | |
92 | + <Group type="103" alignment="0" groupAlignment="3" attributes="0"> | |
93 | + <Component id="dbManagementButton" alignment="3" max="32767" attributes="0"/> | |
94 | + <Component id="exportButton" alignment="3" max="32767" attributes="0"/> | |
95 | + </Group> | |
91 | 96 | <Component id="jSeparator1" alignment="0" max="32767" attributes="0"/> |
92 | 97 | </Group> |
93 | 98 | <EmptySpace max="-2" attributes="0"/> |
... | ... | @@ -118,6 +123,9 @@ |
118 | 123 | <Connection code="new javax.swing.table.DefaultTableModel(
 new Object [][] {

 },
 new String [] {
 "ID", "Title", "Category", "PDF File", "Brief", "Tags", "Year", "Authors", "Type", "Publicer", "Series", "Understability", "Have I read it?", "Importance", "References", "Cited By", "Bibtex"
 }
) {
 Class[] types = new Class [] {
 PKeyIdPair.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Short.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
 };
 boolean[] canEdit = new boolean [] {
 false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false
 };

 public Class getColumnClass(int columnIndex) {
 if (columnIndex == 0) {
 return PKeyIdPair.class;
 }
 return types [columnIndex];
 }

 public boolean isCellEditable(int rowIndex, int columnIndex) {
 return canEdit [columnIndex];
 }
}" type="code"/> |
119 | 124 | </Property> |
120 | 125 | <Property name="rowHeight" type="int" value="22"/> |
126 | + <Property name="selectionModel" type="javax.swing.ListSelectionModel" editor="org.netbeans.modules.form.editors2.JTableSelectionModelEditor"> | |
127 | + <JTableSelectionModel selectionMode="2"/> | |
128 | + </Property> | |
121 | 129 | </Properties> |
122 | 130 | <AuxValues> |
123 | 131 | <AuxValue name="JavaCodeGenerator_InitCodePre" type="java.lang.String" value="mainTable.setModel(new DefaultTableModel());"/> |
... | ... | @@ -206,6 +214,14 @@ |
206 | 214 | <Properties> |
207 | 215 | <Property name="orientation" type="int" value="1"/> |
208 | 216 | </Properties> |
217 | + </Component> | |
218 | + <Component class="javax.swing.JButton" name="exportButton"> | |
219 | + <Properties> | |
220 | + <Property name="text" type="java.lang.String" value="Export"/> | |
221 | + </Properties> | |
222 | + <Events> | |
223 | + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="exportButtonActionPerformed"/> | |
224 | + </Events> | |
209 | 225 | </Component> |
210 | 226 | </SubComponents> |
211 | 227 | </Container> |
org/wheel/gui/Wheel.java
View file @
d7c356f
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | import java.awt.event.MouseEvent; |
16 | 16 | import java.io.File; |
17 | 17 | import java.io.IOException; |
18 | +import java.io.PrintWriter; | |
18 | 19 | import java.net.URL; |
19 | 20 | import java.sql.ResultSet; |
20 | 21 | import java.sql.SQLException; |
... | ... | @@ -23,6 +24,7 @@ |
23 | 24 | import java.util.prefs.Preferences; |
24 | 25 | import javax.swing.AbstractAction; |
25 | 26 | import javax.swing.JButton; |
27 | +import javax.swing.JFileChooser; | |
26 | 28 | import javax.swing.JMenu; |
27 | 29 | import javax.swing.JMenuBar; |
28 | 30 | import javax.swing.JMenuItem; |
... | ... | @@ -92,6 +94,7 @@ |
92 | 94 | openButton = new javax.swing.JButton(); |
93 | 95 | dbManagementButton = new javax.swing.JButton(); |
94 | 96 | jSeparator1 = new javax.swing.JSeparator(); |
97 | + exportButton = new javax.swing.JButton(); | |
95 | 98 | |
96 | 99 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); |
97 | 100 | setTitle("Wheel Bibliography Organizer"); |
... | ... | @@ -132,6 +135,7 @@ |
132 | 135 | } |
133 | 136 | }); |
134 | 137 | mainTable.setRowHeight(22); |
138 | + mainTable.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); | |
135 | 139 | jScrollPane1.setViewportView(mainTable); |
136 | 140 | |
137 | 141 | editButton.setText("Edit"); |
... | ... | @@ -205,6 +209,13 @@ |
205 | 209 | |
206 | 210 | jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL); |
207 | 211 | |
212 | + exportButton.setText("Export"); | |
213 | + exportButton.addActionListener(new java.awt.event.ActionListener() { | |
214 | + public void actionPerformed(java.awt.event.ActionEvent evt) { | |
215 | + exportButtonActionPerformed(evt); | |
216 | + } | |
217 | + }); | |
218 | + | |
208 | 219 | javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); |
209 | 220 | mainPanel.setLayout(mainPanelLayout); |
210 | 221 | mainPanelLayout.setHorizontalGroup( |
211 | 222 | |
... | ... | @@ -225,9 +236,11 @@ |
225 | 236 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
226 | 237 | .addComponent(dbManagementButton) |
227 | 238 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
239 | + .addComponent(exportButton) | |
240 | + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
228 | 241 | .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) |
229 | 242 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
230 | - .addComponent(searchFieldText, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE) | |
243 | + .addComponent(searchFieldText, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE) | |
231 | 244 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
232 | 245 | .addComponent(searchButton) |
233 | 246 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
... | ... | @@ -254,7 +267,9 @@ |
254 | 267 | .addComponent(resetButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) |
255 | 268 | .addComponent(openButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
256 | 269 | .addComponent(configButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
257 | - .addComponent(dbManagementButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
270 | + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
271 | + .addComponent(dbManagementButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
272 | + .addComponent(exportButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | |
258 | 273 | .addComponent(jSeparator1)) |
259 | 274 | .addContainerGap()) |
260 | 275 | ); |
261 | 276 | |
... | ... | @@ -388,7 +403,41 @@ |
388 | 403 | } |
389 | 404 | }//GEN-LAST:event_searchFieldTextKeyPressed |
390 | 405 | |
406 | + private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed | |
407 | + int[] selectedRows = mainTable.getSelectedRows(); | |
408 | + if(selectedRows.length > 0){ | |
409 | + try { | |
410 | + JFileChooser chooser = new JFileChooser(); | |
411 | + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); | |
412 | + if (chooser.showSaveDialog(this) != JFileChooser.OPEN_DIALOG) { | |
413 | + return; | |
414 | + } | |
415 | + String savePath = chooser.getSelectedFile().getPath(); | |
416 | + PrintWriter writer = new PrintWriter(savePath + System.getProperty("file.separator") + "exportedBIB.bib", "UTF-8"); | |
417 | + for(int viewRow : selectedRows){ | |
418 | + DefaultTableModel model = (DefaultTableModel) mainTable.getModel(); | |
419 | + PKeyIdPair keyIdPair = (PKeyIdPair) model.getValueAt(mainTable.convertRowIndexToModel(viewRow), 0); | |
420 | + ResultSet rs = dbController.selectFromTableWhere(DBUtils.PAPERS_TABLENAME, DBUtils.BIBTEX_COLUMN, DBUtils.PKEY_COLUMN+"="+keyIdPair.getpKey(), false); | |
421 | + if(rs.next()){ | |
422 | + String bib = rs.getString(DBUtils.BIBTEX_COLUMN); | |
423 | + if(bib.length() == 0){ | |
424 | + return; | |
425 | + } | |
426 | + writer.println("%naskos index: "+keyIdPair.getId()); | |
427 | + writer.println(bib); | |
428 | + writer.println(); | |
429 | + } | |
430 | + } | |
431 | + writer.close(); | |
432 | + } catch (IOException ex) { | |
433 | + Logger.getLogger(Wheel.class.getName()).log(Level.SEVERE, null, ex); | |
434 | + } catch (SQLException ex) { | |
435 | + Logger.getLogger(Wheel.class.getName()).log(Level.SEVERE, null, ex); | |
436 | + } | |
437 | + } | |
438 | + }//GEN-LAST:event_exportButtonActionPerformed | |
391 | 439 | |
440 | + | |
392 | 441 | // Variables declaration - do not modify//GEN-BEGIN:variables |
393 | 442 | private javax.swing.JButton addButton; |
394 | 443 | private javax.swing.JButton configButton; |
... | ... | @@ -396,6 +445,7 @@ |
396 | 445 | private javax.swing.JButton deleteButton; |
397 | 446 | private javax.swing.JButton detailsButton; |
398 | 447 | private javax.swing.JButton editButton; |
448 | + private javax.swing.JButton exportButton; | |
399 | 449 | private javax.swing.JScrollPane jScrollPane1; |
400 | 450 | private javax.swing.JSeparator jSeparator1; |
401 | 451 | private javax.swing.JPanel mainPanel; |
... | ... | @@ -509,11 +559,11 @@ |
509 | 559 | |
510 | 560 | public void check(MouseEvent e) { |
511 | 561 | int r = mainTable.rowAtPoint(e.getPoint()); |
512 | - if (r >= 0 && r < mainTable.getRowCount()) { | |
513 | - mainTable.setRowSelectionInterval(r, r); | |
514 | - } else { | |
515 | - mainTable.clearSelection(); | |
516 | - } | |
562 | +// if (r >= 0 && r < mainTable.getRowCount()) { | |
563 | +// mainTable.setRowSelectionInterval(r, r); | |
564 | +// } else { | |
565 | +// mainTable.clearSelection(); | |
566 | +// } | |
517 | 567 | |
518 | 568 | int rowindex = mainTable.convertRowIndexToModel(mainTable.getSelectedRow()); |
519 | 569 | if (rowindex < 0) { |