use of java.awt.event.ComponentAdapter in project Spark by igniterealtime.
the class BroadcastDialog method invokeDialog.
/**
* Displays the broadcast dialog.
*/
public void invokeDialog() {
final JDialog dlg;
TitlePanel titlePanel;
// Create the title panel for this dialog
titlePanel = new TitlePanel(Res.getString("title.broadcast.message"), Res.getString("message.enter.broadcast.message"), null, true);
// Construct main panel w/ layout.
final JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(titlePanel, BorderLayout.NORTH);
// The user should only be able to close this dialog.
JButton okButton = new JButton(Res.getString("ok"));
JButton closeButton = new JButton(Res.getString("close"));
mainPanel.add(this, BorderLayout.CENTER);
JPanel buttonpanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
buttonpanel.add(okButton);
buttonpanel.add(closeButton);
mainPanel.add(buttonpanel, BorderLayout.SOUTH);
dlg = new JDialog(SparkManager.getMainWindow(), Res.getString("broadcast"));
dlg.setContentPane(mainPanel);
dlg.pack();
final Rectangle bounds = LayoutSettingsManager.getLayoutSettings().getBroadcastMessageBounds();
if (bounds == null || bounds.width <= 0 || bounds.height <= 0) {
// Use default settings.
dlg.setSize(800, 600);
dlg.setLocationRelativeTo(null);
} else {
dlg.setBounds(bounds);
}
dlg.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
LayoutSettingsManager.getLayoutSettings().setBroadcastMessageBounds(dlg.getBounds());
}
@Override
public void componentMoved(ComponentEvent e) {
LayoutSettingsManager.getLayoutSettings().setBroadcastMessageBounds(dlg.getBounds());
}
});
dlg.setResizable(false);
// Add listener
okButton.addActionListener(e -> {
try {
if (sendBroadcasts(dlg)) {
dlg.setVisible(false);
}
} catch (SmackException.NotConnectedException e1) {
Log.warning("Unable to broadcast.", e1);
}
});
closeButton.addActionListener(e -> dlg.setVisible(false));
dlg.setVisible(true);
dlg.toFront();
dlg.requestFocus();
messageBox.requestFocus();
}
use of java.awt.event.ComponentAdapter in project Spark by igniterealtime.
the class BroadcastHistoryFrame method initComponents.
private void initComponents() {
SearchButton = new javax.swing.JToggleButton();
DateField = new javax.swing.JFormattedTextField();
SearchDate = new javax.swing.JLabel();
Date date = new Date();
Format formatter = new SimpleDateFormat("yyy-MM");
String myDate = formatter.format(date);
DateField.setValue(myDate);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
JScrollPane panelPane = new JScrollPane(BroadcastHistoryArea);
SearchDate.setText(Res.getString("label.broadcast.history.search.date"));
setTitle(Res.getString("title.broadcast.history"));
try {
readFromFile(myDate);
} catch (IOException ex) {
Log.error("Couldn't read from file" + ex.getMessage() + Arrays.toString(ex.getStackTrace()));
}
SearchButton.setText((Res.getString("button.search")));
SearchButton.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
SearchButtonMouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(panelPane, javax.swing.GroupLayout.DEFAULT_SIZE, 533, javax.swing.GroupLayout.DEFAULT_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(SearchDate).addComponent(SearchButton).addComponent(DateField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(22, 22, 22)));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(15, 15, 15).addComponent(panelPane, javax.swing.GroupLayout.DEFAULT_SIZE, 350, javax.swing.GroupLayout.DEFAULT_SIZE)).addGroup(layout.createSequentialGroup().addGap(15, 15, 15).addComponent(SearchDate).addGap(10, 10, 10).addComponent(DateField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(10, 10, 10).addComponent(SearchButton))).addContainerGap(15, Short.MAX_VALUE)));
pack();
final Rectangle bounds = LayoutSettingsManager.getLayoutSettings().getBroadcastHistoryBounds();
if (bounds == null || bounds.width <= 0 || bounds.height <= 0) {
// Use default settings.
setLocationRelativeTo(null);
} else {
setBounds(bounds);
}
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
LayoutSettingsManager.getLayoutSettings().setBroadcastHistoryBounds(getBounds());
}
@Override
public void componentMoved(ComponentEvent e) {
LayoutSettingsManager.getLayoutSettings().setBroadcastHistoryBounds(getBounds());
}
});
}
use of java.awt.event.ComponentAdapter 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, favFirst, dockedHelper.isDocked());
m.setSorting(currentSorting.key);
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) {
if (s != null && !s.isEmpty() && liveStreamListener != null) {
liveStreamListener.liveStreamClicked(s);
}
}
});
}
use of java.awt.event.ComponentAdapter in project triplea by triplea-game.
the class BattleCalculatorDialog method show.
/**
* Shows the Odds Calculator dialog and initializes it using the current state of the specified
* territory.
*/
public static void show(final TripleAFrame taFrame, final Territory t, final GameData data) {
// Note: The data param may not be the same as taFrame.getGame().getData() as GameData gets
// cloned when showing history with a different History instance that doesn't correspond to
// what's shown.
final BattleCalculatorPanel panel = new BattleCalculatorPanel(data, taFrame.getUiContext(), t);
final BattleCalculatorDialog dialog = new BattleCalculatorDialog(panel, taFrame);
dialog.pack();
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowActivated(final WindowEvent e) {
instances.remove(dialog);
instances.add(dialog);
}
@Override
public void windowClosed(final WindowEvent e) {
if (taFrame.getUiContext() != null && !taFrame.getUiContext().isShutDown()) {
taFrame.getUiContext().removeShutdownWindow(dialog);
}
}
});
dialog.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(final ComponentEvent e) {
final Dimension size = dialog.getSize();
size.width = Math.min(size.width, taFrame.getWidth() - 50);
size.height = Math.min(size.height, taFrame.getHeight() - 50);
dialog.setSize(size);
}
});
taFrame.getTerritoryDetails().addBattleCalculatorKeyBindings(dialog);
// close when hitting the escape key
SwingKeyBinding.addKeyBinding(dialog, KeyCode.ESCAPE, () -> {
dialog.setVisible(false);
dialog.dispose();
});
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
if (lastPosition == null) {
dialog.setLocationRelativeTo(taFrame);
} else {
dialog.setLocation(lastPosition);
}
dialog.setVisible(true);
// On some desktop environments, there is an odd behaviour: The new battle calculator dialog is
// not put at the front if the last user-interaction was to move the window of an already
// existing battle calculator dialog. Oddly enough, calling toFront() directly here (before or
// after setVisible(true)) has no effect either, but delaying the call to the end of the queue
// of the Event Dispatch Thread solves the issue (though you can see the new dialog in the
// background for an blink of an eye).
// Tested with Cinnamon Desktop 4.8.5.
SwingUtilities.invokeLater(dialog::toFront);
taFrame.getUiContext().addShutdownWindow(dialog);
}
use of java.awt.event.ComponentAdapter in project cayenne by apache.
the class CayenneModelerFrame method initToolbar.
/**
* Initializes main toolbar.
*/
protected void initToolbar() {
final JToolBar toolBar = new MainToolBar();
Dimension smallBtnDim = new Dimension(30, 30);
JButton backButton = getAction(NavigateBackwardAction.class).buildButton(1);
backButton.setMinimumSize(smallBtnDim);
backButton.setPreferredSize(smallBtnDim);
toolBar.add(backButton);
JButton forwardButton = getAction(NavigateForwardAction.class).buildButton(3);
forwardButton.setMinimumSize(smallBtnDim);
forwardButton.setPreferredSize(smallBtnDim);
toolBar.add(forwardButton);
toolBar.addSeparator(new Dimension(30, 0));
toolBar.add(getAction(NewProjectAction.class).buildButton(1));
toolBar.add(getAction(OpenProjectAction.class).buildButton(2));
toolBar.add(getAction(SaveAction.class).buildButton(3));
toolBar.addSeparator();
JButton removeButton = getAction(RemoveAction.class).buildButton();
toolBar.add(removeButton);
toolBar.addSeparator();
toolBar.add(getAction(CutAction.class).buildButton(1));
toolBar.add(getAction(CopyAction.class).buildButton(2));
toolBar.add(getAction(PasteAction.class).buildButton(3));
toolBar.addSeparator();
toolBar.add(getAction(UndoAction.class).buildButton(1));
toolBar.add(getAction(RedoAction.class).buildButton(3));
toolBar.addSeparator();
toolBar.add(getAction(CreateNodeAction.class).buildButton(1));
toolBar.add(getAction(CreateDataMapAction.class).buildButton(3));
toolBar.addSeparator();
toolBar.add(getAction(CreateDbEntityAction.class).buildButton(1));
toolBar.add(getAction(CreateProcedureAction.class).buildButton(3));
toolBar.addSeparator();
toolBar.add(getAction(CreateObjEntityAction.class).buildButton(1));
toolBar.add(getAction(CreateEmbeddableAction.class).buildButton(2));
toolBar.add(getAction(CreateQueryAction.class).buildButton(3));
// is used to place search feature components the most right on a toolbar
toolBar.add(new SearchPanel());
getContentPane().add(toolBar, BorderLayout.NORTH);
// Hide some buttons when frame is too small
final int defaultBtnWidth = removeButton.getUI().getPreferredSize(backButton).width;
addComponentListener(new ComponentAdapter() {
private final int[] empty = {};
private final int[] all = { 6, 7, 8, 9, 10, 11, 12, 13, 14 };
private final int[] remove = { 6, 7 };
private final int[] removeAndCopy = { 6, 7, 8, 9, 10, 11 };
private final int[] undo = { 12, 13, 14 };
private final int[] undoAndCopy = { 8, 9, 10, 11, 12, 13, 14 };
@Override
public void componentResized(ComponentEvent e) {
int[] hidden, shown;
if (getSize().width < (13 * defaultBtnWidth + 300)) {
hidden = all;
shown = empty;
} else if (getSize().width < (16 * defaultBtnWidth + 300)) {
hidden = removeAndCopy;
shown = undo;
} else if (getSize().width < (18 * defaultBtnWidth + 300)) {
hidden = remove;
shown = undoAndCopy;
} else {
hidden = empty;
shown = all;
}
for (int i : hidden) {
toolBar.getComponentAtIndex(i).setVisible(false);
}
for (int i : shown) {
toolBar.getComponentAtIndex(i).setVisible(true);
}
}
});
}
Aggregations