use of org.opt4j.core.config.annotations.File in project opt4j by felixreimann.
the class PropertyPanel method selectFile.
private void selectFile(Property property) {
final File file = property.getAnnotation(File.class);
final JFileChooser fileChooser = PropertyPanel.this.fileChooser.get();
java.io.File dir = null;
try {
dir = new java.io.File(property.getValue().toString());
} catch (Exception ex) {
}
fileChooser.setCurrentDirectory(dir);
if (file != null && !file.value().equals("")) {
FileFilter filter = new FileFilter() {
@Override
public boolean accept(java.io.File pathname) {
if (pathname.isDirectory()) {
return true;
}
String f = pathname.getName().toLowerCase();
String ext = file.value().toLowerCase();
if (f.endsWith(ext)) {
return true;
}
return false;
}
@Override
public String getDescription() {
String ext = file.value().toLowerCase();
return "(*" + ext + ")";
}
};
fileChooser.setFileFilter(filter);
} else {
fileChooser.setFileFilter(null);
}
if (file.folder()) {
if (file.file()) {
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
} else {
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}
} else {
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
}
fileChooser.setVisible(true);
int status = fileChooser.showOpenDialog(null);
if (status == JFileChooser.APPROVE_OPTION) {
java.io.File f = fileChooser.getSelectedFile();
try {
property.setValue(f.getAbsolutePath());
JTextField field = (JTextField) components.get(property);
field.setText("" + property.getValue());
update();
} catch (InvocationTargetException ex) {
System.err.println(ex.getMessage());
}
}
}
use of org.opt4j.core.config.annotations.File in project opt4j by felixreimann.
the class PropertyPanel method updatePropertyPanel.
protected void updatePropertyPanel() {
panel.removeAll();
for (final Property property : module.getProperties()) {
if (property.isActive()) {
String name = property.getName();
int i = getIndent(property);
String s = "";
for (int j = 0; j < i; j++) {
s += " ";
}
if (i > 0) {
s = s.substring(2) + "\u21aa ";
}
JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
JLabel label = new JLabel(s + name);
label.setFocusable(false);
String tooltip = format.getTooltip(property);
if (tooltip != null) {
label.setToolTipText(tooltip);
}
labelPanel.add(label);
File file = property.getAnnotation(File.class);
if (file != null) {
JButton browse = new JButton(Icons.getIcon(Icons.FOLDER));
browse.setFocusable(false);
browse.setBorderPainted(false);
browse.setContentAreaFilled(false);
browse.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
browse.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectFile(property);
}
});
browse.setCursor(new Cursor(Cursor.HAND_CURSOR));
browse.setToolTipText("Browse ...");
labelPanel.add(browse);
}
panel.add(labelPanel);
Component component = components.get(property);
panel.add(component);
}
}
if (module.getModule().getClass().isAnnotationPresent(Citation.class)) {
Citation citation = module.getModule().getClass().getAnnotation(Citation.class);
addReferenceRow(citation);
}
}
Aggregations