use of java.awt.event.KeyListener in project triplea by triplea-game.
the class SwingActionTest method testKeyReleaseListener.
@Test
public void testKeyReleaseListener(@Mock final Consumer<KeyEvent> listener) {
final KeyEvent event = mock(KeyEvent.class);
final KeyListener action = SwingAction.keyReleaseListener(listener);
action.keyReleased(event);
verify(listener).accept(event);
}
use of java.awt.event.KeyListener in project jbpm by kiegroup.
the class ChecklistUI method initializeComponent.
private void initializeComponent() {
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
getRootPane().setLayout(new BorderLayout());
getRootPane().add(panel, BorderLayout.CENTER);
JButton createButton = new JButton("New...");
createButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
create();
}
});
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(5, 5, 5, 5);
c.anchor = GridBagConstraints.WEST;
panel.add(createButton, c);
contexts = new JComboBox(new DefaultComboBoxModel());
contexts.setPreferredSize(new Dimension(80, 24));
contexts.setSize(new Dimension(80, 24));
c = new GridBagConstraints();
c.weightx = 1;
c.anchor = GridBagConstraints.EAST;
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(5, 5, 5, 5);
panel.add(contexts, c);
contexts.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
refresh();
}
});
JButton refreshButton = new JButton("Refresh");
refreshButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
refresh();
}
});
c = new GridBagConstraints();
c.insets = new Insets(5, 5, 5, 5);
panel.add(refreshButton, c);
itemTable = new JTable(1, 6);
itemTable.setRowHeight(35);
itemTable.setShowHorizontalLines(false);
itemTable.setShowVerticalLines(false);
itemTable.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
ctrl = false;
}
public void keyPressed(KeyEvent e) {
if (e.isControlDown()) {
ctrl = true;
}
}
});
itemTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
int index = e.getFirstIndex();
if (index >= 0 && index < items.size()) {
ChecklistItem item = items.get(index);
if (item.getStatus() == Status.Created) {
String actorId = getActorId();
try {
checklistManager.claimTask(actorId, item.getTaskId());
if (ctrl) {
checklistManager.abortTask(actorId, item.getTaskId());
} else {
checklistManager.completeTask(actorId, item.getTaskId());
}
} catch (Throwable t) {
// Do nothing
}
refresh();
} else if (item.getStatus() == Status.Reserved) {
String actorId = getActorId();
if (item.getActors().equals(actorId)) {
try {
if (ctrl) {
checklistManager.abortTask(actorId, item.getTaskId());
} else {
checklistManager.completeTask(actorId, item.getTaskId());
}
} catch (Throwable t) {
// Do nothing
}
refresh();
}
} else if (item.getStatus() == Status.Optional) {
try {
checklistManager.selectOptionalTask(item.getName(), Long.valueOf((String) contexts.getSelectedItem()));
} catch (Throwable t) {
// Do nothing
t.printStackTrace();
}
refresh();
}
}
}
});
// TODO:
// default width of columns
// icons for state
// not-editable
// no selection
// (scratch for aborted?)
// replace refresh, create, etc. by icon
c = new GridBagConstraints();
c.gridy = 1;
c.weightx = 1;
c.weighty = 1;
c.gridwidth = 3;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(5, 5, 5, 5);
panel.add(itemTable, c);
JLabel nameLabel = new JLabel("Logged in as:");
c = new GridBagConstraints();
c.gridy = 2;
c.insets = new Insets(5, 5, 5, 5);
c.anchor = GridBagConstraints.WEST;
panel.add(nameLabel, c);
userNameTextField = new JTextField("krisv");
userNameTextField.setPreferredSize(new Dimension(80, 20));
userNameTextField.setSize(new Dimension(80, 20));
c = new GridBagConstraints();
c.gridy = 2;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.insets = new Insets(5, 5, 5, 5);
c.anchor = GridBagConstraints.WEST;
panel.add(userNameTextField, c);
JButton createItemButton = new JButton("+");
createItemButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
createNewItem();
}
});
c = new GridBagConstraints();
c.gridy = 2;
c.insets = new Insets(5, 5, 5, 5);
c.anchor = GridBagConstraints.EAST;
panel.add(createItemButton, c);
panel.doLayout();
}
use of java.awt.event.KeyListener in project TrakEM2 by trakem2.
the class Display method makeGUI.
private void makeGUI(final Layer layer, final Object[] props) {
// gather properties
final Point p;
double mag = 1.0D;
Rectangle srcRect = null;
if (null != props) {
p = (Point) props[0];
mag = ((Double) props[1]).doubleValue();
srcRect = (Rectangle) props[2];
} else {
p = null;
}
// transparency slider
this.transp_slider = new JSlider(javax.swing.SwingConstants.HORIZONTAL, 0, 100, 100);
this.transp_slider.setBackground(Color.white);
this.transp_slider.setMinimumSize(new Dimension(250, 20));
this.transp_slider.setMaximumSize(new Dimension(250, 20));
this.transp_slider.setPreferredSize(new Dimension(250, 20));
final TransparencySliderListener tsl = new TransparencySliderListener();
this.transp_slider.addChangeListener(tsl);
this.transp_slider.addMouseListener(tsl);
for (final KeyListener kl : this.transp_slider.getKeyListeners()) {
this.transp_slider.removeKeyListener(kl);
}
// Tabbed pane on the left
this.tabs = new JTabbedPane();
this.tabs.setMinimumSize(new Dimension(250, 300));
this.tabs.setBackground(Color.white);
this.tabs.addChangeListener(tabs_listener);
// Tab 1: Patches
this.panel_patches = new RollingPanel(this, Patch.class);
this.addTab("Patches", panel_patches);
// Tab 2: Profiles
this.panel_profiles = new RollingPanel(this, Profile.class);
this.addTab("Profiles", panel_profiles);
// Tab 3: ZDisplayables
this.panel_zdispl = new RollingPanel(this, ZDisplayable.class);
this.addTab("Z space", panel_zdispl);
// Tab 4: channels
this.panel_channels = makeTabPanel();
this.scroll_channels = makeScrollPane(panel_channels);
this.channels = new Channel[4];
this.channels[0] = new Channel(this, Channel.MONO);
this.channels[1] = new Channel(this, Channel.RED);
this.channels[2] = new Channel(this, Channel.GREEN);
this.channels[3] = new Channel(this, Channel.BLUE);
// this.panel_channels.add(this.channels[0]);
addGBRow(this.panel_channels, this.channels[1], null);
addGBRow(this.panel_channels, this.channels[2], this.channels[1]);
addGBRow(this.panel_channels, this.channels[3], this.channels[2]);
this.addTab("Opacity", scroll_channels);
// Tab 5: labels
this.panel_labels = new RollingPanel(this, DLabel.class);
this.addTab("Labels", panel_labels);
// Tab 6: layers
this.panel_layers = makeTabPanel();
this.scroll_layers = makeScrollPane(panel_layers);
recreateLayerPanels(layer);
this.scroll_layers.addMouseWheelListener(canvas);
this.addTab("Layers", scroll_layers);
// Tab 7: tool options
// empty
this.tool_options = new OptionPanel();
this.scroll_options = makeScrollPane(this.tool_options);
this.scroll_options.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
this.addTab("Tool options", this.scroll_options);
// Tab 8: annotations
this.annot_editor = new JEditorPane();
// by default, nothing is selected
this.annot_editor.setEnabled(false);
this.annot_editor.setMinimumSize(new Dimension(200, 50));
this.annot_label = new JLabel("(No selected object)");
this.annot_panel = makeAnnotationsPanel(this.annot_editor, this.annot_label);
this.addTab("Annotations", this.annot_panel);
// Tab 9: filter options
this.filter_options = createFilterOptionPanel();
this.scroll_filter_options = makeScrollPane(this.filter_options);
this.scroll_filter_options.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
this.addTab("Live filter", this.scroll_filter_options);
this.ht_tabs = new Hashtable<Class<?>, RollingPanel>();
this.ht_tabs.put(Patch.class, panel_patches);
this.ht_tabs.put(Profile.class, panel_profiles);
this.ht_tabs.put(ZDisplayable.class, panel_zdispl);
this.ht_tabs.put(AreaList.class, panel_zdispl);
this.ht_tabs.put(Pipe.class, panel_zdispl);
this.ht_tabs.put(Polyline.class, panel_zdispl);
this.ht_tabs.put(Treeline.class, panel_zdispl);
this.ht_tabs.put(AreaTree.class, panel_zdispl);
this.ht_tabs.put(Connector.class, panel_zdispl);
this.ht_tabs.put(Ball.class, panel_zdispl);
this.ht_tabs.put(Dissector.class, panel_zdispl);
this.ht_tabs.put(DLabel.class, panel_labels);
this.ht_tabs.put(Stack.class, panel_zdispl);
// channels not included
// layers not included
// tools not included
// annotations not included
// Navigator
this.navigator = new DisplayNavigator(this, layer.getLayerWidth(), layer.getLayerHeight());
// Layer scroller (to scroll slices)
int extent = (int) (250.0 / layer.getParent().size());
if (extent < 10)
extent = 10;
this.scroller = new JScrollBar(JScrollBar.HORIZONTAL);
this.scroller.setModel(new ScrollerModel(layer));
updateLayerScroller(layer);
this.scroller.addAdjustmentListener(scroller_listener);
// LAYOUT
final GridBagLayout layout = new GridBagLayout();
final GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.NORTHWEST;
c.fill = GridBagConstraints.NONE;
c.weightx = 0;
c.weighty = 0;
c.gridx = 0;
c.gridy = 0;
c.ipadx = 0;
c.ipady = 0;
c.gridwidth = 1;
c.gridheight = 1;
Display.this.all = new JPanel();
all.setBackground(Color.white);
all.setLayout(layout);
c.insets = new Insets(0, 0, 0, 5);
// 1
// fixed dimensions
toolbar_panel = new ToolbarPanel();
layout.setConstraints(toolbar_panel, c);
all.add(toolbar_panel);
// 2
c.gridy++;
c.fill = GridBagConstraints.HORIZONTAL;
layout.setConstraints(transp_slider, c);
all.add(transp_slider);
// 3
c.gridy++;
c.weighty = 1;
c.fill = GridBagConstraints.BOTH;
layout.setConstraints(tabs, c);
all.add(tabs);
// 4
c.gridy++;
c.weighty = 0;
c.fill = GridBagConstraints.NONE;
layout.setConstraints(navigator, c);
all.add(navigator);
// 5
c.gridy++;
c.fill = GridBagConstraints.HORIZONTAL;
layout.setConstraints(scroller, c);
all.add(scroller);
// Canvas
this.canvas = new DisplayCanvas(this, (int) Math.ceil(layer.getLayerWidth()), (int) Math.ceil(layer.getLayerHeight()));
c.insets = new Insets(0, 0, 0, 0);
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.NORTHWEST;
c.gridx = 1;
c.gridy = 0;
c.gridheight = GridBagConstraints.REMAINDER;
c.weightx = 1;
c.weighty = 1;
layout.setConstraints(Display.this.canvas, c);
all.add(canvas);
// prevent new Displays from screwing up if input is globally disabled
if (!project.isInputEnabled())
Display.this.canvas.setReceivesInput(false);
this.canvas.addComponentListener(canvas_size_listener);
this.navigator.addMouseWheelListener(canvas);
this.transp_slider.addKeyListener(canvas);
// JFrame to show the split pane
this.frame = ControlWindow.createJFrame(layer.toString());
this.frame.setBackground(Color.white);
this.frame.getContentPane().setBackground(Color.white);
if (IJ.isMacintosh() && IJ.getInstance() != null) {
// may be needed for Java 1.4 on OS X
IJ.wait(10);
this.frame.setMenuBar(ij.Menus.getMenuBar());
}
this.frame.addWindowListener(window_listener);
// this.frame.addComponentListener(display_frame_listener);
this.frame.getContentPane().add(all);
if (null != props) {
// restore canvas
canvas.setup(mag, srcRect);
// restore visibility of each channel
// aka c_alphas_state
final int cs = ((Integer) props[5]).intValue();
final int[] sel = new int[4];
sel[0] = ((cs & 0xff000000) >> 24);
sel[1] = ((cs & 0xff0000) >> 16);
sel[2] = ((cs & 0xff00) >> 8);
sel[3] = (cs & 0xff);
// restore channel alphas
Display.this.c_alphas = ((Integer) props[4]).intValue();
channels[0].setAlpha((float) ((c_alphas & 0xff000000) >> 24) / 255.0f, 0 != sel[0]);
channels[1].setAlpha((float) ((c_alphas & 0xff0000) >> 16) / 255.0f, 0 != sel[1]);
channels[2].setAlpha((float) ((c_alphas & 0xff00) >> 8) / 255.0f, 0 != sel[2]);
channels[3].setAlpha((float) (c_alphas & 0xff) / 255.0f, 0 != sel[3]);
// restore visibility in the working c_alphas
Display.this.c_alphas = ((0 != sel[0] ? (int) (255 * channels[0].getAlpha()) : 0) << 24) + ((0 != sel[1] ? (int) (255 * channels[1].getAlpha()) : 0) << 16) + ((0 != sel[2] ? (int) (255 * channels[2].getAlpha()) : 0) << 8) + (0 != sel[3] ? (int) (255 * channels[3].getAlpha()) : 0);
}
if (null != active && null != layer) {
final Rectangle r = active.getBoundingBox();
r.x -= r.width / 2;
r.y -= r.height / 2;
r.width += r.width;
r.height += r.height;
if (r.x < 0)
r.x = 0;
if (r.y < 0)
r.y = 0;
if (r.width > layer.getLayerWidth())
r.width = (int) layer.getLayerWidth();
if (r.height > layer.getLayerHeight())
r.height = (int) layer.getLayerHeight();
final double magn = layer.getLayerWidth() / (double) r.width;
canvas.setup(magn, r);
}
// add keyListener to the whole frame
this.tabs.addKeyListener(canvas);
this.frame.addKeyListener(canvas);
// create a drag and drop listener
dnd = new DNDInsertImage(Display.this);
Utils.invokeLater(new Runnable() {
@Override
public void run() {
Display.this.frame.pack();
ij.gui.GUI.center(Display.this.frame);
Display.this.frame.setVisible(true);
// doesn't get it through events
ProjectToolbar.setProjectToolbar();
final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
if (null != props) {
// fix positioning outside the screen (dual to single monitor)
if (p.x >= 0 && p.x < screen.width - 50 && p.y >= 0 && p.y <= screen.height - 50)
Display.this.frame.setLocation(p);
else
frame.setLocation(0, 0);
}
// fix excessive size
final Rectangle box = Display.this.frame.getBounds();
int x = box.x;
int y = box.y;
int width = box.width;
int height = box.height;
if (box.width > screen.width) {
x = 0;
width = screen.width;
}
if (box.height > screen.height) {
y = 0;
height = screen.height;
}
if (x != box.x || y != box.y) {
// added insets for bad window managers
Display.this.frame.setLocation(x, y + (0 == y ? 30 : 0));
}
if (width != box.width || height != box.height) {
// added insets for bad window managers
Display.this.frame.setSize(new Dimension(width - 10, height - 30));
}
if (null == props) {
// try to optimize canvas dimensions and magn
double magn = layer.getLayerHeight() / screen.height;
if (magn > 1.0)
magn = 1.0;
long size = 0;
// limit magnification if appropriate
for (final Displayable pa : layer.getDisplayables(Patch.class)) {
final Rectangle ba = pa.getBoundingBox();
size += (long) (ba.width * ba.height);
}
if (// 10 Mb
size > 10000000)
// 10 Mb
canvas.setInitialMagnification(0.25);
else {
Display.this.frame.setSize(new Dimension((int) (screen.width * 0.66), (int) (screen.height * 0.66)));
}
}
updateTab(panel_patches);
// re-layout:
tabs.validate();
// Set the calibration of the FakeImagePlus to that of the LayerSet
((FakeImagePlus) canvas.getFakeImagePlus()).setCalibrationSuper(layer.getParent().getCalibrationCopy());
updateFrameTitle(layer);
// Set the FakeImagePlus as the current image
setTempCurrentImage();
// start a repainting thread
if (null != props) {
// repaint() is unreliable
canvas.repaint(true);
}
ControlWindow.setLookAndFeel();
}
});
}
use of java.awt.event.KeyListener in project artisynth_core by artisynth.
the class GLSparkleDebug method main.
public static void main(String[] args) {
Logger.getSystemLogger().setLogLevel(LogLevel.ALL);
GL3Utilities.debug = false;
final GLSparkleDebug sparkle = new GLSparkleDebug();
sparkle.rot.getWindows().get(0).viewer.setShading(Shading.FLAT);
sparkle.rot.getWindows().get(0).viewer.getCanvas().addKeyListener(new KeyListener() {
private void printStuff(KeyEvent e) {
// System.out.print(e.getKeyChar());
// System.out.print(" ");
// System.out.print(e.getKeyCode());
// System.out.print(" ");
// System.out.print(e.getExtendedKeyCode());
// System.out.print("\n");
}
@Override
public void keyTyped(KeyEvent e) {
printStuff(e);
}
@Override
public void keyReleased(KeyEvent e) {
printStuff(e);
}
@Override
public void keyPressed(KeyEvent e) {
printStuff(e);
if (e.getKeyCode() == KeyEvent.VK_F5) {
// re-render
sparkle.rot.rerender();
}
}
});
;
sparkle.run();
}
use of java.awt.event.KeyListener in project protege-client by protegeproject.
the class LoginDialog method dialogInit.
/**
* Called by constructors to initialize the dialog.
*
* @since ostermillerutils 1.00.00
*/
@Override
protected void dialogInit() {
name = new JTextField("", 20);
pass = new JPasswordField("", 20);
okButton = new JButton("OK");
cancelButton = new JButton("Cancel");
nameLabel = new JLabel("Username: ");
passLabel = new JLabel("Password: ");
super.dialogInit();
KeyListener keyListener = (new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE || (e.getSource() == cancelButton && e.getKeyCode() == KeyEvent.VK_ENTER)) {
pressed_OK = false;
LoginDialog.this.setVisible(false);
}
if (e.getSource() == okButton && e.getKeyCode() == KeyEvent.VK_ENTER) {
pressed_OK = true;
LoginDialog.this.setVisible(false);
}
}
});
addKeyListener(keyListener);
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == name) {
// the user pressed enter in the name field.
name.transferFocus();
} else {
// other actions close the dialog.
pressed_OK = (source == pass || source == okButton);
LoginDialog.this.setVisible(false);
}
}
};
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
c.insets.top = 5;
c.insets.bottom = 5;
JPanel pane = new JPanel(gridbag);
pane.setBorder(BorderFactory.createEmptyBorder(10, 20, 5, 20));
c.anchor = GridBagConstraints.EAST;
gridbag.setConstraints(nameLabel, c);
pane.add(nameLabel);
gridbag.setConstraints(name, c);
name.addActionListener(actionListener);
name.addKeyListener(keyListener);
pane.add(name);
c.gridy = 1;
gridbag.setConstraints(passLabel, c);
pane.add(passLabel);
gridbag.setConstraints(pass, c);
pass.addActionListener(actionListener);
pass.addKeyListener(keyListener);
pane.add(pass);
c.gridy = 2;
c.gridwidth = GridBagConstraints.REMAINDER;
c.anchor = GridBagConstraints.CENTER;
JPanel panel = new JPanel();
okButton.addActionListener(actionListener);
okButton.addKeyListener(keyListener);
panel.add(okButton);
cancelButton.addActionListener(actionListener);
cancelButton.addKeyListener(keyListener);
panel.add(cancelButton);
gridbag.setConstraints(panel, c);
pane.add(panel);
getContentPane().add(pane);
pack();
}
Aggregations