Example usage for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION

List of usage examples for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION

Introduction

In this page you can find the example usage for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION.

Prototype

int MULTIPLE_INTERVAL_SELECTION

To view the source code for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION.

Click Source Link

Document

A value for the selectionMode property: select one or more contiguous ranges of indices at a time.

Usage

From source file:com.sec.ose.osi.ui.frm.main.identification.IdentifyMediator.java

public void refreshIdentificationInfoForTreeListChildFrames(String selectedProjectName, String selectedPath,
        int selectedMatchType) {

    if (IdentifyMediator.getInstance().getSelectedProjectName().length() <= 0) {
        return;//from   ww  w  . ja  v  a2  s. co m
    }

    String projectNameFromUI = IdentifyMediator.getInstance().getSelectedProjectName();
    SelectedFilePathInfo selectedPaths = IdentifyMediator.getInstance().getSelectedFilePathInfo();
    String pathFromUI = selectedPaths.getSelectedPath();

    int matchTypeFromUI = IdentifyMediator.getInstance().getSelectedMatchType();
    if (selectedProjectName.equals(projectNameFromUI) == false)
        return;
    if (selectedMatchType != matchTypeFromUI)
        return;
    if ((selectedPath != null) && selectedPath.equals(pathFromUI) == false)
        return;

    MatchedInfoMgr.getInstance().loadIdentifiedFilesInfoToMemory(selectedProjectName);

    log.debug("projectName: " + selectedProjectName);
    log.debug("matchTypeFromUI: " + matchTypeFromUI);

    AbstractDiscoveryController controller = ProjectDiscoveryControllerMap
            .getDiscoveryController(selectedProjectName, matchTypeFromUI);
    ArrayList<String> pendingFileList = controller.getPendingFileList();

    log.debug("### Start Identify UI Update");

    updateJPanPendingTypeSelectionButtonCount(selectedProjectName);

    ArrayList<String> identifiedFileList = MatchedInfoMgr.getInstance()
            .getIdentifiedFilePathListByCurrentMatchType();

    // List Update
    JListMatchedFiles jListMatchedFile = IdentifyMediator.getInstance().getJListMatchedFile();
    if (jListMatchedFile == null) {
        return;
    }
    jListMatchedFile.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    refreshJListMatchedFiles(pendingFileList, identifiedFileList);

    jListMatchedFiles.setSelectPointer(getSelectedFilePathInfo().getSelectedPath());

    // update tree
    IdentifyMediator.getInstance().updateJTreeAllFiles(pendingFileList, identifiedFileList);

    // Identification info Update
    refreshChildFrames(selectedProjectName);

    log.debug("### End Identify UI Update");

}

From source file:edu.ku.brc.specify.tasks.subpane.wb.TemplateEditor.java

@Override
public void createUI() {
    super.createUI();

    databaseSchema = WorkbenchTask.getDatabaseSchema();

    int disciplineeId = AppContextMgr.getInstance().getClassObject(Discipline.class).getDisciplineId();
    SchemaI18NService.getInstance().loadWithLocale(SpLocaleContainer.WORKBENCH_SCHEMA, disciplineeId,
            databaseSchema, SchemaI18NService.getCurrentLocale());

    // Create the Table List
    Vector<TableInfo> tableInfoList = new Vector<TableInfo>();
    for (DBTableInfo ti : databaseSchema.getTables()) {
        if (StringUtils.isNotEmpty(ti.toString())) {
            TableInfo tableInfo = new TableInfo(ti, IconManager.STD_ICON_SIZE);
            tableInfoList.add(tableInfo);

            Vector<FieldInfo> fldList = new Vector<FieldInfo>();
            for (DBFieldInfo fi : ti.getFields()) {
                String fldTitle = fi.getTitle().replace(" ", "");
                if (fldTitle.equalsIgnoreCase(fi.getName())) {
                    //get title from mapped field
                    UploadInfo upInfo = getUploadInfo(fi);
                    DBFieldInfo mInfo = getMappedFieldInfo(fi);
                    if (mInfo != null) {
                        String title = mInfo.getTitle();
                        if (upInfo != null && upInfo.getSequence() != -1) {
                            title += " " + (upInfo.getSequence() + 1);
                        }/*w  w  w. j a v  a 2  s  . c  o m*/
                        //if mapped-to table is different than the container table used
                        // in the wb, add the mapped-to table's title
                        if (mInfo.getTableInfo().getTableId() != ti.getTableId()) {
                            title = mInfo.getTableInfo().getTitle() + " " + title;
                        }
                        fi.setTitle(title);
                    }
                }
                fldList.add(new FieldInfo(ti, fi));
            }
            //Collections.sort(fldList);
            tableInfo.setFieldItems(fldList);
        }
    }
    Collections.sort(tableInfoList);

    fieldModel = new DefaultModifiableListModel<FieldInfo>();
    tableModel = new DefaultModifiableListModel<TableInfo>();
    for (TableInfo ti : tableInfoList) {
        tableModel.add(ti);

        // only added for layout
        for (FieldInfo fi : ti.getFieldItems()) {
            fieldModel.add(fi);
        }
    }

    tableList = new JList(tableModel);
    tableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    tableList.setCellRenderer(tableInfoListRenderer = new TableInfoListRenderer(IconManager.STD_ICON_SIZE));
    JScrollPane tableScrollPane = new JScrollPane(tableList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

    tableList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                Object selObj = tableList.getSelectedValue();
                if (selObj != null) {
                    fillFieldList((TableInfo) selObj);
                }
                updateEnabledState();
            }
        }
    });

    fieldList = new JList(fieldModel);
    fieldList.setCellRenderer(tableInfoListRenderer = new TableInfoListRenderer(IconManager.STD_ICON_SIZE));
    fieldList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    JScrollPane fieldScrollPane = new JScrollPane(fieldList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    fieldList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                updateEnabledState();
                updateFieldDescription();
            }
        }
    });

    mapModel = new DefaultModifiableListModel<FieldMappingPanel>();
    mapList = new JList(mapModel);
    mapList.setCellRenderer(new MapCellRenderer());
    mapList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    mapScrollPane = new JScrollPane(mapList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

    mapList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                FieldMappingPanel fmp = (FieldMappingPanel) mapList.getSelectedValue();
                if (fmp != null) {
                    ignoreMapListUpdate = true;

                    FieldInfo fldInfo = fmp.getFieldInfo();
                    if (fldInfo != null) {
                        for (int i = 0; i < tableModel.size(); i++) {
                            TableInfo tblInfo = (TableInfo) tableModel.get(i);
                            if (fldInfo.getTableinfo() == tblInfo.getTableInfo()) {
                                tableList.setSelectedValue(tblInfo, true);
                                fillFieldList(tblInfo);
                                //System.out.println(fldInfo.hashCode()+" "+fldInfo.getFieldInfo().hashCode());
                                fieldList.setSelectedValue(fldInfo, true);
                                updateFieldDescription();
                                break;
                            }
                        }
                    }
                    ignoreMapListUpdate = false;
                    updateEnabledState();
                }
            }
        }
    });

    upBtn = createIconBtn("ReorderUp", "WB_MOVE_UP", new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int inx = mapList.getSelectedIndex();
            FieldMappingPanel fmp = mapModel.getElementAt(inx);

            mapModel.remove(fmp);
            mapModel.insertElementAt(fmp, inx - 1);
            mapList.setSelectedIndex(inx - 1);
            updateEnabledState();
            setChanged(true);
        }
    });
    downBtn = createIconBtn("ReorderDown", "WB_MOVE_DOWN", new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int inx = mapList.getSelectedIndex();
            FieldMappingPanel fmp = mapModel.getElementAt(inx);

            mapModel.remove(fmp);
            mapModel.insertElementAt(fmp, inx + 1);
            mapList.setSelectedIndex(inx + 1);
            updateEnabledState();
            setChanged(true);
        }
    });

    JButton dumpMappingBtn = createIconBtn("BlankIcon", IconManager.IconSize.Std16, "WB_MAPPING_DUMP",
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    dumpMapping();
                }
            });
    dumpMappingBtn.setEnabled(true);
    dumpMappingBtn.setFocusable(false);
    dumpMappingBtn.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            ((JButton) e.getSource()).setIcon(IconManager.getIcon("Save", IconManager.IconSize.Std16));
            super.mouseEntered(e);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            ((JButton) e.getSource()).setIcon(IconManager.getIcon("BlankIcon", IconManager.IconSize.Std16));
            super.mouseExited(e);
        }

    });

    mapToBtn = createIconBtn("Map", "WB_ADD_MAPPING_ITEM", new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            map();
        }
    });
    unmapBtn = createIconBtn("Unmap", "WB_REMOVE_MAPPING_ITEM", new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            unmap();
        }
    });

    // Adjust all Labels depending on whether we are creating a new template or not
    // and whether it is from a file or not
    String mapListLeftLabel;
    String mapListRightLabel;

    // Note: if workbenchTemplate is null then it is 
    String dataTypeLabel = getResourceString("WB_DATA_TYPE");
    String fieldsLabel = getResourceString("WB_FIELDS");

    mapListLeftLabel = fieldsLabel;
    mapListRightLabel = getResourceString("WB_COLUMNS");

    CellConstraints cc = new CellConstraints();

    JPanel mainLayoutPanel = new JPanel();

    PanelBuilder labelsBldr = new PanelBuilder(new FormLayout("p, f:p:g, p", "p"));
    labelsBldr.add(createLabel(mapListLeftLabel, SwingConstants.LEFT), cc.xy(1, 1));
    labelsBldr.add(createLabel(mapListRightLabel, SwingConstants.RIGHT), cc.xy(3, 1));

    PanelBuilder upDownPanel = new PanelBuilder(new FormLayout("p", "p,f:p:g, p, 2px, p, f:p:g"));
    upDownPanel.add(dumpMappingBtn, cc.xy(1, 1));
    upDownPanel.add(upBtn, cc.xy(1, 3));
    upDownPanel.add(downBtn, cc.xy(1, 5));

    PanelBuilder middlePanel = new PanelBuilder(new FormLayout("c:p:g", "p, 2px, p"));
    middlePanel.add(mapToBtn, cc.xy(1, 1));
    middlePanel.add(unmapBtn, cc.xy(1, 3));

    btnPanel = middlePanel.getPanel();
    btnPanel.setOpaque(false);

    PanelBuilder outerMiddlePanel = new PanelBuilder(new FormLayout("c:p:g", "f:p:g, p, f:p:g"));
    outerMiddlePanel.add(btnPanel, cc.xy(1, 2));
    outerMiddlePanel.getPanel().setOpaque(false);

    // Main Pane Layout
    PanelBuilder builder = new PanelBuilder(
            new FormLayout("f:max(200px;p):g, 5px, max(200px;p), 5px, p:g, 5px, f:max(250px;p):g, 2px, p",
                    "p, 2px, f:max(350px;p):g"),
            mainLayoutPanel);

    builder.add(createLabel(dataTypeLabel, SwingConstants.CENTER), cc.xy(1, 1));
    builder.add(createLabel(fieldsLabel, SwingConstants.CENTER), cc.xy(3, 1));
    builder.add(labelsBldr.getPanel(), cc.xy(7, 1));

    builder.add(tableScrollPane, cc.xy(1, 3));
    builder.add(fieldScrollPane, cc.xy(3, 3));

    builder.add(outerMiddlePanel.getPanel(), cc.xy(5, 3));

    builder.add(mapScrollPane, cc.xy(7, 3));
    builder.add(upDownPanel.getPanel(), cc.xy(9, 3));

    mainLayoutPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    JPanel megaPanel = new JPanel(new BorderLayout());
    megaPanel.add(mainLayoutPanel, BorderLayout.CENTER);
    descriptionLbl = createLabel("  ", SwingConstants.LEFT);
    //PanelBuilder descBuilder = new PanelBuilder(new FormLayout("f:p:g, 3dlu","p"));
    //descBuilder.add(descriptionLbl, cc.xy(1, 1));
    //megaPanel.add(descBuilder.getPanel(), BorderLayout.SOUTH);
    megaPanel.add(descriptionLbl, BorderLayout.SOUTH);
    //contentPanel = mainLayoutPanel;
    contentPanel = megaPanel;

    Color bgColor = btnPanel.getBackground();
    int inc = 16;
    btnPanelColor = new Color(Math.min(255, bgColor.getRed() + inc), Math.min(255, bgColor.getGreen() + inc),
            Math.min(255, bgColor.getBlue() + inc));
    btnPanel.setBackground(btnPanelColor);
    btnPanel.setBorder(BorderFactory.createEmptyBorder(4, 6, 4, 6));

    okBtn.setEnabled(false);

    HelpMgr.registerComponent(helpBtn, helpContext);

    if (dataFileInfo != null) {
        autoMapFromDataFile(dataFileInfo.getColInfo());
    }
    if (workbenchTemplate != null) {
        fillFromTemplate();
        setChanged(false);
    }

    mainPanel.add(contentPanel, BorderLayout.CENTER);

    if (dataFileInfo == null) //can't add new mappings when importing.
    {
        FieldMappingPanel fmp = addMappingItem(null,
                IconManager.getIcon("BlankIcon", IconManager.STD_ICON_SIZE), null);
        fmp.setAdded(true);
        fmp.setNew(true);
    }

    pack();

    SwingUtilities.invokeLater(new Runnable() {
        @SuppressWarnings("synthetic-access")
        public void run() {
            cancelBtn.requestFocus();
            fieldModel.clear();
            fieldList.clearSelection();
            updateFieldDescription();
            updateEnabledState();

            if (mapModel.size() > 1) {
                mapList.clearSelection();
            }
        }
    });
}

From source file:org.fhcrc.cpl.viewer.quant.gui.ProteinQuantSummaryFrame.java

License:asdf

/**
 * Initialize the GUI components/*  w w  w.j av  a2s  . c  om*/
 */
protected void initGUI() {
    //Global stuff
    setSize(fullWidth, fullHeight);

    eventPropertiesTable = new QuantEvent.QuantEventPropertiesTable();
    eventPropertiesTable.setVisible(true);
    JScrollPane eventPropsScrollPane = new JScrollPane();
    eventPropsScrollPane.setViewportView(eventPropertiesTable);
    eventPropsScrollPane.setSize(propertiesWidth, propertiesHeight);
    eventPropertiesDialog = new JDialog(this, "Event Properties");
    eventPropertiesDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    eventPropertiesDialog.setSize(propertiesWidth, propertiesHeight);
    eventPropertiesDialog.setContentPane(eventPropsScrollPane);

    ListenerHelper helper = new ListenerHelper(this);
    setTitle("Protein Summary");
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets = new Insets(5, 5, 5, 5);
    gbc.weighty = 1;
    gbc.weightx = 1;

    try {
        (getOwner()).setIconImage(ImageIO.read(WorkbenchFrame.class.getResourceAsStream("icon.gif")));
    } catch (Exception e) {
    }

    try {
        Localizer.renderSwixml("org/fhcrc/cpl/viewer/quant/gui/ProteinQuantSummaryFrame.xml", this);
        assert null != contentPanel;
        setContentPane(contentPanel);
    } catch (Exception x) {
        ApplicationContext.errorMessage("error creating dialog", x);
        throw new RuntimeException(x);
    }

    buttonSelectAllVisible.setEnabled(false);
    helper.addListener(buttonSelectAllVisible, "buttonSelectAllVisible_actionPerformed");
    buttonDeselectAll.setEnabled(false);
    helper.addListener(buttonDeselectAll, "buttonDeselectAll_actionPerformed");

    buildTurkHITsButton.setEnabled(false);
    helper.addListener(buildTurkHITsButton, "buttonBuildTurkHITs_actionPerformed");
    loadSelectedEventsButton.setEnabled(false);
    helper.addListener(loadSelectedEventsButton, "buttonLoadSelected_actionPerformed");
    autoAssessSelectedEventsButton.setEnabled(false);
    helper.addListener(autoAssessSelectedEventsButton, "buttonAutoAssess_actionPerformed");

    showPropertiesButton.setEnabled(false);
    helper.addListener(showPropertiesButton, "buttonShowProperties_actionPerformed");
    showProteinRatiosButton.setEnabled(false);
    helper.addListener(showProteinRatiosButton, "buttonShowProteinRatios_actionPerformed");

    //summary panel
    summaryPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
    summaryPanel.setPreferredSize(new Dimension(fullWidth, summaryPanelHeight));
    summaryPanel.setMinimumSize(new Dimension(200, summaryPanelHeight));
    gbc.fill = GridBagConstraints.NONE;

    gbc.gridwidth = 1;
    summaryPanel.add(buttonSelectAllVisible, gbc);
    summaryPanel.add(buttonDeselectAll, gbc);
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    summaryPanel.add(showPropertiesButton, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    summaryPanel.add(showProteinRatiosButton, gbc);

    gbc.gridwidth = 1;

    summaryPanel.add(loadSelectedEventsButton, gbc);
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    summaryPanel.add(autoAssessSelectedEventsButton, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    summaryPanel.add(buildTurkHITsButton, gbc);

    gbc.fill = GridBagConstraints.BOTH;

    eventsScrollPane = new JScrollPane();
    eventsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    eventsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    eventsPanel = new JPanel();
    eventsPanel.setLayout(new GridBagLayout());

    eventsTable = new QuantEventsSummaryTable();
    eventsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    eventsTable.getSelectionModel().addListSelectionListener(new EventsTableListSelectionHandler());
    eventsScrollPane.setViewportView(eventsTable);
    eventsScrollPane.setMinimumSize(new Dimension(400, 400));

    gbc.insets = new Insets(0, 0, 0, 0);
    mainPanel.add(eventsScrollPane, gbc);

    logRatioHistogramPanel = new PanelWithLogRatioHistAndFields();
    logRatioHistogramPanel.setBorder(BorderFactory.createTitledBorder("Log Ratios"));
    logRatioHistogramPanel.setPreferredSize(new Dimension(width - 10, 300));
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 100;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    add(logRatioHistogramPanel, gbc);

    //status message
    messageLabel = new JLabel();
    messageLabel.setBackground(Color.WHITE);
    messageLabel.setFont(Font.decode("verdana plain 12"));
    messageLabel.setText(" ");
    statusPanel = new JPanel();
    gbc.weighty = 1;
    statusPanel.setPreferredSize(new Dimension(width - 10, 50));
    statusPanel.add(messageLabel, gbc);
    add(statusPanel, gbc);

    //per-protein event summary table; disembodied
    //todo: move this into its own class? it's getting kind of complicated
    proteinRatiosTable = new JTable();
    proteinRatiosTable.setVisible(true);
    ListSelectionModel proteinTableSelectionModel = proteinRatiosTable.getSelectionModel();
    proteinTableSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    proteinTableSelectionModel.addListSelectionListener(new ProteinTableListSelectionHandler());
    JScrollPane proteinRatiosScrollPane = new JScrollPane();
    proteinRatiosScrollPane.setViewportView(proteinRatiosTable);
    proteinRatiosScrollPane.setPreferredSize(new Dimension(proteinDialogWidth,
            proteinDialogHeight - PROTEINTABLE_HISTPANEL_HEIGHT - PROTEINTABLE_SCATTERPLOTPANEL_HEIGHT - 70));
    proteinRatiosDialog = new JDialog(this, "Protein Ratios");
    proteinRatiosDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    proteinRatiosDialog.setSize(proteinDialogWidth, proteinDialogHeight);
    JPanel proteinRatiosContentPanel = new JPanel();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.BOTH;
    proteinRatiosContentPanel.add(proteinRatiosScrollPane, gbc);
    proteinRatiosDialog.setContentPane(proteinRatiosContentPanel);
    perProteinLogRatioHistogramPanel = new PanelWithLogRatioHistAndFields();
    perProteinLogRatioHistogramPanel.addRangeUpdateListener(new ProteinTableLogRatioHistogramListener());

    perProteinLogRatioHistogramPanel.setBorder(BorderFactory.createTitledBorder("Log Ratios"));
    perProteinLogRatioHistogramPanel
            .setPreferredSize(new Dimension(proteinDialogWidth - 10, PROTEINTABLE_HISTPANEL_HEIGHT));
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    proteinRatiosDialog.add(perProteinLogRatioHistogramPanel, gbc);

    perProteinPeptideLogRatioPanel = new JPanel();
    perProteinPeptideLogRatioPanel.setBorder(BorderFactory.createTitledBorder("By Peptide"));
    perProteinPeptideLogRatioPanel
            .setPreferredSize(new Dimension(proteinDialogWidth - 10, PROTEINTABLE_SCATTERPLOTPANEL_HEIGHT));
    proteinRatiosDialog.add(perProteinPeptideLogRatioPanel, gbc);
}

From source file:net.sf.jhylafax.addressbook.AddressBook.java

private void initializeContent() {
    horizontalSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    horizontalSplitPane.setBorder(GUIHelper.createEmptyBorder(5));

    rootNode = new DefaultMutableTreeNode();
    addressBookTreeModel = new DefaultTreeModel(rootNode);
    addressBookTree = new JTree(addressBookTreeModel);
    addressBookTree.setRootVisible(false);
    addressBookTree.setCellRenderer(new ContactCollectionCellRenderer());
    horizontalSplitPane.add(new JScrollPane(addressBookTree));

    JPanel contactPanel = new JPanel();
    contactPanel.setLayout(new BorderLayout(0, 10));
    horizontalSplitPane.add(contactPanel);

    DefaultFormBuilder builder = new DefaultFormBuilder(
            new FormLayout("min, 3dlu, min, 3dlu, pref:grow, 3dlu, min", ""));
    contactPanel.add(builder.getPanel(), BorderLayout.NORTH);

    searchTextField = new JTextField(10);
    EraseTextFieldAction eraseAction = new EraseTextFieldAction(searchTextField) {
        public void actionPerformed(ActionEvent event) {
            super.actionPerformed(event);
            filterAction.actionPerformed(event);
        };/*from   w  w w . j  av a2 s . co m*/
    };
    builder.append(new TabTitleButton(eraseAction));
    filterLabel = new JLabel();
    builder.append(filterLabel);
    builder.append(searchTextField);
    GUIHelper.bindEnterKey(searchTextField, filterAction);

    builder.append(Builder.createButton(filterAction));

    JPopupMenu tablePopupMenu = new JPopupMenu();
    tablePopupMenu.add(Builder.createMenuItem(newAction));
    tablePopupMenu.addSeparator();
    tablePopupMenu.add(Builder.createMenuItem(editAction));
    tablePopupMenu.addSeparator();
    tablePopupMenu.add(Builder.createMenuItem(deleteAction));

    contactTableModel = new AddressTableModel();
    TableSorter sorter = new TableSorter(contactTableModel);
    contactTable = new ColoredTable(sorter);
    contactTableLayoutManager = new TableLayoutManager(contactTable);
    contactTableLayoutManager.addColumnProperties("displayName", "", 180, true);
    contactTableLayoutManager.addColumnProperties("company", "", 80, true);
    contactTableLayoutManager.addColumnProperties("faxNumber", "", 60, true);
    contactTableLayoutManager.initializeTableLayout();
    contactPanel.add(new JScrollPane(contactTable), BorderLayout.CENTER);

    contactTable.setShowVerticalLines(true);
    contactTable.setShowHorizontalLines(false);
    contactTable.setAutoCreateColumnsFromModel(true);
    contactTable.setIntercellSpacing(new java.awt.Dimension(2, 1));
    contactTable.setBounds(0, 0, 50, 50);
    contactTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    contactTable.getSelectionModel().addListSelectionListener(this);
    contactTable.addMouseListener(new PopupListener(tablePopupMenu));
    contactTable.addMouseListener(new DoubleClickListener(new TableDoubleClickAction()));
    contactTable.setTransferHandler(new ContactTransferHandler());
    contactTable.setDragEnabled(true);

    contactTable.setDefaultRenderer(String.class, new StringCellRenderer());

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(horizontalSplitPane, BorderLayout.CENTER);
}

From source file:com.sec.ose.osi.ui.frm.main.identification.IdentifyMediator.java

public void refreshIdentificationInfoForSnippetRefresh(String selectedProjectName, String selectedPath,
        int selectedMatchType) {

    if (IdentifyMediator.getInstance().getSelectedProjectName().length() <= 0) {
        return;//from   w  w w  .j a v a 2 s.  c om
    }

    String projectNameFromUI = IdentifyMediator.getInstance().getSelectedProjectName();
    int matchTypeFromUI = IdentifyMediator.getInstance().getSelectedMatchType();
    if (selectedProjectName.equals(projectNameFromUI) == false)
        return;
    if (selectedMatchType != matchTypeFromUI)
        return;

    MatchedInfoMgr.getInstance().loadIdentifiedFilesInfoToMemory(selectedProjectName);

    log.debug("projectName: " + selectedProjectName);
    log.debug("matchTypeFromUI: " + matchTypeFromUI);

    AbstractDiscoveryController controller = ProjectDiscoveryControllerMap
            .getDiscoveryController(selectedProjectName, matchTypeFromUI);
    ArrayList<String> pendingFileList = controller.getPendingFileList();

    log.debug("### Start Identify UI Update");

    updateJPanPendingTypeSelectionButtonCount(selectedProjectName);

    ArrayList<String> identifiedFileList = MatchedInfoMgr.getInstance()
            .getIdentifiedFilePathListByCurrentMatchType();

    // List Update
    JListMatchedFiles jListMatchedFile = IdentifyMediator.getInstance().getJListMatchedFile();
    jListMatchedFile.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    refreshJListMatchedFiles(pendingFileList, identifiedFileList);

    jListMatchedFiles.setSelectPointer(getSelectedFilePathInfo().getSelectedPath());

    // update tree
    IdentifyMediator.getInstance().updateJTreeAllFiles(pendingFileList, identifiedFileList);

    // Identification info Update
    refreshChildFrames(selectedProjectName);

    log.debug("### End Identify UI Update");

}

From source file:uk.ac.ox.cbrg.cpfp.uploadapp.UploadApplet.java

/** This method is called from within the init() method to
 * initialize the form.//from   w w  w  .  jav a 2s  .  co  m
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    jPanel1 = new javax.swing.JPanel();
    jScrollPane1 = new javax.swing.JScrollPane();
    fileTable = new javax.swing.JTable();
    btnAdd = new javax.swing.JButton();
    btnDel = new javax.swing.JButton();
    btnUpload = new javax.swing.JButton();
    prgUploadProgress = new javax.swing.JProgressBar();
    lblProgress = new javax.swing.JLabel();
    lblMessages = new javax.swing.JLabel();
    jScrollPane2 = new javax.swing.JScrollPane();
    txtMessages = new javax.swing.JTextArea();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();

    fileTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

    }, new String[] { "Filename", "Size" }) {
        Class[] types = new Class[] { java.lang.String.class, java.lang.String.class };
        boolean[] canEdit = new boolean[] { false, false };

        public Class getColumnClass(int columnIndex) {
            return types[columnIndex];
        }

        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
        }
    });
    fileTable.setColumnSelectionAllowed(true);
    fileTable.getTableHeader().setReorderingAllowed(false);
    jScrollPane1.setViewportView(fileTable);
    fileTable.getColumnModel().getSelectionModel()
            .setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    btnAdd.setIcon(
            new javax.swing.ImageIcon(getClass().getResource("/uk/ac/ox/cbrg/cpfp/uploadapp/12-em-plus.png"))); // NOI18N
    btnAdd.setText("Add File(s)");
    btnAdd.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnAddActionPerformed(evt);
        }
    });

    btnDel.setIcon(
            new javax.swing.ImageIcon(getClass().getResource("/uk/ac/ox/cbrg/cpfp/uploadapp/12-em-cross.png"))); // NOI18N
    btnDel.setText("Remove File(s)");
    btnDel.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnDelActionPerformed(evt);
        }
    });

    btnUpload.setIcon(
            new javax.swing.ImageIcon(getClass().getResource("/uk/ac/ox/cbrg/cpfp/uploadapp/12-em-up.png"))); // NOI18N
    btnUpload.setText("Upload Files");
    btnUpload.setEnabled(false);
    btnUpload.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnUploadActionPerformed(evt);
        }
    });

    prgUploadProgress.setStringPainted(true);

    lblProgress.setText("Progress:");

    lblMessages.setText("Messages:");

    txtMessages.setColumns(20);
    txtMessages.setRows(5);
    jScrollPane2.setViewportView(txtMessages);

    jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() | java.awt.Font.BOLD,
            jLabel1.getFont().getSize() + 3));
    jLabel1.setForeground(javax.swing.UIManager.getDefaults().getColor("textText"));
    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel1.setText("CPFP File Uploader");

    jLabel2.setText("2011.10.04");

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING,
                            javax.swing.GroupLayout.DEFAULT_SIZE, 609, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 609, Short.MAX_VALUE)
                    .addComponent(prgUploadProgress, javax.swing.GroupLayout.DEFAULT_SIZE, 609, Short.MAX_VALUE)
                    .addComponent(lblProgress)
                    .addGroup(jPanel1Layout.createSequentialGroup().addGroup(
                            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup().addComponent(btnAdd)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(btnDel))
                                    .addComponent(lblMessages))
                            .addGroup(jPanel1Layout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 257,
                                                    Short.MAX_VALUE))
                                    .addGroup(jPanel1Layout.createSequentialGroup().addGap(103, 103, 103)
                                            .addComponent(jLabel2)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btnUpload)))
                    .addContainerGap()));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 244,
                                            javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout
                                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(btnAdd).addComponent(btnDel).addComponent(btnUpload)
                                            .addComponent(jLabel1))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(lblMessages)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 87,
                                            Short.MAX_VALUE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(lblProgress)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(prgUploadProgress, javax.swing.GroupLayout.PREFERRED_SIZE, 26,
                                            javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(35, 35, 35))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout
                                    .createSequentialGroup().addComponent(jLabel2).addGap(195, 195, 195)))));

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jPanel1,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
            javax.swing.GroupLayout.Alignment.TRAILING,
            layout.createSequentialGroup().addContainerGap().addComponent(jPanel1,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap()));
}

From source file:com.ibm.issw.odc.gui.BPMArgumentsPanel.java

/**
 * Create the main GUI panel which contains the argument table.
 *
 * @return the main GUI panel/*w w  w  .j a va 2s  . c  o m*/
 */
private Component makeMainPanel() {
    initializeTableModel();
    table = new JTable(tableModel);
    table.getTableHeader().setDefaultRenderer(new HeaderAsPropertyRenderer());
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    if (this.background != null) {
        table.setBackground(this.background);
    }
    return makeScrollPane(table);
}

From source file:de.codesourcery.eve.skills.ui.components.impl.AssetListComponent.java

@Override
protected JPanel createPanel() {

    // Merge controls.
    final JPanel mergeControlsPanel = new JPanel();
    mergeControlsPanel.setLayout(new GridBagLayout());
    mergeControlsPanel.setBorder(BorderFactory.createTitledBorder("Merging"));

    int y = 0;/*w w  w.  j a  v a2s . c o  m*/

    // merge by type
    mergeAssetsByType.setSelected(true);
    mergeAssetsByType.addActionListener(actionListener);

    mergeControlsPanel.add(mergeAssetsByType, constraints(0, y).anchorWest().end());
    mergeControlsPanel.add(new JLabel("Merge assets by type", SwingConstants.LEFT),
            constraints(1, y++).width(2).end());

    // "ignore different packaging"
    ignorePackaging.setSelected(true);
    ignorePackaging.addActionListener(actionListener);

    mergeControlsPanel.add(new JLabel(""), constraints(0, y).anchorWest().end());
    mergeControlsPanel.add(ignorePackaging, constraints(1, y).anchorWest().end());
    final JLabel label1 = new JLabel("Merge different packaging", SwingConstants.RIGHT);
    mergeControlsPanel.add(label1, constraints(2, y++).end());

    // "ignore different locations"
    ignoreLocations.setSelected(true);
    ignoreLocations.addActionListener(actionListener);

    mergeControlsPanel.add(new JLabel(""), constraints(0, y).anchorWest().end());
    mergeControlsPanel.add(ignoreLocations, constraints(1, y).anchorWest().end());
    final JLabel label2 = new JLabel("Merge different locations", SwingConstants.RIGHT);
    mergeControlsPanel.add(label2, constraints(2, y++).end());

    linkComponentEnabledStates(mergeAssetsByType, ignoreLocations, ignorePackaging, label1, label2);

    /*
     * Filter controls.
     */

    final JPanel filterControlsPanel = new JPanel();
    filterControlsPanel.setLayout(new GridBagLayout());
    filterControlsPanel.setBorder(BorderFactory.createTitledBorder("Filters"));

    y = 0;
    // filter by location combo box
    filterByLocation.addActionListener(actionListener);
    locationComboBox.addActionListener(actionListener);

    filterByLocation.setSelected(false);
    linkComponentEnabledStates(filterByLocation, locationComboBox);

    locationComboBox.setRenderer(new LocationRenderer());
    locationComboBox.setPreferredSize(new Dimension(150, 20));
    locationComboBox.setModel(locationModel);

    filterControlsPanel.add(filterByLocation, constraints(0, y).end());
    filterControlsPanel.add(locationComboBox, constraints(1, y++).end());

    // filter by type combo box
    filterByType.addActionListener(actionListener);
    typeComboBox.addActionListener(actionListener);

    filterByType.setSelected(false);

    linkComponentEnabledStates(filterByType, typeComboBox);

    typeComboBox.setPreferredSize(new Dimension(150, 20));
    typeComboBox.setModel(typeModel);

    filterControlsPanel.add(filterByType, constraints(0, y).end());
    filterControlsPanel.add(typeComboBox, constraints(1, y++).end());

    // filter by item category combobox
    filterByCategory.addActionListener(actionListener);
    categoryComboBox.addActionListener(actionListener);
    categoryComboBox.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {

            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

            setText(getDisplayName((InventoryCategory) value));
            setEnabled(categoryComboBox.isEnabled());
            return this;
        }
    });

    filterByCategory.setSelected(false);
    linkComponentEnabledStates(filterByCategory, categoryComboBox);

    categoryComboBox.setPreferredSize(new Dimension(150, 20));
    categoryComboBox.setModel(categoryModel);

    filterControlsPanel.add(filterByCategory, constraints(0, y).end());
    filterControlsPanel.add(categoryComboBox, constraints(1, y++).end());

    // filter by item group combobox
    filterByGroup.addActionListener(actionListener);
    groupComboBox.addActionListener(actionListener);

    filterByGroup.setSelected(false);

    linkComponentEnabledStates(filterByGroup, groupComboBox);

    groupComboBox.setPreferredSize(new Dimension(150, 20));
    groupComboBox.setModel(groupModel);

    filterControlsPanel.add(filterByGroup, constraints(0, y).end());
    filterControlsPanel.add(groupComboBox, constraints(1, y++).end());

    /*
     * Table panel.
     */

    table = new JTable() {

        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {

            // subclassing hack is needed because table
            // returns different renderes depending on column type
            final TableCellRenderer result = super.getCellRenderer(row, column);

            return new TableCellRenderer() {

                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                        boolean hasFocus, int row, int column) {

                    final Component comp = result.getTableCellRendererComponent(table, value, isSelected,
                            hasFocus, row, column);

                    final int modelRow = table.convertRowIndexToModel(row);
                    final Asset asset = model.getRow(modelRow);

                    final StringBuilder label = new StringBuilder("<HTML><BODY>");
                    label.append(asset.getItemId() + " - flags: " + asset.getFlags() + "<BR>");
                    if (asset.hasMultipleLocations()) {
                        label.append("<BR>");
                        for (ILocation loc : asset.getLocations()) {
                            label.append(loc.getDisplayName()).append("<BR>");
                        }
                    }

                    label.append("</BODY></HTML>");
                    ((JComponent) comp).setToolTipText(label.toString());

                    return comp;
                }
            };
        }
    };

    model.setViewFilter(this.viewFilter);

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            updateSelectedVolume();
        }
    });

    FixedBooleanTableCellRenderer.attach(table);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setModel(model);
    table.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    table.setRowSorter(model.getRowSorter());

    popupMenuBuilder.addItem("Refine...", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final List<Asset> assets = getSelectedAssets();
            if (assets == null || assets.isEmpty()) {
                return;
            }

            final ICharacter c = selectionProvider.getSelectedItem();
            final RefiningComponent comp = new RefiningComponent(c);
            comp.setItemsToRefine(assets);
            ComponentWrapper.wrapComponent("Refining", comp).setVisible(true);
        }

        @Override
        public boolean isEnabled() {
            return table.getSelectedRow() != -1;
        }
    });

    popupMenuBuilder.addItem("Copy selection to clipboard (text)", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final List<Asset> assets = getSelectedAssets();
            if (assets == null || assets.isEmpty()) {
                return;
            }

            new PlainTextTransferable(toPlainText(assets)).putOnClipboard();
        }

        @Override
        public boolean isEnabled() {
            return table.getSelectedRow() != -1;
        }
    });

    popupMenuBuilder.addItem("Copy selection to clipboard (CSV)", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final List<Asset> assets = getSelectedAssets();
            if (assets == null || assets.isEmpty()) {
                return;
            }

            final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

            clipboard.setContents(new PlainTextTransferable(toCsv(assets)), null);
        }

        @Override
        public boolean isEnabled() {
            return table.getSelectedRow() != -1;
        }
    });

    table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    this.popupMenuBuilder.attach(table);

    final JScrollPane scrollPane = new JScrollPane(table);

    /*
     * Name filter
     */

    final JPanel nameFilterPanel = new JPanel();
    nameFilterPanel.setLayout(new GridBagLayout());
    nameFilterPanel.setBorder(BorderFactory.createTitledBorder("Filter by name"));
    nameFilterPanel.setPreferredSize(new Dimension(150, 70));
    nameFilter.setColumns(10);
    nameFilter.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void changedUpdate(DocumentEvent e) {
            model.viewFilterChanged();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            model.viewFilterChanged();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            model.viewFilterChanged();
        }
    });

    nameFilterPanel.add(nameFilter, constraints(0, 0).resizeHorizontally().end());
    final JButton clearButton = new JButton("Clear");
    clearButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            nameFilter.setText(null);
        }
    });
    nameFilterPanel.add(clearButton, constraints(1, 0).noResizing().end());

    // Selected volume
    final JPanel selectedVolumePanel = this.selectedVolume.getPanel();

    // add control panels to result panel
    final JPanel topPanel = new JPanel();
    topPanel.setLayout(new GridBagLayout());

    topPanel.add(mergeControlsPanel, constraints(0, 0).height(2).weightX(0).anchorWest().end());
    topPanel.add(filterControlsPanel, constraints(1, 0).height(2).anchorWest().weightX(0).end());
    topPanel.add(nameFilterPanel, constraints(2, 0).height(1).anchorWest().useRemainingWidth().end());
    topPanel.add(selectedVolumePanel, constraints(2, 1).height(1).anchorWest().useRemainingWidth().end());

    final JSplitPane splitPane = new ImprovedSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, scrollPane);

    splitPane.setDividerLocation(0.3d);

    final JPanel content = new JPanel();
    content.setLayout(new GridBagLayout());
    content.add(splitPane, constraints().resizeBoth().useRemainingSpace().end());

    return content;
}

From source file:modnlp.capte.AlignmentInterfaceWS.java

public void actionPerformed(ActionEvent e) {

    //Handle open button action.
    if (e.getSource() == openButton) {
        int returnVal = fc.showOpenDialog(AlignmentInterfaceWS.this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            //This is where a real application would open the file.
            sourceFile = file.getAbsolutePath();
            log.append("Source File: " + sourceFile + "." + newline);
        } else {//from   w  w  w.  jav a2 s.  co  m
            log.append("Open command cancelled by user." + newline);
        }
        log.setCaretPosition(log.getDocument().getLength());

    }
    //deleteSegment
    else if (e.getSource() == deleteSegment) {
        Object[] o;
        String ivalue;
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        if (selected.length < 1) {

            System.out.println("Please select at least one row");
            JOptionPane.showMessageDialog(edit, "Please select at least one row");
        } else {
            System.out.println("Deleting rows...");
            for (int i = selected.length - 1; i > -1; i--) {
                em.removeRow(selected[i]);
                //update numbers

                System.out.println("Removed row " + selected[i]);
            }
        }
        //Table should update itself automatically
    } else if (e.getSource() == moveUp) {
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();
        if (selected.length > 1) {
            System.out.println("You can only move one segment at a time!");
            JOptionPane.showMessageDialog(edit, "You can only move one segment at a time!");
        } else if (selected[0] == 0) {
            System.out.println("Can't move up anymore!");
            JOptionPane.showMessageDialog(edit, "Can't move up anymore!");
        } else {
            System.out.println("Moving " + selected[0]);
            em.moveSegmentUp(selected[0]);
            //Table should repaint
        }
    } else if (e.getSource() == moveDown) {

        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();
        if (selected.length > 1) {

            System.out.println("You can only move one segment at a time!");
            JOptionPane.showMessageDialog(edit, "You can only move one segment at a time!");
        } else if (selected[0] == em.getRowCount() - 1) {

            System.out.println("Can't move down anymore!");
            JOptionPane.showMessageDialog(edit, "Can't move down anymore");
        } else {
            System.out.println("Moving " + selected[0]);
            em.moveSegmentDown(selected[0]);
            //Table should repaint
        }
    } else if (e.getSource() == mergeSource) {
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        if (selected.length < 2 || selected.length > 2) {

            System.out.println("Please select two rows to merge ");
            JOptionPane.showMessageDialog(edit, "Please select two rows to merge");
        } else if (selected[0] - selected[1] > 1 || selected[0] - selected[1] < -1) {

            System.out.println("Can only merge adjacent rows");
            JOptionPane.showMessageDialog(edit, "Can only merge adjacent rows");
        } else {
            System.out.println("Merging source in rows " + selected[0] + " " + selected[1]);
            em.mergeSource(selected[0], selected[1]);
        }
    } else if (e.getSource() == mergeTarget) {
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        if (selected.length < 2 || selected.length > 2) {

            System.out.println("Please select two rows to merge ");
            JOptionPane.showMessageDialog(edit, "Please select two rows to merge");
        } else if (selected[0] - selected[1] > 1 || selected[0] - selected[1] < -1) {

            System.out.println("Can only merge adjacent rows");
            JOptionPane.showMessageDialog(edit, "Can only merge adjacent rows");
        } else {
            System.out.println("Merging target in " + selected[0] + " " + selected[1]);
            em.mergeTarget(selected[0], selected[1]);
        }

    } else if (e.getSource() == newSegment) {
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        if (selected.length < 1) {

            System.out.println("Please select a position to insert at:");
            JOptionPane.showMessageDialog(edit, "Please select a position to insert at");
        } else {
            System.out.println("Inserting new segment at " + (selected[0] + 1));
            //insert empty string array
            Object[] sa = new Object[6];
            sa[0] = "";
            sa[1] = "";
            sa[2] = "0.0";
            sa[3] = new Boolean(false);
            sa[4] = "0";
            sa[5] = em.getValueAt((selected[0]), 5) + "(+)";

            em.insertRow(sa, (selected[0] + 1));

        }
    } else if (e.getSource() == lockSelected) {
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        if (selected.length < 1) {

            System.out.println("Please select some rows to lock:");
            JOptionPane.showMessageDialog(edit, "Please select some rows to lock:");
        } else {

            //lock selected rows

            for (int i = 0; i < selected.length; i++) {
                em.lockRow(selected[i]);
                System.out.println("Locking row " + selected[i]);

            }

        }
    } else if (e.getSource() == unlockSelected) {
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        if (selected.length < 1) {

            System.out.println("Please select some rows to unlock:");
            JOptionPane.showMessageDialog(edit, "Please select some rows to unlock:");
        } else {

            //lock selected rows
            for (int i = 0; i < selected.length; i++) {
                em.unlockRow(selected[i]);
                System.out.println("Unlocking row " + selected[i]);
            }

        }
    } else if (e.getSource() == reAlign) {
        //  if(true){
        // JOptionPane.showMessageDialog(edit,"This feature is currently disabled");
        // }else{
        reNumber++;
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        // Get list of locked segments
        // Find lowest locked segment
        // Realign from lowest locked segment
        // Join the realigned bit back up with the locked bit
        // refresh the table
        int lowestlock = 0;
        Vector<Object[]> slice = new Vector<Object[]>();
        Vector<Object[]> result = new Vector<Object[]>();
        Vector<Object[]> locked = new Vector<Object[]>();
        Boolean b = new Boolean(true);
        for (int i = 0; i < em.getRowCount(); i++) {
            b = (Boolean) em.getValueAt(i, 3);
            if (b.booleanValue() == true) {
                lowestlock = i;
            }
        }

        //get slice of table for realignment
        System.out.println("The lowest lock point is " + (lowestlock));
        System.out.println("Realigning from row:" + (lowestlock + 1) + " to : " + em.getRowCount());
        System.out.println("Total size of realign array =:" + (em.getRowCount() - (lowestlock)));
        //Get locked bits
        for (int h = 0; h < lowestlock + 1; h++) {

            locked.add(em.getRow(h));
        }
        //Get bits to realign
        for (int j = lowestlock + 1; j < em.getRowCount(); j++) {

            slice.add(em.getRow(j));

        }
        //flush 
        em.flush();
        for (int z = 0; z < locked.size(); z++) {
            em.insertRow(locked.get(z), z);
        }
        // System.out.println("Total size of array after bits removed  = " + (em.getRowCount()));
        //get the directory where the source files came from
        File parent = new File(sourceFile).getParentFile();
        String dir = parent.getAbsolutePath();
        //create files
        File sf = null;
        File tf = null;
        try {
            sf = File.createTempFile("source", "tmp");
            tf = File.createTempFile("target", "tmp");
        } catch (IOException ef) {
            ef.printStackTrace();
        }
        System.out.println("Writing temp file:" + sf.getName());
        System.out.println("Writing temp file:" + tf.getName());
        // File mf = new File("merged.tmp");
        //get absolute paths
        String sourceF = sf.getAbsolutePath();
        String targetF = tf.getAbsolutePath();
        //String alignF = mf.getAbsolutePath();
        //write out source and target to files
        //NEW write files to server and return string
        String alignment = "";
        AlignerUtils.reWriteAlignment(targetF, sourceF, slice);
        try {

            alignment = AlignerUtils.MultiPartFileUpload(targetF, sourceF);

        } catch (IOException es) {
            es.printStackTrace();
        }
        //convert the String to a Vector form
        result = AlignerUtils.StringToData(alignment, true, reNumber);
        // append the resultant file to the table
        //System.out.println("Total size of array before bits inserted  = " + (em.getRowCount()));
        for (int y = 0, z = em.getRowCount(); y < result.size(); y++, z++) {

            em.insertRow(result.get(y), z);
            System.out.println("Inserting at position: " + z);
            System.out.println("Inserting from position: " + y);

        }
        //  System.out.println("Total size of array after bits inserted  = " + (em.getRowCount()));
        // }
    } else if (e.getSource() == saveButton) {
        int returnVal = fc.showSaveDialog(AlignmentInterfaceWS.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            //This is where a real application would save the file.
            targetFile = file.getAbsolutePath();
            log.append("Target File " + targetFile + "." + newline);
        } else {
            log.append("Save command cancelled by user." + newline);
        }
        log.setCaretPosition(log.getDocument().getLength());
    } else if (e.getSource() == export) {
        int returnVal = fc.showSaveDialog(AlignmentInterfaceWS.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            outputFile = file.getAbsolutePath();
            //aserver.writeAlignment(targetFile,data);
            AlignerUtils.writeAlignment(outputFile, data);
            log.append(newline + "Saving " + outputFile + "." + newline);
        } else {
            log.append("Save command cancelled by user." + newline);
        }
        log.setCaretPosition(log.getDocument().getLength());
    } else if (e.getSource() == alignButton) {

        if (sl.getText().length() >= 2 && tl.getText().length() >= 2) {

            log.append("Attempting to align texts");
            sourcel = sl.getText();
            targetl = tl.getText();
            String aligned = "";
            try {
                aligned = AlignerUtils.MultiPartFileUpload(sourceFile, targetFile);
            } catch (IOException ed) {

                ed.printStackTrace();
            }
            //Convert string to alignment format
            data = AlignerUtils.StringToData(aligned, false, 0);

            int i = 0;

            //
            // AlreadyRun = true;
            if (i == 0) {
                //log.setCaretPosition(log.getDocument().getLength());
                log.append("\nAutomatic alignment successful!");
                log.append("\nOpening display window......");
                //Set up the editor window
                JFrame edit = new JFrame("Alignment Editor");
                cols = new Vector<String>();
                cols.add("Source");
                cols.add("Target");
                cols.add("Score");
                cols.add("Lock");
                cols.add("Index");
                cols.add("Orig");

                System.out.println("Size of data array " + data.size());
                System.out.println(data.get(0)[0]);
                ex = new ExampleTableModel(cols, data);
                //ex.addTableModelListener(this);
                table = new JTable(ex);
                table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

                TableColumnModel cmodel = table.getColumnModel();

                cmodel.getColumn(0).setCellRenderer(new TextAreaRenderer());
                cmodel.getColumn(1).setCellRenderer(new TextAreaRenderer());
                cmodel.getColumn(2).setCellRenderer(new TextAreaRenderer());
                cmodel.getColumn(4).setCellRenderer(new TextAreaRenderer());
                cmodel.getColumn(5).setCellRenderer(new TextAreaRenderer());
                TextAreaEditor textEditor = new TextAreaEditor();
                textEditor.addCellEditorListener(this);
                cmodel.getColumn(0).setCellEditor(textEditor);
                cmodel.getColumn(1).setCellEditor(textEditor);
                cmodel.getColumn(2).setCellEditor(textEditor);
                cmodel.getColumn(4).setCellEditor(textEditor);
                cmodel.getColumn(5).setCellEditor(textEditor);
                mergeTarget = new JButton("Merge target");
                mergeSource = new JButton("Merge source");
                export = new JButton("Export to File");
                newSegment = new JButton("Create New Segment");
                deleteSegment = new JButton("Delete Selected");
                moveUp = new JButton("Move Segment Up");
                moveDown = new JButton("Move Segment Down");
                lockSelected = new JButton("Lock Selected");
                unlockSelected = new JButton("Unlock Selected");
                reAlign = new JButton("Realign");
                reAlign.addActionListener(this);
                lockSelected.addActionListener(this);
                unlockSelected.addActionListener(this);
                mergeSource.addActionListener(this);
                mergeTarget.addActionListener(this);
                export.addActionListener(this);
                newSegment.addActionListener(this);
                deleteSegment.addActionListener(this);
                moveUp.addActionListener(this);
                moveDown.addActionListener(this);
                JPanel control = new JPanel();
                JPanel manipulate = new JPanel();
                control.add(moveUp);
                control.add(moveDown);
                control.add(mergeTarget);
                control.add(mergeSource);
                //control.add(export);
                control.add(newSegment);
                control.add(deleteSegment);
                manipulate.add(reAlign);
                manipulate.add(lockSelected);
                manipulate.add(unlockSelected);
                manipulate.add(export);
                edit.add(control, BorderLayout.PAGE_START);
                edit.add(manipulate, BorderLayout.PAGE_END);
                JScrollPane scr = new JScrollPane(table);
                //   JTable rowTable = new FirstRowNumberTable(table);

                //scr.add(table);
                //scr.setRowHeaderView(rowTable);
                //scr.setCorner(JScrollPane.UPPER_LEFT_CORNER, rowTable.getTableHeader()); 
                scr.repaint();
                edit.add(scr, BorderLayout.CENTER);
                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                edit.setSize(screenSize.width - 4, screenSize.height - 50);
                int totwidth = screenSize.width - 50;
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                cmodel.getColumn(0).setPreferredWidth((totwidth / 36) * 15);
                cmodel.getColumn(1).setPreferredWidth((totwidth / 36) * 15);
                cmodel.getColumn(2).setPreferredWidth(totwidth / 36 * 2);
                cmodel.getColumn(3).setPreferredWidth(totwidth / 36 * 2);
                cmodel.getColumn(4).setPreferredWidth(totwidth / 36 * 2);
                cmodel.getColumn(4).setPreferredWidth(totwidth / 36 * 2);
                edit.validate(); // Make sure layout is ok

                //edit.setSize(1024,700);
                edit.setVisible(true);

            } else {
                //log.setCaretPosition(log.getDocument().getLength());
                log.append("\nAutomatic alignment unsuccessful..check error logs");
            }
        } else {
            log.append("Please enter valid two letter language codes");
        }
        log.setCaretPosition(log.getDocument().getLength());

    }
}

From source file:org.jets3t.apps.cockpit.Cockpit.java

/**
 * Initialises the application's GUI elements.
 *///from w  w w .j ava2  s  .c om
private void initGui() {
    initMenus();

    JPanel appContent = new JPanel(new GridBagLayout());
    this.getContentPane().add(appContent);

    // Buckets panel.
    JPanel bucketsPanel = new JPanel(new GridBagLayout());

    JButton bucketActionButton = new JButton();
    bucketActionButton.setToolTipText("Bucket actions menu");
    guiUtils.applyIcon(bucketActionButton, "/images/nuvola/16x16/actions/misc.png");
    bucketActionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JButton sourceButton = (JButton) e.getSource();
            bucketActionMenu.show(sourceButton, 0, sourceButton.getHeight());
        }
    });
    bucketsPanel.add(new JHtmlLabel("<html><b>Buckets</b></html>", this), new GridBagConstraints(0, 0, 1, 1, 1,
            0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
    bucketsPanel.add(bucketActionButton, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    bucketTableModel = new BucketTableModel(false);
    bucketTableModelSorter = new TableSorter(bucketTableModel);
    bucketsTable = new JTable(bucketTableModelSorter);
    bucketTableModelSorter.setTableHeader(bucketsTable.getTableHeader());
    bucketsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    bucketsTable.getSelectionModel().addListSelectionListener(this);
    bucketsTable.setShowHorizontalLines(true);
    bucketsTable.setShowVerticalLines(false);
    bucketsTable.addMouseListener(new ContextMenuListener());
    bucketsPanel.add(new JScrollPane(bucketsTable), new GridBagConstraints(0, 1, 2, 1, 1, 1,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsZero, 0, 0));
    bucketsPanel.add(new JLabel(" "), new GridBagConstraints(0, 2, 2, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, insetsDefault, 0, 0));

    // Filter panel.
    filterObjectsPanel = new JPanel(new GridBagLayout());
    filterObjectsPrefix = new JTextField();
    filterObjectsPrefix.setToolTipText("Only show objects with this prefix");
    filterObjectsPrefix.addActionListener(this);
    filterObjectsPrefix.setActionCommand("RefreshObjects");
    filterObjectsDelimiter = new JComboBox(new String[] { "", "/", "?", "\\" });
    filterObjectsDelimiter.setEditable(true);
    filterObjectsDelimiter.setToolTipText("Object name delimiter");
    filterObjectsDelimiter.addActionListener(this);
    filterObjectsDelimiter.setActionCommand("RefreshObjects");
    filterObjectsPanel.add(new JHtmlLabel("Prefix:", this), new GridBagConstraints(0, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0));
    filterObjectsPanel.add(filterObjectsPrefix, new GridBagConstraints(1, 0, 1, 1, 1, 0,
            GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
    filterObjectsPanel.add(new JHtmlLabel("Delimiter:", this), new GridBagConstraints(2, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
    filterObjectsPanel.add(filterObjectsDelimiter, new GridBagConstraints(3, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0));
    filterObjectsPanel.setVisible(false);

    // Objects panel.
    JPanel objectsPanel = new JPanel(new GridBagLayout());
    int row = 0;
    filterObjectsCheckBox = new JCheckBox("Filter objects");
    filterObjectsCheckBox.addActionListener(this);
    filterObjectsCheckBox.setToolTipText("Check this option to filter the objects listed");
    objectsPanel.add(new JHtmlLabel("<html><b>Objects</b></html>", this), new GridBagConstraints(0, row, 1, 1,
            1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
    objectsPanel.add(filterObjectsCheckBox, new GridBagConstraints(1, row, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    JButton objectActionButton = new JButton();
    objectActionButton.setToolTipText("Object actions menu");
    guiUtils.applyIcon(objectActionButton, "/images/nuvola/16x16/actions/misc.png");
    objectActionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JButton sourceButton = (JButton) e.getSource();
            objectActionMenu.show(sourceButton, 0, sourceButton.getHeight());
        }
    });
    objectsPanel.add(objectActionButton, new GridBagConstraints(2, row, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    objectsPanel.add(filterObjectsPanel, new GridBagConstraints(0, ++row, 3, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    objectsTable = new JTable();
    objectTableModel = new ObjectTableModel();
    objectTableModelSorter = new TableSorter(objectTableModel);
    objectTableModelSorter.setTableHeader(objectsTable.getTableHeader());
    objectsTable.setModel(objectTableModelSorter);
    objectsTable.setDefaultRenderer(Long.class, new DefaultTableCellRenderer() {
        private static final long serialVersionUID = 301092191828910402L;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            String formattedSize = byteFormatter.formatByteSize(((Long) value).longValue());
            return super.getTableCellRendererComponent(table, formattedSize, isSelected, hasFocus, row, column);
        }
    });
    objectsTable.setDefaultRenderer(Date.class, new DefaultTableCellRenderer() {
        private static final long serialVersionUID = 7285511556343895652L;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            Date date = (Date) value;
            return super.getTableCellRendererComponent(table, yearAndTimeSDF.format(date), isSelected, hasFocus,
                    row, column);
        }
    });
    objectsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    objectsTable.getSelectionModel().addListSelectionListener(this);
    objectsTable.setShowHorizontalLines(true);
    objectsTable.setShowVerticalLines(true);
    objectsTable.addMouseListener(new ContextMenuListener());
    objectsTableSP = new JScrollPane(objectsTable);
    objectsPanel.add(objectsTableSP, new GridBagConstraints(0, ++row, 3, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsZero, 0, 0));
    objectsSummaryLabel = new JHtmlLabel("Please select a bucket", this);
    objectsSummaryLabel.setHorizontalAlignment(JLabel.CENTER);
    objectsSummaryLabel.setFocusable(false);
    objectsPanel.add(objectsSummaryLabel, new GridBagConstraints(0, ++row, 3, 1, 1, 0,
            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

    // Combine sections.
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, bucketsPanel, objectsPanel);
    splitPane.setOneTouchExpandable(true);
    splitPane.setContinuousLayout(true);

    appContent.add(splitPane, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsDefault, 0, 0));

    // Set preferred sizes
    int preferredWidth = 800;
    int preferredHeight = 600;
    this.setBounds(new Rectangle(new Dimension(preferredWidth, preferredHeight)));

    splitPane.setResizeWeight(0.30);

    // Initialize drop target.
    initDropTarget(new JComponent[] { objectsTableSP, objectsTable });
    objectsTable.getDropTarget().setActive(false);
    objectsTableSP.getDropTarget().setActive(false);
}