blob: 2654f2b86029b33906b5f02b56e6635b46b560bf [file] [log] [blame]
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.uiDesigner.actions;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.uiDesigner.radComponents.RadComponent;
import com.intellij.uiDesigner.radComponents.RadContainer;
import com.intellij.uiDesigner.designSurface.GuiEditor;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* @author yole
*/
public class PackAction extends AbstractGuiEditorAction {
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
RadContainer container = getContainerToPack(selection);
if (container != null) {
container.getDelegee().setSize(container.getMinimumSize());
container.getDelegee().revalidate();
}
}
protected void update(@NotNull GuiEditor editor, final ArrayList<RadComponent> selection, final AnActionEvent e) {
e.getPresentation().setEnabled(getContainerToPack(selection) != null);
}
private static RadContainer getContainerToPack(final List<RadComponent> selection) {
if (selection.size() != 1 || !(selection.get(0) instanceof RadContainer)) {
return null;
}
RadContainer container = (RadContainer)selection.get(0);
if (!container.getParent().isXY()) {
return null;
}
return container;
}
}