List of usage examples for com.jgoodies.forms.layout CellConstraints RIGHT
Alignment RIGHT
To view the source code for com.jgoodies.forms.layout CellConstraints RIGHT.
Click Source Link
From source file:net.pms.medialibrary.gui.dialogs.AddAutoFolderDialog.java
License:Open Source License
private void rebuildPanel() { PanelBuilder builder;/* www . j a v a 2s. c o m*/ CellConstraints cc = new CellConstraints(); FormLayout layout = new FormLayout("2dlu, fill:p:grow, 2dlu, p, 2dlu, p, 2dlu, fill:p:grow, 2dlu", // columns "2dlu, p, 2dlu, p, 2dlu, p"); // raws builder = new PanelBuilder(layout); builder.setOpaque(true); // Options builder.add(cbAutoFolder, cc.xy(2, 2)); builder.add(rbAscending, cc.xy(4, 2)); builder.add(rbDescending, cc.xy(6, 2)); builder.add(pMinOccurences, cc.xyw(4, 4, 5)); // Add A-Z options builder.add(cbProperty, cc.xy(2, 4)); // Add file system options builder.add(lOptionName, cc.xy(2, 4, CellConstraints.RIGHT, CellConstraints.DEFAULT)); builder.add(tfOption, cc.xyw(4, 4, 3)); builder.add(bBrowse, cc.xy(8, 4)); // Buttons builder.add(jPanelButtons, cc.xyw(2, 6, 7)); getContentPane().removeAll(); getContentPane().add(builder.getPanel()); pack(); }
From source file:net.pms.medialibrary.gui.dialogs.folderdialog.ConditionPanel.java
License:Open Source License
private Component getInheritPanel() { PanelBuilder builder;/*from ww w. j av a2 s. c o m*/ CellConstraints cc = new CellConstraints(); FormLayout layout = new FormLayout("p, 3px, p, 3px, p:grow", // columns "p"); // rows builder = new PanelBuilder(layout); builder.setOpaque(true); builder.add(lInherit, cc.xy(1, 1)); builder.add(bShowInherit, cc.xy(3, 1)); builder.add(cbInheritConditions, cc.xy(5, 1, CellConstraints.RIGHT, CellConstraints.DEFAULT)); return builder.getPanel(); }
From source file:net.pms.medialibrary.gui.dialogs.folderdialog.DisplayPanel.java
License:Open Source License
private Component getDisplayItemsPanel() { PanelBuilder builder;// w w w . j a v a2 s. c o m CellConstraints cc = new CellConstraints(); FormLayout layout = new FormLayout("3px, p, 3px, fill:10:grow, 3px, p, 3px", // columns "p"); // rows builder = new PanelBuilder(layout); builder.setOpaque(true); builder.add(cbDisplayItems, cc.xy(2, 1)); builder.add(lMaxFiles, cc.xy(4, 1, CellConstraints.RIGHT, CellConstraints.CENTER)); builder.add(tfMaxFiles, cc.xy(6, 1)); return builder.getPanel(); }
From source file:net.pms.medialibrary.gui.dialogs.ScanFolderDialog.java
License:Open Source License
private void build(String folderPath) { FormLayout layout = new FormLayout("5px, p, 5px, fill:p:grow, 5px, p, 5px, p, 5px", "p, 2px, p, 5px, p, 2px, p"); PanelBuilder builder = new PanelBuilder(layout); builder.setOpaque(true);//from ww w .j a va2s . c om CellConstraints cc = new CellConstraints(); // line 1 builder.addLabel(Messages.getString("ML.ScanFolderDialog.lFolderPath"), cc.xy(2, 1, CellConstraints.RIGHT, CellConstraints.DEFAULT)); tfFolderPath = new JTextField(folderPath); tfFolderPath.setMinimumSize(new Dimension(300, tfFolderPath.getPreferredSize().height)); builder.add(tfFolderPath, cc.xy(4, 1)); bBrowseFolderPath = new JButton(Messages.getString("ML.ScanFolderDialog.bBrowse")); bBrowseFolderPath.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JFileChooser fc = new JFileChooser(bBrowseFolderPath.getText()); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { tfFolderPath.setText(fc.getSelectedFile().getAbsolutePath()); } } }); builder.add(bBrowseFolderPath, cc.xy(6, 1)); cbScanSubFolders = new JCheckBox(Messages.getString("ML.ScanFolderDialog.cbScanSubFolders")); cbScanSubFolders.setSelected(true); builder.add(cbScanSubFolders, cc.xy(8, 1)); // line 2 builder.addLabel(Messages.getString("ML.ScanFolderDialog.lLookFor"), cc.xy(2, 3, CellConstraints.RIGHT, CellConstraints.DEFAULT)); JPanel pFileTypes = new JPanel(new FlowLayout()); cbScanVideo = new JCheckBox(Messages.getString("ML.ScanFolderDialog.cbScanVideo"), true); pFileTypes.add(cbScanVideo); cbScanAudio = new JCheckBox(Messages.getString("ML.ScanFolderDialog.cbScanAudio"), true); pFileTypes.add(cbScanAudio); cbScanPictures = new JCheckBox(Messages.getString("ML.ScanFolderDialog.cbScanPictures"), true); pFileTypes.add(cbScanPictures); builder.add(pFileTypes, cc.xy(4, 3, CellConstraints.LEFT, CellConstraints.DEFAULT)); cbUseFileImportPlugins = new JCheckBox(Messages.getString("ML.ScanFolderDialog.cbUsePlugins")); cbUseFileImportPlugins.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (cbUseFileImportPlugins.isSelected()) { pFileImport.setVisible(true); } else { pFileImport.setVisible(false); } pack(); } }); builder.add(cbUseFileImportPlugins, cc.xy(8, 3, CellConstraints.LEFT, CellConstraints.DEFAULT)); // file import pFileImport = new FileImportTemplatePanel(1); pFileImport.setVisible(false); pFileImport.addRepaintListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pack(); } }); builder.add(pFileImport, cc.xyw(2, 5, 7)); // buttons bImport = new JButton(Messages.getString("ML.ScanFolderDialog.bImport")); if (bImport.getPreferredSize().width < MIN_BUTTON_WIDTH) bImport.setPreferredSize(new Dimension(MIN_BUTTON_WIDTH, bImport.getPreferredSize().height)); bImport.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { save(); File selectedFolder = new File(tfFolderPath.getText()); if (selectedFolder.isDirectory()) { setDoImport(true); instance.setVisible(false); } else { JOptionPane.showMessageDialog(null, Messages.getString("ML.ScanFolderDialog.InvalidPathMsg"), Messages.getString("ML.ScanFolderDialog.InvalidPathTitle"), JOptionPane.INFORMATION_MESSAGE); } } }); bCancel = new JButton(Messages.getString("ML.ScanFolderDialog.bCancel")); if (bCancel.getPreferredSize().width < MIN_BUTTON_WIDTH) bCancel.setPreferredSize(new Dimension(MIN_BUTTON_WIDTH, bCancel.getPreferredSize().height)); bCancel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { setDoImport(false); instance.setVisible(false); } }); bSave = new JButton(Messages.getString("ML.ScanFolderDialog.bSave")); if (bSave.getPreferredSize().width < MIN_BUTTON_WIDTH) bSave.setPreferredSize(new Dimension(MIN_BUTTON_WIDTH, bSave.getPreferredSize().height)); bSave.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { save(); } }); JPanel bPanel = new JPanel(); bPanel.setAlignmentX(CENTER_ALIGNMENT); bPanel.add(bImport); bPanel.add(bSave); bPanel.add(bCancel); builder.add(bPanel, cc.xyw(2, 7, 7)); getContentPane().add(builder.getPanel()); pack(); }
From source file:net.pms.medialibrary.gui.shared.FileImportTemplatePanel.java
License:Open Source License
/** * Places the visual components correctly in the grid. Components being shown are the combo box containing * the templates, all file properties with their list of engines and the buttons *//*w w w .ja v a 2s. c om*/ private void placeComponents() { FormLayout layout = new FormLayout("fill:p:grow, 5px, p, 5px, p, 5px, p", "p, 5px, fill:p:grow"); PanelBuilder builder = new PanelBuilder(layout); builder.setOpaque(true); CellConstraints cc = new CellConstraints(); //create top panel with combo box and and buttons builder.addLabel(Messages.getString("ML.FileImportConfigurationPanel.lTemplate"), cc.xy(1, 1, CellConstraints.RIGHT, CellConstraints.DEFAULT)); builder.add(cbTemplate, cc.xy(3, 1)); builder.add(bNewTemplate, cc.xy(5, 1)); builder.add(bDeleteTemplate, cc.xy(7, 1)); builder.add(tpProperties, cc.xyw(1, 3, 7)); //build the dialog setLayout(new GridLayout()); removeAll(); add(builder.getPanel()); for (ActionListener l : repaintListeners) { l.actionPerformed(new ActionEvent(this, 0, "Repaint")); } }
From source file:net.pms.medialibrary.gui.tab.GeneralOptionsView.java
License:Open Source License
private JComponent build() { this.libraryManager.addFileScannerEventListener(new IFileScannerEventListener() { @Override// www. j a va 2 s .c om public void scanStateChanged(final ScanState state) { scanState = state; updateScanState(); } @Override public void itemInserted(final FileType type) { switch (type) { case VIDEO: int currVal = Integer.parseInt(lVideoCount.getText()); lVideoCount.setText(String.valueOf(++currVal)); break; case AUDIO: currVal = Integer.parseInt(lAudioCount.getText()); lAudioCount.setText(String.valueOf(++currVal)); break; case PICTURES: currVal = Integer.parseInt(lPicturesCount.getText()); lPicturesCount.setText(String.valueOf(++currVal)); break; } } }); this.libraryManager.addLibraryManagerEventListener(new ILibraryManagerEventListener() { @Override public void itemCountChanged(final int itemCount, final FileType type) { switch (type) { case VIDEO: lVideoCount.setText(String.valueOf(itemCount)); break; case AUDIO: lAudioCount.setText(String.valueOf(itemCount)); break; case PICTURES: lPicturesCount.setText(String.valueOf(itemCount)); break; } } }); bApply = new JButton(Messages.getString("ML.ManagedFoldersPanel.bApply")); bApply.setToolTipText(Messages.getString("ML.ManagedFoldersPanel.bApply.ToolTipText")); bApply.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { pManagedFolders.cleanManagedFolders(); MediaLibraryStorage.getInstance().setManagedFolders(pManagedFolders.getManagedFolders()); libConfig.setPictureSaveFolderPath(tfPictureFolderPathValue.getText()); final OmitPrefixesConfiguration omitCfg = new OmitPrefixesConfiguration(); omitCfg.setFiltering(cbOmitFiltering.isSelected()); omitCfg.setSorting(cbOmitSorting.isSelected()); omitCfg.setPrefixes(Arrays.asList(tfOmitPrefix.getText().trim().split(" "))); libConfig.setOmitPrefixesConfiguration(omitCfg); } }); final FormLayout layout = new FormLayout("3px, 10:grow, 3px", "3px, p, 7px, p, 7px, p, 7px, fill:p:grow, 3px, p, 3px"); final PanelBuilder builder = new PanelBuilder(layout); builder.setOpaque(true); final CellConstraints cc = new CellConstraints(); builder.add(buildGeneral(), cc.xy(2, 2)); builder.add(buildLibrary(), cc.xy(2, 4)); builder.add(buildScanner(), cc.xy(2, 6)); builder.add(buildFolderManager(), cc.xy(2, 8)); builder.add(bApply, cc.xy(2, 10, CellConstraints.RIGHT, CellConstraints.CENTER)); final JScrollPane sp = new JScrollPane(builder.getPanel()); sp.setBorder(BorderFactory.createEmptyBorder()); return sp; }
From source file:net.pms.newgui.TranscodingTab.java
License:Open Source License
private JComponent buildSubtitlesSetupPanel() { String colSpec = FormLayoutUtil.getColSpec( "left:pref, 3dlu, p:grow, 3dlu, right:p:grow, 3dlu, p:grow, 3dlu, right:p:grow,3dlu, p:grow, 3dlu, right:p:grow,3dlu, pref:grow", orientation);/*from w ww . j a v a 2 s . co m*/ FormLayout layout = new FormLayout(colSpec, "$lgap, 7*(pref, 3dlu), pref"); final PanelBuilder builder = new PanelBuilder(layout); builder.border(Borders.DLU4); CellConstraints cc = new CellConstraints(); builder.addLabel(Messages.getString("MEncoderVideo.9"), FormLayoutUtil.flip(cc.xy(1, 2), colSpec, orientation)); defaultsubs = new JTextField(configuration.getSubtitlesLanguages()); defaultsubs.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setSubtitlesLanguages(defaultsubs.getText()); } }); builder.add(defaultsubs, FormLayoutUtil.flip(cc.xyw(3, 2, 5), colSpec, orientation)); builder.addLabel(Messages.getString("MEncoderVideo.94"), FormLayoutUtil .flip(cc.xyw(8, 2, 2, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation)); forcedsub = new JTextField(configuration.getForcedSubtitleLanguage()); forcedsub.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setForcedSubtitleLanguage(forcedsub.getText()); } }); builder.add(forcedsub, FormLayoutUtil.flip(cc.xyw(11, 2, 2), colSpec, orientation)); builder.addLabel(Messages.getString("MEncoderVideo.95"), FormLayoutUtil .flip(cc.xyw(12, 2, 2, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation)); forcedtags = new JTextField(configuration.getForcedSubtitleTags()); forcedtags.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setForcedSubtitleTags(forcedtags.getText()); } }); builder.add(forcedtags, FormLayoutUtil.flip(cc.xyw(14, 2, 2), colSpec, orientation)); builder.addLabel(Messages.getString("MEncoderVideo.10"), FormLayoutUtil.flip(cc.xy(1, 4), colSpec, orientation)); defaultaudiosubs = new JTextField(configuration.getAudioSubLanguages()); defaultaudiosubs.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setAudioSubLanguages(defaultaudiosubs.getText()); } }); builder.add(defaultaudiosubs, FormLayoutUtil.flip(cc.xyw(3, 4, 8), colSpec, orientation)); builder.addLabel(Messages.getString("MEncoderVideo.37"), FormLayoutUtil.flip(cc.xyw(1, 6, 2), colSpec, orientation)); alternateSubFolder = new JTextField(configuration.getAlternateSubtitlesFolder()); alternateSubFolder.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setAlternateSubtitlesFolder(alternateSubFolder.getText()); } }); builder.add(alternateSubFolder, FormLayoutUtil.flip(cc.xyw(3, 6, 8), colSpec, orientation)); folderSelectButton = new JButton("..."); folderSelectButton.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) { alternateSubFolder.setText(chooser.getSelectedFile().getAbsolutePath()); configuration.setAlternateSubtitlesFolder(chooser.getSelectedFile().getAbsolutePath()); } } }); builder.add(folderSelectButton, FormLayoutUtil.flip(cc.xyw(11, 6, 2), colSpec, orientation)); builder.addLabel(Messages.getString("MEncoderVideo.11"), FormLayoutUtil.flip(cc.xy(1, 8), colSpec, orientation)); Object data[] = new Object[] { configuration.getSubtitlesCodepage(), Messages.getString("MEncoderVideo.96"), Messages.getString("MEncoderVideo.97"), Messages.getString("MEncoderVideo.98"), Messages.getString("MEncoderVideo.99"), Messages.getString("MEncoderVideo.100"), Messages.getString("MEncoderVideo.101"), Messages.getString("MEncoderVideo.102"), Messages.getString("MEncoderVideo.103"), Messages.getString("MEncoderVideo.104"), Messages.getString("MEncoderVideo.105"), Messages.getString("MEncoderVideo.106"), Messages.getString("MEncoderVideo.107"), Messages.getString("MEncoderVideo.108"), Messages.getString("MEncoderVideo.109"), Messages.getString("MEncoderVideo.110"), Messages.getString("MEncoderVideo.111"), Messages.getString("MEncoderVideo.112"), Messages.getString("MEncoderVideo.113"), Messages.getString("MEncoderVideo.114"), Messages.getString("MEncoderVideo.115"), Messages.getString("MEncoderVideo.116"), Messages.getString("MEncoderVideo.117"), Messages.getString("MEncoderVideo.118"), Messages.getString("MEncoderVideo.119"), Messages.getString("MEncoderVideo.120"), Messages.getString("MEncoderVideo.121"), Messages.getString("MEncoderVideo.122"), Messages.getString("MEncoderVideo.123"), Messages.getString("MEncoderVideo.124") }; MyComboBoxModel cbm = new MyComboBoxModel(data); subtitleCodePage = new JComboBox(cbm); subtitleCodePage.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { String s = (String) e.getItem(); int offset = s.indexOf("/*"); if (offset > -1) { s = s.substring(0, offset).trim(); } configuration.setSubtitlesCodepage(s); } } }); subtitleCodePage.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { subtitleCodePage.getItemListeners()[0].itemStateChanged(new ItemEvent(subtitleCodePage, 0, subtitleCodePage.getEditor().getItem(), ItemEvent.SELECTED)); } }); subtitleCodePage.setEditable(true); builder.add(subtitleCodePage, FormLayoutUtil.flip(cc.xyw(3, 8, 7), colSpec, orientation)); fribidi = new JCheckBox(Messages.getString("MEncoderVideo.23")); fribidi.setContentAreaFilled(false); if (configuration.isMencoderSubFribidi()) { fribidi.setSelected(true); } fribidi.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setMencoderSubFribidi(e.getStateChange() == ItemEvent.SELECTED); } }); builder.add(fribidi, FormLayoutUtil.flip(cc.xyw(11, 8, 4), colSpec, orientation)); builder.addLabel(Messages.getString("MEncoderVideo.24"), FormLayoutUtil.flip(cc.xy(1, 10), colSpec, orientation)); defaultfont = new JTextField(configuration.getFont()); defaultfont.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setFont(defaultfont.getText()); } }); builder.add(defaultfont, FormLayoutUtil.flip(cc.xyw(3, 10, 8), colSpec, orientation)); fontselect = new JButton("..."); fontselect.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FontFileFilter()); int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("MEncoderVideo.25")); if (returnVal == JFileChooser.APPROVE_OPTION) { defaultfont.setText(chooser.getSelectedFile().getAbsolutePath()); configuration.setFont(chooser.getSelectedFile().getAbsolutePath()); } } }); builder.add(fontselect, FormLayoutUtil.flip(cc.xyw(11, 10, 2), colSpec, orientation)); builder.addLabel(Messages.getString("MEncoderVideo.12"), FormLayoutUtil.flip(cc.xy(1, 12), colSpec, orientation)); builder.addLabel(Messages.getString("MEncoderVideo.133"), FormLayoutUtil.flip(cc.xy(1, 14), colSpec, orientation)); ass_scale = new JTextField(configuration.getAssScale()); ass_scale.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setAssScale(ass_scale.getText()); } }); builder.addLabel(Messages.getString("MEncoderVideo.13"), FormLayoutUtil.flip(cc.xy(5, 12), colSpec, orientation)); ass_outline = new JTextField(configuration.getAssOutline()); ass_outline.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setAssOutline(ass_outline.getText()); } }); builder.addLabel(Messages.getString("MEncoderVideo.14"), FormLayoutUtil.flip(cc.xy(9, 12), colSpec, orientation)); ass_shadow = new JTextField(configuration.getAssShadow()); ass_shadow.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setAssShadow(ass_shadow.getText()); } }); builder.addLabel(Messages.getString("MEncoderVideo.15"), FormLayoutUtil.flip(cc.xy(13, 12), colSpec, orientation)); ass_margin = new JTextField(configuration.getAssMargin()); ass_margin.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setAssMargin(ass_margin.getText()); } }); builder.add(ass_scale, FormLayoutUtil.flip(cc.xy(3, 12), colSpec, orientation)); builder.add(ass_outline, FormLayoutUtil.flip(cc.xy(7, 12), colSpec, orientation)); builder.add(ass_shadow, FormLayoutUtil.flip(cc.xy(11, 12), colSpec, orientation)); builder.add(ass_margin, FormLayoutUtil.flip(cc.xy(15, 12), colSpec, orientation)); subs = new JCheckBox(Messages.getString("MEncoderVideo.22"), configuration.isAutoloadExternalSubtitles()); subs.setContentAreaFilled(false); subs.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setAutoloadExternalSubtitles((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(subs, FormLayoutUtil.flip(cc.xyw(1, 16, 13), colSpec, orientation)); subColor = new JButton(); subColor.setText(Messages.getString("MEncoderVideo.31")); subColor.setBackground(new Color(configuration.getSubsColor())); subColor.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Color newColor = JColorChooser.showDialog( SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()), Messages.getString("MEncoderVideo.125"), subColor.getBackground()); if (newColor != null) { subColor.setBackground(newColor); configuration.setSubsColor(newColor.getRGB()); } } }); builder.add(subColor, FormLayoutUtil.flip(cc.xyw(13, 16, 3), colSpec, orientation)); final JPanel panel = builder.getPanel(); boolean enable = !configuration.isDisableSubtitles(); for (Component component : panel.getComponents()) { component.setEnabled(enable); } disableSubs.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { // If "Disable Subtitles" is not selected, subtitles are enabled boolean enabled = e.getStateChange() != ItemEvent.SELECTED; for (Component component : panel.getComponents()) { component.setEnabled(enabled); } } }); panel.applyComponentOrientation(orientation); return panel; }
From source file:net.pms.util.FormLayoutUtil.java
License:Open Source License
/** * Creates and returns a horizontally flipped clone of the given cell * constraints object. Flips the horizontal alignment and the left and right * insets.//from w ww.j a v a2s . c om * * @param cc * the original cell constraints object * @return the flipped cell constraints with flipped horizontal alignment, * and flipped left and right insets - if any */ private static CellConstraints flipHorizontally(CellConstraints cc) { CellConstraints.Alignment flippedHAlign = cc.hAlign; if (flippedHAlign == CellConstraints.LEFT) { flippedHAlign = CellConstraints.RIGHT; } else { if (flippedHAlign == CellConstraints.RIGHT) { flippedHAlign = CellConstraints.LEFT; } } CellConstraints flipped = new CellConstraints(cc.gridX, cc.gridY, cc.gridWidth, cc.gridHeight, flippedHAlign, cc.vAlign); if (cc.insets != null) { flipped.insets = new Insets(cc.insets.top, cc.insets.right, cc.insets.bottom, cc.insets.left); } return flipped; }
From source file:net.rptools.maptool.client.ui.token.EditTokenDialog.java
License:Open Source License
private void updateStatesPanel() { // Group the states first into individual panels List<BooleanTokenOverlay> overlays = new ArrayList<BooleanTokenOverlay>( MapTool.getCampaign().getTokenStatesMap().values()); Map<String, JPanel> groups = new TreeMap<String, JPanel>(); groups.put("", new JPanel(new FormLayout("0px:grow 2px 0px:grow 2px 0px:grow 2px 0px:grow"))); for (BooleanTokenOverlay overlay : overlays) { String group = overlay.getGroup(); if (group != null && (group = group.trim()).length() != 0) { JPanel panel = groups.get(group); if (panel == null) { panel = new JPanel(new FormLayout("0px:grow 2px 0px:grow 2px 0px:grow 2px 0px:grow")); panel.setBorder(BorderFactory.createTitledBorder(group)); groups.put(group, panel); }//from w w w. j a va 2 s . c o m } } // Add the group panels and bar panel to the states panel JPanel panel = getStatesPanel(); panel.removeAll(); FormLayout layout = new FormLayout("0px:grow"); panel.setLayout(layout); int row = 1; for (JPanel gPanel : groups.values()) { layout.appendRow(new RowSpec("pref")); layout.appendRow(new RowSpec("2px")); panel.add(gPanel, new CellConstraints(1, row)); row += 2; } layout.appendRow(new RowSpec("pref")); layout.appendRow(new RowSpec("2px")); JPanel barPanel = new JPanel(new FormLayout("right:pref 2px pref 5px right:pref 2px pref")); panel.add(barPanel, new CellConstraints(1, row)); // Add the individual check boxes. for (BooleanTokenOverlay state : overlays) { String group = state.getGroup(); panel = groups.get(""); if (group != null && (group = group.trim()).length() != 0) panel = groups.get(group); int x = panel.getComponentCount() % 4; int y = panel.getComponentCount() / 4; if (x == 0) { layout = (FormLayout) panel.getLayout(); if (y != 0) layout.appendRow(new RowSpec("2px")); layout.appendRow(new RowSpec("pref")); } panel.add(new JCheckBox(state.getName()), new CellConstraints(x * 2 + 1, y * 2 + 1)); } // Add sliders to the bar panel if (MapTool.getCampaign().getTokenBarsMap().size() > 0) { layout = (FormLayout) barPanel.getLayout(); barPanel.setName("bar"); barPanel.setBorder(BorderFactory.createTitledBorder("Bars")); int count = 0; row = 0; for (BarTokenOverlay bar : MapTool.getCampaign().getTokenBarsMap().values()) { int working = count % 2; if (working == 0) { // slider row layout.appendRow(new RowSpec("pref")); row += 1; } JPanel labelPanel = new JPanel(new FormLayout("pref", "pref 2px:grow pref")); barPanel.add(labelPanel, new CellConstraints(1 + working * 4, row)); labelPanel.add(new JLabel(bar.getName() + ":"), new CellConstraints(1, 1, CellConstraints.RIGHT, CellConstraints.TOP)); JSlider slider = new JSlider(0, 100); JCheckBox hide = new JCheckBox("Hide"); hide.putClientProperty("JSlider", slider); hide.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider js = (JSlider) ((JCheckBox) e.getSource()).getClientProperty("JSlider"); js.setEnabled(!((JCheckBox) e.getSource()).isSelected()); } }); labelPanel.add(hide, new CellConstraints(1, 3, CellConstraints.RIGHT, CellConstraints.TOP)); slider.setName(bar.getName()); slider.setPaintLabels(true); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.createStandardLabels(20); slider.setMajorTickSpacing(10); barPanel.add(slider, new CellConstraints(3 + working * 4, row)); if (working != 0) { // spacer row layout.appendRow(new RowSpec("2px")); row += 1; } count += 1; } } }
From source file:net.rptools.maptool.client.ui.tokenpanel.InitiativeListCellRenderer.java
License:Open Source License
/** * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, * boolean)/*from w w w . java 2 s.com*/ */ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { // Set the background by type Token token = null; TokenInitiative ti = (TokenInitiative) value; if (ti != null) token = ti.getToken(); if (token == null) { // Can happen when deleting a token before all events have propagated currentIndicator.setIcon(null); name.setText(null); name.setIcon(null); setBorder(UNSELECTED_BORDER); return this; } // endif backgroundImageLabel = token.isVisible() ? token.getType() == Token.Type.NPC ? GraphicsUtil.BLUE_LABEL : GraphicsUtil.GREY_LABEL : GraphicsUtil.DARK_GREY_LABEL; name.setForeground(Color.BLACK); // Show the indicator? int currentIndex = panel.getList().getCurrent(); if (currentIndex >= 0 && ti == panel.getList().getTokenInitiative(currentIndex)) { currentIndicator.setIcon(CURRENT_INDICATOR_ICON); } else { currentIndicator.setIcon(null); } // endif // Get the name string, add the state if displayed, then get the icon if needed boolean initStateSecondLine = panel.isInitStateSecondLine() && panel.isShowInitState(); String sName = (initStateSecondLine ? "<html>" : "") + ti.getToken().getName(); if (MapTool.getFrame().getInitiativePanel().hasGMPermission() && token.getGMName() != null && token.getGMName().trim().length() != 0) sName += " (" + token.getGMName().trim() + ")"; if (panel.isShowInitState() && ti.getState() != null) sName += (initStateSecondLine ? "<br>" : " = ") + ti.getState(); if (initStateSecondLine) sName += "</html>"; Icon icon = null; if (panel.isShowTokens()) { icon = ti.getDisplayIcon(); if (icon == null) { icon = new InitiativeListIcon(ti); ti.setDisplayIcon(icon); } // endif } // endif name.setText(sName); name.setIcon(icon); // Align it properly Alignment alignment = ti.isHolding() ? CellConstraints.RIGHT : CellConstraints.LEFT; FormLayout layout = (FormLayout) getLayout(); layout.setConstraints(name, new CellConstraints(4, 1, alignment, CellConstraints.CENTER)); if (alignment == CellConstraints.RIGHT) { name.setHorizontalTextPosition(SwingConstants.LEFT); } else { name.setHorizontalTextPosition(SwingConstants.RIGHT); } // endif // Selected? if (isSelected) { setBorder(SELECTED_BORDER); } else { setBorder(UNSELECTED_BORDER); } // endif return this; }