Search in sources :

Example 1 with IAttributeTableModel

use of org.freeplane.features.attribute.IAttributeTableModel in project freeplane by freeplane.

the class AttributePopupMenu method make.

/**
 */
private void make() {
    final String attributeViewType = table.getAttributeView().getViewType();
    final IAttributeTableModel model = table.getAttributeTableModel();
    final int rowCount = model.getRowCount();
    add(getOptimalWidth());
    if (col == 1) {
        add(getInsertLink());
        add(getInsertFileLink());
        add(getInsertNodeLink());
        final LinkController linkController = LinkController.getController();
        if (linkController instanceof MLinkController && ((MLinkController) linkController).isAnchored())
            add(getInsertAnchoredLink());
    }
    if (attributeViewType.equals(AttributeTableLayoutModel.SHOW_ALL)) {
        add(getInsert());
        if (row != -1) {
            add(getDelete());
            if (row != 0) {
                add(getUp());
            }
            if (row != rowCount - 1) {
                add(getDown());
            }
        }
    }
}
Also used : MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) LinkController(org.freeplane.features.link.LinkController) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) IAttributeTableModel(org.freeplane.features.attribute.IAttributeTableModel) Point(java.awt.Point)

Example 2 with IAttributeTableModel

use of org.freeplane.features.attribute.IAttributeTableModel in project freeplane by freeplane.

the class AttributeTableCellRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
    final Component rendererComponent = super.getTableCellRendererComponent(table, value, hasFocus, isSelected, row, column);
    final AttributeTable attributeTable = (AttributeTable) table;
    zoom = attributeTable.getZoom();
    final IAttributeTableModel attributeTableModel = (IAttributeTableModel) table.getModel();
    final String originalText = value == null ? null : value.toString();
    String text = originalText;
    Icon icon;
    if (column == 1 && value != null) {
        try {
            // evaluate values only
            final TextController textController = TextController.getController();
            Object transformedObject = textController.getTransformedObject(value, attributeTableModel.getNode(), null);
            text = transformedObject.toString();
            if (transformedObject instanceof HighlightedTransformedObject && TextController.isMarkTransformedTextSet()) {
                setBorder(BorderFactory.createLineBorder(Color.GREEN));
            }
        } catch (Exception e) {
            text = TextUtils.format("MainView.errorUpdateText", originalText, e.getLocalizedMessage());
            setBorder(BorderFactory.createLineBorder(Color.RED));
        }
        if (value instanceof URI) {
            icon = ((AttributeTable) table).getLinkIcon((URI) value);
        } else {
            icon = null;
        }
    } else {
        icon = null;
    }
    final Icon scaledIcon;
    final IconFactory iconFactory = IconFactory.getInstance();
    if (icon != null && iconFactory.canScaleIcon(icon)) {
        final int fontSize = getFont().getSize();
        scaledIcon = iconFactory.getScaledIcon(icon, new Quantity<LengthUnits>(fontSize, LengthUnits.px));
    } else
        scaledIcon = icon;
    if (scaledIcon != getIcon()) {
        setIcon(scaledIcon);
    }
    setText(text);
    if (text != originalText) {
        final String toolTip = HtmlUtils.isHtmlNode(originalText) ? text : HtmlUtils.plainToHTML(originalText);
        setToolTipText(toolTip);
    } else {
        final int prefWidth = getPreferredSize().width;
        final int width = table.getColumnModel().getColumn(column).getWidth();
        if (prefWidth > width) {
            final String toolTip = HtmlUtils.isHtmlNode(text) ? text : HtmlUtils.plainToHTML(text);
            setToolTipText(toolTip);
        } else {
            setToolTipText(null);
        }
    }
    setOpaque(hasFocus);
    return rendererComponent;
}
Also used : TextController(org.freeplane.features.text.TextController) Quantity(org.freeplane.core.util.Quantity) URI(java.net.URI) HighlightedTransformedObject(org.freeplane.features.text.HighlightedTransformedObject) IAttributeTableModel(org.freeplane.features.attribute.IAttributeTableModel) HighlightedTransformedObject(org.freeplane.features.text.HighlightedTransformedObject) Icon(javax.swing.Icon) Component(java.awt.Component) IconFactory(org.freeplane.features.icon.factory.IconFactory)

Example 3 with IAttributeTableModel

use of org.freeplane.features.attribute.IAttributeTableModel in project freeplane by freeplane.

the class AttributePopupMenu method getInsertAnchoredLink.

private JMenuItem getInsertAnchoredLink() {
    if (insertAnchoredLink == null) {
        insertAnchoredLink = new JMenuItem(TextUtils.getText("MakeLinkToAnchorAction.text"));
        insertAnchoredLink.addActionListener(new ActionListener() {

            public void actionPerformed(final ActionEvent e) {
                final AttributeTable table = AttributePopupMenu.this.table;
                final Object oldValue = table.getValueAt(row, col);
                final LinkController linkController = LinkController.getController();
                if (linkController instanceof MLinkController) {
                    final MLinkController mLinkController = (MLinkController) linkController;
                    if (mLinkController.isAnchored()) {
                        try {
                            final String anchorIDforNode = mLinkController.getAnchorIDforNode(((IAttributeTableModel) table.getModel()).getNode());
                            if (anchorIDforNode != null) {
                                URI link = LinkController.createURI(anchorIDforNode);
                                if (!oldValue.equals(link))
                                    table.setValueAt(link, row, col);
                            }
                        } catch (URISyntaxException e1) {
                        }
                    }
                }
            }
        });
    }
    return insertAnchoredLink;
}
Also used : MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) LinkController(org.freeplane.features.link.LinkController) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) IAttributeTableModel(org.freeplane.features.attribute.IAttributeTableModel) URISyntaxException(java.net.URISyntaxException) JMenuItem(javax.swing.JMenuItem) URI(java.net.URI)

Example 4 with IAttributeTableModel

use of org.freeplane.features.attribute.IAttributeTableModel in project freeplane by freeplane.

the class AttributeTable method getLinkIcon.

Icon getLinkIcon(final URI uri) {
    NodeModel nodeModel = ((IAttributeTableModel) getModel()).getNode();
    final Icon linkIcon = Controller.getCurrentModeController().getExtension(LinkController.class).getLinkIcon(uri, nodeModel);
    return linkIcon;
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) LinkController(org.freeplane.features.link.LinkController) IAttributeTableModel(org.freeplane.features.attribute.IAttributeTableModel) Icon(javax.swing.Icon)

Example 5 with IAttributeTableModel

use of org.freeplane.features.attribute.IAttributeTableModel in project freeplane by freeplane.

the class AttributeTable method getCellEditor.

@SuppressWarnings("serial")
public TableCellEditor getCellEditor(final int row, final int col, EventObject e) {
    if (dce != null) {
        dce.stopCellEditing();
    }
    if (col == 1) {
        final MTextController textController = (MTextController) TextController.getController();
        if (e instanceof KeyEvent) {
            final KeyEvent kev = (KeyEvent) e;
            textController.getEventQueue().setFirstEvent(kev);
        }
        final IAttributeTableModel model = (IAttributeTableModel) getModel();
        final String text = getValueForEdit(row, col);
        final DialogTableCellEditor dialogTableCellEditor = new DialogTableCellEditor();
        EditNodeBase base = textController.getEditNodeBase(model.getNode(), text, dialogTableCellEditor.getEditControl(), false);
        if (base != null) {
            dialogTableCellEditor.setEditBase(base);
            return dialogTableCellEditor;
        }
    }
    final JComboBox comboBox;
    if (dce == null) {
        comboBox = new JComboBoxWithBorder() {

            // Workaround for bug introduced in Java 8: they use wrong component in DefaultCellEditor.EditorDelegate
            @Override
            public void actionPerformed(ActionEvent e) {
                if (e != null && e.getSource() == dce) {
                    super.actionPerformed(new ActionEvent(getEditor(), e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers()));
                } else
                    super.actionPerformed(e);
            }
        };
        comboBox.addFocusListener(AttributeTable.focusListener);
        comboBox.getEditor().getEditorComponent().addFocusListener(AttributeTable.focusListener);
        comboBox.setRenderer(new TypedListCellRenderer());
        dce = new DefaultCellEditor(comboBox) {

            public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) {
                return super.getTableCellEditorComponent(table, ((AttributeTable) table).getValueForEdit(row, col), isSelected, row, col);
            }
        };
        dce.setClickCountToStart(CLICK_COUNT_TO_START);
    }
    return dce;
}
Also used : JComboBox(javax.swing.JComboBox) EditNodeBase(org.freeplane.features.text.mindmapmode.EditNodeBase) ActionEvent(java.awt.event.ActionEvent) DefaultCellEditor(javax.swing.DefaultCellEditor) KeyEvent(java.awt.event.KeyEvent) TypedListCellRenderer(org.freeplane.core.ui.components.TypedListCellRenderer) JTable(javax.swing.JTable) IAttributeTableModel(org.freeplane.features.attribute.IAttributeTableModel) EventObject(java.util.EventObject) IFormattedObject(org.freeplane.features.format.IFormattedObject) FormattedObject(org.freeplane.features.format.FormattedObject) MTextController(org.freeplane.features.text.mindmapmode.MTextController) JComboBoxWithBorder(org.freeplane.core.ui.components.JComboBoxWithBorder) EditedComponent(org.freeplane.features.text.mindmapmode.EditNodeBase.EditedComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Aggregations

IAttributeTableModel (org.freeplane.features.attribute.IAttributeTableModel)5 LinkController (org.freeplane.features.link.LinkController)3 Component (java.awt.Component)2 ActionEvent (java.awt.event.ActionEvent)2 URI (java.net.URI)2 Icon (javax.swing.Icon)2 MLinkController (org.freeplane.features.link.mindmapmode.MLinkController)2 Point (java.awt.Point)1 ActionListener (java.awt.event.ActionListener)1 KeyEvent (java.awt.event.KeyEvent)1 URISyntaxException (java.net.URISyntaxException)1 EventObject (java.util.EventObject)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 JComboBox (javax.swing.JComboBox)1 JComponent (javax.swing.JComponent)1 JMenuItem (javax.swing.JMenuItem)1 JTable (javax.swing.JTable)1 JComboBoxWithBorder (org.freeplane.core.ui.components.JComboBoxWithBorder)1 TypedListCellRenderer (org.freeplane.core.ui.components.TypedListCellRenderer)1 Quantity (org.freeplane.core.util.Quantity)1