Search in sources :

Example 1 with FormattedDate

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);
    }
}
Also used : FormattedDate(org.freeplane.features.format.FormattedDate) FormattedNumber(org.freeplane.features.format.FormattedNumber) FormattedNumber(org.freeplane.features.format.FormattedNumber)

Example 2 with FormattedDate

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;
}
Also used : BasicComboBoxEditor(javax.swing.plaf.basic.BasicComboBoxEditor) FixedBasicComboBoxEditor(org.freeplane.core.ui.FixedBasicComboBoxEditor) FormattedDate(org.freeplane.features.format.FormattedDate) StyleNamedObject(org.freeplane.features.styles.StyleNamedObject) NamedObject(org.freeplane.core.resources.NamedObject) FixedBasicComboBoxEditor(org.freeplane.core.ui.FixedBasicComboBoxEditor) TimeComboBoxEditor(org.freeplane.features.time.TimeComboBoxEditor) ContainerComboBoxEditor(org.freeplane.core.ui.components.ContainerComboBoxEditor) StyleNamedObject(org.freeplane.features.styles.StyleNamedObject) NamedObject(org.freeplane.core.resources.NamedObject) FormattedObject(org.freeplane.features.format.FormattedObject)

Example 3 with FormattedDate

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;
}
Also used : FormattedDate(org.freeplane.features.format.FormattedDate)

Example 4 with FormattedDate

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);
        }
    }
}
Also used : Window(java.awt.Window) FormattedDate(org.freeplane.features.format.FormattedDate) NodeModel(org.freeplane.features.map.NodeModel) JTable(javax.swing.JTable) JTextComponent(javax.swing.text.JTextComponent) ModeController(org.freeplane.features.mode.ModeController) MTextController(org.freeplane.features.text.mindmapmode.MTextController) Component(java.awt.Component) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent)

Example 5 with FormattedDate

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;
}
Also used : ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) PatternFormat(org.freeplane.features.format.PatternFormat) ModeController(org.freeplane.features.mode.ModeController) FormattedDate(org.freeplane.features.format.FormattedDate) NodeModel(org.freeplane.features.map.NodeModel) JTable(javax.swing.JTable) ItemListener(java.awt.event.ItemListener) MTextController(org.freeplane.features.text.mindmapmode.MTextController) Component(java.awt.Component) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent) Vector(java.util.Vector)

Aggregations

FormattedDate (org.freeplane.features.format.FormattedDate)9 Component (java.awt.Component)2 JComponent (javax.swing.JComponent)2 JTable (javax.swing.JTable)2 JTextComponent (javax.swing.text.JTextComponent)2 FormattedObject (org.freeplane.features.format.FormattedObject)2 NodeModel (org.freeplane.features.map.NodeModel)2 ModeController (org.freeplane.features.mode.ModeController)2 MTextController (org.freeplane.features.text.mindmapmode.MTextController)2 Window (java.awt.Window)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 URI (java.net.URI)1 Date (java.util.Date)1 Vector (java.util.Vector)1 Icon (javax.swing.Icon)1 JComboBox (javax.swing.JComboBox)1 BasicComboBoxEditor (javax.swing.plaf.basic.BasicComboBoxEditor)1