Ctrl + click doesn't add components to the selection in MacOS

This commit is contained in:
Branislav Stojkovic
2018-12-25 23:40:05 +01:00
parent e9615d4d64
commit ce0ac2460c
7 changed files with 197 additions and 203 deletions
Binary file not shown.
Binary file not shown.
@@ -47,7 +47,6 @@ import javax.swing.SwingUtilities;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.IConfigListener;
import org.diylc.appframework.miscutils.Utils;
import org.diylc.common.BadPositionException;
import org.diylc.common.EventType;
import org.diylc.common.IComponentTransformer;
@@ -136,23 +135,31 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
if (canvasPanel == null) {
canvasPanel = new CanvasPanel(plugInPort);
canvasPanel.addMouseListener(new MouseAdapter() {
private MouseEvent pressedEvent;
@Override
public void mouseClicked(MouseEvent e) {
plugInPort.mouseClicked(e.getPoint(), e.getButton(), e.isControlDown(), e.isShiftDown(), e.isAltDown(),
e.getClickCount());
}
@Override
public void mousePressed(MouseEvent e) {
LOG.info("Pressed: " + e.isPopupTrigger());
canvasPanel.requestFocus();
mouseReleased(e);
pressedEvent = e;
}
@Override
public void mouseReleased(final MouseEvent e) {
// Invoke the rest of the code later so we get the chance to
// process selection messages.
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (plugInPort.getNewComponentTypeSlot() == null && e.isPopupTrigger()) {
if (plugInPort.getNewComponentTypeSlot() == null && (e.isPopupTrigger() || pressedEvent.isPopupTrigger())) {
// Enable actions.
boolean enabled = !plugInPort.getSelectedComponents().isEmpty();
getCutAction().setEnabled(enabled);
@@ -192,8 +199,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
@Override
public void keyPressed(KeyEvent e) {
if (plugInPort.keyPressed(e.getKeyCode(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(),
e.isShiftDown(), e.isAltDown())) {
if (plugInPort.keyPressed(e.getKeyCode(), e.isControlDown(), e.isShiftDown(), e.isAltDown())) {
e.consume();
}
}
@@ -204,17 +210,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
@Override
public void mouseMoved(MouseEvent e) {
canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint()));
plugInPort.mouseMoved(e.getPoint(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(),
e.isAltDown());
}
});
canvasPanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
plugInPort.mouseClicked(e.getPoint(), e.getButton(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(),
e.isShiftDown(), e.isAltDown(), e.getClickCount());
plugInPort.mouseMoved(e.getPoint(), e.isControlDown(), e.isShiftDown(), e.isAltDown());
}
});
}
@@ -250,7 +246,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
boolean wheelZoom = ConfigurationManager.getInstance().readBoolean(IPlugInPort.WHEEL_ZOOM_KEY, false);
if (wheelZoom || (Utils.isMac() ? e.isMetaDown() : e.isControlDown())) {
if (wheelZoom || e.isControlDown()) {
Point mousePos = getCanvasPanel().getMousePosition(true);
@@ -271,10 +267,10 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
}
plugInPort.setZoomLevel(newZoom = availableZoomLevels[i]);
}
Rectangle2D selectionBounds = plugInPort.getSelectionBounds(true);
Rectangle visibleRect = scrollPane.getVisibleRect();
JScrollBar horizontal = scrollPane.getHorizontalScrollBar();
JScrollBar vertical = scrollPane.getVerticalScrollBar();
@@ -283,8 +279,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
Point desiredPos =
new Point((int) (1d * mousePos.x / oldZoom * newZoom), (int) (1d * mousePos.y / oldZoom * newZoom));
int dx = desiredPos.x - mousePos.x;
int dy = desiredPos.y - mousePos.y;
horizontal.setValue(horizontal.getValue() + dx);
int dy = desiredPos.y - mousePos.y;
horizontal.setValue(horizontal.getValue() + dx);
vertical.setValue(vertical.getValue() + dy);
} else {
// center to selection
@@ -1,184 +1,178 @@
/*
*
* 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.plugins.toolbox;
DIY Layout Creator (DIYLC).
Copyright (c) 2009-2018 held jointly by the individual authors.
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
This file is part of DIYLC.
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
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.
import org.diylc.common.ComponentType;
import org.diylc.common.IPlugInPort;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Template;
import org.diylc.images.IconLoader;
import org.diylc.swingframework.openide.DropDownButtonFactory;
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.
/**
* Factory that creates {@link JButton}s which display component type icons and instantiates the
* component when clicked.
*
* @author Branislav Stojkovic
*/
public class ComponentButtonFactory {
You should have received a copy of the GNU General Public License
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
public static int MARGIN = 3;
*/
package org.diylc.swing.plugins.toolbox;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import org.diylc.appframework.miscutils.Utils;
import org.diylc.common.ComponentType;
import org.diylc.common.IPlugInPort;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Template;
import org.diylc.images.IconLoader;
import org.diylc.swingframework.openide.DropDownButtonFactory;
/**
* Factory that creates {@link JButton}s which display component type icons and instantiates the
* component when clicked.
*
* @author Branislav Stojkovic
*/
public class ComponentButtonFactory {
public static int MARGIN = 3;
public static JButton create(final IPlugInPort plugInPort, final ComponentType componentType, final JPopupMenu menu) {
JButton button = DropDownButtonFactory.createDropDownButton(componentType.getIcon(), menu);
button.setBorder(BorderFactory.createEmptyBorder(MARGIN + 1, MARGIN + 1, MARGIN, MARGIN));
button.setToolTipText("<html><b>" + componentType.getName() + "</b><br>" + componentType.getDescription()
+ "<br>Author: " + componentType.getAuthor() + "<br><br>Right click to select all components of this type"
+ "</html>");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
plugInPort.setNewComponentTypeSlot(componentType, null);
}
});
button.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
List<IDIYComponent<?>> components = plugInPort.getCurrentProject().getComponents();
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>();
for (IDIYComponent<?> component : components) {
if (componentType.getInstanceClass().equals(component.getClass())) {
newSelection.add(component);
}
}
// Ctrl appends selection
if (Utils.isMac() ? e.isMetaDown() : e.isControlDown()) {
newSelection.addAll(plugInPort.getSelectedComponents());
}
plugInPort.updateSelection(newSelection);
plugInPort.setNewComponentTypeSlot(null, null);
plugInPort.refresh();
}
}
});
button.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
plugInPort.keyPressed(e.getKeyCode(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(),
e.isAltDown());
}
});
return button;
}
public static JMenuItem createTemplateItem(final IPlugInPort plugInPort, final Template template,
final ComponentType componentType) {
final JMenuItem item = new JMenuItem(template.getName()) {
private static final long serialVersionUID = 1L;
// Customize item size to fit the delete button
public java.awt.Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
return new Dimension(d.width + 32, d.height);
}
};
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
plugInPort.setNewComponentTypeSlot(componentType, template);
}
});
JLabel label = new JLabel(template.isDefaultFlag() ? IconLoader.PinGreen.getIcon() : IconLoader.PinGrey.getIcon());
label.setToolTipText(template.isDefaultFlag() ? "Remove default variant" : "Set default variant");
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// Hide the menu
Container c = item.getParent();
if (c != null && c instanceof JPopupMenu) {
JPopupMenu m = (JPopupMenu) c;
m.setVisible(false);
}
plugInPort.setTemplateDefault(componentType.getCategory(), componentType.getName(), template.getName(),
!template.isDefaultFlag());
e.consume();
}
});
Border margin = new EmptyBorder(4, 0, 0, 0);
label.setBorder(margin);
item.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
item.add(label);
label = new JLabel(IconLoader.Garbage.getIcon());
label.setToolTipText("Delete variant");
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// Hide the menu
Container c = item.getParent();
if (c != null && c instanceof JPopupMenu) {
JPopupMenu m = (JPopupMenu) c;
m.setVisible(false);
}
int result =
JOptionPane.showConfirmDialog(SwingUtilities.getRoot(item), "Are you sure you want to delete variant \""
+ template.getName() + "\"", "Delete", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (result != JOptionPane.YES_OPTION) {
return;
}
plugInPort.deleteTemplate(componentType.getCategory(), componentType.getName(), template.getName());
e.consume();
}
});
margin = new EmptyBorder(4, 2, 0, 0);
label.setBorder(margin);
item.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
item.add(label);
return item;
}
}
public static JButton create(final IPlugInPort plugInPort, final ComponentType componentType, final JPopupMenu menu) {
JButton button = DropDownButtonFactory.createDropDownButton(componentType.getIcon(), menu);
button.setBorder(BorderFactory.createEmptyBorder(MARGIN + 1, MARGIN + 1, MARGIN, MARGIN));
button.setToolTipText("<html><b>" + componentType.getName() + "</b><br>" + componentType.getDescription()
+ "<br>Author: " + componentType.getAuthor() + "<br><br>Right click to select all components of this type"
+ "</html>");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
plugInPort.setNewComponentTypeSlot(componentType, null);
}
});
button.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
List<IDIYComponent<?>> components = plugInPort.getCurrentProject().getComponents();
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>();
for (IDIYComponent<?> component : components) {
if (componentType.getInstanceClass().equals(component.getClass())) {
newSelection.add(component);
}
}
// Ctrl appends selection
if (e.isControlDown()) {
newSelection.addAll(plugInPort.getSelectedComponents());
}
plugInPort.updateSelection(newSelection);
plugInPort.setNewComponentTypeSlot(null, null);
plugInPort.refresh();
}
}
});
button.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
plugInPort.keyPressed(e.getKeyCode(), e.isControlDown(), e.isShiftDown(), e.isAltDown());
}
});
return button;
}
public static JMenuItem createTemplateItem(final IPlugInPort plugInPort, final Template template,
final ComponentType componentType) {
final JMenuItem item = new JMenuItem(template.getName()) {
private static final long serialVersionUID = 1L;
// Customize item size to fit the delete button
public java.awt.Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
return new Dimension(d.width + 32, d.height);
}
};
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
plugInPort.setNewComponentTypeSlot(componentType, template);
}
});
JLabel label = new JLabel(template.isDefaultFlag() ? IconLoader.PinGreen.getIcon() : IconLoader.PinGrey.getIcon());
label.setToolTipText(template.isDefaultFlag() ? "Remove default variant" : "Set default variant");
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// Hide the menu
Container c = item.getParent();
if (c != null && c instanceof JPopupMenu) {
JPopupMenu m = (JPopupMenu) c;
m.setVisible(false);
}
plugInPort.setTemplateDefault(componentType.getCategory(), componentType.getName(), template.getName(),
!template.isDefaultFlag());
e.consume();
}
});
Border margin = new EmptyBorder(4, 0, 0, 0);
label.setBorder(margin);
item.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
item.add(label);
label = new JLabel(IconLoader.Garbage.getIcon());
label.setToolTipText("Delete variant");
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// Hide the menu
Container c = item.getParent();
if (c != null && c instanceof JPopupMenu) {
JPopupMenu m = (JPopupMenu) c;
m.setVisible(false);
}
int result =
JOptionPane.showConfirmDialog(SwingUtilities.getRoot(item), "Are you sure you want to delete variant \""
+ template.getName() + "\"", "Delete", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (result != JOptionPane.YES_OPTION) {
return;
}
plugInPort.deleteTemplate(componentType.getCategory(), componentType.getName(), template.getName());
e.consume();
}
});
margin = new EmptyBorder(4, 2, 0, 0);
label.setBorder(margin);
item.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
item.add(label);
return item;
}
}
+6 -2
View File
@@ -2052,8 +2052,12 @@
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>Clicking on a building block twice in a row inside the component tree would make the components go back to the top-left corner of the layout</description>
</org.diylc.appframework.update.Change>
<description>Clicking on a building block in the component tree sometimes makes the components go back to the top-left corner of the layout</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>Ctrl + click doesn't add components to the selection in MacOS</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>