use of java.awt.event.HierarchyEvent in project cuba by cuba-platform.
the class DesktopTabSheet method detachTab.
protected void detachTab(final int tabIndex) {
final JComponent tabContent = (JComponent) impl.getComponentAt(tabIndex);
TabImpl tabAtIndex = null;
for (TabImpl tab : tabs) {
if (DesktopComponentsHelper.getComposition(tab.getComponent()) == tabContent) {
tabAtIndex = tab;
if (tab.isLazy() && !tab.isLazyInitialized()) {
initLazyTab(tabContent);
}
break;
}
}
if (tabAtIndex == null) {
throw new IllegalStateException("Unable to find tab to detach");
}
final TabImpl tabToDetach = tabAtIndex;
final ButtonTabComponent tabComponent = tabToDetach.getButtonTabComponent();
final JFrame frame = new DetachedFrame(tabComponent.getCaption(), impl);
frame.setLocationRelativeTo(DesktopComponentsHelper.getTopLevelFrame(this));
impl.remove(tabContent);
updateTabsEnabledState();
frame.setSize(impl.getSize());
frame.add(tabContent);
final HierarchyListener listener = new HierarchyListener() {
@Override
public void hierarchyChanged(HierarchyEvent e) {
if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) == HierarchyEvent.DISPLAYABILITY_CHANGED && !impl.isDisplayable()) {
attachTab(frame, tabToDetach);
impl.removeHierarchyListener(this);
}
}
};
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
attachTab(frame, tabToDetach);
impl.removeHierarchyListener(listener);
}
});
impl.addHierarchyListener(listener);
frame.setVisible(true);
}
use of java.awt.event.HierarchyEvent in project cuba by cuba-platform.
the class DetachedFrame method initUI.
private void initUI() {
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
glassPane = new DisabledGlassPane();
JRootPane rootPane = SwingUtilities.getRootPane(this);
rootPane.setGlassPane(glassPane);
final java.awt.Component topLevelGlassPane = DesktopComponentsHelper.getTopLevelFrame(parentContainer).getGlassPane();
topLevelGlassPane.addHierarchyListener(new HierarchyListener() {
@Override
public void hierarchyChanged(HierarchyEvent e) {
if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) == HierarchyEvent.SHOWING_CHANGED) {
if (topLevelGlassPane.isVisible()) {
glassPane.activate(null);
} else {
glassPane.deactivate();
}
}
}
});
}
use of java.awt.event.HierarchyEvent in project freeplane by freeplane.
the class UITextChanger method setFocusWhenShowed.
private void setFocusWhenShowed(final JTextField focusOwner) {
focusOwner.addHierarchyListener(new HierarchyListener() {
@Override
public void hierarchyChanged(HierarchyEvent e) {
if (focusOwner.isShowing()) {
final Window windowAncestor = SwingUtilities.getWindowAncestor(focusOwner);
if (windowAncestor.isFocused()) {
focusOwner.requestFocusInWindow();
} else {
windowAncestor.addWindowFocusListener(new WindowFocusListener() {
@Override
public void windowLostFocus(WindowEvent e) {
// intentionally left blank
}
@Override
public void windowGainedFocus(WindowEvent e) {
focusOwner.requestFocusInWindow();
windowAncestor.removeWindowFocusListener(this);
}
});
}
focusOwner.removeHierarchyListener(this);
}
}
});
}
use of java.awt.event.HierarchyEvent in project cuba by cuba-platform.
the class DesktopFrame method detachFrame.
@Override
public void detachFrame(String caption) {
if (isDetached()) {
throw new RuntimeException("Frame already detached");
}
final java.awt.Container parent = impl.getParent();
detachedFrame = new DetachedFrame(caption, parent);
for (int i = 0; i < parent.getComponentCount(); i++) {
if (impl == parent.getComponent(i)) {
componentPosition = i;
break;
}
}
hierarchyListener = new HierarchyListener() {
@Override
public void hierarchyChanged(HierarchyEvent e) {
if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) == HierarchyEvent.DISPLAYABILITY_CHANGED && !parent.isDisplayable()) {
parent.removeHierarchyListener(this);
attachFrame();
}
}
};
detachedFrame.setLocationRelativeTo(DesktopComponentsHelper.getTopLevelFrame(impl));
detachedFrame.setSize(impl.getSize());
detachedFrame.add(impl);
detachedFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
parent.removeHierarchyListener(hierarchyListener);
attachFrame();
}
});
parent.revalidate();
parent.repaint();
parent.addHierarchyListener(hierarchyListener);
detachedFrame.setVisible(true);
detached = true;
for (DetachListener listener : detachListeners) {
listener.frameDetached(this);
}
}
use of java.awt.event.HierarchyEvent in project freeplane by freeplane.
the class MLinkController method createArrowLinkPopup.
@Override
protected void createArrowLinkPopup(final ConnectorModel link, final JComponent arrowLinkPopup) {
super.createArrowLinkPopup(link, arrowLinkPopup);
addClosingAction(arrowLinkPopup, new RemoveConnectorAction(this, link));
addSeparator(arrowLinkPopup);
addAction(arrowLinkPopup, new ConnectorColorAction(this, link));
final JSlider transparencySlider = new JSlider(20, 255, link.getAlpha());
transparencySlider.setMinorTickSpacing(20);
transparencySlider.setPaintTicks(true);
transparencySlider.setSnapToTicks(true);
transparencySlider.setPaintTrack(true);
addPopupComponent(arrowLinkPopup, TextUtils.getText("edit_transparency_label"), transparencySlider);
addSeparator(arrowLinkPopup);
AFreeplaneAction[] arrowActions = new AFreeplaneAction[] { new ChangeConnectorArrowsAction(this, ConnectorArrows.NONE, link), new ChangeConnectorArrowsAction(this, ConnectorArrows.FORWARD, link), new ChangeConnectorArrowsAction(this, ConnectorArrows.BACKWARD, link), new ChangeConnectorArrowsAction(this, ConnectorArrows.BOTH, link) };
JComboBoxWithBorder connectorArrows = createActionBox(arrowActions);
addPopupComponent(arrowLinkPopup, TextUtils.getText("connector_arrows"), connectorArrows);
final boolean twoNodesConnector = !link.getSource().equals(link.getTarget());
AFreeplaneAction[] shapeActions;
if (twoNodesConnector) {
shapeActions = new AFreeplaneAction[] { new ChangeConnectorShapeAction(this, link, Shape.CUBIC_CURVE), new ChangeConnectorShapeAction(this, link, Shape.LINE), new ChangeConnectorShapeAction(this, link, Shape.LINEAR_PATH), new ChangeConnectorShapeAction(this, link, Shape.EDGE_LIKE) };
} else {
shapeActions = new AFreeplaneAction[] { new ChangeConnectorShapeAction(this, link, Shape.CUBIC_CURVE), new ChangeConnectorShapeAction(this, link, Shape.LINE), new ChangeConnectorShapeAction(this, link, Shape.LINEAR_PATH) };
}
final JComboBoxWithBorder connectorShapes = createActionBox(shapeActions);
addPopupComponent(arrowLinkPopup, TextUtils.getText("connector_shapes"), connectorShapes);
ArrayList<AFreeplaneAction> dashActions = new ArrayList<AFreeplaneAction>();
for (DashVariant variant : DashVariant.values()) dashActions.add(new ChangeConnectorDashAction(this, link, variant));
final JComboBoxWithBorder connectorDashes = createActionBox(dashActions.toArray(new AFreeplaneAction[dashActions.size()]));
final int verticalMargin = new Quantity<>(3, LengthUnits.pt).toBaseUnitsRounded();
connectorDashes.setVerticalMargin(verticalMargin);
addPopupComponent(arrowLinkPopup, TextUtils.getText("connector_lines"), connectorDashes);
final SpinnerNumberModel widthModel = new SpinnerNumberModel(link.getWidth(), 1, 32, 1);
final JSpinner widthSpinner = new JSpinner(widthModel);
addPopupComponent(arrowLinkPopup, TextUtils.getText("edit_width_label"), widthSpinner);
addSeparator(arrowLinkPopup);
{
final GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
final String[] envFonts = gEnv.getAvailableFontFamilyNames();
DefaultComboBoxModel fonts = new DefaultComboBoxModel(envFonts);
fonts.setSelectedItem(link.getLabelFontFamily());
JComboBox fontBox = new JComboBoxWithBorder(fonts);
fontBox.setEditable(false);
addPopupComponent(arrowLinkPopup, TextUtils.getText("edit_label_font_family"), fontBox);
fontBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
final Object item = e.getItem();
if (item != null)
setLabelFontFamily(link, item.toString());
}
});
}
{
final Integer[] sizes = { 4, 6, 8, 10, 12, 14, 16, 18, 24, 36 };
DefaultComboBoxModel sizesModel = new DefaultComboBoxModel(sizes);
sizesModel.setSelectedItem(link.getLabelFontSize());
JComboBox sizesBox = new JComboBoxWithBorder(sizesModel);
sizesBox.setEditable(true);
addPopupComponent(arrowLinkPopup, TextUtils.getText("edit_label_font_size"), sizesBox);
sizesBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
final Object item = e.getItem();
if (item != null) {
final int size;
if (item instanceof Integer)
size = (Integer) item;
else {
try {
size = Integer.valueOf(item.toString());
if (size <= 0)
return;
} catch (NumberFormatException ex) {
return;
}
}
setLabelFontSize(link, size);
}
}
});
}
final JTextArea sourceLabelEditor;
sourceLabelEditor = new JTextArea(link.getSourceLabel());
addTextEditor(arrowLinkPopup, "edit_source_label", sourceLabelEditor);
final JTextArea middleLabelEditor = new JTextArea(link.getMiddleLabel());
addTextEditor(arrowLinkPopup, "edit_middle_label", middleLabelEditor);
final JTextArea targetLabelEditor;
targetLabelEditor = new JTextArea(link.getTargetLabel());
addTextEditor(arrowLinkPopup, "edit_target_label", targetLabelEditor);
arrowLinkPopup.addHierarchyListener(new HierarchyListener() {
private Component focusOwner;
private Window dialog;
public void hierarchyChanged(HierarchyEvent e) {
final JComponent component = (JComponent) e.getComponent();
if (component.isShowing()) {
if (dialog == null) {
dialog = SwingUtilities.getWindowAncestor(component);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
component.putClientProperty(CANCEL, Boolean.TRUE);
}
});
}
if (focusOwner == null)
focusOwner = FocusManager.getCurrentManager().getFocusOwner();
return;
}
if (focusOwner == null || !focusOwner.isShowing())
return;
focusOwner.requestFocus();
if (Boolean.TRUE.equals(component.getClientProperty(CANCEL))) {
return;
}
final IMapSelection selection = Controller.getCurrentController().getSelection();
if (selection == null || selection.getSelected() == null)
return;
setSourceLabel(link, sourceLabelEditor.getText());
setTargetLabel(link, targetLabelEditor.getText());
setMiddleLabel(link, middleLabelEditor.getText());
setAlpha(link, transparencySlider.getValue());
setWidth(link, widthModel.getNumber().intValue());
}
});
}
Aggregations