Example usage for javax.swing.event TableModelEvent getSource

List of usage examples for javax.swing.event TableModelEvent getSource

Introduction

In this page you can find the example usage for javax.swing.event TableModelEvent getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:gui.accessories.BattleSimFx.java

private BarChart createBarChart() {
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);//from   w  w  w .j av  a  2 s  . c om
    yAxis.setLabel("Units Sold");

    final BarChart aChart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    tableModel.addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) aChart.getData()
                                .get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return aChart;
}

From source file:gui.accessories.GraphPopup.java

private BarChart createBarChartDynamic() {
    SampleTableModel tableModel = new SampleTableModel();
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);//from   w  w  w.  jav a2 s  .  com
    yAxis.setLabel("Units Sold");

    final BarChart aChart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    aChart.setAnimated(true);
    tableModel.addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) aChart.getData()
                                .get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return aChart;
}

From source file:SampleTableModel.java

private BarChart createBarChart() {
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);//from www.j  av  a 2s  .c o m
    yAxis.setLabel("Units Sold");

    final BarChart chart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    tableModel.addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) chart.getData()
                                .get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return chart;
}

From source file:MainFrame.MainFrame.java

public MainFrame() {
    //Create menu
    this.menuBar = new JMenuBar();
    this.menuProxy = new JMenu("Proxy");
    this.menuBar.add(menuProxy);
    this.cbMenuItem = new JCheckBoxMenuItem("? proxy");
    this.cbMenuItem.setMnemonic(KeyEvent.VK_C);

    ActionListener aListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            AbstractButton aButton = (AbstractButton) event.getSource();
            boolean selected = aButton.getModel().isSelected();
            if (selected) {
                SingleDataHolder.getInstance().isProxyActivated = true;
                SingleDataHolder.getInstance().proxyIpAdress = MainFrame.this.proxyIpAdress.getText();
                SingleDataHolder.getInstance().proxyPort = Integer.parseInt(MainFrame.this.proxyPort.getText());
                SingleDataHolder.getInstance().proxyLogin = MainFrame.this.proxyLogin.getText();
                SingleDataHolder.getInstance().proxyPassword = String
                        .valueOf(MainFrame.this.proxyPassword.getPassword());
            } else {
                SingleDataHolder.getInstance().isProxyActivated = false;
            }/*ww w  . j a  v  a  2 s  . co m*/
        }
    };
    this.cbMenuItem.addActionListener(aListener);

    this.proxyIpAdress = new JTextField();
    this.proxyPort = new JTextField();
    this.proxyLogin = new JTextField();
    ;
    this.proxyPassword = new JPasswordField();
    this.menuProxy.add(this.cbMenuItem);
    this.menuProxy.add(new JLabel("IP ?"));
    this.menuProxy.add(this.proxyIpAdress);
    this.menuProxy.add(new JLabel("? "));
    this.menuProxy.add(this.proxyPort);
    this.menuProxy.add(new JLabel(""));
    this.menuProxy.add(this.proxyLogin);
    this.menuProxy.add(new JLabel(""));
    this.menuProxy.add(this.proxyPassword);
    this.setJMenuBar(this.menuBar);

    communicator = new HttpCommunicator();
    myActionListener = new mainFrameActionListener();
    mainPanel = new JPanel(new BorderLayout());
    this.setContentPane(mainPanel);

    JPanel P = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 5));
    mainPanel.add(P, BorderLayout.NORTH);

    //Create Group label
    labelGroup = new JLabel("");
    P.add(labelGroup);
    //Create Group combo
    comboGroup = new JComboBox();
    comboGroup.addItem("?");
    comboGroup.addActionListener(myActionListener);
    P.add(comboGroup);

    //Create Date label
    labelDate = new JLabel("");
    P.add(labelDate);
    //Create Date combo
    comboDate = new JComboBox();
    comboDate.addItem("?");
    comboDate.addActionListener(myActionListener);
    P.add(comboDate);

    //Create Delete button
    buttonDelete = new JButton("");
    buttonDelete.setEnabled(false);
    buttonDelete.addActionListener(myActionListener);
    P.add(buttonDelete);

    //this.checkConnection = new CheckConnection(buttonDelete);

    buttonPasswordsManager = new JButton(" ");
    buttonPasswordsManager.addActionListener(myActionListener);
    P.add(buttonPasswordsManager);

    try {
        Image img = ImageIO.read(getClass().getResource("resources/table_refresh.png"));
        this.buttonRefresh = new JButton(new ImageIcon(img));
        this.buttonRefresh.addActionListener(myActionListener);
        this.buttonRefresh.setToolTipText(" ");
        P.add(buttonRefresh);
    } catch (IOException ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

    //CreateLessonTableModel
    lessonTableModel = new LessonTableModel();

    try {
        communicator.setCombos(comboGroup, comboDate, lessonTableModel);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, " ? ? .");
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

    //CreateTable
    table = new JTable(lessonTableModel);
    table.setFillsViewportHeight(true);
    table.setAutoCreateRowSorter(true);

    JScrollPane scrollP = new JScrollPane(table);
    mainPanel.add(scrollP, BorderLayout.CENTER);
    //Create Table sorter
    sorter = new TableRowSorter<LessonTableModel>(lessonTableModel);
    table.setRowSorter(sorter);
    table.getModel().addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            int row = e.getFirstRow();
            int column = e.getColumn();
            TableModel model = (TableModel) e.getSource();
            for (int i = 0; i < model.getRowCount(); i++) {
                if ((boolean) model.getValueAt(i, 2) == true) {
                    buttonDelete.setEnabled(true);
                    return;
                }
            }
            buttonDelete.setEnabled(false);
        }
    });

    //Standart block
    this.setSize(700, 400);
    this.setTitle(" ");
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent we) {
            System.exit(0);
        }
    });
    try {
        Image img = ImageIO.read(getClass().getResource("resources/appIcon.png"));
        this.setIconImage(img);
    } catch (IOException ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

    this.setVisible(true);
}

From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatMultiplePanel.java

/**
 * @param model/*  w  w w .ja  v a  2  s .co  m*/
 */
protected void addTableModelListener(DefaultTableModel model) {
    TableModelListener tml = new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            int row = e.getFirstRow();
            int column = e.getColumn();
            DefaultTableModel localModel = (DefaultTableModel) e.getSource();
            String columnName = localModel.getColumnName(column);

            if (columnName.equals(FIELD_VALUE_COL)) {
                int formatColumn = formatSwitchTbl.getColumnModel().getColumnIndex(DISPLAY_FORMAT_COL);
                DataObjDataFieldFormat format = (DataObjDataFieldFormat) localModel.getValueAt(row,
                        formatColumn);
                String value = (String) localModel.getValueAt(row, column);
                format.setValue(value);
                enableUIControls();
            }
        }
    };
    model.addTableModelListener(tml);
}

From source file:com.github.dougkelly88.FLIMPlateReaderGUI.SequencingClasses.GUIComponents.XYSequencing.java

private void setControlDefaults() {

    pmdp_ = new PlateMapDrawPanel(this);
    sap_ = SeqAcqProps.getInstance();/* www  . j a  v  a2 s. c  o  m*/
    plateMapBasePanel.setLayout(new BorderLayout());
    plateMapBasePanel.add(pmdp_, BorderLayout.CENTER);

    tableModel_ = new FOVTableModel(pp_);
    searchFOVtableModel_ = new FOVTableModel(pp_); //Not sure if this is the best way, but try it for now.
    tableModel_.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {

        }
    });

    fovTable_ = new JTable();
    fovTable_.setModel(tableModel_);
    fovTable_.setSurrendersFocusOnKeystroke(true);
    fovTable_.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

    JScrollPane scroller = new javax.swing.JScrollPane(fovTable_);
    fovTable_.setPreferredScrollableViewportSize(new java.awt.Dimension(190, 130));
    fovTablePanel.setLayout(new BorderLayout());
    fovTablePanel.add(scroller, BorderLayout.CENTER);

    final JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem deleteItem = new JMenuItem("Delete FOV");
    deleteItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int r = fovTable_.getSelectedRow();
            tableModel_.removeRow(r);
        }
    });
    JMenuItem addItem = new JMenuItem("Add FOV");
    addItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int r = fovTable_.getSelectedRow();
            tableModel_.insertRow(r, new FOV("A1", pp_, 6000));
        }
    });
    JMenuItem goToFOVItem = new JMenuItem("Go to FOV");
    goToFOVItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int r = fovTable_.getSelectedRow();
            //                FOV fov = tableModel_.getData().get(r);
            xyzmi_.gotoFOV(tableModel_.getData().get(r));
            if (!zAsOffset_) {
                double zval = tableModel_.getData().get(r).getZ();
                xyzmi_.moveZAbsolute(zval);
            } else {
                // obviously, this isn't quite right - we want to get
                // the offset of the CURRENT FOV (perhaps from parent in 
                // later implementations?) and subtract from that of the 
                // NEWLY SELECTED FOV. 
                // TODO: fix for proper zAsOffset behaviour. 
                // Wait for move completion
                while (xyzmi_.isStageBusy()) {
                    System.out.println("Stage moving...");
                }
                ;

                if (parent_.checkifAFenabled()) {
                    // If we have gone to the FOV, and have AF, do AF
                    xyzmi_.customAutofocus(parent_.getAFOffset());
                } else {
                    // If we don't have AF, go to the 'good offset position'
                    xyzmi_.moveZAbsolute(parent_.getFixedAFDefault());
                }
                //Now do the relative shift
                xyzmi_.moveZRelative(tableModel_.getData().get(r).getZ());
                System.out.println("Z value" + tableModel_.getData().get(r).getZ());
            }
        }
    });

    popupMenu.add(addItem);
    popupMenu.add(deleteItem);
    popupMenu.add(goToFOVItem);

    fovTable_.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            //                System.out.println("pressed");
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                JTable source = (JTable) e.getSource();
                int row = source.rowAtPoint(e.getPoint());
                int column = source.columnAtPoint(e.getPoint());

                if (!source.isRowSelected(row)) {
                    source.changeSelection(row, column, false, false);
                }
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    //        fovTable_.setDefaultRenderer(FOV.class, new TableRenderer());
    setupInsertComboBox();
}

From source file:org.hibernate.search.demo.SearchDemo.java

private void initWidgets() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setDefaultLookAndFeelDecorated(true);

    BorderLayout borderLayout = new BorderLayout();
    getContentPane().setLayout(borderLayout);

    // the main table
    model = new DefaultTableModel(headers, 0) {
        public boolean isCellEditable(int row, int column) {
            // at the moment only allows the editing of the title
            return column == 2;
        }//from  w  w  w  . j a  v  a 2 s  .c om
    };
    modelListener = new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            int row = e.getFirstRow();
            int column = e.getColumn();
            TableModel model = (TableModel) e.getSource();
            Object data = model.getValueAt(row, column);
            EntityManager em = emf.createEntityManager();
            updateTitle((Long) model.getValueAt(row, 0), (String) data);
            log.info("new value: {}", data);
        }
    };
    model.addTableModelListener(modelListener);
    final JTable table = new JTable(model);

    table.setFont(new Font("Courier New", Font.PLAIN, 14));
    getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);

    // build  the controls
    JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new FlowLayout());

    final JTextField searchField = new JTextField(30);
    controlPanel.add(searchField);

    JButton searchButton = new JButton("Search");
    searchButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            List<Product> products;

            try {
                products = search(searchField.getText());
            } catch (ParseException pe) {
                JOptionPane.showMessageDialog(null, pe.getMessage(), "alert", JOptionPane.ERROR_MESSAGE);
                return;
            }

            DefaultTableModel model = (DefaultTableModel) table.getModel();
            model.removeTableModelListener(modelListener);
            model.setRowCount(0);
            for (int i = 0; i < products.size(); i++) {
                Object[] data = new Object[headers.length];
                Product p = products.get(i);
                data[0] = p.getProductId();
                data[1] = p.getASIN();
                data[2] = p.getTitle();
                //data[3] = p.getDescription();
                String actors = "";
                for (Actor actor : p.getActors()) {
                    actors = actors + actor.getName() + ", ";
                }
                data[3] = actors.length() == 0 ? actors : actors.substring(0, actors.length() - 2);
                String categories = "";
                for (Category category : p.getCategories()) {
                    categories = categories + category.getName() + ", ";
                }
                data[4] = categories.length() == 0 ? categories
                        : categories.substring(0, categories.length() - 2);
                model.insertRow(i, data);
            }
            model.addTableModelListener(modelListener);
        }
    });
    controlPanel.add(searchButton);

    JButton indexButton = new JButton("Index");
    indexButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            index();
        }
    });
    controlPanel.add(indexButton);

    JButton purgeButton = new JButton("Purge");
    purgeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            purge();
        }
    });
    controlPanel.add(purgeButton);

    getContentPane().add(controlPanel, BorderLayout.NORTH);
    getRootPane().setDefaultButton(searchButton);

    setSize(800, 200);
    setVisible(true);
}

From source file:org.quackbot.gui.InfoPlugins.java

public InfoPlugins(final Controller controller) {
    super();/*from w w w .  j  av  a2 s  . c o m*/
    setBorder(BorderFactory.createTitledBorder("Active plugins"));

    //Configure the table model
    pluginTableModel = new DefaultTableModel() {
        @Override
        public Class getColumnClass(int c) {
            return getValueAt(0, c).getClass();
        }
    };
    pluginTableModel.addColumn("Name");
    pluginTableModel.addColumn("Type");
    pluginTableModel.addColumn("Enabled");
    pluginTableModel.addColumn("Admin Only");
    pluginTableModel.addColumn("Required");
    pluginTableModel.addColumn("Optional");
    pluginTableModel.addColumn("Help");

    //Toggle command enabled status when changed on the table
    pluginTableModel.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getType() != TableModelEvent.UPDATE)
                return;
            TableModel model = ((TableModel) e.getSource());
            String plugin = StringUtils
                    .trimToNull((String) ((TableModel) e.getSource()).getValueAt(e.getFirstRow(), 0));
            Command command = controller.getHookManager().getCommand(plugin);
            if (command != null) {
                command.setEnabled((Boolean) model.getValueAt(e.getFirstRow(), 1));
                log.debug((command.isEnabled() ? "Enabled" : "Disabled") + " command " + command.getName());
            }
        }
    });

    //Configure the table
    pluginTable = new JTable(pluginTableModel) {
        @Override
        public String getToolTipText(MouseEvent e) {
            Point p = e.getPoint();
            int rowIndex = pluginTable.rowAtPoint(p);
            int colIndex = pluginTable.columnAtPoint(p);
            if ((colIndex == 0 || colIndex == 5 || colIndex == 6) && getValueAt(rowIndex, colIndex) != null)
                return getValueAt(rowIndex, colIndex).toString();
            return "";
        }
    };
    pluginTable.setRowSelectionAllowed(false);
    pluginTable.setColumnSelectionAllowed(false);
    pluginTable.setCellSelectionEnabled(false);
    pluginTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    //Configure the default column widths
    TableColumnModel columnModel = pluginTable.getColumnModel();
    columnModel.getColumn(0).setPreferredWidth(120);
    columnModel.getColumn(1).setPreferredWidth(50);
    columnModel.getColumn(2).setPreferredWidth(75);
    columnModel.getColumn(3).setPreferredWidth(50);
    columnModel.getColumn(4).setPreferredWidth(40);
    columnModel.getColumn(5).setPreferredWidth(520);

    //Add the table to the scroll pane
    add(pluginTable);

    //Get notified of hook changes
    controller.getHookManager().addHook(new QListener("QBGuiPluginPanel") {
        @Override
        public void onHookLoad(HookLoadEvent event) {
            //TODO: Inform user about exception
            if (event.getException() != null)
                return;
            QListener hook = event.getHook();
            if (hook instanceof Command) {
                Command command = (Command) hook;
                pluginTableModel.addRow(
                        new Object[] { command.getName(), "Command", command.isEnabled(), command.isAdmin(),
                                command.getRequiredParams(), command.getOptionalParams(), command.getHelp() });
            } else {
                pluginTableModel.addRow(new Object[] { hook.getName(), "Hook", null, null, null, null, null });
            }
        }

        @Override
        public void onHookLoadStart(HookLoadStartEvent event) {
            pluginTableModel.setRowCount(0);
        }
    });
}