use of org.freeplane.features.format.PatternFormat in project freeplane by freeplane.
the class TimeManagement method createDateFormatChooser.
private JComboBox createDateFormatChooser() {
class DateFormatComboBoxElement {
private final PatternFormat dateFormat;
DateFormatComboBoxElement(PatternFormat dateFormat) {
this.dateFormat = dateFormat;
}
PatternFormat getDateFormat() {
return dateFormat;
}
public String toString() {
return dateFormat.formatObject(getCalendarDate()).toString();
}
}
final String dateFormatPattern = ResourceController.getResourceController().getProperty("date_format");
final Vector<DateFormatComboBoxElement> values = new Vector<DateFormatComboBoxElement>();
final List<PatternFormat> datePatterns = FormatController.getController().getDateFormats();
int selectedIndex = 0;
for (int i = 0; i < datePatterns.size(); ++i) {
final PatternFormat patternFormat = datePatterns.get(i);
values.add(new DateFormatComboBoxElement(patternFormat));
if (patternFormat.getPattern().equals(dateFormatPattern)) {
dateFormat = patternFormat;
selectedIndex = i;
}
}
final JComboBox dateFormatChooser = new JComboBox(values);
dateFormatChooser.setFocusable(false);
if (!datePatterns.isEmpty()) {
dateFormatChooser.setSelectedIndex(selectedIndex);
dateFormat = ((DateFormatComboBoxElement) (dateFormatChooser.getSelectedItem())).getDateFormat();
}
dateFormatChooser.addItemListener(new ItemListener() {
public void itemStateChanged(final ItemEvent e) {
dateFormat = ((DateFormatComboBoxElement) e.getItem()).getDateFormat();
final Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (focusOwner instanceof JTable) {
JTable table = (JTable) focusOwner;
final int[] selectedRows = table.getSelectedRows();
final int[] selectedColumns = table.getSelectedColumns();
for (int r : selectedRows) for (int c : selectedColumns) {
Object date = table.getValueAt(r, c);
if (date instanceof FormattedDate) {
final FormattedDate fd = (FormattedDate) date;
if (!fd.getDateFormat().equals(dateFormat)) {
table.setValueAt(new FormattedDate(fd, dateFormat.getPattern()), r, c);
}
}
}
} else {
ModeController mController = Controller.getCurrentModeController();
for (final NodeModel node : mController.getMapController().getSelectedNodes()) {
final MTextController textController = (MTextController) TextController.getController();
Object date = node.getUserObject();
if (date instanceof FormattedDate) {
final FormattedDate fd = (FormattedDate) date;
if (!fd.getDateFormat().equals(dateFormat)) {
textController.setNodeObject(node, new FormattedDate(fd, dateFormat.getPattern()));
}
}
}
}
}
});
dateFormatChooser.setAlignmentX(Component.LEFT_ALIGNMENT);
return dateFormatChooser;
}
use of org.freeplane.features.format.PatternFormat in project freeplane by freeplane.
the class PatternFormatTest method testOnePattern.
private void testOnePattern(String pattern) {
final PatternFormat formatter = PatternFormat.guessPatternFormat(pattern);
assertNotNull("could not create a formatter for pattern " + pattern, formatter);
if (formatter.acceptsDate())
System.err.println(pattern + "->" + formatter.formatObject(new Date()));
else if (formatter.acceptsNumber())
System.err.println(pattern + "->" + formatter.formatObject(1223.456789));
else
System.err.println(pattern + "->" + formatter.formatObject("Hello world!"));
}
Aggregations