Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
ISSUE-10 Add "Move Up" & "Move Down" buttons to "Property files" panel
Browse files Browse the repository at this point in the history
  • Loading branch information
shyiko committed Feb 3, 2011
1 parent 73fba6e commit 0a6bf4e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ivyplug/ui/PropertiesCompositePanel.java
Expand Up @@ -19,7 +19,7 @@ public class PropertiesCompositePanel extends JPanel {
public PropertiesCompositePanel() {
setLayout(new GridBagLayout());
final GridBagConstraints gc = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0);
GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 0), 0, 0);
add(propertyFilesLabel, gc);
add(propertyFilesPanel, gc);
add(customPropertiesLabel, gc);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ivyplug/ui/PropertiesPanel.java
Expand Up @@ -83,7 +83,9 @@ public void actionPerformed(ActionEvent e) {
add(propertyFilesWrapperPanel, BorderLayout.CENTER);
JPanel controlPanel = new JPanel(new GridBagLayout());
final GridBagConstraints gc = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0);
GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 0), 0, 0);
addButton.setSize(new Dimension(104, 25));
addButton.setPreferredSize(new Dimension(104, 25));
controlPanel.add(addButton, gc);
controlPanel.add(removeButton, gc);
gc.weighty = 1.0;
Expand Down
37 changes: 34 additions & 3 deletions src/main/java/ivyplug/ui/PropertyFilesPanel.java
Expand Up @@ -28,6 +28,8 @@ public class PropertyFilesPanel extends JPanel {
private final JBList propertyFilesList = new JBList(new DefaultListModel());
private final JButton addButton = new JButton("Add");
private final JButton removeButton = new JButton("Remove");
private final JButton moveUpButton = new JButton("Move Up");
private final JButton moveDownButton = new JButton("Move Down");
private boolean modified;

public PropertyFilesPanel() {
Expand Down Expand Up @@ -55,6 +57,31 @@ public void actionPerformed(ActionEvent e) {
}
});

moveUpButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DefaultListModel model = (DefaultListModel) propertyFilesList.getModel();
int selectedIndex = propertyFilesList.getSelectedIndex();
if (selectedIndex > 0) {
Object selectedItem = model.remove(selectedIndex);
model.add(selectedIndex - 1, selectedItem);
propertyFilesList.setSelectedIndex(selectedIndex - 1);
}
}
});

moveDownButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DefaultListModel model = (DefaultListModel) propertyFilesList.getModel();
int selectedIndex = propertyFilesList.getSelectedIndex();
int size = model.getSize();
if (selectedIndex + 1 < size) {
Object selectedItem = model.remove(selectedIndex);
model.add(selectedIndex + 1, selectedItem);
propertyFilesList.setSelectedIndex(selectedIndex + 1);
}
}
});

propertyFilesList.getModel().addListDataListener(new ListDataListener() {

public void intervalAdded(ListDataEvent e) { setModified(); }
Expand All @@ -63,18 +90,22 @@ public void actionPerformed(ActionEvent e) {
});

setLayout(new BorderLayout());
setPreferredSize(new Dimension(100, 100));
setMinimumSize(new Dimension(100, 100));
setPreferredSize(new Dimension(100, 140));
setMinimumSize(new Dimension(100, 140));
propertyFilesList.setBorder(BorderFactory.createEtchedBorder());
JPanel propertyFilesWrapperPanel = new JPanel(new BorderLayout());
propertyFilesWrapperPanel.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
propertyFilesWrapperPanel.add(ScrollPaneFactory.createScrollPane(propertyFilesList), BorderLayout.CENTER);
add(propertyFilesWrapperPanel, BorderLayout.CENTER);
JPanel controlPanel = new JPanel(new GridBagLayout());
final GridBagConstraints gc = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0);
GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 0), 0, 0);
addButton.setSize(new Dimension(104, 25));
addButton.setPreferredSize(new Dimension(104, 25));
controlPanel.add(addButton, gc);
controlPanel.add(removeButton, gc);
controlPanel.add(moveUpButton, gc);
controlPanel.add(moveDownButton, gc);
gc.weighty = 1.0;
controlPanel.add(new JPanel(new GridBagLayout()), gc);
controlPanel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
Expand Down

0 comments on commit 0a6bf4e

Please sign in to comment.