use of java.awt.event.ActionListener in project OpenNotebook by jaltekruse.
the class OCButton method addToContainer.
private void addToContainer(int gridwidth, int gridheight, int gridx, int gridy, boolean hasInsets, JComponent comp) {
setMargin(new Insets(1, 1, 1, 1));
GridBagConstraints bCon;
bCon = new GridBagConstraints();
bCon.fill = GridBagConstraints.BOTH;
bCon.weightx = .1;
bCon.weighty = .2;
bCon.gridheight = gridheight;
bCon.gridwidth = gridwidth;
bCon.gridx = gridx;
bCon.gridy = gridy;
bCon.insets = new Insets(2, 2, 2, 2);
this.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
associatedAction();
}
});
comp.add(this, bCon);
}
use of java.awt.event.ActionListener in project OpenNotebook by jaltekruse.
the class EnumeratedAdjuster method addPanelContent.
@Override
public void addPanelContent() {
if (displayFormat == COMBO_BOX) {
setLayout(new GridBagLayout());
GridBagConstraints con = new GridBagConstraints();
con.fill = GridBagConstraints.HORIZONTAL;
con.weightx = .1;
con.gridx = 0;
con.gridy = 0;
con.insets = new Insets(0, 10, 0, 0);
add(new JLabel(mAtt.getName()), con);
con.insets = new Insets(0, 10, 0, 5);
con.weightx = 1;
con.gridx = 1;
final JComboBox valueChoices = new JComboBox(mAtt.getPossibleValues());
valueChoices.setSelectedItem(mAtt.getValue());
valueChoices.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
mAtt.setValue((String) valueChoices.getSelectedItem());
if (notebookPanel != null) {
notebookPanel.getCurrentDocViewer().addUndoState();
notebookPanel.getCurrentDocViewer().repaintDoc();
}
}
});
this.add(valueChoices, con);
} else if (displayFormat == RADIO_BUTTON_ROW) {
setLayout(new GridBagLayout());
GridBagConstraints con = new GridBagConstraints();
con.fill = GridBagConstraints.HORIZONTAL;
con.weightx = .1;
con.gridwidth = mAtt.getPossibleValues().length;
con.gridx = 0;
con.gridy = 0;
con.insets = new Insets(2, 2, 2, 2);
Font f = new Font("Arial", Font.PLAIN, 12);
Font smallF = new Font("Arial", Font.PLAIN, 11);
JLabel label = new JLabel(mAtt.getName());
label.setFont(f);
add(label, con);
con.gridwidth = 1;
con.weightx = 1;
con.gridy++;
final ButtonGroup group = new ButtonGroup();
for (final String s : mAtt.getPossibleValues()) {
final JRadioButton button = new JRadioButton(s);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
mAtt.setValue(s);
if (notebookPanel != null) {
notebookPanel.getCurrentDocViewer().addUndoState();
notebookPanel.getCurrentDocViewer().repaintDoc();
}
}
});
if (mAtt.getValue().equals(s)) {
button.setSelected(true);
}
button.setFont(smallF);
this.add(button, con);
group.add(button);
con.gridx++;
}
} else if (displayFormat == RADIO_BUTTON_COLOUMN) {
}
}
use of java.awt.event.ActionListener in project OpenNotebook by jaltekruse.
the class GenericAdjustmentPanel method addPanelContent.
@Override
public void addPanelContent() {
setLayout(new GridBagLayout());
GridBagConstraints con = new GridBagConstraints();
con.fill = GridBagConstraints.HORIZONTAL;
con.weightx = .1;
con.gridx = 0;
con.gridy = 0;
con.insets = new Insets(0, 5, 0, 5);
add(new JLabel(mAtt.getName()), con);
field = new JTextField();
con.weightx = 1;
con.gridx = 1;
con.insets = new Insets(0, 0, 0, 0);
add(field, con);
if (mAtt.getValue() instanceof Double) {
int len = mAtt.getValue().toString().length();
if (len > 5) {
formatter = new Formatter();
field.setText(String.format("%.5G", mAtt.getValue()));
}
} else {
if (mAtt.getValue() == null) {
field.setText("");
} else
field.setText(mAtt.getValue().toString());
}
field.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent arg0) {
}
@Override
public void focusLost(FocusEvent arg0) {
try {
if (mAtt.getParentObject() != null) {
mAtt.getParentObject().setAttributeValueWithString(mAtt.getName(), field.getText());
} else {
mAtt.setValueWithString(field.getText());
}
if (notebookPanel != null) {
notebookPanel.getCurrentDocViewer().repaintDoc();
notebookPanel.getCurrentDocViewer().updateObjectToolFrame();
}
} catch (AttributeException e) {
if (!showingDialog) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
showingDialog = false;
}
}
}
});
field.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
applyPanelValueToObject();
}
});
}
use of java.awt.event.ActionListener in project jna by java-native-access.
the class AlphaMaskDemo2 method run.
public void run() {
// Must find a graphics configuration with a depth of 32 bits
GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
frame = new JFrame("Alpha Mask Demo");
alphaWindow = new JWindow(frame, gconfig);
icon = new JLabel();
icon.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
alphaWindow.getContentPane().add(icon);
JButton quit = new JButton("Quit");
JLabel label = new JLabel("Drag this window by its image");
label.setHorizontalAlignment(SwingConstants.CENTER);
alphaWindow.getContentPane().add(label, BorderLayout.NORTH);
alphaWindow.getContentPane().add(quit, BorderLayout.SOUTH);
quit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
MouseInputAdapter handler = new MouseInputAdapter() {
private Point offset;
public void mousePressed(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e))
offset = e.getPoint();
}
public void mouseReleased(MouseEvent e) {
offset = null;
}
public void mouseDragged(MouseEvent e) {
if (offset != null) {
Window w = (Window) e.getSource();
Point where = e.getPoint();
where.translate(-offset.x, -offset.y);
Point loc = w.getLocationOnScreen();
loc.translate(where.x, where.y);
w.setLocation(loc.x, loc.y);
}
}
};
alphaWindow.addMouseListener(handler);
alphaWindow.addMouseMotionListener(handler);
JPanel p = new JPanel(new BorderLayout(8, 8));
p.setBorder(new EmptyBorder(8, 8, 8, 8));
p.setTransferHandler(new TransferHandler() {
private static final long serialVersionUID = 1L;
public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
List<DataFlavor> list = Arrays.asList(transferFlavors);
if (list.contains(URL_FLAVOR) || list.contains(URI_LIST_FLAVOR) || list.contains(DataFlavor.imageFlavor) || list.contains(DataFlavor.javaFileListFlavor)) {
return true;
}
if (DataFlavor.selectBestTextFlavor(transferFlavors) != null) {
return true;
}
System.err.println("No acceptable flavor found in " + Arrays.asList(transferFlavors));
return false;
}
public boolean importData(JComponent comp, Transferable t) {
try {
if (t.isDataFlavorSupported(URL_FLAVOR)) {
URL url = (URL) t.getTransferData(URL_FLAVOR);
setImage(Toolkit.getDefaultToolkit().getImage(url));
return true;
}
if (t.isDataFlavorSupported(URI_LIST_FLAVOR)) {
String s = (String) t.getTransferData(URI_LIST_FLAVOR);
String[] uris = s.split("[\r\n]");
if (uris.length > 0) {
URL url = new URL(uris[0]);
setImage(Toolkit.getDefaultToolkit().getImage(url));
return true;
}
return false;
}
if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
Image image = (Image) t.getTransferData(DataFlavor.imageFlavor);
setImage(image);
return true;
}
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
List<File> files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
File f = files.get(0);
URL url = new URL("file://" + f.toURI().toURL().getPath());
Image image = Toolkit.getDefaultToolkit().getImage(url);
setImage(image);
return true;
}
DataFlavor flavor = DataFlavor.selectBestTextFlavor(t.getTransferDataFlavors());
if (flavor != null) {
Reader reader = flavor.getReaderForText(t);
char[] buf = new char[512];
StringBuilder b = new StringBuilder();
int count;
// encoding wrong
while ((count = reader.read(buf)) > 0) {
for (int i = 0; i < count; i++) {
if (buf[i] != 0)
b.append(buf, i, 1);
}
}
String html = b.toString();
Pattern p = Pattern.compile("<img.*src=\"([^\\\"\">]+)\"", Pattern.CANON_EQ | Pattern.UNICODE_CASE);
Matcher m = p.matcher(html);
if (m.find()) {
URL url = new URL(m.group(1));
System.out.println("Load image from " + url);
Image image = Toolkit.getDefaultToolkit().getImage(url);
setImage(image);
return true;
}
System.err.println("Can't parse text: " + html);
return false;
}
System.err.println("No flavor available: " + Arrays.asList(t.getTransferDataFlavors()));
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
return false;
}
});
p.add(new JLabel("<html><center>Drop an image with an alpha channel onto this window<br>" + "You may also adjust the overall transparency with the slider</center></html>"), BorderLayout.NORTH);
p.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
final JSlider slider = new JSlider(0, 255, 255);
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int value = slider.getValue();
WindowUtils.setWindowAlpha(alphaWindow, value / 255f);
}
});
p.add(slider, BorderLayout.SOUTH);
frame.getContentPane().add(p);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
centerOnScreen(frame);
frame.setVisible(true);
WindowUtils.setWindowTransparent(alphaWindow, true);
alphaWindow.setLocation(frame.getX() + frame.getWidth() + 4, frame.getY());
try {
URL url = getClass().getResource("tardis.png");
if (url != null) {
setImage(Toolkit.getDefaultToolkit().getImage(url));
}
} catch (Exception e) {
}
}
use of java.awt.event.ActionListener in project screenbird by adamhub.
the class RecorderPanel method startCountdown.
/**
* Initiates countdown and prepares for screen capture.
*/
private void startCountdown() {
final Countdown[] countdown = new Countdown[1];
countdownSec = 6;
countdownTimer = new Timer(500, new ActionListener() {
public void actionPerformed(ActionEvent e) {
countdownSec--;
log("Counting: " + countdownSec);
switch(countdownSec) {
case 0:
countdownTimer.stop();
jLabel5.setText("Recording");
btnRecordNonRec.setText("Stop");
btnRecordRec.setText("Stop");
btnPlayPauseBackup.setText("");
btnPlayPauseBackup.setIcon(pauseIcon);
btnFinalizeBackup.setEnabled(true);
// Destroy the countdown window.
countdown[0].destroy();
try {
Thread.sleep(500);
} catch (Exception ee) {
}
startRecordState();
break;
case 1:
case 2:
case 3:
case 4:
btnPlayPauseBackup.setText(String.valueOf(countdownSec));
countdown[0].destroy();
countdown[0] = new Countdown(false, recorder);
countdown[0].setCount(countdownSec);
countdown[0].setVisible(true);
try {
SoundUtil.tone(880, 500, 0.15);
} catch (LineUnavailableException ee) {
}
break;
case 5:
btnPlayPauseBackup.setText(String.valueOf(countdownSec));
// Hide drop box
if (captureBox != null) {
captureBox.setDragBoxVisible(false);
}
countdown[0] = new Countdown(false, recorder);
countdown[0].setCount(5);
countdown[0].setVisible(true);
try {
SoundUtil.tone(880, 500, 0.15);
} catch (LineUnavailableException ee) {
}
break;
}
}
});
countdownTimer.start();
}
Aggregations