Example usage for com.jgoodies.forms.layout CellConstraints xy

List of usage examples for com.jgoodies.forms.layout CellConstraints xy

Introduction

In this page you can find the example usage for com.jgoodies.forms.layout CellConstraints xy.

Prototype

public CellConstraints xy(int col, int row) 

Source Link

Document

Sets column and row origins; sets width and height to 1; uses the default alignments.

Examples:

 cc.xy(1, 1); cc.xy(1, 3); 

Usage

From source file:ca.phon.app.project.NewSessionPanel.java

License:Open Source License

/**
 * Adds fill components to empty cells in the first row and first column
 * of the grid. This ensures that the grid spacing will be the same as
 * shown in the designer./* ww w .j  a v  a2 s . c  om*/
 * 
 * @param cols
 *            an array of column indices in the first row where fill
 *            components should be added.
 * @param rows
 *            an array of row indices in the first column where fill
 *            components should be added.
 */
void addFillComponents(Container panel, int[] cols, int[] rows) {
    Dimension filler = new Dimension(10, 10);

    boolean filled_cell_11 = false;
    CellConstraints cc = new CellConstraints();
    if (cols.length > 0 && rows.length > 0) {
        if (cols[0] == 1 && rows[0] == 1) {
            /** add a rigid area */
            panel.add(Box.createRigidArea(filler), cc.xy(1, 1));
            filled_cell_11 = true;
        }
    }

    for (int index = 0; index < cols.length; index++) {
        if (cols[index] == 1 && filled_cell_11)
            continue;
        panel.add(Box.createRigidArea(filler), cc.xy(cols[index], 1));
    }

    for (int index = 0; index < rows.length; index++) {
        if (rows[index] == 1 && filled_cell_11)
            continue;
        panel.add(Box.createRigidArea(filler), cc.xy(1, rows[index]));
    }
}

From source file:ca.phon.app.project.NewSessionPanel.java

License:Open Source License

public JPanel createPanel() {
    JPanel jpanel1 = new JPanel();
    FormLayout formlayout1 = new FormLayout("CENTER:25PX:NONE,FILL:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE",
            "CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:20PX:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:20PX:NONE,CENTER:DEFAULT:NONE");
    CellConstraints cc = new CellConstraints();
    jpanel1.setLayout(formlayout1);//from w  ww. j  a v  a  2  s  .  c  om
    jpanel1.setBorder(new EmptyBorder(5, 5, 5, 5));

    DefaultComponentFactory fac = DefaultComponentFactory.getInstance();

    JComponent titledseparator1 = fac.createSeparator("Step 1");
    jpanel1.add(titledseparator1, cc.xywh(1, 1, 3, 1));

    JComponent titledseparator2 = fac.createSeparator("Step 2");
    jpanel1.add(titledseparator2, cc.xywh(1, 5, 3, 1));

    JLabel jlabel1 = new JLabel();
    jlabel1.setText("Enter a name for the new session:");
    jpanel1.add(jlabel1, cc.xywh(2, 2, 2, 1));

    txtName.setName("txtName");
    jpanel1.add(txtName, cc.xywh(2, 3, 2, 1));

    cmbCorpus.setName("cmbCorpus");
    jpanel1.add(cmbCorpus, cc.xy(2, 7));

    //         ImageFactory imgFactory = ImageFactory.getInstance();
    //         ImageIcon im = new ImageIcon(imgFactory.getImage("new_corpus", 16, 16));
    ImageIcon im = IconManager.getInstance().getIcon("actions/list-add", IconSize.SMALL);
    btnCreateCorpus.setIcon(im);
    btnCreateCorpus.setName("btnCreateCorpus");
    btnCreateCorpus.addActionListener(new CreateCorpusListener());
    jpanel1.add(btnCreateCorpus, cc.xy(3, 7));

    JLabel jlabel2 = new JLabel();
    jlabel2.setText("Select a corpus to use for this session:");
    jpanel1.add(jlabel2, cc.xy(2, 6));

    addFillComponents(jpanel1, new int[] { 2, 3 }, new int[] { 2, 3, 4, 6, 7, 8 });
    return jpanel1;
}

From source file:ca.phon.app.project.ProjectWindow.java

License:Open Source License

private void init() {
    /* Layout *//*from   w w w  .j av  a  2s  .c o m*/
    setLayout(new BorderLayout());

    final ProjectDataTransferHandler transferHandler = new ProjectDataTransferHandler(this);

    /* Create components */
    newCorpusButton = createNewCorpusButton();
    createCorpusButton = createCorpusButton();

    corpusList = new JList<String>();
    corpusModel = new CorpusListModel(getProject());
    corpusList.setModel(corpusModel);
    corpusList.setCellRenderer(new CorpusListCellRenderer());
    corpusList.setVisibleRowCount(20);
    corpusList.addListSelectionListener(e -> {
        if (getSelectedCorpus() != null) {
            String corpus = getSelectedCorpus();
            sessionModel.setCorpus(corpus);
            sessionList.clearSelection();
            corpusDetails.setCorpus(corpus);

            if (getProject().getCorpusSessions(corpus).size() == 0) {
                onSwapNewAndCreateSession(newSessionButton);
            } else {
                onSwapNewAndCreateSession(createSessionButton);
            }
        }
    });
    corpusList.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            doPopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            doPopup(e);
        }

        public void doPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                int clickedIdx = corpusList.locationToIndex(e.getPoint());
                if (clickedIdx >= 0 && Arrays.binarySearch(corpusList.getSelectedIndices(), clickedIdx) < 0) {
                    corpusList.setSelectedIndex(clickedIdx);
                }
                showCorpusListContextMenu(e.getPoint());
            }
        }
    });

    final DragSource corpusDragSource = new DragSource();
    corpusDragSource.createDefaultDragGestureRecognizer(corpusList, DnDConstants.ACTION_COPY, (event) -> {
        final List<ProjectPath> paths = new ArrayList<>();
        for (String corpus : getSelectedCorpora()) {
            final ProjectPath corpusPath = new ProjectPath(getProject(), corpus, null);
            paths.add(corpusPath);
        }
        final ProjectPathTransferable transferable = new ProjectPathTransferable(paths);
        event.startDrag(DragSource.DefaultCopyDrop, transferable);
    });

    corpusList.setDragEnabled(true);
    corpusList.setTransferHandler(transferHandler);

    corpusDetails = new CorpusDetailsPane(getProject());
    corpusDetails.setWrapStyleWord(true);
    corpusDetails.setRows(6);
    corpusDetails.setLineWrap(true);
    corpusDetails.setBackground(Color.white);
    corpusDetails.setOpaque(true);
    JScrollPane corpusDetailsScroller = new JScrollPane(corpusDetails);

    sessionList = new JList<String>();
    newSessionButton = createNewSessionButton();
    createSessionButton = createSessionButton();
    sessionModel = new SessionListModel(getProject());
    sessionList.setModel(sessionModel);
    sessionList.setCellRenderer(new SessionListCellRenderer());
    sessionList.setVisibleRowCount(20);
    sessionList.addListSelectionListener(e -> {
        if (sessionList.getSelectedValue() != null && !e.getValueIsAdjusting()) {
            String corpus = getSelectedCorpus();
            String session = getSelectedSessionName();

            sessionDetails.setSession(corpus, session);
        }
    });
    sessionList.addMouseListener(new MouseInputAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && e.getButton() == 1) {
                // get the clicked item
                int clickedItem = sessionList.locationToIndex(e.getPoint());
                if (sessionList.getModel().getElementAt(clickedItem) == null)
                    return;

                final String session = sessionList.getModel().getElementAt(clickedItem).toString();
                final String corpus = ((SessionListModel) sessionList.getModel()).getCorpus();

                msgPanel.reset();
                msgPanel.setMessageLabel("Opening '" + corpus + "." + session + "'");
                msgPanel.setIndeterminate(true);
                msgPanel.repaint();

                SwingUtilities.invokeLater(() -> {
                    final ActionEvent ae = new ActionEvent(sessionList, -1, "openSession");
                    (new OpenSessionAction(ProjectWindow.this, corpus, session)).actionPerformed(ae);

                    msgPanel.setIndeterminate(false);
                });
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            doPopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            doPopup(e);
        }

        public void doPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                int clickedIdx = sessionList.locationToIndex(e.getPoint());
                if (clickedIdx >= 0 && Arrays.binarySearch(sessionList.getSelectedIndices(), clickedIdx) < 0) {
                    sessionList.setSelectedIndex(clickedIdx);
                }
                showSessionListContextMenu(e.getPoint());
            }
        }
    });

    sessionList.setDragEnabled(true);
    sessionList.setTransferHandler(transferHandler);

    final DragSource sessionDragSource = new DragSource();
    sessionDragSource.createDefaultDragGestureRecognizer(sessionList, DnDConstants.ACTION_COPY, (event) -> {
        final List<ProjectPath> paths = new ArrayList<>();
        final String corpus = getSelectedCorpus();
        if (corpus == null)
            return;
        for (String session : getSelectedSessionNames()) {
            final ProjectPath sessionPath = new ProjectPath(getProject(), corpus, session);
            paths.add(sessionPath);
        }
        final ProjectPathTransferable transferable = new ProjectPathTransferable(paths);
        event.startDrag(DragSource.DefaultCopyDrop, transferable);
    });

    sessionDetails = new SessionDetailsPane(getProject());
    sessionDetails.setLineWrap(true);
    sessionDetails.setRows(6);
    sessionDetails.setWrapStyleWord(true);
    sessionDetails.setBackground(Color.white);
    sessionDetails.setOpaque(true);
    JScrollPane sessionDetailsScroller = new JScrollPane(sessionDetails);

    JScrollPane corpusScroller = new JScrollPane(corpusList);
    JScrollPane sessionScroller = new JScrollPane(sessionList);

    blindModeBox = new JCheckBox("Blind transcription");
    blindModeBox.setSelected(false);

    msgPanel = new StatusPanel();

    corpusPanel = new JPanel(new BorderLayout());
    corpusPanel.add(newCorpusButton, BorderLayout.NORTH);
    corpusPanel.add(corpusScroller, BorderLayout.CENTER);
    corpusPanel.add(corpusDetailsScroller, BorderLayout.SOUTH);

    sessionPanel = new JPanel(new BorderLayout());
    sessionPanel.add(newSessionButton, BorderLayout.NORTH);
    sessionPanel.add(sessionScroller, BorderLayout.CENTER);
    sessionPanel.add(sessionDetailsScroller, BorderLayout.SOUTH);

    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setLeftComponent(corpusPanel);
    splitPane.setRightComponent(sessionPanel);
    splitPane.setResizeWeight(0.5);

    // invoke later
    SwingUtilities.invokeLater(() -> {
        splitPane.setDividerLocation(0.5);
    });

    // the frame layout
    String projectName = null;
    projectName = getProject().getName();

    DialogHeader header = new DialogHeader(projectName, StringUtils.abbreviate(projectLoadPath, 80));

    add(header, BorderLayout.NORTH);

    CellConstraints cc = new CellConstraints();
    final JPanel topPanel = new JPanel(new FormLayout("pref, fill:pref:grow, right:pref", "pref"));
    topPanel.add(msgPanel, cc.xy(1, 1));
    topPanel.add(blindModeBox, cc.xy(3, 1));

    add(splitPane, BorderLayout.CENTER);
    add(topPanel, BorderLayout.SOUTH);

    // if no corpora are currently available, 'prompt' the user to create a new one
    if (getProject().getCorpora().size() == 0) {
        SwingUtilities.invokeLater(() -> {
            onSwapNewAndCreateCorpus(newCorpusButton);
        });
    } else {
        SwingUtilities.invokeLater(() -> {
            corpusList.setSelectedIndex(0);
        });
    }
}

From source file:ca.phon.app.query.EditQueryPanel.java

License:Open Source License

private void init() {
    final FormLayout layout = new FormLayout("right:pref, 3dlu, fill:pref:grow",
            "pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, fill:pref:grow");
    final CellConstraints cc = new CellConstraints();
    setLayout(layout);/*  w ww. j a  v  a 2 s.c  o  m*/

    starBox = new StarBox(IconSize.SMALL);
    starBox.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (getQuery() != null) {
                getQuery().setStarred(starBox.isSelected());
            }
        }
    });

    queryNameField = new JTextField();
    queryNameField.selectAll();
    queryNameField.requestFocusInWindow();
    queryNameField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateName();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateName();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }

        private void updateName() {
            if (getQuery() != null)
                getQuery().setName(queryNameField.getText());
        }
    });

    queryCommentsArea = new JTextArea();
    queryCommentsArea.setRows(5);
    queryCommentsArea.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateComments();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateComments();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }

        private void updateComments() {
            if (getQuery() != null)
                getQuery().setComments(queryCommentsArea.getText());
        }
    });

    uuidLabel = new JLabel();

    dateLabel = new JLabel();

    add(starBox, cc.xy(1, 1));
    add(queryNameField, cc.xy(3, 1));

    add(new JLabel("UUID:"), cc.xy(1, 3));
    add(uuidLabel, cc.xy(3, 3));

    add(new JLabel("Date:"), cc.xy(1, 5));
    add(dateLabel, cc.xy(3, 5));

    add(new JLabel("Comments:"), cc.xy(1, 7));
    add(new JScrollPane(queryCommentsArea), cc.xywh(3, 7, 1, 2));
}

From source file:ca.phon.app.query.QueryEditorWindow.java

License:Open Source License

private JComponent createForm() {
    JComponent retVal = new JPanel();
    retVal.setLayout(new BorderLayout());

    ImageIcon saveIcon = IconManager.getInstance().getIcon("actions/document-save", IconSize.SMALL);
    saveButton = new JButton(saveIcon);
    saveButton.setToolTipText("Save script");
    saveButton.putClientProperty("JButton.buttonType", "textured");
    saveButton.addActionListener(new ActionListener() {

        @Override//from www  . jav  a 2s .  c  o  m
        public void actionPerformed(ActionEvent e) {
            if (getCurrentFile() != null) {
                saveScriptToFile(getCurrentFile());
            } else {
                saveScriptAs();
            }
        }

    });

    ImageIcon saveAsIcon = IconManager.getInstance().getIcon("actions/document-save-as", IconSize.SMALL);
    saveAsButton = new JButton(saveAsIcon);
    saveAsButton.setToolTipText("Save script as...");
    saveAsButton.putClientProperty("JButton.buttonType", "textured");
    saveAsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            saveScriptAs();
        }

    });

    ImageIcon openIcon = IconManager.getInstance().getIcon("actions/document-open", IconSize.SMALL);
    openButton = new JButton(openIcon);
    openButton.setToolTipText("Open script");
    openButton.putClientProperty("JButton.buttonType", "textured");
    openButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Runnable run = new Runnable() {
                @Override
                public void run() {
                    openScript();
                }
            };
            PhonWorker.getInstance().invokeLater(run);
        }
    });

    final JToolBar toolBar = new JToolBar();
    //      toolBar.disableBackgroundPainter();
    toolBar.setFloatable(false);
    toolBar.add(openButton);
    toolBar.add(saveButton);
    toolBar.add(saveAsButton);
    //      toolBar.addComponentToLeft(openButton);
    //      toolBar.addComponentToLeft(saveButton);
    //      toolBar.addComponentToLeft(saveAsButton);

    FormLayout bottomLayout = new FormLayout("left:pref, fill:pref:grow, right:pref", "pref, pref");

    JPanel bottomPanel = new JPanel();
    bottomPanel.setLayout(bottomLayout);

    includeExcludedBox = new JCheckBox("Include excluded records");

    positionLabel = new JLabel();
    positionLabel.setFont(positionLabel.getFont().deriveFont(10.0f));

    execButton = new JButton("Run Query");
    execButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            onRunQuery();
        }

    });
    getRootPane().setDefaultButton(execButton);

    CellConstraints cc = new CellConstraints();

    bottomPanel.add(positionLabel, cc.xy(1, 1));
    bottomPanel.add(includeExcludedBox, cc.xy(1, 2));
    bottomPanel.add(execButton, cc.xy(3, 2));

    final JPanel editorPanel = new JPanel(new BorderLayout());
    editorPanel.add(toolBar, BorderLayout.NORTH);
    editorPanel.add(scriptEditor, BorderLayout.CENTER);
    editorPanel.add(bottomPanel, BorderLayout.SOUTH);

    editorTabs = new JTabbedPane();
    final QueryScript script = (QueryScript) scriptEditor.getScript();
    final QueryName queryName = script.getExtension(QueryName.class);
    final String name = (queryName != null ? queryName.getName() : "untitled");
    editorTabs.add("Script : " + name, editorPanel);

    retVal.add(editorTabs, BorderLayout.CENTER);
    return retVal;
}

From source file:ca.phon.app.query.QueryHistory.java

License:Open Source License

private void init() {
    setLayout(new BorderLayout());

    final Project project = getProject();
    header = new DialogHeader("Query History", project.getName());

    queryModel = new QueryHistoryTableModel(project);
    queryTable = new JXTable(queryModel);
    queryRowSorter = new TableRowSorter<QueryHistoryTableModel>(queryModel);
    final RowSorter.SortKey sortKey = new RowSorter.SortKey(QueryHistoryTableModel.Columns.Date.ordinal(),
            SortOrder.ASCENDING);
    queryRowSorter.setSortKeys(Collections.singletonList(sortKey));
    queryRowSorter.setSortsOnUpdates(true);
    queryTable.setRowSorter(queryRowSorter);
    queryTable.addHighlighter(HighlighterFactory.createSimpleStriping());
    queryTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    queryTable.addKeyListener(new KeyListener() {

        @Override/*ww  w  .  jav a2  s.  c om*/
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE || e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
                int selectedRow = queryTable.getSelectedRow();
                if (selectedRow < 0)
                    return;
                selectedRow = queryTable.convertRowIndexToModel(selectedRow);
                Query q = queryModel.getQueryForRow(selectedRow);
                if (q != null) {
                    deleteQuery(q);
                }
                e.consume();
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyTyped(KeyEvent e) {

        }

    });
    queryTable.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showQueryContextMenu(e.getPoint());
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            showMenu(e);
        }

        @Override
        public void mousePressed(MouseEvent e) {
            showMenu(e);
        }

        private void showMenu(MouseEvent e) {
            if (e.isPopupTrigger()) {
                int selectedRow = queryTable.rowAtPoint(e.getPoint());
                if (selectedRow < 0)
                    return;
                queryTable.getSelectionModel().setSelectionInterval(selectedRow, selectedRow);
                selectedRow = queryTable.convertRowIndexToModel(selectedRow);
                //               if(selectedRow >= 0 && selectedRow < queryTable.getModel().r)
                showQueryContextMenu(e.getPoint());
            }
            super.mousePressed(e);
        }

    });

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

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            int selectedRow = queryTable.getSelectedRow();
            if (selectedRow < 0)
                return;
            selectedRow = queryTable.convertRowIndexToModel(selectedRow);
            final Query q = queryModel.getQueryForRow(selectedRow);
            if (q != null) {
                final Runnable update = new Runnable() {
                    public void run() {
                        updateWindow(q);
                    }
                };
                SwingUtilities.invokeLater(update);
            }
        }

    });

    queryTable.getColumn(QueryHistoryTableModel.Columns.Date.ordinal()).setCellRenderer(new DateRenderer());
    //      queryTable.getColumn(QueryHistoryTableModel.Columns.Starred.ordinal()).setCellRenderer(
    //            new StarRenderer());
    queryTable.setColumnControlVisible(true);
    queryModel.update();

    tblSearchField = new TableSearchField(queryTable, false);
    tblSearchField.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            tblSearchField.updateTableFilter();
        }

        @Override
        public void keyPressed(KeyEvent e) {
        }
    });

    infoPanel = new QueryInfoPanel(project);

    ImageIcon refreshIcon = IconManager.getInstance().getIcon("actions/reload", IconSize.SMALL);
    PhonUIAction refreshAct = new PhonUIAction(queryModel, "update");
    refreshAct.putValue(PhonUIAction.SMALL_ICON, refreshIcon);
    refreshAct.putValue(PhonUIAction.SHORT_DESCRIPTION, "Refresh query table");
    refreshButton = new JButton(refreshAct);

    onlyStarredBox = new StarBox(IconSize.SMALL);
    onlyStarredBox.setToolTipText("Only show starred queries");
    onlyStarredBox.setSelected(false);
    onlyStarredBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            queryModel.setStarredOnly(onlyStarredBox.isSelected());
            queryModel.update();
        }
    });

    FormLayout filterLayout = new FormLayout("pref, fill:pref:grow, pref", "pref");
    CellConstraints cc = new CellConstraints();
    JPanel filterPanel = new JPanel(filterLayout);

    filterPanel.add(tblSearchField, cc.xy(2, 1));
    filterPanel.add(onlyStarredBox, cc.xy(1, 1));
    filterPanel.add(refreshButton, cc.xy(3, 1));

    JPanel leftPanel = new JPanel(new BorderLayout());
    leftPanel.add(filterPanel, BorderLayout.NORTH);
    leftPanel.add(new JScrollPane(queryTable), BorderLayout.CENTER);

    JSplitPane splitPane = new JSplitPane();
    splitPane.setLeftComponent(leftPanel);
    splitPane.setRightComponent(infoPanel);
    splitPane.setOneTouchExpandable(true);

    add(header, BorderLayout.NORTH);
    add(splitPane, BorderLayout.CENTER);
}

From source file:ca.phon.app.query.QueryInfoPanel.java

License:Open Source License

private void init() {
    setLayout(new BorderLayout());

    starBox = new StarBox(IconSize.SMALL);
    starBox.addActionListener(new ActionListener() {

        @Override/*  w ww . jav a  2 s. co m*/
        public void actionPerformed(ActionEvent e) {
            toggleStarred();
        }
    });

    // query name
    nameLabel = new JXLabel();
    Font nameFont = nameLabel.getFont().deriveFont(Font.BOLD, 14.0f);
    nameLabel.setFont(nameFont);

    final ImageIcon searchIcon = IconManager.getInstance().getIcon("actions/system-search", IconSize.SMALL);
    final PhonUIAction openAction = new PhonUIAction(this, "onOpenQuery");
    openAction.putValue(PhonUIAction.NAME, "Open Query");
    openAction.putValue(PhonUIAction.SMALL_ICON, searchIcon);
    openAction.putValue(PhonUIAction.SHORT_DESCRIPTION, "Open query in editor");
    openButton = new JButton(openAction);

    nameField = new JTextField();
    nameField.setFont(nameFont);

    uuidLabel = new JLabel();

    dateLabel = new JLabel();

    commentsArea = new JTextArea();
    commentsArea.setRows(5);
    commentsArea.setLineWrap(true);
    commentsArea.setEditable(false);
    commentsArea.setFont(Font.getFont("dialog"));
    final JScrollPane commentsLabelScroller = new JScrollPane(commentsArea);

    // layout form components
    final FormLayout layout = new FormLayout("right:pref, 3dlu, fill:pref:grow, right:pref",
            "pref, 3dlu, pref, 3dlu, pref, 3dlu, top:pref, fill:pref:grow");
    final CellConstraints cc = new CellConstraints();

    infoSection = new JPanel(layout);
    infoSection.setBorder(BorderFactory.createTitledBorder("Information"));
    infoSection.add(starBox, cc.xy(1, 1));
    infoSection.add(nameLabel, cc.xy(3, 1));
    infoSection.add(openButton, cc.xy(4, 1));

    infoSection.add(new JLabel("UUID:"), cc.xy(1, 3));
    infoSection.add(uuidLabel, cc.xyw(3, 3, 2));

    infoSection.add(new JLabel("Date:"), cc.xy(1, 5));
    infoSection.add(dateLabel, cc.xyw(3, 5, 2));

    infoSection.add(new JLabel("Comments:"), cc.xy(1, 7));
    infoSection.add(commentsLabelScroller, cc.xywh(3, 7, 2, 2));

    resultsModel = new ResultSetTableModel(project, null);
    resultsModel.addPropertyChangeListener(bgTaskPropertyListener);
    resultsTable = new JXTable(resultsModel);
    resultsTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    resultsTable.addMouseListener(resultsMouseListener);
    resultsRowSorter = new TableRowSorter<ResultSetTableModel>(resultsModel);
    resultsRowSorter.setSortsOnUpdates(true);
    final RowSorter.SortKey sortKey = new RowSorter.SortKey(ResultSetTableModel.Columns.ID.ordinal(),
            SortOrder.ASCENDING);
    resultsRowSorter.setSortKeys(Collections.singletonList(sortKey));
    resultsTable.setRowSorter(resultsRowSorter);
    resultsTable.setColumnControlVisible(true);
    resultsTable.addHighlighter(HighlighterFactory.createSimpleStriping());
    resultsTable.setVisibleRowCount(10);

    // remove selection column
    resultsTable.getColumnModel().removeColumn(resultsTable.getColumn(0));
    JScrollPane resultsScroller = new JScrollPane(resultsTable);

    final ImageIcon reportIcon = IconManager.getInstance().getIcon("mimetypes/x-office-spreadsheet",
            IconSize.SMALL);
    final PhonUIAction reportAction = new PhonUIAction(this, "onReport");
    reportAction.putValue(PhonUIAction.NAME, "Report");
    reportAction.putValue(PhonUIAction.SHORT_DESCRIPTION, "Create report");
    reportAction.putValue(PhonUIAction.SMALL_ICON, reportIcon);
    reportButton = new JButton(reportAction);

    busyLabel = new JXBusyLabel(new Dimension(16, 16));
    busyLabel.setBusy(false);

    hideResultsBox = new JCheckBox("Hide empty result sets");
    hideResultsBox.setSelected(false);
    hideResultsBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            toggleRowFilter();
        }
    });

    // system preference
    openEditorBox = new JCheckBox("Open session with result set");
    openEditorBox.setSelected(true);

    resultsSection = new JPanel(new BorderLayout());
    resultsSection.setBorder(BorderFactory.createTitledBorder("Results"));
    final FormLayout topLayout = new FormLayout("pref, left:pref, left:pref, fill:pref:grow, right:pref",
            "pref");
    final JPanel topResultsPanel = new JPanel();
    topResultsPanel.setLayout(topLayout);
    topResultsPanel.add(busyLabel, cc.xy(1, 1));
    topResultsPanel.add(hideResultsBox, cc.xy(2, 1));
    topResultsPanel.add(openEditorBox, cc.xy(3, 1));
    topResultsPanel.add(reportButton, cc.xy(5, 1));

    resultsSection.add(topResultsPanel, BorderLayout.NORTH);
    resultsSection.add(resultsScroller, BorderLayout.CENTER);

    openButton.setEnabled(false);
    reportButton.setEnabled(false);

    add(infoSection, BorderLayout.NORTH);
    add(resultsSection, BorderLayout.CENTER);
}

From source file:ca.phon.app.query.QueryRunnerPanel.java

License:Open Source License

private void init() {
    setLayout(new BorderLayout());

    // top panel/*  w  w  w  .j a  va  2  s . c  o m*/
    FormLayout topLayout = new FormLayout("pref, 3dlu, left:pref, left:pref, fill:pref:grow, pref, right:pref",
            "pref");
    CellConstraints cc = new CellConstraints();
    topPanel = new JPanel(topLayout);

    saveButton = new JButton("Save results");
    ImageIcon saveIcon = IconManager.getInstance().getIcon("actions/document-save-as", IconSize.SMALL);
    saveButton.setIcon(saveIcon);
    saveButton.setEnabled(false);
    saveButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            showSaveQueryDialog();
        }

    });

    reportButton = new JButton("Report");
    ImageIcon ssIcon = IconManager.getInstance().getIcon("mimetypes/x-office-spreadsheet", IconSize.SMALL);
    reportButton.setIcon(ssIcon);
    reportButton.setEnabled(false);
    reportButton.setVisible(true);
    reportButton.addActionListener((e) -> {
        // show menu
        final JMenu menu = new JMenu();
        final ReportLibrary library = new ReportLibrary();
        library.setupMenu(tempProject, query.getUUID().toString(), menu);

        menu.getPopupMenu().show(reportButton, 0, reportButton.getHeight());
    });

    hideRowsBox = new JCheckBox("Hide empty results");
    hideRowsBox.setEnabled(false);
    hideRowsBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (hideRowsBox.isSelected()) {
                final RowFilter<RunnerTableModel, Integer> filter = RowFilter.regexFilter("[1-9][0-9]*", 3);
                resultsTableSorter.setRowFilter(filter);
            } else {
                resultsTableSorter.setRowFilter(null);
            }
        }

    });

    openEditorBox = new JCheckBox("Open session with results");
    openEditorBox.setSelected(true);
    openEditorBox.setVisible(false);

    busyLabel = new JXBusyLabel(new Dimension(16, 16));
    busyLabel.setBusy(true);

    String labelText = "Completed: 0/" + tableModel.getRowCount();
    completedLabel = new JLabel(labelText);

    topPanel.add(completedLabel, cc.xy(3, 1));
    topPanel.add(busyLabel, cc.xy(1, 1));
    topPanel.add(openEditorBox, cc.xy(4, 1));
    topPanel.add(saveButton, cc.xy(6, 1));
    topPanel.add(reportButton, cc.xy(7, 1));

    // table

    resultsTable = new JXTable(tableModel);
    resultsTable.addHighlighter(HighlighterFactory.createSimpleStriping());
    resultsTable.setRowSorter(resultsTableSorter);

    resultsTable.getColumn(1).setCellRenderer(statusCellRenderer);
    resultsTable.getColumn(2).setCellRenderer(progressCellRenderer);

    resultsTable.setColumnControlVisible(true);
    resultsTable.setVisibleRowCount(15);
    resultsTable.packAll();

    resultsTable.addMouseListener(tableMouseListener);

    add(new JScrollPane(resultsTable), BorderLayout.CENTER);
    add(topPanel, BorderLayout.NORTH);
}

From source file:ca.phon.app.query.report.GroupSectionPanel.java

License:Open Source License

private void init() {
    super.setInformationText(getClass().getName() + ".info", INFO_TEXT);
    Group gt = getSection();/*from   w ww  .  jav a  2s. c om*/

    FormLayout layout = new FormLayout("5dlu, fill:pref:grow", "pref, pref");
    JPanel panel = new JPanel(layout);
    CellConstraints cc = new CellConstraints();

    printSessionInfoBox = new JCheckBox("Include session information");
    printSessionInfoBox.setSelected(gt.isPrintSessionHeader());
    printSessionInfoBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            getSection().setPrintSessionHeader(printSessionInfoBox.isSelected());
            printParticipantInfoBox.setEnabled(printSessionInfoBox.isSelected());
        }
    });

    printParticipantInfoBox = new JCheckBox("Include participant information");
    printParticipantInfoBox.setSelected(gt.isPrintParticipantInformation());
    printParticipantInfoBox.setEnabled(printSessionInfoBox.isSelected());
    printParticipantInfoBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            getSection().setPrintParticipantInformation(printParticipantInfoBox.isSelected());
        }
    });

    panel.add(printSessionInfoBox, cc.xyw(1, 1, 2));
    panel.add(printParticipantInfoBox, cc.xy(2, 2));

    panel.setBorder(BorderFactory.createTitledBorder("Options"));
    add(panel, BorderLayout.CENTER);
}

From source file:ca.phon.app.query.report.InventorySectionPanel.java

License:Open Source License

private void init() {
    super.setInformationText(getClass().getName() + ".info", INFO_TEXT);

    InventorySection invData = getSection();

    caseSensitiveBox = new JCheckBox("Case sensitive");
    caseSensitiveBox.setSelected(invData.isCaseSensitive());
    caseSensitiveBox.addActionListener(new ActionListener() {

        @Override//from  w ww. ja  v a  2s.  c  om
        public void actionPerformed(ActionEvent arg0) {
            getSection().setCaseSensitive(caseSensitiveBox.isSelected());

        }
    });

    ignoreDiacriticsBox = new JCheckBox("Ignore diacritics (i.e., diacritics are removed from result values)");
    ignoreDiacriticsBox.setSelected(invData.isIgnoreDiacritics());
    ignoreDiacriticsBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            getSection().setIgnoreDiacritics(ignoreDiacriticsBox.isSelected());
        }

    });

    groupByFormatBox = new JCheckBox(
            "Group results by format (e.g., for 'Data Tiers' queries this will group results by tier)");
    groupByFormatBox.setSelected(invData.isGroupByFormat());
    groupByFormatBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            getSection().setGroupByFormat(groupByFormatBox.isSelected());
        }
    });

    includeResultValueBox = new JCheckBox("Include result value (i.e., data matched in the result set)");
    includeResultValueBox.setSelected(invData.isIncludeResultValue());
    includeResultValueBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            getSection().setIncludeResultValue(includeResultValueBox.isSelected());
        }
    });

    includeMetadataBox = new JCheckBox("Include metadata in result value when counting");
    includeMetadataBox.setSelected(invData.isIncludeMetadata());
    includeMetadataBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            getSection().setIncludeMetadata(includeMetadataBox.isSelected());
        }
    });

    includeExcludedBox = new JCheckBox("Include excluded results");
    includeExcludedBox.setSelected(invData.isIncludeExcluded());
    includeExcludedBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            getSection().setIncludeExcluded(includeExcludedBox.isSelected());
        }
    });

    JPanel resultFormatPanel = new JPanel(new GridLayout(0, 1));
    resultFormatPanel.setBorder(BorderFactory.createTitledBorder("Result Data"));
    resultFormatPanel.add(includeResultValueBox);
    resultFormatPanel.add(includeMetadataBox);
    resultFormatPanel.add(includeExcludedBox);

    JPanel dataOptionsPanel = new JPanel(new GridLayout(0, 1));
    dataOptionsPanel.setBorder(BorderFactory.createTitledBorder("Options"));
    dataOptionsPanel.add(caseSensitiveBox);
    dataOptionsPanel.add(ignoreDiacriticsBox);

    JPanel groupingOptions = new JPanel(new GridLayout(0, 1));
    groupingOptions.setBorder(BorderFactory.createTitledBorder("Grouping"));
    groupingOptions.add(groupByFormatBox);

    FormLayout layout = new FormLayout("fill:pref:grow", "pref, pref, pref");
    CellConstraints cc = new CellConstraints();
    optionsPanel = new JPanel(layout);
    optionsPanel.add(dataOptionsPanel, cc.xy(1, 2));
    optionsPanel.add(resultFormatPanel, cc.xy(1, 1));
    optionsPanel.add(groupingOptions, cc.xy(1, 3));

    add(optionsPanel, BorderLayout.CENTER);

}