private void jbInit() throws Exception { dm = hr.restart.baza.dM.getDataModule(); initDataSet(); jpGetVrnal.setDataSet(dataSet); jtDATUMKNJ.setColumnName("DATUMKNJ"); jtDATUMKNJ.setDataSet(dataSet); jtDATUMKNJ.setHorizontalAlignment(SwingConstants.CENTER); jlDATUMKNJ.setText("Datum knjiženja"); jtDATUMDO.setColumnName("DATUMDO"); jtDATUMDO.setDataSet(dataSet); jtDATUMDO.setHorizontalAlignment(SwingConstants.CENTER); jtDATUMDO.setHelpText("Unesite zadnji datum dokumenata koje knjižite"); jlDATUMDO.setText("Knjižiti do dana"); rcbNK.setRaColumn("NK"); rcbNK.setDataSet(dataSet); rcbNK.setRaItems( new String[][] { {"Zbrojiti stavke prema kontnom planu", "K"}, {"Zbrojiti stavke po kontima i org. jedinicama", "Z"}, {"Svaka stavka pojedina\u010Dno", "P"} }); xYLCommon.setHeight(100); jp.setLayout(new BorderLayout()); jpCommon.setLayout(xYLCommon); jpCommon.add(jpGetVrnal, new XYConstraints(0, 0, -1, 41)); jpCommon.add(jlDATUMKNJ, new XYConstraints(15, 45, -1, -1)); jpCommon.add(jtDATUMKNJ, new XYConstraints(150, 45, 100, -1)); jpCommon.add(jlDATUMDO, new XYConstraints(15, 70, -1, -1)); jpCommon.add(jtDATUMDO, new XYConstraints(150, 70, 100, -1)); jpCommon.add(rcbNK, new XYConstraints(255, 70, 265, -1)); jp.add(jpCommon, BorderLayout.NORTH); jp.add(okpanel, BorderLayout.SOUTH); getContentPane().add(jp, BorderLayout.CENTER); addComponentListener( new ComponentAdapter() { public void componentShown(ComponentEvent e) { initInputValues(); SetFokus(); } }); jbIspis.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { fake = true; okPressed(); } }); okpanel.addResetButton(this); okpanel.add(jbIspis, BorderLayout.WEST); okpanel.registerOKPanelKeys(this); }
public void showResults(Container parent, String title) { Container realparent = null; if (parent instanceof JComponent) realparent = ((JComponent) parent).getTopLevelAncestor(); else if (parent instanceof Window) realparent = parent; if (realparent instanceof Dialog) win = new JraDialog((Dialog) realparent, title, true); else if (realparent instanceof Frame) win = new JraDialog((Frame) realparent, title, true); else win = new JraDialog((Frame) null, title, true); win.setContentPane(contents); ((MatchTableModel) table.getModel()).fillData(master); win.pack(); win.setLocationRelativeTo(parent); win.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); win.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { CancelPress(); } }); win.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent e) { if (e.getKeyChar() == e.VK_ESCAPE) { CancelPress(); e.consume(); } } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == e.VK_A && e.getModifiers() == e.CTRL_MASK) { ((Action) table.getActionMap().get("selectAll")).actionPerformed(null); e.consume(); } } }); int dd = ToolTipManager.sharedInstance().getDismissDelay(); ToolTipManager.sharedInstance().setDismissDelay(10000); okp.registerOKPanelKeys(win); table.scrollRectToVisible(new Rectangle(0, 0, 10, 10)); if (table.isEditing()) table.removeEditor(); win.show(); ToolTipManager.sharedInstance().setDismissDelay(dd); }
private void init() throws Exception { model = new MatchTableModel(); cbox = new JraComboBox(); cbox.setRenderer( new BasicComboBoxRenderer() { public Component getListCellRendererComponent( JList l, Object val, int idx, boolean sel, boolean foc) { if (sel && idx >= 0 && val instanceof MatchableCollection) l.setToolTipText(((MatchableCollection) val).getToolTipText()); return super.getListCellRendererComponent(l, val, idx, sel, foc); } }); table = new JTable(model) { public void paintChildren(Graphics g) { super.paintChildren(g); paintSections(g); } public void changeSelection(int row, int col, boolean toggle, boolean extend) { int scrow = row; int oldrow = getSelectedRow(); int oldcol = getSelectedColumn(); int maxrow = model.getRowCount() - 2; if (model.isRowHeader(row) && (toggle || extend)) return; if (oldrow != -1 && model.isRowHeader(row)) { if (oldrow < row) while (row < maxrow && model.isRowHeader(++row)) ; else while (row > 0 && model.isRowHeader(--row)) ; if (model.isRowHeader(row)) if (oldrow < row) while (row > 0 && model.isRowHeader(--row)) ; else while (row < maxrow && model.isRowHeader(++row)) ; if (model.isRowHeader(row)) row = oldrow; } if (scrow < 2) scrow = 0; else if (scrow <= maxrow) scrow = row; getSelectionModel().setSelectionInterval(row, row); // super.changeSelection(row, col, false, false); if (oldrow < 0) oldrow = row; if ((toggle || extend) && (col == oldcol || row != oldrow)) { if (!extend) selectOrToggle(row, true); else { int beg = (oldrow > row ? row : oldrow), end = oldrow + row - beg; if (beg == end && extend) return; for (int i = beg; i <= end; i++) selectOrToggle(i, toggle); } repaint(); } if (getAutoscrolls()) { Rectangle cellRect = getCellRect(scrow, 0, true); if (cellRect != null) scrollRectToVisible(cellRect); } } private void selectOrToggle(int row, boolean toggle) { if (toggle) model.toggleRowSelected(row); else model.setRowSelected(row, true); } }; table.setColumnSelectionAllowed(false); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); for (int i = 0; i < model.m_columns.length; i++) table.getColumnModel().getColumn(i).setPreferredWidth(model.m_columns[i].m_width); table .getColumnModel() .getColumn(1) .setCellEditor( new DefaultCellEditor(cbox) { public Component getTableCellEditorComponent( JTable t, Object v, boolean sel, int row, int col) { cbox.setModel(new DefaultComboBoxModel(model.getMatchOptions(row))); cbox.setToolTipText( v instanceof MatchableCollection ? ((MatchableCollection) v).getToolTipText() : null); return super.getTableCellEditorComponent(t, v, sel, row, col); } }); table.setDefaultRenderer( Object.class, new DefaultTableCellRenderer() { private javax.swing.border.Border emptyBorder = BorderFactory.createEmptyBorder(0, 2, 0, 2); private Color m = null; private Color g = Color.green.darker().darker().darker(); private Color halfTone(Color cFrom, Color cTo, float factor) { return new Color( (int) (cFrom.getRed() * (1 - factor) + cTo.getRed() * factor), (int) (cFrom.getGreen() * (1 - factor) + cTo.getGreen() * factor), (int) (cFrom.getBlue() * (1 - factor) + cTo.getBlue() * factor)); } public Component getTableCellRendererComponent( JTable t, Object v, boolean sel, boolean foc, int row, int col) { super.getTableCellRendererComponent(t, v, sel, false, row, col); setOpaque(true); setBorder(emptyBorder); if (model.isRowSelected(row)) { if (m == null) m = halfTone(Color.yellow, t.getBackground(), 0.75f); super.setBackground(sel ? g : m); } else super.setBackground(sel ? t.getSelectionBackground() : t.getBackground()); int rc = t.convertColumnIndexToModel(col); if (rc == 2) setHorizontalAlignment(JLabel.TRAILING); else { setHorizontalAlignment(JLabel.LEADING); if (rc == 0 || rc == 1) setToolTipText(model.getToolTip(row, col)); } return this; } }); table.setRowHeight(21); table.setPreferredScrollableViewportSize( new Dimension(740, table.getPreferredScrollableViewportSize().height)); /* table.getActionMap().put("select-all", new AbstractAction() { if (e.getKeyCode() == e.VK_A && e.getModifiers() == e.CTRL_MASK) { for (int i = 0; i < model.getRowCount(); i++) model.toggleRowSelected(i); table.repaint(); e.consume(); } });*/ table .getActionMap() .put( "selectAll", new AbstractAction() { public void actionPerformed(ActionEvent e) { if (table.isEditing()) table.removeEditor(); for (int i = 0; i < model.getRowCount(); i++) model.toggleRowSelected(i); table.repaint(); } }); table.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == e.VK_ENTER && table.getSelectedRow() >= 0) { model.toggleRowSelected(table.getSelectedRow()); table.repaint(); } } }); contents = new JPanel(new BorderLayout()); okp = new OKpanel() { public void jBOK_actionPerformed() { OKPress(); } public void jPrekid_actionPerformed() { CancelPress(); } }; JPanel pd = new JPanel(null); pd.setLayout(new BoxLayout(pd, BoxLayout.X_AXIS)); JButton all = new JraButton(); all.setText("Oznaèi sve"); all.setIcon(raImages.getImageIcon(raImages.IMGALIGNJUSTIFY)); all.setPreferredSize(new Dimension(120, 25)); all.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { for (int i = 0; i < model.getRowCount(); i++) model.setRowSelected(i, true); table.repaint(); } }); okp.add(all, BorderLayout.WEST); contents.add(new JraScrollPane(table)); contents.add(okp, BorderLayout.SOUTH); okp.registerOKPanelKeys(table); }
public void setFake(boolean _fake) { fake = _fake; rcbNK.setVisible(fake); jbIspis.setVisible(!fake); if (fake) okpanel.change_jBOK("Ispis", raImages.IMGPRINT); }