/** Generates the List of Programs */ private void generateList(Date date, int time) { // If Time > 24 try next Day if (time > 60 * 24) { date = date.addDays(1); time -= 60 * 24; } Channel[] channels = Plugin.getPluginManager().getSubscribedChannels(); if ((mChannels != null) && (mChannels.getSelectedIndex() > 0)) { FilterComponent component = FilterComponentList.getInstance() .getFilterComponentByName(mChannels.getSelectedItem().toString()); if (component instanceof ChannelFilterComponent) { channels = ((ChannelFilterComponent) component).getChannels(); } } for (Channel channel : channels) { Program prg = findProgram(date, time, channel, false); Program nprg = null; if (prg == null) { prg = findProgram(date.addDays(-1), time + 60 * 24, channel, false); } if (prg != null) { nprg = findNextProgram(prg); } else { Iterator<Program> it = Plugin.getPluginManager().getChannelDayProgram(date, channel); if (it.hasNext()) { Program p = it.next(); if (p.getStartTime() > time && mCurrentFilter.accept(p)) { nprg = p; } else { nprg = findProgram(date, time + 60, channel, true); } } else { nprg = findProgram(date, time + 60, channel, true); } if (nprg == null) { it = Plugin.getPluginManager().getChannelDayProgram(date.addDays(1), channel); while (it.hasNext() && nprg == null) { Program p = it.next(); if (!p.isExpired() && mCurrentFilter.accept(p)) { nprg = p; } } } } mModel.updateRow(channel, prg, nprg); } }
/** 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); }