use of java.util.EventObject in project intellij-community by JetBrains.
the class AbstractValueHint method showHint.
protected boolean showHint(final JComponent component) {
myInsideShow = true;
if (myCurrentHint != null) {
myCurrentHint.hide();
}
myCurrentHint = new LightweightHint(component) {
@Override
protected boolean canAutoHideOn(TooltipEvent event) {
InputEvent inputEvent = event.getInputEvent();
if (inputEvent instanceof MouseEvent) {
Component comp = inputEvent.getComponent();
if (comp instanceof EditorComponentImpl) {
EditorImpl editor = ((EditorComponentImpl) comp).getEditor();
return !isInsideCurrentRange(editor, ((MouseEvent) inputEvent).getPoint());
}
}
return true;
}
};
myCurrentHint.addHintListener(new HintListener() {
@Override
public void hintHidden(EventObject event) {
if (myHideRunnable != null && !myInsideShow) {
myHideRunnable.run();
}
onHintHidden();
}
});
// editor may be disposed before later invokator process this action
if (myEditor.isDisposed() || myEditor.getComponent().getRootPane() == null) {
return false;
}
Point p = HintManagerImpl.getHintPosition(myCurrentHint, myEditor, myEditor.xyToLogicalPosition(myPoint), HintManager.UNDER);
HintHint hint = HintManagerImpl.createHintHint(myEditor, p, myCurrentHint, HintManager.UNDER, true);
hint.setShowImmediately(true);
HintManagerImpl.getInstanceImpl().showEditorHint(myCurrentHint, myEditor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false, hint);
myInsideShow = false;
return true;
}
use of java.util.EventObject in project intellij-community by JetBrains.
the class ShowUIDefaultsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final UIDefaults defaults = UIManager.getDefaults();
Enumeration keys = defaults.keys();
final Object[][] data = new Object[defaults.size()][2];
int i = 0;
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
data[i][0] = key;
data[i][1] = defaults.get(key);
i++;
}
Arrays.sort(data, (o1, o2) -> StringUtil.naturalCompare(o1[0].toString(), o2[0].toString()));
final Project project = getEventProject(e);
new DialogWrapper(project) {
{
setTitle("Edit LaF Defaults");
setModal(false);
init();
}
public JBTable myTable;
@Nullable
@Override
public JComponent getPreferredFocusedComponent() {
return myTable;
}
@Nullable
@Override
protected String getDimensionServiceKey() {
return project == null ? null : "UI.Defaults.Dialog";
}
@Override
protected JComponent createCenterPanel() {
final JBTable table = new JBTable(new DefaultTableModel(data, new Object[] { "Name", "Value" }) {
@Override
public boolean isCellEditable(int row, int column) {
return column == 1 && getValueAt(row, column) instanceof Color;
}
}) {
@Override
public boolean editCellAt(int row, int column, EventObject e) {
if (isCellEditable(row, column) && e instanceof MouseEvent) {
final Object color = getValueAt(row, column);
final Color newColor = ColorPicker.showDialog(this, "Choose Color", (Color) color, true, null, true);
if (newColor != null) {
final ColorUIResource colorUIResource = new ColorUIResource(newColor);
final Object key = getValueAt(row, 0);
UIManager.put(key, colorUIResource);
setValueAt(colorUIResource, row, column);
}
}
return false;
}
};
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final JPanel panel = new JPanel(new BorderLayout());
final JLabel label = new JLabel(value == null ? "" : value.toString());
panel.add(label, BorderLayout.CENTER);
if (value instanceof Color) {
final Color c = (Color) value;
label.setText(String.format("[r=%d,g=%d,b=%d] hex=0x%s", c.getRed(), c.getGreen(), c.getBlue(), ColorUtil.toHex(c)));
label.setForeground(ColorUtil.isDark(c) ? Color.white : Color.black);
panel.setBackground(c);
return panel;
} else if (value instanceof Icon) {
try {
final Icon icon = new IconWrap((Icon) value);
if (icon.getIconHeight() <= 20) {
label.setIcon(icon);
}
label.setText(String.format("(%dx%d) %s)", icon.getIconWidth(), icon.getIconHeight(), label.getText()));
} catch (Throwable e1) {
//
}
return panel;
} else if (value instanceof Border) {
try {
final Insets i = ((Border) value).getBorderInsets(null);
label.setText(String.format("[%d, %d, %d, %d] %s", i.top, i.left, i.bottom, i.right, label.getText()));
return panel;
} catch (Exception ignore) {
}
}
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
});
final JBScrollPane pane = new JBScrollPane(table);
new TableSpeedSearch(table, (o, cell) -> cell.column == 1 ? null : String.valueOf(o));
table.setShowGrid(false);
final JPanel panel = new JPanel(new BorderLayout());
panel.add(pane, BorderLayout.CENTER);
myTable = table;
TableUtil.ensureSelectionExists(myTable);
return panel;
}
}.show();
}
use of java.util.EventObject in project intellij-community by JetBrains.
the class FileColorSettingsTable method editCellAt.
@Override
public boolean editCellAt(int row, int column, EventObject e) {
if (e == null || (e instanceof MouseEvent && ((MouseEvent) e).getClickCount() == 1))
return false;
final Object at = getModel().getValueAt(row, column);
if (!(at instanceof FileColorConfiguration))
return false;
final FileColorConfigurationEditDialog dialog = new FileColorConfigurationEditDialog(myManager, ((FileColorConfiguration) at));
dialog.getScopeComboBox().setEnabled(false);
dialog.show();
return false;
}
use of java.util.EventObject in project JMRI by JMRI.
the class HelpUtil method makeHelpMenu.
public static JMenu makeHelpMenu(String ref, boolean direct) {
if (!initOK()) {
log.warn("help initialization not completed");
// initialization failed
return null;
}
JMenu helpMenu = new JMenu(Bundle.getMessage("HELP"));
JMenuItem item = makeHelpMenuItem(ref);
if (item == null) {
log.error("Can't make help menu item for " + ref);
return null;
}
helpMenu.add(item);
if (direct) {
item = new JMenuItem(Bundle.getMessage("MenuItemHelp"));
globalHelpBroker.enableHelpOnButton(item, "index", null);
helpMenu.add(item);
// add standard items
JMenuItem license = new JMenuItem(Bundle.getMessage("MenuItemLicense"));
helpMenu.add(license);
license.addActionListener(new apps.LicenseAction());
JMenuItem directories = new JMenuItem(Bundle.getMessage("MenuItemLocations"));
helpMenu.add(directories);
directories.addActionListener(new jmri.jmrit.XmlFileLocationAction());
JMenuItem updates = new JMenuItem(Bundle.getMessage("MenuItemCheckUpdates"));
helpMenu.add(updates);
updates.addActionListener(new apps.CheckForUpdateAction());
JMenuItem context = new JMenuItem(Bundle.getMessage("MenuItemContext"));
helpMenu.add(context);
context.addActionListener(new apps.ReportContextAction());
JMenuItem console = new JMenuItem(Bundle.getMessage("MenuItemConsole"));
helpMenu.add(console);
console.addActionListener(new apps.SystemConsoleAction());
helpMenu.add(new jmri.jmrit.mailreport.ReportAction());
// Put about dialog in Apple's prefered area on Mac OS X
if (SystemType.isMacOSX()) {
try {
Application.getApplication().setAboutHandler((EventObject eo) -> {
new AboutDialog(null, true).setVisible(true);
});
} catch (java.lang.RuntimeException re) {
log.error("Unable to put About handler in default location", re);
}
}
// Include About in Help menu if not on Mac OS X or not using Aqua Look and Feel
if (!SystemType.isMacOSX() || !UIManager.getLookAndFeel().isNativeLookAndFeel()) {
helpMenu.addSeparator();
JMenuItem about = new JMenuItem(Bundle.getMessage("MenuItemAbout") + " " + jmri.Application.getApplicationName());
helpMenu.add(about);
about.addActionListener(new AboutAction());
}
}
return helpMenu;
}
use of java.util.EventObject in project cayenne by apache.
the class ProjectController method removeFromHistory.
private void removeFromHistory(EventObject e) {
int count = controllerStateHistory.size();
List<ControllerState> removeList = new ArrayList<>();
for (int i = 0; i < count; i++) {
ControllerState cs = controllerStateHistory.get(i);
if (cs == null || cs.event == null) {
continue;
}
EventObject csEvent = cs.event;
if (e instanceof EntityEvent && csEvent instanceof EntityDisplayEvent) {
if (((EntityEvent) e).getEntity() == ((EntityDisplayEvent) csEvent).getEntity()) {
removeList.add(cs);
}
} else if (e instanceof EmbeddableEvent && csEvent instanceof EmbeddableDisplayEvent) {
if (((EmbeddableEvent) e).getEmbeddable() == ((EmbeddableDisplayEvent) csEvent).getEmbeddable()) {
removeList.add(cs);
}
} else if (e instanceof ProcedureEvent && csEvent instanceof ProcedureDisplayEvent) {
if (((ProcedureEvent) e).getProcedure() == ((ProcedureDisplayEvent) csEvent).getProcedure()) {
removeList.add(cs);
}
} else if (e instanceof QueryEvent && csEvent instanceof QueryDisplayEvent) {
if (((QueryEvent) e).getQuery() == ((QueryDisplayEvent) csEvent).getQuery()) {
removeList.add(cs);
}
} else if (e instanceof DataMapEvent && csEvent instanceof DataMapDisplayEvent) {
if (((DataMapEvent) e).getDataMap() == ((DataMapDisplayEvent) csEvent).getDataMap()) {
removeList.add(cs);
}
} else if (e instanceof DataNodeEvent && csEvent instanceof DataNodeDisplayEvent) {
if (((DataNodeEvent) e).getDataNode() == ((DataNodeDisplayEvent) csEvent).getDataNode()) {
removeList.add(cs);
}
} else if (e instanceof DomainEvent && csEvent instanceof DomainDisplayEvent) {
if (((DomainEvent) e).getDomain() == ((DomainDisplayEvent) csEvent).getDomain()) {
removeList.add(cs);
}
}
}
for (ControllerState o : removeList) {
controllerStateHistory.remove(o);
}
}
Aggregations