Skip to content

Commit

Permalink
Merge pull request #88 from marc-outins/fix_filter_box_display
Browse files Browse the repository at this point in the history
Updates layout of filter dialog for a more consistent look and feel
  • Loading branch information
schuemie committed Jun 18, 2015
2 parents c343f8d + 543e4ed commit 4f8723a
Showing 1 changed file with 51 additions and 21 deletions.
72 changes: 51 additions & 21 deletions src/org/ohdsi/rabbitInAHat/FilterDialog.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package org.ohdsi.rabbitInAHat;

import java.awt.Container;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import org.ohdsi.rabbitInAHat.ResizeListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;

Expand All @@ -29,60 +32,70 @@ public class FilterDialog extends JDialog implements ActionListener, ResizeListe

SpringLayout layout = new SpringLayout();

JPanel mainView = new JPanel(layout);
Container contentPane = this.getContentPane();

public FilterDialog(Window parentWindow){

super(parentWindow,"Filter",ModalityType.MODELESS);
this.setResizable(false);
this.setLocation(parentWindow.getX()+parentWindow.getWidth()/2, parentWindow.getY()+100);
this.setSize(700,120);

sourceSearchField = new JTextField(40);

contentPane.setLayout(layout);
sourceSearchField = new JTextField(30);
sourceSearchField.setName("Source");

targetSearchField = new JTextField(40);
targetSearchField = new JTextField(30);
targetSearchField.setName("Target");


// Add key listener to send search string as it's being typed
sourceSearchField.addKeyListener(new SearchListener() );
sourceSearchField.addFocusListener(new SearchFocusListener());
JLabel sourceLabel = new JLabel("Filter Source:",JLabel.TRAILING);
JButton sourceClearBtn = new JButton("Clear");
mainView.add(sourceLabel);
mainView.add(sourceSearchField);
contentPane.add(sourceLabel);
contentPane.add(sourceSearchField);
sourceClearBtn.addActionListener(this);
sourceClearBtn.setActionCommand("Clear Source");
mainView.add(sourceClearBtn);
sourceClearBtn.setFocusable(false);
contentPane.add(sourceClearBtn);

targetSearchField.addKeyListener(new SearchListener() );
targetSearchField.addFocusListener(new SearchFocusListener());
JLabel targetLabel = new JLabel("Filter Target:",JLabel.TRAILING);
JButton targetClearBtn = new JButton("Clear");
mainView.add(targetLabel);
mainView.add(targetSearchField);
contentPane.add(targetLabel);
contentPane.add(targetSearchField);
targetClearBtn.addActionListener(this);
targetClearBtn.setActionCommand("Clear Target");
mainView.add(targetClearBtn);
targetClearBtn.setFocusable(false);
contentPane.add(targetClearBtn);

layout.putConstraint(SpringLayout.WEST, sourceLabel, 10, SpringLayout.WEST, mainView);
layout.putConstraint(SpringLayout.NORTH, sourceLabel, 10, SpringLayout.NORTH, mainView);
layout.putConstraint(SpringLayout.WEST, sourceLabel, 5, SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, sourceLabel, 5, SpringLayout.NORTH, contentPane);

layout.putConstraint(SpringLayout.WEST, sourceSearchField, 5, SpringLayout.EAST, sourceLabel);
layout.putConstraint(SpringLayout.NORTH, sourceSearchField, 10, SpringLayout.NORTH, mainView);
layout.putConstraint(SpringLayout.NORTH, sourceSearchField, 5, SpringLayout.NORTH, contentPane);

layout.putConstraint(SpringLayout.WEST, sourceClearBtn, 5, SpringLayout.EAST, sourceSearchField);
layout.putConstraint(SpringLayout.NORTH, sourceClearBtn, 10, SpringLayout.NORTH, mainView);
layout.putConstraint(SpringLayout.NORTH, sourceClearBtn, 5, SpringLayout.NORTH, contentPane);

layout.putConstraint(SpringLayout.WEST, targetLabel, 10, SpringLayout.WEST, mainView);
layout.putConstraint(SpringLayout.WEST, targetLabel, 5, SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, targetLabel, 10, SpringLayout.SOUTH, sourceLabel);

layout.putConstraint(SpringLayout.WEST, targetSearchField, 0, SpringLayout.WEST, sourceSearchField);
layout.putConstraint(SpringLayout.NORTH, targetSearchField, 0, SpringLayout.NORTH, targetLabel);

layout.putConstraint(SpringLayout.WEST, targetClearBtn, 5, SpringLayout.EAST, targetSearchField);
layout.putConstraint(SpringLayout.NORTH, targetClearBtn, 0, SpringLayout.NORTH, targetSearchField);
layout.putConstraint(SpringLayout.NORTH, targetClearBtn, 0, SpringLayout.NORTH, targetSearchField);


this.add(mainView);
layout.putConstraint(SpringLayout.SOUTH, contentPane, 5, SpringLayout.SOUTH, targetLabel);
layout.putConstraint(SpringLayout.NORTH, contentPane, 5, SpringLayout.NORTH, sourceLabel);
layout.putConstraint(SpringLayout.WEST, contentPane, 5, SpringLayout.WEST, sourceLabel);
layout.putConstraint(SpringLayout.EAST, contentPane, 5, SpringLayout.EAST, targetClearBtn);

this.pack();
};

public void setFilterPanel(MappingPanel aFilterPanel){
Expand Down Expand Up @@ -174,6 +187,23 @@ public void keyTyped(KeyEvent event) {

}

public class SearchFocusListener implements FocusListener {

@Override
public void focusGained(FocusEvent e) {
// TODO Auto-generated method stub
JTextField jtf = (JTextField) e.getComponent();
jtf.selectAll();
}

@Override
public void focusLost(FocusEvent e) {
// TODO Auto-generated method stub

}

}


}

0 comments on commit 4f8723a

Please sign in to comment.