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);
}
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;
}
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;
}
Aggregations