@Override
  protected void updateButtons() {
    final CommonActionsPanel p = getActionsPanel();
    if (p != null) {
      boolean someElementSelected;
      if (myTable.isEnabled()) {
        final int index = myTable.getSelectedRow();
        final int size = myTable.getModel().getRowCount();
        someElementSelected = 0 <= index && index < size;
        if (someElementSelected) {
          final boolean downEnable = myTable.getSelectionModel().getMaxSelectionIndex() < size - 1;
          final boolean upEnable = myTable.getSelectionModel().getMinSelectionIndex() > 0;
          final boolean editEnabled = myTable.getSelectedRowCount() == 1;
          p.setEnabled(CommonActionsPanel.Buttons.EDIT, editEnabled);
          p.setEnabled(CommonActionsPanel.Buttons.UP, upEnable);
          p.setEnabled(CommonActionsPanel.Buttons.DOWN, downEnable);
        } else {
          p.setEnabled(CommonActionsPanel.Buttons.EDIT, false);
          p.setEnabled(CommonActionsPanel.Buttons.UP, false);
          p.setEnabled(CommonActionsPanel.Buttons.DOWN, false);
        }
        p.setEnabled(
            CommonActionsPanel.Buttons.ADD, myProducer == null || myProducer.canCreateElement());
      } else {
        someElementSelected = false;
        p.setEnabled(CommonActionsPanel.Buttons.ADD, false);
        p.setEnabled(CommonActionsPanel.Buttons.EDIT, false);
        p.setEnabled(CommonActionsPanel.Buttons.UP, false);
        p.setEnabled(CommonActionsPanel.Buttons.DOWN, false);
      }

      p.setEnabled(CommonActionsPanel.Buttons.REMOVE, someElementSelected);
      updateExtraElementActions(someElementSelected);
    }
  }
  // Implementation of valueChanged
  public void valueChanged(ListSelectionEvent e) {
    if (e.getSource() == table.getSelectionModel()) {
      ListSelectionModel ls = table.getSelectionModel();

      int index = ls.getMinSelectionIndex();
      long id = (long) table.getValueAt(index, 0);

      updateFeesData(id);
    } else {
      ListSelectionModel ls = feestable.getSelectionModel();

      int index = ls.getMinSelectionIndex();

      float feespayed = (float) feestable.getValueAt(index, 1);
      float totalfees = (float) feestable.getValueAt(index, 2);

      feespayedlabel.setText("Fees Payed: " + feespayed);
      totalfeeslabel.setText("Total Fees: " + totalfees);

      if (totalfees - feespayed > 0) {
        feesduelabel.setText("Fees Due: " + (totalfees - feespayed));
      }

      panel_6.revalidate();
    }
  }
Beispiel #3
0
  public JointPriorDialog(JFrame frame, BeautiOptions options) {
    this.frame = frame;

    this.options = options;

    priorSettingsPanel = new PriorSettingsPanel(frame);

    nameField.setColumns(30);

    parametersTableModel = new ParametersTableModel();
    //        TableSorter sorter = new TableSorter(traitsTableModel);
    //        traitsTable = new JTable(sorter);
    //        sorter.setTableHeader(traitsTable.getTableHeader());
    parametersTable = new JTable(parametersTableModel);

    parametersTable.getTableHeader().setReorderingAllowed(false);
    parametersTable.getTableHeader().setResizingAllowed(false);
    //        traitsTable.getTableHeader().setDefaultRenderer(
    //                new HeaderRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));

    parametersTable
        .getSelectionModel()
        .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    parametersTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent evt) {
                parametersSelectionChanged();
              }
            });
  }
  public void fixSelection(int rows[]) {
    if (rows.length == 0) return;

    table.getSelectionModel().setValueIsAdjusting(true);

    int rowcount = table.getModel().getRowCount();

    for (int x = 0; x < rows.length; x++) {
      if (rows[x] < rowcount) {
        table.getSelectionModel().addSelectionInterval(rows[x], rows[x]);
      }
    }

    table.getSelectionModel().setValueIsAdjusting(false);
  }
  // Fees update method
  private void updateFeesData(long id) {
    String columns[] = {"Course", "Fees Payed", "Total fees", "Installments"};
    try {
      Database db = new Database();

      panel_7.removeAll();

      feestablemodel = new MyTableModel(db.getFeeData(id), columns);

      feestable = new JTable(feestablemodel);
      feestable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      feestable.getSelectionModel().addListSelectionListener(this);

      feesscrollpane = new JScrollPane(feestable);
      panel_7.add(feesscrollpane);

      // change fees payed label
      feespayedlabel.setText("Fees Payed");
      feesduelabel.setText("Fees Due");
      totalfeeslabel.setText("Total Fees");

      panel_7.revalidate();
    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, e.getMessage(), null, JOptionPane.ERROR_MESSAGE);
    }
  }
    public void popuniSaPodacima(long idSelektiranogKlijenta) {
        // Isprazni tabelu dostava
        //obracuniJTable.setModel(new ObracuniTableModel());

        // Uzmi sve klijente iz baze
        Baza baza = Baza.getBaza();
        List<Klijent> sviKlijenti = baza.dajSve(Klijent.class);
        // izfiltriraj one klijente koji su obrisani
        ukloniObrisaneKlijenteIz(sviKlijenti);

        // Napravi jComboBoxItem-ove sa svim klijentima
        List<JComboBoxItem> sviKlijentiJComboBoxItemi = new ArrayList<JComboBoxItem>();
        for (Klijent k : sviKlijenti) {
            sviKlijentiJComboBoxItemi.add(new JComboBoxItem(k.getId(), k.getIme()));
        }
        // Popuni obracunZaJComboBox sa JComboBoxItem-ovima
        GuiUtilities.popuniJComboBoxSa(sviKlijentiJComboBoxItemi, obracunZaJComboBox, idSelektiranogKlijenta);

        // Popuni tabelu obracuni sa obracunima za klijenta koji ima idSelektiranogKlijenta
        Klijent selektiraniKlijent = baza.dajPoId(Klijent.class, idSelektiranogKlijenta);
        popuniObracuniJTableSaPodacimaOKlijentu(selektiraniKlijent);
        // Oznaci prvi red u tabeli za dostave
        if (obracuniJTable.getRowCount() > 0) {
            ListSelectionModel selectionModel = obracuniJTable.getSelectionModel();
            selectionModel.setSelectionInterval(0, 0);

            // Uzmi oznaceni obracun iz tabele Racun
            Racun oznaceniRacun = ((ObracuniTableModel) obracuniJTable.getModel()).getRacuniZaKlijenta()
                    .get(obracuniJTable.getSelectedRow());
        }

        // Refreshati panel
        osvjeziJPanel();
    }
  @Override
  protected void addComponents() {
    // add descriptive panel
    JPanel metaDataPanel = new JPanel();
    metaDataPanel.setOpaque(false);
    metaDataPanel.setLayout(new FlowLayout(FlowLayout.LEFT));

    // table label
    JLabel tableLabel = new JLabel("<html><b>" + PSM_TABLE_DESC + "</b></html>");
    metaDataPanel.add(tableLabel);
    this.add(metaDataPanel, BorderLayout.NORTH);

    psmTable =
        TableFactory.createPSMTable(
            controller.getAvailablePeptideLevelScores(),
            PeptideRankingFilter.LESS_EQUAL_THAN_ONE.getRankingThreshold(),
            controller);

    // add PSM table selection listener
    psmTable.getSelectionModel().addListSelectionListener(new PSMSelectionListener(psmTable));

    JScrollPane scrollPane =
        new JScrollPane(
            psmTable,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    this.add(scrollPane, BorderLayout.CENTER);
  }
 TableToolbarDecorator(@NotNull JTable table, @Nullable final ElementProducer<?> producer) {
   myTable = table;
   myProducer = producer;
   myAddActionEnabled =
       myRemoveActionEnabled = myUpActionEnabled = myDownActionEnabled = isModelEditable();
   if (isModelEditable()) {
     createDefaultTableActions(producer);
   }
   myTable
       .getSelectionModel()
       .addListSelectionListener(
           new ListSelectionListener() {
             @Override
             public void valueChanged(ListSelectionEvent e) {
               updateButtons();
             }
           });
   myTable.addPropertyChangeListener(
       "enabled",
       new PropertyChangeListener() {
         @Override
         public void propertyChange(PropertyChangeEvent evt) {
           updateButtons();
         }
       });
 }
 protected void createWidgets() {
   ReadOnlyTableModel<B> model = new ReadOnlyTableModel<>(getAssignments());
   model.addColumn(
       "Profesor",
       "request",
       new ToStringConverter<Request>() {
         @Override
         public String convert(Request aRequest) {
           return aRequest.getProfessor().getName();
         }
       });
   model.addColumn(
       "Materia",
       "request",
       new ToStringConverter<Request>() {
         @Override
         public String convert(Request aRequest) {
           return aRequest.getSubject().getName();
         }
       });
   assignmentsTable = new JTable(model);
   assignmentsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   assignmentsTable
       .getSelectionModel()
       .addListSelectionListener(
           AssignmentsDetailWindow.this::whenAssignmentsTableSelectionChanged);
   periodDetail = new JTextArea();
   periodDetail.setPreferredSize(new Dimension(480, 100));
   periodDetail.setEditable(false);
   createOtherWidgets();
 }
  public void setOptions(BeautiOptions options) {

    this.options = options;

    resetPanel();

    settingOptions = true;

    int selRow = partitionTable.getSelectedRow();
    partitionTableModel.fireTableDataChanged();
    if (options.getDataPartitions().size() > 0) {
      if (selRow < 0) {
        selRow = 0;
      }
      partitionTable.getSelectionModel().setSelectionInterval(selRow, selRow);

      setCurrentPartition(options.getDataPartitions().get(selRow));
    }

    AncestralStatesOptionsPanel panel = optionsPanels.get(currentPartition);
    if (panel != null) {
      panel.setupPanel();
    }

    settingOptions = false;

    validate();
    repaint();
  }
 /** Creates and displays the main GUI This GUI has the list and the main * buttons */
 public void showGUI() {
   final JScrollPane scrollPane = new JScrollPane();
   table =
       new JTable(
           new DefaultTableModel(
               new Object[][] {}, new String[] {"Username", "Password", "Pin", "Reward"}));
   AccountManager.loadAccounts();
   if (AccountManager.hasAccounts()) {
     for (Account account : AccountManager.getAccounts()) {
       ((DefaultTableModel) table.getModel())
           .addRow(
               new Object[] {
                 account.getUsername(), account.getReward(), account.getPin(), account.getReward()
               });
     }
   }
   final JToolBar bar = new JToolBar();
   bar.setMargin(new Insets(1, 1, 1, 1));
   bar.setFloatable(false);
   removeButton = new JButton("Remove");
   final JButton newButton = new JButton("Add");
   final JButton doneButton = new JButton("Save");
   table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   table.getSelectionModel().addListSelectionListener(new TableSelectionListener());
   table.setShowGrid(true);
   final TableColumnModel cm = table.getColumnModel();
   cm.getColumn(cm.getColumnIndex("Password")).setCellRenderer(new PasswordCellRenderer());
   cm.getColumn(cm.getColumnIndex("Password")).setCellEditor(new PasswordCellEditor());
   cm.getColumn(cm.getColumnIndex("Pin")).setCellRenderer(new PasswordCellRenderer());
   cm.getColumn(cm.getColumnIndex("Pin")).setCellEditor(new PasswordCellEditor());
   cm.getColumn(cm.getColumnIndex("Reward")).setCellEditor(new RandomRewardEditor());
   scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
   scrollPane.setViewportView(table);
   add(scrollPane, BorderLayout.CENTER);
   newButton.setFocusable(false);
   newButton.setToolTipText(newButton.getText());
   newButton.setText("+");
   bar.add(newButton);
   removeButton.setFocusable(false);
   removeButton.setToolTipText(removeButton.getText());
   removeButton.setText("-");
   bar.add(removeButton);
   bar.add(Box.createHorizontalGlue());
   doneButton.setToolTipText(doneButton.getText());
   bar.add(doneButton);
   newButton.addActionListener(this);
   removeButton.addActionListener(this);
   doneButton.addActionListener(this);
   add(bar, BorderLayout.SOUTH);
   final int row = table.getSelectedRow();
   removeButton.setEnabled(row >= 0 && row < table.getRowCount());
   table.clearSelection();
   doneButton.requestFocus();
   setPreferredSize(new Dimension(600, 300));
   pack();
   setLocationRelativeTo(getOwner());
   setResizable(false);
 }
  // Add fee method
  private void addFees() {
    try {
      float feesadded = Float.parseFloat(addfeestextfield.getText());

      int id = table.getSelectionModel().getMinSelectionIndex();
      long studentid = (long) table.getValueAt(id, 0);

      int index = feestable.getSelectionModel().getMinSelectionIndex();
      String coursename = (String) feestable.getValueAt(index, 0);

      Database db = new Database();
      db.addFees(feesadded, studentid, coursename);

      updateFeesData(studentid);

      addfeestextfield.setText("");
    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, e.getMessage(), null, JOptionPane.ERROR_MESSAGE);
    }
  }
 private void createClassroomsTable() {
   ReadOnlyTableModel<Classroom> tableModel =
       new ReadOnlyTableModel<>(department.getClassroomsDepartment().searchClassroomByName(""));
   addClassroomsColumns(tableModel);
   classroomsTable = new JTable(tableModel);
   classroomsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   classroomsTable
       .getSelectionModel()
       .addListSelectionListener(EditAssignmentWindow.this::whenClassroomsTableSelectionChanged);
   classroomsTableScrollPane = new JScrollPane(classroomsTable);
 }
  public void init() {
    setTitle(SettingsMessages.getInstance().getString("ShowPasswordsDialog.Title"));

    removeAction = new RemovePasswordsAction();

    tableModel = new PasswordTableModel();
    passwordTable = new JTable(tableModel);
    passwordTable.getSelectionModel().addListSelectionListener(removeAction);

    super.init();
  }
Beispiel #15
0
 protected void selectEditor(MouseEvent e) {
   int row;
   if (e == null) {
     row = table.getSelectionModel().getAnchorSelectionIndex();
   } else {
     row = table.rowAtPoint(e.getPoint());
   }
   editor = (TableCellEditor) editors.get(new Integer(row));
   if (editor == null) {
     editor = defaultEditor;
   }
 }
  private JScrollPane createTable(Object tableData[][], Object columnTitle[], JPopupMenu popup) {
    _table =
        new JTable(tableData, columnTitle) {

          private static final boolean INCLUDE_INTERCELL_SPACING = true;

          public boolean isCellEditable(int row, int column) {
            return false;
          }

          //            public JToolTip createToolTip() {
          //                PropertySheetToolTip.getInstance().setComponent(this);
          //                return PropertySheetToolTip.getInstance();
          //            }

          public String getToolTipText(MouseEvent event) {
            int col = columnAtPoint(event.getPoint());
            int row = rowAtPoint(event.getPoint());
            String tip = (String) getValueAt(row, col);
            Graphics2D g2 = (Graphics2D) getGraphics();
            Rectangle2D tipRect = getFont().getStringBounds(tip, g2.getFontRenderContext());
            g2.dispose();
            Rectangle visibleCell = getVisibleRect().intersection(getCellRect(row, col, false));
            if (tipRect.getWidth() + 1.0D < visibleCell.getWidth()) tip = null;
            return tip;
          }

          public Point getToolTipLocation(MouseEvent event) {
            int col = columnAtPoint(event.getPoint());
            int row = rowAtPoint(event.getPoint());
            return getCellRect(row, col, true).getLocation();
          }
        };
    _table.setAutoResizeMode(0);
    _table.getSelectionModel().setSelectionMode(0);

    //        JPopupMenu popup = new JPopupMenu();
    //        popup.add(new JMenuItem("Hello"));
    //
    // add Popup Menu
    if (popup != null) {
      // todo -- implement me
      //            MouseListener popupListener = new PopupListener(popup);
      //            _table.addMouseListener(popupListener);
    }

    for (int i = 0; i < columnTitle.length; i++) {
      packColumn(_table, i, 2);
    }
    //        packColumn(_table, 0, 2);
    //        packColumn(_table, 1, 2);
    return new JScrollPane(_table);
  }
  private void init() {
    setLayout(new BorderLayout());

    tableModel = new NotesTableModel(getCharacter());
    table = new JTable(tableModel);
    table.setRowHeight(50);
    tableModel.updateColumns(table);
    table.setDefaultRenderer(String.class, new NotesCellRenderer());
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                updateControls();
              }
            });

    add(new JScrollPane(table), "Center");

    Box box = Box.createHorizontalBox();
    box.add(Box.createHorizontalGlue());
    addNoteButton = new JButton("Add Custom");
    addNoteButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ev) {
            String note = JOptionPane.showInputDialog("Custom Note");
            getCharacter().addNote(getGameHandler().getClient().getClientName(), "Custom", note);
            updatePanel();
          }
        });
    box.add(addNoteButton);
    box.add(Box.createHorizontalGlue());
    deleteNoteButton = new JButton("Delete Custom");
    deleteNoteButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ev) {
            Note note = getSelectedNote();
            if (note != null) {
              getCharacter().deleteNote(note.getId());
              updatePanel();
            }
          }
        });
    box.add(deleteNoteButton);
    box.add(Box.createHorizontalGlue());
    add(box, "South");

    updateControls();
  }
 private void addListSelectionListener(final JTable table, final JButton deleteDOTItemButton) {
   final ListSelectionModel selectionModel = table.getSelectionModel();
   ListSelectionListener listSelectionListener =
       new ListSelectionListener() {
         public void valueChanged(ListSelectionEvent e) {
           final int selectedRow = table.getSelectedRow();
           if (selectedRow == -1) {
             deleteDOTItemButton.setEnabled(false);
           } else {
             deleteDOTItemButton.setEnabled(_dotDefinitionDialogFrame.isEditable());
           }
         }
       };
   selectionModel.addListSelectionListener(listSelectionListener);
 }
  private void selectionChanged() {
    if (settingOptions) return;

    int selRow = partitionTable.getSelectedRow();

    if (selRow >= options.getDataPartitions().size()) {
      selRow = 0;
      partitionTable.getSelectionModel().setSelectionInterval(selRow, selRow);
    }

    if (selRow >= 0) {
      setCurrentPartition(options.getDataPartitions().get(selRow));
      //            frame.modelSelectionChanged(!isUsed(selRow));
    }
  }
  //
  //  Implement the PropertyChangeListener
  //
  public void propertyChange(PropertyChangeEvent e) {
    //  Keep the row table in sync with the main table

    if ("selectionModel".equals(e.getPropertyName())) {
      setSelectionModel(main.getSelectionModel());
    }

    if ("rowHeight".equals(e.getPropertyName())) {
      repaint();
    }

    if ("model".equals(e.getPropertyName())) {
      main.getModel().addTableModelListener(this);
      revalidate();
    }
  }
Beispiel #21
0
  public boolean createFromTraits(List<TraitData> traits) {
    int selRow = -1;

    if (selectTraitDialog == null) {
      selectTraitDialog = new SelectTraitDialog(frame);
    }

    if (traits == null || traits.size() == 0) {
      int result = selectTraitDialog.showDialog(options.traits, null);
      if (result != JOptionPane.CANCEL_OPTION) {
        TraitData trait = selectTraitDialog.getTrait();
        String name = trait.getName();
        if (selectTraitDialog.getMakeCopy()) {
          name = selectTraitDialog.getName();
        }

        selRow = options.createPartitionForTraits(name, trait);
      } else {
        return false;
      }
    } else {
      if (traits.size() > 1) {
        // a set of traits have been passed to the function
        int result = selectTraitDialog.showDialog(null, null);
        if (result != JOptionPane.CANCEL_OPTION) {
          String name = selectTraitDialog.getName();
          selRow = options.createPartitionForTraits(name, traits);
        } else {
          return false;
        }
      } else {
        selRow = options.createPartitionForTraits(traits.get(0).getName(), traits);
      }
    }

    modelsChanged();
    dataTableModel.fireTableDataChanged();

    if (selRow != -1) {
      dataTable.getSelectionModel().setSelectionInterval(selRow, selRow);
    }
    fireDataChanged();
    repaint();

    return true;
  }
  public RowNumberTable(JTable table) {
    main = table;
    main.addPropertyChangeListener(this);
    main.getModel().addTableModelListener(this);

    setFocusable(false);
    setAutoCreateColumnsFromModel(false);
    setSelectionModel(main.getSelectionModel());

    TableColumn column = new TableColumn();
    column.setHeaderValue(" ");
    addColumn(column);
    column.setCellRenderer(new RowNumberRenderer());

    getColumnModel().getColumn(0).setPreferredWidth(50);
    setPreferredScrollableViewportSize(getPreferredSize());
  }
 public void actionPerformed(ActionEvent e) {
   JTable table = (JTable) e.getSource();
   if (!table.hasFocus()) {
     CellEditor cellEditor = table.getCellEditor();
     if (cellEditor != null && !cellEditor.stopCellEditing()) {
       return;
     }
     table.requestFocus();
     return;
   }
   ListSelectionModel rsm = table.getSelectionModel();
   int anchorRow = rsm.getAnchorSelectionIndex();
   table.editCellAt(anchorRow, PropertySheetTableModel.VALUE_COLUMN);
   Component editorComp = table.getEditorComponent();
   if (editorComp != null) {
     editorComp.requestFocus();
   }
 }
  private void rebuildPopup(
      @NotNull final UsageViewImpl usageView,
      @NotNull final List<Usage> usages,
      @NotNull List<UsageNode> nodes,
      @NotNull final JTable table,
      @NotNull final JBPopup popup,
      @NotNull final UsageViewPresentation presentation,
      @NotNull final RelativePoint popupPosition,
      boolean findUsagesInProgress) {
    ApplicationManager.getApplication().assertIsDispatchThread();

    boolean shouldShowMoreSeparator = usages.contains(MORE_USAGES_SEPARATOR);
    if (shouldShowMoreSeparator) {
      nodes.add(MORE_USAGES_SEPARATOR_NODE);
    }

    String title = presentation.getTabText();
    String fullTitle =
        getFullTitle(
            usages,
            title,
            shouldShowMoreSeparator,
            nodes.size() - (shouldShowMoreSeparator ? 1 : 0),
            findUsagesInProgress);

    ((AbstractPopup) popup).setCaption(fullTitle);

    List<UsageNode> data = collectData(usages, nodes, usageView, presentation);
    MyModel tableModel = setTableModel(table, usageView, data);
    List<UsageNode> existingData = tableModel.getItems();

    int row = table.getSelectedRow();

    int newSelection = updateModel(tableModel, existingData, data, row == -1 ? 0 : row);
    if (newSelection < 0 || newSelection >= tableModel.getRowCount()) {
      TableScrollingUtil.ensureSelectionExists(table);
      newSelection = table.getSelectedRow();
    } else {
      table.getSelectionModel().setSelectionInterval(newSelection, newSelection);
    }
    TableScrollingUtil.ensureIndexIsVisible(table, newSelection, 0);

    setSizeAndDimensions(table, popup, popupPosition, data);
  }
  /** Initial method to populate the insuranceCompaniesTable */
  public void loadTable() {

    Map<Integer, InsuranceCompany> data = model.getInsuranceCompanies();
    tableData = new InsuranceCompanyTableModel(data);
    insuranceCompaniesTable.setModel(tableData);
    insuranceCompaniesTable.getColumnModel().getColumn(0).setMaxWidth(50);
    insuranceCompaniesTable
        .getSelectionModel()
        .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    // Check if db is empty and proceed with selecting only if the table is populated
    if (insuranceCompaniesTable.getRowCount() > 0) {
      // Set selected company according to selected row on load
      selectRow();
      int selectedCompanyId =
          Integer.valueOf(
              (String)
                  insuranceCompaniesTable.getValueAt(insuranceCompaniesTable.getSelectedRow(), 0));
    }
  }
Beispiel #26
0
  /** Creates an instance <tt>PropertiesEditorPanel</tt>. */
  public PropertiesEditorPanel() {
    super(new BorderLayout());

    /**
     * Instantiates the properties table and adds selection model and listener and adds a row sorter
     * to the table model
     */
    ResourceManagementService r = PropertiesEditorActivator.getResourceManagementService();
    String[] columnNames =
        new String[] {r.getI18NString("service.gui.NAME"), r.getI18NString("service.gui.VALUE")};

    propsTable = new JTable(new PropsTableModel(initTableModel(), columnNames));
    propsTable.setRowSorter(new TableRowSorter<TableModel>(propsTable.getModel()));
    propsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    PropsListSelectionListener selectionListener = new PropsListSelectionListener();

    propsTable.getSelectionModel().addListSelectionListener(selectionListener);
    propsTable.getColumnModel().getSelectionModel().addListSelectionListener(selectionListener);

    JScrollPane scrollPane = new JScrollPane(propsTable);
    SearchField searchField = new SearchField("", propsTable);

    buttonsPanel = new ButtonsPanel(propsTable, searchField);

    centerPanel = new TransparentPanel(new BorderLayout());
    centerPanel.add(scrollPane, BorderLayout.CENTER);
    centerPanel.add(buttonsPanel, BorderLayout.EAST);

    JLabel needRestart = new JLabel(r.getI18NString("plugin.propertieseditor.NEED_RESTART"));

    needRestart.setForeground(Color.RED);

    TransparentPanel searchPanel = new TransparentPanel(new BorderLayout(5, 0));

    searchPanel.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
    searchPanel.add(searchField, BorderLayout.CENTER);

    setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
    add(searchPanel, BorderLayout.NORTH);
    add(centerPanel, BorderLayout.CENTER);
    add(needRestart, BorderLayout.SOUTH);
  }
 private void maybeGrabSelection() {
   if (table.getSelectedRow() != -1) {
     // Grab selection
     ListSelectionModel rowSel = table.getSelectionModel();
     ListSelectionModel colSel = table.getColumnModel().getSelectionModel();
     if (!haveAnchor()) {
       //        System.err.println("Updating from table's selection");
       setSelection(
           rowSel.getAnchorSelectionIndex(), rowSel.getLeadSelectionIndex(),
           colSel.getAnchorSelectionIndex(), colSel.getLeadSelectionIndex());
     } else {
       //        System.err.println("Updating lead from table's selection");
       setSelection(
           getRowAnchor(), rowSel.getLeadSelectionIndex(),
           getColAnchor(), colSel.getLeadSelectionIndex());
     }
     //      printSelection();
   }
 }
  // Add course method
  public void addCourse() {
    try {
      Database db = new Database();

      String coursename = (String) coursecombobox.getSelectedItem();
      if (coursecombobox.getSelectedIndex() == 0) {
        throw new Exception("No course selected");
      }

      float fees = db.getCoursefees(coursename);
      float totalfees = fees + (ims.main.Settings.getInstallment() * (int) spinner.getValue());

      long id = (long) table.getValueAt((int) table.getSelectionModel().getMinSelectionIndex(), 0);

      db.addCourseToCurrentStudent(id, totalfees, (int) spinner.getValue(), coursename);

      updateFeesData(id);
      courseReset();
    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, e.getMessage(), null, JOptionPane.ERROR_MESSAGE);
    }
  }
  private void loadView() {
    // main views
    mTableModel = new SpreadsheetTableModel();

    mTableView = new JTable(mTableModel);
    mTableView.setRowSelectionAllowed(false);
    mTableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    mTableView.setFillsViewportHeight(true);
    mTableView.setDefaultRenderer(String.class, new ColorCellRenderer(TABLE_CELL_COLOR));
    mTableView.setDefaultEditor(
        String.class, new SpreadsheetCellEditor(mTableView.getDefaultEditor(String.class)));
    mTableView.getSelectionModel().addListSelectionListener(new SpreadsheetSelectionListener());
    mTableView
        .getColumnModel()
        .getSelectionModel()
        .addListSelectionListener(new SpreadsheetSelectionListener());

    JTable rowHeaderTable = new JTable(new RowHeaderTableModel());
    rowHeaderTable.setCellSelectionEnabled(false);
    rowHeaderTable.setPreferredScrollableViewportSize(new Dimension(50, Integer.MAX_VALUE));
    rowHeaderTable.setDefaultRenderer(Object.class, new ColorCellRenderer(ROW_HEADER_COLOR));

    mFormulaTextField = new BindableTextField();
    mFormulaTextField.setEditable(false);
    mFormulaTextField.setFocusable(false);

    JScrollPane scrollView = new JScrollPane(mTableView);
    scrollView.setRowHeaderView(rowHeaderTable);

    add(mFormulaTextField, BorderLayout.BEFORE_FIRST_LINE);
    add(scrollView, BorderLayout.CENTER);

    // helpers

    mFileChooser = new SingleExtensionFileChooser();
    String extension = SpreadsheetPersistenceManager.SPREADSHEET_FILE_EXTENSION;
    mFileChooser.setFileExtension(extension, "Spreadsheets file (." + extension + ")");
  }
  public void refresh(File root) {
    this.removeAll();
    filesCache.clear();
    DefaultTableModel model = new DefaultTableModel();
    model.addColumn("Name");
    model.addColumn("Size");
    if (root != null && root.isDirectory() && !root.getName().startsWith(".")) {
      File[] files = root.listFiles();
      for (int i = 0; i < files.length; i++) {
        if (!files[i].getName().startsWith(".")) {
          String[] values = {files[i].getName(), files[i].getTotalSpace() + ""};
          model.addRow(values);
          filesCache.put(i, files[i]);
        }
      }
    }
    JTable table = new JTable(model);
    table.getColumnModel().getColumn(0).setPreferredWidth(300);
    table.getColumnModel().getColumn(1).setPreferredWidth(100);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setUI(new ITunesTableUI());
    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    IAppWidgetFactory.makeIAppScrollPane(scrollPane);
    this.add(scrollPane, BorderLayout.CENTER);
    this.repaint();
    this.revalidate();

    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent listSelectionEvent) {
                explorer.fileSelected(filesCache.get(listSelectionEvent.getFirstIndex()));
              }
            });
  }