Example usage for javax.swing JTable JTable

List of usage examples for javax.swing JTable JTable

Introduction

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

Prototype

public JTable(TableModel dm) 

Source Link

Document

Constructs a JTable that is initialized with dm as the data model, a default column model, and a default selection model.

Usage

From source file:com.plugin.UI.Windows.BiblePeopleSearchResultsDialog.java

/**
 * Initialize./*from   www  .  java 2  s . c om*/
 * 
 * @param _term the _term
 * 
 * @throws Exception the exception
 */
private void initialize(String _term) throws Exception {
    ArrayList<String[]> arr = new ArrayList<String[]>();
    for (BiblePerson bp : Global.biblePersons) {
        if (isSoundexCalc(bp.getName().toUpperCase(), _term)) {
            String[] arrin = new String[5];
            arrin[0] = String.valueOf(bp.getName_id());
            arrin[1] = bp.getName();
            arrin[2] = bp.getFather();
            arrin[3] = bp.getMother();
            arrin[4] = bp.getBible_ref();
            arr.add(arrin);
        }
    }
    String[][] arr3 = new String[arr.size()][5];
    for (int i = 0; i < arr.size(); i++)
        arr3[i] = arr.get(i);
    String columns[] = new String[] { "ID", "Name", "Father", "Mother", "Reference" };
    tm = new DefaultTableModel(arr3, columns) {
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };

    table = new JTable(tm);

    table.addMouseListener(new MouseListener() {

        public void mouseClicked(MouseEvent e) {
            int member_id = Integer.parseInt((String) tm.getValueAt(table.getSelectedRow(), 0));
            BibleGenealogy.setSelectMember(member_id);
            if (e.getClickCount() == 2) {
                new BiblePersonDialog(Global._jMainFrame, member_id);
            }
        }

        public void mouseEntered(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        public void mouseExited(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        public void mousePressed(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        public void mouseReleased(MouseEvent e) {
            // TODO Auto-generated method stub

        }
    });

    JScrollPane jsp = new JScrollPane(table);
    jsp.setSize(640, 260);
    this.getContentPane().add(jsp);
    this.pack();
    this.setTitle("Bible People Search Results - " + _term);
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.setLocationRelativeTo(null);
    this.setVisible(true);
}

From source file:logdruid.ui.mainpanel.StatRecordingSelectorPanel.java

/**
 * Create the panel.// www.ja  v a  2s. c o  m
 */
public StatRecordingSelectorPanel(final Repository rep, Source src) {
    repository = rep;
    source = src;
    records = rep.getRecordings(StatRecording.class);
    // Collections.sort(records);
    Iterator it = records.iterator();
    while (it.hasNext()) {
        Recording record = (Recording) it.next();
        data.add(new Object[] { record.getName(), record.getRegexp(), record.getType(),
                src.isActiveRecordingOnSource(record) });
    }

    model = new logdruid.ui.mainpanel.StatRecordingSelectorPanel.MyTableModel(data, header);

    StatRecordingSelectorPanel thiis = this;
    logger.info("source is " + ((source == null) ? "null" : src.getSourceName()));
    setLayout(new BorderLayout(0, 0));

    JPanel panel_1 = new JPanel();
    panel_1.setLayout(new BorderLayout(0, 0));

    table = new JTable(model);
    JScrollPane scrollPane = new JScrollPane(table);
    panel_1.add(scrollPane, BorderLayout.CENTER);

    table.setPreferredScrollableViewportSize(new Dimension(0, 150));
    table.setFillsViewportHeight(true);
    table.setAutoCreateRowSorter(true);
    // Set up column sizes.
    initColumnSizes(table);

    JSplitPane splitPane = new JSplitPane();
    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    add(splitPane);

    jPanelDetail = new JPanel();
    splitPane.setBottomComponent(jPanelDetail);
    splitPane.setTopComponent(panel_1);
    jPanelDetail.setLayout(new BorderLayout(0, 0));
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            int selectedRow = ((table.getSelectedRow() != -1)
                    ? table.convertRowIndexToModel(table.getSelectedRow())
                    : -1);
            logger.info("ListSelectionListener - selectedRow: " + selectedRow);
            if (selectedRow >= 0) {
                if (jPanelDetail != null) {
                    logger.debug("ListSelectionListener - valueChanged");
                    jPanelDetail.removeAll();
                    recEditor = getEditor(repository.getRecording(StatRecording.class, selectedRow));
                    if (recEditor != null) {
                        jPanelDetail.add(recEditor, BorderLayout.CENTER);
                    }
                    jPanelDetail.revalidate();
                }
            }
        }
    });
    if (repository.getRecordings(StatRecording.class).size() > 0) {
        recEditor = getEditor(repository.getRecording(StatRecording.class, 0));
        jPanelDetail.add(recEditor, BorderLayout.CENTER);
        table.setRowSelectionInterval(0, 0);
    }
    if (model.getRowCount() > 0) {
        table.getRowSorter().toggleSortOrder(0);
        table.setRowSelectionInterval(0, 0);

    }
}

From source file:logdruid.ui.table.EventRecordingEditorTable.java

public EventRecordingEditorTable(Repository repo, Recording re, JTextPane textPane) {
    super(new GridLayout(1, 0));
    this.examplePane = textPane;
    model = new MyTableModel(data, header);
    table = new JTable(model);
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);//from  w w w.  j av  a2  s.c  om
    rep = repo;
    this.theLine = textPane.getText();
    recording = re;
    // Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    // Set up column sizes.
    initColumnSizes(table);
    // Fiddle with the type and processing column's cell editors/renderers.
    setUpTypeColumn(table, table.getColumnModel().getColumn(2));
    setUpProcessingColumn(table, table.getColumnModel().getColumn(3));

    // Add the scroll pane to this panel.
    add(scrollPane);

    if (re.getClass() == EventRecording.class) {
        records = ((EventRecording) re).getRecordingItem();
    } else if (re.getClass() == StatRecording.class) {
        records = ((StatRecording) re).getRecordingItem();
    } else if (re.getClass() == MetadataRecording.class) {
        records = ((MetadataRecording) re).getRecordingItem();
    }
    // Collections.sort(records);
    if (records != null) {
        Iterator it = records.iterator();

        while (it.hasNext()) {
            RecordingItem rI = (RecordingItem) it.next();
            data.add(new Object[] { rI.getName(), rI.getBefore(), rI.getType(), rI.getProcessingType(),
                    rI.getAfter(), rI.isSelected(), "" });
        }
        FixValues();
    }
}

From source file:com.plugin.UI.Windows.UserSearchResultsDialog.java

/**
 * Initialize.//  ww w.  j  a v  a 2 s  .  co m
 * 
 * @param _term the _term
 * 
 * @throws Exception the exception
 */
private void initialize(String _term) throws Exception {
    ArrayList<String[]> arr = new ArrayList<String[]>();
    for (ChurchMembersData mem : ChurchMemberUtils.getChurchMembers()) {
        if (isSoundex(mem, _term.toUpperCase())) {
            String[] arrin = new String[5];
            arrin[0] = MemberID.getTranslatedID(mem.getMember_id(), mem.getName_english());
            arrin[1] = mem.getName_english() + " (" + mem.getName_otherLang() + ")";
            arrin[2] = mem.getStreet();
            arrin[3] = mem.getSuburb();
            arrin[4] = mem.getState();
            arr.add(arrin);
        }
    }
    String[][] arr3 = new String[arr.size()][5];
    for (int i = 0; i < arr.size(); i++)
        arr3[i] = arr.get(i);
    String columns[] = new String[] { "MemberID", "Name", "Street", "Suburb", "State" };
    tm = new DefaultTableModel(arr3, columns) {
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };

    table = new JTable(tm);

    table.addMouseListener(new MouseListener() {

        public void mouseClicked(MouseEvent e) {
            String member_id = (String) tm.getValueAt(table.getSelectedRow(), 0);
            ChurchMembers.setSelectMember(member_id);
            if (e.getClickCount() == 2) {
                new MemberDialog(Global.DISPLAY_CHURCH_MEMBER, MemberID.getOriginalID(member_id));
            }
        }

        public void mouseEntered(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        public void mouseExited(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        public void mousePressed(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        public void mouseReleased(MouseEvent e) {
            // TODO Auto-generated method stub

        }
    });

    JScrollPane jsp = new JScrollPane(table);
    jsp.setSize(640, 260);
    this.getContentPane().add(jsp);
    this.pack();
    this.setTitle("Church Members Search Results - " + _term);
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.setLocationRelativeTo(null);
    this.setVisible(true);
}

From source file:logdruid.ui.mainpanel.MetadataRecordingSelectorPanel.java

/**
 * Create the panel.//from w w w .ja  v a 2s  .c  o  m
 */
public MetadataRecordingSelectorPanel(Repository rep, Source src) {
    repository = rep;
    source = src;
    records = rep.getRecordings(MetadataRecording.class);
    // Collections.sort(records);
    Iterator it = records.iterator();
    while (it.hasNext()) {
        Recording record = (Recording) it.next();
        data.add(new Object[] { record.getName(), record.getRegexp(), record.getType(),
                src.isActiveRecordingOnSource(record) });
    }

    model = new logdruid.ui.mainpanel.MetadataRecordingSelectorPanel.MyTableModel(data, header);

    logger.info("source is " + ((source == null) ? "null" : src.getSourceName()));
    setLayout(new BorderLayout(0, 0));

    JPanel panel_1 = new JPanel();
    panel_1.setLayout(new BorderLayout(0, 0));

    table = new JTable(model);
    JScrollPane scrollPane = new JScrollPane(table);
    panel_1.add(scrollPane, BorderLayout.CENTER);

    table.setPreferredScrollableViewportSize(new Dimension(0, 150));
    table.setFillsViewportHeight(true);
    table.setAutoCreateRowSorter(true);

    // Set up column sizes.
    initColumnSizes(table);
    reloadTable();

    JSplitPane splitPane = new JSplitPane();
    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    add(splitPane);

    jPanelDetail = new JPanel();
    splitPane.setBottomComponent(jPanelDetail);
    splitPane.setTopComponent(panel_1);

    jPanelDetail.setLayout(new BorderLayout(0, 0));
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            // ((table.getSelectedRow()!=-1)?table.convertRowIndexToModel(table.getSelectedRow()):-1)
            // persist repository
            // display selected row
            int selectedRow = ((table.getSelectedRow() != -1)
                    ? table.convertRowIndexToModel(table.getSelectedRow())
                    : -1);

            logger.info("ListSelectionListener - selectedRow: " + selectedRow);
            if (selectedRow >= 0) {

                if (jPanelDetail != null) {
                    logger.debug("ListSelectionListener - valueChanged");
                    jPanelDetail.removeAll();
                    recEditor = getEditor(repository.getRecording(MetadataRecording.class, selectedRow));
                    if (recEditor != null) {
                        jPanelDetail.add(recEditor, BorderLayout.CENTER);
                    }
                    reloadTable();
                    jPanelDetail.revalidate();
                }
            }
        }
    });
    if (repository.getRecordings(MetadataRecording.class).size() > 0) {
        recEditor = getEditor(repository.getRecording(MetadataRecording.class, 0));
        jPanelDetail.add(recEditor, BorderLayout.CENTER);
        table.setRowSelectionInterval(0, 0);
    }
    if (model.getRowCount() > 0) {
        table.getRowSorter().toggleSortOrder(0);
        table.setRowSelectionInterval(0, 0);
    }
    //reloadTable();
    // jPanelDetail.revalidate();

}

From source file:mekhq.gui.FinancesTab.java

@Override
public void initTab() {
    resourceMap = ResourceBundle.getBundle("mekhq.resources.FinancesTab", new EncodeControl()); //$NON-NLS-1$

    GridBagConstraints gridBagConstraints;

    setLayout(new GridBagLayout());
    ChartPanel financeAmountPanel = (ChartPanel) createGraphPanel(GraphType.BALANCE_AMOUNT);
    ChartPanel financeMonthlyPanel = (ChartPanel) createGraphPanel(GraphType.MONTHLY_FINANCES);

    financeModel = new FinanceTableModel();
    financeTable = new JTable(financeModel);
    financeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    financeTable.addMouseListener(new FinanceTableMouseAdapter(getCampaignGui(), financeTable, financeModel));
    financeTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    TableColumn column = null;//from  www  . j ava2s.co  m
    for (int i = 0; i < FinanceTableModel.N_COL; i++) {
        column = financeTable.getColumnModel().getColumn(i);
        column.setPreferredWidth(financeModel.getColumnWidth(i));
        column.setCellRenderer(financeModel.getRenderer());
    }
    financeTable.setIntercellSpacing(new Dimension(0, 0));
    financeTable.setShowGrid(false);

    loanModel = new LoanTableModel();
    loanTable = new JTable(loanModel);
    loanTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    loanTable.addMouseListener(new LoanTableMouseAdapter(getCampaignGui(), loanTable, loanModel));
    loanTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    column = null;
    for (int i = 0; i < LoanTableModel.N_COL; i++) {
        column = loanTable.getColumnModel().getColumn(i);
        column.setPreferredWidth(loanModel.getColumnWidth(i));
        column.setCellRenderer(loanModel.getRenderer());
    }
    loanTable.setIntercellSpacing(new Dimension(0, 0));
    loanTable.setShowGrid(false);
    JScrollPane scrollLoanTable = new JScrollPane(loanTable);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    JPanel panBalance = new JPanel(new GridBagLayout());
    panBalance.add(new JScrollPane(financeTable), gridBagConstraints);
    panBalance.setMinimumSize(new java.awt.Dimension(350, 100));
    panBalance.setBorder(BorderFactory.createTitledBorder("Balance Sheet"));
    JPanel panLoan = new JPanel(new GridBagLayout());
    panLoan.add(scrollLoanTable, gridBagConstraints);

    JTabbedPane financeTab = new JTabbedPane();
    financeTab.setMinimumSize(new java.awt.Dimension(450, 300));
    financeTab.setPreferredSize(new java.awt.Dimension(450, 300));

    JSplitPane splitFinances = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panBalance, financeTab);
    splitFinances.setOneTouchExpandable(true);
    splitFinances.setContinuousLayout(true);
    splitFinances.setResizeWeight(1.0);
    splitFinances.setName("splitFinances");

    financeTab.addTab(resourceMap.getString("activeLoans.text"), panLoan);
    financeTab.addTab(resourceMap.getString("cbillsBalanceTime.text"), financeAmountPanel);
    financeTab.addTab(resourceMap.getString("monthlyRevenueExpenditures.text"), financeMonthlyPanel);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    add(splitFinances, gridBagConstraints);

    JPanel panelFinanceRight = new JPanel(new BorderLayout());

    JPanel pnlFinanceBtns = new JPanel(new GridLayout(2, 2));
    btnAddFunds = new JButton("Add Funds (GM)");
    btnAddFunds.addActionListener(ev -> addFundsActionPerformed());
    btnAddFunds.setEnabled(getCampaign().isGM());
    pnlFinanceBtns.add(btnAddFunds);
    JButton btnGetLoan = new JButton("Get Loan");
    btnGetLoan.addActionListener(e -> showNewLoanDialog());
    pnlFinanceBtns.add(btnGetLoan);

    btnManageAssets = new JButton("Manage Assets (GM)");
    btnManageAssets.addActionListener(e -> manageAssets());
    btnManageAssets.setEnabled(getCampaign().isGM());
    pnlFinanceBtns.add(btnManageAssets);

    panelFinanceRight.add(pnlFinanceBtns, BorderLayout.NORTH);

    areaNetWorth = new JTextArea();
    areaNetWorth.setLineWrap(true);
    areaNetWorth.setWrapStyleWord(true);
    areaNetWorth.setFont(new Font("Courier New", Font.PLAIN, 12));
    areaNetWorth.setText(getCampaign().getFinancialReport());
    areaNetWorth.setEditable(false);

    JScrollPane descriptionScroll = new JScrollPane(areaNetWorth);
    panelFinanceRight.add(descriptionScroll, BorderLayout.CENTER);
    areaNetWorth.setCaretPosition(0);
    descriptionScroll.setMinimumSize(new Dimension(300, 200));

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.0;
    gridBagConstraints.weighty = 1.0;
    add(panelFinanceRight, gridBagConstraints);
}

From source file:com.apatar.webdav.ui.JWebDavTreeModePanel.java

private JTable createFolderTable() {
    tblModel = new DefaultTableModel();
    tblModel.addColumn("Folder List");

    folderTable = new JTable(tblModel);
    folderTable.setOpaque(false);/*from   w w  w  .  jav a 2s . c  o m*/
    folderTable.setBackground(null);
    folderTable.setBorder(null);
    folderTable.setShowGrid(false);

    folderTable.addKeyListener(new TableKeyListener());

    folderTable.getColumn("Folder List").setCellEditor(new CellTableEditor(new JTextField()));

    folderTable.setComponentPopupMenu(new JDefaultContextMenu(folderTable));

    return folderTable;
}

From source file:de.uka.aifb.com.systemDynamics.gui.ModelExecutionChartPanel.java

/**
 * Creates panel./*from w  w  w  . java2 s  .c  o  m*/
 */
private void createPanel() {
    setLayout(new BorderLayout());

    // CENTER: chart
    ChartPanel chartPanel = new ChartPanel(createChart());
    // no context menu
    chartPanel.setPopupMenu(null);
    // not zoomable
    chartPanel.setMouseZoomable(false);
    add(chartPanel, BorderLayout.CENTER);

    // LINE_END: series table
    JPanel tablePanel = new JPanel(new GridBagLayout());
    String[] columnNames = { messages.getString("ModelExecutionChartPanel.Table.ColumnNames.ExtraAxis"),
            messages.getString("ModelExecutionChartPanel.Table.ColumnNames.LevelNode") };
    final MyTableModel tableModel = new MyTableModel(columnNames, xySeriesArray.length);
    for (int i = 0; i < xySeriesArray.length; i++) {
        tableModel.addEntry((String) xySeriesArray[i].getKey());
    }
    JTable table = new JTable(tableModel);
    table.setRowSelectionAllowed(false);
    JScrollPane tableScrollPane = new JScrollPane(table);
    int width = (int) Math.min(300, table.getPreferredSize().getWidth());
    int height = (int) Math.min(200, table.getPreferredSize().getHeight());
    tableScrollPane.getViewport().setPreferredSize(new Dimension(width, height));
    tableScrollPane.setMaximumSize(tableScrollPane.getViewport().getPreferredSize());
    axesButton = new JButton(messages.getString("ModelExecutionChartPanel.AxesButton.Text"));
    axesButton.setToolTipText(messages.getString("ModelExecutionChartPanel.AxesButton.ToolTipText"));
    axesButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // create XYSeriesCollections (and renderer)
            XYSeriesCollection standardData = new XYSeriesCollection();
            XYLineAndShapeRenderer standardRenderer = new XYLineAndShapeRenderer(true, false);
            LinkedList<XYSeriesCollection> extraDataList = new LinkedList<XYSeriesCollection>();
            LinkedList<XYLineAndShapeRenderer> extraRendererList = new LinkedList<XYLineAndShapeRenderer>();
            for (int i = 0; i < tableModel.getRowCount(); i++) {
                if (tableModel.getValueAt(i, 0).equals(Boolean.FALSE)) {
                    standardData.addSeries(xySeriesArray[i]);
                    standardRenderer.setSeriesPaint(standardData.getSeriesCount() - 1,
                            DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i
                                    % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length]);
                } else {
                    // extra axis
                    XYSeriesCollection extraData = new XYSeriesCollection();
                    extraData.addSeries(xySeriesArray[i]);
                    extraDataList.add(extraData);
                    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
                    extraRendererList.add(renderer);
                    renderer.setSeriesPaint(0, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i
                            % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length]);
                }
            }
            LinkedList<XYSeriesCollection> dataList = new LinkedList<XYSeriesCollection>();
            LinkedList<XYLineAndShapeRenderer> rendererList = new LinkedList<XYLineAndShapeRenderer>();
            if (!standardData.getSeries().isEmpty()) {
                dataList.add(standardData);
                rendererList.add(standardRenderer);
            }
            for (XYSeriesCollection data : extraDataList) {
                dataList.add(data);
            }
            for (XYLineAndShapeRenderer renderer : extraRendererList) {
                rendererList.add(renderer);
            }

            // creates axes
            LinkedList<NumberAxis> axesList = new LinkedList<NumberAxis>();
            if (!standardData.getSeries().isEmpty()) {
                NumberAxis axis = new NumberAxis(messages.getString("ModelExecutionChartPanel.Value"));
                axis.setNumberFormatOverride(NumberFormat.getInstance(locale));
                axesList.add(axis);
            }
            for (XYSeriesCollection data : extraDataList) {
                NumberAxis axis = new NumberAxis((String) data.getSeries(0).getKey());
                axis.setNumberFormatOverride(NumberFormat.getInstance(locale));
                axesList.add(axis);
            }

            // store data and axes in plot
            XYPlot plot = chart.getXYPlot();
            plot.clearRangeAxes();
            plot.setRangeAxes(axesList.toArray(new NumberAxis[0]));
            for (int i = 0; i < plot.getDatasetCount(); i++) {
                plot.setDataset(i, null);
            }
            int datasetIndex = 0;
            Iterator<XYSeriesCollection> datasetIterator = dataList.iterator();
            Iterator<XYLineAndShapeRenderer> rendererIterator = rendererList.iterator();
            while (datasetIterator.hasNext()) {
                plot.setDataset(datasetIndex, datasetIterator.next());
                plot.setRenderer(datasetIndex, rendererIterator.next());
                datasetIndex++;
            }
            for (int i = 0; i < plot.getDatasetCount(); i++) {
                plot.mapDatasetToRangeAxis(i, i);
            }
        }
    });
    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.CENTER;
    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(0, 0, 10, 0);
    tablePanel.add(tableScrollPane, c);
    c.gridx = 0;
    c.gridy = 1;
    tablePanel.add(axesButton, c);
    add(tablePanel, BorderLayout.LINE_END);

    // PAGE_END: number of rounds and execution button
    JPanel commandPanel = new JPanel();
    commandPanel.add(new JLabel(messages.getString("ModelExecutionChartPanel.NumberRounds")));
    final JTextField numberRoundsField = new JTextField("1", 5);
    numberRoundsField.addFocusListener(this);
    commandPanel.add(numberRoundsField);
    executionButton = new JButton(messages.getString("ModelExecutionChartPanel.ExecutionButton.Text"));
    executionButton.setToolTipText(messages.getString("ModelExecutionChartPanel.ExecutionButton.ToolTipText"));
    executionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int numberRounds = 0;
            boolean correctNumber = false;
            try {
                numberRounds = integerNumberFormatter.parse(numberRoundsField.getText()).intValue();
            } catch (ParseException parseExcep) {
                // do nothing
            }

            if (numberRounds >= 1) {
                correctNumber = true;
            }

            if (correctNumber) {
                ModelExecutionThread executionThread = new ModelExecutionThread(numberRounds);
                executionThread.start();
            } else {
                JOptionPane.showMessageDialog(null,
                        messages.getString("ModelExecutionChartPanel.Error.Message"),
                        messages.getString("ModelExecutionChartPanel.Error.Title"), JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    commandPanel.add(executionButton);
    add(commandPanel, BorderLayout.PAGE_END);
}

From source file:eu.apenet.dpt.standalone.gui.dateconversion.DateConversionRulesDialog.java

private void createDataConversionRulesList() {
    Vector<String> columnNames = new Vector<String>();
    columnNames.add(labels.getString("dateConversion.valueRead"));
    columnNames.add(labels.getString("dateConversion.valueConverted"));
    dm = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);
    dm.addRow(new Vector<String>());
    dm.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            if (ruleTable.getEditingRow() != ruleTable.getRowCount() - 1
                    && (StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                            && StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1)))) {
                dm.removeRow(ruleTable.getEditingRow());
            }/* www .  ja  v  a  2 s  . co  m*/
            if (ruleTable.getEditingRow() == ruleTable.getRowCount() - 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                        && StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    dm.addRow(new Vector<String>());
                }
            }
            if (ruleTable.getEditingColumn() == 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))
                        && !isCorrectDateFormat((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    createOptionPaneForIsoDate(ruleTable.getEditingRow(), 1);
                }
            }
        }
    });

    ruleTable = new JTable(dm);
    oldModel = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);

    JButton saveButton = new JButton(labels.getString("saveBtn"));
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            for (int i = 0; i < data.size() - 1; i++) {
                Vector<String> vector = data.elementAt(i);
                if (vector.elementAt(1) != null && !isCorrectDateFormat((String) vector.elementAt(1))) {
                    createOptionPaneForIsoDate(i, 1);
                }
            }
            xmlFilehandler.saveDataToFile(data, FILENAME);
            saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                    new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
        }
    });

    JButton closeButton = new JButton(labels.getString("quit"));
    closeButton.addActionListener(new ActionListener() {
        // boolean cancel = true;

        public void actionPerformed(ActionEvent e) {
            /*System.out.println(Boolean.toString(oldModel.getRowCount() == (ruleTable.getModel().getRowCount() - 1)) + "<<" + oldModel.getRowCount() + ", " + (ruleTable.getModel().getRowCount() - 1));
            if (oldModel.getRowCount() != ruleTable.getModel().getRowCount() - 1) {
            cancel = showUnsavedChangesDialog();
            } else {
            for (int i = 0; i < (ruleTable.getModel().getRowCount() - 1); i++) {
                for (int j = 0; j <= 1; j++) {
                    System.out.println(oldModel.getValueAt(i, j) == ruleTable.getModel().getValueAt(i, j) + " >> " + oldModel.getValueAt(i, j) + ", " + ruleTable.getModel().getValueAt(i, j));
                    if (oldModel.getValueAt(i, j) != ruleTable.getModel().getValueAt(i, j)) {
                        cancel = showUnsavedChangesDialog();
                    }
                }
            }
            }
            if (cancel) {*/
            dispose();
            //  }
        }
    });

    JButton downloadButton = new JButton(labels.getString("downloadBtn"));
    downloadButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            File currentLocation = new File(retrieveFromDb.retrieveOpenLocation());
            JFileChooser fileChooser = new JFileChooser(currentLocation);
            fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
            fileChooser.setFileFilter(new FileNameExtensionFilter("XML file", "xml"));
            int returnedVal = fileChooser.showSaveDialog(getParent());

            if (returnedVal == JFileChooser.APPROVE_OPTION) {
                String fileName = fileChooser.getSelectedFile().toString();
                if (!fileName.endsWith(".xml")) {
                    fileName = fileName + ".xml";
                }
                xmlFilehandler.saveDataToFile(data, fileName);
                //additionally save data to standard file
                xmlFilehandler.saveDataToFile(data, FILENAME);
                saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                        new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
            }
        }
    });

    JPanel contentPanel = new JPanel(new BorderLayout());
    contentPanel.add(new JScrollPane(ruleTable));
    saveMessage = new JLabel();
    contentPanel.add(saveMessage, BorderLayout.SOUTH);

    JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
    buttonPanel.add(saveButton);
    buttonPanel.add(closeButton);
    buttonPanel.add(downloadButton);

    JPanel pane = new JPanel(new BorderLayout());
    pane.add(contentPanel, BorderLayout.PAGE_START);
    pane.add(buttonPanel, BorderLayout.PAGE_END);
    add(pane);
}

From source file:logdruid.ui.DateEditor.java

/**
 * Create the panel.//from   w w w .j  a  v  a 2  s .  co  m
 */
public DateEditor(Repository rep) {
    repository = rep;
    model = new MyTableModel2(data, header);

    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 15, 550, 15 };
    gridBagLayout.rowHeights = new int[] { 152, 300 };
    gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0 };
    gridBagLayout.rowWeights = new double[] { 0.0, 1.0 };
    setLayout(gridBagLayout);

    JPanel panel_1 = new JPanel();
    GridBagConstraints gbc_panel_1 = new GridBagConstraints();
    gbc_panel_1.fill = GridBagConstraints.BOTH;
    gbc_panel_1.insets = new Insets(5, 0, 5, 5);
    gbc_panel_1.gridx = 1;
    gbc_panel_1.gridy = 0;
    add(panel_1, gbc_panel_1);
    panel_1.setLayout(new BorderLayout(0, 0));

    table = new JTable(model);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setBorder(UIManager.getBorder("TextPane.border"));
    table.setPreferredScrollableViewportSize(new Dimension(0, 0));
    table.setFillsViewportHeight(true);

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

        public void valueChanged(ListSelectionEvent e) {
            // ((table.getSelectedRow()!=-1)?table.convertRowIndexToModel(table.getSelectedRow()):-1)
            // persist repository
            // display selected row

            if (((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                    : -1) >= 0) {
                /*
                 * recEditor = new RecordingEditor(repository
                 * .getRecordings().get(((table.getSelectedRow()!=-1)?table.
                 * convertRowIndexToModel(table.getSelectedRow()):-1)),
                 * repository); jPanelDetail.removeAll();
                 */
                // jPanelDetail.add(recEditor, gbc_jPanelDetail);
                DateFormat df = repository.getDateFormat(
                        ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                                : -1));
                if (df != null) {
                    textFieldName.setText((String) df.getName());
                    textFieldPattern.setText((String) df.getPattern());
                    textField.setText((String) df.getDateFormat());
                }
                // jPanelDetail.revalidate();
                // jPanelDetail.repaint();
                // jPanelDetail.setVisible(true);
                // reloadTable(); those 2 ********
                // jPanelDetail.revalidate();
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(table);
    panel_1.add(scrollPane, BorderLayout.CENTER);
    // Set up column sizes.
    initColumnSizes(table);

    JPanel panel = new JPanel();
    FlowLayout flowLayout = (FlowLayout) panel.getLayout();
    flowLayout.setAlignment(FlowLayout.LEFT);
    flowLayout.setVgap(2);
    flowLayout.setHgap(2);
    panel_1.add(panel, BorderLayout.SOUTH);

    JButton btnNew = new JButton("New");
    panel.add(btnNew);
    btnNew.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            DateFormat df = new DateFormat("name", "\\w{3}\\s[0-9]{1}/[0-9]{2}/[0-9]{2}\\s\\d\\d:\\d\\d:\\d\\d",
                    "EEE. MM/dd/yy HH:mm:ss");
            repository.addDateFormat(df);
            data.add(new Object[] { df.getName(), df.getPattern(), df.getDateFormat() });
            table.repaint();
        }
    });

    JButton btnDuplicate = new JButton("Duplicate");
    btnDuplicate.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                    : -1) >= 0) {
                DateFormat df = repository.getDateFormat(
                        ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                                : -1));
                repository.addDateFormat(df);
                reloadTable();
                // data.add(new Object[] { table.getRowCount()+1,
                // df.getName(),df.getDateFormat()});
                table.repaint();
            }
        }
    });
    panel.add(btnDuplicate);

    JButton btnDelete = new JButton("Delete");
    btnDelete.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int selectedRow = ((table.getSelectedRow() != -1)
                    ? table.convertRowIndexToModel(table.getSelectedRow())
                    : -1);
            if (selectedRow >= 0) {
                repository.deleteDateFormat(
                        ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                                : -1));
                data.remove(
                        ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                                : -1));
                reloadTable();
                table.setRowSelectionInterval(selectedRow, selectedRow);
                table.repaint();
            }
        }
    });
    panel.add(btnDelete);

    jPanelDetail = new JPanel();
    gbc_jPanelDetail = new GridBagConstraints();
    gbc_jPanelDetail.anchor = GridBagConstraints.NORTH;
    gbc_jPanelDetail.fill = GridBagConstraints.HORIZONTAL;
    gbc_jPanelDetail.gridx = 1;
    gbc_jPanelDetail.gridy = 1;
    add(jPanelDetail, gbc_jPanelDetail);
    GridBagLayout gbl_jPanelDetail = new GridBagLayout();
    gbl_jPanelDetail.columnWidths = new int[] { 169 };
    gbl_jPanelDetail.rowHeights = new int[] { 0, 0, 0, 0, 150, 0 };
    gbl_jPanelDetail.columnWeights = new double[] { 1.0, 0.0 };
    gbl_jPanelDetail.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, 1.0, 0.0 };
    jPanelDetail.setLayout(gbl_jPanelDetail);

    JPanel panel_2 = new JPanel();
    panel_2.setBorder(null);
    GridBagConstraints gbc_panel_2 = new GridBagConstraints();
    gbc_panel_2.gridwidth = 2;
    gbc_panel_2.anchor = GridBagConstraints.NORTHWEST;
    gbc_panel_2.insets = new Insets(0, 0, 5, 0);
    gbc_panel_2.gridx = 0;
    gbc_panel_2.gridy = 0;
    jPanelDetail.add(panel_2, gbc_panel_2);
    panel_2.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));

    JLabel label = new JLabel("Name");
    panel_2.add(label);

    textFieldName = new JTextField();
    textFieldName.setColumns(20);
    panel_2.add(textFieldName);

    JPanel panel_3 = new JPanel();
    FlowLayout flowLayout_1 = (FlowLayout) panel_3.getLayout();
    flowLayout_1.setAlignment(FlowLayout.LEFT);
    panel_3.setBorder(null);
    GridBagConstraints gbc_panel_3 = new GridBagConstraints();
    gbc_panel_3.insets = new Insets(0, 0, 5, 0);
    gbc_panel_3.gridwidth = 2;
    gbc_panel_3.anchor = GridBagConstraints.NORTHWEST;
    gbc_panel_3.gridx = 0;
    gbc_panel_3.gridy = 1;
    jPanelDetail.add(panel_3, gbc_panel_3);

    labelPattern = new JLabel("Pattern");
    panel_3.add(labelPattern);

    textFieldPattern = new JTextField();
    textFieldPattern.setColumns(40);
    panel_3.add(textFieldPattern);

    JButton btnSave = new JButton("Save");
    btnSave.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DateFormat df1 = repository.getDateFormat(
                    ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                            : -1));
            df1.update(textFieldName.getText(), textFieldPattern.getText(), textField.getText());
            reloadTable();
        }
    });

    JPanel panel_4 = new JPanel();
    FlowLayout flowLayout_2 = (FlowLayout) panel_4.getLayout();
    flowLayout_2.setAlignment(FlowLayout.LEFT);
    GridBagConstraints gbc_panel_4 = new GridBagConstraints();
    gbc_panel_4.anchor = GridBagConstraints.WEST;
    gbc_panel_4.insets = new Insets(0, 0, 5, 5);
    gbc_panel_4.gridx = 0;
    gbc_panel_4.gridy = 2;
    jPanelDetail.add(panel_4, gbc_panel_4);

    JLabel lblFastDateFormat = new JLabel("FastDateFormat");
    panel_4.add(lblFastDateFormat);

    textField = new JTextField();
    panel_4.add(textField);
    textField.setColumns(30);

    JPanel panel_5 = new JPanel();
    FlowLayout flowLayout_3 = (FlowLayout) panel_5.getLayout();
    flowLayout_3.setAlignment(FlowLayout.LEFT);
    GridBagConstraints gbc_panel_5 = new GridBagConstraints();
    gbc_panel_5.insets = new Insets(0, 0, 5, 5);
    gbc_panel_5.fill = GridBagConstraints.BOTH;
    gbc_panel_5.gridx = 0;
    gbc_panel_5.gridy = 3;
    jPanelDetail.add(panel_5, gbc_panel_5);

    JLabel lblSampleLabel = new JLabel("Sample");
    panel_5.add(lblSampleLabel);

    JPanel panel_6 = new JPanel();
    panel_6.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
    GridBagConstraints gbc_panel_6 = new GridBagConstraints();
    gbc_panel_6.ipady = 1;
    gbc_panel_6.ipadx = 1;
    gbc_panel_6.insets = new Insets(0, 0, 5, 5);
    gbc_panel_6.fill = GridBagConstraints.BOTH;
    gbc_panel_6.gridx = 0;
    gbc_panel_6.gridy = 4;
    jPanelDetail.add(panel_6, gbc_panel_6);
    panel_6.setLayout(new BorderLayout(0, 0));

    JTextPane textPane = new JTextPane();
    textPane.setBackground(UIManager.getColor("windowBorder"));
    panel_6.add(textPane);
    GridBagConstraints gbc_btnSave = new GridBagConstraints();
    gbc_btnSave.anchor = GridBagConstraints.WEST;
    gbc_btnSave.insets = new Insets(0, 0, 0, 5);
    gbc_btnSave.gridx = 0;
    gbc_btnSave.gridy = 5;
    jPanelDetail.add(btnSave, gbc_btnSave);
    reloadTable();
}