List of usage examples for javax.swing BoxLayout Y_AXIS
int Y_AXIS
To view the source code for javax.swing BoxLayout Y_AXIS.
Click Source Link
From source file:org.rimudb.editor.DescriptorEditor.java
private JPanel createButtonPanel() { addColumnBtn = createMenuButtonVert("Add..."); addColumnBtn.setName("AddColumnBtn"); addColumnBtn.addActionListener(this); removeColumnBtn = createMenuButtonVert("Remove"); removeColumnBtn.setName("RemoveColumnBtn"); removeColumnBtn.setEnabled(false);/*from w w w .ja v a2 s . co m*/ removeColumnBtn.addActionListener(this); moveUpBtn = createMenuButtonVert("Move up"); moveUpBtn.setName("MoveUpBtn"); moveUpBtn.setEnabled(false); moveUpBtn.addActionListener(this); moveDownBtn = createMenuButtonVert("Move down"); moveDownBtn.setName("MoveDownBtn"); moveDownBtn.setEnabled(false); moveDownBtn.addActionListener(this); addPkBtn = createMenuButtonVert("Add..."); addPkBtn.setName("AddPkBtn"); addPkBtn.addActionListener(this); removePkBtn = createMenuButtonVert("Remove"); removePkBtn.setName("RemovePkBtn"); removePkBtn.setEnabled(false); removePkBtn.addActionListener(this); JPanel buttonPanel = new JPanel(); buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 0)); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS)); buttonPanel.add(addColumnBtn); buttonPanel.add(Box.createRigidArea(new Dimension(0, 5))); buttonPanel.add(removeColumnBtn); buttonPanel.add(Box.createRigidArea(new Dimension(0, 5))); buttonPanel.add(moveUpBtn); buttonPanel.add(Box.createRigidArea(new Dimension(0, 5))); buttonPanel.add(moveDownBtn); buttonPanel.add(Box.createRigidArea(new Dimension(0, 242))); buttonPanel.add(addPkBtn); buttonPanel.add(Box.createRigidArea(new Dimension(0, 5))); buttonPanel.add(removePkBtn); buttonPanel.add(Box.createGlue()); return buttonPanel; }
From source file:org.rimudb.editor.DescriptorEditor.java
/** * Build the panel/*from w w w .ja v a 2 s . c o m*/ */ private JPanel createColumnTablePanel() { JPanel columnPanel = new JPanel(); columnPanel.setLayout(new BoxLayout(columnPanel, BoxLayout.Y_AXIS)); // Create the property table panel propertyModel = new PropertyTableModel(); // Add a listener to set the changed state propertyModel.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { markChanged(); if (e instanceof PropertyTableModelEvent) { PropertyTableModelEvent ptme = (PropertyTableModelEvent) e; // If the columnName column was changed then check it isn't // a PK if (ptme.getColumn() == 1) { String beforeColumnName = (String) ptme.getBeforeValue(); String afterColumnName = (String) ptme.getAfterValue(); // Is the field entry in the list of primary keys? for (int i = 0; i < pkListModel.getSize(); i++) { String pkColumnName = (String) pkListModel.get(i); // If it's found then remove it if (beforeColumnName.equals(pkColumnName)) { pkListModel.set(i, afterColumnName); break; } } } } } }); table = new ATable(getPropertyModel()); table.setName("ColumnTable"); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { int selectedRowCount = table.getSelectedRowCount(); removeColumnBtn.setEnabled(selectedRowCount > 0); moveUpBtn.setEnabled(selectedRowCount > 0); moveDownBtn.setEnabled(selectedRowCount > 0); } }); table.setTransferHandler(new TransferHandler() { public int getSourceActions(JComponent c) { return COPY; } protected Transferable createTransferable(JComponent c) { ATable columnTable = (ATable) c; int row = columnTable.getSelectedRow(); String columnName = getPropertyModel().getRow(row).getColumnName(); return new StringSelection(columnName); } }); table.setDragEnabled(true); JScrollPane sp = new JScrollPane(table); sp.setMaximumSize(new Dimension(Short.MAX_VALUE, 325)); sp.setPreferredSize(new Dimension(Short.MAX_VALUE, 325)); sp.setMinimumSize(new Dimension(Short.MAX_VALUE, 325)); JComboBox typeCB = new JComboBox(DatabaseTypes.getAllTypes()); typeCB.setEditable(false); javax.swing.table.TableColumn typeColumn = table.getColumnModel().getColumn(2); typeColumn.setCellEditor(new DefaultCellEditor(typeCB)); // Create the popup menu and set it on the table propertyPopup = new TablePopupMenu(this, table); table.addMouseListener(propertyPopup); sp.addMouseListener(propertyPopup); sp.setAlignmentX(LEFT_ALIGNMENT); columnPanel.add(sp); columnPanel.add(Box.createVerticalStrut(10)); JLabel pkLabel = new JLabel("Primary Key Columns", SwingConstants.LEFT); pkLabel.setAlignmentX(LEFT_ALIGNMENT); columnPanel.add(pkLabel); pkListModel = new DefaultListModel(); pkListModel.addListDataListener(new ListDataListener() { public void intervalRemoved(ListDataEvent e) { markChanged(); } public void intervalAdded(ListDataEvent e) { markChanged(); } public void contentsChanged(ListDataEvent e) { markChanged(); } }); pkList = new JList(pkListModel); pkList.setName("pkList"); pkList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); pkList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { int selectedRowCount = pkList.getSelectedIndex(); removePkBtn.setEnabled(selectedRowCount > -1); } }); pkList.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport info) { // we only import Strings if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); if (dl.getIndex() == -1) { return false; } return true; } public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; } // Check for String flavor if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { displayDropLocation("List doesn't accept a drop of this type."); return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); DefaultListModel listModel = (DefaultListModel) pkList.getModel(); int index = dl.getIndex(); // Get the string that is being dropped. Transferable t = info.getTransferable(); String data; try { data = (String) t.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } // If this is a copy action then check we don't already have that String if (info.getDropAction() == COPY && listModel.indexOf(data) > -1) { displayDropLocation("The column " + data + " is already a primary key"); return false; } // Perform the actual import. if (dl.isInsert()) { int oldIndex = listModel.indexOf(data); if (oldIndex < index) { listModel.add(index, data); listModel.remove(oldIndex); } else { listModel.remove(oldIndex); listModel.add(index, data); } } else { // Don't handle replacements } return true; } public int getSourceActions(JComponent c) { return MOVE; } protected Transferable createTransferable(JComponent c) { JList list = (JList) c; Object[] values = list.getSelectedValues(); StringBuffer buff = new StringBuffer(); for (int i = 0; i < values.length; i++) { Object val = values[i]; buff.append(val == null ? "" : val.toString()); if (i != values.length - 1) { buff.append("\n"); } } return new StringSelection(buff.toString()); } }); pkList.setDropMode(DropMode.INSERT); pkList.setDragEnabled(true); JScrollPane pkScrollPanel = new JScrollPane(pkList); pkScrollPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, 100)); pkScrollPanel.setAlignmentX(LEFT_ALIGNMENT); columnPanel.add(pkScrollPanel); return columnPanel; }
From source file:org.rimudb.editor.RimuDBEditor.java
/** * DataObjectEditor//from w ww . j ava2s . c o m */ public RimuDBEditor() { super(TITLE); log.debug(System.getProperties()); logMemory(); // Create a preferences object preferences = new RimuDBPreferences(this.getClass().getName()); // Use the system l&f try { String plaf = UIManager.getSystemLookAndFeelClassName(); UIManager.setLookAndFeel(plaf); } catch (Exception e) { } setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { if (getDescriptorEditor().hasChanged()) { log.debug("windowClosing() Save changes to table descriptor?"); int option = JOptionPane.showConfirmDialog(RimuDBEditor.this, "Save changes to Table Descriptor?", "RimuDB Editor", JOptionPane.YES_NO_CANCEL_OPTION); // Cancel the close operation if (option == JOptionPane.CANCEL_OPTION) { // setVisible(true); return; } // Save the file if (option == JOptionPane.YES_OPTION) { log.debug("windowClosing() saving data"); getDescriptorFileContoller().save(); } } log.debug("System.exit(0)"); System.exit(0); } }); setIconImage(loadIcon("/images/rimudb_logo.gif").getImage()); descriptorFileController = new DescriptorFileController(this); setJMenuBar(buildJMenuBar()); JToolBar toolbar = createToolbar(); editor = new DescriptorEditor(this); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(toolbar, BorderLayout.NORTH); panel.add(new JSeparator()); panel.add(editor, BorderLayout.CENTER); setContentPane(panel); pack(); editor.requestPackageFocus(); // Center in the screen setLocationRelativeTo(null); startDriverCheck(); }
From source file:org.sikuli.ide.extmanager.ExtensionManagerFrame.java
void createComponents() { Container pane;//from ww w. ja v a 2s. co m pane = getContentPane(); pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); try { // Populate the list of extensions _extensions = retrieveExtensions(); for (ExtensionItem ext : _extensions) { pane.add(ext); ; } // Select the first one select(0); } catch (IOException io) { String msg = "Unable to load extensions from the server: " + io.getMessage(); JTextField txt = new JTextField(msg); txt.setBackground(null); txt.setBorder(null); txt.setEditable(false); pane.add(txt); } JPanel bottomBar = new JPanel(); bottomBar.setLayout(new BorderLayout()); bottomBar.setMinimumSize(new Dimension(400, 20)); JButton closeBtn = new JButton("Close"); closeBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { dispose(); } }); closeBtn.setFocusable(false); bottomBar.add(closeBtn, BorderLayout.LINE_END); pane.add(bottomBar); }
From source file:org.sonar.ide.ui.ServerPanel.java
public ServerPanel() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); host = new JTextField(); username = new JTextField(); password = new JPasswordField(); useGlobalProxyConfiguration = new JCheckBox("Use global network connections preferences", true); proxyHost = new JTextField(); proxyPort = new JTextField(); proxyUsername = new JTextField(); proxyPassword = new JPasswordField(); // TODO Godin: enable in future useGlobalProxyConfiguration.setEnabled(false); proxyHost.setEnabled(false);// www.j a v a 2 s.c o m proxyPort.setEnabled(false); proxyUsername.setEnabled(false); proxyPassword.setEnabled(false); final JButton testConnectionButton = new JButton("Test connection"); testConnectionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO throw new NotImplementedException(); } }); DefaultFormBuilder formBuilder = new DefaultFormBuilder(new FormLayout("")); formBuilder.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); formBuilder.appendColumn("right:pref"); formBuilder.appendColumn("3dlu"); formBuilder.appendColumn("fill:p:g"); formBuilder.append("Sonar server URL:", host); formBuilder.append("Username:", username); formBuilder.append("Password:", password); formBuilder.appendSeparator("Proxy server configuration"); formBuilder.append("", useGlobalProxyConfiguration); formBuilder.append("Host:", proxyHost); formBuilder.append("Port:", proxyPort); // formBuilder.append("Enable proxy authentication", new JCheckBox()); formBuilder.append("Username:", proxyUsername); formBuilder.append("Password:", proxyPassword); formBuilder.append(testConnectionButton); add(formBuilder.getPanel()); }
From source file:org.tinymediamanager.ui.tvshows.TvShowTreeCellRenderer.java
/** * Instantiates a new tv show tree cell renderer. *//*from w ww . java2 s.c om*/ public TvShowTreeCellRenderer() { tvShowPanel.setLayout(new FormLayout( new ColumnSpec[] { ColumnSpec.decode("min:grow"), FormFactory.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("center:20px"), ColumnSpec.decode("center:20px"), ColumnSpec.decode("center:20px") }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); TmmFontHelper.changeFont(tvShowTitle, Font.BOLD); tvShowTitle.setHorizontalAlignment(JLabel.LEFT); tvShowTitle.setMinimumSize(new Dimension(0, 0)); tvShowTitle.setHorizontalTextPosition(SwingConstants.LEADING); tvShowPanel.add(tvShowTitle, "1, 1"); tvShowPanel.add(tvShowNfoLabel, "3, 1, 1, 2"); tvShowPanel.add(tvShowImageLabel, "4, 1, 1, 2"); TmmFontHelper.changeFont(tvShowInfo, 0.816); tvShowInfo.setHorizontalAlignment(JLabel.LEFT); tvShowInfo.setMinimumSize(new Dimension(0, 0)); tvShowPanel.add(tvShowInfo, "1, 2"); tvShowSeasonPanel.setLayout(new BoxLayout(tvShowSeasonPanel, BoxLayout.Y_AXIS)); tvShowSeasonPanel.add(tvShowSeasonTitle); tvShowSeasonTitle.setHorizontalTextPosition(SwingConstants.LEADING); tvShowEpisodePanel .setLayout( new FormLayout( new ColumnSpec[] { ColumnSpec.decode("min:grow"), FormFactory.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("center:20px"), ColumnSpec.decode("center:20px"), ColumnSpec.decode("center:20px") }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC })); tvShowEpisodeTitle.setMinimumSize(new Dimension(0, 0)); tvShowEpisodeTitle.setHorizontalTextPosition(SwingConstants.LEADING); tvShowEpisodePanel.add(tvShowEpisodeTitle, "1, 1"); tvShowEpisodePanel.add(tvShowEpisodeNfoLabel, "3, 1"); tvShowEpisodePanel.add(tvShowEpisodeImageLabel, "4, 1"); tvShowEpisodePanel.add(tvShowEpisodeSubtitleLabel, "5, 1"); }
From source file:org.ut.biolab.medsavant.client.project.ProjectWizard.java
private AbstractWizardPage getReferencePage() throws SQLException, RemoteException { //setup page/* w w w . j a v a 2s .c om*/ final DefaultWizardPage page = new DefaultWizardPage(PAGENAME_REF) { @Override public void setupWizardButtons() { fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.BACK); fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH); fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT); } }; page.addText("Choose reference genome(s) to add to this project, along\n" + "with corresponding annotations. Annotations will be\n" + "applied to all variants added to these tables."); //setup list JScrollPane scrollpane = new JScrollPane(); scrollpane.setPreferredSize(new Dimension(300, 220)); scrollpane.getViewport().setBackground(Color.white); final JPanel p = new JPanel(); p.setBackground(Color.white); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); refreshReferencePanel(p); scrollpane.getViewport().add(p); page.addComponent(scrollpane); JButton addRefButton = new JButton("New Reference"); addRefButton.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { try { new NewReferenceDialog().setVisible(true); refreshReferencePanel(p); } catch (Exception ex) { ClientMiscUtils.reportError("Unable to retrieve references and annotations: %s", ex); } } }); page.addComponent(addRefButton); return page; }
From source file:org.ut.biolab.medsavant.client.query.view.NumberSearchConditionEditorView.java
@Override public void loadViewFromSearchConditionParameters(String encoding) throws ConditionRestorationException { double[] selectedValues; if (encoding == null) { selectedValues = null;/*from www .j a v a 2s . com*/ } else { selectedValues = NumericConditionEncoder.unencodeConditions(encoding); } final double[] extremeValues = generator.getExtremeNumericValues(); this.removeAll(); if (extremeValues == null || (extremeValues[0] == 0 && extremeValues[1] == 0)) { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.add(Box.createHorizontalGlue()); p.add(new JLabel("<html>All values are blank for this condition.</html>")); p.add(Box.createHorizontalGlue()); this.add(p); return; } setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); JPanel p = ViewUtil.getClearPanel(); ViewUtil.applyVerticalBoxLayout(p); JPanel labelPanel = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(labelPanel); labelPanel.add(Box.createHorizontalGlue()); labelPanel.add(new JLabel("Filtering variants where " + item.getName() + ": ")); labelPanel.add(Box.createHorizontalGlue()); ButtonGroup group = new ButtonGroup(); //JRadioButton isButton = new JRadioButton("is within the following range:"); //JRadioButton nullButton = new JRadioButton("is missing"); //group.add(isButton); //group.add(nullButton); final JCheckBox nullButton = new JCheckBox("include missing values"); JPanel bp = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(bp); p.add(labelPanel); p.add(bp); add(p); final DecimalRangeSlider slider = new DecimalRangeSlider(); slider.setMajorTickSpacing(5); slider.setMinorTickSpacing(1); final JTextField fromBox = new JTextField(); final JTextField toBox = new JTextField(); nullButton.setSelected(NumericConditionEncoder.encodesNull(encoding)); nullButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()), ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0], extremeValues[1], nullButton.isSelected()); } }); fromBox.setMaximumSize(new Dimension(10000, 24)); toBox.setMaximumSize(new Dimension(10000, 24)); fromBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24)); toBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24)); fromBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24)); toBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24)); fromBox.setHorizontalAlignment(JTextField.RIGHT); toBox.setHorizontalAlignment(JTextField.RIGHT); final JLabel fromLabel = new JLabel(); final JLabel toLabel = new JLabel(); ViewUtil.makeMini(fromLabel); ViewUtil.makeMini(toLabel); JPanel fromToContainer = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(fromToContainer); fromToContainer.add(Box.createHorizontalGlue()); fromToContainer.add(fromBox); fromToContainer.add(new JLabel(" - ")); fromToContainer.add(toBox); fromToContainer.add(Box.createHorizontalGlue()); JPanel minMaxContainer = ViewUtil.getClearPanel(); minMaxContainer.setLayout(new BoxLayout(minMaxContainer, BoxLayout.X_AXIS)); JPanel sliderContainer = ViewUtil.getClearPanel(); sliderContainer.setLayout(new BoxLayout(sliderContainer, BoxLayout.Y_AXIS)); sliderContainer.add(slider); JPanel nullValueContainer = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(nullValueContainer); nullValueContainer.add(Box.createHorizontalGlue()); nullValueContainer.add(nullButton); nullButton.setBackground(nullValueContainer.getBackground()); //fixes a windows issue. nullValueContainer.add(Box.createHorizontalGlue()); JPanel labelContainer = ViewUtil.getClearPanel(); labelContainer.setLayout(new BoxLayout(labelContainer, BoxLayout.X_AXIS)); labelContainer.add(fromLabel); labelContainer.add(Box.createHorizontalGlue()); labelContainer.add(toLabel); sliderContainer.add(labelContainer); minMaxContainer.add(Box.createHorizontalGlue()); minMaxContainer.add(sliderContainer); minMaxContainer.add(Box.createHorizontalGlue()); add(fromToContainer); add(minMaxContainer); add(nullValueContainer); add(Box.createVerticalBox()); slider.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (slider.isEnabled()) { fromBox.setText(ViewUtil.numToString(slider.getLow())); toBox.setText(ViewUtil.numToString(slider.getHigh())); encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()), ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0], extremeValues[1], nullButton.isSelected()); } } }); final KeyListener keyListener = new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_ENTER) { Range selectedRage = new Range(getNumber(fromBox.getText()), getNumber(toBox.getText())); setSelectedValues(slider, fromBox, toBox, selectedRage); } } private double getNumber(String s) { try { return Double.parseDouble(s.replaceAll(",", "")); } catch (NumberFormatException ignored) { return 0; } } }; CaretListener caretListener = new CaretListener() { @Override public void caretUpdate(CaretEvent ce) { if (!isAdjustingSlider) { try { encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()), ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0], extremeValues[1], nullButton.isSelected()); } catch (Exception e) { } } } }; fromBox.addKeyListener(keyListener); toBox.addKeyListener(keyListener); fromBox.addCaretListener(caretListener); toBox.addCaretListener(caretListener); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { isAdjustingSlider = true; fromBox.setText(ViewUtil.numToString(slider.getLow())); toBox.setText(ViewUtil.numToString(slider.getHigh())); isAdjustingSlider = false; } }); JPanel bottomContainer = new JPanel(); bottomContainer.setLayout(new BoxLayout(bottomContainer, BoxLayout.X_AXIS)); bottomContainer.add(Box.createHorizontalGlue()); add(bottomContainer); setExtremeValues(slider, fromLabel, toLabel, fromBox, toBox, 0, new Range(extremeValues[0], extremeValues[1])); if (encoding != null) { double[] d = NumericConditionEncoder.unencodeConditions(encoding); setSelectedValues(slider, fromBox, toBox, new Range(d[0], d[1])); } }
From source file:org.ut.biolab.medsavant.client.region.RegionWizard.java
private AbstractWizardPage getGenesPage() { return new DefaultWizardPage(PAGENAME_GENES) { private static final int GENE_SELECTION_PANE_WIDTH = 350; private JPanel leftSide; private GeneSelectionPanel geneManiaResultsPanel; private Set<String> geneManiaGeneNames = null; {// w ww. j a v a 2s .co m selectedGenesPanel = new GeneSelectionPanel(true, true); sourceGenesPanel = new GeneSelectionPanel(true, true); geneManiaResultsPanel = new GeneSelectionPanel(true, true) { @Override protected void dragAndDropAddGenes(Set<Gene> geneSet) { Set<Object> genesToMoveToGeneManiaPanel = new HashSet<Object>(geneManiaGeneNames); genesToMoveToGeneManiaPanel.retainAll(selectedGenesPanel.getSelectedKeys()); selectedGenesPanel.copyItems(geneManiaResultsPanel, genesToMoveToGeneManiaPanel); selectedGenesPanel.moveSelectedItems(sourceGenesPanel); } @Override protected void dragAndDropRemoveKeys(Set<Object> keySet) { Set<Object> keys = geneManiaResultsPanel.getSelectedKeys(); geneManiaResultsPanel.removeRows(keys); sourceGenesPanel.removeRows(keys); } }; geneManiaResultsPanel.setOddRowColor(new Color(242, 249, 245)); runGeneManiaButton = new JButton("Run GeneMANIA"); runGeneManiaButton.setEnabled(!DirectorySettings.isGeneManiaInstalled()); ListSelectionListener selectionListener = new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent lse) { int numSel = sourceGenesPanel.getNumSelected() + selectedGenesPanel.getNumSelected(); if (geneManiaGeneNames != null) { numSel += geneManiaResultsPanel.getNumSelected(); } if (GenemaniaInfoRetriever.isGeneManiaDownloading()) { runGeneManiaButton.setEnabled(false); } else { runGeneManiaButton.setEnabled(numSel > 0 || !DirectorySettings.isGeneManiaInstalled()); } } }; sourceGenesPanel.getTable().getSelectionModel().addListSelectionListener(selectionListener); selectedGenesPanel.getTable().getSelectionModel().addListSelectionListener(selectionListener); selectedGenesPanel.getTable().getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent tme) { if (selectedGenesPanel.getData().length > 0) { fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT); } else { fireButtonEvent(ButtonEvent.DISABLE_BUTTON, ButtonNames.NEXT); } } }); selectedGenesPanel.setPreferredSize( new Dimension(GENE_SELECTION_PANE_WIDTH, selectedGenesPanel.getPreferredSize().height)); final JPanel outerLeftSide = new JPanel(); outerLeftSide.setLayout(new BoxLayout(outerLeftSide, BoxLayout.X_AXIS)); leftSide = new JPanel(); leftSide.setLayout(new BoxLayout(leftSide, BoxLayout.Y_AXIS)); leftSide.add(sourceGenesPanel); outerLeftSide.add(leftSide); final JPanel bg = new JPanel(); bg.setLayout(new BoxLayout(bg, BoxLayout.Y_AXIS)); JButton addButton = new JButton("Add "); JButton removeButton = new JButton("? Remove"); sourceGenesPanel.getTable().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { if (me.getClickCount() == 2) { sourceGenesPanel.moveSelectedItems(selectedGenesPanel); } } }); selectedGenesPanel.getTable().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { if (me.getClickCount() == 2) { if (geneManiaGeneNames != null) { Set<Object> genesToMoveToGeneManiaPanel = new HashSet<Object>(geneManiaGeneNames); genesToMoveToGeneManiaPanel.retainAll(selectedGenesPanel.getSelectedKeys()); selectedGenesPanel.copyItems(geneManiaResultsPanel, genesToMoveToGeneManiaPanel); } selectedGenesPanel.moveSelectedItems(sourceGenesPanel); } } }); geneManiaResultsPanel.getTable().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { if (me.getClickCount() == 2) { Set<Object> keys = geneManiaResultsPanel.getSelectedKeys(); geneManiaResultsPanel.moveSelectedItems(selectedGenesPanel); sourceGenesPanel.moveItems(selectedGenesPanel, keys); } } }); addButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (geneManiaGeneNames != null) { Set<Object> keys = geneManiaResultsPanel.getSelectedKeys(); geneManiaResultsPanel.moveSelectedItems(selectedGenesPanel); sourceGenesPanel.moveItems(selectedGenesPanel, keys); } else { sourceGenesPanel.moveSelectedItems(selectedGenesPanel); } } }); removeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (geneManiaGeneNames != null) { Set<Object> genesToMoveToGeneManiaPanel = new HashSet<Object>(geneManiaGeneNames); genesToMoveToGeneManiaPanel.retainAll(selectedGenesPanel.getSelectedKeys()); selectedGenesPanel.copyItems(geneManiaResultsPanel, genesToMoveToGeneManiaPanel); } selectedGenesPanel.moveSelectedItems(sourceGenesPanel); } }); bg.add(Box.createVerticalGlue()); bg.add(addButton); bg.add(removeButton); bg.add(Box.createVerticalGlue()); outerLeftSide.add(bg); JPanel rightSide = new JPanel(); rightSide.setLayout(new BoxLayout(rightSide, BoxLayout.Y_AXIS)); rightSide.add(selectedGenesPanel); rightSide.add(runGeneManiaButton); final JSplitPane hsplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, outerLeftSide, rightSide); hsplitPane.setResizeWeight(1); addComponent(hsplitPane, true); if (!DirectorySettings.isGeneManiaInstalled()) { runGeneManiaButton.setText("Download GeneMANIA"); if (GenemaniaInfoRetriever.isGeneManiaDownloading()) { runGeneManiaButton.setEnabled(false); registerDownloadListener(); } } runGeneManiaButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (!DirectorySettings.isGeneManiaInstalled()) { int response = DialogUtils.askYesNo("Download GeneMANIA?", "GeneMANIA is not yet installed. Do you want to download and install it now?"); try { if (response == DialogUtils.OK) { runGeneManiaButton.setText("Run GeneMANIA"); runGeneManiaButton.setEnabled(false); registerDownloadListener(); /* DownloadTask dt = GenemaniaInfoRetriever.getGeneManiaDownloadTask(); dt.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("downloadState")) { DownloadTask.DownloadState ds = (DownloadTask.DownloadState) evt.getNewValue(); if (ds == DownloadTask.DownloadState.CANCELLED || ds == DownloadTask.DownloadState.FINISHED) { runGeneManiaButton.setEnabled( (selectedGenesPanel.getNumSelected() + sourceGenesPanel.getNumSelected()) > 0); } } } }); */ GenemaniaInfoRetriever.getGeneManiaDownloadTask().execute(); } } catch (IOException e) { DialogUtils.displayMessage("Error downloading GeneMANIA files"); LOG.error(e); } } else { final List<String> selectedGenes = new LinkedList<String>(); for (Gene g : selectedGenesPanel.getSelectedGenes()) { selectedGenes.add(g.getName()); } for (Gene g : sourceGenesPanel.getSelectedGenes()) { selectedGenes.add(g.getName()); } if (geneManiaGeneNames != null) { for (Gene g : geneManiaResultsPanel.getSelectedGenes()) { selectedGenes.add(g.getName()); } } final JButton closeGeneManiaButton = new JButton("? Close GeneMANIA results"); closeGeneManiaButton.setEnabled(false); final JPanel geneManiaContainingPanel = new JPanel(); geneManiaContainingPanel .setLayout(new BoxLayout(geneManiaContainingPanel, BoxLayout.Y_AXIS)); final SwingWorker geneManiaWorker = new SwingWorker() { private List<Object[]> results; @Override public void done() { Object[][] newdata = new Object[results.size()][4]; results.toArray(newdata); geneManiaResultsPanel.updateData(newdata); geneManiaResultsPanel.updateView(); geneManiaContainingPanel.removeAll(); geneManiaContainingPanel.add(geneManiaResultsPanel); geneManiaContainingPanel.revalidate(); geneManiaContainingPanel.repaint(); closeGeneManiaButton.setEnabled(true); } @Override public Object doInBackground() { try { GenemaniaInfoRetriever genemania = new GenemaniaInfoRetriever(); genemania.setGenes(selectedGenes); List<String> geneNameList = genemania.getRelatedGeneNamesByScore(); geneManiaGeneNames = new HashSet<String>(); geneManiaGeneNames.addAll(geneNameList); LOG.debug("Found " + geneNameList.size() + " related genes"); results = new ArrayList<Object[]>(geneNameList.size()); int i = 0; for (String gene : geneNameList) { if (isCancelled()) { return null; } Gene g = GeneSetFetcher.getInstance().getGeneDictionary().get(gene); if (g == null) { LOG.warn("No gene found for " + gene); } else if (!selectedGenesPanel.hasKey(g.getName())) { results.add(new Object[] { g.getName(), g.getChrom(), g.getStart(), g.getEnd() }); } } } catch (IOException e) { LOG.error(e); } catch (ApplicationException e) { LOG.error(e); } catch (DataStoreException e) { LOG.error(e); } catch (NoRelatedGenesInfoException e) { LOG.error(e); } return null; } }; leftSide.removeAll(); closeGeneManiaButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { try { geneManiaWorker.cancel(true); } catch (Exception e) { //genemania throws exceptions when cancelled } leftSide.removeAll(); leftSide.add(sourceGenesPanel); leftSide.validate(); leftSide.repaint(); geneManiaGeneNames = null; } }); JPanel closeButtonPanel = new JPanel(); closeButtonPanel.setLayout(new BoxLayout(closeButtonPanel, BoxLayout.X_AXIS)); closeButtonPanel.add(closeGeneManiaButton); closeButtonPanel.add(Box.createHorizontalGlue()); leftSide.add(closeButtonPanel); geneManiaContainingPanel.add(new WaitPanel("Querying GeneMANIA for related genes")); leftSide.add(geneManiaContainingPanel); leftSide.validate(); leftSide.repaint(); geneManiaWorker.execute(); } //end else }//end actionPerformed });//end ActionListener } @Override public void setupWizardButtons() { fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH); fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK); if (selectedGenesPanel.getNumSelected() > 0) { fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT); } else { fireButtonEvent(ButtonEvent.DISABLE_BUTTON, ButtonNames.NEXT); } } }; }