use of net.pms.newgui.components.CustomJButton in project UniversalMediaServer by UniversalMediaServer.
the class NavigationShareTab method initSharedFoldersGuiComponents.
private PanelBuilder initSharedFoldersGuiComponents(CellConstraints cc) {
// Apply the orientation for the locale
ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
String colSpec = FormLayoutUtil.getColSpec(SHARED_FOLDER_COL_SPEC, orientation);
FormLayout layoutFolders = new FormLayout(colSpec, SHARED_FOLDER_ROW_SPEC);
PanelBuilder builderFolder = new PanelBuilder(layoutFolders);
builderFolder.opaque(true);
JComponent cmp = builderFolder.addSeparator(Messages.getString("FoldTab.7"), FormLayoutUtil.flip(cc.xyw(1, 1, 7), colSpec, orientation));
cmp = (JComponent) cmp.getComponent(0);
cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
folderTableModel = new SharedFoldersTableModel();
FList = new JTable(folderTableModel);
TableColumn column = FList.getColumnModel().getColumn(0);
column.setMinWidth(650);
JPopupMenu popupMenu = new JPopupMenu();
JMenuItem menuItemMarkPlayed = new JMenuItem(Messages.getString("FoldTab.75"));
JMenuItem menuItemMarkUnplayed = new JMenuItem(Messages.getString("FoldTab.76"));
menuItemMarkPlayed.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String path = (String) FList.getValueAt(FList.getSelectedRow(), 0);
TableFilesStatus.setDirectoryFullyPlayed(path, true);
}
});
menuItemMarkUnplayed.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String path = (String) FList.getValueAt(FList.getSelectedRow(), 0);
TableFilesStatus.setDirectoryFullyPlayed(path, false);
}
});
popupMenu.add(menuItemMarkPlayed);
popupMenu.add(menuItemMarkUnplayed);
FList.setComponentPopupMenu(popupMenu);
FList.addMouseListener(new TableMouseListener(FList));
/* An attempt to set the correct row height adjusted for font scaling.
* It sets all rows based on the font size of cell (0, 0). The + 4 is
* to allow 2 pixels above and below the text. */
DefaultTableCellRenderer cellRenderer = (DefaultTableCellRenderer) FList.getCellRenderer(0, 0);
FontMetrics metrics = cellRenderer.getFontMetrics(cellRenderer.getFont());
FList.setRowHeight(metrics.getLeading() + metrics.getMaxAscent() + metrics.getMaxDescent() + 4);
FList.setIntercellSpacing(new Dimension(8, 2));
CustomJButton but = new CustomJButton(LooksFrame.readImageIcon("button-adddirectory.png"));
but.setToolTipText(Messages.getString("FoldTab.9"));
but.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser chooser;
try {
chooser = new JFileChooser();
} catch (Exception ee) {
chooser = new JFileChooser(new RestrictedFileSystemView());
}
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = chooser.showOpenDialog((Component) e.getSource());
if (returnVal == JFileChooser.APPROVE_OPTION) {
((SharedFoldersTableModel) FList.getModel()).addRow(new Object[] { chooser.getSelectedFile().getAbsolutePath(), true });
if (FList.getModel().getValueAt(0, 0).equals(ALL_DRIVES)) {
((SharedFoldersTableModel) FList.getModel()).removeRow(0);
}
updateModel();
}
}
});
builderFolder.add(but, FormLayoutUtil.flip(cc.xy(1, 3), colSpec, orientation));
CustomJButton but2 = new CustomJButton(LooksFrame.readImageIcon("button-remove.png"));
but2.setToolTipText(Messages.getString("FoldTab.36"));
but2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (FList.getSelectedRow() > -1) {
if (FList.getModel().getRowCount() == 0) {
folderTableModel.addRow(new Object[] { ALL_DRIVES, false });
} else {
PMS.get().getDatabase().removeMediaEntriesInFolder((String) FList.getValueAt(FList.getSelectedRow(), 0));
}
((SharedFoldersTableModel) FList.getModel()).removeRow(FList.getSelectedRow());
updateModel();
}
}
});
builderFolder.add(but2, FormLayoutUtil.flip(cc.xy(2, 3), colSpec, orientation));
CustomJButton but3 = new CustomJButton(LooksFrame.readImageIcon("button-arrow-down.png"));
but3.setToolTipText(Messages.getString("FoldTab.12"));
but3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < FList.getRowCount() - 1; i++) {
if (FList.isRowSelected(i)) {
Object value1 = FList.getValueAt(i, 0);
boolean value2 = (boolean) FList.getValueAt(i, 1);
FList.setValueAt(FList.getValueAt(i + 1, 0), i, 0);
FList.setValueAt(value1, i + 1, 0);
FList.setValueAt(FList.getValueAt(i + 1, 1), i, 1);
FList.setValueAt(value2, i + 1, 1);
FList.changeSelection(i + 1, 1, false, false);
break;
}
}
}
});
builderFolder.add(but3, FormLayoutUtil.flip(cc.xy(3, 3), colSpec, orientation));
CustomJButton but4 = new CustomJButton(LooksFrame.readImageIcon("button-arrow-up.png"));
but4.setToolTipText(Messages.getString("FoldTab.12"));
but4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
for (int i = 1; i < FList.getRowCount(); i++) {
if (FList.isRowSelected(i)) {
Object value1 = FList.getValueAt(i, 0);
boolean value2 = (boolean) FList.getValueAt(i, 1);
FList.setValueAt(FList.getValueAt(i - 1, 0), i, 0);
FList.setValueAt(value1, i - 1, 0);
FList.setValueAt(FList.getValueAt(i - 1, 1), i, 1);
FList.setValueAt(value2, i - 1, 1);
FList.changeSelection(i - 1, 1, false, false);
break;
}
}
}
});
builderFolder.add(but4, FormLayoutUtil.flip(cc.xy(4, 3), colSpec, orientation));
but5 = new CustomJButton(LooksFrame.readImageIcon("button-scan.png"));
but5.setToolTipText(Messages.getString("FoldTab.2"));
but5.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (configuration.getUseCache()) {
DLNAMediaDatabase database = PMS.get().getDatabase();
if (database != null) {
if (database.isScanLibraryRunning()) {
int option = JOptionPane.showConfirmDialog(looksFrame, Messages.getString("FoldTab.10"), Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION);
if (option == JOptionPane.YES_OPTION) {
database.stopScanLibrary();
looksFrame.setStatusLine(Messages.getString("FoldTab.41"));
setScanLibraryEnabled(false);
but5.setToolTipText(Messages.getString("FoldTab.41"));
}
} else {
database.scanLibrary();
but5.setIcon(LooksFrame.readImageIcon("button-scan-busy.gif"));
but5.setRolloverIcon(LooksFrame.readImageIcon("button-scan-cancel.png"));
but5.setToolTipText(Messages.getString("FoldTab.40"));
}
}
}
}
});
/**
* Hide the scan button in basic mode since we do it automatically now.
*/
if (!configuration.isHideAdvancedOptions()) {
builderFolder.add(but5, FormLayoutUtil.flip(cc.xy(5, 3), colSpec, orientation));
}
but5.setEnabled(configuration.getUseCache());
isScanSharedFoldersOnStartup = new JCheckBox(Messages.getString("NetworkTab.StartupScan"), configuration.isScanSharedFoldersOnStartup());
isScanSharedFoldersOnStartup.setToolTipText(Messages.getString("NetworkTab.StartupScanTooltip"));
isScanSharedFoldersOnStartup.setContentAreaFilled(false);
isScanSharedFoldersOnStartup.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setScanSharedFoldersOnStartup((e.getStateChange() == ItemEvent.SELECTED));
}
});
builderFolder.add(isScanSharedFoldersOnStartup, FormLayoutUtil.flip(cc.xy(7, 3), colSpec, orientation));
File[] folders = PMS.get().getSharedFoldersArray(false);
if (folders != null && folders.length > 0) {
File[] foldersMonitored = PMS.get().getSharedFoldersArray(true);
for (File folder : folders) {
boolean isMonitored = false;
if (foldersMonitored != null && foldersMonitored.length > 0) {
for (File folderMonitored : foldersMonitored) {
if (folderMonitored.getAbsolutePath().equals(folder.getAbsolutePath())) {
isMonitored = true;
}
}
}
folderTableModel.addRow(new Object[] { folder.getAbsolutePath(), isMonitored });
}
} else {
folderTableModel.addRow(new Object[] { ALL_DRIVES, false });
}
JScrollPane pane = new JScrollPane(FList);
Dimension d = FList.getPreferredSize();
pane.setPreferredSize(new Dimension(d.width, FList.getRowHeight() * 2));
builderFolder.add(pane, FormLayoutUtil.flip(cc.xyw(1, 5, 7), colSpec, orientation));
return builderFolder;
}
use of net.pms.newgui.components.CustomJButton in project UniversalMediaServer by UniversalMediaServer.
the class NavigationShareTab method initSimpleComponents.
private void initSimpleComponents(CellConstraints cc) {
// Thumbnail seeking position
seekpos = new JTextField("" + configuration.getThumbnailSeekPos());
seekpos.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
try {
int ab = Integer.parseInt(seekpos.getText());
configuration.setThumbnailSeekPos(ab);
if (configuration.getUseCache()) {
PMS.get().getDatabase().init(true);
}
} catch (NumberFormatException nfe) {
LOGGER.debug("Could not parse thumbnail seek position from \"" + seekpos.getText() + "\"");
}
}
});
if (configuration.isThumbnailGenerationEnabled()) {
seekpos.setEnabled(true);
} else {
seekpos.setEnabled(false);
}
// Generate thumbnails
thumbgenCheckBox = new JCheckBox(Messages.getString("NetworkTab.2"), configuration.isThumbnailGenerationEnabled());
thumbgenCheckBox.setContentAreaFilled(false);
thumbgenCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setThumbnailGenerationEnabled((e.getStateChange() == ItemEvent.SELECTED));
seekpos.setEnabled(configuration.isThumbnailGenerationEnabled());
mplayer_thumb.setEnabled(configuration.isThumbnailGenerationEnabled());
}
});
// Use MPlayer for video thumbnails
mplayer_thumb = new JCheckBox(Messages.getString("FoldTab.14"), configuration.isUseMplayerForVideoThumbs());
mplayer_thumb.setToolTipText(Messages.getString("FoldTab.61"));
mplayer_thumb.setContentAreaFilled(false);
mplayer_thumb.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setUseMplayerForVideoThumbs((e.getStateChange() == ItemEvent.SELECTED));
}
});
if (configuration.isThumbnailGenerationEnabled()) {
mplayer_thumb.setEnabled(true);
} else {
mplayer_thumb.setEnabled(false);
}
// DVD ISO thumbnails
dvdiso_thumb = new JCheckBox(Messages.getString("FoldTab.19"), configuration.isDvdIsoThumbnails());
dvdiso_thumb.setContentAreaFilled(false);
dvdiso_thumb.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setDvdIsoThumbnails((e.getStateChange() == ItemEvent.SELECTED));
}
});
// Image thumbnails
image_thumb = new JCheckBox(Messages.getString("FoldTab.21"), configuration.getImageThumbnailsEnabled());
image_thumb.setContentAreaFilled(false);
image_thumb.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setImageThumbnailsEnabled((e.getStateChange() == ItemEvent.SELECTED));
}
});
// Audio thumbnails import
final KeyedComboBoxModel<CoverSupplier, String> thumbKCBM = new KeyedComboBoxModel<>(new CoverSupplier[] { CoverSupplier.NONE, CoverSupplier.COVER_ART_ARCHIVE }, new String[] { Messages.getString("FoldTab.35"), Messages.getString("FoldTab.73") });
audiothumbnail = new JComboBox<>(thumbKCBM);
audiothumbnail.setEditable(false);
thumbKCBM.setSelectedKey(configuration.getAudioThumbnailMethod());
audiothumbnail.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
configuration.setAudioThumbnailMethod(thumbKCBM.getSelectedKey());
LOGGER.info("Setting {} {}", Messages.getRootString("FoldTab.26"), thumbKCBM.getSelectedValue());
}
}
});
// Alternate video cover art folder
defaultThumbFolder = new JTextField(configuration.getAlternateThumbFolder());
defaultThumbFolder.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
configuration.setAlternateThumbFolder(defaultThumbFolder.getText());
}
});
// Alternate video cover art folder button
select = new CustomJButton("...");
select.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser chooser;
try {
chooser = new JFileChooser();
} catch (Exception ee) {
chooser = new JFileChooser(new RestrictedFileSystemView());
}
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("FoldTab.28"));
if (returnVal == JFileChooser.APPROVE_OPTION) {
defaultThumbFolder.setText(chooser.getSelectedFile().getAbsolutePath());
configuration.setAlternateThumbFolder(chooser.getSelectedFile().getAbsolutePath());
}
}
});
// Show Server Settings folder
isShowFolderServerSettings = new JCheckBox(Messages.getString("FoldTab.38"), configuration.isShowServerSettingsFolder());
isShowFolderServerSettings.setContentAreaFilled(false);
isShowFolderServerSettings.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setShowServerSettingsFolder((e.getStateChange() == ItemEvent.SELECTED));
}
});
// Show #--TRANSCODE--# folder
isShowFolderTranscode = new JCheckBox(Messages.getString("FoldTab.33"), configuration.isShowTranscodeFolder());
isShowFolderTranscode.setContentAreaFilled(false);
isShowFolderTranscode.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setShowTranscodeFolder((e.getStateChange() == ItemEvent.SELECTED));
}
});
// Show Media Library folder
isShowFolderMediaLibrary = new JCheckBox(Messages.getString("FoldTab.32"), configuration.isShowMediaLibraryFolder());
isShowFolderMediaLibrary.setContentAreaFilled(false);
isShowFolderMediaLibrary.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setShowMediaLibraryFolder((e.getStateChange() == ItemEvent.SELECTED));
}
});
// Browse compressed archives
archive = new JCheckBox(Messages.getString("NetworkTab.1"), configuration.isArchiveBrowsing());
archive.setContentAreaFilled(false);
archive.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setArchiveBrowsing(e.getStateChange() == ItemEvent.SELECTED);
}
});
// Enable the cache
cacheenable = new JCheckBox(Messages.getString("NetworkTab.17"), configuration.getUseCache());
cacheenable.setToolTipText(Messages.getString("FoldTab.48"));
cacheenable.setContentAreaFilled(false);
cacheenable.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setUseCache((e.getStateChange() == ItemEvent.SELECTED));
cachereset.setEnabled(configuration.getUseCache());
setScanLibraryEnabled(configuration.getUseCache());
}
});
// Reset cache
cachereset = new CustomJButton(Messages.getString("NetworkTab.18"));
cachereset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int option = JOptionPane.showConfirmDialog(looksFrame, Messages.getString("NetworkTab.13") + "\n" + Messages.getString("NetworkTab.19"), Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION);
if (option == JOptionPane.YES_OPTION) {
PMS.get().getDatabase().init(true);
}
}
});
cachereset.setEnabled(configuration.getUseCache());
// Hide file extensions
hideextensions = new JCheckBox(Messages.getString("FoldTab.5"), configuration.isHideExtensions());
hideextensions.setContentAreaFilled(false);
if (configuration.isPrettifyFilenames()) {
hideextensions.setEnabled(false);
}
hideextensions.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setHideExtensions((e.getStateChange() == ItemEvent.SELECTED));
}
});
// Hide transcoding engine names
hideengines = new JCheckBox(Messages.getString("FoldTab.8"), configuration.isHideEngineNames());
hideengines.setToolTipText(Messages.getString("FoldTab.46"));
hideengines.setContentAreaFilled(false);
hideengines.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setHideEngineNames((e.getStateChange() == ItemEvent.SELECTED));
}
});
// Hide empty folders
hideemptyfolders = new JCheckBox(Messages.getString("FoldTab.31"), configuration.isHideEmptyFolders());
hideemptyfolders.setToolTipText(Messages.getString("FoldTab.59"));
hideemptyfolders.setContentAreaFilled(false);
hideemptyfolders.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setHideEmptyFolders((e.getStateChange() == ItemEvent.SELECTED));
}
});
// Show iTunes library
itunes = new JCheckBox(Messages.getString("FoldTab.30"), configuration.isShowItunesLibrary());
itunes.setToolTipText(Messages.getString("FoldTab.47"));
itunes.setContentAreaFilled(false);
if (!(Platform.isMac() || Platform.isWindows())) {
itunes.setEnabled(false);
}
itunes.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setShowItunesLibrary((e.getStateChange() == ItemEvent.SELECTED));
}
});
// Show iPhoto library
iphoto = new JCheckBox(Messages.getString("FoldTab.29"), configuration.isShowIphotoLibrary());
iphoto.setContentAreaFilled(false);
if (!Platform.isMac()) {
iphoto.setEnabled(false);
}
iphoto.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setShowIphotoLibrary((e.getStateChange() == ItemEvent.SELECTED));
}
});
// Show aperture library
aperture = new JCheckBox(Messages.getString("FoldTab.34"), configuration.isShowApertureLibrary());
aperture.setContentAreaFilled(false);
if (!Platform.isMac()) {
aperture.setEnabled(false);
}
aperture.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setShowApertureLibrary((e.getStateChange() == ItemEvent.SELECTED));
}
});
// File order
final KeyedComboBoxModel<Integer, String> kcbm = new KeyedComboBoxModel<>(new Integer[] { // alphabetical
UMSUtils.SORT_LOC_SENS, // natural sort
UMSUtils.SORT_LOC_NAT, // ASCIIbetical
UMSUtils.SORT_INS_ASCII, // newest first
UMSUtils.SORT_MOD_NEW, // oldest first
UMSUtils.SORT_MOD_OLD, // random
UMSUtils.SORT_RANDOM, // no sorting
UMSUtils.SORT_NO_SORT }, new String[] { Messages.getString("FoldTab.15"), Messages.getString("FoldTab.22"), Messages.getString("FoldTab.20"), Messages.getString("FoldTab.16"), Messages.getString("FoldTab.17"), Messages.getString("FoldTab.58"), Messages.getString("FoldTab.62") });
sortmethod = new JComboBox<>(kcbm);
sortmethod.setEditable(false);
kcbm.setSelectedKey(configuration.getSortMethod(null));
sortmethod.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
configuration.setSortMethod(kcbm.getSelectedKey());
LOGGER.info("Setting {} {}", Messages.getRootString("FoldTab.18"), kcbm.getSelectedValue());
}
}
});
// Ignore the word "the" while sorting
ignorethewordthe = new JCheckBox(Messages.getString("FoldTab.39"), configuration.isIgnoreTheWordAandThe());
ignorethewordthe.setToolTipText(Messages.getString("FoldTab.44"));
ignorethewordthe.setContentAreaFilled(false);
ignorethewordthe.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setIgnoreTheWordAandThe((e.getStateChange() == ItemEvent.SELECTED));
}
});
atzLimit = new JTextField("" + configuration.getATZLimit());
atzLimit.setToolTipText(Messages.getString("FoldTab.49"));
atzLimit.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
try {
int ab = Integer.parseInt(atzLimit.getText());
configuration.setATZLimit(ab);
} catch (NumberFormatException nfe) {
LOGGER.debug("Could not parse ATZ limit from \"" + atzLimit.getText() + "\"");
LOGGER.debug("The full error was: " + nfe);
}
}
});
isShowFolderLiveSubtitles = new JCheckBox(Messages.getString("FoldTab.42"), configuration.isShowLiveSubtitlesFolder());
isShowFolderLiveSubtitles.setContentAreaFilled(false);
isShowFolderLiveSubtitles.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setShowLiveSubtitlesFolder((e.getStateChange() == ItemEvent.SELECTED));
}
});
prettifyfilenames = new JCheckBox(Messages.getString("FoldTab.43"), configuration.isPrettifyFilenames());
prettifyfilenames.setToolTipText(Messages.getString("FoldTab.45"));
prettifyfilenames.setContentAreaFilled(false);
prettifyfilenames.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setPrettifyFilenames((e.getStateChange() == ItemEvent.SELECTED));
hideextensions.setEnabled((e.getStateChange() != ItemEvent.SELECTED));
episodeTitles.setEnabled((e.getStateChange() == ItemEvent.SELECTED));
}
});
episodeTitles = new JCheckBox(Messages.getString("FoldTab.74"), configuration.isUseInfoFromIMDb());
episodeTitles.setToolTipText(Messages.getString("FoldTab.64"));
episodeTitles.setContentAreaFilled(false);
if (!configuration.isPrettifyFilenames()) {
episodeTitles.setEnabled(false);
}
episodeTitles.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setUseInfoFromIMDb((e.getStateChange() == ItemEvent.SELECTED));
}
});
isShowFolderNewMedia = new JCheckBox(Messages.getString("FoldTab.54"), configuration.isShowNewMediaFolder());
isShowFolderNewMedia.setToolTipText(Messages.getString("FoldTab.66"));
isShowFolderNewMedia.setContentAreaFilled(false);
isShowFolderNewMedia.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setShowNewMediaFolder((e.getStateChange() == ItemEvent.SELECTED));
}
});
resume = new JCheckBox(Messages.getString("NetworkTab.68"), configuration.isResumeEnabled());
resume.setToolTipText(Messages.getString("NetworkTab.69"));
resume.setContentAreaFilled(false);
resume.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setResume((e.getStateChange() == ItemEvent.SELECTED));
}
});
isShowFolderRecentlyPlayed = new JCheckBox(Messages.getString("FoldTab.55"), configuration.isShowRecentlyPlayedFolder());
isShowFolderRecentlyPlayed.setContentAreaFilled(false);
isShowFolderRecentlyPlayed.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setShowRecentlyPlayedFolder((e.getStateChange() == ItemEvent.SELECTED));
}
});
// Fully played action
final KeyedComboBoxModel<FullyPlayedAction, String> fullyPlayedActionModel = new KeyedComboBoxModel<>(new FullyPlayedAction[] { FullyPlayedAction.NO_ACTION, FullyPlayedAction.MARK, FullyPlayedAction.HIDE_VIDEO, FullyPlayedAction.MOVE_FOLDER, FullyPlayedAction.MOVE_TRASH }, new String[] { Messages.getString("FoldTab.67"), Messages.getString("FoldTab.68"), Messages.getString("FoldTab.69"), Messages.getString("FoldTab.70"), Messages.getString("FoldTab.71") });
fullyPlayedAction = new JComboBox<>(fullyPlayedActionModel);
fullyPlayedAction.setEditable(false);
fullyPlayedActionModel.setSelectedKey(configuration.getFullyPlayedAction());
fullyPlayedAction.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
configuration.setFullyPlayedAction(fullyPlayedActionModel.getSelectedKey());
fullyPlayedOutputDirectory.setEnabled(fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.MOVE_FOLDER);
selectFullyPlayedOutputDirectory.setEnabled(fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.MOVE_FOLDER);
if (configuration.getUseCache() && fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.NO_ACTION) {
PMS.get().getDatabase().init(true);
}
}
}
});
// Watched video output directory
fullyPlayedOutputDirectory = new JTextField(configuration.getFullyPlayedOutputDirectory());
fullyPlayedOutputDirectory.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
configuration.setFullyPlayedOutputDirectory(fullyPlayedOutputDirectory.getText());
}
});
fullyPlayedOutputDirectory.setEnabled(configuration.getFullyPlayedAction() == FullyPlayedAction.MOVE_FOLDER);
// Watched video output directory selection button
selectFullyPlayedOutputDirectory = new CustomJButton("...");
selectFullyPlayedOutputDirectory.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser chooser;
try {
chooser = new JFileChooser();
} catch (Exception ee) {
chooser = new JFileChooser(new RestrictedFileSystemView());
}
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("FoldTab.28"));
if (returnVal == JFileChooser.APPROVE_OPTION) {
fullyPlayedOutputDirectory.setText(chooser.getSelectedFile().getAbsolutePath());
configuration.setFullyPlayedOutputDirectory(chooser.getSelectedFile().getAbsolutePath());
}
}
});
selectFullyPlayedOutputDirectory.setEnabled(configuration.getFullyPlayedAction() == FullyPlayedAction.MOVE_FOLDER);
}
use of net.pms.newgui.components.CustomJButton in project UniversalMediaServer by UniversalMediaServer.
the class PluginTab method appendPlugin.
public boolean appendPlugin(final ExternalListener listener) {
final JComponent comp = listener.config();
if (comp == null) {
return true;
}
CellConstraints cc = new CellConstraints();
CustomJButton bPlugin = new CustomJButton(listener.name());
// Listener to show option screen
bPlugin.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showOptionDialog(looksFrame, comp, Messages.getString("Dialog.Options"), JOptionPane.CLOSED_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null);
}
});
int y = pPlugins.getComponentCount() + 1;
if (y > 30) {
return false;
}
pPlugins.add(bPlugin, cc.xy(1, y));
return true;
}
use of net.pms.newgui.components.CustomJButton in project UniversalMediaServer by UniversalMediaServer.
the class PluginTab method build.
public JComponent build() {
ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
String colSpec = FormLayoutUtil.getColSpec(COL_SPEC, orientation);
FormLayout layout = new FormLayout(colSpec, ROW_SPEC);
PanelBuilder builder = new PanelBuilder(layout);
builder.border(Borders.DLU4);
builder.opaque(true);
CellConstraints cc = new CellConstraints();
// Available Plugins section
JComponent availablePluginsHeading = builder.addSeparator(Messages.getString("PluginTab.1"), FormLayoutUtil.flip(cc.xyw(1, 1, 9), colSpec, orientation));
availablePluginsHeading = (JComponent) availablePluginsHeading.getComponent(0);
availablePluginsHeading.setFont(availablePluginsHeading.getFont().deriveFont(Font.BOLD));
final String[] cols = { Messages.getString("NetworkTab.41"), Messages.getString("PluginTab.3"), Messages.getString("NetworkTab.42"), Messages.getString("NetworkTab.43"), Messages.getString("NetworkTab.53") };
final JTable table = new JTable(1, cols.length) {
private static final long serialVersionUID = -5032210766949508624L;
@Override
public boolean isCellEditable(int rowIndex, int vColIndex) {
return false;
}
@Override
public String getToolTipText(MouseEvent e) {
java.awt.Point p = e.getPoint();
int rowIndex = rowAtPoint(p);
DownloadPlugins plugin = plugins.get(rowIndex);
return plugin.htmlString();
}
};
refresh(table, cols);
/* An attempt to set the correct row height adjusted for font scaling.
* It sets all rows based on the font size of cell (0, 0). The + 4 is
* to allow 2 pixels above and below the text. */
DefaultTableCellRenderer cellRenderer = (DefaultTableCellRenderer) table.getCellRenderer(0, 0);
FontMetrics metrics = cellRenderer.getFontMetrics(cellRenderer.getFont());
table.setRowHeight(metrics.getLeading() + metrics.getMaxAscent() + metrics.getMaxDescent() + 4);
table.setIntercellSpacing(new Dimension(8, 2));
// Define column widths
TableColumn nameColumn = table.getColumnModel().getColumn(0);
nameColumn.setMinWidth(70);
TableColumn versionColumn = table.getColumnModel().getColumn(2);
versionColumn.setPreferredWidth(45);
TableColumn ratingColumn = table.getColumnModel().getColumn(2);
ratingColumn.setPreferredWidth(45);
TableColumn authorColumn = table.getColumnModel().getColumn(3);
authorColumn.setMinWidth(150);
TableColumn descriptionColumn = table.getColumnModel().getColumn(4);
descriptionColumn.setMinWidth(300);
JScrollPane pane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
pane.setBorder(BorderFactory.createEmptyBorder());
pane.setPreferredSize(new Dimension(200, 139));
builder.add(pane, FormLayoutUtil.flip(cc.xyw(1, 3, 9), colSpec, orientation));
CustomJButton install = new CustomJButton(Messages.getString("NetworkTab.39"));
builder.add(install, FormLayoutUtil.flip(cc.xy(1, 5), colSpec, orientation));
install.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!ExternalFactory.localPluginsInstalled()) {
JOptionPane.showMessageDialog(looksFrame, Messages.getString("NetworkTab.40"));
return;
}
// need admin rights here.
try {
if (!FileUtil.getFilePermissions(configuration.getPluginDirectory()).isWritable()) {
JOptionPane.showMessageDialog(looksFrame, Messages.getString("PluginTab.16") + (Platform.isWindows() ? "\n" + Messages.getString("AutoUpdate.13") : ""), Messages.getString("Dialog.PermissionsError"), JOptionPane.ERROR_MESSAGE);
return;
}
} catch (FileNotFoundException e1) {
JOptionPane.showMessageDialog(looksFrame, String.format(Messages.getString("PluginTab.17"), configuration.getPluginDirectory()), Messages.getString("Dialog.Error"), JOptionPane.ERROR_MESSAGE);
return;
}
final int[] rows = table.getSelectedRows();
JPanel panel = new JPanel();
GridLayout layout = new GridLayout(3, 1);
panel.setLayout(layout);
final JFrame frame = new JFrame(Messages.getString("NetworkTab.46"));
frame.setSize(250, 110);
JProgressBar progressBar = new JProgressBar();
progressBar.setIndeterminate(true);
panel.add(progressBar);
final JLabel label = new JLabel("");
final JLabel inst = new JLabel("");
panel.add(inst);
panel.add(label);
frame.add(panel);
// Center the installation progress window
frame.setLocationRelativeTo(null);
Runnable r = new Runnable() {
@Override
public void run() {
for (int i = 0; i < rows.length; i++) {
DownloadPlugins plugin = plugins.get(rows[i]);
if (plugin.isOld()) {
// This plugin requires newer UMS
// display error and skip it.
JOptionPane.showMessageDialog(looksFrame, "Plugin " + plugin.getName() + " requires a newer version of UMS. Please upgrade.", "Version Error", JOptionPane.ERROR_MESSAGE);
frame.setVisible(false);
continue;
}
frame.setVisible(true);
inst.setText(Messages.getString("NetworkTab.50") + ": " + plugin.getName());
try {
plugin.install(label);
} catch (Exception e) {
LOGGER.debug("An error occurred when trying to install the plugin: " + plugin.getName());
LOGGER.debug("Full error: " + e);
}
}
frame.setVisible(false);
}
};
new Thread(r).start();
}
});
CustomJButton refresh = new CustomJButton(Messages.getString("PluginTab.2") + " " + Messages.getString("PluginTab.1").toLowerCase());
builder.add(refresh, FormLayoutUtil.flip(cc.xy(3, 5), colSpec, orientation));
refresh.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refresh(table, cols);
}
});
// Installed Plugins section
JComponent component;
installedPluginsSeparator = (JPanel) builder.addSeparator(Messages.getString("PluginTab.0"), FormLayoutUtil.flip(cc.xyw(1, 7, 9), colSpec, orientation));
installedPluginsSeparator.setVisible(false);
component = (JComponent) installedPluginsSeparator.getComponent(0);
component.setFont(component.getFont().deriveFont(Font.BOLD));
pPlugins = new JPanel(new GridLayout());
pPlugins.setVisible(false);
builder.add(pPlugins, FormLayoutUtil.flip(cc.xyw(1, 9, 9), colSpec, orientation));
// Credentials section
component = builder.addSeparator(Messages.getString("PluginTab.8"), FormLayoutUtil.flip(cc.xyw(1, 11, 9), colSpec, orientation));
component = (JComponent) component.getComponent(0);
component.setFont(component.getFont().deriveFont(Font.BOLD));
/* An attempt to set the correct row height adjusted for font scaling.
* It sets all rows based on the font size of cell (0, 0). The + 4 is
* to allow 2 pixels above and below the text. */
cellRenderer = (DefaultTableCellRenderer) credTable.getCellRenderer(0, 0);
metrics = cellRenderer.getFontMetrics(cellRenderer.getFont());
credTable.setRowHeight(metrics.getLeading() + metrics.getMaxAscent() + metrics.getMaxDescent() + 4);
credTable.setFillsViewportHeight(true);
credTable.setIntercellSpacing(new Dimension(8, 2));
// Define column widths
TableColumn ownerColumn = credTable.getColumnModel().getColumn(0);
ownerColumn.setMinWidth(70);
TableColumn tagColumn = credTable.getColumnModel().getColumn(2);
tagColumn.setPreferredWidth(45);
TableColumn usrColumn = credTable.getColumnModel().getColumn(2);
usrColumn.setPreferredWidth(45);
TableColumn pwdColumn = credTable.getColumnModel().getColumn(3);
pwdColumn.setPreferredWidth(45);
pane = new JScrollPane(credTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
pane.setBorder(BorderFactory.createEmptyBorder());
pane.setPreferredSize(new Dimension(200, 95));
builder.add(pane, FormLayoutUtil.flip(cc.xyw(1, 13, 9), colSpec, orientation));
// Add button
CustomJButton add = new CustomJButton(Messages.getString("PluginTab.9"));
builder.add(add, FormLayoutUtil.flip(cc.xy(1, 15), colSpec, orientation));
add.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addEditDialog(credTable, -1);
}
});
// Edit button
CustomJButton edit = new CustomJButton(Messages.getString("PluginTab.11"));
builder.add(edit, FormLayoutUtil.flip(cc.xy(3, 15), colSpec, orientation));
edit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addEditDialog(credTable, credTable.getSelectedRow());
}
});
// Delete button
CustomJButton del = new CustomJButton(Messages.getString("PluginTab.12"));
builder.add(del, FormLayoutUtil.flip(cc.xy(5, 15), colSpec, orientation));
del.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int[] rows = credTable.getSelectedRows();
if (rows.length > 0) {
int n = JOptionPane.showConfirmDialog(looksFrame, Messages.getString("PluginTab.13"), "", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
for (int i = 0; i < rows.length; i++) {
String key = (String) credTable.getValueAt(rows[i], 0);
if (StringUtils.isNotEmpty((String) credTable.getValueAt(rows[i], 1))) {
key = key + "." + (String) credTable.getValueAt(rows[i], 1);
}
cred.clearProperty(key);
}
}
try {
cred.save();
} catch (ConfigurationException e1) {
LOGGER.warn("Couldn't save credentials file {}", e1.getMessage());
LOGGER.trace("", e1);
}
refreshCred(credTable);
}
}
});
// Edit Plugin Credential File button
CustomJButton credEdit = new CustomJButton(Messages.getString("NetworkTab.54"));
credEdit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JPanel tPanel = new JPanel(new BorderLayout());
final JTextArea textArea = new JTextArea();
textArea.setFont(new Font("Courier", Font.PLAIN, 12));
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setPreferredSize(new Dimension(900, 450));
try {
configuration.initCred();
} catch (IOException e2) {
LOGGER.error("Could not create credentials file: {}", e2.getMessage());
LOGGER.trace("", e2);
return;
}
try {
cred.save();
} catch (ConfigurationException e3) {
LOGGER.error("Could not save credentials file: {}", e3.getMessage());
LOGGER.trace("", e3);
}
File f = configuration.getCredFile();
try {
try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8))) {
String line;
StringBuilder sb = new StringBuilder();
while ((line = in.readLine()) != null) {
sb.append(line);
sb.append("\n");
}
textArea.setText(sb.toString());
}
} catch (IOException e1) {
LOGGER.error("Could not read credentials file: {}", e1.getMessage());
LOGGER.trace("", e1);
return;
}
tPanel.add(scrollPane, BorderLayout.NORTH);
Object[] options = { Messages.getString("LooksFrame.9"), Messages.getString("NetworkTab.45") };
if (JOptionPane.showOptionDialog(looksFrame, tPanel, Messages.getString("NetworkTab.54"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, null) == JOptionPane.OK_OPTION) {
String text = textArea.getText();
try {
try (FileOutputStream fos = new FileOutputStream(f)) {
fos.write(text.getBytes(StandardCharsets.UTF_8));
fos.flush();
}
PMS.getConfiguration().reload();
try {
cred.refresh();
} catch (ConfigurationException e2) {
LOGGER.error("An error occurred while updating credentials: {}", e2);
LOGGER.trace("", e2);
}
refreshCred(credTable);
} catch (Exception e1) {
JOptionPane.showMessageDialog(looksFrame, Messages.getString("NetworkTab.55") + ": " + e1.getMessage());
}
}
}
});
builder.add(credEdit, FormLayoutUtil.flip(cc.xy(7, 15), colSpec, orientation));
JPanel panel = builder.getPanel();
JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setBorder(BorderFactory.createEmptyBorder());
return scrollPane;
}
use of net.pms.newgui.components.CustomJButton in project UniversalMediaServer by UniversalMediaServer.
the class RendererPanel method referenceButton.
public JButton referenceButton() {
final File ref = ((DeviceConfiguration) renderer).getConfiguration(DeviceConfiguration.RENDERER).getFile();
final CustomJButton open = new CustomJButton(MetalIconFactory.getTreeLeafIcon());
boolean exists = ref != null && ref.exists();
open.setToolTipText(exists ? (Messages.getString("RendererPanel.3") + ": " + ref) : Messages.getString("RendererPanel.4"));
open.setFocusPainted(false);
open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
try {
java.awt.Desktop.getDesktop().open(ref);
} catch (IOException ioe) {
LOGGER.debug("Failed to open default desktop application: " + ioe);
}
}
});
if (!exists) {
open.setText("!");
open.setHorizontalTextPosition(JButton.CENTER);
open.setForeground(Color.lightGray);
open.setEnabled(false);
}
return open;
}
Aggregations