private void init(String format) {
    jxdDate = new org.jdesktop.swingx.JXDatePicker();
    jxdDate
        .getEditor()
        .setFormatterFactory(
            new javax.swing.text.DefaultFormatterFactory(
                new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat(format))));
    jxdDate.addActionListener(this);
    jxdDate
        .getEditor()
        .addKeyListener(
            new java.awt.event.KeyAdapter() {

              @Override
              public void keyReleased(KeyEvent e) {
                if (e.getKeyCode() == java.awt.event.KeyEvent.VK_DELETE)
                  jxdDate.getEditor().setText("");
              }
            });
    jxdDate
        .getEditor()
        .addMouseListener(
            new java.awt.event.MouseAdapter() {

              @Override
              public void mouseReleased(MouseEvent e) {
                if (e.getButton() != java.awt.event.MouseEvent.BUTTON1)
                  jxdDate.getEditor().setText("");
              }
            });
  }
  private JXDatePicker createDatePicker(Date initialDate) {
    final JXDatePicker dp = new JXDatePicker(initialDate);
    dp.setFormats(PhotoCopyToolPanel.DATE_PICKER_FORMAT);
    dp.setEditable(true);
    dp.addActionListener(
        new ActionListener() {
          long lastTime = dp.getDate() == null ? -1 : dp.getDate().getTime();

          @Override
          public void actionPerformed(ActionEvent e) {
            Date d = dp.getDate();
            long t = -1;
            if (d != null) t = d.getTime();

            if (t != lastTime) {
              lastTime = t;
              if (imagesLoaded) selection = getSelectedImages(SelectImageDialog.this);
              loadImagesAsync();
            }
          }
        });
    dp.getEditor()
        .addFocusListener(
            new FocusAdapter() {
              @Override
              public void focusLost(FocusEvent e) {
                try {
                  dp.commitEdit();
                } catch (ParseException pe) {
                }
              }
            });
    return dp;
  }
Example #3
0
  public TimeStampEditor() {
    super(new BorderLayout());
    add(BorderLayout.WEST, datePicker);
    add(BorderLayout.CENTER, hours);
    add(BorderLayout.EAST, minutes);
    datePicker.setOpaque(false);
    datePicker.addActionListener(this);
    datePicker.getEditor().addFocusListener(this);

    hours.setOpaque(false);
    hours.addChangeListener(this);
    ((JSpinner.DefaultEditor) hours.getEditor()).getTextField().addFocusListener(this);

    minutes.setOpaque(false);
    minutes.addChangeListener(this);
    ((JSpinner.DefaultEditor) minutes.getEditor()).getTextField().addFocusListener(this);
  }
Example #4
0
    protected void init() {

      addProperty(
          new String[] {
            "fecha", "tipo", "concepto", "debe", "haber", "cuadre", "fecha", "year", "mes"
          });
      addLabels(
          new String[] {
            "Fecha", "tipo", "concepto", "Debe", "Haber", "Cuadre", "fecha", "year", "mes"
          });

      installTextComponentMatcherEditor("A Favor", "afavor");
      installTextComponentMatcherEditor("Cuenta", "cuenta");
      installTextComponentMatcherEditor("Año", "year");
      installTextComponentMatcherEditor("Mes", "mes");
      datePicker = new JXDatePicker();
      datePicker.setFormats(new String[] {"dd/MM/yyyy"});
      datePicker.addActionListener(this);
    }
  public pnl_wheels_view(int width, int height) {
    setBackground(Color.WHITE);

    setSize(width, height - 30);

    window_width = this.getWidth();
    window_height = this.getHeight();

    setLayout(null);

    tbl_service_details =
        new JTable() {

          private static final long serialVersionUID = 1L;

          protected JTableHeader createDefaultTableHeader() {
            return new JTableHeader(columnModel) {

              private static final long serialVersionUID = 1L;

              public String getToolTipText(MouseEvent e) {
                String tip = null;
                java.awt.Point p = e.getPoint();
                int index = columnModel.getColumnIndexAtX(p.x);

                if (index == 8) {
                  tip = "Enable checkbox if Free checkup is Completed";
                }

                return tip;
              }
            };
          }

          @Override
          public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
            Component comp = super.prepareRenderer(renderer, row, col);
            int index = (int) getModel().getValueAt(row, 0);
            int due_date = fcd_completed_due_date.get(index - 1);
            if (col == 8) {
              if (due_date == 0) {
                comp.setBackground(Color.LIGHT_GRAY);
              }
            }
            return comp;
          }
        };

    tbl_service_details.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    tbl_service_details.setRowSelectionAllowed(false);
    mdl_service_details =
        new DefaultTableModel() {

          private static final long serialVersionUID = 1L;

          public boolean isCellEditable(int row, int col) {

            if (col == 9) return true;
            else if (col == 8 && fcd_completed_due_date.get((int) getValueAt(row, 0) - 1) != 0)
              return true;
            else return false;
          }

          public Class<?> getColumnClass(int c) {

            if (this.getRowCount() >= 1) {
              return getValueAt(0, c).getClass();
            } else {
              return new String().getClass();
            }
          }
        };

    String[] columns = {
      "S.NO",
      "Customer Name",
      "Mobile No",
      "Vehicle No",
      "Bill Date",
      "Remarks",
      "Particulars",
      "Total",
      "FCD",
      "Info"
    };

    mdl_service_details.setColumnIdentifiers(columns);

    load_all_sbd();

    tbl_service_details.setModel(mdl_service_details);
    tbl_service_details.setFont(new Font("Arial", Font.PLAIN, 14));
    tbl_service_details.setForeground(Color.DARK_GRAY);
    tbl_service_details.setGridColor(Color.BLUE);
    tbl_service_details.setBackground(Color.WHITE);
    tbl_service_details.setRowMargin(5);
    tbl_service_details.setRowHeight(50);

    tbl_service_details.getColumn("Particulars").setCellRenderer(new SubTableRenderer());
    tbl_service_details.getColumn("Customer Name").setCellRenderer(new WrapCellRenderer());
    tbl_service_details.getColumn("Mobile No").setCellRenderer(new WrapCellRenderer());
    tbl_service_details.getColumn("Vehicle No").setCellRenderer(new WrapCellRenderer());
    tbl_service_details.getColumn("Bill Date").setCellRenderer(new WrapCellRenderer());
    tbl_service_details.getColumn("Remarks").setCellRenderer(new WrapCellRenderer());

    Action update_fcd =
        new AbstractAction() {

          private static final long serialVersionUID = 1L;

          @Override
          public void actionPerformed(ActionEvent e) {

            int row = Integer.valueOf(e.getActionCommand());

            int completed_date = fcd_completed_date.get(row);

            int due_date = fcd_completed_due_date.get(row);

            if (due_date > 0) {
              String msg = "";
              if (completed_date > 0) {
                msg =
                    "<html><Table>"
                        + "<tr>"
                        + "<td><font color='green'> FreeCheckup Status </font></td>"
                        + "<td> : </td>"
                        + "<td><font color='green'> Completed </font></td>"
                        + "</tr>"
                        + "<tr>"
                        + "<td><font color='green'> Completed Date </font></td>"
                        + "<td> : </td>"
                        + "<td><font color='green'>"
                        + Time.get_date(completed_date, "dd/MM/yyyy hh:mm:ss a")
                        + " </font></td>"
                        + "</tr>"
                        + "</Table></html>";

              } else if (completed_date == 0) {
                msg =
                    "<html><Table>"
                        + "<tr>"
                        + "<td><font color='red'> FreeCheckup Status </font></td>"
                        + "<td> : </td>"
                        + "<td><font color='red'> Not Completed </font></td>"
                        + "</tr>"
                        + "<tr>"
                        + "<td><font color='red'> Due Date </font></td>"
                        + "<td> : </td>"
                        + "<td><font color='red'>"
                        + Time.get_date(due_date)
                        + " </font></td>"
                        + "</tr>"
                        + "</Table></html>";
              }
              JOptionPane.showMessageDialog(tbl_service_details, msg);
            } else {
              JOptionPane.showMessageDialog(
                  tbl_service_details, " This bill don't have any service which has Free Checkup");
            }
          }
        };

    @SuppressWarnings("unused")
    ButtonColumn buttonColumn = new ButtonColumn(tbl_service_details, update_fcd, 9);

    tbl_service_details.addMouseListener(
        new java.awt.event.MouseAdapter() {
          @Override
          public void mouseClicked(java.awt.event.MouseEvent evt) {

            int col = tbl_service_details.columnAtPoint(evt.getPoint());
            int row = tbl_service_details.rowAtPoint(evt.getPoint());

            ServiceBill obj_service_bill = null;

            int index = (int) tbl_service_details.getValueAt(row, 0) - 1;

            boolean is_fcd_update =
                (col == 8 && fcd_completed_due_date.get(index) > 0) ? true : false;

            if (col == 0 || is_fcd_update) {
              String date_str = tbl_service_details.getValueAt(row, 4).toString();

              obj_service_bill = dbh.get_service_bill(vehicle_id.get(index), date_str);
            }

            if ((col == 0 || is_fcd_update) && obj_service_bill == null) {

              JOptionPane.showMessageDialog(
                  tbl_service_details, "Error while getting service bill object");
              Logger.log.severe(
                  "Error while getting service bill object for service bill id " + index);

            } else if (col == 0) {

              wheel_bill_print obj_wbp = new wheel_bill_print(obj_service_bill.getId());

              obj_wbp.setVisible(true);

            } else if (is_fcd_update) {

              int epoch = (boolean) tbl_service_details.getValueAt(row, col) ? Time.now() : 0;

              fcd_completed_date.set(index, epoch);

              obj_service_bill.setFree_checkup_completed(epoch);
              dbh.update(obj_service_bill);
            }
          }
        });

    JTableHeader obj_jtable_header = tbl_service_details.getTableHeader();
    obj_jtable_header.setBackground(Color.BLUE);
    obj_jtable_header.setForeground(Color.WHITE);
    obj_jtable_header.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 12));

    JScrollPane jsp_service_details = new JScrollPane(tbl_service_details);
    jsp_service_details.setForeground(new Color(102, 153, 255));
    jsp_service_details.setBorder(new MatteBorder(3, 3, 3, 3, (Color) new Color(204, 51, 102)));
    jsp_service_details.setBackground(new Color(204, 102, 153));
    jsp_service_details.setBounds(20, 120, window_width - 40, window_height - 220);
    add(jsp_service_details);

    int tbl_width = jsp_service_details.getWidth();

    tbl_service_details.getColumn("S.NO").setMaxWidth((tbl_width / 100) * 4);
    tbl_service_details.getColumn("Customer Name").setPreferredWidth((tbl_width / 100) * 9);
    tbl_service_details.getColumn("Mobile No").setWidth((tbl_width / 100) * 9);
    tbl_service_details.getColumn("Vehicle No").setWidth((tbl_width / 100) * 7);
    tbl_service_details.getColumn("Bill Date").setWidth((tbl_width / 100) * 10);
    tbl_service_details.getColumn("Remarks").setPreferredWidth((tbl_width / 100) * 8);
    tbl_service_details.getColumn("Total").setMaxWidth((tbl_width / 100) * 8);
    tbl_service_details.getColumn("FCD").setMaxWidth((tbl_width / 100) * 10);
    tbl_service_details.getColumn("Info").setMaxWidth((tbl_width / 100) * 8);
    tbl_service_details.getColumn("Particulars").setPreferredWidth((tbl_width / 100) * 28);

    rowSorter = new TableRowSorter<>(tbl_service_details.getModel());
    tbl_service_details.setRowSorter(rowSorter);

    JPanel pnl_search = new JPanel();
    pnl_search.setBackground(new Color(204, 51, 153));
    pnl_search.setBorder(new MatteBorder(3, 3, 3, 3, (Color) new Color(204, 51, 153)));
    pnl_search.setBounds(20, 95, tbl_width, 30);
    add(pnl_search);
    pnl_search.setLayout(new BoxLayout(pnl_search, BoxLayout.X_AXIS));

    JLabel lbl_search_word = new JLabel("Search Text        ");
    lbl_search_word.setBackground(new Color(204, 153, 0));
    lbl_search_word.setAlignmentX(Component.CENTER_ALIGNMENT);
    pnl_search.add(lbl_search_word);
    lbl_search_word.setForeground(new Color(255, 255, 153));
    lbl_search_word.setFont(new Font("Bitstream Charter", Font.BOLD | Font.ITALIC, 18));

    txt_search_word = new JTextField();
    txt_search_word.setBackground(new Color(255, 255, 255));
    pnl_search.add(txt_search_word);
    txt_search_word.setColumns(10);
    txt_search_word
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              @Override
              public void insertUpdate(DocumentEvent e) {

                String text = txt_search_word.getText();

                if (text.trim().length() == 0) {
                  rowSorter.setRowFilter(null);
                } else {
                  rowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
                }
                calculate_total();
              }

              @Override
              public void removeUpdate(DocumentEvent e) {

                String text = txt_search_word.getText();

                if (text.trim().length() == 0) {
                  rowSorter.setRowFilter(null);
                } else {
                  rowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
                }
                calculate_total();
              }

              @Override
              public void changedUpdate(DocumentEvent e) {
                throw new UnsupportedOperationException(
                    "Not supported yet."); // To change body of generated methods, choose Tools |
                                           // Templates.
              }
            });

    JPanel pnl_total = new JPanel();
    pnl_total.setBackground(Color.WHITE);
    pnl_total.setBorder(new MatteBorder(3, 3, 3, 3, (Color) new Color(204, 51, 153)));
    pnl_total.setBounds(20, window_height - 105, tbl_width, 40);
    add(pnl_total);
    pnl_total.setLayout(new BoxLayout(pnl_total, BoxLayout.X_AXIS));

    pnl_total.add(Box.createHorizontalGlue());

    lbl_total = new JLabel("Total        ");
    lbl_total.setBackground(new Color(204, 153, 0));
    lbl_total.setAlignmentX(Component.CENTER_ALIGNMENT);
    pnl_total.add(lbl_total);
    lbl_total.setForeground(Color.BLUE);
    lbl_total.setVisible(false);
    lbl_total.setFont(new Font("Bitstream Charter", Font.BOLD | Font.ITALIC, 18));

    btn_toggle_total = new JButton("Show Total");
    btn_toggle_total.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String btn_text = btn_toggle_total.getText();

            if (btn_text.equals("Show Total")) {
              lbl_total.setVisible(true);
              btn_toggle_total.setText("Hide Total");
            } else {
              lbl_total.setVisible(false);
              btn_toggle_total.setText("Show Total");
            }
          }
        });
    pnl_total.add(btn_toggle_total);

    cmb_search_catagory = new JComboBox<String>();
    cmb_search_catagory.setBounds((window_width / 2) - 245, 45, 225, 24);
    cmb_search_catagory.addItem("Vehicle Number");
    cmb_search_catagory.addItem("Customer Name");
    cmb_search_catagory.addItem("Date Period");
    cmb_search_catagory.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (cmb_search_catagory.getSelectedIndex() != 2) {
              load_all_sbd();
              calculate_total();
              jdp_from.setVisible(false);
              jdp_to.setVisible(false);
              txt_search_text.setVisible(true);
            } else {
              jdp_from.setVisible(true);
              jdp_to.setVisible(true);
              txt_search_text.setVisible(false);
            }
          }
        });
    add(cmb_search_catagory);

    jdp_from = new JXDatePicker();
    jdp_from.setDate(Calendar.getInstance().getTime());
    jdp_from.setFormats(new SimpleDateFormat("dd.MM.yyyy"));
    jdp_from.setBounds((window_width / 2), 28, 225, 24);
    jdp_from.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            load_sbd_bw_date_range();
          }
        });
    add(jdp_from);
    jdp_from.setVisible(false);

    jdp_to = new JXDatePicker();
    jdp_to.setDate(Calendar.getInstance().getTime());
    jdp_to.setFormats(new SimpleDateFormat("dd.MM.yyyy"));
    jdp_to.setBounds((window_width / 2), 58, 225, 24);
    jdp_to.setVisible(false);
    jdp_to.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jdp_from.getMonthView().setUpperBound(jdp_to.getDate());
            load_sbd_bw_date_range();
          }
        });
    add(jdp_to);

    txt_search_text = new JTextField();
    txt_search_text.setBorder(new LineBorder(new Color(0, 0, 0)));
    txt_search_text.setBounds((window_width / 2), 45, 225, 24);
    add(txt_search_text);
    txt_search_text
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              @Override
              public void insertUpdate(DocumentEvent e) {
                update_filter();
                calculate_total();
              }

              @Override
              public void removeUpdate(DocumentEvent e) {
                update_filter();
                calculate_total();
              }

              @Override
              public void changedUpdate(DocumentEvent e) {
                update_filter();
                calculate_total();
              }
            });

    calculate_total();

    txt_search_word.setText(Time.get_current_date_time());
  }