Selection d'objets empilés

This commit is contained in:
AdecWatt 2019-04-17 13:53:14 +02:00
parent 04927ed4c0
commit 805ff7b813
5 changed files with 117 additions and 53 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>This file is automaticaly generated by AdecWatt application at 5:39 PM on Apr 15, 2019.</comment>
<comment>This file is automaticaly generated by AdecWatt application at 10:39 AM on Apr 17, 2019.</comment>
<entry key="DownloaddataChecked">true</entry>
<entry key="RoleFurnitureManager">true</entry>
<entry key="Uploadhelp-en_USChecked">false</entry>
@ -29,16 +29,16 @@
<entry key="Country">FR</entry>
<entry key="SearchOrder">5</entry>
<entry key="FilePlace">North</entry>
<entry key="AboutLocation">[x=0,y=26]</entry>
<entry key="AboutLocation">[x=3 200,y=146]</entry>
<entry key="SearchUndocked">false</entry>
<entry key="FileChecked">true</entry>
<entry key="FrameLocation">[x=738,y=247]</entry>
<entry key="FrameLocation">[x=73,y=212]</entry>
<entry key="EditPlace">North</entry>
<entry key="Uploadhelp-fr_FRChecked">false</entry>
<entry key="CheckPeriod">Day</entry>
<entry key="AboutChecked">false</entry>
<entry key="LicenceLocation">[x=0,y=26]</entry>
<entry key="JConsoleLocation">[x=0,y=26]</entry>
<entry key="LicenceLocation">[x=3 200,y=146]</entry>
<entry key="JConsoleLocation">[x=3 200,y=146]</entry>
<entry key="PlacementChecked">true</entry>
<entry key="SliderUndocked">false</entry>
<entry key="SliderOrder">2</entry>
@ -61,7 +61,7 @@
<entry key="HelpUndocked">false</entry>
<entry key="ManualChecked">false</entry>
<entry key="RemoteRemovehelp-br_FR_galloChecked">false</entry>
<entry key="LastCheck">20190415</entry>
<entry key="LastCheck">20190417</entry>
<entry key="RemoteRemovehelp-br_FR_bretonChecked">false</entry>
<entry key="HttpServerChecked">false</entry>
<entry key="LicenceChecked">false</entry>
@ -70,7 +70,7 @@
<entry key="RemoteRemovehelp-imagesChecked">false</entry>
<entry key="Uploadhelp-br_FR_galloChecked">false</entry>
<entry key="EditUndocked">false</entry>
<entry key="ManualLocation">[x=0,y=26]</entry>
<entry key="ManualLocation">[x=3 200,y=146]</entry>
<entry key="PlacementUndocked">false</entry>
<entry key="RemoteRemovehelp-fr_FRChecked">false</entry>
<entry key="PlacementPlace">North</entry>

Binary file not shown.

After

Width:  |  Height:  |  Size: 688 B

View File

@ -122,6 +122,8 @@ import adecWatt.model.Segm;
// ========================================
public void updateLocation () {
if (currentPos == null)
return;
Point pos = jWorkspaceView.scaleModelToView (currentPos);
pos.x -= getWidth ()/2;
pos.y -= getHeight ()/2;

View File

@ -0,0 +1,85 @@
package adecWatt.view;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import adecWatt.model.Item;
import adecWatt.control.AdecWattManager;
@SuppressWarnings ("serial") public class JOverlapItemPopup extends JPopupMenu {
JWorkspaceView<?> jWorkspaceView;
MouseEvent mouseEvent;
public JOverlapItemPopup (JWorkspaceView<?> jWorkspaceView, MouseEvent mouseEvent) {
this.jWorkspaceView = jWorkspaceView;
this.mouseEvent = mouseEvent;
Point pos = mouseEvent.getPoint ();
ArrayList<Item> overlapItems = jWorkspaceView.findItems (pos);
if (mouseEvent.getID () == MouseEvent.MOUSE_PRESSED && !SwingUtilities.isRightMouseButton (mouseEvent) &&
jWorkspaceView.selectedItems.size () > 0) {
for (final JItem jItem : jWorkspaceView.selectedItems.values ())
if (overlapItems.contains (jItem.getItem ())) {
jWorkspaceView.startDrag (jItem.getItem (), mouseEvent.getPoint ());
return;
}
}
switch (overlapItems.size ()) {
case 0:
select (null);
return;
case 1:
select (overlapItems.get (0));
return;
}
if (SwingUtilities.isRightMouseButton (mouseEvent) && jWorkspaceView.selectedItems.size () > 0) {
if (jWorkspaceView.performPopup (mouseEvent))
return;
}
for (final Item item : overlapItems) {
JMenuItem menuItem = new JMenuItem (item.getName (), item.getParentUnit ().getIcon (16));
menuItem.setActionCommand (item.getName ());
menuItem.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent e) {
select (item);
}
});
add (menuItem);
}
show (jWorkspaceView, pos.x, pos.y);
}
public void select (Item item) {
switch (mouseEvent.getID ()) {
case MouseEvent.MOUSE_PRESSED:
if (SwingUtilities.isRightMouseButton (mouseEvent)) {
if (jWorkspaceView.performPopup (mouseEvent))
return;
jWorkspaceView.performSelection (item, mouseEvent);
jWorkspaceView.performPopup (mouseEvent);
return;
}
jWorkspaceView.performSelection (item, mouseEvent);
break;
case MouseEvent.MOUSE_CLICKED:
if (mouseEvent.getClickCount () > 1) {
// double click
if (jWorkspaceView.selectedItems.size () < 1)
jWorkspaceView.setSelectedItems (item);
ArrayList<Item> param = new ArrayList<Item> ();
for (final JItem jItem : jWorkspaceView.selectedItems.values ())
param.add (jItem.getItem ());
jWorkspaceView.adecWatt.broadcastDisplay (AdecWattManager.actionDisplayItem, param);
return;
}
break;
}
}
}

View File

@ -163,16 +163,14 @@ import adecWatt.model.unit.Workspace;
public ArrayList<Item> findItems (Point pos) {
return workspace.findItems (scaleViewToModel (pos), closePixelsItems/scale);
}
public Hashtable<Item, ArrayList<Acc>> findAccs (Point pos, ArrayList<Item> overlap) {
public Hashtable<Item, ArrayList<Acc>> findAccs (Point pos, Item<?,?,?> item) {
Hashtable<Item, ArrayList<Acc>> result = new Hashtable<Item, ArrayList<Acc>> ();
if (overlap ==null)
if (item ==null)
return result;
Point2D.Double realPos = scaleViewToModel (new Point (pos.x, pos.y));
for (Item item : overlap) {
ArrayList<Acc> accs = item.findAccs (realPos, closePixelsAccs/scale);
if (accs.size () > 0)
result.put (item, accs);
}
return result;
}
@ -220,36 +218,16 @@ import adecWatt.model.unit.Workspace;
adecWatt.broadcastDisplay (AdecWattManager.actionDisplayAcc, selectedAcc.getAcc ());
return;
}
ArrayList<Item> overlapItems = findItems (e.getPoint ());
if (e.getClickCount () > 1) {
// double click
if (selectedItems.size () > 1)
for (Item item : overlapItems)
if (selectedItems.containsKey (item.getId ()))
// XXX info multiple
return;
if (overlapItems.size () < 1)
return;
setSelectedItems (overlapItems.get ((overlapItems.indexOf (lastSelectedItem)+1)%overlapItems.size ()));
List<Item> param = Arrays.asList (lastSelectedItem);
adecWatt.broadcastDisplay (AdecWattManager.actionDisplayItem, param);
return;
}
new JOverlapItemPopup (this, e);
}
public void mousePressed (MouseEvent e) {
requestFocusInWindow ();
jAdecWatt.setCurrentWorkspace (workspace);
if (SwingUtilities.isRightMouseButton (e)) {
if (performPopup (e))
return;
performSelection (e);
performPopup (e);
return;
}
if (e.isControlDown ()) {
rotation (e);
return;
}
performSelection (e);
new JOverlapItemPopup (this, e);
}
protected boolean performPopup (MouseEvent e) {
if (selectedAcc != null) {
@ -263,17 +241,20 @@ import adecWatt.model.unit.Workspace;
}
return false;
}
private ArrayList<Item> overlapItems;
protected void performSelection (MouseEvent e) {
//private ArrayList<Item> overlapItems;
public void startDrag (Item<?,?,?> item, Point mPos) {
firstClick = lastClick = mPos;
selectionRefHandle (item, mPos);
}
public void performSelection (Item<?,?,?> item, MouseEvent e) {
// XXX YYY peut-être passer la liste
Point mPos = e.getPoint ();
setSelectedAcc ();
overlapItems = findItems (mPos);
if (overlapItems.size () < 1) {
if (item == null) {
startsZoneSelection (e);
return;
}
firstClick = lastClick = mPos;
Hashtable<Item, ArrayList<Acc>> overlapAccs = findAccs (mPos, overlapItems);
Hashtable<Item, ArrayList<Acc>> overlapAccs = findAccs (mPos, item);
if (overlapAccs.size () > 0) {
lastSelectedAccId = (lastSelectedAccId+1)%nbOverlapAccs (overlapAccs);
setSelectedAcc (overlapAccs, lastSelectedAccId);
@ -282,7 +263,8 @@ import adecWatt.model.unit.Workspace;
lastSelectedAccId = -1;
// XXX revoir si overlapAccs deja selectionnes
if (e.isShiftDown ()) {
invertItemSelection (overlapItems.get (0));
//invertItemSelection (overlapItems.get (0));
invertItemSelection (item);
if (selectedItems.size () < 1) {
firstClick = lastClick = null;
refHandle = null;
@ -291,14 +273,7 @@ import adecWatt.model.unit.Workspace;
// XXX changement du choix de la poignée de référence ?
return;
}
if (selectedItems.size () > 0)
for (Item item : overlapItems)
if (selectedItems.containsKey (item.getId ())) {
selectionRefHandle (item, mPos);
return;
}
Item item = overlapItems.get ((overlapItems.indexOf (lastSelectedItem)+1) % overlapItems.size ());
selectionRefHandle (item, mPos);
startDrag (item, mPos);
setSelectedItems (item);
}
public void selectionRefHandle (Item item, Point mPos) {
@ -544,6 +519,8 @@ import adecWatt.model.unit.Workspace;
JItem jItem = selectedItems.get (itemId);
Item item = jItem.getItem ();
double [] bounds = jItem.getCurrentBounds ();
if (bounds == null)
continue;
int [] x = new int[4];
int [] y = new int[4];
for (int i = 0, j = 1, k = 0; k < 4; i += 2, j += 2, k++) {
@ -673,7 +650,7 @@ import adecWatt.model.unit.Workspace;
Point2D.Double refHandle;
DimensionDouble handleOff;
public void dragItems (MouseEvent e) {
if (notEditable () || firstClick == null)
if (notEditable () || firstClick == null || handleOff == null)
return;
Point newPos = e.getPoint ();