mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Added mini toolbar in the top-right corner of the screen with transform
actions exposed for quick access
This commit is contained in:
@@ -66,7 +66,9 @@ public interface ISwingUI extends IView {
|
||||
* @param action {@link Action} to inser
|
||||
* @param menuName name of the menu to insert into
|
||||
*/
|
||||
void injectMenuAction(Action action, String menuName);
|
||||
void injectMenuAction(Action action, String menuName);
|
||||
|
||||
void injectMenuComponent(JComponent component);
|
||||
|
||||
/**
|
||||
* Injects a custom submenu into application's main menu. If the specified menu does not exist it
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.ButtonGroup;
|
||||
@@ -55,7 +55,7 @@ import javax.swing.SwingWorker;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.event.MenuEvent;
|
||||
import javax.swing.event.MenuListener;
|
||||
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.BadPositionException;
|
||||
@@ -69,6 +69,7 @@ import org.diylc.images.IconLoader;
|
||||
import org.diylc.presenter.Presenter;
|
||||
import org.diylc.swing.IDynamicSubmenuHandler;
|
||||
import org.diylc.swing.ISwingUI;
|
||||
import org.diylc.swing.gui.actionBar.ActionBarPlugin;
|
||||
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
||||
import org.diylc.swing.plugins.autosave.AutoSavePlugin;
|
||||
import org.diylc.swing.plugins.canvas.CanvasPlugin;
|
||||
@@ -125,7 +126,8 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
presenter.installPlugin(new ConfigPlugin(this));
|
||||
presenter.installPlugin(new LayersMenuPlugin(this));
|
||||
presenter.installPlugin(new CloudPlugIn(this));
|
||||
presenter.installPlugin(new HelpMenuPlugin(this));
|
||||
presenter.installPlugin(new HelpMenuPlugin(this));
|
||||
presenter.installPlugin(new ActionBarPlugin(this));
|
||||
|
||||
presenter.installPlugin(new StatusBar(this));
|
||||
|
||||
@@ -313,7 +315,7 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
menu.add(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectSubmenu(String name, Icon icon, String parentMenuName) {
|
||||
@@ -323,6 +325,11 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
submenu.setIcon(icon);
|
||||
menu.add(submenu);
|
||||
menuMap.put(name, submenu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectMenuComponent(JComponent component) {
|
||||
getMainMenuBar().add(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
*
|
||||
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
*
|
||||
* This file is part of DIYLC.
|
||||
*
|
||||
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.diylc.swing.gui.actionBar;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.swing.ActionFactory;
|
||||
import org.diylc.swing.ISwingUI;
|
||||
|
||||
/**
|
||||
* Mini toolbar with common actions
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class ActionBarPlugin implements IPlugIn {
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
private ISwingUI swingUI;
|
||||
|
||||
private JPanel actionPanel;
|
||||
private MiniToolbar miniToolbar;
|
||||
|
||||
public ActionBarPlugin(ISwingUI swingUI) {
|
||||
this.swingUI = swingUI;
|
||||
}
|
||||
|
||||
public JPanel getActionPanel() {
|
||||
if (actionPanel == null) {
|
||||
actionPanel = new JPanel();
|
||||
actionPanel.setOpaque(false);
|
||||
actionPanel.setLayout(new BorderLayout());
|
||||
actionPanel.add(getMiniToolbar(), BorderLayout.EAST);
|
||||
actionPanel.setBorder(BorderFactory.createEmptyBorder());
|
||||
}
|
||||
return actionPanel;
|
||||
}
|
||||
|
||||
public MiniToolbar getMiniToolbar() {
|
||||
if (miniToolbar == null) {
|
||||
miniToolbar = new MiniToolbar();
|
||||
miniToolbar.add(ActionFactory.getInstance().createRotateSelectionAction(plugInPort, 1));
|
||||
miniToolbar.add(ActionFactory.getInstance().createRotateSelectionAction(plugInPort, -1));
|
||||
miniToolbar.addSpacer();
|
||||
miniToolbar.add(ActionFactory.getInstance().createMirrorSelectionAction(plugInPort, IComponentTransformer.HORIZONTAL));
|
||||
miniToolbar.add(ActionFactory.getInstance().createMirrorSelectionAction(plugInPort, IComponentTransformer.VERTICAL));
|
||||
miniToolbar.addSpacer();
|
||||
miniToolbar.add(ActionFactory.getInstance().createNudgeAction(plugInPort));
|
||||
miniToolbar.addSpacer();
|
||||
miniToolbar.add(ActionFactory.getInstance().createSendToBackAction(plugInPort));
|
||||
miniToolbar.add(ActionFactory.getInstance().createBringToFrontAction(plugInPort));
|
||||
miniToolbar.addSpacer();
|
||||
miniToolbar.add(ActionFactory.getInstance().createGroupAction(plugInPort));
|
||||
miniToolbar.add(ActionFactory.getInstance().createUngroupAction(plugInPort));
|
||||
}
|
||||
return miniToolbar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(IPlugInPort plugInPort) {
|
||||
this.plugInPort = plugInPort;
|
||||
swingUI.injectMenuComponent(getActionPanel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||
return EnumSet.of(EventType.SELECTION_CHANGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processMessage(EventType eventType, Object... params) {
|
||||
if (eventType != EventType.SELECTION_CHANGED)
|
||||
return;
|
||||
boolean enabled = !plugInPort.getSelectedComponents().isEmpty();
|
||||
getMiniToolbar().setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.swing.gui.actionBar;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSeparator;
|
||||
|
||||
public class MiniToolbar extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MiniToolbar() {
|
||||
setOpaque(false);
|
||||
setBorder(BorderFactory.createEmptyBorder());
|
||||
}
|
||||
|
||||
public void add(final Action action) {
|
||||
final JLabel l = new JLabel();
|
||||
l.setIcon((Icon) action.getValue(AbstractAction.SMALL_ICON));
|
||||
l.setToolTipText((String) action.getValue(AbstractAction.NAME));
|
||||
l.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
l.addMouseListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
action.actionPerformed(null);
|
||||
}
|
||||
});
|
||||
add(l);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
for (Component c : getComponents())
|
||||
c.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public void addSpacer() {
|
||||
JSeparator l = new JSeparator();
|
||||
// l.setBorder(BorderFactory.createMatteBorder(0, 1, 0, 0, Color.black));
|
||||
add(l);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user