use of java.awt.event.ActionListener in project openblocks by mikaelhg.
the class WindowExplorer method setDrawersCard.
/**
* Reassigns the set of canvases that this explorer controls.
* Though the collection of canvas mnay be empty, it may not be null.
* @param items
*
* @requires items != null &&
* for each element in item, element!= null
*/
public void setDrawersCard(List<? extends Canvas> items) {
canvases.clear();
buttonPane.removeAll();
int size = items.size();
if (size % 2 == 1) {
size++;
}
size = buttonHeight * size;
buttonPane.setPreferredSize(new Dimension(6, size));
for (int i = 0; i < items.size(); i++) {
final int index = i;
Canvas item = items.get(i);
//final CButton button = new CButton(item.getColor(), item.getColor().brighter().brighter().brighter(),item.getName());
CButton button = new CBorderlessButton(item.getName());
JComponent scroll = new CHoverScrollPane(item.getJComponent(), ScrollPolicy.VERTICAL_BAR_AS_NEEDED, ScrollPolicy.HORIZONTAL_BAR_AS_NEEDED, 18, item.getColor(), Color.darkGray);
canvases.add(scroll);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
selectCanvas(index);
}
});
buttonPane.add(button);
}
if (!canvases.isEmpty()) {
canvasPane.add(canvases.get(0));
}
this.revalidate();
}
use of java.awt.event.ActionListener in project openblocks by mikaelhg.
the class FactoryManager method setupSubsets.
/**
* Sets up the subsets by clearing all subsets and installing
* the new collection of subsets. If "usingSys" is true,
* the the factory and myblocks drawers will be accessible.
* If "usingSubs" is true, then the subset drawers will
* be accessible.
* @param subsets - collection of subsets
* @param usingSys - true for factory and myblocks
* @param usingSubs - true for subsets
*/
public void setupSubsets(Collection<Subset> subsets, boolean usingSys, boolean usingSubs) {
if (usingSubs) {
this.subsetCanvases.clear();
for (Subset subset : subsets) {
FactoryCanvas canvas = new FactoryCanvas(subset.getName(), subset.getColor());
for (RenderableBlock frb : subset.getBlocks()) {
canvas.addBlock(frb);
workspace.notifyListeners(new WorkspaceEvent(workspace, this, frb.getBlockID(), WorkspaceEvent.BLOCK_ADDED));
}
canvas.layoutBlocks();
this.subsetCanvases.add(canvas);
}
this.navigator.setCanvas(this.subsetCanvases, SUBSETS_NAME);
if (usingSys) {
this.factorySwicther.removeAll();
this.factorySwicther.add(this.navigator.getSwitcher());
} else {
this.factorySwicther.removeAll();
this.factorySwicther.add(new CLabel(SUBSETS_NAME));
}
this.viewSubsetsDrawers();
} else if (usingSys) {
this.factorySwicther.removeAll();
final CBorderlessButton factoryButton = new CBorderlessButton(STATIC_NAME);
final CBorderlessButton myblocksButton = new CBorderlessButton(DYNAMIC_NAME);
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (factoryButton.equals(e.getSource())) {
FactoryManager.this.viewStaticDrawers();
} else if (myblocksButton.equals(e.getSource())) {
FactoryManager.this.viewDynamicDrawers();
}
}
};
factoryButton.addActionListener(listener);
myblocksButton.addActionListener(listener);
this.factorySwicther.add(factoryButton, BorderLayout.WEST);
this.factorySwicther.add(myblocksButton, BorderLayout.EAST);
this.viewStaticDrawers();
}
this.factorySwicther.revalidate();
this.factorySwicther.repaint();
}
use of java.awt.event.ActionListener in project languagetool by languagetool-org.
the class LanguageManagerDialog method show.
public void show() {
dialog = new JDialog(owner, true);
dialog.setTitle(messages.getString("guiLanguageManagerDialog"));
// close dialog when user presses Escape key:
// TODO: taken from ConfigurationDialog, avoid duplication:
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
ActionListener actionListener = new ActionListener() {
@Override
@SuppressWarnings("unused")
public void actionPerformed(ActionEvent actionEvent) {
dialog.setVisible(false);
}
};
JRootPane rootPane = dialog.getRootPane();
rootPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
Container contentPane = dialog.getContentPane();
contentPane.setLayout(new GridBagLayout());
list = new JList<>(ruleFiles.toArray(new File[ruleFiles.size()]));
GridBagConstraints cons = new GridBagConstraints();
cons.insets = new Insets(4, 4, 4, 4);
cons.gridx = 0;
cons.gridy = 0;
cons.fill = GridBagConstraints.BOTH;
cons.weightx = 2.0f;
cons.weighty = 2.0f;
contentPane.add(new JScrollPane(list), cons);
cons = new GridBagConstraints();
cons.insets = new Insets(4, 4, 4, 4);
cons.fill = GridBagConstraints.HORIZONTAL;
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridBagLayout());
addButton = new JButton(messages.getString("guiAddButton"));
addButton.addActionListener(this);
cons.gridx = 1;
cons.gridy = 0;
buttonPanel.add(addButton, cons);
removeButton = new JButton(messages.getString("guiRemoveButton"));
removeButton.addActionListener(this);
cons.gridx = 1;
cons.gridy = 1;
buttonPanel.add(removeButton, cons);
closeButton = new JButton(messages.getString("guiCloseButton"));
closeButton.addActionListener(this);
cons.gridx = 1;
cons.gridy = 2;
buttonPanel.add(closeButton, cons);
cons.gridx = 1;
cons.gridy = 0;
cons = new GridBagConstraints();
cons.anchor = GridBagConstraints.NORTH;
contentPane.add(buttonPanel, cons);
dialog.pack();
dialog.setSize(300, 200);
dialog.setLocationByPlatform(true);
dialog.setVisible(true);
}
use of java.awt.event.ActionListener in project Smack by igniterealtime.
the class EnhancedDebugger method addAdhocPacketPanel.
private void addAdhocPacketPanel() {
// Create UI elements for sending ad-hoc messages.
final JTextArea adhocMessages = new JTextArea();
adhocMessages.setEditable(true);
adhocMessages.setForeground(new Color(1, 94, 35));
tabbedPane.add("Ad-hoc message", new JScrollPane(adhocMessages));
tabbedPane.setToolTipTextAt(3, "Panel that allows you to send adhoc packets");
// Add pop-up menu.
JPopupMenu menu = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("Message");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText("<message to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"><body></body></message>");
}
});
menu.add(menuItem);
menuItem = new JMenuItem("IQ Get");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText("<iq type=\"get\" to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"><query xmlns=\"\"></query></iq>");
}
});
menu.add(menuItem);
menuItem = new JMenuItem("IQ Set");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText("<iq type=\"set\" to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"><query xmlns=\"\"></query></iq>");
}
});
menu.add(menuItem);
menuItem = new JMenuItem("Presence");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText("<presence to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"/>");
}
});
menu.add(menuItem);
menu.addSeparator();
menuItem = new JMenuItem("Send");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!"".equals(adhocMessages.getText())) {
AdHocPacket packetToSend = new AdHocPacket(adhocMessages.getText());
try {
connection.sendStanza(packetToSend);
} catch (InterruptedException | NotConnectedException e1) {
LOGGER.log(Level.WARNING, "exception", e);
}
}
}
});
menu.add(menuItem);
menuItem = new JMenuItem("Clear");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText(null);
}
});
menu.add(menuItem);
// Add listener to the text area so the popup menu can come up.
adhocMessages.addMouseListener(new PopupListener(menu));
}
use of java.awt.event.ActionListener in project apjp by jvansteirteghem.
the class Main method main.
public static void main(final String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
Security.addProvider(new IAIK());
Properties properties = new Properties();
properties.load(new FileInputStream("APJP_LOCAL.properties"));
APJP.APJP_KEY = properties.getProperty("APJP_KEY", "");
APJP.APJP_LOGGER_ID = "APJP";
APJP.APJP_LOGGER_LEVEL = 1;
APJP.APJP_LOCAL_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_PROXY_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_PROXY_SERVER";
APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTP_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_PROXY_SERVER";
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_LOCAL_HTTP_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTP_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_HTTP_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTP_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_HTTP_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_SERVER";
APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL = new String[10];
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
for (int i = 0; i < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL[i] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_URL", "");
for (int j = 0; j < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i][j] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE[i][j] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
}
}
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTPS_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_PROXY_SERVER";
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_LOCAL_HTTPS_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTPS_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_HTTPS_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTPS_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_HTTPS_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_SERVER";
APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL = new String[10];
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
for (int i = 0; i < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL[i] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_URL", "");
for (int j = 0; j < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i][j] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE[i][j] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
}
}
APJP.APJP_HTTP_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_HTTP_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_HTTP_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_HTTP_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_HTTP_PROXY_SERVER_PORT = 0;
}
APJP.APJP_HTTP_PROXY_SERVER_USERNAME = properties.getProperty("APJP_HTTP_PROXY_SERVER_USERNAME", "");
APJP.APJP_HTTP_PROXY_SERVER_PASSWORD = properties.getProperty("APJP_HTTP_PROXY_SERVER_PASSWORD", "");
APJP.APJP_HTTPS_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_HTTPS_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_HTTPS_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_HTTPS_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_HTTPS_PROXY_SERVER_PORT = 0;
}
APJP.APJP_HTTPS_PROXY_SERVER_USERNAME = properties.getProperty("APJP_HTTPS_PROXY_SERVER_USERNAME", "");
APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD = properties.getProperty("APJP_HTTPS_PROXY_SERVER_PASSWORD", "");
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
PasswordAuthentication passwordAuthentication = null;
if (this.getRequestorType() == Authenticator.RequestorType.PROXY) {
if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTP") == true) {
passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTP_PROXY_SERVER_USERNAME, APJP.APJP_HTTP_PROXY_SERVER_PASSWORD.toCharArray());
} else {
if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTPS") == true) {
passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTPS_PROXY_SERVER_USERNAME, APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD.toCharArray());
}
}
}
return passwordAuthentication;
}
});
logger = Logger.getLogger(APJP.APJP_LOGGER_ID);
final ProxyServer proxyServer = new ProxyServer();
final JTextArea outputTextArea = new JTextArea();
outputTextArea.setEditable(false);
outputTextArea.setLineWrap(true);
outputTextArea.setBackground(new Color(0, 0, 0));
outputTextArea.setForeground(new Color(255, 255, 255));
outputTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
final JScrollPane outputScrollPane = new JScrollPane(outputTextArea);
final OutputStream outputStream = new OutputStream() {
public void write(final int b) throws IOException {
outputTextArea.append(new String(new char[] { (char) b }));
}
public void write(final byte[] b, final int off, final int len) throws IOException {
outputTextArea.append(new String(b, off, len));
}
};
final PrintStream printStream = new PrintStream(outputStream, true);
System.setOut(printStream);
final JButton startButton = new JButton();
startButton.setText("Start");
startButton.setPreferredSize(new Dimension(100, 30));
startButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent actionEvent) {
outputTextArea.setText("");
logger.log(1, "START_PROXY_SERVER");
try {
proxyServer.start();
logger.log(1, "START_PROXY_SERVER: OK");
} catch (Exception e) {
logger.log(1, "START_PROXY_SERVER: EXCEPTION", e);
logger.log(1, "START_PROXY_SERVER: NOT OK");
}
HTTPRequests httpRequests = HTTPRequests.getHTTPRequests();
logger.log(1, "TEST_HTTP_REQUESTS");
try {
httpRequests.test();
logger.log(1, "TEST_HTTP_REQUESTS: OK");
} catch (Exception e) {
logger.log(1, "TEST_HTTP_REQUESTS: EXCEPTION", e);
logger.log(1, "TEST_HTTP_REQUESTS: NOT OK");
}
HTTPSRequests httpsRequests = HTTPSRequests.getHTTPSRequests();
logger.log(1, "TEST_HTTPS_REQUESTS");
try {
httpsRequests.test();
logger.log(1, "TEST_HTTPS_REQUESTS: OK");
} catch (Exception e) {
logger.log(1, "TEST_HTTPS_REQUESTS: EXCEPTION", e);
logger.log(1, "TEST_HTTPS_REQUESTS: NOT OK");
}
}
});
final JButton stopButton = new JButton();
stopButton.setText("Stop");
stopButton.setPreferredSize(new Dimension(100, 30));
stopButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent actionEvent) {
outputTextArea.setText("");
logger.log(1, "STOP_PROXY_SERVER");
try {
proxyServer.stop();
logger.log(1, "STOP_PROXY_SERVER: OK");
} catch (Exception e) {
logger.log(1, "STOP_PROXY_SERVER: EXCEPTION", e);
logger.log(1, "STOP_PROXY_SERVER: NOT OK");
}
}
});
final Panel buttonPanel = new Panel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
buttonPanel.add(startButton);
buttonPanel.add(stopButton);
final ImageIcon imageIcon = new ImageIcon("APJP_LOCAL.png");
final JFrame frame = new JFrame();
frame.setIconImage(imageIcon.getImage());
frame.setSize(675, 375);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(buttonPanel, BorderLayout.NORTH);
frame.add(outputScrollPane, BorderLayout.CENTER);
if (SystemTray.isSupported()) {
final TrayIcon trayIcon = new TrayIcon(imageIcon.getImage());
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent actionEvent) {
frame.setVisible(!frame.isVisible());
}
});
SystemTray.getSystemTray().add(trayIcon);
}
frame.setVisible(true);
} catch (Exception e) {
logger.log(1, "EXCEPTION", e);
}
}
});
}
Aggregations