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());
}
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations