예제 #1
0
 // For the ending date, we want the end of the selected day which is
 public Date getEndDate() {
   gc.set(Calendar.DAY_OF_MONTH, (date + 1));
   gc.set(Calendar.AM_PM, Calendar.AM);
   gc.set(Calendar.HOUR, 23);
   gc.set(Calendar.MINUTE, 59);
   gc.set(Calendar.SECOND, 59);
   return (gc.getTime());
 }
예제 #2
0
  public static void refreshCalendar(int month, int year) {
    // instantiation
    String[] months = {
      "January",
      "February",
      "March",
      "April",
      "May",
      "June",
      "July",
      "August",
      "September",
      "October",
      "November",
      "December"
    };
    int numoday, startom; // Number Of Days, Start Of Month

    // Allow/disallow buttons
    prev.setEnabled(true);
    next.setEnabled(true);
    if (month == 0 && year <= ryear) {
      prev.setEnabled(false);
    } // Cannot set an appointment back in time
    if (month == 11 && year >= ryear + 50) {
      next.setEnabled(false);
    } // Too early to set an appointment
    lmonth.setText(months[month]); // Refresh the month label (at the top)
    lmonth.setBounds(
        160 - lmonth.getPreferredSize().width / 2, 25, 180, 25); // Re-align label with calendar
    cyear.setSelectedItem(String.valueOf(year)); // Select the correct year in the combo box

    // deletes current table
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 7; j++) {
        mcal.setValueAt(null, i, j);
      }
    }

    // Get first day of month and number of days
    GregorianCalendar cal = new GregorianCalendar(year, month, 1);
    numoday = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
    startom = cal.get(GregorianCalendar.DAY_OF_WEEK);

    // Create calendar
    for (int i = 1; i <= numoday; i++) {
      int row = new Integer((i + startom - 2) / 7);
      int column = (i + startom - 2) % 7;
      mcal.setValueAt(i, row, column);
    }

    // Apply renderers
    Cal.setDefaultRenderer(Cal.getColumnClass(0), new tblCalendarRenderer());
  }
예제 #3
0
 public void jButtonStart_actionPerformed(ActionEvent e) {
   GregorianCalendar now = new GregorianCalendar();
   if (now.before(new GregorianCalendar(2005, 12, 31))) {
     jButtonStop.setEnabled(true);
     server = new Server(this);
     server.start();
     //        System.out.println(System.getProperty("sun.boot.class.path"));
     statusBar.setText("Server is running...");
     jButtonStart.setEnabled(false);
     jButtonConfig.setEnabled(false);
   } else {
     JOptionPane.showMessageDialog(
         this,
         "Evaluation License has expired or is obsolete;\nplease contact vendor for renewal.",
         "License Error",
         JOptionPane.ERROR_MESSAGE);
   }
 }
예제 #4
0
 /**
  * Set calendar to this week's Monday; set year and week combo boxes to the currently set date;
  * set the date labels appropriately; and, refresh the review table.
  */
 private void updateYearWeekDates() {
   yearWeekCalendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
   yearWeekCalendar.set(Calendar.HOUR_OF_DAY, 0);
   yearWeekCalendar.set(Calendar.MINUTE, 0);
   yearWeekCalendar.set(Calendar.SECOND, 0);
   yearWeekCalendar.set(Calendar.MILLISECOND, 0);
   yearCB.setSelectedItem(yearWeekCalendar.get(Calendar.YEAR));
   weekCB.setSelectedItem(yearWeekCalendar.get(Calendar.WEEK_OF_YEAR));
   fromDate.setDate(yearWeekCalendar);
   yearWeekCalendar.add(Calendar.DAY_OF_MONTH, 7);
   toDate.setDate(yearWeekCalendar);
   yearWeekCalendar.add(Calendar.DAY_OF_MONTH, -7);
   refreshReviewTable();
 }
예제 #5
0
 {
   addItem("Custom");
   int currentYear = yearWeekCalendar.get(Calendar.YEAR);
   for (int year = currentYear - 5; year <= currentYear + 5; year++) addItem(year);
   addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent ae) {
           if (yearCB.getSelectedIndex() == 0) return;
           yearWeekCalendar.set(Calendar.YEAR, (Integer) yearCB.getSelectedItem());
           updateYearWeekDates();
         }
       });
 }
 private static GregorianCalendar parseDate(final String dateString) {
   GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
   try {
     calendar.set(Calendar.YEAR, Integer.parseInt(dateString.substring(0, 4)));
     calendar.set(Calendar.MONTH, Integer.parseInt(dateString.substring(4, 6)) - 1);
     calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateString.substring(6, 8)));
     if (dateString.length() > 8) {
       calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(dateString.substring(8, 10)));
       calendar.set(Calendar.MINUTE, Integer.parseInt(dateString.substring(10, 12)));
     } else {
       calendar.set(Calendar.HOUR_OF_DAY, 0);
       calendar.set(Calendar.MINUTE, 0);
     }
   } catch (Exception ignore) {
   }
   return calendar;
 }
예제 #7
0
  // Generates a unique filename based on the current date and time.
  private String getUniqueFileName() {

    GregorianCalendar now = new GregorianCalendar();
    String fileName =
        ""
            + now.get(Calendar.YEAR)
            + now.get(Calendar.MONTH)
            + now.get(Calendar.DATE)
            + now.get(Calendar.HOUR_OF_DAY)
            + now.get(Calendar.MINUTE)
            + now.get(Calendar.SECOND)
            + now.get(Calendar.MILLISECOND);

    return fileName + ".jpg";
  }
예제 #8
0
 /** Refreshes the label's text according to the current date. */
 private void refresh() {
   setText(dateFormat.format(calendar.getTime()));
 }
예제 #9
0
 /**
  * Obtains the date associated with the label.
  *
  * @return The date.
  */
 Date getDate() {
   return calendar.getTime();
 }
예제 #10
0
 /**
  * A method used to set the date externally (not through {@link DateChooser}).
  *
  * @param calendar The calendar to clone.
  */
 void setDate(GregorianCalendar calendar) {
   this.calendar = (GregorianCalendar) calendar.clone();
   refresh();
 }
  /** Creates new form frmAsignarTransporte */
  public frmAsignarTransporte() {
    initComponents();
    gestorH.actualizarUsuario(labelusuario);
    txtFecha.setEditable(false);
    txtFecha.setEnabled(false);
    txtHora.setEditable(false);
    txtHora.setEnabled(false);
    // setear el campo de fecha con la del sistema
    GregorianCalendar gc = new GregorianCalendar();
    GregorianCalendar.getInstance();
    gc.setTimeZone(TimeZone.getTimeZone("GMT-3"));
    gc.get(Calendar.DAY_OF_WEEK);
    gc.get(Calendar.MONTH);
    gc.get(Calendar.YEAR);
    SimpleDateFormat formateador = new SimpleDateFormat("dd-MM-yyyy");
    txtFecha.setText(formateador.format(gc.getTime()));
    // setear el campo de hora con la del sistema
    GregorianCalendar calendario = new GregorianCalendar();
    GregorianCalendar.getInstance();
    gc.setTimeZone(TimeZone.getTimeZone("GMT-3"));
    calendario.get(Calendar.HOUR);
    calendario.get(Calendar.MINUTE);
    SimpleDateFormat formateadorHora = new SimpleDateFormat("HH:mm");
    txtHora.setText(formateadorHora.format(calendario.getTime()));

    // Las siguientes lineas son para dar a la pantalla el tamaño requerido y luego centrarla en la
    // pantalla.
    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension tamanioPantalla = kit.getScreenSize();
    int ancho = 820;
    int alto = 570;
    //        int posX = (int) ((tamanioPantalla.width - ancho) / 2);
    //        int posY = (int) ((tamanioPantalla.height - alto) / 2);
    this.setSize(ancho, alto);
    this.setLocation(260, 30);

    // redimensionar columnas tabla
    tblViaje.getColumnModel().getColumn(0).setPreferredWidth(50);
    tblViaje.getColumnModel().getColumn(1).setPreferredWidth(50);
    tblViaje.getColumnModel().getColumn(2).setPreferredWidth(100);
    tblVehiculo.getColumnModel().getColumn(0).setPreferredWidth(100);
    tblVehiculo.getColumnModel().getColumn(1).setPreferredWidth(100);
    // centrar cabecera jtable
    DefaultTableCellRenderer renderer =
        (DefaultTableCellRenderer) tblVehiculo.getTableHeader().getDefaultRenderer();
    renderer.setHorizontalAlignment(0);
    DefaultTableCellRenderer renderer2 =
        (DefaultTableCellRenderer) tblViaje.getTableHeader().getDefaultRenderer();
    renderer2.setHorizontalAlignment(0);

    Iterator ite = gestorH.listarClase(Viaje.class).iterator();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy");
    SimpleDateFormat sdfguion = new SimpleDateFormat("dd-MM-yyyy");
    while (ite.hasNext()) {
      Viaje viaje = (Viaje) ite.next();
      Date fecha1 = sdf.parse(viaje.getFecha(), new ParsePosition(0));
      Date fecha3 = sdfguion.parse(txtFecha.getText(), new ParsePosition(0));
      if (viaje.getEstado().equalsIgnoreCase("En Proceso")
          && (viaje.getTipoViaje().getNombreTipoViaje().equalsIgnoreCase("Traslado a Puerto")
              || viaje
                  .getTipoViaje()
                  .getNombreTipoViaje()
                  .equalsIgnoreCase("Traslado a Establecimiento"))) {
        if (fecha1.before(fecha3)) {
          viaje.setEstado("Finalizado");
          viaje.getVehiculo().setEstado("Disponible");
        }
      }
    }

    gestorA.RellenarTablaViajes(tblViaje);
  }
예제 #12
0
 public LogDateChooser(String label) {
   thisDialog = this;
   border = new EtchedBorder();
   setBorder(border);
   Font f = new Font("Helvetica", Font.PLAIN, 10);
   title = new JLabel(label);
   add(title);
   setLayout(new DateLayout());
   dfs = new DateFormatSymbols();
   months = dfs.getMonths();
   weekdays = dfs.getShortWeekdays();
   for (int i = 0; i < 7; i++) {
     days[i] = new JLabel(weekdays[i + 1]);
     days[i].setFont(f);
     add(days[i]);
   }
   gc = new GregorianCalendar();
   mDown = new JButton("<");
   mDown.setMargin(new Insets(0, 0, 0, 0));
   mDown.addActionListener(new MDownEar());
   mDown.setBorderPainted(false);
   mDown.setFont(f);
   mDown.setForeground(Color.BLUE);
   add(mDown);
   mUp = new JButton(">");
   mUp.setMargin(new Insets(0, 0, 0, 0));
   mUp.addActionListener(new MUpEar());
   mUp.setBorderPainted(false);
   mUp.setFont(f);
   mUp.setForeground(Color.BLUE);
   add(mUp);
   month = new JLabel(months[gc.get(Calendar.MONTH)]);
   month.setHorizontalAlignment(SwingConstants.CENTER);
   month.setFont(f);
   add(month);
   year = new JLabel(new Integer(gc.get(Calendar.YEAR)).toString());
   year.setFont(f);
   add(year);
   yDown = new JButton("<");
   yDown.setMargin(new Insets(0, 0, 0, 0));
   yDown.addActionListener(new YDownEar());
   yDown.setBorderPainted(false);
   yDown.setFont(f);
   yDown.setForeground(Color.BLUE);
   add(yDown);
   yUp = new JButton(">");
   yUp.setMargin(new Insets(0, 0, 0, 0));
   yUp.addActionListener(new YUpEar());
   yUp.setBorderPainted(false);
   yUp.setFont(f);
   yUp.setForeground(Color.BLUE);
   add(yUp);
   //    System.out.println(year.getText());
   NumberEar numberEar = new NumberEar();
   for (int i = 0; i < 31; i++) {
     number[i] = new JButton(new Integer(i + 1).toString());
     number[i].setMargin(new Insets(0, 0, 0, 0));
     number[i].addActionListener(numberEar);
     number[i].setBorderPainted(false);
     number[i].setContentAreaFilled(false);
     number[i].setFont(f);
     number[i].setForeground(Color.BLUE);
     add(number[i]);
   }
   number[0].setForeground(Color.CYAN);
 }
예제 #13
0
  public static void main(String args[]) {
    // style that is necessary
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e) {
    } catch (InstantiationException e) {
    } catch (IllegalAccessException e) {
    } catch (UnsupportedLookAndFeelException e) {
    }

    // Standard preparation for a frame
    fmain = new JFrame("Schedule Appointments"); // Create and name frame
    fmain.setSize(330, 375); // Set size to 400x400 pixels
    pane = fmain.getContentPane();
    pane.setLayout(null); // Apply null layout
    fmain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Close when X is clicked

    // controls and portions of Calendar
    lmonth = new JLabel("January");
    lyear = new JLabel("Change year:");
    cyear = new JComboBox();
    prev = new JButton("<<");
    next = new JButton(">>");
    canc = new JButton("Cancel");
    mcal =
        new DefaultTableModel() {
          public boolean isCellEditable(int rowIndex, int mColIndex) {
            return false;
          }
        };
    Cal = new JTable(mcal);
    scal = new JScrollPane(Cal);
    pcal = new JPanel(null);

    canc.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            System.exit(0);
          }
        });

    // action listeners for buttons and the like
    prev.addActionListener(new btnPrev_Action());
    next.addActionListener(new btnNext_Action());
    cyear.addActionListener(new cmbYear_Action());
    Cal.addMouseListener(new mouseCont());

    // Adding the elements to the pane
    pane.add(pcal);
    pcal.add(lmonth);
    pcal.add(cyear);
    pcal.add(prev);
    pcal.add(next);
    pcal.add(canc);
    pcal.add(scal);

    // Setting where the elements are on the pane
    pcal.setBounds(0, 0, 320, 335);
    lmonth.setBounds(160 - lmonth.getPreferredSize().width / 2, 25, 100, 25);
    canc.setBounds(10, 305, 80, 20);
    cyear.setBounds(215, 305, 100, 20);
    prev.setBounds(10, 25, 50, 25);
    next.setBounds(260, 25, 50, 25);
    scal.setBounds(10, 50, 300, 250);

    // Make frame visible
    fmain.setResizable(false);
    fmain.setVisible(true);

    // Inner workings for the day mechanism
    GregorianCalendar cal = new GregorianCalendar(); // Create calendar
    rday = cal.get(GregorianCalendar.DAY_OF_MONTH); // Get day
    rmonth = cal.get(GregorianCalendar.MONTH); // Get month
    ryear = cal.get(GregorianCalendar.YEAR); // Get year
    currentMonth = rmonth; // Match month and year
    currentYear = ryear;

    // Add days
    String[] days = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; // All of the days
    for (int i = 0; i < 7; i++) {
      mcal.addColumn(days[i]);
    }

    Cal.getParent().setBackground(Cal.getBackground()); // Set background

    // No resize/reorder
    Cal.getTableHeader().setResizingAllowed(false);
    Cal.getTableHeader().setReorderingAllowed(false);

    // Single cell selection
    Cal.setColumnSelectionAllowed(true);
    Cal.setRowSelectionAllowed(true);
    Cal.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    // Set row/column count
    Cal.setRowHeight(38);
    mcal.setColumnCount(7);
    mcal.setRowCount(6);

    // Placing the dates in the cells
    for (int i = ryear - 100; i <= ryear + 100; i++) {
      cyear.addItem(String.valueOf(i));
    }

    // Refresh calendar
    refreshCalendar(rmonth, ryear); // Refresh calendar
  }