use of org.freeplane.features.format.FormattedDate in project freeplane by freeplane.
the class CompareConditionAdapter method compareToData.
private int compareToData(final Object transformedContent) {
if (conditionValue instanceof FormattedNumber && transformedContent instanceof Number) {
return -((FormattedNumber) conditionValue).compareTo((Number) transformedContent);
}
if (conditionValue instanceof Number && transformedContent instanceof String) {
try {
Number number = TextUtils.toNumber((String) transformedContent);
if (conditionValue instanceof FormattedNumber) {
return -((FormattedNumber) conditionValue).compareTo(number);
}
if (number instanceof Long)
return compareTo((Long) number);
if (number instanceof Double)
return compareTo((Double) number);
} catch (final NumberFormatException fne) {
}
;
error = true;
return 0;
}
if (conditionValue instanceof FormattedDate) {
if (transformedContent instanceof FormattedDate) {
return compareTo((FormattedDate) transformedContent);
}
error = true;
return 0;
}
final String valueAsString = conditionValue.toString();
final String text = transformedContent.toString();
if (isEqualityCondition()) {
return stringMatchingStrategy.matches(valueAsString, text, false, matchCase) ? 0 : -1;
} else {
return matchCase ? text.compareTo(valueAsString) : text.compareToIgnoreCase(valueAsString);
}
}
use of org.freeplane.features.format.FormattedDate in project freeplane by freeplane.
the class FrameController method getTextDateTimeEditor.
public static ComboBoxEditor getTextDateTimeEditor() {
final ContainerComboBoxEditor editor = new ContainerComboBoxEditor();
final NamedObject keyText = new NamedObject("text", "1Ab");
final BasicComboBoxEditor textEditor = new FixedBasicComboBoxEditor() {
private Object oldItem;
@Override
public void setItem(Object object) {
oldItem = object;
if (object instanceof FormattedDate)
super.setItem("");
else
super.setItem(object);
}
@Override
public Object getItem() {
final Object item = super.getItem();
final Object oldItem = this.oldItem;
this.oldItem = null;
if (item != null && oldItem != null && item.toString().equals(oldItem.toString()))
return oldItem;
if (ResourceController.getResourceController().getBooleanProperty("parse_data") && item instanceof String) {
final Object scannedObject = ScannerController.getController().parse((String) item);
return scannedObject;
}
return item;
}
};
editor.put(keyText, textEditor);
final NamedObject keyDate = new NamedObject("date", "");
keyDate.setIcon(dateIcon);
final TimeComboBoxEditor dateComboBoxEditor = new TimeComboBoxEditor(false) {
@Override
public void setItem(Object object) {
if (object instanceof FormattedDate && !((FormattedDate) object).containsTime())
super.setItem(object);
else
super.setItem(null);
}
};
dateComboBoxEditor.setItem();
editor.put(keyDate, dateComboBoxEditor);
final NamedObject keyDateTime = new NamedObject("date_time", "");
keyDateTime.setIcon(dateTimeIcon);
final TimeComboBoxEditor dateTimeComboBoxEditor = new TimeComboBoxEditor(true) {
@Override
public void setItem(Object object) {
if (object instanceof FormattedDate && ((FormattedDate) object).containsTime())
super.setItem(object);
else
super.setItem(null);
}
};
dateTimeComboBoxEditor.setItem();
editor.put(keyDateTime, dateTimeComboBoxEditor);
return editor;
}
use of org.freeplane.features.format.FormattedDate in project freeplane by freeplane.
the class ReminderConditionController method loadCondition.
public ASelectableCondition loadCondition(final XMLElement element) {
try {
if (element.getName().equalsIgnoreCase(ReminderConditionLater.NAME)) {
return new ReminderConditionLater();
}
if (element.getName().equalsIgnoreCase(ReminderConditionExecuted.NAME)) {
return new ReminderConditionExecuted();
}
if (element.getName().equalsIgnoreCase(ReminderConditionBefore.NAME)) {
final String dateString = element.getAttribute(ReminderCondition.DATE, null);
final FormattedDate date = FormattedDate.createDefaultFormattedDate(Long.parseLong(dateString), IFormattedObject.TYPE_DATETIME);
return new ReminderConditionBefore(date);
}
if (element.getName().equalsIgnoreCase(ReminderConditionAfter.NAME)) {
final String dateString = element.getAttribute(ReminderCondition.DATE, null);
final FormattedDate date = FormattedDate.createDefaultFormattedDate(Long.parseLong(dateString), IFormattedObject.TYPE_DATETIME);
return new ReminderConditionAfter(date);
}
} catch (final Exception e) {
LogUtils.severe(e);
}
return null;
}
use of org.freeplane.features.format.FormattedDate in project freeplane by freeplane.
the class TimeManagement method insertTime.
void insertTime(final Dialog dialog, final JButton appendButton) {
FormattedDate date = getCalendarDate();
final String dateAsString = dateFormat.formatObject(date).toString();
final Window parentWindow;
if (dialog != null) {
parentWindow = (Window) dialog.getParent();
} else {
parentWindow = SwingUtilities.getWindowAncestor(appendButton);
}
final Component mostRecentFocusOwner = parentWindow.getMostRecentFocusOwner();
if (mostRecentFocusOwner instanceof JTextComponent && !(mostRecentFocusOwner.getClass().getName().contains("JSpinField"))) {
final JTextComponent textComponent = (JTextComponent) mostRecentFocusOwner;
textComponent.replaceSelection(dateAsString);
return;
}
if (mostRecentFocusOwner instanceof JTable) {
JTable table = (JTable) mostRecentFocusOwner;
final int[] selectedRows = table.getSelectedRows();
final int[] selectedColumns = table.getSelectedColumns();
for (int r : selectedRows) for (int c : selectedColumns) table.setValueAt(date, r, c);
} else {
ModeController mController = Controller.getCurrentModeController();
for (final NodeModel node : mController.getMapController().getSelectedNodes()) {
final MTextController textController = (MTextController) TextController.getController();
textController.setNodeObject(node, date);
}
}
}
use of org.freeplane.features.format.FormattedDate 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;
}
Aggregations