Search in sources :

Example 1 with TypedListCellRenderer

use of org.freeplane.core.ui.components.TypedListCellRenderer in project freeplane by freeplane.

the class ListDialog method init.

public void init(final Component locationComp, final String labelText, final IListModel data, final String longValue) {
    this.data = data;
    final JButton closeButton = new JButton();
    LabelAndMnemonicSetter.setLabelAndMnemonic(closeButton, TextUtils.getRawText("simplyhtml.closeBtnName"));
    closeButton.addActionListener(new CloseAction());
    getRootPane().setDefaultButton(closeButton);
    addButton = new JButton();
    LabelAndMnemonicSetter.setLabelAndMnemonic(addButton, TextUtils.getRawText("add"));
    final AddAction addAction = new AddAction();
    addButton.addActionListener(addAction);
    renameButton = new JButton();
    LabelAndMnemonicSetter.setLabelAndMnemonic(renameButton, TextUtils.getRawText("rename"));
    renameButton.addActionListener(new RenameAction());
    deleteButton = new JButton();
    LabelAndMnemonicSetter.setLabelAndMnemonic(deleteButton, TextUtils.getRawText("delete"));
    deleteButton.addActionListener(new DeleteAction());
    textField = new JTextField(20);
    textField.getDocument().addDocumentListener(new TextChangeListener());
    list = new JList(data) {

        /**
         */
        private static final long serialVersionUID = 1L;

        @Override
        public int getScrollableUnitIncrement(final Rectangle visibleRect, final int orientation, final int direction) {
            int row;
            if (orientation == SwingConstants.VERTICAL && direction < 0 && (row = getFirstVisibleIndex()) != -1) {
                final Rectangle r = getCellBounds(row, row);
                if ((r.y == visibleRect.y) && (row != 0)) {
                    final Point loc = r.getLocation();
                    loc.y--;
                    final int prevIndex = locationToIndex(loc);
                    final Rectangle prevR = getCellBounds(prevIndex, prevIndex);
                    if (prevR == null || prevR.y >= r.y) {
                        return 0;
                    }
                    return prevR.height;
                }
            }
            return super.getScrollableUnitIncrement(visibleRect, orientation, direction);
        }
    };
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    if (longValue != null) {
        list.setPrototypeCellValue(longValue);
    }
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    list.setVisibleRowCount(-1);
    list.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                addButton.doClick();
            }
        }
    });
    list.setCellRenderer(new TypedListCellRenderer());
    list.setModel(data);
    list.addListSelectionListener(new ListSelectionChangeListener());
    final JScrollPane listScroller = new JScrollPane(list);
    listScroller.setPreferredSize(new Dimension(250, 80));
    listScroller.setAlignmentX(Component.LEFT_ALIGNMENT);
    final JPanel listPane = new JPanel();
    listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
    final JLabel label = new JLabel(labelText);
    label.setLabelFor(list);
    listPane.add(label);
    listPane.add(Box.createRigidArea(new Dimension(0, 5)));
    listPane.add(listScroller);
    listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    final JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
    buttonPane.add(Box.createHorizontalGlue());
    buttonPane.add(closeButton);
    buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPane.add(addButton);
    buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPane.add(renameButton);
    buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPane.add(deleteButton);
    final JPanel textPane = new JPanel();
    textPane.setLayout(new BoxLayout(textPane, BoxLayout.LINE_AXIS));
    textPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
    textPane.add(textField);
    final Container contentPane = getContentPane();
    contentPane.add(textPane, BorderLayout.PAGE_START);
    contentPane.add(listPane, BorderLayout.CENTER);
    contentPane.add(buttonPane, BorderLayout.PAGE_END);
    updateButtons();
    pack();
    setLocationRelativeTo(locationComp);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) Rectangle(java.awt.Rectangle) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Point(java.awt.Point) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) Point(java.awt.Point) Container(java.awt.Container) TypedListCellRenderer(org.freeplane.core.ui.components.TypedListCellRenderer) JList(javax.swing.JList)

Example 2 with TypedListCellRenderer

use of org.freeplane.core.ui.components.TypedListCellRenderer 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 JComboBoxWithBorder();
    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 JComboBoxWithBorder();
    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) 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) JComboBoxWithBorder(org.freeplane.core.ui.components.JComboBoxWithBorder) Component(java.awt.Component) ClonedComboBoxModel(org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel) ComboBoxModel(javax.swing.ComboBoxModel)

Example 3 with TypedListCellRenderer

use of org.freeplane.core.ui.components.TypedListCellRenderer in project freeplane by freeplane.

the class AttributeTable method getCellEditor.

@SuppressWarnings("serial")
public TableCellEditor getCellEditor(final int row, final int col, EventObject e) {
    if (dce != null) {
        dce.stopCellEditing();
    }
    if (col == 1) {
        final MTextController textController = (MTextController) TextController.getController();
        if (e instanceof KeyEvent) {
            final KeyEvent kev = (KeyEvent) e;
            textController.getEventQueue().setFirstEvent(kev);
        }
        final IAttributeTableModel model = (IAttributeTableModel) getModel();
        final String text = getValueForEdit(row, col);
        final DialogTableCellEditor dialogTableCellEditor = new DialogTableCellEditor();
        EditNodeBase base = textController.getEditNodeBase(model.getNode(), text, dialogTableCellEditor.getEditControl(), false);
        if (base != null) {
            dialogTableCellEditor.setEditBase(base);
            return dialogTableCellEditor;
        }
    }
    final JComboBox comboBox;
    if (dce == null) {
        comboBox = new JComboBoxWithBorder() {

            // Workaround for bug introduced in Java 8: they use wrong component in DefaultCellEditor.EditorDelegate
            @Override
            public void actionPerformed(ActionEvent e) {
                if (e != null && e.getSource() == dce) {
                    super.actionPerformed(new ActionEvent(getEditor(), e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers()));
                } else
                    super.actionPerformed(e);
            }
        };
        comboBox.addFocusListener(AttributeTable.focusListener);
        comboBox.getEditor().getEditorComponent().addFocusListener(AttributeTable.focusListener);
        comboBox.setRenderer(new TypedListCellRenderer());
        dce = new DefaultCellEditor(comboBox) {

            public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) {
                return super.getTableCellEditorComponent(table, ((AttributeTable) table).getValueForEdit(row, col), isSelected, row, col);
            }
        };
        dce.setClickCountToStart(CLICK_COUNT_TO_START);
    }
    return dce;
}
Also used : JComboBox(javax.swing.JComboBox) EditNodeBase(org.freeplane.features.text.mindmapmode.EditNodeBase) ActionEvent(java.awt.event.ActionEvent) DefaultCellEditor(javax.swing.DefaultCellEditor) KeyEvent(java.awt.event.KeyEvent) TypedListCellRenderer(org.freeplane.core.ui.components.TypedListCellRenderer) JTable(javax.swing.JTable) IAttributeTableModel(org.freeplane.features.attribute.IAttributeTableModel) EventObject(java.util.EventObject) IFormattedObject(org.freeplane.features.format.IFormattedObject) FormattedObject(org.freeplane.features.format.FormattedObject) MTextController(org.freeplane.features.text.mindmapmode.MTextController) JComboBoxWithBorder(org.freeplane.core.ui.components.JComboBoxWithBorder) EditedComponent(org.freeplane.features.text.mindmapmode.EditNodeBase.EditedComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Aggregations

TypedListCellRenderer (org.freeplane.core.ui.components.TypedListCellRenderer)3 Component (java.awt.Component)2 Dimension (java.awt.Dimension)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 JComboBoxWithBorder (org.freeplane.core.ui.components.JComboBoxWithBorder)2 Container (java.awt.Container)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 ActionEvent (java.awt.event.ActionEvent)1 HierarchyEvent (java.awt.event.HierarchyEvent)1 HierarchyListener (java.awt.event.HierarchyListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 KeyEvent (java.awt.event.KeyEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1