Merge pull request #1471 from SiboVG/issue-1054
[fixes #1054] Better register of double-click in 3D view
This commit is contained in:
		
						commit
						9350dbe1a6
					
				| @ -33,6 +33,8 @@ RocketActions.CopyAct.Copy = Copy | |||||||
| RocketActions.CopyAct.ttip.Copy = Copy this component (and subcomponents) to the clipboard. | RocketActions.CopyAct.ttip.Copy = Copy this component (and subcomponents) to the clipboard. | ||||||
| RocketActions.PasteAct.Paste = Paste | RocketActions.PasteAct.Paste = Paste | ||||||
| RocketActions.PasteAct.ttip.Paste = Paste the component or simulation on the clipboard to the design. | RocketActions.PasteAct.ttip.Paste = Paste the component or simulation on the clipboard to the design. | ||||||
|  | RocketActions.PasteAct.invalidPosition.msg = Invalid paste position for object '%s', ignoring pasting. | ||||||
|  | RocketActions.PasteAct.invalidPosition.title = Could not paste | ||||||
| RocketActions.DuplicateAct.Duplicate = Duplicate | RocketActions.DuplicateAct.Duplicate = Duplicate | ||||||
| RocketActions.DuplicateAct.ttip.Duplicate = Duplicate this component (and subcomponents). | RocketActions.DuplicateAct.ttip.Duplicate = Duplicate this component (and subcomponents). | ||||||
| RocketActions.EditAct.Edit = Edit | RocketActions.EditAct.Edit = Edit | ||||||
|  | |||||||
| @ -303,12 +303,34 @@ public class BasicFrame extends JFrame { | |||||||
| 				int selRow = tree.getRowForLocation(e.getX(), e.getY()); | 				int selRow = tree.getRowForLocation(e.getX(), e.getY()); | ||||||
| 				TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); | 				TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); | ||||||
| 				if (selRow != -1) { | 				if (selRow != -1) { | ||||||
| 					if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2) && !ComponentConfigDialog.isDialogVisible()) { | 					if (selPath == null) return; | ||||||
|  | 
 | ||||||
| 					// Double-click | 					// Double-click | ||||||
| 						RocketComponent c = (RocketComponent) selPath.getLastPathComponent(); | 					if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2) && !ComponentConfigDialog.isDialogVisible()) { | ||||||
| 						ComponentConfigDialog.showDialog(BasicFrame.this, | 						RocketComponent component = (RocketComponent) selPath.getLastPathComponent(); | ||||||
| 								BasicFrame.this.document, c); | 
 | ||||||
| 					} else if ((e.getButton() == MouseEvent.BUTTON3) && (e.getClickCount() == 1)) { | 						// Multi-component edit if shift/meta key is pressed | ||||||
|  | 						if ((e.isShiftDown() || e.isMetaDown()) && tree.getSelectionPaths() != null) { | ||||||
|  | 							// Add the other selected components as listeners to the last selected component | ||||||
|  | 							for (TreePath p : tree.getSelectionPaths()) { | ||||||
|  | 								if (p != null) { | ||||||
|  | 									if (p.getLastPathComponent() == component) continue; | ||||||
|  | 									RocketComponent c = (RocketComponent) p.getLastPathComponent(); | ||||||
|  | 									c.clearConfigListeners(); | ||||||
|  | 									component.addConfigListener(c); | ||||||
|  | 								} | ||||||
|  | 							} | ||||||
|  | 
 | ||||||
|  | 							// Add the selection path to the tree selection | ||||||
|  | 							List<TreePath> paths = new LinkedList<>(Arrays.asList(tree.getSelectionPaths())); | ||||||
|  | 							paths.add(selPath); | ||||||
|  | 							tree.setSelectionPaths(paths.toArray(new TreePath[0])); | ||||||
|  | 						} | ||||||
|  | 
 | ||||||
|  | 						ComponentConfigDialog.showDialog(BasicFrame.this, BasicFrame.this.document, component); | ||||||
|  | 					} | ||||||
|  | 					// Context menu | ||||||
|  | 					else if ((e.getButton() == MouseEvent.BUTTON3) && (e.getClickCount() == 1)) { | ||||||
| 						if (!tree.isPathSelected(selPath)) { | 						if (!tree.isPathSelected(selPath)) { | ||||||
| 							// Select new path | 							// Select new path | ||||||
| 							tree.setSelectionPath(selPath); | 							tree.setSelectionPath(selPath); | ||||||
| @ -316,7 +338,7 @@ public class BasicFrame extends JFrame { | |||||||
| 
 | 
 | ||||||
| 						doComponentTreePopup(e); | 						doComponentTreePopup(e); | ||||||
| 					} | 					} | ||||||
| 				} else { | 				} else {	// Clicked on blank space | ||||||
| 					tree.clearSelection(); | 					tree.clearSelection(); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  | |||||||
| @ -5,6 +5,7 @@ import java.awt.Toolkit; | |||||||
| import java.awt.event.ActionEvent; | import java.awt.event.ActionEvent; | ||||||
| import java.awt.event.KeyEvent; | import java.awt.event.KeyEvent; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
|  | import java.util.Collections; | ||||||
| import java.util.Comparator; | import java.util.Comparator; | ||||||
| import java.util.LinkedList; | import java.util.LinkedList; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| @ -270,6 +271,15 @@ public class RocketActions { | |||||||
| 				RocketComponent originalParent = components.get(i).getParent(); | 				RocketComponent originalParent = components.get(i).getParent(); | ||||||
| 				int originalParentIdx = components.indexOf(originalParent); | 				int originalParentIdx = components.indexOf(originalParent); | ||||||
| 
 | 
 | ||||||
|  | 				result.get(originalParentIdx).addChild(result.get(i)); | ||||||
|  | 			} else if (RocketComponent.listContainsParent(components, components.get(i))){ | ||||||
|  | 				RocketComponent originalParent = components.get(i); | ||||||
|  | 				while (originalParent != components.get(i)) { | ||||||
|  | 					if (components.contains(originalParent.getParent())) { | ||||||
|  | 						originalParent = originalParent.getParent(); | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 				int originalParentIdx = components.indexOf(originalParent); | ||||||
| 				result.get(originalParentIdx).addChild(result.get(i)); | 				result.get(originalParentIdx).addChild(result.get(i)); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @ -378,24 +388,41 @@ public class RocketActions { | |||||||
| 	 * should be pasted.  Returns null if the clipboard is empty or if the | 	 * should be pasted.  Returns null if the clipboard is empty or if the | ||||||
| 	 * clipboard cannot be pasted to the current selection. | 	 * clipboard cannot be pasted to the current selection. | ||||||
| 	 *  | 	 *  | ||||||
| 	 * @param   clipboard	the component on the clipboard. | 	 * @param   copyComponent	the component to be copy-pasted. | ||||||
|  | 	 * @param	pasteComponent	the component where copyComponent should be pasted to. | ||||||
| 	 * @return  a Pair with both components defined, or null. | 	 * @return  a Pair with both components defined, or null. | ||||||
| 	 */ | 	 */ | ||||||
| 	private Pair<RocketComponent, Integer> getPastePosition(RocketComponent clipboard) { | 	private Pair<RocketComponent, Integer> getPastePosition(RocketComponent copyComponent, RocketComponent pasteComponent) { | ||||||
|  | 		if (pasteComponent == null) | ||||||
|  | 			return null; | ||||||
|  | 
 | ||||||
|  | 		if (copyComponent == null) | ||||||
|  | 			return null; | ||||||
|  | 
 | ||||||
|  | 		if (pasteComponent.isCompatible(copyComponent)) | ||||||
|  | 			return new Pair<RocketComponent, Integer>(pasteComponent, pasteComponent.getChildCount()); | ||||||
|  | 
 | ||||||
|  | 		RocketComponent parent = pasteComponent.getParent(); | ||||||
|  | 		return getPastePositionFromParent(copyComponent, parent); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * Return the component and position to which the current clipboard | ||||||
|  | 	 * should be pasted.  Returns null if the clipboard is empty or if the | ||||||
|  | 	 * clipboard cannot be pasted to the current selection. | ||||||
|  | 	 * | ||||||
|  | 	 * @param   copyComponent	the component to be copy-pasted. | ||||||
|  | 	 * @return  a Pair with both components defined, or null. | ||||||
|  | 	 */ | ||||||
|  | 	private Pair<RocketComponent, Integer> getPastePosition(RocketComponent copyComponent) { | ||||||
| 		RocketComponent selected = selectionModel.getSelectedComponent(); | 		RocketComponent selected = selectionModel.getSelectedComponent(); | ||||||
| 		if (selected == null) | 		return getPastePosition(copyComponent, selected); | ||||||
| 			return null; | 	} | ||||||
| 
 | 
 | ||||||
| 		if (clipboard == null) | 	private Pair<RocketComponent, Integer> getPastePositionFromParent(RocketComponent component, RocketComponent parent) { | ||||||
| 			return null; | 		if (parent != null && parent.isCompatible(component)) { | ||||||
| 
 | 			int index = parent.getChildPosition(parent) + 1; | ||||||
| 		if (selected.isCompatible(clipboard)) | 			return new Pair<>(parent, index); | ||||||
| 			return new Pair<RocketComponent, Integer>(selected, selected.getChildCount()); |  | ||||||
| 
 |  | ||||||
| 		RocketComponent parent = selected.getParent(); |  | ||||||
| 		if (parent != null && parent.isCompatible(clipboard)) { |  | ||||||
| 			int index = parent.getChildPosition(selected) + 1; |  | ||||||
| 			return new Pair<RocketComponent, Integer>(parent, index); |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		return null; | 		return null; | ||||||
| @ -727,11 +754,20 @@ public class RocketActions { | |||||||
| 					document.addUndoPosition("Paste components"); | 					document.addUndoPosition("Paste components"); | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
|  | 				List<RocketComponent> successfullyPasted = new LinkedList<>(); | ||||||
| 				for (int i = 0; i < pasted.size(); i++) { | 				for (int i = 0; i < pasted.size(); i++) { | ||||||
|  | 					if (positions.get(i) == null) { | ||||||
|  | 						JOptionPane.showMessageDialog(null, | ||||||
|  | 								String.format(trans.get("RocketActions.PasteAct.invalidPosition.msg"), | ||||||
|  | 										pasted.get(i).getComponentName()), | ||||||
|  | 								trans.get("RocketActions.PasteAct.invalidPosition.title"), JOptionPane.WARNING_MESSAGE); | ||||||
|  | 					} else { | ||||||
| 						positions.get(i).getU().addChild(pasted.get(i), positions.get(i).getV()); | 						positions.get(i).getU().addChild(pasted.get(i), positions.get(i).getV()); | ||||||
|  | 						successfullyPasted.add(pasted.get(i)); | ||||||
|  | 					} | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				selectionModel.setSelectedComponents(pasted); | 				selectionModel.setSelectedComponents(successfullyPasted); | ||||||
| 				 | 				 | ||||||
| 				parentFrame.selectTab(BasicFrame.COMPONENT_TAB); | 				parentFrame.selectTab(BasicFrame.COMPONENT_TAB); | ||||||
| 				 | 				 | ||||||
| @ -805,7 +841,14 @@ public class RocketActions { | |||||||
| 
 | 
 | ||||||
| 				List<Pair<RocketComponent, Integer>> positions = new LinkedList<>(); | 				List<Pair<RocketComponent, Integer>> positions = new LinkedList<>(); | ||||||
| 				for (RocketComponent component : duplicateComponents) { | 				for (RocketComponent component : duplicateComponents) { | ||||||
| 					positions.add(getPastePosition(component)); | 					Pair<RocketComponent, Integer> pos; | ||||||
|  | 					if (RocketComponent.listContainsParent(duplicateComponents, component)) { | ||||||
|  | 						pos = getPastePosition(component, component.getParent()); | ||||||
|  | 					} else { | ||||||
|  | 						RocketComponent pasteParent = components.get(duplicateComponents.indexOf(component)).getParent(); | ||||||
|  | 						pos = getPastePosition(component, pasteParent); | ||||||
|  | 					} | ||||||
|  | 					positions.add(pos); | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				if (duplicateComponents.size() == 1) { | 				if (duplicateComponents.size() == 1) { | ||||||
| @ -814,6 +857,9 @@ public class RocketActions { | |||||||
| 					document.addUndoPosition("Duplicate components"); | 					document.addUndoPosition("Duplicate components"); | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
|  | 				Collections.reverse(duplicateComponents); | ||||||
|  | 				Collections.reverse(positions); | ||||||
|  | 
 | ||||||
| 				for (int i = 0; i < duplicateComponents.size(); i++) { | 				for (int i = 0; i < duplicateComponents.size(); i++) { | ||||||
| 					positions.get(i).getU().addChild(duplicateComponents.get(i), positions.get(i).getV()); | 					positions.get(i).getU().addChild(duplicateComponents.get(i), positions.get(i).getV()); | ||||||
| 				} | 				} | ||||||
|  | |||||||
| @ -5,6 +5,7 @@ import java.awt.BorderLayout; | |||||||
| import java.awt.Dimension; | import java.awt.Dimension; | ||||||
| import java.awt.Font; | import java.awt.Font; | ||||||
| import java.awt.Point; | import java.awt.Point; | ||||||
|  | import java.awt.Toolkit; | ||||||
| import java.awt.event.ActionEvent; | import java.awt.event.ActionEvent; | ||||||
| import java.awt.event.ActionListener; | import java.awt.event.ActionListener; | ||||||
| import java.awt.event.InputEvent; | import java.awt.event.InputEvent; | ||||||
| @ -15,6 +16,7 @@ import java.util.EventListener; | |||||||
| import java.util.EventObject; | import java.util.EventObject; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.LinkedList; | import java.util.LinkedList; | ||||||
|  | import java.util.TimerTask; | ||||||
| import java.util.concurrent.ExecutorService; | import java.util.concurrent.ExecutorService; | ||||||
| import java.util.concurrent.Executors; | import java.util.concurrent.Executors; | ||||||
| import java.util.concurrent.ThreadFactory; | import java.util.concurrent.ThreadFactory; | ||||||
| @ -74,6 +76,7 @@ import net.sf.openrocket.util.Chars; | |||||||
| import net.sf.openrocket.util.Coordinate; | import net.sf.openrocket.util.Coordinate; | ||||||
| import net.sf.openrocket.util.MathUtil; | import net.sf.openrocket.util.MathUtil; | ||||||
| import net.sf.openrocket.util.StateChangeListener; | import net.sf.openrocket.util.StateChangeListener; | ||||||
|  | import net.sf.openrocket.utils.CustomClickCountListener; | ||||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||||
| 
 | 
 | ||||||
| @ -200,10 +203,12 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change | |||||||
| 
 | 
 | ||||||
| 		scrollPane = new ScaleScrollPane(figure) { | 		scrollPane = new ScaleScrollPane(figure) { | ||||||
| 			private static final long serialVersionUID = 1L; | 			private static final long serialVersionUID = 1L; | ||||||
|  | 			final CustomClickCountListener clickCountListener = new CustomClickCountListener(); | ||||||
| 
 | 
 | ||||||
| 			@Override | 			@Override | ||||||
| 			public void mouseClicked(MouseEvent event) { | 			public void mouseClicked(MouseEvent event) { | ||||||
| 				handleMouseClick(event); | 				clickCountListener.click(); | ||||||
|  | 				handleMouseClick(event, clickCountListener.getClickCount()); | ||||||
| 			} | 			} | ||||||
| 		}; | 		}; | ||||||
| 		scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); | 		scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); | ||||||
| @ -237,9 +242,12 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change | |||||||
| 		}); | 		}); | ||||||
| 
 | 
 | ||||||
| 		figure3d.addComponentSelectionListener(new RocketFigure3d.ComponentSelectionListener() { | 		figure3d.addComponentSelectionListener(new RocketFigure3d.ComponentSelectionListener() { | ||||||
|  | 			final CustomClickCountListener clickCountListener = new CustomClickCountListener(); | ||||||
|  | 
 | ||||||
| 			@Override | 			@Override | ||||||
| 			public void componentClicked(RocketComponent clicked[], MouseEvent event) { | 			public void componentClicked(RocketComponent[] clicked, MouseEvent event) { | ||||||
| 				handleComponentClick(clicked, event); | 				clickCountListener.click(); | ||||||
|  | 				handleComponentClick(clicked, event, clickCountListener.getClickCount()); | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
| @ -551,7 +559,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change | |||||||
| 	 */ | 	 */ | ||||||
| 	public static final int CYCLE_SELECTION_MODIFIER = InputEvent.SHIFT_DOWN_MASK; | 	public static final int CYCLE_SELECTION_MODIFIER = InputEvent.SHIFT_DOWN_MASK; | ||||||
| 
 | 
 | ||||||
| 	private void handleMouseClick(MouseEvent event) { | 	private void handleMouseClick(MouseEvent event, int clickCount) { | ||||||
| 		// Get the component that is clicked on | 		// Get the component that is clicked on | ||||||
| 		Point p0 = event.getPoint(); | 		Point p0 = event.getPoint(); | ||||||
| 		Point p1 = scrollPane.getViewport().getViewPosition(); | 		Point p1 = scrollPane.getViewport().getViewPosition(); | ||||||
| @ -567,7 +575,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change | |||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if (event.getButton() == MouseEvent.BUTTON1) { | 		if (event.getButton() == MouseEvent.BUTTON1) { | ||||||
| 			handleComponentClick(clicked, event); | 			handleComponentClick(clicked, event, clickCount); | ||||||
| 		} else if (event.getButton() == MouseEvent.BUTTON3) { | 		} else if (event.getButton() == MouseEvent.BUTTON3) { | ||||||
| 			List<RocketComponent> selectedComponents = Arrays.stream(selectionModel.getSelectionPaths()) | 			List<RocketComponent> selectedComponents = Arrays.stream(selectionModel.getSelectionPaths()) | ||||||
| 					.map(c -> (RocketComponent) c.getLastPathComponent()).collect(Collectors.toList()); | 					.map(c -> (RocketComponent) c.getLastPathComponent()).collect(Collectors.toList()); | ||||||
| @ -593,14 +601,58 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private void handleComponentClick(RocketComponent[] clicked, MouseEvent event) { | 	private void handleComponentClick(RocketComponent[] clicked, MouseEvent event, int clickCount) { | ||||||
| 		List<RocketComponent> selectedComponents = Arrays.stream(selectionModel.getSelectionPaths()) | 		List<RocketComponent> selectedComponents = Arrays.stream(selectionModel.getSelectionPaths()) | ||||||
| 				.map(c -> (RocketComponent) c.getLastPathComponent()).collect(Collectors.toList()); | 				.map(c -> (RocketComponent) c.getLastPathComponent()).collect(Collectors.toList()); | ||||||
| 
 | 
 | ||||||
| 		if (clicked == null || clicked.length == 0) return; | 		if (clicked == null || clicked.length == 0) return; | ||||||
| 
 | 
 | ||||||
|  | 		// Check for double-click. | ||||||
|  | 		// If the shift/meta key is not pressed and the component was not already selected, ignore the double click and treat it as a single click | ||||||
|  | 		if (clickCount == 2) { | ||||||
|  | 			if (event.isShiftDown() || event.isMetaDown()) { | ||||||
|  | 				List<TreePath> paths = new ArrayList<>(Arrays.asList(selectionModel.getSelectionPaths())); | ||||||
|  | 				RocketComponent component = selectedComponents.get(selectedComponents.size() - 1); | ||||||
|  | 
 | ||||||
|  | 				// Make sure the clicked component is selected | ||||||
|  | 				for (RocketComponent c : clicked) { | ||||||
|  | 					if (!selectedComponents.contains(c)) { | ||||||
|  | 						TreePath path = ComponentTreeModel.makeTreePath(c); | ||||||
|  | 						paths.add(path); | ||||||
|  | 						selectionModel.setSelectionPaths(paths.toArray(new TreePath[0])); | ||||||
|  | 						selectedComponents = Arrays.stream(selectionModel.getSelectionPaths()) | ||||||
|  | 								.map(c1 -> (RocketComponent) c1.getLastPathComponent()).collect(Collectors.toList()); | ||||||
|  | 						component = c; | ||||||
|  | 						break; | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
|  | 				// Multi-component edit if shift/meta key is pressed | ||||||
|  | 				for (RocketComponent c : selectedComponents) { | ||||||
|  | 					if (c == component) continue; | ||||||
|  | 					c.clearConfigListeners(); | ||||||
|  | 					component.addConfigListener(c); | ||||||
|  | 				} | ||||||
|  | 				ComponentConfigDialog.showDialog(SwingUtilities.getWindowAncestor(this), document, component); | ||||||
|  | 			} | ||||||
|  | 			// Normal double click (no shift or meta key) | ||||||
|  | 			else { | ||||||
|  | 				if (!selectedComponents.contains(clicked[0])) { | ||||||
|  | 					clickCount = 1; | ||||||
|  | 				} else { | ||||||
|  | 					TreePath path = ComponentTreeModel.makeTreePath(clicked[0]); | ||||||
|  | 					selectionModel.setSelectionPath(path);        // Revert to single selection | ||||||
|  | 					RocketComponent component = (RocketComponent) path.getLastPathComponent(); | ||||||
|  | 
 | ||||||
|  | 					ComponentConfigDialog.showDialog(SwingUtilities.getWindowAncestor(this), | ||||||
|  | 							document, component); | ||||||
|  | 					return; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		// If the shift-button is held, add a newly clicked component to the selection path | 		// If the shift-button is held, add a newly clicked component to the selection path | ||||||
| 		if ((event.isShiftDown() || event.isMetaDown()) && event.getClickCount() == 1) { | 		if (clickCount == 1 && (event.isShiftDown() || event.isMetaDown())) { | ||||||
| 			List<TreePath> paths = new ArrayList<>(Arrays.asList(selectionModel.getSelectionPaths())); | 			List<TreePath> paths = new ArrayList<>(Arrays.asList(selectionModel.getSelectionPaths())); | ||||||
| 			for (int i = 0; i < clicked.length; i++) { | 			for (int i = 0; i < clicked.length; i++) { | ||||||
| 				if (!selectedComponents.contains(clicked[i])) { | 				if (!selectedComponents.contains(clicked[i])) { | ||||||
| @ -622,16 +674,6 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change | |||||||
| 				selectionModel.setSelectionPath(path); | 				selectionModel.setSelectionPath(path); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 |  | ||||||
| 		// Check for double-click |  | ||||||
| 		if (event.getClickCount() == 2) { |  | ||||||
| 			TreePath path = ComponentTreeModel.makeTreePath(clicked[0]); |  | ||||||
| 			selectionModel.setSelectionPath(path);		// Revert to single selection |  | ||||||
| 			RocketComponent component = (RocketComponent) path.getLastPathComponent(); |  | ||||||
| 
 |  | ||||||
| 			ComponentConfigDialog.showDialog(SwingUtilities.getWindowAncestor(this), |  | ||||||
| 					document, component); |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	/** | 	/** | ||||||
|  | |||||||
| @ -0,0 +1,46 @@ | |||||||
|  | package net.sf.openrocket.utils; | ||||||
|  | 
 | ||||||
|  | import java.util.TimerTask; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * This class is a custom implementation of the mouse click count listener, where you can choose the maximum | ||||||
|  |  * interval between two clicks for them to still be registered as a double click. | ||||||
|  |  * | ||||||
|  |  * @author Sibo Van Gool <sibo.vangool@hotmail.com> | ||||||
|  |  */ | ||||||
|  | public class CustomClickCountListener { | ||||||
|  |     private final int CLICK_INTERVAL; // Maximum interval between two clicks for them to still be registered as a double click (in ms) | ||||||
|  |     private int clickCnt = 0; | ||||||
|  |     private final java.util.Timer timer = new java.util.Timer("doubleClickTimer", false); | ||||||
|  | 
 | ||||||
|  |     public CustomClickCountListener() { | ||||||
|  |         this.CLICK_INTERVAL = 600;  // ms | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public CustomClickCountListener(int clickInterval) { | ||||||
|  |         this.CLICK_INTERVAL = clickInterval; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Call this method when the mouseClicked event is activated. | ||||||
|  |      */ | ||||||
|  |     public void click() { | ||||||
|  |         clickCnt++; | ||||||
|  |         if (clickCnt == 1) { | ||||||
|  |             timer.schedule(new TimerTask() { | ||||||
|  |                 @Override | ||||||
|  |                 public void run() { | ||||||
|  |                     clickCnt = 0; | ||||||
|  |                 } | ||||||
|  |             }, CLICK_INTERVAL); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Return the current click count. | ||||||
|  |      * @return the current click count | ||||||
|  |      */ | ||||||
|  |     public int getClickCount() { | ||||||
|  |         return clickCnt; | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user