use of java.awt.event.ComponentAdapter 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.ComponentAdapter in project JMRI by JMRI.
the class ControlPanel method initGUI.
/**
* Create, initialize and place GUI components.
*/
private void initGUI() {
mainPanel = new JPanel();
this.setContentPane(mainPanel);
mainPanel.setLayout(new BorderLayout());
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
speedControlPanel = new JPanel();
speedControlPanel.setLayout(new BoxLayout(speedControlPanel, BoxLayout.X_AXIS));
speedControlPanel.setOpaque(false);
mainPanel.add(speedControlPanel, BorderLayout.CENTER);
sliderPanel = new JPanel();
sliderPanel.setLayout(new GridBagLayout());
sliderPanel.setOpaque(false);
speedSlider = new JSlider(0, intSpeedSteps);
speedSlider.setOpaque(false);
speedSlider.setValue(0);
speedSlider.setFocusable(false);
// add mouse-wheel support
speedSlider.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getWheelRotation() > 0) {
for (int i = 0; i < e.getScrollAmount(); i++) {
decelerate1();
}
} else {
for (int i = 0; i < e.getScrollAmount(); i++) {
accelerate1();
}
}
}
});
speedSliderContinuous = new JSlider(-intSpeedSteps, intSpeedSteps);
speedSliderContinuous.setValue(0);
speedSliderContinuous.setOpaque(false);
speedSliderContinuous.setFocusable(false);
// add mouse-wheel support
speedSliderContinuous.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getWheelRotation() > 0) {
for (int i = 0; i < e.getScrollAmount(); i++) {
decelerate1();
}
} else {
for (int i = 0; i < e.getScrollAmount(); i++) {
accelerate1();
}
}
}
});
speedSpinner = new JSpinner();
speedSpinnerModel = new SpinnerNumberModel(0, 0, intSpeedSteps, 1);
speedSpinner.setModel(speedSpinnerModel);
speedSpinner.setFocusable(false);
SpeedStep128Button = new JRadioButton(Bundle.getMessage("Button128SS"));
SpeedStep28Button = new JRadioButton(Bundle.getMessage("Button28SS"));
SpeedStep27Button = new JRadioButton(Bundle.getMessage("Button27SS"));
SpeedStep14Button = new JRadioButton(Bundle.getMessage("Button14SS"));
forwardButton = new JRadioButton();
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
forwardButton.setBorderPainted(false);
forwardButton.setContentAreaFilled(false);
forwardButton.setText(null);
forwardButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/up-red.png")));
forwardButton.setSelectedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/up-green.png")));
forwardButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
forwardButton.setToolTipText(Bundle.getMessage("ButtonForward"));
} else {
forwardButton.setText(Bundle.getMessage("ButtonForward"));
}
reverseButton = new JRadioButton();
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
reverseButton.setBorderPainted(false);
reverseButton.setContentAreaFilled(false);
reverseButton.setText(null);
reverseButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/down-red.png")));
reverseButton.setSelectedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/down-green.png")));
reverseButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
reverseButton.setToolTipText(Bundle.getMessage("ButtonReverse"));
} else {
reverseButton.setText(Bundle.getMessage("ButtonReverse"));
}
propertiesPopup = new JPopupMenu();
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.CENTER;
constraints.fill = GridBagConstraints.BOTH;
constraints.gridheight = 1;
constraints.gridwidth = 1;
constraints.ipadx = 0;
constraints.ipady = 0;
Insets insets = new Insets(2, 2, 2, 2);
constraints.insets = insets;
constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 0;
constraints.gridy = 0;
sliderPanel.add(speedSlider, constraints);
//this.getContentPane().add(sliderPanel,BorderLayout.CENTER);
speedControlPanel.add(sliderPanel);
speedSlider.setOrientation(JSlider.VERTICAL);
speedSlider.setMajorTickSpacing(maxSpeed / 2);
java.util.Hashtable<Integer, JLabel> labelTable = new java.util.Hashtable<Integer, JLabel>();
labelTable.put(Integer.valueOf(maxSpeed / 2), new JLabel("50%"));
labelTable.put(Integer.valueOf(maxSpeed), new JLabel("100%"));
labelTable.put(Integer.valueOf(0), new JLabel(Bundle.getMessage("LabelStop")));
speedSlider.setLabelTable(labelTable);
speedSlider.setPaintTicks(true);
speedSlider.setPaintLabels(true);
// remove old actions
speedSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!internalAdjust) {
boolean doIt = false;
if (!speedSlider.getValueIsAdjusting()) {
doIt = true;
lastTrackedSliderMovementTime = System.currentTimeMillis() - trackSliderMinInterval;
} else if (trackSlider && System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
doIt = true;
lastTrackedSliderMovementTime = System.currentTimeMillis();
}
if (doIt) {
float newSpeed = (speedSlider.getValue() / (intSpeedSteps * 1.0f));
if (log.isDebugEnabled()) {
log.debug("stateChanged: slider pos: " + speedSlider.getValue() + " speed: " + newSpeed);
}
if (sliderPanel.isVisible() && throttle != null) {
throttle.setSpeedSetting(newSpeed);
}
if (speedSpinner != null) {
speedSpinnerModel.setValue(Integer.valueOf(speedSlider.getValue()));
}
if (speedSliderContinuous != null) {
if (forwardButton.isSelected()) {
speedSliderContinuous.setValue(((Integer) speedSlider.getValue()).intValue());
} else {
speedSliderContinuous.setValue(-((Integer) speedSlider.getValue()).intValue());
}
}
}
}
}
});
speedSliderContinuousPanel = new JPanel();
speedSliderContinuousPanel.setLayout(new GridBagLayout());
constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.CENTER;
constraints.fill = GridBagConstraints.BOTH;
constraints.gridheight = 1;
constraints.gridwidth = 1;
constraints.ipadx = 0;
constraints.ipady = 0;
insets = new Insets(2, 2, 2, 2);
constraints.insets = insets;
constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 0;
constraints.gridy = 0;
speedSliderContinuousPanel.add(speedSliderContinuous, constraints);
//this.getContentPane().add(sliderPanel,BorderLayout.CENTER);
speedControlPanel.add(speedSliderContinuousPanel);
speedSliderContinuous.setOrientation(JSlider.VERTICAL);
speedSliderContinuous.setMajorTickSpacing(maxSpeed / 2);
labelTable = new java.util.Hashtable<Integer, JLabel>();
labelTable.put(Integer.valueOf(maxSpeed / 2), new JLabel("50%"));
labelTable.put(Integer.valueOf(maxSpeed), new JLabel("100%"));
labelTable.put(Integer.valueOf(0), new JLabel(Bundle.getMessage("LabelStop")));
labelTable.put(Integer.valueOf(-maxSpeed / 2), new JLabel("-50%"));
labelTable.put(Integer.valueOf(-maxSpeed), new JLabel("-100%"));
speedSliderContinuous.setLabelTable(labelTable);
speedSliderContinuous.setPaintTicks(true);
speedSliderContinuous.setPaintLabels(true);
// remove old actions
speedSliderContinuous.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!internalAdjust) {
boolean doIt = false;
if (!speedSliderContinuous.getValueIsAdjusting()) {
doIt = true;
lastTrackedSliderMovementTime = System.currentTimeMillis() - trackSliderMinInterval;
} else if (trackSlider && System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
doIt = true;
lastTrackedSliderMovementTime = System.currentTimeMillis();
}
if (doIt) {
float newSpeed = (java.lang.Math.abs(speedSliderContinuous.getValue()) / (intSpeedSteps * 1.0f));
boolean newDir = (speedSliderContinuous.getValue() >= 0);
if (log.isDebugEnabled()) {
log.debug("stateChanged: slider pos: " + speedSliderContinuous.getValue() + " speed: " + newSpeed + " dir: " + newDir);
}
if (speedSliderContinuousPanel.isVisible() && throttle != null) {
throttle.setSpeedSetting(newSpeed);
if ((newSpeed > 0) && (newDir != forwardButton.isSelected())) {
throttle.setIsForward(newDir);
}
}
if (speedSpinner != null) {
speedSpinnerModel.setValue(Integer.valueOf(java.lang.Math.abs(speedSliderContinuous.getValue())));
}
if (speedSlider != null) {
speedSlider.setValue(Integer.valueOf(java.lang.Math.abs(speedSliderContinuous.getValue())));
}
}
}
}
});
spinnerPanel = new JPanel();
spinnerPanel.setLayout(new GridBagLayout());
spinnerPanel.add(speedSpinner, constraints);
speedControlPanel.add(spinnerPanel);
// remove old actions
speedSpinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!internalAdjust) {
//if (!speedSpinner.getValueIsAdjusting())
//{
float newSpeed = ((Integer) speedSpinner.getValue()).floatValue() / (intSpeedSteps * 1.0f);
if (log.isDebugEnabled()) {
log.debug("stateChanged: spinner pos: " + speedSpinner.getValue() + " speed: " + newSpeed);
}
if (throttle != null) {
if (spinnerPanel.isVisible()) {
throttle.setSpeedSetting(newSpeed);
}
speedSlider.setValue(((Integer) speedSpinner.getValue()).intValue());
if (speedSliderContinuous != null) {
if (forwardButton.isSelected()) {
speedSliderContinuous.setValue(((Integer) speedSpinner.getValue()).intValue());
} else {
speedSliderContinuous.setValue(-((Integer) speedSpinner.getValue()).intValue());
}
}
} else {
log.warn("no throttle object in stateChanged, ignoring change of speed to " + newSpeed);
}
//}
}
}
});
ButtonGroup speedStepButtons = new ButtonGroup();
speedStepButtons.add(SpeedStep128Button);
speedStepButtons.add(SpeedStep28Button);
speedStepButtons.add(SpeedStep27Button);
speedStepButtons.add(SpeedStep14Button);
constraints.fill = GridBagConstraints.NONE;
constraints.gridy = 1;
spinnerPanel.add(SpeedStep128Button, constraints);
constraints.gridy = 2;
spinnerPanel.add(SpeedStep28Button, constraints);
constraints.gridy = 3;
spinnerPanel.add(SpeedStep27Button, constraints);
constraints.gridy = 4;
spinnerPanel.add(SpeedStep14Button, constraints);
SpeedStep14Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedStepsMode(DccThrottle.SpeedStepMode14);
throttle.setSpeedStepMode(DccThrottle.SpeedStepMode14);
}
});
SpeedStep27Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedStepsMode(DccThrottle.SpeedStepMode27);
throttle.setSpeedStepMode(DccThrottle.SpeedStepMode27);
}
});
SpeedStep28Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedStepsMode(DccThrottle.SpeedStepMode28);
throttle.setSpeedStepMode(DccThrottle.SpeedStepMode28);
}
});
SpeedStep128Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedStepsMode(DccThrottle.SpeedStepMode128);
throttle.setSpeedStepMode(DccThrottle.SpeedStepMode128);
}
});
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridBagLayout());
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
ButtonGroup directionButtons = new ButtonGroup();
directionButtons.add(forwardButton);
directionButtons.add(reverseButton);
constraints.fill = GridBagConstraints.NONE;
constraints.gridy = 1;
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
constraints.gridx = 3;
}
buttonPanel.add(forwardButton, constraints);
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
constraints.gridx = 1;
} else {
constraints.gridy = 2;
}
buttonPanel.add(reverseButton, constraints);
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
constraints.gridx = 2;
}
forwardButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
throttle.setIsForward(true);
if (speedSliderContinuous != null) {
speedSliderContinuous.setValue(java.lang.Math.abs(speedSliderContinuous.getValue()));
}
}
});
reverseButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
throttle.setIsForward(false);
if (speedSliderContinuous != null) {
speedSliderContinuous.setValue(-java.lang.Math.abs(speedSliderContinuous.getValue()));
}
}
});
stopButton = new JButton();
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
stopButton.setBorderPainted(false);
stopButton.setContentAreaFilled(false);
stopButton.setText(null);
stopButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/estop.png")));
stopButton.setPressedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/estop24.png")));
stopButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
stopButton.setToolTipText(Bundle.getMessage("ButtonEStop"));
} else {
stopButton.setText(Bundle.getMessage("ButtonEStop"));
}
constraints.gridy = 4;
constraints.fill = GridBagConstraints.HORIZONTAL;
buttonPanel.add(stopButton, constraints);
stopButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stop();
}
});
stopButton.addMouseListener(new MouseListener() {
@Override
public void mousePressed(MouseEvent e) {
stop();
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
});
idleButton = new JButton();
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
idleButton.setBorderPainted(false);
idleButton.setContentAreaFilled(false);
idleButton.setText(null);
idleButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/stop.png")));
idleButton.setPressedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/stop24.png")));
idleButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
idleButton.setToolTipText(Bundle.getMessage("ButtonIdle"));
} else {
idleButton.setText(Bundle.getMessage("ButtonIdle"));
}
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
constraints.gridy = 1;
} else {
constraints.gridy = 3;
}
buttonPanel.add(idleButton, constraints);
idleButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
speedSlider.setValue(0);
if (speedSpinner != null) {
speedSpinner.setValue(Integer.valueOf(0));
}
if (speedSliderContinuous != null) {
speedSliderContinuous.setValue(Integer.valueOf(0));
}
throttle.setSpeedSetting(0);
}
});
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
changeOrientation();
}
});
JMenuItem propertiesItem = new JMenuItem(Bundle.getMessage("ControlPanelProperties"));
propertiesItem.addActionListener(this);
propertiesPopup.add(propertiesItem);
// Add a mouse listener all components to trigger the popup menu.
MouseInputAdapter popupListener = new PopupListener(propertiesPopup, this);
MouseInputAdapterInstaller.installMouseInputAdapterOnAllComponents(popupListener, this);
// Install the Key bindings on all Components
KeyListenerInstaller.installKeyListenerOnAllComponents(new ControlPadKeyListener(), this);
// set by default which speed selection method is on top
setSpeedController(_displaySlider);
}
use of java.awt.event.ComponentAdapter 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.ComponentAdapter in project android by JetBrains.
the class ConnectionsView method createRequestsTable.
@NotNull
private JTable createRequestsTable() {
JTable table = new JBTable(myTableModel);
table.setAutoCreateRowSorter(true);
table.getColumnModel().getColumn(Column.SIZE.ordinal()).setCellRenderer(new SizeRenderer());
table.getColumnModel().getColumn(Column.STATUS.ordinal()).setCellRenderer(new StatusRenderer());
table.getColumnModel().getColumn(Column.TIME.ordinal()).setCellRenderer(new TimeRenderer());
table.getColumnModel().getColumn(Column.TIMELINE.ordinal()).setCellRenderer(new TimelineRenderer(table, myStageView.getTimeline().getSelectionRange()));
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().addListSelectionListener(e -> {
int selectedRow = table.getSelectedRow();
if (0 <= selectedRow && selectedRow < myTableModel.getRowCount()) {
int modelRow = myConnectionsTable.convertRowIndexToModel(selectedRow);
myDetailedViewListener.showDetailedConnection(myTableModel.getHttpData(modelRow));
}
});
table.setFont(AdtUiUtils.DEFAULT_FONT);
int defaultFontHeight = table.getFontMetrics(AdtUiUtils.DEFAULT_FONT).getHeight();
table.setRowHeight(defaultFontHeight + ROW_HEIGHT_PADDING);
table.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
for (int i = 0; i < Column.values().length; ++i) {
Column column = Column.values()[i];
table.getColumnModel().getColumn(i).setPreferredWidth((int) (table.getWidth() * column.getWidthPercentage()));
}
}
});
// Keep the previously selected row selected if it's still there
myTableModel.addTableModelListener(e -> ApplicationManager.getApplication().invokeLater(() -> {
HttpData selectedData = myStageView.getStage().getConnection();
if (selectedData != null) {
for (int i = 0; i < myTableModel.getRowCount(); ++i) {
if (myTableModel.getHttpData(i).getId() == selectedData.getId()) {
int row = table.convertRowIndexToView(i);
table.setRowSelectionInterval(row, row);
break;
}
}
}
}));
return table;
}
use of java.awt.event.ComponentAdapter in project intellij-plugins by JetBrains.
the class AngularUiRouterDiagramProvider method createPresentationModel.
@Nullable
@Override
public DiagramPresentationModel createPresentationModel(Project project, Graph2D graph) {
return new DiagramPresentationModelImpl(graph, project, this) {
@Override
public boolean allowChangeVisibleCategories() {
return false;
}
private final Map<DiagramEdge, EdgeRealizer> myEdgeRealizers = new HashMap<>();
@NotNull
@Override
public EdgeRealizer getEdgeRealizer(DiagramEdge edge) {
if (!(edge instanceof AngularUiRouterEdge))
return super.getEdgeRealizer(edge);
if (myEdgeRealizers.containsKey(edge))
return myEdgeRealizers.get(edge);
UmlGraphBuilder builder = (UmlGraphBuilder) graph.getDataProvider(DiagramDataKeys.GRAPH_BUILDER).get(null);
final Edge graphEdge = builder.getEdge(edge);
final AngularEdgeLayouter.OneEdgeLayouter layouter = new AngularEdgeLayouter.OneEdgeLayouter(graphEdge, (AngularUiRouterEdge) edge, graph);
layouter.calculateEdgeLayout();
final QuadCurveEdgeRealizer realizer = layouter.getRealizer();
for (int i = 0; i < realizer.labelCount(); i++) {
realizer.removeLabel(realizer.getLabel(i));
}
/*final EdgeLabel[] labels = getEdgeLabels(edge, "");
if (labels.length == 0) realizer.setLabelText("");
else {
for (EdgeLabel label : labels) {
realizer.addLabel(label);
}
}*/
myEdgeRealizers.put(edge, realizer);
return realizer;
}
private Map<Integer, Integer> myEdgesPositions = new HashMap<>();
private final Set<AngularUiRouterEdge> myVisibleEdges = new HashSet<>();
@Override
public EdgeLabel[] getEdgeLabels(DiagramEdge umlEdge, String label) {
if (!(umlEdge instanceof AngularUiRouterEdge))
return super.getEdgeLabels(umlEdge, label);
AngularUiRouterEdge angularEdge = (AngularUiRouterEdge) umlEdge;
if (!isShowEdgeLabels() || umlEdge == null || StringUtil.isEmptyOrSpaces(angularEdge.getLabel())) {
return EMPTY_LABELS;
}
//if (!myVisibleEdges.contains(umlEdge)) return EMPTY_LABELS;
UmlGraphBuilder builder = (UmlGraphBuilder) graph.getDataProvider(DiagramDataKeys.GRAPH_BUILDER).get(null);
final Edge edge = builder.getEdge(umlEdge);
final EdgeRealizer edgeRealizer = getEdgeRealizer(umlEdge);
for (int i = 0; i < edgeRealizer.labelCount(); i++) {
edgeRealizer.removeLabel(edgeRealizer.getLabel(i));
}
final Integer position = calculatePosition(edge, builder);
final EdgeLabel edgeLabel = GraphManager.getGraphManager().createEdgeLabel();
final SmartEdgeLabelModel model = GraphManager.getGraphManager().createSmartEdgeLabelModel();
edgeLabel.setLabelModel(model, model.createDiscreteModelParameter(position));
edgeLabel.setFontSize(9);
edgeLabel.setDistance(5);
edgeLabel.setTextColor(JBColor.foreground());
myEdgesPositions.put(edge.index(), 1);
return new EdgeLabel[] { edgeLabel };
}
private Integer calculatePosition(final Edge edge, UmlGraphBuilder builder) {
final Integer existing = myEdgesPositions.get(edge.index());
if (existing != null)
return existing;
final List<Edge> list = new ArrayList<>();
for (Edge current : edge.getGraph().getEdgeArray()) {
if (current.source().index() == edge.source().index() && current.target().index() == edge.target().index() || current.target().index() == edge.source().index() && current.source().index() == edge.target().index()) {
list.add(current);
}
}
boolean sourceHeavier = edge.source().degree() > edge.target().degree();
Collections.sort(list, (o1, o2) -> {
final YPoint s1 = ((Graph2D) o1.getGraph()).getSourcePointAbs(o1);
final YPoint s2 = ((Graph2D) o1.getGraph()).getSourcePointAbs(o2);
if (Math.abs(s1.getX() - s2.getX()) > 5)
return Double.compare(s1.getX(), s2.getX());
return Double.compare(s1.getY(), s2.getY());
});
int[] variants = sourceHeavier ? new int[] { SmartEdgeLabelModel.POSITION_TARGET_RIGHT, SmartEdgeLabelModel.POSITION_RIGHT, SmartEdgeLabelModel.POSITION_SOURCE_RIGHT } : new int[] { SmartEdgeLabelModel.POSITION_SOURCE_RIGHT, SmartEdgeLabelModel.POSITION_RIGHT, SmartEdgeLabelModel.POSITION_TARGET_RIGHT };
int variantIdx = 0;
for (Edge current : list) {
myEdgesPositions.put(current.index(), variants[variantIdx++]);
if (variantIdx >= variants.length)
variantIdx = 0;
}
return myEdgesPositions.get(edge.index());
}
private boolean inUpdate = false;
@Override
public void update() {
if (inUpdate)
return;
try {
inUpdate = true;
myEdgeRealizers.clear();
final List<DiagramNode> nodes = GraphUtil.getSelectedNodes(getGraphBuilder());
super.update();
myEdgesPositions.clear();
final DiagramBuilder builder = getBuilder();
builder.relayout();
builder.getView().fitContent();
builder.updateView();
if (!nodes.isEmpty()) {
final Collection<DiagramNode> objects = builder.getNodeObjects();
for (DiagramNode object : objects) {
if (isInSelectedNodes(nodes, object)) {
builder.getGraph().setSelected(builder.getNode(object), true);
}
}
}
updateBySelection(nodes.isEmpty() ? null : nodes.get(0));
} finally {
inUpdate = false;
}
}
@Override
public void customizeSettings(Graph2DView view, EditMode editMode) {
super.customizeSettings(view, editMode);
view.getGraph2D().addGraph2DSelectionListener(new Graph2DSelectionListener() {
@Override
public void onGraph2DSelectionEvent(Graph2DSelectionEvent _e) {
myEdgesPositions.clear();
updateBySelection(null);
view.updateView();
}
});
view.getJComponent().addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(ComponentEvent e) {
ApplicationManager.getApplication().invokeLater(() -> {
UmlGraphBuilder builder = (UmlGraphBuilder) graph.getDataProvider(DiagramDataKeys.GRAPH_BUILDER).get(null);
builder.getPresentationModel().update();
});
}
});
ApplicationManager.getApplication().invokeLater(() -> {
UmlGraphBuilder builder = (UmlGraphBuilder) graph.getDataProvider(DiagramDataKeys.GRAPH_BUILDER).get(null);
final AngularUiRouterDiagramModel model = (AngularUiRouterDiagramModel) builder.getDataModel();
final AngularUiRouterNode rootNode = findDataObject(project, model).getRootNode();
updateBySelection(rootNode);
});
}
private void updateBySelection(DiagramNode node) {
myVisibleEdges.clear();
UmlGraphBuilder builder = (UmlGraphBuilder) graph.getDataProvider(DiagramDataKeys.GRAPH_BUILDER).get(null);
final List<DiagramNode> nodes = new ArrayList<>(GraphUtil.getSelectedNodes(builder));
if (node != null && !nodes.contains(node))
nodes.add(node);
DiagramNode selected = null;
for (DiagramEdge edge : builder.getEdgeObjects()) {
if (nodes.contains(edge.getSource())) {
selected = edge.getSource();
} else if (nodes.contains(edge.getTarget())) {
selected = edge.getTarget();
} else
continue;
break;
}
if (selected == null) {
for (DiagramEdge edge : builder.getEdgeObjects()) {
if (isInSelectedNodes(nodes, edge.getSource())) {
selected = edge.getSource();
} else if (isInSelectedNodes(nodes, edge.getTarget())) {
selected = edge.getTarget();
} else
continue;
break;
}
}
for (DiagramEdge edge : builder.getEdgeObjects()) {
if (!(edge instanceof AngularUiRouterEdge))
continue;
if (isShowEdgeLabels() && selected != null && (selected.equals(edge.getSource()) || selected.equals(edge.getTarget()))) {
myVisibleEdges.add((AngularUiRouterEdge) edge);
graph.setLabelText(builder.getEdge(edge), ((AngularUiRouterEdge) edge).getLabel());
} else {
graph.setLabelText(builder.getEdge(edge), "");
}
}
}
@Override
public DefaultUmlRenderer getRenderer() {
if (myRenderer == null) {
myRenderer = new DefaultUmlRenderer(getBuilder(), createModificationTracker()) {
@Override
public void tuneNode(NodeRealizer realizer, JPanel wrapper) {
wrapper.setBorder(JBUI.Borders.empty());
if (wrapper.getParent() instanceof JComponent)
((JComponent) wrapper.getParent()).setBorder(JBUI.Borders.empty());
super.tuneNode(realizer, wrapper);
}
};
}
return myRenderer;
}
};
}
Aggregations