Search in sources :

Example 16 with HierarchyListener

use of java.awt.event.HierarchyListener in project freeplane by freeplane.

the class MapViewChangeObserverCompound method fireMapViewCreatedAfterItIsDisplayed.

private void fireMapViewCreatedAfterItIsDisplayed(final MapView view) {
    HierarchyListener retryEventListener = new HierarchyListener() {

        public void hierarchyChanged(HierarchyEvent e) {
            if (view.isShowing()) {
                view.removeHierarchyListener(this);
                mapViewCreated(view);
            }
        }
    };
    view.addHierarchyListener(retryEventListener);
}
Also used : HierarchyEvent(java.awt.event.HierarchyEvent) HierarchyListener(java.awt.event.HierarchyListener)

Example 17 with HierarchyListener

use of java.awt.event.HierarchyListener in project freeplane by freeplane.

the class ManageAddOnsDialog method install.

public void install(final URL url) {
    if (addOnInstallerPanel.isShowing()) {
        addOnInstallerPanel.getUrlField().setText(url.toString());
        tabbedPane.paintImmediately(0, 0, tabbedPane.getWidth(), tabbedPane.getHeight());
        addOnInstallerPanel.getInstallButton().doClick();
    } else {
        addOnInstallerPanel.addHierarchyListener(new HierarchyListener() {

            public void hierarchyChanged(HierarchyEvent e) {
                if (addOnInstallerPanel.isShowing()) {
                    addOnInstallerPanel.removeHierarchyListener(this);
                    install(url);
                }
            }
        });
        tabbedPane.setSelectedComponent(addOnInstallerPanel);
        if (!isVisible())
            setVisible(true);
    }
}
Also used : HierarchyEvent(java.awt.event.HierarchyEvent) HierarchyListener(java.awt.event.HierarchyListener)

Example 18 with HierarchyListener

use of java.awt.event.HierarchyListener in project freeplane by freeplane.

the class AddAttributeAction method getPanel.

/**
 * This method creates the input dialog
 *
 * @return : the input dialog
 */
private JPanel getPanel() {
    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    panel.setBorder(new EtchedBorder());
    final GridBagConstraints gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = GridBagConstraints.CENTER;
    gridBagConstraints.insets = new Insets(20, 10, 2, 10);
    // Size of JComboBoxes
    final String pattern = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    final JLabel patternLabel = new JLabel(pattern);
    final Dimension comboBoxMaximumSize = patternLabel.getPreferredSize();
    comboBoxMaximumSize.width += 4;
    comboBoxMaximumSize.height += 10;
    // Label: name
    final JLabel nameLabel = new JLabel(TextUtils.getText("attribute_name"));
    panel.add(nameLabel, gridBagConstraints);
    gridBagConstraints.gridx++;
    // Label: value
    final JLabel valueLabel = new JLabel(TextUtils.getText("attribute_value"));
    panel.add(valueLabel, gridBagConstraints);
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    // Attribute name combo-box
    gridBagConstraints.insets = new Insets(2, 10, 20, 10);
    attributeNames = new JComboBox();
    final MapModel map = Controller.getCurrentController().getMap();
    final AttributeRegistry attributes = AttributeRegistry.getRegistry(map);
    final ComboBoxModel names = attributes.getComboBoxModel();
    attributeNames.setModel(new ClonedComboBoxModel(names));
    attributeNames.setEditable(true);
    attributeNames.setMaximumSize(comboBoxMaximumSize);
    attributeNames.setPreferredSize(comboBoxMaximumSize);
    attributeNames.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            selectedAttributeChanged(e.getItem(), attributeValues);
        }
    });
    panel.add(attributeNames, gridBagConstraints);
    // Attribute value combo-box
    attributeValues = new JComboBox();
    attributeValues.setRenderer(new TypedListCellRenderer());
    attributeValues.setMaximumSize(comboBoxMaximumSize);
    attributeValues.setPreferredSize(comboBoxMaximumSize);
    gridBagConstraints.gridx++;
    panel.add(attributeValues, gridBagConstraints);
    // set focus to attributeNames
    panel.addHierarchyListener(new HierarchyListener() {

        public void hierarchyChanged(HierarchyEvent e) {
            final Component component = e.getComponent();
            if (component.isShowing()) {
                attributeNames.requestFocus();
                component.removeHierarchyListener(this);
            }
        }
    });
    return panel;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) ItemEvent(java.awt.event.ItemEvent) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) MapModel(org.freeplane.features.map.MapModel) HierarchyListener(java.awt.event.HierarchyListener) EtchedBorder(javax.swing.border.EtchedBorder) TypedListCellRenderer(org.freeplane.core.ui.components.TypedListCellRenderer) AttributeRegistry(org.freeplane.features.attribute.AttributeRegistry) HierarchyEvent(java.awt.event.HierarchyEvent) ItemListener(java.awt.event.ItemListener) ClonedComboBoxModel(org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel) Component(java.awt.Component) ClonedComboBoxModel(org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel) ComboBoxModel(javax.swing.ComboBoxModel)

Example 19 with HierarchyListener

use of java.awt.event.HierarchyListener 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, "none", link, ArrowType.NONE, ArrowType.NONE), new ChangeConnectorArrowsAction(this, "forward", link, ArrowType.NONE, ArrowType.DEFAULT), new ChangeConnectorArrowsAction(this, "backward", link, ArrowType.DEFAULT, ArrowType.NONE), new ChangeConnectorArrowsAction(this, "both", link, ArrowType.DEFAULT, ArrowType.DEFAULT) };
    final JComboBox 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 JComboBox connectorShapes = createActionBox(shapeActions);
    addPopupComponent(arrowLinkPopup, TextUtils.getText("connector_shapes"), connectorShapes);
    AFreeplaneAction[] dashActions = new AFreeplaneAction[] { new ChangeConnectorDashAction(this, link, null), new ChangeConnectorDashAction(this, link, new int[] { 3, 3 }), new ChangeConnectorDashAction(this, link, new int[] { 7, 7 }), new ChangeConnectorDashAction(this, link, new int[] { 2, 7 }), new ChangeConnectorDashAction(this, link, new int[] { 2, 7, 7, 7 }) };
    final JComboBox connectorDashes = createActionBox(dashActions);
    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 JComboBox(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 JComboBox(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());
        }
    });
}
Also used : ItemEvent(java.awt.event.ItemEvent) JTextArea(javax.swing.JTextArea) IMapSelection(org.freeplane.features.map.IMapSelection) WindowAdapter(java.awt.event.WindowAdapter) HierarchyListener(java.awt.event.HierarchyListener) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JSlider(javax.swing.JSlider) Component(java.awt.Component) JComponent(javax.swing.JComponent) Window(java.awt.Window) JComboBox(javax.swing.JComboBox) JComponent(javax.swing.JComponent) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) HierarchyEvent(java.awt.event.HierarchyEvent) WindowEvent(java.awt.event.WindowEvent) JSpinner(javax.swing.JSpinner) ItemListener(java.awt.event.ItemListener)

Example 20 with HierarchyListener

use of java.awt.event.HierarchyListener in project freeplane by freeplane.

the class AttributeTable method updateRowHeights.

private void updateRowHeights() {
    if (!isDisplayable()) {
        addHierarchyListener(new HierarchyListener() {

            public void hierarchyChanged(HierarchyEvent e) {
                if (isDisplayable()) {
                    updateRowHeights();
                    removeHierarchyListener(this);
                }
            }
        });
        return;
    }
    final int rowCount = getRowCount();
    if (rowCount == 0) {
        return;
    }
    final int constHeight = getTableHeaderHeight() + AttributeTable.EXTRA_HEIGHT;
    final float zoom = getZoom();
    final float fontSize = (float) getFont().getMaxCharBounds(((Graphics2D) getGraphics()).getFontRenderContext()).getHeight();
    final float tableRowHeight = fontSize + zoom * AttributeTable.TABLE_ROW_HEIGHT;
    int newHeight = (int) ((tableRowHeight * rowCount + (zoom - 1) * constHeight) / rowCount);
    if (newHeight < 1) {
        newHeight = 1;
    }
    final int highRowsNumber = (int) ((tableRowHeight - newHeight) * rowCount);
    for (int i = 0; i < highRowsNumber; i++) {
        setRowHeight(i, 1 + newHeight + (i == highRowIndex ? AttributeTable.EXTRA_HEIGHT : 0));
    }
    for (int i = highRowsNumber; i < rowCount; i++) {
        setRowHeight(i, newHeight + (i == highRowIndex ? AttributeTable.EXTRA_HEIGHT : 0));
    }
}
Also used : HierarchyEvent(java.awt.event.HierarchyEvent) HierarchyListener(java.awt.event.HierarchyListener)

Aggregations

HierarchyListener (java.awt.event.HierarchyListener)20 HierarchyEvent (java.awt.event.HierarchyEvent)19 Window (java.awt.Window)5 WindowEvent (java.awt.event.WindowEvent)5 Component (java.awt.Component)4 WindowAdapter (java.awt.event.WindowAdapter)4 DetachedFrame (com.haulmont.cuba.desktop.DetachedFrame)2 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 JComboBox (javax.swing.JComboBox)2 JDialog (javax.swing.JDialog)2 RenderResult (com.android.tools.idea.rendering.RenderResult)1 ButtonTabComponent (com.haulmont.cuba.desktop.sys.ButtonTabComponent)1 DisabledGlassPane (com.haulmont.cuba.desktop.sys.DisabledGlassPane)1 Editor (com.intellij.openapi.editor.Editor)1 com.intellij.openapi.fileEditor (com.intellij.openapi.fileEditor)1 PsiFile (com.intellij.psi.PsiFile)1 Update (com.intellij.util.ui.update.Update)1 java.awt (java.awt)1 Dialog (java.awt.Dialog)1