public TelaCadastrarConsulta(TelaPrincipal t) {
    initComponents();
    this.tp = t;

    // Spinner de Hora
    JSpinner.DateEditor editorHora = new JSpinner.DateEditor(spinHorario, "HH:mm");
    JFormattedTextField ftfHora = editorHora.getTextField();
    ftfHora.setEditable(false);
    ftfHora.setHorizontalAlignment(JTextField.CENTER);
    spinHorario.setEditor(editorHora);
  }
Esempio n. 2
0
  @Override
  public Date getEntryDate() {

    // return DateUtils.removeTimeFromDate((Date) entryDateSpinnerModel
    // 		.getValue());

    String entryDateText = entryDateSpinnerEditor.getTextField().getText();
    if (entryDateText == null) {
      return null;
    }
    try {
      return DateUtils.parseDate(entryDateText);
    } catch (ParseException e) {
      return null;
    }
  }
  /**
   * Set up the calendar panel with the basic layout and components. These are not date specific.
   */
  private void createCalendarComponents() {
    // The date panel will hold the calendar and/or the time spinner

    JPanel datePanel = new JPanel(new BorderLayout(2, 2));

    // Create the calendar if we are displaying a calendar

    if ((selectedComponents & DISPLAY_DATE) > 0) {
      formatMonth = new SimpleDateFormat("MMM", locale);
      formatWeekDay = new SimpleDateFormat("EEE", locale);

      // Set up the shared keyboard bindings

      setInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
      setActionMap(actionMap);

      // Set up the decrement buttons

      yearDecrButton =
          new JButton(
              new ButtonAction(
                  "YearDecrButton",
                  "YearDecrButtonMnemonic",
                  "YearDecrButtonAccelerator",
                  "YearDecrButtonImage",
                  "YearDecrButtonShort",
                  "YearDecrButtonLong",
                  YEAR_DECR_BUTTON));
      monthDecrButton =
          new JButton(
              new ButtonAction(
                  "MonthDecrButton",
                  "MonthDecrButtonMnemonic",
                  "MonthDecrButtonAccelerator",
                  "MonthDecrButtonImage",
                  "MonthDecrButtonShort",
                  "MonthDecrButtonLong",
                  MONTH_DECR_BUTTON));
      JPanel decrPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0));
      decrPanel.add(yearDecrButton);
      decrPanel.add(monthDecrButton);

      // Set up the month/year label

      monthYearLabel = new JLabel();
      monthYearLabel.setHorizontalAlignment(JLabel.CENTER);

      // Set up the increment buttons

      monthIncrButton =
          new JButton(
              new ButtonAction(
                  "MonthIncrButton",
                  "MonthIncrButtonMnemonic",
                  "MonthIncrButtonAccelerator",
                  "MonthIncrButtonImage",
                  "MonthIncrButtonShort",
                  "MonthIncrButtonLong",
                  MONTH_INCR_BUTTON));
      yearIncrButton =
          new JButton(
              new ButtonAction(
                  "YearIncrButton",
                  "YearIncrButtonMnemonic",
                  "YearIncrButtonAccelerator",
                  "YearIncrButtonImage",
                  "YearIncrButtonShort",
                  "YearIncrButtonLong",
                  YEAR_INCR_BUTTON));
      JPanel incrPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0));
      incrPanel.add(monthIncrButton);
      incrPanel.add(yearIncrButton);

      // Put them all together

      JPanel monthYearNavigator = new JPanel(new BorderLayout(2, 2));
      monthYearNavigator.add(decrPanel, BorderLayout.WEST);
      monthYearNavigator.add(monthYearLabel);
      monthYearNavigator.add(incrPanel, BorderLayout.EAST);

      // Set up the day panel

      JPanel dayPanel = new JPanel(new GridLayout(7, 7));
      int firstDay = displayCalendar.getFirstDayOfWeek();

      // Get the week day labels. The following technique is used so
      // that we can start the calendar on the right day of the week and
      // we can get the week day labels properly localized

      Calendar temp = Calendar.getInstance(locale);
      temp.set(2000, Calendar.MARCH, 15);
      while (temp.get(Calendar.DAY_OF_WEEK) != firstDay) {
        temp.add(Calendar.DATE, 1);
      }
      dayOfWeekLabels = new JLabel[7];
      for (int i = 0; i < 7; i++) {
        Date date = temp.getTime();
        String dayOfWeek = formatWeekDay.format(date);
        dayOfWeekLabels[i] = new JLabel(dayOfWeek);
        dayOfWeekLabels[i].setHorizontalAlignment(JLabel.CENTER);
        dayPanel.add(dayOfWeekLabels[i]);
        temp.add(Calendar.DATE, 1);
      }

      // Add all the day buttons

      dayButtons = new JToggleButton[6][7];
      dayGroup = new ButtonGroup();
      DayListener dayListener = new DayListener();
      for (int row = 0; row < 6; row++) {
        for (int day = 0; day < 7; day++) {
          dayButtons[row][day] = new JToggleButton();
          dayButtons[row][day].addItemListener(dayListener);
          dayPanel.add(dayButtons[row][day]);
          dayGroup.add(dayButtons[row][day]);
        }
      }

      // We add this special button to the button group, so we have a
      // way of unselecting all the visible buttons

      offScreenButton = new JToggleButton("X");
      dayGroup.add(offScreenButton);

      // Combine the navigators and days

      datePanel.add(monthYearNavigator, BorderLayout.NORTH);
      datePanel.add(dayPanel);
    }

    // Create the time spinner field if we are displaying the time

    if ((selectedComponents & DISPLAY_TIME) > 0) {

      // Create the time component

      spinnerDateModel = new SpinnerDateModel();
      spinnerDateModel.addChangeListener(new TimeListener());
      spinner = new JSpinner(spinnerDateModel);

      JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(spinner, timePattern);
      dateEditor.getTextField().setEditable(false);
      dateEditor.getTextField().setHorizontalAlignment(JTextField.CENTER);
      spinner.setEditor(dateEditor);

      // Set the input/action maps for the spinner. (Only BACK_SPACE
      // seems to work!)

      InputMap sim = new InputMap();
      sim.put(KeyStroke.getKeyStroke("BACK_SPACE"), "setNullDate");
      sim.put(KeyStroke.getKeyStroke("DELETE"), "setNullDate");
      sim.setParent(spinner.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));

      ActionMap sam = new ActionMap();
      sam.put(
          "setNullDate",
          new AbstractAction("setNullDate") {
            public void actionPerformed(ActionEvent e) {
              JCalendar.this.setDate(null);
            }
          });
      sam.setParent(spinner.getActionMap());

      spinner.setInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, sim);
      spinner.setActionMap(sam);

      // Create a special panel for the time display

      JPanel timePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 2, 2));
      timePanel.add(spinner);

      // Now add it to the bottom

      datePanel.add(timePanel, BorderLayout.SOUTH);
    }

    setLayout(new BorderLayout(2, 2));
    add(datePanel);

    // Add today's date at the bottom of the calendar/time, if needed

    if (isTodayDisplayed) {
      Object[] args = {new Date()};
      String todaysDate = MessageFormat.format(bundle.getString("Today"), args);
      todaysLabel = new JLabel(todaysDate);
      todaysLabel.setHorizontalAlignment(JLabel.CENTER);

      // Add today's date at the very bottom

      add(todaysLabel, BorderLayout.SOUTH);
    }
  }
  /** Creates the GUI */
  private void createGUI() {
    JPanel content = (JPanel) this.getContentPane();
    content.setLayout(new BorderLayout());
    content.setBorder(UiUtilities.DIALOG_BORDER);

    Vector<String> data = new Vector<String>();

    data.add(TIMETEXT[0]);
    data.add(TIMETEXT[1]);
    data.add(TIMETEXT[2]);

    TimeFormatter formatter = new TimeFormatter();

    for (int time : mTimes) {
      int h = time / 60;
      int m = time % 60;
      StringBuilder builder = new StringBuilder();
      builder.append(mLocalizer.msg("at", "at"));
      builder.append(' ');
      builder.append(formatter.formatTime(h, m));
      data.add(builder.toString());
    }

    data.add(mLocalizer.msg("configureTimes", "Configure Times"));

    mBox = new JComboBox(data);

    mBox.addActionListener(
        new ActionListener() {

          private int lastSelected = 0;

          public void actionPerformed(ActionEvent e) {
            if (mBox.getSelectedIndex() == mBox.getItemCount() - 1) {
              mBox.setSelectedIndex(lastSelected);
              Plugin.getPluginManager().showSettings(SettingsItem.TIMEBUTTONS);
            } else {
              lastSelected = mDate.getSelectedIndex();
              int time = calcTimeForSelection(mBox.getSelectedIndex());
              generateList(new Date(), time);
            }
          }
        });

    ButtonGroup group = new ButtonGroup();
    group.add(mRuns);
    group.add(mOn);

    JPanel datetimeselect = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));

    Vector<Date> dates = new Vector<Date>();

    Date currentDate = Date.getCurrentDate();
    for (int i = 0; i < 14; i++) {
      dates.add(currentDate.addDays(i));
    }

    mDate = new JComboBox(dates);

    datetimeselect.add(mDate);

    datetimeselect.add(new JLabel(" " + mLocalizer.msg("at", "at") + " "));

    JSpinner.DateEditor dateEditor =
        new JSpinner.DateEditor(mTimeSpinner, Settings.getTimePattern());

    mTimeSpinner.setEditor(dateEditor);

    CaretPositionCorrector.createCorrector(dateEditor.getTextField(), new char[] {':'}, -1);

    datetimeselect.add(mTimeSpinner);

    Vector<String> filters = new Vector<String>();
    filters.add(mLocalizer.msg("filterAll", "all channels"));
    for (String filterName : FilterComponentList.getInstance().getChannelFilterNames()) {
      filters.add(filterName);
    }
    filters.add(mLocalizer.ellipsisMsg("filterDefine", "define filter"));
    mChannels = new JComboBox(filters);
    datetimeselect.add(new JLabel("    "));
    datetimeselect.add(mChannels);

    // Event-Handler

    mRuns.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            refreshView();
          }
        });

    mOn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            refreshView();
          }
        });

    mDate.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            refreshView();
          }
        });

    mTimeSpinner.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent arg0) {
            refreshView();
          }
        });

    mChannels.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // user defined selection
            if (mChannels.getSelectedIndex() == mChannels.getItemCount() - 1) {
              EditFilterComponentDlg dlg =
                  new EditFilterComponentDlg(null, null, ChannelFilterComponent.class);
              FilterComponent rule = dlg.getFilterComponent();
              if (rule == null) {
                return;
              }
              if (!(rule instanceof ChannelFilterComponent)) {
                return;
              }
              FilterComponentList.getInstance().add(rule);
              FilterComponentList.getInstance().store();
              String filterName = rule.getName();
              mChannels.removeAllItems();
              mChannels.addItem(mLocalizer.msg("filterAll", "all channels"));
              for (String channel : FilterComponentList.getInstance().getChannelFilterNames()) {
                mChannels.addItem(channel);
              }
              mChannels.addItem(mLocalizer.ellipsisMsg("filterDefine", "define filter"));
              mChannels.setSelectedItem(filterName);
            }
            mModel.removeAllRows();
            refreshView();
          }
        });

    mRuns.setSelected(true);
    mDate.setEnabled(false);
    mTimeSpinner.setEnabled(false);

    JLabel filterLabel = new JLabel("Filter:");
    filterLabel.setHorizontalAlignment(SwingConstants.RIGHT);

    mFilterBox = new JComboBox(Plugin.getPluginManager().getFilterManager().getAvailableFilters());
    mFilterBox.setSelectedItem(Plugin.getPluginManager().getFilterManager().getCurrentFilter());
    mFilterBox.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
              mCurrentFilter = (ProgramFilter) e.getItem();
              refreshView();
            }
          }
        });

    // Upper Panel

    JPanel topPanel =
        new JPanel(
            new FormLayout(
                "pref, 3dlu, pref, 15dlu, pref, 3dlu, pref, 3dlu, pref", "pref, 1dlu, pref, 3dlu"));

    CellConstraints cc = new CellConstraints();

    topPanel.add(mRuns, cc.xy(1, 1));
    topPanel.add(mBox, cc.xy(3, 1));
    topPanel.add(mOn, cc.xy(5, 1));
    topPanel.add(datetimeselect, cc.xy(7, 1));

    topPanel.add(filterLabel, cc.xy(1, 3));
    topPanel.add(mFilterBox, cc.xyw(3, 3, 5));

    content.add(topPanel, BorderLayout.NORTH);

    // Rest of the GUI
    mProgramTable = new ListTable(mModel);
    mProgramTable.getTableHeader().setReorderingAllowed(false);
    mProgramTable.getTableHeader().setResizingAllowed(false);
    mProgramTable.setToolTipText("");

    mProgramTable.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
              showPopup(evt);
            }
          }

          @Override
          public void mouseReleased(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
              showPopup(evt);
            }
          }

          @Override
          public void mouseClicked(MouseEvent e) {
            mouseClickedOnTable(e);
          }
        });

    // Dispatch the KeyEvent to the RootPane for Closing the Dialog.
    // Needed for Java 1.4.
    mProgramTable.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            mProgramTable.getRootPane().dispatchEvent(e);
          }
        });

    setTableColumProperties();

    JScrollPane scroll =
        new JScrollPane(
            mProgramTable,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    content.add(scroll, BorderLayout.CENTER);

    JPanel buttonPn = new JPanel(new BorderLayout());
    buttonPn.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    content.add(buttonPn, BorderLayout.SOUTH);

    JButton closeButton = new JButton(Localizer.getLocalization(Localizer.I18N_CLOSE));
    closeButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent evt) {
            dispose();
          }
        });

    JPanel p = new JPanel(new FormLayout("pref,5dlu,pref,5dlu,pref", "pref"));
    JButton settings = new JButton(TVBrowserIcons.preferences(TVBrowserIcons.SIZE_SMALL));
    settings.setToolTipText(mLocalizer.msg("settings", "Open settings"));

    settings.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            close();
            Plugin.getPluginManager().showSettings(ListViewPlugin.getInstance());
          }
        });

    final JCheckBox showAtStartup = new JCheckBox(mLocalizer.msg("showAtStart", "Show at start"));
    showAtStartup.setSelected(mSettings.getProperty("showAtStartup", "false").equals("true"));

    showAtStartup.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            if (showAtStartup.isSelected()) {
              mSettings.setProperty("showAtStartup", "true");
            } else {
              mSettings.setProperty("showAtStartup", "false");
            }
          }
        });

    p.add(settings, cc.xy(1, 1));
    p.add(showAtStartup, cc.xy(3, 1));

    buttonPn.add(p, BorderLayout.WEST);

    buttonPn.add(closeButton, BorderLayout.EAST);
    getRootPane().setDefaultButton(closeButton);
  }
Esempio n. 5
0
 @Override
 public Object getCellEditorValue() {
   return timeEditor.getFormat().format(timeSpinner.getValue());
 }
Esempio n. 6
0
  @Override
  protected void createComponents() {
    super.createComponents();

    Date initDate = DateUtils.currentDate();
    Date latestDate = initDate;
    Date earliestDate = DateUtils.earliestDate();

    entryDateLabel = new JLabel("Entry Date:");

    entryDateSpinnerModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);
    entryDateSpinner = new JSpinner(entryDateSpinnerModel);
    entryDateSpinnerEditor = new JSpinner.DateEditor(entryDateSpinner, DateUtils.DATE_FORMAT);
    entryDateSpinner.setEditor(entryDateSpinnerEditor);
    entryDateSpinnerEditor
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {

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

              @Override
              public void insertUpdate(DocumentEvent e) {
                processChange(e);
              }

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

              private void processChange(DocumentEvent e) {
                if (eventsAreDisabled()) {
                  return;
                }
                if (entryDateSpinnerEditor.getTextField().hasFocus()) {
                  entryDateChanged();
                }
              }
            });
    //		entryDateSpinner.addChangeListener(new ChangeListener() {
    //			@Override
    //			public void stateChanged(ChangeEvent e) {
    //				if (eventsAreDisabled()) {
    //					return;
    //				}
    //				entryDateChanged();
    //			}
    //		});

    countLabel = new JLabel("Count:");

    countField = new JTextField(5);
    countField.addKeyListener(
        new KeyListener() {
          @Override
          public void keyPressed(KeyEvent e) {
            return;
          }

          @Override
          public void keyReleased(KeyEvent e) {
            if (eventsAreDisabled()) {
              return;
            }
            countChanged();
          }

          @Override
          public void keyTyped(KeyEvent arg0) {
            return;
          }
        });
  }