use of javax.swing.event.ChangeEvent 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 javax.swing.event.ChangeEvent in project screenbird by adamhub.
the class PreviewPlayer method initView.
/**
* Creates "record from here" secondary window.
*/
private void initView() {
this.previewTimeSlider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
previewTimeSlider.repaint();
updateRecordNowButtonPosition();
scrubManager.updateTimeLabels(previewTimeSlider.getValue());
}
});
this.jfRecordFromHere = new JDialog(this.jfPreviewPlayer, "Record From Here");
this.jfRecordFromHere.setUndecorated(true);
this.jfRecordFromHere.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource(ResourceUtil.LOGO_TASKBAR)));
if (MediaUtil.osIsUnix()) {
// Renders Linux's custom view due to transparency issues.
this.jpRecordFromHere = new RecordFromHereLinux(this);
} else {
// Renders Default view
this.jpRecordFromHere = new RecordFromHereSB(this);
}
this.jfRecordFromHere.add(jpRecordFromHere);
try {
if (!AWTUtilities.isTranslucencyCapable(this.jfRecordFromHere.getGraphicsConfiguration())) {
log("Can not set transparency");
this.setBackground(new Color(64, 64, 64, 255));
this.jpRecordFromHere.setBackground(new Color(64, 64, 64, 255));
this.jpRecordFromHere.setOpaque(true);
} else {
log("Transparency is set");
AWTUtilities.setWindowOpaque(this.jfRecordFromHere, false);
}
} catch (Exception ex) {
log(ex);
}
// Hack for handling draggable JFrames on Mac OSX
this.jfRecordFromHere.getRootPane().putClientProperty("apple.awt.draggableWindowBackground", Boolean.FALSE);
this.jfRecordFromHere.pack();
this.addMouseListener(new PreivewMouseListener());
this.addMouseMotionListener(new PreviewMotionListener());
this.previewTimeSlider.addMouseMotionListener(new PreviewSliderMotionListener());
}
use of javax.swing.event.ChangeEvent in project intellij-community by JetBrains.
the class MavenArtifactSearchDialog method initComponents.
private void initComponents(Project project, String initialText, boolean classMode) {
myTabbedPane = new TabbedPaneWrapper(project);
MavenArtifactSearchPanel.Listener listener = new MavenArtifactSearchPanel.Listener() {
public void itemSelected() {
clickDefaultButton();
}
public void canSelectStateChanged(MavenArtifactSearchPanel from, boolean canSelect) {
myOkButtonStates.put(from, canSelect);
updateOkButtonState();
}
};
myArtifactsPanel = new MavenArtifactSearchPanel(project, !classMode ? initialText : "", false, listener, this, myManagedDependenciesMap);
myClassesPanel = new MavenArtifactSearchPanel(project, classMode ? initialText : "", true, listener, this, myManagedDependenciesMap);
myTabbedPane.addTab("Search for artifact", myArtifactsPanel);
myTabbedPane.addTab("Search for class", myClassesPanel);
myTabbedPane.setSelectedIndex(classMode ? 1 : 0);
myTabbedPane.getComponent().setPreferredSize(JBUI.size(900, 600));
myTabbedPane.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
updateOkButtonState();
}
});
updateOkButtonState();
}
use of javax.swing.event.ChangeEvent in project pcgen by PCGen.
the class ExperienceAdjusterView method initComponents.
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
jPanel5 = new javax.swing.JPanel();
panelChar = new javax.swing.JPanel();
characterList = new javax.swing.JList();
spCharLabel = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
enemyList = new javax.swing.JList();
jPanel6 = new javax.swing.JPanel();
jPanel7 = new javax.swing.JPanel();
jLabel7 = new javax.swing.JLabel();
experienceToAdd = new javax.swing.JTextField(6);
addExperienceToCharButton = new javax.swing.JButton();
jPanel8 = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
experienceFromCombat = new javax.swing.JLabel();
experienceMultNameLabel = new javax.swing.JLabel();
experienceMultSlider = new javax.swing.JSlider();
addExperienceToPartyButton = new javax.swing.JButton();
experienceMultLabel = new javax.swing.JLabel();
adjustCRButton = new javax.swing.JButton();
addEnemyButton = new javax.swing.JButton();
removeEnemyButton = new javax.swing.JButton();
scrollPaneChar = new JScrollPane(characterList);
scrollPaneEnemy = new JScrollPane(enemyList);
setLayout(new GridLayout(0, 1));
//$NON-NLS-1$
jPanel5.setBorder(new TitledBorder(LanguageBundle.getString("in_plugin_xp_char")));
jPanel5.setLayout(new java.awt.GridLayout(1, 0));
panelChar.setLayout(new java.awt.BorderLayout());
//$NON-NLS-1$
spCharLabel.setText(LanguageBundle.getString("in_plugin_xp_nameLvlXp"));
panelChar.add(spCharLabel, BorderLayout.NORTH);
panelChar.add(scrollPaneChar, java.awt.BorderLayout.CENTER);
jPanel5.add(panelChar);
jPanel1.setLayout(new java.awt.BorderLayout());
//$NON-NLS-1$
jLabel4.setText(LanguageBundle.getString("in_plugin_xp_nameCr"));
jPanel1.add(jLabel4, java.awt.BorderLayout.NORTH);
jPanel1.add(scrollPaneEnemy, java.awt.BorderLayout.CENTER);
add(jPanel5);
jPanel6.setLayout(new java.awt.GridLayout(1, 0));
//$NON-NLS-1$
jPanel6.setBorder(new TitledBorder(LanguageBundle.getString("in_plugin_xp_enemies")));
jPanel6.add(jPanel1);
jPanel7.setLayout(new java.awt.GridBagLayout());
// the button is after to allow the use of Tab after entering a value then pressing the button
//$NON-NLS-1$
jLabel7.setText(LanguageBundle.getString("in_plugin_xp_xpTo"));
//$NON-NLS-1$
addExperienceToCharButton.setText(LanguageBundle.getString("in_plugin_xp_selectedChar"));
addExperienceToCharButton.setEnabled(false);
gridBagConstraints = new java.awt.GridBagConstraints();
//$NON-NLS-1$
jPanel7.add(new JLabel(LanguageBundle.getString("in_plugin_xp_add")), gridBagConstraints);
jPanel7.add(experienceToAdd, gridBagConstraints);
jPanel7.add(jLabel7, gridBagConstraints);
jPanel7.add(addExperienceToCharButton, gridBagConstraints);
gridBagConstraints.weightx = 1.0;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
// add an empty horizontal glue like panel
jPanel7.add(new JPanel(), gridBagConstraints);
// Updates the button if there is a selected character
characterList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
addExperienceToCharButton.setEnabled(!characterList.isSelectionEmpty());
}
}
});
jPanel7.setBorder(BorderFactory.createEmptyBorder(0, BORDER_SIZE, 0, 0));
jPanel5.add(jPanel7);
jPanel8.setLayout(new java.awt.GridBagLayout());
//$NON-NLS-1$
jLabel5.setText(LanguageBundle.getString("in_plugin_xp_xpFromCombat"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = 2;
jPanel8.add(jLabel5, gridBagConstraints);
experienceFromCombat.setText(Integer.toString(0));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(experienceFromCombat, gridBagConstraints);
//$NON-NLS-1$
experienceMultNameLabel.setText(LanguageBundle.getString("in_plugin_xp_normal"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(experienceMultNameLabel, gridBagConstraints);
experienceMultSlider.setMaximum(10);
experienceMultSlider.setMinimum(-5);
experienceMultSlider.setValue(0);
// TODO the false value (the slider's) should not be visible, only the real one should
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridheight = 2;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
jPanel8.add(experienceMultSlider, gridBagConstraints);
experienceMultSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
double realValue = getSliderRealValue();
if (CoreUtility.doublesEqual(realValue, 0.5)) {
getExperienceMultNameLabel().setText(//$NON-NLS-1$
LanguageBundle.getString("in_plugin_xp_half"));
} else if (realValue <= 0.7) {
getExperienceMultNameLabel().setText(//$NON-NLS-1$
LanguageBundle.getString("in_plugin_xp_easier"));
} else if ((realValue > 0.7) && (realValue < 1.5)) {
getExperienceMultNameLabel().setText(//$NON-NLS-1$
LanguageBundle.getString("in_plugin_xp_normal"));
} else if (realValue >= 1.5) {
getExperienceMultNameLabel().setText(//$NON-NLS-1$
LanguageBundle.getString("in_plugin_xp_harder"));
}
if (CoreUtility.doublesEqual(realValue, 2)) {
getExperienceMultNameLabel().setText(//$NON-NLS-1$
LanguageBundle.getString("in_plugin_xp_twice"));
}
getExperienceMultLabel().setText(LanguageBundle.getPrettyMultiplier(realValue));
model.setMultiplier(realValue);
}
});
//$NON-NLS-1$
addExperienceToPartyButton.setText(LanguageBundle.getString("in_plugin_xp_addXpToParty"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(addExperienceToPartyButton, gridBagConstraints);
experienceMultLabel.setText(LanguageBundle.getPrettyMultiplier(1.0d));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(experienceMultLabel, gridBagConstraints);
//$NON-NLS-1$
adjustCRButton.setText(LanguageBundle.getString("in_plugin_xp_adjustCr"));
adjustCRButton.setEnabled(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 5;
gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(adjustCRButton, gridBagConstraints);
//$NON-NLS-1$
addEnemyButton.setText(LanguageBundle.getString("in_plugin_xp_addEnemy"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 6;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(addEnemyButton, gridBagConstraints);
//$NON-NLS-1$
removeEnemyButton.setText(LanguageBundle.getString("in_plugin_xp_removeEnemy"));
removeEnemyButton.setEnabled(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 5;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.insets = new java.awt.Insets(12, BORDER_SIZE, 0, 0);
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(removeEnemyButton, gridBagConstraints);
// Update buttons on selection change
enemyList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
adjustCRButton.setEnabled(!enemyList.isSelectionEmpty());
removeEnemyButton.setEnabled(!enemyList.isSelectionEmpty());
}
}
});
jPanel8.setBorder(BorderFactory.createEmptyBorder(0, BORDER_SIZE, 0, 0));
jPanel6.add(jPanel8);
add(jPanel6);
}
use of javax.swing.event.ChangeEvent in project ACS by ACS-Community.
the class BeanGrouper method getTimeWindowSpinner.
/**
* Initializes the TextField that will allow to input the desired Time Window for the Sampling Group.<br>
* By default the value is 10, which means 10 minutes.<br>
* Also checks for its correctness when the value changes.
* @return javax.swing.JTextField Reference to the Text Field containing the number.
*/
private JSpinner getTimeWindowSpinner() {
if (timeWindowSpinner == null) {
timeWindowSpinner = new JSpinner();
timeWindowSpinner.setToolTipText("How much data, expressed in seconds, will the trend present in the graph.");
timeWindowSpinner.setModel(new SpinnerNumberModel(5, 1, 900, 1));
timeWindowSpinner.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
setTimeWindow();
}
});
}
return timeWindowSpinner;
}
Aggregations