use of java.awt.event.WindowAdapter in project jabref by JabRef.
the class SearchResultFrame method init.
private void init(String title) {
searchResultFrame = new JFrame();
searchResultFrame.setTitle(title);
searchResultFrame.setIconImages(IconTheme.getLogoSet());
preview = new PreviewPanel(null, null);
sortedEntries = new SortedList<>(entries, new EntryComparator(false, true, FieldName.AUTHOR));
model = (DefaultEventTableModel<BibEntry>) GlazedListsSwing.eventTableModelWithThreadProxyList(sortedEntries, new EntryTableFormat());
entryTable = new JTable(model);
GeneralRenderer renderer = new GeneralRenderer(Color.white);
entryTable.setDefaultRenderer(JLabel.class, renderer);
entryTable.setDefaultRenderer(String.class, renderer);
setWidths();
TableComparatorChooser<BibEntry> tableSorter = TableComparatorChooser.install(entryTable, sortedEntries, AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD);
setupComparatorChooser(tableSorter);
JScrollPane sp = new JScrollPane(entryTable);
final DefaultEventSelectionModel<BibEntry> selectionModel = (DefaultEventSelectionModel<BibEntry>) GlazedListsSwing.eventSelectionModelWithThreadProxyList(sortedEntries);
entryTable.setSelectionModel(selectionModel);
selectionModel.getSelected().addListEventListener(new EntrySelectionListener());
entryTable.addMouseListener(new TableClickListener());
contentPane.setTopComponent(sp);
contentPane.setBottomComponent(preview);
// Key bindings:
AbstractAction closeAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
};
ActionMap actionMap = contentPane.getActionMap();
InputMap inputMap = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DATABASE), "close");
actionMap.put("close", closeAction);
actionMap = entryTable.getActionMap();
inputMap = entryTable.getInputMap();
//Override 'selectNextColumnCell' and 'selectPreviousColumnCell' to move rows instead of cells on TAB
actionMap.put("selectNextColumnCell", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectNextEntry();
}
});
actionMap.put("selectPreviousColumnCell", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectPreviousEntry();
}
});
actionMap.put("selectNextRow", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectNextEntry();
}
});
actionMap.put("selectPreviousRow", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectPreviousEntry();
}
});
String selectFirst = "selectFirst";
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_FIRST_ENTRY), selectFirst);
actionMap.put(selectFirst, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent event) {
selectFirstEntry();
}
});
String selectLast = "selectLast";
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_LAST_ENTRY), selectLast);
actionMap.put(selectLast, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent event) {
selectLastEntry();
}
});
actionMap.put("copy", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (!selectionModel.getSelected().isEmpty()) {
List<BibEntry> bes = selectionModel.getSelected();
TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes);
// ! look at ClipBoardManager
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trbe, frame.getCurrentBasePanel());
frame.output(Localization.lang("Copied") + ' ' + (bes.size() > 1 ? bes.size() + " " + Localization.lang("entries") : "1 " + Localization.lang("entry") + '.'));
}
}
});
// override standard enter-action; enter opens the selected entry
entryTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
actionMap.put("Enter", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent ae) {
BibEntry entry = sortedEntries.get(entryTable.getSelectedRow());
selectEntryInBasePanel(entry);
}
});
searchResultFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
contentPane.setDividerLocation(0.5f);
}
@Override
public void windowClosing(WindowEvent event) {
dispose();
}
});
searchResultFrame.getContentPane().add(contentPane, BorderLayout.CENTER);
// Remember and default to last size:
SearchPreferences searchPreferences = new SearchPreferences(Globals.prefs);
searchResultFrame.setSize(searchPreferences.getSeachDialogWidth(), searchPreferences.getSeachDialogHeight());
searchResultFrame.setLocation(searchPreferences.getSearchDialogPosX(), searchPreferences.getSearchDialogPosY());
searchResultFrame.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
new SearchPreferences(Globals.prefs).setSearchDialogWidth(searchResultFrame.getSize().width).setSearchDialogHeight(searchResultFrame.getSize().height);
}
@Override
public void componentMoved(ComponentEvent e) {
new SearchPreferences(Globals.prefs).setSearchDialogPosX(searchResultFrame.getLocation().x).setSearchDialogPosY(searchResultFrame.getLocation().y);
}
});
}
use of java.awt.event.WindowAdapter in project jabref by JabRef.
the class MergeSharedEntryDialog method showMergeDialog.
public void showMergeDialog() {
mergeDialog.setMinimumSize(new Dimension(600, 600));
StringBuilder message = new StringBuilder();
message.append("<html>");
message.append("<b>");
message.append(Localization.lang("Update could not be performed due to existing change conflicts."));
message.append("</b>");
message.append("<br/><br/>");
message.append(Localization.lang("You are not working on the newest version of BibEntry."));
message.append("<br/><br/>");
message.append(Localization.lang("Shared version: %0", String.valueOf(sharedBibEntry.getSharedBibEntryData().getVersion())));
message.append("<br/>");
message.append(Localization.lang("Local version: %0", String.valueOf(localBibEntry.getSharedBibEntryData().getVersion())));
message.append("<br/><br/>");
message.append(Localization.lang("Please merge the shared entry with yours and press \"Merge entries\" to resolve this problem."));
message.append("<br/>");
JLabel mergeInnformation = new JLabel(message.toString());
mergeInnformation.setBorder(new EmptyBorder(9, 9, 9, 9));
mergeDialog.add(mergeInnformation, BorderLayout.NORTH);
mergeDialog.add(mergeEntries.getMergeEntryPanel(), BorderLayout.CENTER);
JButton mergeButton = new JButton(Localization.lang("Merge entries"));
mergeButton.addActionListener(e -> mergeEntries());
JButton cancelButton = new JButton(Localization.lang("Cancel"));
cancelButton.addActionListener(e -> showConfirmationDialog());
JPanel buttonPanel = new JPanel();
buttonPanel.add(mergeButton, BorderLayout.WEST);
buttonPanel.add(cancelButton, BorderLayout.EAST);
mergeDialog.add(buttonPanel, BorderLayout.SOUTH);
mergeDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
mergeDialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
showConfirmationDialog();
}
});
mergeDialog.setLocationRelativeTo(jabRefFrame);
mergeDialog.pack();
mergeDialog.setVisible(true);
}
use of java.awt.event.WindowAdapter in project JMRI by JMRI.
the class PanelEditor method init.
@Override
protected void init(String name) {
Runnable r = new Runnable() {
@Override
public void run() {
try {
// Build resource catalog and load CatalogTree.xml now
jmri.jmrit.catalog.CatalogPanel catalog = new jmri.jmrit.catalog.CatalogPanel();
catalog.createNewBranch("IFJAR", "Program Directory", "resources");
} catch (Exception ex) {
log.error("Error in trying to setup preferences " + ex.toString());
}
}
};
Thread thr = new Thread(r);
thr.start();
java.awt.Container contentPane = this.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
// common items
JPanel common = new JPanel();
common.setLayout(new FlowLayout());
common.add(new JLabel(" x:"));
common.add(nextX);
common.add(new JLabel(" y:"));
common.add(nextY);
contentPane.add(common);
setAllEditable(true);
setShowHidden(true);
super.setTargetPanel(null, makeFrame(name));
super.setTargetPanelSize(400, 300);
super.setDefaultToolTip(new ToolTip(null, 0, 0, new Font("SansSerif", Font.PLAIN, 12), Color.black, new Color(215, 225, 255), Color.black));
// set scrollbar initial state
setScroll(SCROLL_BOTH);
// add menu - not using PanelMenu, because it now
// has other stuff in it?
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
menuBar.add(fileMenu);
fileMenu.add(new jmri.jmrit.display.NewPanelAction(Bundle.getMessage("MenuItemNew")));
fileMenu.add(new jmri.configurexml.StoreXmlUserAction(Bundle.getMessage("MenuItemStore")));
JMenuItem storeIndexItem = new JMenuItem(Bundle.getMessage("MIStoreImageIndex"));
fileMenu.add(storeIndexItem);
storeIndexItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
jmri.jmrit.catalog.ImageIndexEditor.storeImageIndex();
}
});
JMenuItem editItem = new JMenuItem(Bundle.getMessage("editIndexMenu"));
editItem.addActionListener(new ActionListener() {
PanelEditor panelEd;
@Override
public void actionPerformed(ActionEvent e) {
ImageIndexEditor ii = ImageIndexEditor.instance(panelEd);
ii.pack();
ii.setVisible(true);
}
ActionListener init(PanelEditor pe) {
panelEd = pe;
return this;
}
}.init(this));
fileMenu.add(editItem);
editItem = new JMenuItem(Bundle.getMessage("CPEView"));
fileMenu.add(editItem);
editItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
changeView("jmri.jmrit.display.controlPanelEditor.ControlPanelEditor");
}
});
fileMenu.addSeparator();
JMenuItem deleteItem = new JMenuItem(Bundle.getMessage("DeletePanel"));
fileMenu.add(deleteItem);
deleteItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
if (deletePanel()) {
dispose(true);
}
}
});
setJMenuBar(menuBar);
addHelpMenu("package.jmri.jmrit.display.PanelEditor", true);
// allow naming the panel
{
JPanel namep = new JPanel();
namep.setLayout(new FlowLayout());
JButton b = new JButton(Bundle.getMessage("ButtonSetName"));
b.addActionListener(new ActionListener() {
PanelEditor editor;
@Override
public void actionPerformed(ActionEvent e) {
// prompt for name
String newName = JOptionPane.showInputDialog(null, Bundle.getMessage("PromptNewName"));
if (newName == null) {
// cancelled
return;
}
if (jmri.jmrit.display.PanelMenu.instance().isPanelNameUsed(newName)) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("CanNotRename"), Bundle.getMessage("PanelExist"), JOptionPane.ERROR_MESSAGE);
return;
}
if (getTargetPanel().getTopLevelAncestor() != null) {
((JFrame) getTargetPanel().getTopLevelAncestor()).setTitle(newName);
}
editor.setTitle();
jmri.jmrit.display.PanelMenu.instance().renameEditorPanel(editor);
}
ActionListener init(PanelEditor e) {
editor = e;
return this;
}
}.init(this));
namep.add(b);
this.getContentPane().add(namep);
}
// add a text label
{
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(labelAdd);
labelAdd.setEnabled(false);
labelAdd.setToolTipText(Bundle.getMessage("ToolTipWillActivate"));
panel.add(nextLabel);
labelAdd.addActionListener(new ActionListener() {
PanelEditor editor;
@Override
public void actionPerformed(ActionEvent a) {
editor.addLabel(nextLabel.getText());
}
ActionListener init(PanelEditor e) {
editor = e;
return this;
}
}.init(this));
nextLabel.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent a) {
if (nextLabel.getText().equals("")) {
labelAdd.setEnabled(false);
labelAdd.setToolTipText(Bundle.getMessage("ToolTipWillActivate"));
} else {
labelAdd.setEnabled(true);
labelAdd.setToolTipText(null);
}
}
});
this.getContentPane().add(panel);
}
// Selection of the type of entity for the icon to represent is done from a combobox
_addIconBox = new JComboBox<ComboBoxItem>();
_addIconBox.setMinimumSize(new Dimension(75, 75));
_addIconBox.setMaximumSize(new Dimension(200, 200));
_addIconBox.addItem(new ComboBoxItem("RightTurnout"));
_addIconBox.addItem(new ComboBoxItem("LeftTurnout"));
_addIconBox.addItem(new ComboBoxItem("SlipTOEditor"));
// NOI18N
_addIconBox.addItem(new ComboBoxItem("Sensor"));
_addIconBox.addItem(new ComboBoxItem("SignalHead"));
_addIconBox.addItem(new ComboBoxItem("SignalMast"));
_addIconBox.addItem(new ComboBoxItem("Memory"));
_addIconBox.addItem(new ComboBoxItem("BlockLabel"));
_addIconBox.addItem(new ComboBoxItem("Reporter"));
_addIconBox.addItem(new ComboBoxItem("Light"));
_addIconBox.addItem(new ComboBoxItem("Background"));
_addIconBox.addItem(new ComboBoxItem("MultiSensor"));
_addIconBox.addItem(new ComboBoxItem("RPSreporter"));
_addIconBox.addItem(new ComboBoxItem("FastClock"));
_addIconBox.addItem(new ComboBoxItem("Icon"));
_addIconBox.setSelectedIndex(-1);
// must be AFTER no selection is set
_addIconBox.addItemListener(this);
JPanel p1 = new JPanel();
p1.setLayout(new BoxLayout(p1, BoxLayout.Y_AXIS));
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(new JLabel(Bundle.getMessage("selectTypeIcon")));
p1.add(p2);
p1.add(_addIconBox);
contentPane.add(p1);
// edit, position, control controls
{
// edit mode item
contentPane.add(editableBox);
editableBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setAllEditable(editableBox.isSelected());
hiddenCheckBoxListener();
}
});
editableBox.setSelected(isEditable());
// positionable item
contentPane.add(positionableBox);
positionableBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setAllPositionable(positionableBox.isSelected());
}
});
positionableBox.setSelected(allPositionable());
// controlable item
contentPane.add(controllingBox);
controllingBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setAllControlling(controllingBox.isSelected());
}
});
controllingBox.setSelected(allControlling());
// hidden item
contentPane.add(hiddenBox);
hiddenCheckBoxListener();
hiddenBox.setSelected(showHidden());
/*
contentPane.add(showCoordinatesBox);
showCoordinatesBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setShowCoordinates(showCoordinatesBox.isSelected());
}
});
showCoordinatesBox.setSelected(showCoordinates());
*/
contentPane.add(showTooltipBox);
showTooltipBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setAllShowTooltip(showTooltipBox.isSelected());
}
});
showTooltipBox.setSelected(showTooltip());
contentPane.add(menuBox);
menuBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setPanelMenuVisible(menuBox.isSelected());
}
});
menuBox.setSelected(true);
// Show/Hide Scroll Bars
JPanel scrollPanel = new JPanel();
scrollPanel.setLayout(new FlowLayout());
scrollableLabel.setLabelFor(scrollableComboBox);
scrollPanel.add(scrollableLabel);
scrollPanel.add(scrollableComboBox);
contentPane.add(scrollPanel);
scrollableComboBox.addItem(Bundle.getMessage("ScrollNone"));
scrollableComboBox.addItem(Bundle.getMessage("ScrollBoth"));
scrollableComboBox.addItem(Bundle.getMessage("ScrollHorizontal"));
scrollableComboBox.addItem(Bundle.getMessage("ScrollVertical"));
scrollableComboBox.setSelectedIndex(SCROLL_BOTH);
scrollableComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setScroll(scrollableComboBox.getSelectedIndex());
}
});
}
// register the resulting panel for later configuration
ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cm != null) {
cm.registerUser(this);
}
// when this window closes, set contents of target uneditable
addWindowListener(new java.awt.event.WindowAdapter() {
HashMap<String, JFrameItem> iconAdderFrames;
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
Iterator<JFrameItem> iter = iconAdderFrames.values().iterator();
while (iter.hasNext()) {
JFrameItem frame = iter.next();
frame.dispose();
}
}
WindowAdapter init(HashMap<String, JFrameItem> f) {
iconAdderFrames = f;
return this;
}
}.init(_iconEditorFrame));
// and don't destroy the window
setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
// move this editor panel off the panel's position
getTargetFrame().setLocationRelativeTo(this);
getTargetFrame().pack();
getTargetFrame().setVisible(true);
log.debug("PanelEditor ctor done.");
}
use of java.awt.event.WindowAdapter in project jdk8u_jdk by JetBrains.
the class JOptionPane method initDialog.
private void initDialog(final JDialog dialog, int style, Component parentComponent) {
dialog.setComponentOrientation(this.getComponentOrientation());
Container contentPane = dialog.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(this, BorderLayout.CENTER);
dialog.setResizable(false);
if (JDialog.isDefaultLookAndFeelDecorated()) {
boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();
if (supportsWindowDecorations) {
dialog.setUndecorated(true);
getRootPane().setWindowDecorationStyle(style);
}
}
dialog.pack();
dialog.setLocationRelativeTo(parentComponent);
final PropertyChangeListener listener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
// (newValue = null in that case). Otherwise, close the dialog.
if (dialog.isVisible() && event.getSource() == JOptionPane.this && (event.getPropertyName().equals(VALUE_PROPERTY)) && event.getNewValue() != null && event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) {
dialog.setVisible(false);
}
}
};
WindowAdapter adapter = new WindowAdapter() {
private boolean gotFocus = false;
public void windowClosing(WindowEvent we) {
setValue(null);
}
public void windowClosed(WindowEvent e) {
removePropertyChangeListener(listener);
dialog.getContentPane().removeAll();
}
public void windowGainedFocus(WindowEvent we) {
// Once window gets focus, set initial focus
if (!gotFocus) {
selectInitialValue();
gotFocus = true;
}
}
};
dialog.addWindowListener(adapter);
dialog.addWindowFocusListener(adapter);
dialog.addComponentListener(new ComponentAdapter() {
public void componentShown(ComponentEvent ce) {
// reset value to ensure closing works properly
setValue(JOptionPane.UNINITIALIZED_VALUE);
}
});
addPropertyChangeListener(listener);
}
use of java.awt.event.WindowAdapter in project JMRI by JMRI.
the class PaneProgAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (log.isDebugEnabled()) {
log.debug("Pane programmer requested");
}
// create the initial frame that steers
final JmriJFrame f = new JmriJFrame(SymbolicProgBundle.getMessage("FrameServiceProgrammerSetup"));
f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
// ensure status line is cleared on close so it is normal if re-opened
f.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
statusLabel.setText(SymbolicProgBundle.getMessage("StateIdle"));
f.windowClosing(we);
}
});
// add the Roster menu
JMenuBar menuBar = new JMenuBar();
// menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
JMenu j = new JMenu(SymbolicProgBundle.getMessage("MenuFile"));
j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintDecoderDefinitions"), f, false));
j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintPreviewDecoderDefinitions"), f, true));
menuBar.add(j);
menuBar.add(new jmri.jmrit.roster.swing.RosterMenu(SymbolicProgBundle.getMessage("MenuRoster"), jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
f.setJMenuBar(menuBar);
// new Loco on programming track
JPanel pane1 = new CombinedLocoSelTreePane(statusLabel, modePane) {
@Override
protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String filename) {
String title = java.text.MessageFormat.format(SymbolicProgBundle.getMessage("FrameServiceProgrammerTitle"), new Object[] { "new decoder" });
if (re != null) {
title = java.text.MessageFormat.format(SymbolicProgBundle.getMessage("FrameServiceProgrammerTitle"), new Object[] { re.getId() });
}
JFrame p = new PaneServiceProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", modePane.getProgrammer());
p.pack();
p.setVisible(true);
// f.setVisible(false);
// f.dispose();
}
};
// load primary frame
JPanel tempPane = new JPanel();
tempPane.add(modePane);
f.getContentPane().add(tempPane);
f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
pane1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
f.getContentPane().add(pane1);
f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
statusLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
f.getContentPane().add(statusLabel);
f.pack();
if (log.isDebugEnabled()) {
log.debug("Tab-Programmer setup created");
}
f.setVisible(true);
}
Aggregations