diff --git a/api.visual/apichanges.xml b/api.visual/apichanges.xml
--- a/api.visual/apichanges.xml
+++ b/api.visual/apichanges.xml
@@ -712,12 +712,32 @@
- InplaceEditorProvider.TypedEditorController
+ InplaceEditorProvider.TypedEditorController
contains getEditorInvocationType()
which returns invocation type
(MOUSE
, KEY
, CODE
).
+
+
+
+ Support for contiguous selection action added (factory method+provider+event)
+
+
+
+
+
+
+ ActionFactory.createContiguousSelectAction
creates contiguous selection action.
+ ContiguousSelectProvider
+ provides logic for selection action.
+ ContiguousSelectEvent
+ is an event for ContiguousSelectProvider
.
+
+
+
+
+
diff --git a/api.visual/manifest.mf b/api.visual/manifest.mf
--- a/api.visual/manifest.mf
+++ b/api.visual/manifest.mf
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.api.visual
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/visual/resources/Bundle.properties
-OpenIDE-Module-Specification-Version: 2.16
+OpenIDE-Module-Specification-Version: 2.17
AutoUpdate-Essential-Module: true
diff --git a/api.visual/src/org/netbeans/api/visual/action/ActionFactory.java b/api.visual/src/org/netbeans/api/visual/action/ActionFactory.java
--- a/api.visual/src/org/netbeans/api/visual/action/ActionFactory.java
+++ b/api.visual/src/org/netbeans/api/visual/action/ActionFactory.java
@@ -626,6 +626,21 @@
}
/**
+ * Creates a contiguous select action. Trigger by any left, middle or right mouse-button.
+ * If no key-modifier is held, then it behaves as a non-contiguous replace selection.
+ * If Shift key-modifier is held, then it behaves as a contiguous replace selection.
+ * If Ctrl key-modifier is held, then it behaves as a non-contiguous additive selection.
+ * If Ctrl and Shift key-modifiers are held, then it behaves as a contiguous additive selection.
+ * @param provider the contiguous select logic provider
+ * @return the contiguous select action
+ * @since 2.17
+ */
+ public static WidgetAction createContiguousSelectAction (ContiguousSelectProvider provider) {
+ assert provider != null;
+ return new ContiguousSelectAction (provider);
+ }
+
+ /**
* Creates a switch card action with controls an active card of a widget where a card layout is used.
* @param cardLayoutWidget the widget where a card layout is used
* @return the switch card action
diff --git a/api.visual/src/org/netbeans/api/visual/action/ContiguousSelectEvent.java b/api.visual/src/org/netbeans/api/visual/action/ContiguousSelectEvent.java
new file mode 100644
--- /dev/null
+++ b/api.visual/src/org/netbeans/api/visual/action/ContiguousSelectEvent.java
@@ -0,0 +1,158 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+package org.netbeans.api.visual.action;
+
+import org.netbeans.api.visual.widget.Widget;
+
+import java.awt.*;
+
+/**
+ * Represents an event for ContiguousSelectEvent passed to ContiguousSelectProvider. Contains information about selection-type, previously and currently choosen objects spots.
+ *
+ * @author David Kaspar
+ * @since 2.17
+ */
+public final class ContiguousSelectEvent {
+
+ private final Widget previouslyChoosenWidget;
+ private final Point previouslyChoosenLocalLocation;
+
+ private final Widget choosenWidget;
+ private final Point choosenLocalLocation;
+
+ private final SelectionType selectionType;
+
+ private ContiguousSelectEvent (Widget previouslyChoosenWidget, Point previouslyChoosenLocalLocation, Widget choosenWidget, Point choosenLocalLocation, SelectionType selectionType) {
+ this.previouslyChoosenWidget = previouslyChoosenWidget;
+ this.previouslyChoosenLocalLocation = previouslyChoosenLocalLocation;
+ this.choosenWidget = choosenWidget;
+ this.choosenLocalLocation = choosenLocalLocation;
+ this.selectionType = selectionType;
+ }
+
+ /**
+ * Returns a previously choosen widget.
+ * @return the previously choosen widget
+ */
+ public Widget getPreviouslyChoosenWidget () {
+ return previouslyChoosenWidget;
+ }
+
+ /**
+ * Returns a local location of a previously choosen widget.
+ * @return the local location of the previously choosen widget
+ */
+ public Point getPreviouslyChoosenLocalLocation () {
+ return previouslyChoosenLocalLocation != null ? new Point (previouslyChoosenLocalLocation) : null;
+ }
+
+ /**
+ * Returns a choosen widget.
+ * @return the choosen widget
+ */
+ public Widget getChoosenWidget () {
+ return choosenWidget;
+ }
+
+ /**
+ * Returns a local location of a choosen widget.
+ * @return the local location of the choosen widget
+ */
+ public Point getChoosenLocalLocation () {
+ return choosenLocalLocation != null ? new Point (choosenLocalLocation) : null;
+ }
+
+ /**
+ * Represents a selection type.
+ * @return the selection type
+ */
+ public SelectionType getSelectionType () {
+ return selectionType;
+ }
+
+ /**
+ * Creates an event. Meant to be used by the library only.
+ * @param previousWidget the previously choosen widget
+ * @param previousLocalLocation the local location of the previously choosen widget
+ * @param choosenWidget the choosen widget
+ * @param choosenLocalLocation the local location of the currently choosen widget
+ * @param selectionType the selection type invoked by an user
+ * @return the contiguous select event
+ */
+ public static ContiguousSelectEvent create (Widget previousWidget, Point previousLocalLocation, Widget choosenWidget, Point choosenLocalLocation, SelectionType selectionType) {
+ assert selectionType != null;
+ return new ContiguousSelectEvent (previousWidget, previousLocalLocation, choosenWidget, choosenLocalLocation, selectionType);
+ }
+
+ /**
+ * Defines a type of a selection.
+ */
+ public enum SelectionType {
+
+ /**
+ * Represents a normal selection that replace the previous selection.
+ * Usually invokes without any key-modifier.
+ */
+ REPLACE_NON_CONTIGUOUS,
+
+ /**
+ * Represents a normal selection that replace the previous selection.
+ * All objects that are between previously and current choosen spots defines the current selection.
+ * Usually invokes with Shift key-modifier.
+ */
+ REPLACE_CONTIGUOUS,
+
+ /**
+ * Represents an additive selection where the new selection should be added to the current selection.
+ * Usually invokes with Ctrl key-modifier.
+ */
+ ADDITIVE_NON_CONTIGUOUS,
+
+ /**
+ * Represents an additive selection where the new selection should be added to the current selection.
+ * All objects that are between previously and current choosen spots defines the current selection.
+ * Usually invokes with Ctrl and Shift key-modifiers.
+ */
+ ADDITIVE_CONTIGUOUS,
+
+ }
+
+}
diff --git a/api.visual/src/org/netbeans/api/visual/action/ContiguousSelectProvider.java b/api.visual/src/org/netbeans/api/visual/action/ContiguousSelectProvider.java
new file mode 100644
--- /dev/null
+++ b/api.visual/src/org/netbeans/api/visual/action/ContiguousSelectProvider.java
@@ -0,0 +1,64 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+package org.netbeans.api.visual.action;
+
+/**
+ * Provides a logic for ContiguousSelectAction.
+ *
+ * @author David Kaspar
+ * @since 2.17
+ */
+public interface ContiguousSelectProvider {
+
+ /**
+ * Called to resolve whether a selection is allowed.
+ * @param event the range select event
+ * @return true, if allowed; false, if not
+ */
+ public boolean isSelectionAllowed (ContiguousSelectEvent event);
+
+ /**
+ * Should perform the selection. Call event.getSelectionType() to resolve the type of selection.
+ * @param event the range select event
+ */
+ public void select (ContiguousSelectEvent event);
+
+}
diff --git a/api.visual/src/org/netbeans/modules/visual/action/ContiguousSelectAction.java b/api.visual/src/org/netbeans/modules/visual/action/ContiguousSelectAction.java
new file mode 100644
--- /dev/null
+++ b/api.visual/src/org/netbeans/modules/visual/action/ContiguousSelectAction.java
@@ -0,0 +1,101 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+package org.netbeans.modules.visual.action;
+
+import org.netbeans.api.visual.action.ContiguousSelectEvent;
+import org.netbeans.api.visual.action.ContiguousSelectProvider;
+import org.netbeans.api.visual.action.WidgetAction;
+import org.netbeans.api.visual.widget.Widget;
+
+import java.awt.*;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+
+/**
+ * @author David Kaspar
+ */
+public final class ContiguousSelectAction extends WidgetAction.Adapter {
+
+ private ContiguousSelectProvider provider;
+ private Widget previousWidget;
+ private Point previousLocalLocation;
+
+ public ContiguousSelectAction (ContiguousSelectProvider provider) {
+ this.provider = provider;
+ }
+
+ @Override
+ public State mousePressed (Widget widget, WidgetMouseEvent event) {
+ Point localLocation = event.getPoint();
+ if ((event.getButton() & (MouseEvent.BUTTON1 | MouseEvent.BUTTON2 | MouseEvent.BUTTON3)) != 0) {
+ if (process (widget, localLocation, event.getModifiersEx ()))
+ return State.CHAIN_ONLY;
+ }
+ return State.REJECTED;
+ }
+
+ private boolean process (Widget widget, Point localLocation, int modifiers) {
+ boolean ctrl = (modifiers & MouseEvent.CTRL_DOWN_MASK) != 0;
+ boolean shift = (modifiers & MouseEvent.SHIFT_DOWN_MASK) != 0;
+ ContiguousSelectEvent.SelectionType type = ctrl
+ ? (shift ? ContiguousSelectEvent.SelectionType.ADDITIVE_CONTIGUOUS : ContiguousSelectEvent.SelectionType.ADDITIVE_NON_CONTIGUOUS)
+ : (shift ? ContiguousSelectEvent.SelectionType.REPLACE_CONTIGUOUS : ContiguousSelectEvent.SelectionType.REPLACE_NON_CONTIGUOUS);
+ ContiguousSelectEvent providerEvent = ContiguousSelectEvent.create (previousWidget, previousLocalLocation, widget, localLocation, type);
+ if (provider.isSelectionAllowed (providerEvent)) {
+ provider.select(providerEvent);
+ if (! shift) {
+ previousWidget = widget;
+ previousLocalLocation = localLocation;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public State keyTyped (Widget widget, WidgetKeyEvent event) {
+ if (event.getKeyChar () == KeyEvent.VK_SPACE)
+ if (process (widget, null, event.getModifiers ()))
+ return State.CONSUMED;
+ return State.REJECTED;
+ }
+
+}