| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
package org.xmlhammer.gui.preferences; |
| 23 |
|
|
| 24 |
|
import java.awt.BorderLayout; |
| 25 |
|
import java.io.File; |
| 26 |
|
import java.util.List; |
| 27 |
|
|
| 28 |
|
import javax.swing.JCheckBox; |
| 29 |
|
import javax.swing.JFileChooser; |
| 30 |
|
import javax.swing.JFrame; |
| 31 |
|
import javax.swing.JPanel; |
| 32 |
|
import javax.swing.border.EmptyBorder; |
| 33 |
|
import javax.swing.table.DefaultTableModel; |
| 34 |
|
|
| 35 |
|
import org.bounce.DefaultFileFilter; |
| 36 |
|
import org.xmlhammer.model.preferences.Preferences.Catalogs; |
| 37 |
|
import org.xmlhammer.model.preferences.Preferences.Catalogs.Catalog; |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
public class CatalogsPanel extends PreferencesTablePanel { |
| 46 |
|
|
| 47 |
|
private static final long serialVersionUID = -6856643909200549168L; |
| 48 |
|
|
| 49 |
22 |
private JFileChooser chooser = null; |
| 50 |
22 |
private JCheckBox preferPublicIdentifiersCheck = null; |
| 51 |
|
|
| 52 |
|
public CatalogsPanel(JFrame parent, String name, String helpID) { |
| 53 |
22 |
super( parent, name, helpID); |
| 54 |
22 |
preferPublicIdentifiersCheck = new JCheckBox("Prefer Public Identifiers"); |
| 55 |
22 |
preferPublicIdentifiersCheck.setBorder(new EmptyBorder(10, 10, 20, 10)); |
| 56 |
|
|
| 57 |
22 |
JPanel panel = new JPanel(new BorderLayout()); |
| 58 |
22 |
panel.add(preferPublicIdentifiersCheck, BorderLayout.NORTH); |
| 59 |
22 |
panel.add(getCenterPane(), BorderLayout.CENTER); |
| 60 |
22 |
setCenterPane(panel); |
| 61 |
22 |
} |
| 62 |
|
|
| 63 |
|
protected DefaultTableModel getModel() { |
| 64 |
66 |
if ( model == null) { |
| 65 |
22 |
model = new ActivatableTableModel(); |
| 66 |
22 |
model.setColumnCount(2); |
| 67 |
22 |
model.setColumnIdentifiers( new String[] {" ", "Catalog location"}); |
| 68 |
|
} |
| 69 |
|
|
| 70 |
66 |
return model; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
private JFileChooser getFileChooser() { |
| 74 |
0 |
if ( chooser == null) { |
| 75 |
0 |
chooser = new JFileChooser(); |
| 76 |
0 |
chooser.setAcceptAllFileFilterUsed( true); |
| 77 |
0 |
chooser.addChoosableFileFilter(new DefaultFileFilter( "cat,xcat", "XML Catalogs")); |
| 78 |
0 |
chooser.addChoosableFileFilter(new DefaultFileFilter( "xml", "XML Documents")); |
| 79 |
|
} |
| 80 |
|
|
| 81 |
0 |
return chooser; |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
public void setCatalogs(Catalogs catalogs) { |
| 85 |
22 |
List<Catalog> list = catalogs.getCatalog(); |
| 86 |
22 |
preferPublicIdentifiersCheck.setSelected(catalogs.isPreferPublicIdentifiers()); |
| 87 |
|
|
| 88 |
22 |
while (getModel().getRowCount() > 0) { |
| 89 |
0 |
getModel().removeRow(0); |
| 90 |
0 |
} |
| 91 |
|
|
| 92 |
22 |
for (Catalog catalog : list) { |
| 93 |
0 |
getModel().addRow(new Object[] {catalog.isActive(), catalog.getSrc()}); |
| 94 |
0 |
} |
| 95 |
22 |
} |
| 96 |
|
|
| 97 |
|
protected int[] getColumnWidths() { |
| 98 |
22 |
return new int[] {25, 1000}; |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
public Catalogs getCatalogs() { |
| 102 |
22 |
Catalogs catalogs = new Catalogs(); |
| 103 |
22 |
catalogs.setPreferPublicIdentifiers(preferPublicIdentifiersCheck.isSelected()); |
| 104 |
|
|
| 105 |
22 |
for ( int i = 0; i < getModel().getRowCount(); i++) { |
| 106 |
0 |
Catalog catalog = new Catalog(); |
| 107 |
0 |
catalog.setActive((Boolean)getModel().getValueAt(i, 0)); |
| 108 |
0 |
catalog.setSrc((String)getModel().getValueAt(i, 1)); |
| 109 |
0 |
catalogs.getCatalog().add(catalog); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
22 |
return catalogs; |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
protected void addButtonPressed() { |
| 116 |
|
|
| 117 |
0 |
if (getModel().getRowCount() > 0) { |
| 118 |
0 |
String selection = (String)getModel().getValueAt(getModel().getRowCount()-1, 1); |
| 119 |
0 |
if ( selection != null && selection.length() > 0) { |
| 120 |
0 |
getFileChooser().setSelectedFile(new File(selection)); |
| 121 |
|
} |
| 122 |
|
} |
| 123 |
|
|
| 124 |
0 |
int value = getFileChooser().showOpenDialog( getFrame()); |
| 125 |
|
|
| 126 |
0 |
if ( value == JFileChooser.APPROVE_OPTION) { |
| 127 |
0 |
File file = getFileChooser().getSelectedFile(); |
| 128 |
|
|
| 129 |
0 |
if ( file.exists()) { |
| 130 |
0 |
getModel().addRow( new Object[] {Boolean.TRUE, file.getAbsolutePath()}); |
| 131 |
0 |
getTable().scrollRectToVisible( getTable().getCellRect( getModel().getRowCount()-1, 1, false)); |
| 132 |
|
} |
| 133 |
|
} |
| 134 |
0 |
} |
| 135 |
|
|
| 136 |
|
@Override |
| 137 |
|
protected Object[] getDefaultRowContent() { |
| 138 |
0 |
return new Object[] {Boolean.TRUE, "New Catalog Location"}; |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
@Override |
| 142 |
|
protected String getName(int row) { |
| 143 |
0 |
return getModel().getValueAt(row, 1).toString(); |
| 144 |
|
} |
| 145 |
|
} |