use of java.awt.event.ComponentListener in project clusterMaker2 by RBVI.
the class ScatterPlotDialog method repaintScatterPlot.
public void repaintScatterPlot() {
int pointSize = 2;
try {
pointSize = Integer.parseInt(textFieldPointSize.getText());
} catch (NumberFormatException er) {
JOptionPane.showMessageDialog(null, textFieldPointSize.getText() + " is not a number", "Error: Size of point", JOptionPane.ERROR_MESSAGE);
return;
}
// Execute when button is pressed
container.remove(0);
for (ComponentListener cl : container.getComponentListeners()) container.removeComponentListener(cl);
int xAxis = 0;
int yAxis = 1;
if (variances != null) {
xAxis = comboXAxis.getSelectedIndex();
yAxis = comboYAxis.getSelectedIndex();
}
ScatterPlot scatterPlot = new ScatterPlot(manager, scores, loadings, xAxis, yAxis, pointColor, pointSize, loadingsColorMap, useLoadings);
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.insets = new Insets(5, 5, 5, 5);
constraints.gridx = 0;
constraints.gridy = 0;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
constraints.fill = GridBagConstraints.BOTH;
container.add(scatterPlot, constraints, 0);
container.updateUI();
}
use of java.awt.event.ComponentListener in project logisim-evolution by reds-heig.
the class Analyzer method addTab.
private void addTab(int index, final JComponent comp) {
final JScrollPane pane = new JScrollPane(comp, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
if (comp instanceof TableTab) {
pane.setVerticalScrollBar(((TableTab) comp).getVerticalScrollBar());
}
pane.addComponentListener(new ComponentListener() {
public void componentHidden(ComponentEvent arg0) {
}
public void componentMoved(ComponentEvent arg0) {
}
public void componentResized(ComponentEvent event) {
int width = pane.getViewport().getWidth();
comp.setSize(new Dimension(width, comp.getHeight()));
}
public void componentShown(ComponentEvent arg0) {
}
});
tabbedPane.insertTab("Untitled", null, pane, null, index);
}
use of java.awt.event.ComponentListener in project chatty by chatty.
the class LiveStreamsList method addListeners.
private void addListeners() {
ComponentListener cl = new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
// Trick from kleopatra:
// https://stackoverflow.com/questions/7306295/swing-jlist-with-multiline-text-and-dynamic-height
// next line possible if list is of type JXList
// list.invalidateCellSizeCache();
// for core: force cache invalidation by temporarily setting fixed height
setFixedCellHeight(10);
setFixedCellHeight(-1);
}
};
addComponentListener(cl);
JListActionHelper.install(this, (a, l, s) -> {
if (a == Action.CONTEXT_MENU) {
StreamInfosContextMenu m = new StreamInfosContextMenu(s, true);
for (ContextMenuListener cml : contextMenuListeners) {
m.addContextMenuListener(cml);
}
lastContextMenu = m;
m.show(this, l.x, l.y);
} else if (a == Action.ENTER) {
List<String> channels = new ArrayList<>();
s.forEach(si -> channels.add(si.stream));
for (ContextMenuListener cml : contextMenuListeners) {
cml.streamsMenuItemClicked(new ActionEvent(s, 0, "join"), channels);
}
} else if (a == Action.DOUBLE_CLICK || a == Action.SPACE) {
StreamInfo info = getSelectedValue();
if (info != null && liveStreamListener != null) {
liveStreamListener.liveStreamClicked(info);
}
}
});
}
use of java.awt.event.ComponentListener in project briefcase by opendatakit.
the class ODKOptionPane method showErrorDialog.
public static void showErrorDialog(Component parentComponent, String errorString, String title) {
// create a n-character wide label for aiding layout calculations...
// the dialog box will display this width of text.
JLabel t = new JLabel("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM");
JTextArea textArea = new JTextArea(errorString);
textArea.setEditable(false);
// same as JLabel
textArea.setFont(t.getFont());
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
// same as JLabel
textArea.setBackground(t.getBackground());
// textArea.setBackground(Color.white); // same as JLabel
// same as JLabel
textArea.setForeground(t.getForeground());
final JScrollPane scrollPane = new JScrollPane(textArea);
// don't show the gray border of the scroll pane
// unless we are showing the scroll bar, in which case we do show it.
scrollPane.setBorder(BorderFactory.createEmptyBorder());
scrollPane.getVerticalScrollBar().addComponentListener(new ComponentListener() {
@Override
public void componentHidden(ComponentEvent component) {
if (component.getComponent().equals(scrollPane.getVerticalScrollBar())) {
scrollPane.setBorder(BorderFactory.createEmptyBorder());
}
}
@Override
public void componentMoved(ComponentEvent component) {
}
@Override
public void componentResized(ComponentEvent component) {
}
@Override
public void componentShown(ComponentEvent component) {
if (component.getComponent().equals(scrollPane.getVerticalScrollBar())) {
scrollPane.setBorder(BorderFactory.createLineBorder(Color.GRAY));
}
}
});
// set preferred and minimum widths of the scroll pane to
// the width of the 't' label above with 5 lines within the scroll area.
Dimension pref = t.getPreferredSize();
pref.setSize(pref.getWidth(), 5.3 * pref.getHeight());
scrollPane.setMinimumSize(pref);
scrollPane.setPreferredSize(pref);
JOptionPane.showMessageDialog(parentComponent, scrollPane, title, JOptionPane.ERROR_MESSAGE);
}
use of java.awt.event.ComponentListener in project Universal-G-Code-Sender by winder.
the class ExperimentalWindow method main.
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
// Fix look and feel to use CMD+C/X/V/A instead of CTRL
if (SystemUtils.IS_OS_MAC) {
Collection<InputMap> ims = new ArrayList<>();
ims.add((InputMap) UIManager.get("TextField.focusInputMap"));
ims.add((InputMap) UIManager.get("TextArea.focusInputMap"));
ims.add((InputMap) UIManager.get("EditorPane.focusInputMap"));
ims.add((InputMap) UIManager.get("FormattedTextField.focusInputMap"));
ims.add((InputMap) UIManager.get("PasswordField.focusInputMap"));
ims.add((InputMap) UIManager.get("TextPane.focusInputMap"));
int c = KeyEvent.VK_C;
int v = KeyEvent.VK_V;
int x = KeyEvent.VK_X;
int a = KeyEvent.VK_A;
int meta = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
for (InputMap im : ims) {
im.put(KeyStroke.getKeyStroke(c, meta), DefaultEditorKit.copyAction);
im.put(KeyStroke.getKeyStroke(v, meta), DefaultEditorKit.pasteAction);
im.put(KeyStroke.getKeyStroke(x, meta), DefaultEditorKit.cutAction);
im.put(KeyStroke.getKeyStroke(a, meta), DefaultEditorKit.selectAllAction);
}
}
/* Create the form */
final ExperimentalWindow mw = new ExperimentalWindow();
/* Apply the settings to the ExperimentalWindow bofore showing it */
mw.setSize(mw.backend.getSettings().getMainWindowSettings().width, mw.backend.getSettings().getMainWindowSettings().height);
mw.setLocation(mw.backend.getSettings().getMainWindowSettings().xLocation, mw.backend.getSettings().getMainWindowSettings().yLocation);
mw.addComponentListener(new ComponentListener() {
@Override
public void componentResized(ComponentEvent ce) {
mw.backend.getSettings().getMainWindowSettings().height = ce.getComponent().getSize().height;
mw.backend.getSettings().getMainWindowSettings().width = ce.getComponent().getSize().width;
}
@Override
public void componentMoved(ComponentEvent ce) {
mw.backend.getSettings().getMainWindowSettings().xLocation = ce.getComponent().getLocation().x;
mw.backend.getSettings().getMainWindowSettings().yLocation = ce.getComponent().getLocation().y;
}
@Override
public void componentShown(ComponentEvent ce) {
}
@Override
public void componentHidden(ComponentEvent ce) {
}
});
/* Display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
mw.setVisible(true);
}
});
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
mw.connectionPanel.saveSettings();
mw.commandPanel.saveSettings();
if (mw.pendantUI != null) {
mw.pendantUI.stop();
}
}
});
// Check command line for a file to open.
boolean open = false;
for (String arg : args) {
if (open) {
try {
mw.backend.setGcodeFile(new File(arg));
open = false;
} catch (Exception ex) {
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
System.exit(1);
}
}
if (arg.equals("--open") || arg.equals("-o")) {
open = true;
}
}
}
Aggregations