[Home] DMelt member access. Java source code: org.jhotdraw.draw.action.PickAttributesAction
/*
* @(#)PickAttributesAction.java
*
* Copyright (c) 1996-2010 by the original authors of JHotDraw and all its
* contributors. All rights reserved.
*
* You may not use, copy or modify this file, except in compliance with the
* license agreement you entered into with the copyright holders. For details
* see accompanying license terms.
*/
package org.jhotdraw.draw.action;
import org.jhotdraw.draw.event.FigureSelectionEvent;
import java.util.*;
import org.jhotdraw.draw.*;
import org.jhotdraw.util.ResourceBundleUtil;
import static org.jhotdraw.draw.AttributeKeys.*;
/**
* PickAttributesAction.
*
* @author Werner Randelshofer
* @version $Id: PickAttributesAction.java 717 2010-11-21 12:30:57Z rawcoder $
*/
public class PickAttributesAction extends AbstractSelectedAction {
private Set excludedAttributes = new HashSet(
Arrays.asList(new AttributeKey[]{TRANSFORM, TEXT}));
/** Creates a new instance. */
public PickAttributesAction(DrawingEditor editor) {
super(editor);
ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels");
labels.configureAction(this, "edit.pickAttributes");
updateEnabledState();
}
/**
* Set of attributes that is excluded when applying default attributes.
* By default, the TRANSFORM attribute is excluded.
*/
public void setExcludedAttributes(Set a) {
this.excludedAttributes = a;
}
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
pickAttributes();
}
@SuppressWarnings("unchecked")
public void pickAttributes() {
DrawingEditor editor = getEditor();
Collection selection = getView().getSelectedFigures();
if (selection.size() > 0) {
Figure figure = (Figure) selection.iterator().next();
for (Map.Entry entry : figure.getAttributes().entrySet()) {
if (!excludedAttributes.contains(entry.getKey())) {
editor.setDefaultAttribute(entry.getKey(), entry.getValue());
}
}
}
}
public void selectionChanged(FigureSelectionEvent evt) {
setEnabled(getView().getSelectionCount() == 1);
}
}