コード例 #1
0
  public void valueChanged(ListSelectionEvent e) {

    JTable table = statTable.getTable();

    int[] selRow = table.getSelectedRows();

    // exit if initing or nothing selected
    if (isIniting() || selRow.length == 0) return;

    if (getProbCalc().getProbMode() == ProbabilityCalculatorViewD.PROB_INTERVAL) {
      // System.out.println(Arrays.toString(selectedRow));
      String lowStr = (String) table.getModel().getValueAt(selRow[0], 0);
      String highStr = (String) table.getModel().getValueAt(selRow[selRow.length - 1], 0);
      int low = Integer.parseInt(lowStr);
      int high = Integer.parseInt(highStr);
      // System.out.println(low + " , " + high);
      ((ProbabilityCalculatorViewD) getProbCalc()).setInterval(low, high);
    } else if (getProbCalc().getProbMode() == ProbabilityCalculatorViewD.PROB_LEFT) {
      String lowStr = (String) statTable.getTable().getModel().getValueAt(0, 0);
      String highStr =
          (String) statTable.getTable().getModel().getValueAt(selRow[selRow.length - 1], 0);
      int low = Integer.parseInt(lowStr);
      int high = Integer.parseInt(highStr);
      // System.out.println(low + " , " + high);
      ((ProbabilityCalculatorViewD) getProbCalc()).setInterval(low, high);

      // adjust the selection
      table.getSelectionModel().removeListSelectionListener(this);
      if (isCumulative()) {
        // single row selected
        table.changeSelection(selRow[selRow.length - 1], 0, false, false);
      } else {
        // select multiple rows: first up to selected
        table.changeSelection(0, 0, false, false);
        table.changeSelection(selRow[selRow.length - 1], 0, false, true);
        table.scrollRectToVisible(table.getCellRect(selRow[selRow.length - 1], 0, true));
      }
      table.getSelectionModel().addListSelectionListener(this);
    } else if (getProbCalc().getProbMode() == ProbabilityCalculatorView.PROB_RIGHT) {
      String lowStr = (String) statTable.getTable().getModel().getValueAt(selRow[0], 0);
      int maxRow = statTable.getTable().getRowCount() - 1;
      String highStr = (String) statTable.getTable().getModel().getValueAt(maxRow, 0);
      int low = Integer.parseInt(lowStr);
      int high = Integer.parseInt(highStr);
      // System.out.println(low + " , " + high);
      ((ProbabilityCalculatorViewD) getProbCalc()).setInterval(low, high);

      table.getSelectionModel().removeListSelectionListener(this);
      table.changeSelection(maxRow, 0, false, false);
      table.changeSelection(selRow[0], 0, false, true);
      // table.scrollRectToVisible(table.getCellRect(selRow[0], 0, true));
      table.getSelectionModel().addListSelectionListener(this);
    }
  }
コード例 #2
0
  public void buscarComputadora(JTable table) {
    JTextField marca = new JTextField();
    JTextField clave = new JTextField();
    Object[] mensaje = {
      "Marca:", marca,
      "Clave:", clave
    };

    int opcion =
        JOptionPane.showConfirmDialog(this, mensaje, "Buscar", JOptionPane.OK_CANCEL_OPTION);
    if (opcion == JOptionPane.OK_OPTION) {
      for (int i = 0; i < sistema.getEmpresa().getProductos().size(); i++) {
        try {
          if (marca
                  .getText()
                  .equalsIgnoreCase(sistema.getEmpresa().getProductos().get(i).getMarca())
              && Integer.parseInt(clave.getText())
                  == sistema.getEmpresa().getProductos().get(i).getClave()) {
            table.changeSelection(i, 0, false, false);
            JOptionPane.showMessageDialog(this, "Encontrado");
            return;
          }
        } catch (NumberFormatException ex) {
          JOptionPane.showMessageDialog(this, "Número inválido");
        }
      }
    }
    JOptionPane.showMessageDialog(this, "No se encontró el producto");
  }
コード例 #3
0
  public Object getCellEditorValue() {
    java.math.BigDecimal valorRetorno;
    try {
      valorRetorno = new java.math.BigDecimal(this.getValue().toString()).add(cero);
    } catch (NumberFormatException nfe) {
      valorRetorno = null;
    } catch (NullPointerException npe) {
      valorRetorno = null;
    }
    obtenerValorPorcentaje(valorRetorno);
    obtenerValoresDescuentoPorcentaje(valorRetorno);

    //        if (jIFProformas != null) {
    //            jIFProformas.descuentoIva = cero;
    //            if (jIFProformas.jchkAsumirIva.isSelected()) {
    //                descuentoIva(jIFProformas, jIFProformasModificar, valorRetorno);
    //            } else {
    //                obtenerValoresDescuentoPorcentaje(valorRetorno);
    //            }
    //        } else {
    //            jIFProformasModificar.descuentoIva = cero;
    //
    //            obtenerValoresDescuentoPorcentaje(valorRetorno);
    //
    //        }

    tabla.changeSelection(fila, columna + 1, false, false);
    return valorRetorno;
  }
コード例 #4
0
  /**
   * @see org.tramper.gui.viewer.Body#displayDocument(org.tramper.doc.SimpleDocument,
   *     org.tramper.doc.Target, int)
   */
  public void displayDocument(SimpleDocument doc, Target target, int documentPart) {
    if (!(doc instanceof Feed)) {
      throw new RuntimeException(doc.getTitle() + " is not a Feed");
    }
    document = (Feed) doc;
    this.target = target;

    feedTable.setModel(document);
    TableRowSorter<TableModel> tableSorter = new TableRowSorter<TableModel>(document);
    feedTable.setRowSorter(tableSorter);

    long indexModel = document.getIndex();
    int indexView = feedTable.convertColumnIndexToView((int) indexModel);
    feedTable.changeSelection(indexView, 0, false, false);
    TableColumnModel model = feedTable.getColumnModel();

    ListTableCellRenderer linkCellRenderer = new ListTableCellRenderer();
    ListTableCellEditor linkCellEditor = new ListTableCellEditor();
    TableColumn descColumn = model.getColumn(2);
    descColumn.setCellRenderer(linkCellRenderer);
    descColumn.setCellEditor(linkCellEditor);

    DateTableCellRenderer dateCellRenderer = new DateTableCellRenderer();
    descColumn = model.getColumn(3);
    descColumn.setCellRenderer(dateCellRenderer);
    descColumn = model.getColumn(4);
    descColumn.setCellRenderer(dateCellRenderer);

    this.initColumnSizes(feedTable);
  }
コード例 #5
0
ファイル: CustomTable.java プロジェクト: sneumann/ISAcreator
 @Override
 public void changeSelection(int row, int column, boolean toggle, boolean extend) {
   super.changeSelection(row, column, toggle, extend);
   TableCellEditor editor = getCellEditor(row, column);
   if (editor instanceof DefaultAutoFilterCellEditor) {
     if (editCellAt(row, column)) getEditorComponent().requestFocusInWindow();
   }
 }
コード例 #6
0
 /** @see org.tramper.gui.viewer.Viewer#last() */
 public void last() {
   int maxRowView = feedTable.getModel().getRowCount();
   feedTable.changeSelection(maxRowView - 1, 0, false, false);
   int maxRowModel = feedTable.convertRowIndexToModel(maxRowView);
   document.setIndex(maxRowModel - 1);
   FeedItem selectedItem = document.getItem(maxRowModel - 1);
   String displayableItem = renderFeedItem(selectedItem);
   feedItemDetail.setText(displayableItem);
 }
コード例 #7
0
 /** @see org.tramper.gui.viewer.Viewer#previous() */
 public void previous() {
   int selectedRowView = feedTable.getSelectedRow();
   feedTable.changeSelection(selectedRowView - 1, 0, false, false);
   int selectedRowModel = feedTable.convertRowIndexToModel(selectedRowView);
   document.setIndex(selectedRowModel - 1);
   FeedItem selectedItem = document.getItem(selectedRowModel - 1);
   String displayableItem = renderFeedItem(selectedItem);
   feedItemDetail.setText(displayableItem);
 }
コード例 #8
0
 private void addNewRowToTable(JTable table) {
   DefaultTableModel model = (DefaultTableModel) table.getModel();
   int rowCount = model.getRowCount();
   model.addRow(new Object[] {null, null, null});
   rowCount++;
   table.setCellSelectionEnabled(true);
   table.changeSelection(rowCount, 0, false, false);
   table.editCellAt(rowCount, 0);
 }
コード例 #9
0
 /** @see org.tramper.gui.viewer.Viewer#first() */
 public void first() {
   int minRowView = 0;
   feedTable.changeSelection(minRowView, 0, false, false);
   int minRowModel = feedTable.convertRowIndexToModel(minRowView);
   document.setIndex(minRowModel);
   FeedItem selectedItem = document.getItem(minRowModel);
   String displayableItem = renderFeedItem(selectedItem);
   feedItemDetail.setText(displayableItem);
 }
コード例 #10
0
 private void moveItemUp() {
   int index = menuItemsTable.getSelectedRow();
   // Return if nothing was selected.
   if (index == -1) return;
   // Return if the first item is selected.
   if (index == 0) return;
   nodeAttributesDialog.moveParameterItemUp(parameter, index);
   // TODO: Changing the selection doesn't have any effect on Mac.
   menuItemsTable.changeSelection(index - 1, 1, false, false);
 }
コード例 #11
0
 private void moveItemDown() {
   int index = menuItemsTable.getSelectedRow();
   // Return if nothing was selected.
   if (index == -1) return;
   java.util.List<Parameter.MenuItem> items = parameter.getMenuItems();
   // Return if the last item is selected.
   if (index >= items.size() - 1) return;
   nodeAttributesDialog.moveParameterItemDown(parameter, index);
   // TODO: Changing the selection doesn't have any effect on Mac.
   menuItemsTable.changeSelection(index + 1, 1, false, false);
 }
コード例 #12
0
        public void actionPerformed(ActionEvent e) {
          int column = table.getSelectedColumn();
          int row = table.getSelectedRow();

          if (table.isEditing()) table.getCellEditor().stopCellEditing();

          if (column < 4) {
            table.changeSelection(row, column + 1, false, false);
            table.editCellAt(row, column + 1);
          }
        }
コード例 #13
0
  private void populaTabela() {

    int counter = 0;
    if (this.isConsultaPorResponsavel) {
      try {
        ligacoes =
            BusinessFactory.getInstance()
                .getNumeroTelefonico()
                .getLigacoesPorUsuario(usuarioSelecionado.getEmail());

      } catch (BusinessException ex) {
        Logger.getLogger(JPConsultarLigacao.class.getName()).log(Level.SEVERE, null, ex);
      }
    } else {
      try {
        ligacoes =
            BusinessFactory.getInstance()
                .getNumeroTelefonico()
                .getLigacoes(new NumeroTelefonicoVO(jTextField5.getText()));

      } catch (BusinessException ex) {
        Logger.getLogger(JPConsultarLigacao.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
    DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
    model.setRowCount(0);
    for (UsuarioNumeroTelefonicoVO ligacao : ligacoes) {
      DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
      String recorrencia = "";

      ResourceBundle bundle = ResourceBundle.getBundle("I18n/Bundle");

      if (ligacao.getRecorrencia() == 1) {
        recorrencia = bundle.getString("JPConsultarNumeroTelefonico.CellText.Recorrente");
      } else if (ligacao.getRecorrencia() == 0) {
        recorrencia = bundle.getString("JPConsultarNumeroTelefonico.CellText.NaoRecorrente");
      }

      model.insertRow(
          counter,
          new Object[] {
            ligacao.getNumero().getNumero(),
            ligacao.getUsuario().getNome(),
            df.format(ligacao.getDataHora().getTime()),
            recorrencia
          });

      counter++;
    }
    jTable1.changeSelection(0, 0, false, false);
  }
コード例 #14
0
    @Override
    public void onEvent(ChangeRankingThresholdEvent event) {
      int rankingThreshold = event.getRankingThreshold();

      // table model
      PeptideSpeciesPSMTableModel peptideSpeciesTableModel =
          (PeptideSpeciesPSMTableModel) table.getModel();
      peptideSpeciesTableModel.setRankingThreshold(rankingThreshold);
      table.changeSelection(
          0,
          peptideSpeciesTableModel.getColumnIndex(PeptideTableHeader.PEPTIDE_COLUMN.getHeader()),
          false,
          false);
    }
コード例 #15
0
  public Object getCellEditorValue() {
    java.math.BigDecimal valorRetorno;
    try {
      valorRetorno = new java.math.BigDecimal(this.getValue().toString()).add(cero);
    } catch (NumberFormatException nfe) {
      valorRetorno = null;
    } catch (NullPointerException npe) {
      valorRetorno = null;
    }
    obtenerPrecio(valorRetorno);
    obtenerValoresIva(valorRetorno);

    tabla.changeSelection(fila, columna + 1, false, false);
    return valorRetorno;
  }
コード例 #16
0
ファイル: BeanTableDataModel.java プロジェクト: KenC57/JMRI
  protected void showPopup(MouseEvent e) {
    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);
    }
    final int rowindex = source.convertRowIndexToModel(row);

    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem(Bundle.getMessage("CopyName"));
    menuItem.addActionListener(
        (ActionEvent e1) -> {
          copyName(rowindex, 0);
        });
    popupMenu.add(menuItem);

    menuItem = new JMenuItem(Bundle.getMessage("Rename"));
    menuItem.addActionListener(
        (ActionEvent e1) -> {
          renameBean(rowindex, 0);
        });
    popupMenu.add(menuItem);

    menuItem = new JMenuItem(Bundle.getMessage("Clear"));
    menuItem.addActionListener(
        (ActionEvent e1) -> {
          removeName(rowindex, 0);
        });
    popupMenu.add(menuItem);

    menuItem = new JMenuItem(Bundle.getMessage("Move"));
    menuItem.addActionListener(
        (ActionEvent e1) -> {
          moveBean(rowindex, 0);
        });
    popupMenu.add(menuItem);

    menuItem = new JMenuItem(Bundle.getMessage("Delete"));
    menuItem.addActionListener(
        (ActionEvent e1) -> {
          deleteBean(rowindex, 0);
        });
    popupMenu.add(menuItem);

    popupMenu.show(e.getComponent(), e.getX(), e.getY());
  }
コード例 #17
0
  public TableFeedBody() {
    this.setOrientation(JSplitPane.VERTICAL_SPLIT);
    this.setOneTouchExpandable(false);
    this.setContinuousLayout(true);
    // the top component (the list) takes the extra space
    this.setResizeWeight(1);

    JScrollPane scroll = new JScrollPane();
    feedTable = new JTable();
    feedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    feedTable.setRowSelectionAllowed(true);
    feedTable.changeSelection(0, 0, false, false);
    feedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    feedTable.addMouseListener(this);
    feedTable.setRowHeight(25);
    feedTable.addKeyListener(this);
    scroll.setViewportView(feedTable);

    this.setTopComponent(scroll);

    feedItemDetail = new JEditorPane();
    feedItemDetail.setContentType("text/html");
    feedItemDetail.addHyperlinkListener(this);
    feedItemDetail.setBackground(Color.WHITE);
    feedItemDetail.setEditable(false);
    HTMLEditorKit kit = (HTMLEditorKit) feedItemDetail.getEditorKit();
    StyleSheet sheet = kit.getStyleSheet();
    Font font = UIManager.getFont("Label.font");
    sheet.addRule(
        "body {font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt;}");

    JScrollPane detailScroll = new JScrollPane();
    Dimension minDetailSize = detailScroll.getMinimumSize();
    minDetailSize.height = 100;
    detailScroll.setMinimumSize(minDetailSize);
    Dimension prefDetailSize = detailScroll.getPreferredSize();
    prefDetailSize.height = 200;
    detailScroll.setPreferredSize(prefDetailSize);
    detailScroll.setViewportView(feedItemDetail);

    this.setBottomComponent(detailScroll);

    this.setDividerSize(2);
    this.setDividerLocation(-1);
  }
コード例 #18
0
    @Override
    public void onEvent(PeptideSpeciesEvent event) {
      PeptideSpecies peptideSpecies = event.getPeptideSpecies();

      // table model
      PeptideSpeciesPSMTableModel peptideSpeciesTableModel =
          (PeptideSpeciesPSMTableModel) table.getModel();
      // delete all rows
      peptideSpeciesTableModel.removeAllRows();
      // get peptide
      if (peptideSpecies != null) {
        peptideSpeciesTableModel.addData(
            new Tuple<TableContentType, Object>(TableContentType.PEPTIDE_SPECIES, peptideSpecies));
        table.changeSelection(
            0,
            peptideSpeciesTableModel.getColumnIndex(PeptideTableHeader.PEPTIDE_COLUMN.getHeader()),
            false,
            false);
      }
    }
コード例 #19
0
 /**
  * This method will handle the selection change, if just one row has been selected on this records
  * creation.<br>
  */
 private void applySingleSelection() {
   affected.getSelectionModel().setValueIsAdjusting(true);
   affected.getSelectionModel().clearSelection();
   File searchFor = (File) selectedFiles.get(0);
   for (int i = 0; i < model.getRowCount(); i++) {
     if (model.getFileAt(sorter.modelIndex(i)).equals(searchFor)) {
       int newIndex = -1;
       if (i <= singleFileIndex) {
         newIndex = singleFileIndex + 1;
         if (newIndex >= model.getRowCount()) {
           newIndex = model.getRowCount() - 1;
         }
       } else {
         newIndex = singleFileIndex;
       }
       affected.changeSelection(newIndex, 0, false, false);
       break;
     }
   }
   affected.getSelectionModel().setValueIsAdjusting(false);
 }
コード例 #20
0
 // add, find or save button
 public void buttonActionPerformed(java.awt.event.ActionEvent ae) {
   // log.debug("car button activated");
   if (ae.getSource() == findButton) {
     int rowindex = carsTableModel.findCarByRoadNumber(findCarTextBox.getText());
     if (rowindex < 0) {
       JOptionPane.showMessageDialog(
           this,
           MessageFormat.format(
               Bundle.getMessage("carWithRoadNumNotFound"),
               new Object[] {findCarTextBox.getText()}),
           Bundle.getMessage("carCouldNotFind"),
           JOptionPane.INFORMATION_MESSAGE);
       return;
     }
     // clear any sorts by column
     clearTableSort(carsTable);
     carsTable.changeSelection(rowindex, 0, false, false);
     return;
   }
   if (ae.getSource() == addButton) {
     if (f != null) {
       f.dispose();
     }
     f = new CarEditFrame();
     f.initComponents();
     f.setTitle(Bundle.getMessage("TitleCarAdd"));
   }
   if (ae.getSource() == saveButton) {
     if (carsTable.isEditing()) {
       log.debug("cars table edit true");
       carsTable.getCellEditor().stopCellEditing();
     }
     OperationsXml.save();
     saveTableDetails(carsTable);
     if (Setup.isCloseWindowOnSaveEnabled()) {
       dispose();
     }
   }
 }
コード例 #21
0
  private void moveFocus() {
    int col = table.getSelectedColumn();
    int row = table.getSelectedRow();
    // table.nextFocus();
    // table.setCellSelectionEnabled(true);
    int moveToCol = 0;
    int moveToRow = 0;

    if (table.getColumnCount() < col) {
      moveToCol = col + 1;
    }

    if (col == 3 && table.getSelectedRow() < row) {
      moveToRow = row + 1;
    }

    table.changeSelection(moveToRow, moveToCol, true, false);
    table.editCellAt(moveToRow, moveToCol);
    Component c = table.getEditorComponent();

    if (c != null) {
      c.requestFocusInWindow();
    }
  }
コード例 #22
0
 private void inserirLinha() {
   int linha = jtbVenda.getSelectedRow();
   ((DefaultTableModel) jtbVenda.getModel()).addRow(new Vector());
   int coluna = -1;
   jtbVenda.changeSelection(linha, coluna, false, false);
 }
コード例 #23
0
 /** Lisää vientimallin. */
 public void addEntryTemplate() {
   int index = model.addDocumentType();
   tableModel.fireTableRowsInserted(index, index);
   table.requestFocusInWindow();
   table.changeSelection(index, 1, false, false);
 }
コード例 #24
0
 public void changeSelection(final int row, final int column, boolean toggle, boolean extend) {
   super.changeSelection(row, column, toggle, extend);
   editCellAt(row, column);
   transferFocus();
 }
コード例 #25
0
ファイル: TextPopup.java プロジェクト: anhnnp/HKTConsultants
    public PopupFilter(TextPopup txtSearch, DefaultTableModelCommon defaultTableModelCommon) {
      this.textField = txtSearch;
      table = new JTable();
      table.setModel(defaultTableModelCommon);
      add(table);
      table.setRowHeight(23);
      // table.getColumnModel().getColumn(0).setMaxWidth(200);
      table.setFont(new Font("Tahoma", Font.PLAIN, 14));

      if (table.getRowCount() >= 0) {
        table.changeSelection(0, 0, true, false);
      }

      table.addKeyListener(
          new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
              JTable table = (JTable) e.getSource();
              switch (e.getKeyCode()) {
                case KeyEvent.VK_ESCAPE:
                  setVisible(false);
                  return;
                case KeyEvent.VK_ENTER:
                  // textField.setText(" ");
                  try {
                    object = table.getValueAt(table.getSelectedRow(), value);
                  } catch (Exception e1) {
                    textField.setText("");
                    setVisible(false);
                    return;
                  }
                  if (object != null) {
                    if (clearText) {
                      textField.setText("");
                      object = null;
                    } else {
                      if (viewCode) {
                        textField.setText(table.getValueAt(table.getSelectedRow(), 0).toString());
                        object = null;
                      } else {
                        textField.setText(object.toString());
                        object = null;
                      }
                    }
                    setVisible(false);
                    if (component instanceof JTextField) {
                      if (((JTextField) component).getText().trim().isEmpty()
                          && !(component instanceof TextPopup)) {
                        ((JTextField) component).setText("1");
                      }
                      ((JTextField) component).setSelectionStart(0);
                      component.requestFocus();
                    }
                    table.clearSelection();
                    return;
                  }
              }
            }
          });

      table.addMouseListener(
          new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
              JTable table = (JTable) e.getSource();
              if (e.getClickCount() >= 2) {
                try {
                  object = table.getValueAt(table.getSelectedRow(), value);
                  try {
                    profile = AccountModelManager.getInstance().getProfileConfigAdmin();
                    if (profile.get(DialogConfig.Keyboard) != null
                        && profile.get(DialogConfig.Keyboard).toString().equals("true")) {
                      clearText1 = true;
                    } else {
                      clearText1 = false;
                    }
                  } catch (Exception e1) {
                  }
                } catch (Exception e1) {
                  setVisible(false);
                  return;
                }
                // textField.setText("  ");
                if (object != null) {
                  if (clearText) {
                    textField.setText("");
                    object = null;
                  } else {
                    if (viewCode) {
                      textField.setText(table.getValueAt(table.getSelectedRow(), 0).toString());
                      object = null;
                    } else {
                      textField.setText(object.toString());
                      object = null;
                    }
                  }
                  setVisible(false);
                  if (profile.get(DialogConfig.Keyboard) != null
                      && profile.get(DialogConfig.Keyboard).toString().equals("true")) {
                    table.clearSelection();
                    return;
                  }
                  if (component instanceof JTextField) {
                    if (((JTextField) component).getText().trim().isEmpty()
                        && !(component instanceof TextPopup)) {
                      ((JTextField) component).setText("1");
                      ((JTextField) component).setSelectionStart(0);
                    }
                    component.requestFocus();
                  }
                  table.clearSelection();
                  return;
                }
              }
            }
          });
      if (textField.getKeyListeners().length > 0) {
        textField.removeKeyListener(textField.getKeyListeners()[0]);
      }

      textField.addKeyListener(
          new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
              switch (e.getKeyCode()) {
                case KeyEvent.VK_DOWN:
                  table.clearSelection();
                  table.changeSelection(1, 1, true, false);
                  table.requestFocus();
                  return;
                case KeyEvent.VK_ENTER:
                  if (table.getSelectedRow() >= 0) {
                    try {
                      object = table.getValueAt(table.getSelectedRow(), value);
                    } catch (Exception e1) {
                      setVisible(false);
                      return;
                    }
                    // textField.setText("  ");
                    if (object != null) {
                      if (clearText) {
                        textField.setText("");
                        object = null;
                        setVisible(false);
                      } else {
                        if (viewCode) {
                          textField.setText(table.getValueAt(table.getSelectedRow(), 0).toString());
                          object = null;
                          setVisible(false);
                        } else {
                          textField.setText(object.toString());
                          object = null;
                          setVisible(false);
                        }
                      }

                      if (component instanceof JTextField) {
                        if (((JTextField) component).getText().trim().isEmpty()
                            && !(component instanceof TextPopup)) {
                          ((JTextField) component).setText("1");
                          ((JTextField) component).setSelectionStart(0);
                        }
                        component.requestFocus();
                      }
                      table.clearSelection();
                      return;
                    }
                  }
              }
            }
          });
    }
コード例 #26
0
ファイル: MainFrame.java プロジェクト: gaurav/taxref
  /**
   * Move the currently selected cell up or down by one cell.
   *
   * @param direction -1 for previous, +1 for next.
   */
  public void goToRow(int direction) {
    int row = table.getSelectedRow();
    int column = table.getSelectedColumn();

    table.changeSelection(row + direction, column, false, false);
  }
コード例 #27
0
ファイル: MainFrame.java プロジェクト: gaurav/taxref
  void goToSpecificColumn(int selectedIndex) {
    int row = table.getSelectedRow();

    table.changeSelection(row, selectedIndex, true, true);
  }
コード例 #28
0
  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == prodGui.getModificar()) { // Modificar producto
      prodGui.getGuardar().setEnabled(true);
      modificarPulsado = true;
      nuevoPulsado = false;
      prodGui.habilitarCampos(true);
      prodGui.getIdArticulo().setEditable(false);
      prodGui.getProveedores().removeAllItems();
      abrirBase();
      int r = tabla.getSelectedRow();
      if (r > -1) {
        Producto p = Producto.first("numero_producto = ?", tabla.getValueAt(r, 0));

        LazyList<Proveedor> l = Proveedor.findAll();
        Iterator<Proveedor> it = l.iterator();
        while (it.hasNext()) {
          Proveedor prov = it.next();
          String nom = prov.getString("nombre");
          String cuil = prov.getString("cuil");
          String prove = nom + ";" + cuil;
          prodGui.getProveedores().addItem(prove);
        }
        if (p != null) {
          prodGui.CargarCampos(p);
          Proveedor prov = Proveedor.findById(p.getInteger("proveedor_id"));
          if (prov != null) {
            String nom = prov.getString("nombre");
            String cuil = prov.getString("cuil");
            String pr = nom + ";" + cuil;
            prodGui.getProveedores().setSelectedItem(pr);
          }
        }
      }
      if (Base.hasConnection()) Base.close();

      // Agregar al combo todos los proveedores!
    }
    if (e.getSource() == prodGui.getNuevo()) { // Producto nuevo
      prodGui.getGuardar().setEnabled(true);
      nuevoPulsado = true;
      modificarPulsado = false;
      prodGui.getModificar().setEnabled(false);
      prodGui.getBorrar().setEnabled(false);
      prodGui.limpiarCampos();
      prodGui.habilitarCampos(true);
      prodGui.getProveedores().removeAllItems();
      abrirBase();
      LazyList<Proveedor> l = Proveedor.findAll();
      Iterator<Proveedor> it = l.iterator();
      while (it.hasNext()) {
        Proveedor prov = it.next();
        String nom = prov.getString("nombre");
        String cuil = prov.getString("cuil");
        String prove = nom + ";" + cuil;
        prodGui.getProveedores().addItem(prove);
      }
      if (Base.hasConnection()) Base.close();
      // Agregar al combo todos los proveedores
    }
    if (e.getSource() == prodGui.getGuardar() && modificarPulsado) {
      String id = prodGui.getIdArticulo().getText();
      abrirBase();
      Producto p = Producto.first("numero_producto = ?", id);
      cargarDatosProd(p, false);
      if (Base.hasConnection()) Base.close();
      String prov = (String) prodGui.getProveedores().getSelectedItem();
      String[] proveedor = prov.split(";");
      p.setCuilProveedor(proveedor[1]);
      // p.set("priveedor_id");
      abrirBase();
      Proveedor proveed = Proveedor.first("cuil = ?", proveedor[1]);
      p.set("proveedor_id", proveed.get("id"));
      if (abmProd.modificar(p)) {
        JOptionPane.showMessageDialog(apgui, "Producto modificado exitosamente.");
        pl = pb.filtroProducto("", "", "");
        actualizarLista();
        modificarPulsado = false;
        prodGui.habilitarCampos(false);
        prodGui.getModificar().setEnabled(false);
        prodGui.getGuardar().setEnabled(false);
      } else {
        JOptionPane.showMessageDialog(prodGui, "El número de producto ya existe");
      }
    }
    if (e.getSource() == prodGui.getGuardar() && nuevoPulsado) {
      Producto p = new Producto();
      cargarDatosProd(p, false);
      String prov = (String) prodGui.getProveedores().getSelectedItem();
      String[] proveedor = prov.split(";");
      p.setCuilProveedor(proveedor[1]);
      if (p.getString("nombre").equals("") || p.getString("marca").equals("")) {
        JOptionPane.showMessageDialog(prodGui, "Un producto debe tener nombre y marca");
      }
      abrirBase();
      if (abmProd.alta(p)) {
        JOptionPane.showMessageDialog(prodGui, "Producto registrado exitosamente");
        p = abmProd.getProducto(p);
        agregarFila(p);
        nuevoPulsado = false;
        prodGui.habilitarCampos(false);
        prodGui.getGuardar().setEnabled(false);
      } else {
        JOptionPane.showMessageDialog(prodGui, "Producto existente");
      }
      vc.actualizarListaProd();
      if (Base.hasConnection()) Base.close();
    }

    if (e.getSource() == prodGui.getBorrar()) {
      confirmarBorrar =
          JOptionPane.showConfirmDialog(
              prodGui, "¿borrar producto?", "Confirmar Borrado", JOptionPane.YES_NO_OPTION);
      if (JOptionPane.OK_OPTION == confirmarBorrar) {
        abrirBase();
        Producto p = Producto.first("numero_producto = ?", prodGui.getIdArticulo().getText());
        if (abmProd.baja(p)) {
          JOptionPane.showMessageDialog(prodGui, "Producto borrado exitosamente");
          pl = pb.filtroProducto("", "", "");
          actualizarLista();
          prodGui.limpiarCampos();
          prodGui.getBorrar().setEnabled(false);
          prodGui.getModificar().setEnabled(false);
          prodGui.getGuardar().setEnabled(false);
        } else {
          JOptionPane.showMessageDialog(prodGui, "No se ha borrado el producto");
        }
      }
    }
    if (e.getSource() == prodGui.getAnterior()) {
      prodGui.getProveedores().removeAllItems();
      int r = tabla.getSelectedRow();
      if (r > 0) {
        tabla.changeSelection(tabla.getSelectedRow() - 1, 0, false, false);
        r--;
        abrirBase();
        Producto c = Producto.first("numero_producto =?", tabla.getValueAt(r, 0));
        Proveedor p = Proveedor.first("id = ?", c.getString("proveedor_id"));
        if (Base.hasConnection()) Base.close();

        prodGui.CargarCampos(c);
        String nom = p.getString("nombre");
        String cuil = p.getString("cuil");
        String pr = nom + ";" + cuil;
        prodGui.getProveedores().addItem(pr);
        prodGui.repaint();
      }
    }

    if (e.getSource()
        == prodGui.getSiguiente()) { // permite avanzar al siguiente cliente de la lista
      prodGui.getProveedores().removeAllItems();
      int r = tabla.getSelectedRow();
      if (tablaProductos.getRowCount() - 1 > r) {
        tabla.changeSelection(r + 1, 0, false, false);
        r++;
        abrirBase();
        Producto c = Producto.first("numero_producto =?", tabla.getValueAt(r, 0));
        Proveedor p = Proveedor.first("id = ?", c.getString("proveedor_id"));
        if (Base.hasConnection()) Base.close();
        prodGui.CargarCampos(c);
        String nom = p.getString("nombre");
        String cuil = p.getString("cuil");
        String pr = nom + ";" + cuil;
        prodGui.getProveedores().addItem(pr);
      }
    }

    if (e.getSource() == prodGui.getModificarPrecios()) {
      DefaultTableModel t = mpp.getTablaArticulos();
      t.setRowCount(0);
      abrirBase();
      LazyList<Producto> prod = Producto.findAll();
      Iterator<Producto> it = prod.iterator();
      while (it.hasNext()) {
        Producto a = it.next();
        Object row[] = new Object[7];
        row[0] = a.getString("numero_producto");
        row[1] = a.getString("nombre");
        row[2] = a.getString("marca");
        row[3] = a.getString("tipo");
        row[4] = a.getString("precio_compra");
        row[5] = BigDecimal.valueOf(Double.valueOf(a.getString("precio_venta")));
        row[6] = BigDecimal.valueOf(Double.valueOf(a.getString("precio_venta")));
        t.addRow(row);
      }
      if (Base.hasConnection()) Base.close();
      mpp.setLocationRelativeTo(prodGui);
      mpp.setVisible(true);
      if (mpp.getReturnStatus() == 1) {
        Iterator<Pair> list = mpp.getProductosModificados().iterator();
        while (list.hasNext()) {
          Pair par = list.next();
          abrirBase();
          Producto p = Producto.findFirst("numero_producto =?", (String) par.first());
          p.set("precio_venta", par.second());
          if (p.saveIt()) {
            JOptionPane.showMessageDialog(
                prodGui,
                "Precios modificados exitosamente",
                "Precios modificados",
                JOptionPane.INFORMATION_MESSAGE);
          }
          if (Base.hasConnection()) Base.close();
        }
      }
    }
    vc.actualizarListaProd();
    cc.actualizarListaProd();
    vrc.actualizarListaFacturas();
    crc.actualizarListaCompras();
    /*if(e.getSource() == mpp.getAceptar()){
    int srow = prodGui.getTabla().getSelectedRow();
    Object id = prodGui.getTablaArticulos().getValueAt(srow, 0);
    Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/sexshop", "root", "root");
    Producto p = Producto.first("id = ?", id);
    p.set("precio_venta", mpp.getPesos().getText());
    p.saveIt();
    if (Base.hasConnection())
    Base.close();
    mpp.dispose();
    JOptionPane.showMessageDialog(apgui, "Precio modificado exitosamente.");

    }
    if(e.getSource() == mpp.getCancelar()){
    mpp.dispose();
    }
    */
  }