/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* LuceneOptionsUI.java
*
* Created on Nov 26, 2010, 3:54:55 PM
*/
package org.alastairmailer;
import java.awt.Component;
import java.awt.Frame;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Vector;
import java.util.logging.Logger;
import javax.swing.AbstractListModel;
import javax.swing.DefaultListModel;
import javax.swing.DefaultListSelectionModel;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.store.FSDirectory;
/**
*
* @author agm
*/
public class LuceneOptionsUI extends javax.swing.JDialog {
private static final long serialVersionUID = 1L;
private class dbOptions {
private LuceneBibtexDatabase db;
private String fileDir;
private String indexDir;
private boolean autoIndex = true;
private int autoIndexSeconds = 60;
public dbOptions(LuceneBibtexDatabase db) {
this.db = db;
if (db.getFileDir() != null) {
this.fileDir = db.getFileDir().getAbsolutePath();
} else {
this.fileDir = "";
}
if (db.getIndexDir() != null) {
this.indexDir = db.getIndexDir().getAbsolutePath();
} else {
this.indexDir = "";
}
this.autoIndex = db.getAutoIndexEnabled();
this.autoIndexSeconds = db.getUpdateTime();
}
public void saveSettings() {
File toSave = this.indexDir.trim().isEmpty() ? null : new File(this.indexDir);
if (db.getIndexDir() == null) {
db.setIndexDir(toSave);
} else if (!(db.getIndexDir().equals(new File(this.indexDir)))) {
db.setIndexDir(toSave);
}
if (!(db.getAutoIndexEnabled() == this.autoIndex)) {
db.setAutoIndexEnabled(autoIndex);
}
if (!(db.getUpdateTime() == this.autoIndexSeconds)) {
db.setUpdateTime(autoIndexSeconds);
}
}
}
private Vector<dbOptions> optionsList;
private ListCellRenderer r = new ListCellRenderer() {
public Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected,
boolean cellHasFocus) {
dbOptions o = (dbOptions) value;
JLabel l = new JLabel(o.db.toString());
l.setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());
l.setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());
l.setOpaque(true);
return l;
}
};
public ListCellRenderer getCellModel() {
return r;
}
private ListModel m;
public ListModel getListModel() {
return m;
}
public ListModel getPluginsListModel() {
return pluginListModel;
}
private ListModel pluginListModel;
/** Creates new form LuceneOptionsUI */
public LuceneOptionsUI(java.awt.Frame parent, boolean modal, final LuceneSidePanelPlugin plugin) {
super(parent, modal);
this.optionsList = new Vector<dbOptions>();
for (LuceneBibtexDatabase db : plugin.getDatabases()) {
optionsList.add(new dbOptions(db));
}
ListModel m1 = new AbstractListModel() {
/**
*
*/
private static final long serialVersionUID = 1L;
public int getSize() {
return optionsList.size();
}
public Object getElementAt(int i) {
return optionsList.get(i);
}
};
pluginListModel = new DefaultListModel() {
private List<FiletypeHandler> plugins = FiletypeHandler.getRegisteredHandlers();
public int getSize() {
return plugins.size();
}
public Object getElementAt(int i) {
return plugins.get(i).getPluginName();
}
};
this.m = m1;
initComponents();
indexDirTextField.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
updateWarnings();
}
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
public void keyTyped(KeyEvent e) {
updateWarnings();
}
});
jList1.setSelectionModel(new SingleSelectionModel() {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void updateSingleSelection(int oldValue, int newValue) {
if (oldValue != -1) { updateSettings(oldValue); }
if (newValue != -1) { loadSettings(newValue); }
}
});
pluginsList.setSelectionModel(new SingleSelectionModel() {
public void updateSingleSelection(int oldValue, int newValue) {
if (newValue == -1) {
pluginTitleLabel.setText("");
pluginAboutLabel.setText("");
} else {
FiletypeHandler selected = FiletypeHandler.getRegisteredHandlers().get(newValue);
pluginTitleLabel.setText(selected.getPluginName());
pluginAboutLabel.setText("<html>" + selected.getPluginAbout() + "</html>");
}
}
});
if (optionsList.size() > 0) {
jList1.setSelectedIndex(0);
} else {
tabs.setEnabledAt(tabs.indexOfTab("Databases"), false);
}
}
public LuceneOptionsUI(Frame parent, boolean modal, final LuceneSidePanelPlugin plugin, LuceneBibtexDatabase ldb) {
this(parent, modal, plugin);
tabs.setSelectedIndex(tabs.indexOfTab("Databases"));
jList1.setSelectedValue(ldb, true);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
fileChooser = new javax.swing.JFileChooser();
optionsPanel = new javax.swing.JPanel();
tabs = new javax.swing.JTabbedPane();
pluginsTab = new javax.swing.JPanel();
pluginsListLabel = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
pluginsList = new javax.swing.JList();
jPanel1 = new javax.swing.JPanel();
pluginTitleLabel = new javax.swing.JLabel();
pluginAboutLabel = new javax.swing.JLabel();
databasesTab = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jLabel1 = new javax.swing.JLabel();
fileDirTextField = new javax.swing.JTextField();
fileBrowseButton = new javax.swing.JButton();
fileWarningLabel = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
indexDirTextField = new javax.swing.JTextField();
indexBrowseButton = new javax.swing.JButton();
indexWarningLabel = new javax.swing.JLabel();
updateButton = new javax.swing.JButton();
rebuildButton = new javax.swing.JButton();
updateLabel1 = new javax.swing.JLabel();
updateEnabled = new javax.swing.JCheckBox();
updateSeconds = new javax.swing.JTextField();
updateLabel2 = new javax.swing.JLabel();
saveButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
fileChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
setResizable(false);
pluginsTab.setOpaque(false);
pluginsListLabel.setText("Loaded plugins:");
pluginsList.setModel(getPluginsListModel());
jScrollPane2.setViewportView(pluginsList);
jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true));
jPanel1.setOpaque(false);
pluginTitleLabel.setFont(pluginTitleLabel.getFont().deriveFont(pluginTitleLabel.getFont().getSize()+3f));
pluginAboutLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
pluginAboutLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pluginAboutLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 441, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(pluginTitleLabel))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(pluginTitleLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(pluginAboutLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
javax.swing.GroupLayout pluginsTabLayout = new javax.swing.GroupLayout(pluginsTab);
pluginsTab.setLayout(pluginsTabLayout);
pluginsTabLayout.setHorizontalGroup(
pluginsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pluginsTabLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pluginsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE)
.addComponent(pluginsListLabel, javax.swing.GroupLayout.Alignment.LEADING))
.addContainerGap())
);
pluginsTabLayout.setVerticalGroup(
pluginsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pluginsTabLayout.createSequentialGroup()
.addContainerGap()
.addComponent(pluginsListLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
.addContainerGap())
);
tabs.addTab("Plugins", pluginsTab);
databasesTab.setOpaque(false);
jList1.setModel(m
);
jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jList1.setCellRenderer(r);
jScrollPane1.setViewportView(jList1);
jLabel1.setText("File directory:");
fileDirTextField.setEditable(false);
fileDirTextField.setName("fileDirTextField"); // NOI18N
fileBrowseButton.setText("Browse");
fileBrowseButton.setEnabled(false);
fileBrowseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chooseIndexFile(evt);
}
});
fileWarningLabel.setFont(new java.awt.Font("Lucida Grande", 0, 10));
fileWarningLabel.setText(" ");
jLabel3.setText("Index directory:");
indexDirTextField.setName("indexDirTextField"); // NOI18N
indexBrowseButton.setText("Browse");
indexBrowseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chooseIndexFile(evt);
}
});
indexWarningLabel.setFont(new java.awt.Font("Lucida Grande", 0, 10));
indexWarningLabel.setText(" ");
updateButton.setText("Update Index");
updateButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
updateIndex(evt);
}
});
rebuildButton.setText("Rebuild Index");
rebuildButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
updateIndex(evt);
}
});
updateLabel1.setText("Background update of database indexes every ");
updateEnabled.setSelected(true);
updateEnabled.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
toggleUpdate(evt);
}
});
updateSeconds.setColumns(4);
updateSeconds.setText("60");
updateLabel2.setText("seconds");
javax.swing.GroupLayout databasesTabLayout = new javax.swing.GroupLayout(databasesTab);
databasesTab.setLayout(databasesTabLayout);
databasesTabLayout.setHorizontalGroup(
databasesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(databasesTabLayout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE)
.addGap(20, 20, 20))
.addGroup(databasesTabLayout.createSequentialGroup()
.addContainerGap()
.addGroup(databasesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(databasesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(databasesTabLayout.createSequentialGroup()
.addComponent(updateButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(rebuildButton))
.addGroup(databasesTabLayout.createSequentialGroup()
.addGroup(databasesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(fileDirTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
.addComponent(indexDirTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(databasesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(indexBrowseButton)
.addComponent(fileBrowseButton)))
.addGroup(databasesTabLayout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(indexWarningLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE))
.addGroup(databasesTabLayout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(fileWarningLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)))
.addContainerGap())
.addGroup(databasesTabLayout.createSequentialGroup()
.addContainerGap()
.addComponent(updateEnabled)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(updateLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(updateSeconds, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(updateLabel2)
.addContainerGap(47, Short.MAX_VALUE))
);
databasesTabLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {rebuildButton, updateButton});
databasesTabLayout.setVerticalGroup(
databasesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(databasesTabLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(databasesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(fileDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(fileBrowseButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(fileWarningLabel)
.addGap(14, 14, 14)
.addGroup(databasesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(indexDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(indexBrowseButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(indexWarningLabel)
.addGap(7, 7, 7)
.addGroup(databasesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(updateButton)
.addComponent(rebuildButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(databasesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(updateEnabled, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
.addGroup(databasesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(updateSeconds)
.addComponent(updateLabel1)
.addComponent(updateLabel2)))
.addGap(49, 49, 49))
);
tabs.addTab("Databases", databasesTab);
saveButton.setText("Save");
saveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveButtonActionPerformed(evt);
}
});
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
actionCancelled(evt);
}
});
javax.swing.GroupLayout optionsPanelLayout = new javax.swing.GroupLayout(optionsPanel);
optionsPanel.setLayout(optionsPanelLayout);
optionsPanelLayout.setHorizontalGroup(
optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(optionsPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, optionsPanelLayout.createSequentialGroup()
.addComponent(cancelButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(saveButton)
.addContainerGap())
.addComponent(tabs, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)))
);
optionsPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, saveButton});
optionsPanelLayout.setVerticalGroup(
optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, optionsPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(tabs)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(saveButton)
.addComponent(cancelButton))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(optionsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(optionsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void actionCancelled(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionCancelled
setVisible(false);
}//GEN-LAST:event_actionCancelled
public void loadSettings(int i) {
dbOptions selected = optionsList.get(i);
if (selected.fileDir != null) {
fileDirTextField.setText(selected.fileDir);
} else {
fileDirTextField.setText("");
}
if (selected.indexDir != null) {
indexDirTextField.setText(selected.indexDir);
} else {
indexDirTextField.setText("");
}
updateWarnings();
updateEnabled.setSelected(selected.autoIndex);
updateSeconds.setText("" + selected.autoIndexSeconds);
}
public void updateSettings(int i) throws NumberFormatException {
dbOptions selected = optionsList.get(i);
selected.fileDir = fileDirTextField.getText();
selected.indexDir = indexDirTextField.getText();
selected.autoIndex = updateEnabled.isSelected();
selected.autoIndexSeconds = Integer.parseInt(updateSeconds.getText());
}
private void chooseIndexFile(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseIndexFile
int returnVal = fileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
if (evt.getSource() == fileBrowseButton) {
fileDirTextField.setText(file.getAbsolutePath());
} else if (evt.getSource() == indexBrowseButton) {
indexDirTextField.setText(file.getAbsolutePath());
}
} else {
}
dbOptions selected = (dbOptions)jList1.getSelectedValue();
selected.indexDir = indexDirTextField.getText();
updateWarnings();
}//GEN-LAST:event_chooseIndexFile
private void updateIndex(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateIndex
int confirmUpdate = JOptionPane.showConfirmDialog(databasesTab, "Updating the index require you save your changes. Continue?", "Continue?", JOptionPane.YES_NO_OPTION);
if (confirmUpdate == JOptionPane.NO_OPTION) {
return;
}
updateSettings(jList1.getSelectedIndex());
dbOptions selected = (dbOptions)jList1.getSelectedValue();
selected.saveSettings();
File indexDir = new File(selected.indexDir);
if (!indexDir.exists()) {
int confirm = JOptionPane.showConfirmDialog(this.getContentPane(), "The index directory does not exist. Do you want to create it?", "Create directory?", JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
indexDir.mkdirs();
} else { return; }
}
LuceneBibtexDatabase ldb = selected.db;
try {
ldb.updateIndex(this, evt.getSource() == this.rebuildButton);
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
updateWarnings();
}//GEN-LAST:event_updateIndex
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
updateSettings(jList1.getSelectedIndex());
for (dbOptions o : optionsList) {
o.saveSettings();
}
setVisible(false);
}//GEN-LAST:event_saveButtonActionPerformed
private void toggleUpdate(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_toggleUpdate
updateLabel1.setEnabled(updateEnabled.isSelected());
updateSeconds.setEnabled(updateEnabled.isSelected());
updateLabel2.setEnabled(updateEnabled.isSelected());
}//GEN-LAST:event_toggleUpdate
private void updateWarnings() {
File fileDir = new File(fileDirTextField.getText());
File indexDir = new File(indexDirTextField.getText());
try {
if (!fileDir.exists()) {
fileWarningLabel.setText("The specified path does not exist.");
updateButton.setEnabled(false);
rebuildButton.setEnabled(false);
} else if (!fileDir.isDirectory()) {
fileWarningLabel.setText("The specified path is not a directory.");
updateButton.setEnabled(false);
rebuildButton.setEnabled(false);
} else {
fileWarningLabel.setText(" ");
updateButton.setEnabled(true);
rebuildButton.setEnabled(true);
}
if (!indexDir.exists()) {
indexWarningLabel.setText("The specified path does not exist.");
updateButton.setEnabled(false);
rebuildButton.setText("Build index");
rebuildButton.setEnabled(true);
} else if (!indexDir.isDirectory()) {
indexWarningLabel.setText("The specified path is not a directory.");
updateButton.setEnabled(false);
rebuildButton.setEnabled(false);
} else if (!IndexReader.indexExists(FSDirectory.open(indexDir))) {
indexWarningLabel.setText("No readable index exists at the specified path.");
updateButton.setEnabled(false);
rebuildButton.setText("Build index");
rebuildButton.setEnabled(true);
} else {
indexWarningLabel.setText(" ");
updateButton.setEnabled(true);
rebuildButton.setText("Rebuild index");
rebuildButton.setEnabled(true);
}
} catch (IOException e) {
indexWarningLabel.setText("An exception occured while trying to read the specified path.");
updateButton.setEnabled(false);
rebuildButton.setEnabled(false);
Logger.getAnonymousLogger().severe(e.getLocalizedMessage());
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JPanel databasesTab;
private javax.swing.JButton fileBrowseButton;
private javax.swing.JFileChooser fileChooser;
private javax.swing.JTextField fileDirTextField;
private javax.swing.JLabel fileWarningLabel;
private javax.swing.JButton indexBrowseButton;
private javax.swing.JTextField indexDirTextField;
private javax.swing.JLabel indexWarningLabel;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel3;
private javax.swing.JList jList1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JPanel optionsPanel;
private javax.swing.JLabel pluginAboutLabel;
private javax.swing.JLabel pluginTitleLabel;
private javax.swing.JList pluginsList;
private javax.swing.JLabel pluginsListLabel;
private javax.swing.JPanel pluginsTab;
private javax.swing.JButton rebuildButton;
private javax.swing.JButton saveButton;
private javax.swing.JTabbedPane tabs;
private javax.swing.JButton updateButton;
private javax.swing.JCheckBox updateEnabled;
private javax.swing.JLabel updateLabel1;
private javax.swing.JLabel updateLabel2;
private javax.swing.JTextField updateSeconds;
// End of variables declaration//GEN-END:variables
}