use of java.awt.event.MouseListener in project JMRI by JMRI.
the class JmriJFrameServlet method sendClick.
void sendClick(String name, Component c, int xg, int yg, Container FrameContentPane) {
// global positions
int x = xg - c.getLocation().x;
int y = yg - c.getLocation().y;
// log.debug("component is {}", c);
log.debug("Local click at {},{}", x, y);
if (c.getClass().equals(JButton.class)) {
((AbstractButton) c).doClick();
} else if (c.getClass().equals(JCheckBox.class)) {
((AbstractButton) c).doClick();
} else if (c.getClass().equals(JRadioButton.class)) {
((AbstractButton) c).doClick();
} else if (MouseListener.class.isAssignableFrom(c.getClass())) {
log.debug("Invoke directly on MouseListener, at {},{}", x, y);
sendClickSequence((MouseListener) c, c, x, y);
} else if (c instanceof jmri.jmrit.display.MultiSensorIcon) {
log.debug("Invoke Clicked on MultiSensorIcon");
MouseEvent e = new MouseEvent(c, MouseEvent.MOUSE_CLICKED, // time
0, // modifiers
0, // this component expects global positions for some reason
xg, // this component expects global positions for some reason
yg, // one click
1, // not a popup
false);
((Positionable) c).doMouseClicked(e);
} else if (Positionable.class.isAssignableFrom(c.getClass())) {
log.debug("Invoke Pressed, Released and Clicked on Positionable");
MouseEvent e = new MouseEvent(c, MouseEvent.MOUSE_PRESSED, // time
0, // modifiers
0, // x, y not in this component?
x, // x, y not in this component?
y, // one click
1, // not a popup
false);
((jmri.jmrit.display.Positionable) c).doMousePressed(e);
e = new MouseEvent(c, MouseEvent.MOUSE_RELEASED, // time
0, // modifiers
0, // x, y not in this component?
x, // x, y not in this component?
y, // one click
1, // not a popup
false);
((jmri.jmrit.display.Positionable) c).doMouseReleased(e);
e = new MouseEvent(c, MouseEvent.MOUSE_CLICKED, // time
0, // modifiers
0, // x, y not in this component?
x, // x, y not in this component?
y, // one click
1, // not a popup
false);
((jmri.jmrit.display.Positionable) c).doMouseClicked(e);
} else {
MouseListener[] la = c.getMouseListeners();
log.debug("Invoke {} contained mouse listeners", la.length);
log.debug("component is {}", c);
// y -= (int)(pc.getY() - pf.getY());
for (MouseListener ml : la) {
log.debug("Send click sequence at {},{}", x, y);
sendClickSequence(ml, c, x, y);
}
}
}
use of java.awt.event.MouseListener in project JMRI by JMRI.
the class SlotMonPane method initComponents.
@Override
public void initComponents(jmri.jmrix.loconet.LocoNetSystemConnectionMemo memo) {
super.initComponents(memo);
slotModel = new SlotMonDataModel(128, 16, memo);
slotTable = new JTable(slotModel);
slotTable.setRowSorter(new TableRowSorter<>(slotModel));
slotScroll = new JScrollPane(slotTable);
// configure items for GUI
showAllCheckBox.setText(Bundle.getMessage("TextSlotMonShowUnused"));
showAllCheckBox.setVisible(true);
showAllCheckBox.setSelected(false);
showAllCheckBox.setToolTipText(Bundle.getMessage("TooltipSlotMonShowUnused"));
showSystemCheckBox.setText(Bundle.getMessage("TextSlotMonShowSystem"));
showSystemCheckBox.setVisible(true);
showSystemCheckBox.setSelected(false);
showSystemCheckBox.setToolTipText(Bundle.getMessage("TooltipSlotMonShowSystem"));
slotModel.configureTable(slotTable);
// add listener object so checkboxes function
showAllCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
slotModel.showAllSlots(showAllCheckBox.isSelected());
slotModel.fireTableDataChanged();
}
});
showSystemCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
slotModel.showSystemSlots(showSystemCheckBox.isSelected());
slotModel.fireTableDataChanged();
}
});
// add listener object so stop all button functions
estopAllButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
slotModel.estopAll();
}
});
estopAllButton.addMouseListener(new MouseListener() {
@Override
public void mousePressed(MouseEvent e) {
slotModel.estopAll();
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
});
//Jeffrey 6/29/2013
clearAllButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
slotModel.clearAllSlots();
}
});
// adjust model to default settings
slotModel.showAllSlots(showAllCheckBox.isSelected());
slotModel.showSystemSlots(showSystemCheckBox.isSelected());
// general GUI config
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
// install items in GUI
JPanel pane1 = new JPanel();
pane1.setLayout(new FlowLayout());
pane1.add(showAllCheckBox);
pane1.add(showSystemCheckBox);
pane1.add(estopAllButton);
pane1.add(clearAllButton);
add(pane1);
add(slotScroll);
//pane1.setMaximumSize(new java.awt.Dimension(100,300));
if (pane1.getMaximumSize().height > 0 && pane1.getMaximumSize().width > 0) {
pane1.setMaximumSize(pane1.getPreferredSize());
}
}
use of java.awt.event.MouseListener in project freeplane by freeplane.
the class SpellChecker method enablePopup.
/**
* Enable or disable the popup menu with the menu item "Orthography" and "Languages".
* @param text the JTextComponent that should change
* @param enable true, enable the feature.
*/
public static void enablePopup(final JTextComponent text, final boolean enable) {
if (enable) {
final JPopupMenu menu = new JPopupMenu();
menu.add(SpellChecker.createCheckerMenu());
menu.add(SpellChecker.createLanguagesMenu());
text.addMouseListener(new PopupListener(menu));
} else {
for (final MouseListener listener : text.getMouseListeners()) {
if (listener instanceof PopupListener) {
text.removeMouseListener(listener);
}
}
}
}
use of java.awt.event.MouseListener in project artisynth_core by artisynth.
the class LabeledComponentPanel method doAddWidget.
protected void doAddWidget(Component comp, int idx) {
boolean resetNeeded = false;
LabeledComponentPanel topPanel = null;
if (comp instanceof HasAlignableLabels) {
if (comp instanceof LabeledComponent) {
((LabeledComponent) comp).setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
} else if (comp instanceof LabeledPanel) {
((LabeledPanel) comp).setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
}
topPanel = getTopPanel(this);
HasAlignableLabels lcomp = (HasAlignableLabels) comp;
LabelSpacing spc = new LabelSpacing();
LabelSpacing top = new LabelSpacing();
lcomp.getPreferredLabelSpacing(spc);
topPanel.getLabelSpacing(top);
top.labelWidth -= getLeftInsetToTop();
if (spc.labelWidth > top.labelWidth || spc.preSpacing > top.preSpacing) {
resetNeeded = true;
} else {
if (spc.expand(top)) {
lcomp.setLabelSpacing(spc);
}
}
}
if (comp instanceof JComponent) {
JComponent jcomp = (JComponent) comp;
jcomp.setAlignmentX(Component.LEFT_ALIGNMENT);
// Prevent JSeparators from acting as stretchable components:
if (jcomp instanceof JSeparator) {
Dimension maxsize = new Dimension(jcomp.getMaximumSize());
maxsize.height = jcomp.getPreferredSize().height;
jcomp.setMaximumSize(maxsize);
}
}
myWidgets.add(idx, comp);
if (resetNeeded) {
topPanel.resetLabelAlignment();
}
// mouse events.
for (MouseListener l : getMouseListeners()) {
comp.addMouseListener(l);
}
for (MouseMotionListener l : getMouseMotionListeners()) {
comp.addMouseMotionListener(l);
}
}
use of java.awt.event.MouseListener in project lotro-companion by dmorcellet.
the class EquipmentPanelController method buildPanel.
private JPanel buildPanel() {
JPanel panel = GuiFactory.buildPanel(null);
_layeredPane = new JLayeredPane();
panel.add(_layeredPane, BorderLayout.CENTER);
Dimension d = computeDimensions();
panel.setPreferredSize(d);
panel.setMinimumSize(d);
_layeredPane.setSize(d);
MouseListener listener = buildRightClickListener();
for (EQUIMENT_SLOT slot : EQUIMENT_SLOT.values()) {
// Position for item
Dimension position = _iconPositions.get(slot);
// Add object icon
// - icon controller
EquipmentSlotIconController iconController = new EquipmentSlotIconController(slot);
_icons.put(slot, iconController);
ImageIcon icon = iconController.getIcon();
// - button
JButton button = new JButton(icon);
button.setBorderPainted(false);
button.setMargin(new Insets(0, 0, 0, 0));
button.setBounds(position.width, position.height, ICON_SIZE, ICON_SIZE);
_layeredPane.add(button, ICONS_DEPTH);
_buttons.put(slot, button);
button.setActionCommand(SLOT_SEED + slot.name());
button.addActionListener(this);
button.addMouseListener(listener);
button.setToolTipText("");
}
updateIcons();
return panel;
}
Aggregations