use of java.awt.ComponentOrientation in project UniversalMediaServer by UniversalMediaServer.
the class TsMuxeRVideo method config.
@Override
public JComponent config() {
// Apply the orientation for the locale
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.EMPTY);
builder.opaque(false);
CellConstraints cc = new CellConstraints();
JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), FormLayoutUtil.flip(cc.xyw(2, 1, 1), colSpec, orientation));
cmp = (JComponent) cmp.getComponent(0);
cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
tsmuxerforcefps = new JCheckBox(Messages.getString("TsMuxeRVideo.2"), configuration.isTsmuxerForceFps());
tsmuxerforcefps.setContentAreaFilled(false);
tsmuxerforcefps.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setTsmuxerForceFps(e.getStateChange() == ItemEvent.SELECTED);
}
});
builder.add(GuiUtil.getPreferredSizeComponent(tsmuxerforcefps), FormLayoutUtil.flip(cc.xy(2, 3), colSpec, orientation));
muxallaudiotracks = new JCheckBox(Messages.getString("TsMuxeRVideo.19"), configuration.isMuxAllAudioTracks());
muxallaudiotracks.setContentAreaFilled(false);
muxallaudiotracks.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setMuxAllAudioTracks(e.getStateChange() == ItemEvent.SELECTED);
}
});
builder.add(GuiUtil.getPreferredSizeComponent(muxallaudiotracks), FormLayoutUtil.flip(cc.xy(2, 5), colSpec, orientation));
JPanel panel = builder.getPanel();
// Apply the orientation to the panel and all components in it
panel.applyComponentOrientation(orientation);
return panel;
}
use of java.awt.ComponentOrientation in project UniversalMediaServer by UniversalMediaServer.
the class VLCVideo method config.
@Override
public JComponent config() {
// Apply the orientation for the locale
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.EMPTY);
builder.opaque(false);
CellConstraints cc = new CellConstraints();
JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), FormLayoutUtil.flip(cc.xyw(1, 1, 5), colSpec, orientation));
cmp = (JComponent) cmp.getComponent(0);
cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
experimentalCodecs = new JCheckBox(Messages.getString("VlcTrans.3"), configuration.isVlcExperimentalCodecs());
experimentalCodecs.setContentAreaFilled(false);
experimentalCodecs.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setVlcExperimentalCodecs(e.getStateChange() == ItemEvent.SELECTED);
}
});
builder.add(GuiUtil.getPreferredSizeComponent(experimentalCodecs), FormLayoutUtil.flip(cc.xy(1, 3), colSpec, orientation));
audioSyncEnabled = new JCheckBox(Messages.getString("MEncoderVideo.2"), configuration.isVlcAudioSyncEnabled());
audioSyncEnabled.setContentAreaFilled(false);
audioSyncEnabled.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
configuration.setVlcAudioSyncEnabled(e.getStateChange() == ItemEvent.SELECTED);
}
});
builder.add(GuiUtil.getPreferredSizeComponent(audioSyncEnabled), FormLayoutUtil.flip(cc.xy(1, 5), colSpec, orientation));
JPanel panel = builder.getPanel();
// Apply the orientation to the panel and all components in it
panel.applyComponentOrientation(orientation);
return panel;
}
use of java.awt.ComponentOrientation in project UniversalMediaServer by UniversalMediaServer.
the class NavigationShareTab method build.
public JComponent build() {
// Apply the orientation for the locale
ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
String colSpec = FormLayoutUtil.getColSpec(PANEL_COL_SPEC, orientation);
// Set basic layout
FormLayout layout = new FormLayout(colSpec, PANEL_ROW_SPEC);
PanelBuilder builder = new PanelBuilder(layout);
builder.border(Borders.DLU4);
builder.opaque(true);
CellConstraints cc = new CellConstraints();
// Init all gui components
initSimpleComponents(cc);
PanelBuilder builderSharedFolder = initSharedFoldersGuiComponents(cc);
// Build gui with initialized components
if (!configuration.isHideAdvancedOptions()) {
JComponent cmp = builder.addSeparator(Messages.getString("FoldTab.13"), FormLayoutUtil.flip(cc.xyw(1, 1, 12), colSpec, orientation));
cmp = (JComponent) cmp.getComponent(0);
cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
builder.add(GuiUtil.getPreferredSizeComponent(thumbgenCheckBox), FormLayoutUtil.flip(cc.xyw(1, 3, 3), colSpec, orientation));
builder.addLabel(Messages.getString("NetworkTab.16"), FormLayoutUtil.flip(cc.xyw(4, 3, 2), colSpec, orientation));
builder.add(seekpos, FormLayoutUtil.flip(cc.xy(6, 3), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(image_thumb), FormLayoutUtil.flip(cc.xyw(9, 3, 4), colSpec, orientation));
builder.addLabel(Messages.getString("FoldTab.26"), FormLayoutUtil.flip(cc.xyw(1, 5, 3), colSpec, orientation));
builder.add(audiothumbnail, FormLayoutUtil.flip(cc.xyw(4, 5, 3), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(mplayer_thumb), FormLayoutUtil.flip(cc.xyw(9, 5, 4), colSpec, orientation));
builder.addLabel(Messages.getString("FoldTab.27"), FormLayoutUtil.flip(cc.xy(1, 7), colSpec, orientation));
builder.add(defaultThumbFolder, FormLayoutUtil.flip(cc.xyw(4, 7, 2), colSpec, orientation));
builder.add(select, FormLayoutUtil.flip(cc.xy(6, 7), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(dvdiso_thumb), FormLayoutUtil.flip(cc.xyw(9, 7, 4), colSpec, orientation));
cmp = builder.addSeparator(Messages.getString("NetworkTab.59"), FormLayoutUtil.flip(cc.xyw(1, 9, 12), colSpec, orientation));
cmp = (JComponent) cmp.getComponent(0);
cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
builder.addLabel(Messages.getString("FoldTab.18"), FormLayoutUtil.flip(cc.xyw(1, 11, 3), colSpec, orientation));
builder.add(sortmethod, FormLayoutUtil.flip(cc.xyw(4, 11, 3), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(ignorethewordthe), FormLayoutUtil.flip(cc.xyw(9, 11, 4), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(prettifyfilenames), FormLayoutUtil.flip(cc.xyw(1, 13, 5), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(episodeTitles), FormLayoutUtil.flip(cc.xyw(9, 13, 4), colSpec, orientation));
cmp = builder.addSeparator(Messages.getString("NetworkTab.60"), FormLayoutUtil.flip(cc.xyw(1, 15, 12), colSpec, orientation));
cmp = (JComponent) cmp.getComponent(0);
cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
builder.add(GuiUtil.getPreferredSizeComponent(hideextensions), FormLayoutUtil.flip(cc.xyw(1, 17, 3), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(hideengines), FormLayoutUtil.flip(cc.xyw(4, 17, 3), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(hideemptyfolders), FormLayoutUtil.flip(cc.xyw(9, 17, 4), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(itunes), FormLayoutUtil.flip(cc.xy(1, 19), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(iphoto), FormLayoutUtil.flip(cc.xyw(4, 19, 3), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(aperture), FormLayoutUtil.flip(cc.xyw(9, 19, 4), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(cacheenable), FormLayoutUtil.flip(cc.xy(1, 21), colSpec, orientation));
builder.add(cachereset, FormLayoutUtil.flip(cc.xyw(4, 21, 3), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(isShowFolderMediaLibrary), FormLayoutUtil.flip(cc.xyw(9, 21, 4), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(archive), FormLayoutUtil.flip(cc.xyw(1, 23, 3), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(isShowFolderServerSettings), FormLayoutUtil.flip(cc.xyw(4, 23, 3), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(isShowFolderTranscode), FormLayoutUtil.flip(cc.xyw(9, 23, 4), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(isShowFolderLiveSubtitles), FormLayoutUtil.flip(cc.xyw(1, 25, 3), colSpec, orientation));
builder.addLabel(Messages.getString("FoldTab.37"), FormLayoutUtil.flip(cc.xyw(4, 25, 2), colSpec, orientation));
builder.add(atzLimit, FormLayoutUtil.flip(cc.xy(6, 25), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(isShowFolderNewMedia), FormLayoutUtil.flip(cc.xyw(9, 25, 4), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(resume), FormLayoutUtil.flip(cc.xy(1, 27), colSpec, orientation));
builder.add(GuiUtil.getPreferredSizeComponent(isShowFolderRecentlyPlayed), FormLayoutUtil.flip(cc.xyw(9, 27, 4), colSpec, orientation));
builder.addLabel(Messages.getString("FoldTab.72"), FormLayoutUtil.flip(cc.xy(1, 29), colSpec, orientation));
builder.add(fullyPlayedAction, FormLayoutUtil.flip(cc.xyw(4, 29, 3), colSpec, orientation));
builder.add(fullyPlayedOutputDirectory, FormLayoutUtil.flip(cc.xyw(9, 29, 2), colSpec, orientation));
builder.add(selectFullyPlayedOutputDirectory, FormLayoutUtil.flip(cc.xyw(11, 29, 2), colSpec, orientation));
builder.add(builderSharedFolder.getPanel(), FormLayoutUtil.flip(cc.xyw(1, 31, 12), colSpec, orientation));
} else {
builder.add(builderSharedFolder.getPanel(), FormLayoutUtil.flip(cc.xyw(1, 1, 12), colSpec, orientation));
}
builder.add(builderSharedFolder.getPanel(), FormLayoutUtil.flip(cc.xyw(1, 31, 12), colSpec, orientation));
JPanel panel = builder.getPanel();
// Apply the orientation to the panel and all components in it
panel.applyComponentOrientation(orientation);
JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setBorder(BorderFactory.createEmptyBorder());
return scrollPane;
}
use of java.awt.ComponentOrientation 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 java.awt.ComponentOrientation 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;
}
Aggregations