diff --git a/diylc/diylc-swing/src/org/diylc/swing/ISwingUI.java b/diylc/diylc-swing/src/org/diylc/swing/ISwingUI.java index 4ef3d404..f68dc2d9 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/ISwingUI.java +++ b/diylc/diylc-swing/src/org/diylc/swing/ISwingUI.java @@ -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 diff --git a/diylc/diylc-swing/src/org/diylc/swing/gui/MainFrame.java b/diylc/diylc-swing/src/org/diylc/swing/gui/MainFrame.java index e8175fd0..1fa6ecaa 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/gui/MainFrame.java +++ b/diylc/diylc-swing/src/org/diylc/swing/gui/MainFrame.java @@ -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 diff --git a/diylc/diylc-swing/src/org/diylc/swing/gui/actionBar/ActionBarPlugin.java b/diylc/diylc-swing/src/org/diylc/swing/gui/actionBar/ActionBarPlugin.java new file mode 100644 index 00000000..0daab3e0 --- /dev/null +++ b/diylc/diylc-swing/src/org/diylc/swing/gui/actionBar/ActionBarPlugin.java @@ -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 + * . + */ +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 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); + } +} diff --git a/diylc/diylc-swing/src/org/diylc/swing/gui/actionBar/MiniToolbar.java b/diylc/diylc-swing/src/org/diylc/swing/gui/actionBar/MiniToolbar.java new file mode 100644 index 00000000..b3b02b8b --- /dev/null +++ b/diylc/diylc-swing/src/org/diylc/swing/gui/actionBar/MiniToolbar.java @@ -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 . + +*/ +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); + } +} diff --git a/diylc/diylc-swing/update.xml b/diylc/diylc-swing/update.xml index ae15ccfc..8adc3720 100644 --- a/diylc/diylc-swing/update.xml +++ b/diylc/diylc-swing/update.xml @@ -2634,6 +2634,10 @@ NEW_FEATURE Added an optional third control point to leaded components and some schematic symbols that can be used to set component label position. This feature is off by default to keep things backwards compatible and is driven by "Movable Label" property + + NEW_FEATURE + Added mini toolbar in the top-right corner of the screen with transform actions exposed for quick access + NEW_FEATURE Auto-save plugin now works by periodically creating project backups in user\.diylc\autoSave directory and maintains file history, keeping the last X versions of the file. Maximum size for all backups combined is configurable and pre-set to 64MB @@ -2668,7 +2672,7 @@ IMPROVEMENT - Merge switch configurations that yield with the same effective wiring for "Analyze Guitar Wirings" module, for more compact report + Merge switch configurations that yield with the same effective wiring for "Analyze Guitar Wirings" module, for a more compact report IMPROVEMENT