use of java.awt.event.MouseListener in project JSettlers2 by jdmonin.
the class NewGameOptionsFrame method initInterface_Pref1.
/**
* Set up one preference row (desc label, checkbox and/or input box)
* for {@link #initInterface_UserPrefs(JPanel, GridBagLayout, GridBagConstraints)}.
* @param bp Add to this panel
* @param gbl Use this layout
* @param gbc Use these constraints
* @param key Pref key name to update in {@link #localPrefs} when changed,
* such as {@link SOCPlayerClient#PREF_BOT_TRADE_REJECT_SEC}, or {@code null}.
* If {@code hasBool} but not {@code hasInt}, will store {@link Boolean#TRUE} or {@code .FALSE} as key's value.
* If {@code hasInt} and can't parse text field contents, stores {@link Integer} 0 as key's value.
* If both bool and int, will store an {@code Integer} which is negative if checkbox is unchecked.
* @param desc Preference description text to show. If {@code hasInt}, must contain {@code "#"} placeholder.
* @param hasBool True if preference has a boolean value
* @param hasInt True if preference has an integer value
* @param initBoolVal Pref's initial boolean value, for checkbox; ignored unless {@code hasBool}
* @param initIntVal Pref's initial integer value, for input box; ignored unless {@code hasInt}
* @param pcl Callback when checkbox is checked/unchecked by clicking the box or its label, or {@code null}
* @throws IllegalArgumentException if {@code hasInt} but {@code desc} doesn't contain {@code "#"},
* or if both {@code key} and {@code pcl} are {@code null}
* @since 1.2.00
*/
private void initInterface_Pref1(final JPanel bp, final GridBagLayout gbl, final GridBagConstraints gbc, final String key, final String desc, final boolean hasBool, final boolean hasInt, final boolean initBoolVal, final int initIntVal, final PrefCheckboxListener pcl) throws IllegalArgumentException {
if ((key == null) && (pcl == null))
throw new IllegalArgumentException("null key, pcl");
// reminder: same gbc widths/weights are used in initInterface_Opt1
final Checkbox cb;
final IntTextField itf = (hasInt) ? new IntTextField(initIntVal, 3) : null;
final MouseListener ml;
if (hasBool) {
cb = new Checkbox();
cb.setState(initBoolVal);
gbc.gridwidth = 1;
gbc.weightx = 0;
gbl.setConstraints(cb, gbc);
bp.add(cb);
ml = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
final boolean makeChecked = !cb.getState();
cb.setState(makeChecked);
if (pcl != null)
pcl.stateChanged(makeChecked);
if (key != null) {
if (hasInt) {
int iv = 0;
try {
iv = Integer.parseInt(itf.getText().trim());
if (!makeChecked)
iv = -iv;
} catch (NumberFormatException nfe) {
}
localPrefs.put(key, Integer.valueOf(iv));
} else {
localPrefs.put(key, (makeChecked) ? Boolean.TRUE : Boolean.FALSE);
}
}
e.consume();
}
};
} else {
cb = null;
ml = null;
}
final int placeholderIdx;
// null or holds label with start of desc, int input field, label with rest of desc
final Panel prefp;
if (hasInt) {
placeholderIdx = desc.indexOf('#');
if (placeholderIdx == -1)
throw new IllegalArgumentException("missing '#'");
// with FlowLayout
prefp = new Panel();
try {
FlowLayout fl = (FlowLayout) (prefp.getLayout());
fl.setAlignment(FlowLayout.LEFT);
fl.setVgap(0);
fl.setHgap(0);
} catch (Exception fle) {
}
} else {
placeholderIdx = -1;
prefp = null;
}
// Any text to the left of placeholder in desc?
if (placeholderIdx > 0) {
Label L = new Label(desc.substring(0, placeholderIdx));
L.setForeground(LABEL_TXT_COLOR);
prefp.add(L);
L.addMouseListener(ml);
}
if (hasInt) {
prefp.add(itf);
// for ESC/ENTER
itf.addKeyListener(this);
if ((cb != null) || (key != null))
itf.addTextListener(new // for value store or enable/disable
TextListener() {
public void textValueChanged(TextEvent arg0) {
final String newText = itf.getText().trim();
final boolean notEmpty = (newText.length() > 0);
if (cb != null) {
if (notEmpty != cb.getState()) {
cb.setState(notEmpty);
if (pcl != null)
pcl.stateChanged(notEmpty);
}
}
if (key != null) {
int iv = 0;
try {
iv = Integer.parseInt(newText);
if ((cb != null) && !cb.getState())
iv = -iv;
} catch (NumberFormatException nfe) {
}
localPrefs.put(key, Integer.valueOf(iv));
}
}
});
}
// the text label if there is no placeholder.
if (placeholderIdx + 1 < desc.length()) {
Label L = new Label(desc.substring(placeholderIdx + 1));
L.setForeground(LABEL_TXT_COLOR);
if (prefp != null) {
prefp.add(L);
} else {
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.weightx = 1;
gbl.setConstraints(L, gbc);
bp.add(L);
}
L.addMouseListener(ml);
}
if (prefp != null) {
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.weightx = 1;
gbl.setConstraints(prefp, gbc);
bp.add(prefp);
}
if (cb != null)
cb.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ie) {
pcl.stateChanged(ie.getStateChange() == ItemEvent.SELECTED);
}
});
}
use of java.awt.event.MouseListener in project cytoscape-impl by cytoscape.
the class DingVisualStyleRenderingEngineFactory method createRenderingEngine.
@Override
public RenderingEngine<CyNetwork> createRenderingEngine(Object presentationContainer, View<CyNetwork> view) {
RenderingEngine<CyNetwork> engine = super.createRenderingEngine(presentationContainer, view);
Container component = (Container) presentationContainer;
// Remove unnecessary mouse listeners.
final int compCount = component.getComponentCount();
for (int i = 0; i < compCount; i++) {
final Component comp = component.getComponent(i);
final MouseListener[] listeners = comp.getMouseListeners();
for (MouseListener ml : listeners) comp.removeMouseListener(ml);
}
return engine;
}
use of java.awt.event.MouseListener in project Spark by igniterealtime.
the class SysTrayPlugin method initialize.
@Override
public void initialize() {
if (SystemTray.isSupported()) {
JMenuItem openMenu = new JMenuItem(Res.getString("menuitem.open"));
JMenuItem minimizeMenu = new JMenuItem(Res.getString("menuitem.hide"));
JMenuItem exitMenu = new JMenuItem(Res.getString("menuitem.exit"));
statusMenu = new JMenu(Res.getString("menuitem.status"));
JMenuItem logoutMenu = new JMenuItem(Res.getString("menuitem.logout.no.status"));
SystemTray tray = SystemTray.getSystemTray();
SparkManager.getNativeManager().addNativeHandler(this);
ChatManager.getInstance().addChatMessageHandler(chatMessageHandler);
// XEP-0085 suport (replaces the obsolete XEP-0022)
org.jivesoftware.smack.chat.ChatManager.getInstanceFor(SparkManager.getConnection()).addChatListener(this);
if (Spark.isLinux()) {
newMessageIcon = SparkRes.getImageIcon(SparkRes.MESSAGE_NEW_TRAY_LINUX);
typingIcon = SparkRes.getImageIcon(SparkRes.TYPING_TRAY_LINUX);
} else {
newMessageIcon = SparkRes.getImageIcon(SparkRes.MESSAGE_NEW_TRAY);
typingIcon = SparkRes.getImageIcon(SparkRes.TYPING_TRAY);
}
availableIcon = Default.getImageIcon(Default.TRAY_IMAGE);
if (Spark.isLinux()) {
if (availableIcon == null) {
availableIcon = SparkRes.getImageIcon(SparkRes.TRAY_IMAGE_LINUX);
Log.error(availableIcon.toString());
}
awayIcon = SparkRes.getImageIcon(SparkRes.TRAY_AWAY_LINUX);
dndIcon = SparkRes.getImageIcon(SparkRes.TRAY_DND_LINUX);
offlineIcon = SparkRes.getImageIcon(SparkRes.TRAY_OFFLINE_LINUX);
connectingIcon = SparkRes.getImageIcon(SparkRes.TRAY_CONNECTING_LINUX);
} else {
if (availableIcon == null) {
availableIcon = SparkRes.getImageIcon(SparkRes.TRAY_IMAGE);
}
awayIcon = SparkRes.getImageIcon(SparkRes.TRAY_AWAY);
dndIcon = SparkRes.getImageIcon(SparkRes.TRAY_DND);
offlineIcon = SparkRes.getImageIcon(SparkRes.TRAY_OFFLINE);
connectingIcon = SparkRes.getImageIcon(SparkRes.TRAY_CONNECTING);
}
popupMenu.add(openMenu);
openMenu.addActionListener(new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent event) {
SparkManager.getMainWindow().setVisible(true);
SparkManager.getMainWindow().toFront();
}
});
popupMenu.add(minimizeMenu);
minimizeMenu.addActionListener(new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent event) {
SparkManager.getMainWindow().setVisible(false);
}
});
// See if we should disable ability to change presence status
if (!Default.getBoolean("DISABLE_PRESENCE_STATUS_CHANGE") && Enterprise.containsFeature(Enterprise.PRESENCE_STATUS_FEATURE)) {
popupMenu.addSeparator();
addStatusMessages();
popupMenu.add(statusMenu);
}
statusMenu.addActionListener(new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent event) {
}
});
// Logout Menu
if (Spark.isWindows()) {
if (!Default.getBoolean("DISABLE_EXIT") && Enterprise.containsFeature(Enterprise.LOGOUT_EXIT_FEATURE)) {
if (!Default.getBoolean("HIDE_SAVE_PASSWORD_AND_AUTOLOGIN") && SettingsManager.getLocalPreferences().getPswdAutologin()) {
logoutMenu.addActionListener(new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
SparkManager.getMainWindow().logout(false);
}
});
popupMenu.add(logoutMenu);
}
}
}
// Exit Menu
exitMenu.addActionListener(new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
SparkManager.getMainWindow().shutdown();
}
});
if (!Default.getBoolean("DISABLE_EXIT") && Enterprise.containsFeature(Enterprise.LOGOUT_EXIT_FEATURE))
popupMenu.add(exitMenu);
/**
* If connection closed set offline tray image
*/
SparkManager.getConnection().addConnectionListener(new ConnectionListener() {
@Override
public void connected(XMPPConnection xmppConnection) {
trayIcon.setImage(availableIcon.getImage());
}
@Override
public void authenticated(XMPPConnection xmppConnection, boolean b) {
trayIcon.setImage(availableIcon.getImage());
}
@Override
public void connectionClosed() {
trayIcon.setImage(offlineIcon.getImage());
}
@Override
public void connectionClosedOnError(Exception arg0) {
trayIcon.setImage(offlineIcon.getImage());
}
@Override
public void reconnectingIn(int arg0) {
trayIcon.setImage(connectingIcon.getImage());
}
@Override
public void reconnectionSuccessful() {
trayIcon.setImage(availableIcon.getImage());
}
@Override
public void reconnectionFailed(Exception arg0) {
trayIcon.setImage(offlineIcon.getImage());
}
});
SparkManager.getSessionManager().addPresenceListener(presence -> {
if (presence.getMode() == Presence.Mode.available) {
trayIcon.setImage(availableIcon.getImage());
} else if (presence.getMode() == Presence.Mode.away || presence.getMode() == Presence.Mode.xa) {
trayIcon.setImage(awayIcon.getImage());
} else if (presence.getMode() == Presence.Mode.dnd) {
trayIcon.setImage(dndIcon.getImage());
} else {
trayIcon.setImage(availableIcon.getImage());
}
});
try {
trayIcon = new TrayIcon(availableIcon.getImage(), Default.getString(Default.APPLICATION_NAME), null);
trayIcon.setImageAutoSize(true);
trayIcon.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent event) {
// if we are using double click on tray icon
if ((!pref.isUsingSingleTrayClick() && event.getButton() == MouseEvent.BUTTON1 && event.getClickCount() % 2 == 0) || // if we using single click on tray icon
(pref.isUsingSingleTrayClick() && event.getButton() == MouseEvent.BUTTON1 && event.getClickCount() == 1)) {
// bring the mainwindow to front
if ((SparkManager.getMainWindow().isVisible()) && (SparkManager.getMainWindow().getState() == java.awt.Frame.NORMAL)) {
SparkManager.getMainWindow().setVisible(false);
} else {
SparkManager.getMainWindow().setVisible(true);
SparkManager.getMainWindow().setState(java.awt.Frame.NORMAL);
SparkManager.getMainWindow().toFront();
}
} else if (event.getButton() == MouseEvent.BUTTON1) {
SparkManager.getMainWindow().toFront();
// SparkManager.getMainWindow().requestFocus();
} else if (event.getButton() == MouseEvent.BUTTON3) {
if (popupMenu.isVisible()) {
popupMenu.setVisible(false);
} else {
double x = MouseInfo.getPointerInfo().getLocation().getX();
double y = MouseInfo.getPointerInfo().getLocation().getY();
if (Spark.isMac()) {
popupMenu.setLocation((int) x, (int) y);
} else {
popupMenu.setLocation(event.getX(), event.getY());
}
popupMenu.setInvoker(popupMenu);
popupMenu.setVisible(true);
}
}
}
@Override
public void mouseEntered(MouseEvent event) {
}
@Override
public void mouseExited(MouseEvent event) {
}
@Override
public void mousePressed(MouseEvent event) {
// on Mac i would want the window to show when i left-click the Icon
if (Spark.isMac() && event.getButton() != MouseEvent.BUTTON3) {
SparkManager.getMainWindow().setVisible(false);
SparkManager.getMainWindow().setVisible(true);
SparkManager.getMainWindow().requestFocusInWindow();
SparkManager.getMainWindow().bringFrameIntoFocus();
SparkManager.getMainWindow().toFront();
SparkManager.getMainWindow().requestFocus();
}
}
@Override
public void mouseReleased(MouseEvent event) {
}
});
tray.add(trayIcon);
} catch (Exception e) {
// Not Supported
}
} else {
Log.error("Tray don't supports on this platform.");
}
}
use of java.awt.event.MouseListener in project cardgame1 by joey101937.
the class CardLabel method init.
/**
* initializes starting values based on given card
* @param c given card
*/
private void init(Card c) {
card = c;
setForeground(c.heroClass.getColor());
setText(c.name);
setFont(cardTitleFont);
addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
CardDisplay.display(card);
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
DeckLoaderScratch.mousedOver = c;
if (host != null)
host.updatePreview();
}
@Override
public void mouseExited(MouseEvent e) {
DeckLoaderScratch.mousedOver = null;
if (host != null)
host.updatePreview();
}
});
}
use of java.awt.event.MouseListener in project cardgame1 by joey101937.
the class DeckLoaderScratch method setupInitialComponents.
/**
* initializes ui components
*/
private void setupInitialComponents() {
core = new coreJFrame(this, maker, builder);
core.setSize(625, 720);
core.setIconImage(SpriteHandler.swords);
core.setPreferredSize(new Dimension(600, 720));
if (maker == null && builder == null)
core.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
else {
System.out.println("dispose on close");
core.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
panel = new BackgroundPane(Main.BackgroundImage);
panel.setSize(core.getWidth(), core.getHeight());
// allows us to place components at indevidual xy coordinates
panel.setLayout(null);
titleLabel = new JLabel();
titleLabel.setText("Select Custom Deck to Use");
titleLabel.setSize(600, 50);
titleLabel.setFont(titleFont);
titleLabel.setLocation(90, 0);
panel.add(titleLabel);
directoryLabel = new JLabel();
// sets the text to where we will be looking for decks
directoryLabel.setText("Loading From: " + System.getProperty("user.dir") + File.separator + "Decks" + File.separator);
directoryLabel.setLocation(30, 50);
directoryLabel.setSize(600, 20);
panel.add(directoryLabel);
cardDisplay = new CardPreviewPanel(mousedOver);
cardDisplay.setSize(200, 300);
cardDisplay.setLocation(400, 250);
panel.add(cardDisplay);
isValidLabel = new JLabel();
isValidLabel.setSize(200, 100);
isValidLabel.setLocation(400, 600);
isValidLabel.setFont(cardTitleFont);
// isValidLabel.setText("Illegal Deck");
// isValidLabel.setIcon(new ImageIcon(Main.assets+"redXsmall.png"));
panel.add(isValidLabel);
isValidLabel.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
if (chosenDeck == null)
return;
if (chosenDeck.isValid()) {
maker.setLoadedCustomDeckPlayer(chosenDeck);
maker.setEnabled(true);
CardDisplay.close();
core.dispose();
return;
}
String toDisplay = "";
for (String s : chosenDeck.diagnose()) {
toDisplay += (s + "\n");
}
JOptionPane.showMessageDialog(null, toDisplay);
}
@Override
public void mousePressed(MouseEvent e) {
if (chosenDeck == null)
return;
if (chosenDeck.isValid() && maker != null) {
maker.setLoadedCustomDeckPlayer(chosenDeck);
maker.setEnabled(true);
return;
}
if (builder != null) {
if (!chosenDeck.isValid())
JOptionPane.showMessageDialog(null, "Notice: Loading invalid Deck");
builder.setEnabled(true);
core.dispose();
return;
}
String toDisplay = "";
for (String s : chosenDeck.diagnose()) {
toDisplay += (s + "\n");
}
JOptionPane.showMessageDialog(null, toDisplay);
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
deckTitleLabel = new JLabel();
deckTitleLabel.setText("");
deckTitleLabel.setSize(600, 45);
deckTitleLabel.setLocation(20, 150);
deckTitleLabel.setFont(titleFont);
panel.add(deckTitleLabel);
combo = new JComboBox();
combo.setSize(400, 40);
combo.setLocation(20, 90);
combo.addItem("No Decks Found");
panel.add(combo);
loadButton = new JButton();
loadButton.setSize(100, 40);
loadButton.setText("Load");
loadButton.setLocation(450, 90);
panel.add(loadButton);
loadButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loadButtonActionPerformed(evt);
}
});
panel.repaint();
core.add(panel);
core.setVisible(true);
core.requestFocus();
populateCombo();
}
Aggregations