use of java.awt.event.MouseListener in project lionengine by b3dgs.
the class MouseAwtTest method testClicked.
/**
* Test clicked state.
*/
@Test
void testClicked() {
final MouseAwt mouse = createMouse();
final MouseListener clicker = mouse.getClicker();
assertFalse(mouse.isPushed(MouseAwt.LEFT));
clicker.mousePressed(createEvent(MouseAwt.LEFT, 0, 0));
assertTrue(mouse.isPushed(MouseAwt.LEFT));
clicker.mouseReleased(createEvent(MouseAwt.LEFT, 0, 0));
assertFalse(mouse.isPushed(MouseAwt.LEFT));
assertFalse(mouse.isPushed(MouseAwt.RIGHT));
clicker.mousePressed(createEvent(MouseAwt.RIGHT, 0, 0));
assertTrue(mouse.isPushed(MouseAwt.RIGHT));
clicker.mouseReleased(createEvent(MouseAwt.RIGHT, 0, 0));
assertFalse(mouse.isPushed(MouseAwt.RIGHT));
}
use of java.awt.event.MouseListener in project lionengine by b3dgs.
the class MouseAwtTest method testClick.
/**
* Test click.
*/
@Test
void testClick() {
final MouseAwt mouse = createMouse();
final MouseListener clicker = mouse.getClicker();
clicker.mousePressed(createEvent(MouseAwt.MIDDLE, 0, 0));
assertEquals(MouseAwt.MIDDLE, mouse.getPushed());
clicker.mouseReleased(createEvent(MouseAwt.MIDDLE, 0, 0));
assertNotEquals(MouseAwt.MIDDLE, mouse.getPushed());
}
use of java.awt.event.MouseListener in project lionengine by b3dgs.
the class MouseAwtTest method testMouse.
/**
* Test move.
*/
@Test
void testMouse() {
final MouseAwt mouse = createMouse();
final MouseListener clicker = mouse.getClicker();
final MouseMotionListener mover = mouse.getMover();
mover.mouseMoved(createEvent(MouseAwt.LEFT, 0, 0));
mover.mouseDragged(createEvent(Integer.valueOf(0), 0, 0));
mouse.update(1.0);
assertEquals(0, mouse.getMoveX());
assertEquals(0, mouse.getMoveY());
clicker.mouseEntered(null);
clicker.mouseExited(null);
clicker.mouseClicked(null);
}
use of java.awt.event.MouseListener in project lionengine by b3dgs.
the class MouseAwtTest method testEvent.
/**
* Test event.
*/
@Test
void testEvent() {
final MouseAwt mouse = createMouse();
final AtomicBoolean left = new AtomicBoolean(false);
mouse.addActionPressed(MouseAwt.LEFT, () -> left.set(true));
mouse.addActionPressed(MouseAwt.LEFT, () -> left.set(true));
mouse.addActionReleased(MouseAwt.LEFT, () -> left.set(false));
mouse.addActionReleased(MouseAwt.LEFT, () -> left.set(false));
assertFalse(left.get());
final MouseListener clicker = mouse.getClicker();
clicker.mousePressed(createEvent(MouseAwt.LEFT, 0, 0));
assertTrue(left.get());
clicker.mouseReleased(createEvent(MouseAwt.LEFT, 0, 0));
assertFalse(left.get());
}
use of java.awt.event.MouseListener in project sldeditor by robward-scisys.
the class FileSystemExtension method initialise.
/**
* Initialise.
*
* @param parent the parent
* @param toolMgr the tool manager
*/
@Override
public void initialise(LoadSLDInterface parent, ToolSelectionInterface toolMgr) {
this.toolMgr = toolMgr;
this.parentObj = parent;
if (toolMgr != null) {
toolMgr.addRecursiveListener(this);
}
// Add extensions
List<FileSystemInterface> extensionList = FileSystemExtensionFactory.getFileExtensionList(toolMgr);
extensionPanel = new JPanel();
extensionPanel.setLayout(new BorderLayout());
extensionPanel.setPreferredSize(new Dimension(450, 400));
JPanel toolPanel = null;
if (toolMgr != null) {
toolPanel = toolMgr.getPanel();
}
if (toolPanel != null) {
extensionPanel.add(toolPanel, BorderLayout.NORTH);
}
tree = new FSTree();
tree.setRootVisible(true);
DefaultMutableTreeNode rootNode;
try {
rootNode = new DefaultMutableTreeNode(ROOT_NODE);
model = new DefaultTreeModel(rootNode);
FileSystemNodeManager.create(tree, model);
for (FileSystemInterface extension : extensionList) {
extension.populate(tree, model, rootNode);
}
} catch (SecurityException e1) {
ConsoleManager.getInstance().exception(this, e1);
}
tree.setModel(model);
tree.setDragEnabled(true);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
tree.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
treeSelected(e);
}
@Override
public void mousePressed(MouseEvent e) {
// Do nothing
}
@Override
public void mouseReleased(MouseEvent e) {
// Do nothing
}
@Override
public void mouseEntered(MouseEvent e) {
// Do nothing
}
@Override
public void mouseExited(MouseEvent e) {
// Do nothing
}
});
// Listen for Tree Selection Events
tree.addTreeExpansionListener(new TreeExpansionListener() {
/*
* (non-Javadoc)
*
* @see javax.swing.event.TreeExpansionListener#treeExpanded(javax.swing.event.
* TreeExpansionEvent)
*/
public void treeExpanded(TreeExpansionEvent evt) {
TreePath path = evt.getPath();
Object selectedItem = path.getLastPathComponent();
for (FileSystemInterface extension : extensionList) {
if (extension.treeExpanded(selectedItem)) {
((DefaultTreeModel) tree.getModel()).nodeStructureChanged((TreeNode) selectedItem);
}
}
}
/*
* (non-Javadoc)
*
* @see javax.swing.event.TreeExpansionListener#treeCollapsed(javax.swing.event.
* TreeExpansionEvent)
*/
public void treeCollapsed(TreeExpansionEvent evt) {
// Nothing to do
}
});
// Tree selection listener
tree.setTreeSelection(this);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
panel.add(new JScrollPane(tree));
extensionPanel.add(panel, BorderLayout.CENTER);
logger.debug("FileSystem initialise finished");
}
Aggregations