/*
 * @(#)BringToFrontAction.java
 *
 * Copyright (c) 2003-2008 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 java.util.*;
import javax.swing.undo.*;
import org.jhotdraw.draw.*;
import org.jhotdraw.util.ResourceBundleUtil;

/**
 * ToFrontAction.
 *
 * @author  Werner Randelshofer
 * @version $Id: BringToFrontAction.java 717 2010-11-21 12:30:57Z rawcoder $
 */
public class BringToFrontAction extends AbstractSelectedAction {

    public final static String ID = "edit.bringToFront";

    /** Creates a new instance. */
    public BringToFrontAction(DrawingEditor editor) {
        super(editor);
        ResourceBundleUtil labels =
                ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels");
        labels.configureAction(this, ID);
        updateEnabledState();
    }

    @Override
    public void actionPerformed(java.awt.event.ActionEvent e) {
        final DrawingView view = getView();
        final LinkedList
figures = new LinkedList
(view.getSelectedFigures()); bringToFront(view, figures); fireUndoableEditHappened(new AbstractUndoableEdit() { @Override public String getPresentationName() { ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); return labels.getTextProperty(ID); } @Override public void redo() throws CannotRedoException { super.redo(); BringToFrontAction.bringToFront(view, figures); } @Override public void undo() throws CannotUndoException { super.undo(); SendToBackAction.sendToBack(view, figures); } }); } public static void bringToFront(DrawingView view, Collection
figures) { Drawing drawing = view.getDrawing(); Iterator i = drawing.sort(figures).iterator(); while (i.hasNext()) { Figure figure = (Figure) i.next(); drawing.bringToFront(figure); } } }

Ads help maintain this website.