Search in sources :

Example 51 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project iris by mnit-rtmc.

the class TimeActionModel method createColumns.

/**
 * Create the columns in the model
 */
@Override
protected ArrayList<ProxyColumn<TimeAction>> createColumns() {
    ArrayList<ProxyColumn<TimeAction>> cols = new ArrayList<ProxyColumn<TimeAction>>(4);
    cols.add(new ProxyColumn<TimeAction>("action.plan.day", 100) {

        public Object getValueAt(TimeAction ta) {
            return ta.getDayPlan();
        }
    });
    cols.add(new ProxyColumn<TimeAction>("action.plan.date", 100) {

        public Object getValueAt(TimeAction ta) {
            return ta.getSchedDate();
        }
    });
    cols.add(new ProxyColumn<TimeAction>("action.plan.time", 80) {

        public Object getValueAt(TimeAction ta) {
            return ta.getTimeOfDay();
        }
    });
    cols.add(new ProxyColumn<TimeAction>("action.plan.phase", 100) {

        public Object getValueAt(TimeAction ta) {
            return ta.getPhase();
        }

        public boolean isEditable(TimeAction ta) {
            return canWrite(ta);
        }

        public void setValueAt(TimeAction ta, Object value) {
            if (value instanceof PlanPhase)
                ta.setPhase((PlanPhase) value);
        }

        protected TableCellEditor createCellEditor() {
            JComboBox<PlanPhase> cbx = new JComboBox<PlanPhase>();
            cbx.setModel(new IComboBoxModel<PlanPhase>(phase_mdl));
            return new DefaultCellEditor(cbx);
        }
    });
    return cols;
}
Also used : IComboBoxModel(us.mn.state.dot.tms.client.widget.IComboBoxModel) JComboBox(javax.swing.JComboBox) TimeAction(us.mn.state.dot.tms.TimeAction) ArrayList(java.util.ArrayList) PlanPhase(us.mn.state.dot.tms.PlanPhase) TableCellEditor(javax.swing.table.TableCellEditor) ProxyColumn(us.mn.state.dot.tms.client.proxy.ProxyColumn) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 52 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project iris by mnit-rtmc.

the class RoadModel method createColumns.

/**
 * Create the columns in the model
 */
@Override
protected ArrayList<ProxyColumn<Road>> createColumns() {
    ArrayList<ProxyColumn<Road>> cols = new ArrayList<ProxyColumn<Road>>(4);
    cols.add(new ProxyColumn<Road>("location.road", 200) {

        public Object getValueAt(Road r) {
            return r.getName();
        }
    });
    cols.add(new ProxyColumn<Road>("location.road.abbrev", 80) {

        public Object getValueAt(Road r) {
            return r.getAbbrev();
        }

        public boolean isEditable(Road r) {
            return canWrite(r);
        }

        public void setValueAt(Road r, Object value) {
            r.setAbbrev(value.toString());
        }
    });
    cols.add(new ProxyColumn<Road>("location.road.class", 120) {

        public Object getValueAt(Road r) {
            return RoadClass.fromOrdinal(r.getRClass());
        }

        public boolean isEditable(Road r) {
            return canWrite(r);
        }

        public void setValueAt(Road r, Object value) {
            if (value instanceof RoadClass) {
                RoadClass c = (RoadClass) value;
                r.setRClass((short) c.ordinal());
            }
        }

        protected TableCellEditor createCellEditor() {
            JComboBox<RoadClass> cbx = new JComboBox<RoadClass>(RoadClass.values());
            return new DefaultCellEditor(cbx);
        }
    });
    cols.add(new ProxyColumn<Road>("location.direction", 120) {

        public Object getValueAt(Road r) {
            return Direction.fromOrdinal(r.getDirection());
        }

        public boolean isEditable(Road r) {
            return canWrite(r);
        }

        public void setValueAt(Road r, Object value) {
            if (value instanceof Direction) {
                Direction d = (Direction) value;
                r.setDirection((short) d.ordinal());
            }
        }

        protected TableCellEditor createCellEditor() {
            JComboBox<Direction> cbx = new JComboBox<Direction>(Direction.values());
            return new DefaultCellEditor(cbx);
        }
    });
    return cols;
}
Also used : JComboBox(javax.swing.JComboBox) Road(us.mn.state.dot.tms.Road) ArrayList(java.util.ArrayList) RoadClass(us.mn.state.dot.tms.RoadClass) Direction(us.mn.state.dot.tms.Direction) DefaultCellEditor(javax.swing.DefaultCellEditor) TableCellEditor(javax.swing.table.TableCellEditor) ProxyColumn(us.mn.state.dot.tms.client.proxy.ProxyColumn)

Example 53 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project gdmatrix by gdmatrix.

the class SelectBoxEditor method initComponents.

private void initComponents() throws Exception {
    this.setLayout(gridBagLayout2);
    this.setMinimumSize(new Dimension(400, 340));
    this.setBorder(new EmptyBorder(10, 10, 10, 10));
    addButton.setText("Add");
    addButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            addButton_actionPerformed(e);
        }
    });
    insertButton.setText("Insert");
    insertButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            insertButton_actionPerformed(e);
        }
    });
    deleteButton.setText("Delete");
    deleteButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            deleteButton_actionPerformed(e);
        }
    });
    JTextPane sqlTextPane = sqlEditor.getTextPane();
    sqlTextPane.setEditorKitForContentType("text/sql", new SQLEditorKit());
    sqlTextPane.setContentType("text/sql");
    sqlTextPane.setSelectionColor(new Color(198, 198, 198));
    sqlTextPane.setFont(Options.getEditorFont());
    scrollPane.getViewport().add(optionsTable, null);
    scrollPane.setPreferredSize(new Dimension(400, 150));
    sqlEditor.setPreferredSize(new Dimension(300, 100));
    sqlEditor.setMinimumSize(new Dimension(300, 100));
    sqlEditor.setBorder(new LineBorder(Color.LIGHT_GRAY));
    SymbolHighlighter symbolHighlighter = new SymbolHighlighter(sqlEditor.getTextPane(), "({[", ")}]");
    datarefLabel.setText("Dataref:");
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    this.add(scrollPane, new GridBagConstraints(1, 2, 2, 3, 1.0, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(4, 4, 4, 4), 0, 0));
    this.add(addButton, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(insertButton, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(deleteButton, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(variableLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(variableTextField, new GridBagConstraints(1, 0, 1, 1, 0.4, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(sqlEditor, new GridBagConstraints(1, 7, 2, 1, 0.0, 0.5, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(4, 4, 4, 4), 0, 0));
    this.add(staticLabel, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(dynamicLabel, new GridBagConstraints(0, 5, 4, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(sqlLabel, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(connLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(connTextField, new GridBagConstraints(1, 6, 1, 1, 0.4, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(connInfoLabel, new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(usernameLabel, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(usernameTextField, new GridBagConstraints(1, 8, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(passwordLabel, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(passwordField, new GridBagConstraints(1, 9, 1, 1, 0.4, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(datarefLabel, new GridBagConstraints(0, 10, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    this.add(datarefTextField, new GridBagConstraints(1, 10, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
    optionsTable.setAutoCreateColumnsFromModel(false);
    tableModel.addColumn("Label");
    tableModel.addColumn("Value");
    optionsTable.setModel(tableModel);
    passwordLabel.setText("Password:");
    usernameLabel.setText("Username:");
    connLabel.setText("Connection:");
    connInfoLabel.setText("DSN or alias");
    sqlLabel.setText("SQL (id, label):");
    dynamicLabel.setText("Dynamic options:");
    staticLabel.setText("Static options:");
    variableLabel.setText("Variable:");
    JTextField editorTextField = new JTextField();
    editorTextField.setBorder(null);
    DefaultCellEditor editor = new DefaultCellEditor(editorTextField);
    editor.setClickCountToStart(2);
    optionsTable.addColumn(new TableColumn(0, 300, null, editor));
    optionsTable.addColumn(new TableColumn(1, 100, null, editor));
    optionsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    optionsTable.getTableHeader().setReorderingAllowed(false);
}
Also used : SQLEditorKit(org.santfeliu.swing.text.SQLEditorKit) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) ActionEvent(java.awt.event.ActionEvent) Color(java.awt.Color) LineBorder(javax.swing.border.LineBorder) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor) JTextPane(javax.swing.JTextPane) SymbolHighlighter(org.santfeliu.swing.text.SymbolHighlighter) ActionListener(java.awt.event.ActionListener) EmptyBorder(javax.swing.border.EmptyBorder)

Example 54 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project knetbuilder by Rothamsted.

the class TabularExporter method initGUI.

/**
 * Puts mainly the configuration table together
 */
private void initGUI() {
    // dispose viewer on close
    this.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
    JPanel mainPanel = new JPanel(new SpringLayout());
    // empty table to start with (one empty row)
    configurationTableModel = new MyDefaultTableModel(columnNames, 0);
    // table to define export configuration
    configurationTable = new JTable(configurationTableModel);
    // add input checking to Integer values
    configurationTable.getColumnModel().getColumn(0).setCellEditor(new IntegerEditor(1, 100));
    // add ComboBox for ONDEX entity types
    TableColumn entityColumn = configurationTable.getColumnModel().getColumn(1);
    JComboBox entityTypes = getEntityTypeComboBox();
    entityColumn.setCellEditor(new DefaultCellEditor(entityTypes));
    // set concept choices ComboBox as editor for value selection
    TableColumn valueColumn = configurationTable.getColumnModel().getColumn(2);
    valueColumn.setCellEditor(new DefaultCellEditor(conceptChoices));
    // add first line to table
    addNewTableRow();
    // add listener for user selections
    configurationTableModel.addTableModelListener(this);
    // display configuration table in a scroll pane
    mainPanel.add(new JScrollPane(configurationTable));
    // button to add new row to table
    JButton addRow = new JButton("Add new row");
    addRow.addActionListener(this);
    addRow.setActionCommand(ADD);
    mainPanel.add(addRow);
    // button to add remove last row
    JButton removeRow = new JButton("Remove last row");
    removeRow.addActionListener(this);
    removeRow.setActionCommand(REMOVE);
    mainPanel.add(removeRow);
    // GO button to start processing
    JButton exportGo = new JButton("Export");
    exportGo.addActionListener(this);
    exportGo.setActionCommand(GO);
    mainPanel.add(exportGo);
    SpringUtilities.makeCompactGrid(mainPanel, mainPanel.getComponentCount(), 1, 5, 5, 5, 5);
    // set layout
    this.getContentPane().setLayout(new GridLayout(1, 1));
    this.getContentPane().add(mainPanel);
    this.pack();
    // add to desktop
    OVTK2Desktop.getInstance().getDesktopPane().add(this);
    this.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) JComboBox(javax.swing.JComboBox) JTable(javax.swing.JTable) SpringLayout(javax.swing.SpringLayout) IntegerEditor(net.sourceforge.ondex.ovtk2.util.IntegerEditor) JButton(javax.swing.JButton) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 55 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project knetbuilder by Rothamsted.

the class DialogConceptLabel method getSettings.

/**
 * Load possible label settings from annotations
 */
private void getSettings() {
    Map<String, String> annotations = this.viewer.getONDEXJUNGGraph().getAnnotations();
    if (annotations != null && annotations.containsKey(KEY)) {
        // get settings from graph
        String xml = annotations.get(KEY);
        if (xml == null || xml.trim().length() == 0)
            return;
        // configure XML input
        System.setProperty("ondex.javax.xml.stream.XMLInputFactory", "com.ctc.wstx.stax.WstxInputFactory");
        XMLInputFactory2 xmlInput = (XMLInputFactory2) XMLInputFactory2.newFactory("ondex.javax.xml.stream.XMLInputFactory", this.getClass().getClassLoader());
        xmlInput.configureForSpeed();
        // parse from a String
        final ByteArrayInputStream inStream = new ByteArrayInputStream(xml.getBytes());
        try {
            // configure Parser
            XMLStreamReader2 xmlReadStream = (XMLStreamReader2) xmlInput.createXMLStreamReader(inStream, CharsetNames.CS_UTF8);
            // de-serialise annotations from XML
            ConceptLabelXMLReader.read(xmlReadStream, this);
            xmlReadStream.close();
        } catch (XMLStreamException e1) {
            ErrorDialog.show(e1);
        }
        // editors used for meta data selection etc.
        JComboBox accessionDataSources = populateAccessionDataSources();
        JComboBox filterDataSources = populateFilterDataSources();
        JComboBox filterConceptClasses = populatFilterConceptClasses();
        JComboBox separator = populateSeparator();
        // set data source editor
        TableColumn dataSourceColumn = table.getColumnModel().getColumn(0);
        dataSourceColumn.setCellEditor(new DefaultCellEditor(filterDataSources));
        // set concept class editor
        TableColumn conceptClassColumn = table.getColumnModel().getColumn(1);
        conceptClassColumn.setCellEditor(new DefaultCellEditor(filterConceptClasses));
        // set accession editor
        TableColumn accessionColumn = table.getColumnModel().getColumn(2);
        accessionColumn.setCellEditor(new DefaultCellEditor(accessionDataSources));
        // set separator editor
        TableColumn separatorColumn = table.getColumnModel().getColumn(3);
        separatorColumn.setCellEditor(new DefaultCellEditor(separator));
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) JComboBox(javax.swing.JComboBox) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLInputFactory2(org.codehaus.stax2.XMLInputFactory2) XMLStreamReader2(org.codehaus.stax2.XMLStreamReader2) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor)

Aggregations

DefaultCellEditor (javax.swing.DefaultCellEditor)169 JComboBox (javax.swing.JComboBox)105 TableColumn (javax.swing.table.TableColumn)57 JTable (javax.swing.JTable)53 ArrayList (java.util.ArrayList)43 TableCellEditor (javax.swing.table.TableCellEditor)35 JScrollPane (javax.swing.JScrollPane)33 JPanel (javax.swing.JPanel)25 ActionEvent (java.awt.event.ActionEvent)24 ProxyColumn (us.mn.state.dot.tms.client.proxy.ProxyColumn)23 JTextField (javax.swing.JTextField)22 JLabel (javax.swing.JLabel)20 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)20 Component (java.awt.Component)18 DefaultTableModel (javax.swing.table.DefaultTableModel)17 Dimension (java.awt.Dimension)16 JButton (javax.swing.JButton)16 ActionListener (java.awt.event.ActionListener)15 JCheckBox (javax.swing.JCheckBox)13 TableColumnModel (javax.swing.table.TableColumnModel)13