This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 144139
Collapse All | Expand All

(-)a/api.visual/src/org/netbeans/api/visual/action/ActionFactory.java (+15 lines)
Lines 626-631 Link Here
626
    }
626
    }
627
627
628
    /**
628
    /**
629
     * Creates a contiguous select action. Trigger by any left, middle or right mouse-button.
630
     * If no key-modifier is held, then it behaves as a non-contiguous replace selection.
631
     * If Shift key-modifier is held, then it behaves as a contiguous replace selection.
632
     * If Ctrl key-modifier is held, then it behaves as a non-contiguous additive selection.
633
     * If Ctrl and Shift key-modifiers are held, then it behaves as a contiguous additive selection.
634
     * @param provider the contiguous select logic provider
635
     * @return the contiguous select action
636
     * @since
637
     */
638
    public static WidgetAction createContiguousAction (ContiguousSelectProvider provider) {
639
        assert provider != null;
640
        return new ContiguousSelectAction (provider);
641
    }
642
643
    /**
629
     * Creates a switch card action with controls an active card of a widget where a card layout is used.
644
     * Creates a switch card action with controls an active card of a widget where a card layout is used.
630
     * @param cardLayoutWidget the widget where a card layout is used
645
     * @param cardLayoutWidget the widget where a card layout is used
631
     * @return the switch card action
646
     * @return the switch card action
(-)8bf4fddd49f6 (+158 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.api.visual.action;
42
43
import org.netbeans.api.visual.widget.Widget;
44
45
import java.awt.*;
46
47
/**
48
 * Represents an event for ContiguousSelectEvent passed to ContiguousSelectProvider. Contains information about selection-type, previously and currently choosen objects spots.
49
 *
50
 * @author David Kaspar
51
 * @since
52
 */
53
public final class ContiguousSelectEvent {
54
55
    private final Widget previouslyChoosenWidget;
56
    private final Point previouslyChoosenLocalLocation;
57
58
    private final Widget choosenWidget;
59
    private final Point choosenLocalLocation;
60
61
    private final SelectionType selectionType;
62
63
    private ContiguousSelectEvent (Widget previouslyChoosenWidget, Point previouslyChoosenLocalLocation, Widget choosenWidget, Point choosenLocalLocation, SelectionType selectionType) {
64
        this.previouslyChoosenWidget = previouslyChoosenWidget;
65
        this.previouslyChoosenLocalLocation = previouslyChoosenLocalLocation;
66
        this.choosenWidget = choosenWidget;
67
        this.choosenLocalLocation = choosenLocalLocation;
68
        this.selectionType = selectionType;
69
    }
70
71
    /**
72
     * Returns a previously choosen widget.
73
     * @return the previously choosen widget
74
     */
75
    public Widget getPreviouslyChoosenWidget () {
76
        return previouslyChoosenWidget;
77
    }
78
79
    /**
80
     * Returns a local location of a previously choosen widget.
81
     * @return the local location of the previously choosen widget
82
     */
83
    public Point getPreviouslyChoosenLocalLocation () {
84
        return previouslyChoosenLocalLocation != null ? new Point (previouslyChoosenLocalLocation) : null;
85
    }
86
87
    /**
88
     * Returns a choosen widget.
89
     * @return the choosen widget
90
     */
91
    public Widget getChoosenWidget () {
92
        return choosenWidget;
93
    }
94
95
    /**
96
     * Returns a local location of a choosen widget.
97
     * @return the local location of the choosen widget
98
     */
99
    public Point getChoosenLocalLocation () {
100
        return choosenLocalLocation != null ?  new Point (choosenLocalLocation) : null;
101
    }
102
103
    /**
104
     * Represents a selection type.
105
     * @return the selection type
106
     */
107
    public SelectionType getSelectionType () {
108
        return selectionType;
109
    }
110
111
    /**
112
     * Creates an event. Meant to be used by the library only.
113
     * @param previousWidget the previously choosen widget
114
     * @param previousLocalLocation the local location of the previously choosen widget
115
     * @param choosenWidget the choosen widget
116
     * @param choosenLocalLocation the local location of the currently choosen widget
117
     * @param selectionType the selection type invoked by an user
118
     * @return the contiguous select event
119
     */
120
    public static ContiguousSelectEvent create (Widget previousWidget, Point previousLocalLocation, Widget choosenWidget, Point choosenLocalLocation, SelectionType selectionType) {
121
        assert selectionType != null;
122
        return new ContiguousSelectEvent (previousWidget, previousLocalLocation, choosenWidget, choosenLocalLocation, selectionType);
123
    }
124
125
    /**
126
     * Defines a type of a selection.
127
     */
128
    public enum SelectionType {
129
130
        /**
131
         * Represents a normal selection that replace the previous selection.
132
         * Usually invokes without any key-modifier.
133
         */
134
        REPLACE_NON_CONTIGUOUS,
135
136
        /**
137
         * Represents a normal selection that replace the previous selection.
138
         * All objects that are between previously and current choosen spots defines the current selection.
139
         * Usually invokes with Shift key-modifier.
140
         */
141
        REPLACE_CONTIGUOUS,
142
143
        /**
144
         * Represents an additive selection where the new selection should be added to the current selection.
145
         * Usually invokes with Ctrl key-modifier.
146
         */
147
        ADDITIVE_NON_CONTIGUOUS,
148
149
        /**
150
         * Represents an additive selection where the new selection should be added to the current selection.
151
         * All objects that are between previously and current choosen spots defines the current selection.
152
         * Usually invokes with Ctrl and Shift key-modifiers.
153
         */
154
        ADDITIVE_CONTIGUOUS,
155
156
    }
157
158
}
(-)8bf4fddd49f6 (+66 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.api.visual.action;
42
43
/**
44
 * Provides a logic for ContiguousSelectAction.
45
 *
46
 * @author David Kaspar
47
 * @since
48
 */
49
public interface ContiguousSelectProvider {
50
51
    /**
52
     * Called to resolve whether a selection is allowed.
53
     * @param event the range select event
54
     * @return true, if allowed; false, if not
55
     * @since
56
     */
57
    public boolean isSelectionAllowed (ContiguousSelectEvent event);
58
59
    /**
60
     * Should perform the selection. Call event.getSelectionType() to resolve the type of selection.
61
     * @param event the range select event
62
     * @since
63
     */
64
    public void select (ContiguousSelectEvent event);
65
    
66
}
(-)8bf4fddd49f6 (+99 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.visual.action;
42
43
import org.netbeans.api.visual.action.ContiguousSelectEvent;
44
import org.netbeans.api.visual.action.ContiguousSelectProvider;
45
import org.netbeans.api.visual.action.WidgetAction;
46
import org.netbeans.api.visual.widget.Widget;
47
48
import java.awt.*;
49
import java.awt.event.KeyEvent;
50
import java.awt.event.MouseEvent;
51
52
/**
53
 * @author David Kaspar
54
 */
55
public final class ContiguousSelectAction extends WidgetAction.Adapter {
56
57
    private ContiguousSelectProvider provider;
58
    private Widget previousWidget;
59
    private Point previousLocalLocation;
60
61
    public ContiguousSelectAction (ContiguousSelectProvider provider) {
62
        this.provider = provider;
63
    }
64
65
    public State mousePressed (Widget widget, WidgetMouseEvent event) {
66
        Point localLocation = event.getPoint();
67
        if ((event.getButton() & (MouseEvent.BUTTON1  | MouseEvent.BUTTON2  | MouseEvent.BUTTON3)) != 0) {
68
            if (process (widget, localLocation, event.getModifiersEx ()))
69
                return State.CHAIN_ONLY;
70
        }
71
        return State.REJECTED;
72
    }
73
74
    private boolean process (Widget widget, Point localLocation, int modifiers) {
75
        boolean ctrl = (modifiers & MouseEvent.CTRL_DOWN_MASK) != 0;
76
        boolean shift = (modifiers & MouseEvent.SHIFT_DOWN_MASK) != 0;
77
        ContiguousSelectEvent.SelectionType type = ctrl
78
                ? (shift ? ContiguousSelectEvent.SelectionType.ADDITIVE_CONTIGUOUS : ContiguousSelectEvent.SelectionType.ADDITIVE_NON_CONTIGUOUS)
79
                : (shift ? ContiguousSelectEvent.SelectionType.REPLACE_CONTIGUOUS : ContiguousSelectEvent.SelectionType.REPLACE_NON_CONTIGUOUS);
80
        ContiguousSelectEvent providerEvent = ContiguousSelectEvent.create (previousWidget, previousLocalLocation, widget, localLocation, type);
81
        if (provider.isSelectionAllowed (providerEvent)) {
82
            provider.select(providerEvent);
83
            if (! shift) {
84
                previousWidget = widget;
85
                previousLocalLocation = localLocation;
86
            }
87
            return true;
88
        }
89
        return false;
90
    }
91
92
    public State keyTyped (Widget widget, WidgetKeyEvent event) {
93
        if (event.getKeyChar () == KeyEvent.VK_SPACE)
94
            if (process (widget, null, event.getModifiers ()))
95
                return State.CONSUMED;
96
        return State.REJECTED;
97
    }
98
99
}

Return to bug 144139