public MainPanel() { super(new BorderLayout()); InputMap im = table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); KeyStroke stab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK); KeyStroke senter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK); im.put(tab, im.get(enter)); im.put(stab, im.get(senter)); final Color orgColor = table.getSelectionBackground(); final Color tflColor = this.getBackground(); table.addFocusListener( new FocusListener() { @Override public void focusGained(FocusEvent e) { table.setSelectionForeground(Color.WHITE); table.setSelectionBackground(orgColor); } @Override public void focusLost(FocusEvent e) { table.setSelectionForeground(Color.BLACK); table.setSelectionBackground(tflColor); } }); table.setComponentPopupMenu(new TablePopupMenu()); add(new JScrollPane(table)); setPreferredSize(new Dimension(320, 240)); }
private static JTable createUITable( boolean keyColumnResizable, int typeWidth, Type type, List<String> lst, Actions editAction) { String[] keys = lst.toArray(new String[lst.size()]); Arrays.sort(keys); TableModel mdl = type == null ? new UITableModel(keys) : new UITypeTableModel(keys, type, true); JTable table = new UITable(mdl, null); table.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowHeight(25); TableColumnModel columns = table.getColumnModel(); int keyWidth = TABLE_WIDTH - typeWidth - VALUE_WIDTH - DEFAULT_WIDTH; columns.getColumn(UITableModel.KEY_COLUMN_INDEX).setMinWidth(keyWidth); columns.getColumn(UITableModel.KEY_COLUMN_INDEX).setPreferredWidth(keyWidth); columns.getColumn(UITableModel.KEY_COLUMN_INDEX).setResizable(keyColumnResizable); Creator.setWidth(columns.getColumn(UITableModel.TYPE_COLUMN_INDEX), typeWidth); TableColumn column = columns.getColumn(UITableModel.VALUE_COLUMN_INDEX); Creator.setWidth(column, VALUE_WIDTH); column.setCellRenderer(new UIDefaultsRenderer()); column.setCellEditor(new UIDefaultsEditor()); Creator.setWidth(columns.getColumn(UITableModel.DEFAULT_COLUMN_INDEX), DEFAULT_WIDTH); table.setAutoCreateRowSorter(true); DefaultRowSorter<?, ?> sorter = (DefaultRowSorter<?, ?>) table.getRowSorter(); sorter.setSortable(UITableModel.VALUE_COLUMN_INDEX, false); table .getInputMap(JComponent.WHEN_FOCUSED) .put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0), editAction); table.getActionMap().put(editAction, editAction); return table; }
/* * Assign ENTER and ESCAPE keystrokes to be equivalent to OK and Cancel buttons, respectively. */ @SuppressWarnings("serial") protected void setupKeys() { // Get the InputMap and ActionMap of the RootPane of this JDialog. JRootPane rootPane = this.getRootPane(); InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = rootPane.getActionMap(); // Setup ENTER key. inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); actionMap.put( "enter", new AbstractAction() { public void actionPerformed(ActionEvent e) { okChosen(); } }); // Setup ESCAPE key. inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape"); actionMap.put( "escape", new AbstractAction() { public void actionPerformed(ActionEvent e) { cancelChosen(); } }); // Stop table_ from consuming the ENTER keystroke and preventing it from being received by this // (JDialog). table_ .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "none"); }
/** * This method updates the input and action maps with a new ColumnAction. * * @param isSelectedColumn * @param isAdjust * @param key * @param keyStroke */ private void installColumnAction( boolean isSelectedColumn, boolean isAdjust, String key, String keyStroke) { Action action = new ColumnAction(isSelectedColumn, isAdjust); KeyStroke ks = KeyStroke.getKeyStroke(keyStroke); table.getInputMap().put(ks, key); table.getActionMap().put(key, action); }
/** * This method updates the input and action maps with new ToggleAction. * * @param isToggleDynamic * @param isToggleLarger * @param key * @param keyStroke */ private void installToggleAction( boolean isToggleDynamic, boolean isToggleLarger, String key, String keyStroke) { Action action = new ToggleAction(isToggleDynamic, isToggleLarger); KeyStroke ks = KeyStroke.getKeyStroke(keyStroke); table.getInputMap().put(ks, key); table.getActionMap().put(key, action); }
/** Create the panel */ public LabelsPage(Preferences prefs) { super(); title_ = "Define position labels for state devices"; helpText_ = "State devices with discrete positions, such as filter changers or objective turrets, etc. can have mnemonic labels assigned for each position.\n\n" + "Select the device in the left-hand list and edit corresponding position labels in the right-hand list.\n\n" + "Use the 'Read' button to read label info from the hardware. This will override your changes!\n\n"; setHelpFileName("conf_labels_page.html"); prefs_ = prefs; setLayout(null); final JScrollPane labelsScrollPane = new JScrollPane(); labelsScrollPane.setBounds(186, 10, 269, 254); add(labelsScrollPane); labelTable_ = new JTable(); labelTable_.setModel(new LabelTableModel()); labelTable_.setAutoCreateColumnsFromModel(false); labelTable_.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); InputMap im = labelTable_.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "none"); labelsScrollPane.setViewportView(labelTable_); GUIUtils.setClickCountToStartEditing(labelTable_, 1); GUIUtils.stopEditingOnLosingFocus(labelTable_); final JScrollPane devScrollPane = new JScrollPane(); devScrollPane.setBounds(10, 10, 162, 255); add(devScrollPane); devTable_ = new JTable(); DevTableModel m = new DevTableModel(); devTable_.setModel(m); devTable_.getSelectionModel().addListSelectionListener(new SelectionListener(devTable_)); devTable_.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); devScrollPane.setViewportView(devTable_); final JButton readButton = new JButton(); readButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { // read labels from hardware readFromHardware(); } }); readButton.setText("Read"); readButton.setBounds(469, 10, 93, 23); add(readButton); final JButton resetButton = new JButton(); resetButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { // read labels from hardware resetLabels(); } }); resetButton.setText("Reset"); resetButton.setBounds(469, 43, 93, 23); add(resetButton); }
/** * Luo tilikarttataulukon. * * @param container taulukon säiliö */ private void createTable() { tableModel = new DocumentTypeTableModel(); tableModel.setModel(model); table = new JTable(tableModel); table.setFillsViewportHeight(true); table.setPreferredScrollableViewportSize(new Dimension(400, 250)); table.setRowHeight(24); TableColumn column; int[] widths = new int[] {80, 140, 80, 80}; for (int i = 0; i < widths.length; i++) { column = table.getColumnModel().getColumn(i); column.setPreferredWidth(widths[i]); } /* Muutetaan enter-näppäimen toiminta. */ table .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "nextCell"); table.getActionMap().put("nextCell", nextCellAction); add( new JScrollPane( table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER); }
private JPanel createPanel() { table.setFillsViewportHeight(true); table.setFont(getMonospacedFont()); table.addMouseListener( new MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent e) { if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { final int viewRow = table.rowAtPoint(e.getPoint()); if (viewRow != -1) { final int modelRow = table.convertRowIndexToModel(viewRow); final Breakpoint breakPoint = tableModel.getBreakpoint(modelRow); disView.setViewStartingAddress(breakPoint.getAddress()); if (sourceLevelDebugView != null) { // may be NULL when debugging a plain object file without attached // source sourceLevelDebugView.scrollToVisible(breakPoint.getAddress()); } } } }; }); table .getActionMap() .put( "deleteRow", new AbstractAction("deleteRow") { public void actionPerformed(ActionEvent e) { final int viewRow = table.getSelectedRow(); final int modelRow = table.convertRowIndexToModel(viewRow); Breakpoint bp = tableModel.getBreakpoint(modelRow); emulator.deleteBreakpoint(bp); } }); final KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0); table.getInputMap().put(stroke, "deleteRow"); setColors(table); // setup scrollpane final JScrollPane pane = new JScrollPane(table); setColors(pane); // setup result panel final JPanel panel = new JPanel(); setColors(panel); panel.setLayout(new GridBagLayout()); final GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH); panel.add(pane, cnstrs); return panel; }
private static void installActions(JTable table) { InputMap inputMap = table.getInputMap(WHEN_FOCUSED); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0), "selectLastRow"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0), "selectFirstRow"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_HOME, KeyEvent.SHIFT_DOWN_MASK), "selectFirstRowExtendSelection"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_END, KeyEvent.SHIFT_DOWN_MASK), "selectLastRowExtendSelection"); }
private static void registerSortMnemonics(JTable t) { for (int col = t.getColumnCount(); --col >= 0; ) { String name = t.getColumnName(col); int idx = name.indexOf('\u0332'); if (idx > 0) { int mnemonic = (int) Character.toUpperCase(name.charAt(idx - 1)); Actions act = new Actions(Actions.SORT); act.putValue(Actions.SORT, name); t.getInputMap(JComponent.WHEN_FOCUSED) .put(KeyStroke.getKeyStroke(mnemonic, InputEvent.ALT_DOWN_MASK), act); t.getActionMap().put(act, act); } } }
/** Create the dialog. */ public USDialog(ActionListener listener) { setIconImages(Simulator.makeIcons()); setBounds(100, 100, 450, 300); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(new BorderLayout(0, 0)); { JComboBox typeBox = new JComboBox(new DefaultComboBoxModel(Relationship.values())); typeEditor = new DefaultCellEditor(typeBox); table = new JTable(new USValuesTableModel()) { // Overridden to return a combobox for duration type @Override public TableCellEditor getCellEditor(int row, int column) { int modelColumn = convertColumnIndexToModel(column); if (modelColumn == 0) return typeEditor; else return super.getCellEditor(row, column); } }; // Make window close on second enter press InputMap map = table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); map.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)); table.getColumnModel().getColumn(1).setPreferredWidth(10); table.getColumnModel().getColumn(1).setMaxWidth(10); table.doLayout(); // Make single click start editing instead of needing double DefaultCellEditor singleClickEditor = new DefaultCellEditor(new JTextField()); singleClickEditor.setClickCountToStart(1); table.setDefaultEditor(Object.class, singleClickEditor); table.setCellSelectionEnabled(false); JScrollPane scrollPane = new JScrollPane(table); contentPanel.add(scrollPane); } { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton okButton = new JButton("OK"); okButton.setActionCommand("OK"); okButton.addActionListener(listener); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } } }
public ContentView(final ContentPane control) { super(new GridLayout(1, 1)); this.control = control; data = new JTable(); data.setModel(model = new ContentModel(getControl().getQueryModel() == null)); data.addMouseListener(popup = new ContentPopup(this)); data.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent key) { if (key.getKeyCode() == KeyEvent.VK_DOWN || key.getKeyCode() == KeyEvent.VK_PAGE_DOWN) { if ((ContentView.this.data.getSelectedRow() == ContentView.this.data.getRowCount() - 1) && !control.areAllRowsFetched()) { int col = ContentView.this.data.getSelectedColumn(); int row = ContentView.this.data.getRowCount() - 1; ContentView.this.data.scrollRectToVisible( ContentView.this.data.getCellRect(row, col, true)); ContentView.this.data.setRowSelectionInterval(row + 1, row + 1); ContentView.this.data.scrollRectToVisible( ContentView.this.data.getCellRect(row + 1, col, true)); key.consume(); } } } }); JScrollPane scroll = new JScrollPane(data); scroll.getViewport().setBackground(UIManager.getDefaults().getColor("Table.background")); add(scroll); jsb = scroll.getVerticalScrollBar(); jsb.addAdjustmentListener(new ListenerScrollBar()); data.setRowSelectionAllowed(false); data.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); data.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); data.setDefaultRenderer(Object.class, new InternalCellRenderer()); data.getTableHeader().addMouseListener(popup); data.getTableHeader().setReorderingAllowed(false); lines = new LineNumberView(); lines.addMouseListener(popup); lines.setSelectionModel(data.getSelectionModel()); scroll.setRowHeaderView(lines); JLabel cUL = new JLabel("#", JLabel.CENTER); cUL.setBorder(UIManager.getBorder("TableHeader.cellBorder")); cUL.setFont(UIManager.getFont("TableHeader.font")); scroll.setCorner(JScrollPane.UPPER_LEFT_CORNER, cUL); JLabel cLL = new JLabel(); cLL.setBorder(new CustomLineBorder(true, false, false, false)); scroll.setCorner(JScrollPane.LOWER_LEFT_CORNER, cLL); data.getColumnModel().getSelectionModel().addListSelectionListener(this); data.getActionMap().put("copy", ((JMenuItem) popup.getSubElementsAt(1)).getAction()); data.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK), "copy"); data.getActionMap().put("paste", ((JMenuItem) popup.getSubElementsAt(2)).getAction()); data.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK), "paste"); data.getActionMap().put("set-null", ((JMenuItem) popup.getSubElementsAt(3)).getAction()); data.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "set-null"); MouseAdapter ma = new MouseAdapter() { public void mousePressed(MouseEvent me) { ContentView.this.data.setColumnSelectionAllowed( me.getSource() == ContentView.this.data.getTableHeader()); ContentView.this.data.setRowSelectionAllowed(me.getSource() == ContentView.this.lines); } }; data.getTableHeader().addMouseListener(ma); data.addMouseListener(ma); lines.addMouseListener(ma); }
// {{{ InstallPanel constructor InstallPanel(PluginManager window, boolean updates) { super(new BorderLayout(12, 12)); this.window = window; this.updates = updates; setBorder(new EmptyBorder(12, 12, 12, 12)); final JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT); split.setResizeWeight(0.75); /* Setup the table */ table = new JTable(pluginModel = new PluginTableModel()); table.setShowGrid(false); table.setIntercellSpacing(new Dimension(0, 0)); table.setRowHeight(table.getRowHeight() + 2); table.setPreferredScrollableViewportSize(new Dimension(500, 200)); table.setDefaultRenderer( Object.class, new TextRenderer((DefaultTableCellRenderer) table.getDefaultRenderer(Object.class))); table.addFocusListener(new TableFocusHandler()); InputMap tableInputMap = table.getInputMap(JComponent.WHEN_FOCUSED); ActionMap tableActionMap = table.getActionMap(); tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "tabOutForward"); tableActionMap.put("tabOutForward", new KeyboardAction(KeyboardCommand.TAB_OUT_FORWARD)); tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK), "tabOutBack"); tableActionMap.put("tabOutBack", new KeyboardAction(KeyboardCommand.TAB_OUT_BACK)); tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "editPlugin"); tableActionMap.put("editPlugin", new KeyboardAction(KeyboardCommand.EDIT_PLUGIN)); tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "closePluginManager"); tableActionMap.put( "closePluginManager", new KeyboardAction(KeyboardCommand.CLOSE_PLUGIN_MANAGER)); TableColumn col1 = table.getColumnModel().getColumn(0); TableColumn col2 = table.getColumnModel().getColumn(1); TableColumn col3 = table.getColumnModel().getColumn(2); TableColumn col4 = table.getColumnModel().getColumn(3); TableColumn col5 = table.getColumnModel().getColumn(4); col1.setPreferredWidth(30); col1.setMinWidth(30); col1.setMaxWidth(30); col1.setResizable(false); col2.setPreferredWidth(180); col3.setPreferredWidth(130); col4.setPreferredWidth(70); col5.setPreferredWidth(70); JTableHeader header = table.getTableHeader(); header.setReorderingAllowed(false); header.addMouseListener(new HeaderMouseHandler()); header.setDefaultRenderer( new HeaderRenderer((DefaultTableCellRenderer) header.getDefaultRenderer())); scrollpane = new JScrollPane(table); scrollpane.getViewport().setBackground(table.getBackground()); split.setTopComponent(scrollpane); /* Create description */ JScrollPane infoPane = new JScrollPane(infoBox = new PluginInfoBox()); infoPane.setPreferredSize(new Dimension(500, 100)); split.setBottomComponent(infoPane); EventQueue.invokeLater( new Runnable() { @Override public void run() { split.setDividerLocation(0.75); } }); final JTextField searchField = new JTextField(); searchField.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) { table.dispatchEvent(e); table.requestFocus(); } } }); searchField .getDocument() .addDocumentListener( new DocumentListener() { void update() { pluginModel.setFilterString(searchField.getText()); } @Override public void changedUpdate(DocumentEvent e) { update(); } @Override public void insertUpdate(DocumentEvent e) { update(); } @Override public void removeUpdate(DocumentEvent e) { update(); } }); table.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { int i = table.getSelectedRow(), n = table.getModel().getRowCount(); if (e.getKeyCode() == KeyEvent.VK_DOWN && i == (n - 1) || e.getKeyCode() == KeyEvent.VK_UP && i == 0) { searchField.requestFocus(); searchField.selectAll(); } } }); Box filterBox = Box.createHorizontalBox(); filterBox.add(new JLabel("Filter : ")); filterBox.add(searchField); add(BorderLayout.NORTH, filterBox); add(BorderLayout.CENTER, split); /* Create buttons */ Box buttons = new Box(BoxLayout.X_AXIS); buttons.add(new InstallButton()); buttons.add(Box.createHorizontalStrut(12)); buttons.add(new SelectallButton()); buttons.add(chooseButton = new ChoosePluginSet()); buttons.add(new ClearPluginSet()); buttons.add(Box.createGlue()); buttons.add(new SizeLabel()); add(BorderLayout.SOUTH, buttons); String path = jEdit.getProperty(PluginManager.PROPERTY_PLUGINSET, ""); if (!path.isEmpty()) { loadPluginSet(path); } } // }}}
public LeksikonaEditorsFrame(Lexicon _lexicon) { this.lexicon = _lexicon; JPanel panelis = (JPanel) this.getContentPane(); // panelis.setMaximumSize(new Dimension(820, 672)); panelis.setMinimumSize(new Dimension(820, 610)); // this.setLocale(java.util.Locale.getDefault()); this.setPreferredSize(new Dimension(820, 610)); this.setTitle("Leksikona redaktors"); // this.setResizable(false); panelis.setLayout(new BorderLayout()); vgrMod = new VardgrupuModelis(lexicon); vārdgrupas = new JTable(vgrMod); vārdgrupas.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); TableColumn column = null; for (int i = 0; i < vgrMod.getColumnCount(); i++) { column = vārdgrupas.getColumnModel().getColumn(i); if (i == 1) { column.setPreferredWidth(300); // third column is bigger } else { column.setPreferredWidth(50); } } vārdgrupas .getInputMap() .put( KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_DOWN_MASK), "deleteRow"); vārdgrupas .getInputMap() .put( KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, java.awt.event.InputEvent.CTRL_DOWN_MASK), "insertRow"); vārdgrupas .getActionMap() .put( "deleteRow", new AbstractAction() { public void actionPerformed(ActionEvent e) { deleteWGroup(vārdgrupas.convertRowIndexToModel(vārdgrupas.getSelectedRow())); } }); vārdgrupas .getActionMap() .put( "insertRow", new AbstractAction() { public void actionPerformed(ActionEvent e) { insertWGroup(); } }); vārdgrupas.setBorder(BorderFactory.createLineBorder(Color.black)); vārdgrupas .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { vārdgrupaSelektēta(); } }); vgrĪpMod = new AttributeModel(null); vgrĪpašībuTabula = new IpasibuTable(vgrĪpMod); vgrĪpašībuTabula.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); vgrĪpašībuTabula.setBorder(BorderFactory.createLineBorder(Color.black)); vgrĪpašībuTabula .getInputMap() .put( KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_DOWN_MASK), "deleteRow"); vgrĪpašībuTabula .getInputMap() .put( KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, java.awt.event.InputEvent.CTRL_DOWN_MASK), "insertRow"); vgrĪpašībuTabula .getActionMap() .put( "deleteRow", new AbstractAction() { public void actionPerformed(ActionEvent e) { deleteWgroupProperty( vgrĪpašībuTabula.convertRowIndexToModel(vgrĪpašībuTabula.getSelectedRow())); } }); vgrĪpašībuTabula .getActionMap() .put( "insertRow", new AbstractAction() { public void actionPerformed(ActionEvent e) { addWgroupProperty(); } }); galMod = new EndingModel(); galotņuTabula = new JTable(galMod); galotņuTabula.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // galotņuTabula.setPreferredScrollableViewportSize(new Dimension(500, 70)); galotņuTabula.setBorder(BorderFactory.createLineBorder(Color.black)); galotņuTabula .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { galotneSelektēta(); } }); galotņuTabula .getInputMap() .put( KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_DOWN_MASK), "deleteRow"); galotņuTabula .getInputMap() .put( KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, java.awt.event.InputEvent.CTRL_DOWN_MASK), "insertRow"); galotņuTabula .getActionMap() .put( "deleteRow", new AbstractAction() { public void actionPerformed(ActionEvent e) { deleteEnding(galotņuTabula.convertRowIndexToModel(galotņuTabula.getSelectedRow())); } }); galotņuTabula .getActionMap() .put( "insertRow", new AbstractAction() { public void actionPerformed(ActionEvent e) { addEnding(); } }); galĪpMod = new AttributeModel(null); galotņuĪpašībuTabula = new IpasibuTable(galĪpMod); galotņuĪpašībuTabula.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // galotņuĪpašībuTabula.setPreferredScrollableViewportSize(new Dimension(500, 70)); galotņuĪpašībuTabula.setBorder(BorderFactory.createLineBorder(Color.black)); galotņuĪpašībuTabula .getInputMap() .put( KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_DOWN_MASK), "deleteRow"); galotņuĪpašībuTabula .getInputMap() .put( KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, java.awt.event.InputEvent.CTRL_DOWN_MASK), "insertRow"); galotņuĪpašībuTabula .getActionMap() .put( "deleteRow", new AbstractAction() { public void actionPerformed(ActionEvent e) { deleteEndingProperty( galotņuĪpašībuTabula.convertRowIndexToModel( galotņuĪpašībuTabula.getSelectedRow())); } }); galotņuĪpašībuTabula .getActionMap() .put( "insertRow", new AbstractAction() { public void actionPerformed(ActionEvent e) { addEndingProperty(); } }); leksMod = new LexemeModel(); leksēmuTabula = new JTable(leksMod); leksēmuTabula.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); leksēmuTabula.setBorder(BorderFactory.createLineBorder(Color.black)); // leksēmuTabula.setAutoCreateRowSorter(true); leksēmuTabula .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { leksēmaSelektēta(); } }); leksēmuTabula .getInputMap() .put( KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_DOWN_MASK), "deleteRow"); leksēmuTabula .getInputMap() .put( KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, java.awt.event.InputEvent.CTRL_DOWN_MASK), "insertRow"); leksēmuTabula .getActionMap() .put( "deleteRow", new AbstractAction() { public void actionPerformed(ActionEvent e) { deleteLexeme(leksēmuTabula.convertRowIndexToModel(leksēmuTabula.getSelectedRow())); } }); leksēmuTabula .getActionMap() .put( "insertRow", new AbstractAction() { public void actionPerformed(ActionEvent e) { addLexeme(); } }); leksĪpMod = new AttributeModel(null); leksēmuĪpašībuTabula = new IpasibuTable(leksĪpMod); leksēmuĪpašībuTabula.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); leksēmuĪpašībuTabula.setBorder(BorderFactory.createLineBorder(Color.black)); leksēmuĪpašībuTabula .getInputMap() .put( KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_DOWN_MASK), "deleteRow"); leksēmuĪpašībuTabula .getInputMap() .put( KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, java.awt.event.InputEvent.CTRL_DOWN_MASK), "insertRow"); leksēmuĪpašībuTabula .getActionMap() .put( "deleteRow", new AbstractAction() { public void actionPerformed(ActionEvent e) { deleteLexemeProperty( leksēmuĪpašībuTabula.convertRowIndexToModel( leksēmuĪpašībuTabula.getSelectedRow())); } }); leksēmuĪpašībuTabula .getActionMap() .put( "insertRow", new AbstractAction() { public void actionPerformed(ActionEvent e) { addLexemeProperty(); } }); JPanel leja = new JPanel(new BorderLayout()); JPanel pnlVgrTab = new JPanel(new BorderLayout()); JPanel pnlVgrĪpTab = new JPanel(new BorderLayout()); JPanel pnlGalTab = new JPanel(new BorderLayout()); JPanel pnlGalĪpTab = new JPanel(new BorderLayout()); JPanel pnlLeksTab = new JPanel(new BorderLayout()); JPanel pnlLeksĪpTab = new JPanel(new BorderLayout()); pnlVgrTab.add(lblVgr, BorderLayout.NORTH); pnlVgrTab.add(vārdgrupas, BorderLayout.SOUTH); pnlVgrTab.add(spanVgr); spanVgr.getViewport().add(vārdgrupas, null); pnlVgrĪpTab.add(lblVgrĪp, BorderLayout.NORTH); pnlVgrĪpTab.add(vgrĪpašībuTabula, BorderLayout.SOUTH); pnlVgrĪpTab.add(spanVgrĪp); spanVgrĪp.getViewport().add(vgrĪpašībuTabula, null); pnlGalTab.add(lblGal, BorderLayout.NORTH); pnlGalTab.add(galotņuTabula, BorderLayout.SOUTH); pnlGalTab.add(spanGal); spanGal.getViewport().add(galotņuTabula, null); pnlGalĪpTab.add(lblGalĪp, BorderLayout.NORTH); pnlGalĪpTab.add(galotņuĪpašībuTabula, BorderLayout.SOUTH); pnlGalĪpTab.add(spanGalĪp); spanGalĪp.getViewport().add(galotņuĪpašībuTabula, null); pnlLeksTab.add(lblLeks, BorderLayout.NORTH); pnlLeksTab.add(leksēmuTabula, BorderLayout.SOUTH); pnlLeksTab.add(spanLeks); spanLeks.getViewport().add(leksēmuTabula, null); pnlLeksĪpTab.add(lblLeksĪp, BorderLayout.NORTH); pnlLeksĪpTab.add(leksēmuĪpašībuTabula, BorderLayout.SOUTH); pnlLeksĪpTab.add(spanLeksĪp); spanLeksĪp.getViewport().add(leksēmuĪpašībuTabula, null); pnlGalTab.setPreferredSize(new Dimension(400, 400)); pnlGalotnes.add(pnlGalTab, BorderLayout.CENTER); pnlGalĪpTab.setPreferredSize(new Dimension(400, 150)); pnlGalotnes.add(pnlGalĪpTab, BorderLayout.SOUTH); pnlLeksTab.setPreferredSize(new Dimension(400, 400)); pnlLeksēmas.add(pnlLeksTab, BorderLayout.CENTER); pnlLeksĪpTab.setPreferredSize(new Dimension(400, 150)); pnlLeksēmas.add(pnlLeksĪpTab, BorderLayout.SOUTH); pnlVgrTab.setPreferredSize(new Dimension(400, 400)); pnlKreisais.add(pnlVgrTab, BorderLayout.CENTER); pnlVgrĪpTab.setPreferredSize(new Dimension(400, 150)); pnlKreisais.add(pnlVgrĪpTab, BorderLayout.SOUTH); centrs.add(pnlKreisais, BorderLayout.WEST); centrs.add(pnlLeksēmas, BorderLayout.CENTER); pārslēgt.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { changeTables(); } }); aizvērt.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { aizvērtLogu(); } }); leja.add(pārslēgt, BorderLayout.LINE_START); leja.add(aizvērt, BorderLayout.LINE_END); panelis.add(centrs, BorderLayout.CENTER); panelis.add(leja, BorderLayout.SOUTH); addWGroupPopupMenu(); addWGroupPropertiesPopupMenu(); addEndingPopupMenu(); addEngingPropertiesPopupMenu(); addLexemePopupMenu(); addLexemePropertiesPopupMenu(); this.pack(); }
/** * @param editor the editor * @param table where to put the action */ public static void registerAction(SwingScilabVariableEditor editor, JTable table) { table.getActionMap().put(PRECISION, new SetPrecisionLongAction(editor, PRECISION)); table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), PRECISION); }
/** * @param stylesPreferencesKey the preferences key with the list of active style sources * (filenames and URLs) * @param iconsPreferenceKey the preference key with the list of icon sources (can be null) * @param availableStylesUrl the URL to the list of available style sources */ public StyleSourceEditor( String stylesPreferencesKey, String iconsPreferenceKey, final String availableStylesUrl) { DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); tblActiveStyles = new JTable(activeStylesModel = new ActiveStylesModel(selectionModel)); tblActiveStyles.putClientProperty("terminateEditOnFocusLost", true); tblActiveStyles.setSelectionModel(selectionModel); tblActiveStyles.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); tblActiveStyles.setTableHeader(null); tblActiveStyles.getColumnModel().getColumn(0).setCellEditor(new FileOrUrlCellEditor()); tblActiveStyles.setRowHeight(20); activeStylesModel.setActiveStyles(Main.pref.getCollection(stylesPreferencesKey, null)); selectionModel = new DefaultListSelectionModel(); lstAvailableStyles = new JList(availableStylesModel = new AvailableStylesListModel(selectionModel)); lstAvailableStyles.setSelectionModel(selectionModel); lstAvailableStyles.setCellRenderer(new StyleSourceCellRenderer()); // availableStylesModel.setStyleSources(reloadAvailableStyles(availableStylesUrl)); this.availableStylesUrl = availableStylesUrl; this.pref = stylesPreferencesKey; this.iconpref = iconsPreferenceKey; JButton iconadd = null; JButton iconedit = null; JButton icondelete = null; if (iconsPreferenceKey != null) { selectionModel = new DefaultListSelectionModel(); tblIconPaths = new JTable(iconPathsModel = new IconPathTableModel(selectionModel)); tblIconPaths.setSelectionModel(selectionModel); tblIconPaths.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); tblIconPaths.setTableHeader(null); tblIconPaths.getColumnModel().getColumn(0).setCellEditor(new FileOrUrlCellEditor()); tblIconPaths.setRowHeight(20); iconPathsModel.setIconPaths(Main.pref.getCollection(iconsPreferenceKey, null)); iconadd = new JButton(new NewIconPathAction()); EditIconPathAction editIconPathAction = new EditIconPathAction(); tblIconPaths.getSelectionModel().addListSelectionListener(editIconPathAction); iconedit = new JButton(editIconPathAction); RemoveIconPathAction removeIconPathAction = new RemoveIconPathAction(); tblIconPaths.getSelectionModel().addListSelectionListener(removeIconPathAction); icondelete = new JButton(removeIconPathAction); tblIconPaths .getInputMap(JComponent.WHEN_FOCUSED) .put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete"); tblIconPaths.getActionMap().put("delete", removeIconPathAction); } JButton add = new JButton(new NewActiveStyleAction()); EditActiveStyleAction editActiveStyleAction = new EditActiveStyleAction(); tblActiveStyles.getSelectionModel().addListSelectionListener(editActiveStyleAction); JButton edit = new JButton(editActiveStyleAction); RemoveActiveStylesAction removeActiveStylesAction = new RemoveActiveStylesAction(); tblActiveStyles.getSelectionModel().addListSelectionListener(removeActiveStylesAction); tblActiveStyles .getInputMap(JComponent.WHEN_FOCUSED) .put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete"); tblActiveStyles.getActionMap().put("delete", removeActiveStylesAction); JButton delete = new JButton(removeActiveStylesAction); ActivateStylesAction activateStylesAction = new ActivateStylesAction(); lstAvailableStyles.addListSelectionListener(activateStylesAction); JButton copy = new JButton(activateStylesAction); JButton update = new JButton(new ReloadStylesAction(availableStylesUrl)); setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); setLayout(new GridBagLayout()); add(new JLabel(tr("Active styles")), GBC.eol().insets(5, 5, 5, 0)); JScrollPane sp; add(sp = new JScrollPane(tblActiveStyles), GBC.eol().insets(5, 0, 5, 0).fill(GBC.BOTH)); sp.setColumnHeaderView(null); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); add(buttonPanel, GBC.eol().insets(5, 0, 5, 5).fill(GBC.HORIZONTAL)); buttonPanel.add(add, GBC.std().insets(0, 5, 0, 0)); buttonPanel.add(edit, GBC.std().insets(5, 5, 5, 0)); buttonPanel.add(delete, GBC.std().insets(0, 5, 5, 0)); buttonPanel.add(copy, GBC.std().insets(0, 5, 5, 0)); add( new JLabel(tr("Available styles (from {0})", availableStylesUrl)), GBC.eol().insets(5, 5, 5, 0)); add(new JScrollPane(lstAvailableStyles), GBC.eol().insets(5, 0, 5, 0).fill(GBC.BOTH)); buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); add(buttonPanel, GBC.eol().insets(5, 0, 5, 5).fill(GBC.HORIZONTAL)); buttonPanel.add(update, GBC.std().insets(0, 5, 0, 0)); if (tblIconPaths != null) { add(new JLabel(tr("Icon paths")), GBC.eol().insets(5, -5, 5, 0)); add(sp = new JScrollPane(tblIconPaths), GBC.eol().insets(5, 0, 5, 0).fill(GBC.BOTH)); sp.setColumnHeaderView(null); buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); add(buttonPanel, GBC.eol().insets(5, 0, 5, 5).fill(GBC.HORIZONTAL)); buttonPanel.add(iconadd); buttonPanel.add(iconedit); buttonPanel.add(icondelete); } }
private void init() { tm = new RhTableModel(); lookUp = new JButton("Ver", new ImageIcon(RhTable.class.getResource("/icons/Preview_24x24.png"))); delete = new JButton( "Eliminar", new ImageIcon(RhTable.class.getResource("/icons/Delete_24x24.png"))); filter = new JTextField(35); filterLab = new JLabel("Filtrar: "); filterBackUp = null; table = new JTable(tm); table.setFont(TABLE_FONT); table.getTableHeader().setFont(TABLE_FONT.deriveFont(java.awt.Font.BOLD).deriveFont(12f)); table.setAutoCreateRowSorter(true); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); filter.setBackground(Color.LIGHT_GRAY); filter.setHorizontalAlignment(JTextField.CENTER); filter.setFont(TABLE_FONT); filterLab.setFont(TABLE_FONT.deriveFont(Font.BOLD)); lookUp.setFont(TABLE_FONT); delete.setFont(TABLE_FONT); // removing ENTER behavior table .getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put( KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) {} }); table.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); if (e.getClickCount() > 1) { lookUpSelected(); } } }); table.addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { super.keyReleased(e); switch (e.getKeyCode()) { case KeyEvent.VK_DELETE: removeSelected(); break; case KeyEvent.VK_ENTER: lookUpSelected(); break; case KeyEvent.VK_F5: filter.setText(""); updateTableData(); break; case KeyEvent.VK_P: if (e.getModifiers() == KeyEvent.CTRL_MASK) openPrintableView(); break; case KeyEvent.VK_F: if (e.getModifiers() == KeyEvent.CTRL_MASK) { filter.getParent().setVisible(true); filter.requestFocus(); } break; default: } } }); lookUp.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { lookUpSelected(); } }); delete.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { removeSelected(); } }); filter.addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { super.keyReleased(e); if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { filter.getParent().setVisible(false); filter.setText(""); } if (filterBackUp != null) { applyFilter(); } } }); setLayout(new BorderLayout()); add(Util.packInJP(new FlowLayout(FlowLayout.RIGHT), filterLab, filter), BorderLayout.NORTH); add(new JScrollPane(table)); add(Util.packInJP(new FlowLayout(FlowLayout.RIGHT), lookUp, delete), BorderLayout.SOUTH); filter.getParent().setVisible(false); }