List of usage examples for javax.swing SwingUtilities getWindowAncestor
public static Window getWindowAncestor(Component c)
Window
ancestor of c
, or null if c
is not contained inside a Window
. From source file:net.pms.encoders.AviSynthMEncoder.java
@Override public JComponent config() { FormLayout layout = new FormLayout("left:pref, 0:grow", "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 12dlu, p, 3dlu, 0:grow"); PanelBuilder builder = new PanelBuilder(layout); builder.border(Borders.EMPTY);// w ww . j a v a 2 s. co m builder.opaque(false); CellConstraints cc = new CellConstraints(); JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), cc.xyw(2, 1, 1)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); multithreading = new JCheckBox(Messages.getString("MEncoderVideo.35"), configuration.getAvisynthMultiThreading()); multithreading.setContentAreaFilled(false); multithreading.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setAvisynthMultiThreading((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(GuiUtil.getPreferredSizeComponent(multithreading), cc.xy(2, 3)); interframe = new JCheckBox(Messages.getString("AviSynthMEncoder.13"), configuration.getAvisynthInterFrame()); interframe.setContentAreaFilled(false); interframe.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { configuration.setAvisynthInterFrame(interframe.isSelected()); if (configuration.getAvisynthInterFrame()) { JOptionPane.showMessageDialog( SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()), Messages.getString("AviSynthMEncoder.16"), Messages.getString("Dialog.Information"), JOptionPane.INFORMATION_MESSAGE); } } }); builder.add(GuiUtil.getPreferredSizeComponent(interframe), cc.xy(2, 5)); interframegpu = new JCheckBox(Messages.getString("AviSynthMEncoder.15"), configuration.getAvisynthInterFrameGPU()); interframegpu.setContentAreaFilled(false); interframegpu.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setAvisynthInterFrameGPU((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(GuiUtil.getPreferredSizeComponent(interframegpu), cc.xy(2, 7)); convertfps = new JCheckBox(Messages.getString("AviSynthMEncoder.3"), configuration.getAvisynthConvertFps()); convertfps.setContentAreaFilled(false); convertfps.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setAvisynthConvertFps((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(GuiUtil.getPreferredSizeComponent(convertfps), cc.xy(2, 9)); String aviSynthScriptInstructions = Messages.getString("AviSynthMEncoder.4") + Messages.getString("AviSynthMEncoder.5") + Messages.getString("AviSynthMEncoder.6") + Messages.getString("AviSynthMEncoder.7") + Messages.getString("AviSynthMEncoder.8"); JTextArea aviSynthScriptInstructionsContainer = new JTextArea(aviSynthScriptInstructions); aviSynthScriptInstructionsContainer.setEditable(false); aviSynthScriptInstructionsContainer.setBorder(BorderFactory.createEtchedBorder()); aviSynthScriptInstructionsContainer.setBackground(new Color(255, 255, 192)); aviSynthScriptInstructionsContainer.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(new Color(130, 135, 144)), BorderFactory.createEmptyBorder(3, 5, 3, 5))); builder.add(aviSynthScriptInstructionsContainer, cc.xy(2, 11)); String clip = configuration.getAvisynthScript(); if (clip == null) { clip = ""; } StringBuilder sb = new StringBuilder(); StringTokenizer st = new StringTokenizer(clip, PMS.AVS_SEPARATOR); int i = 0; while (st.hasMoreTokens()) { if (i > 0) { sb.append("\n"); } sb.append(st.nextToken()); i++; } textArea = new JTextArea(sb.toString()); textArea.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { StringBuilder sb = new StringBuilder(); StringTokenizer st = new StringTokenizer(textArea.getText(), "\n"); int i = 0; while (st.hasMoreTokens()) { if (i > 0) { sb.append(PMS.AVS_SEPARATOR); } sb.append(st.nextToken()); i++; } configuration.setAvisynthScript(sb.toString()); } }); JScrollPane pane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); pane.setPreferredSize(new Dimension(500, 350)); builder.add(pane, cc.xy(2, 13)); configuration.addConfigurationListener(new ConfigurationListener() { @Override public void configurationChanged(ConfigurationEvent event) { if (event.getPropertyName() == null) { return; } if ((!event.isBeforeUpdate()) && event.getPropertyName().equals(PmsConfiguration.KEY_GPU_ACCELERATION)) { interframegpu.setEnabled(configuration.isGPUAcceleration()); } } }); return builder.getPanel(); }
From source file:com.googlecode.vfsjfilechooser2.accessories.DefaultAccessoriesPanel.java
private void initComponents() { buttonsPanel = new JPanel(); buttonsPanel.setLayout(new GridLayout(0, 1, 3, 3)); Action action;//from ww w. ja v a 2 s . c om action = new ManageBookmarksAction(VFSResources.getMessage("VFSJFileChooser.bookmarksLabelText"), getIcon("book.png")); bookmarksButton = new JButton(action); bookmarksButton.setHorizontalAlignment(SwingConstants.LEFT); action = new ConnectionWizardAction(VFSResources.getMessage("VFSJFileChooser.connectionButtonText"), getIcon("connect.png")); connectionsButton = new JButton(action); connectionsButton.setHorizontalAlignment(SwingConstants.LEFT); action = new LocalFilesAction(VFSResources.getMessage("VFSJFileChooser.localFilesButtonText"), getIcon("drive.png")); localFSButton = new JButton(action); localFSButton.setHorizontalAlignment(SwingConstants.LEFT); buttonsPanel.add(bookmarksButton); buttonsPanel.add(Box.createVerticalStrut(20)); buttonsPanel.add(connectionsButton); buttonsPanel.add(Box.createVerticalStrut(20)); buttonsPanel.add(localFSButton); add(buttonsPanel, BorderLayout.NORTH); add(new JPanel(), BorderLayout.CENTER); final Frame c = (Frame) SwingUtilities.getWindowAncestor(fileChooser); bookmarksDialog = new BookmarksDialog(c, fileChooser); connectionDialog = new ConnectionDialog(c, bookmarksDialog, fileChooser); }
From source file:com.opendoorlogistics.studio.components.map.plugins.snapshot.ExportImagePanel.java
public static ExportImageConfig showModal(Component parent, ExportImageConfig inputConfig, Dimension defaultSize) {//from w ww.j av a 2 s . c o m return showModal(parent != null ? SwingUtilities.getWindowAncestor(parent) : null, parent, inputConfig, defaultSize); }
From source file:net.pms.dlna.DLNAMediaDatabase.java
public void init(boolean force) { dbCount = -1;//from w ww .j av a2s . c o m String version = null; Connection conn = null; ResultSet rs = null; Statement stmt = null; try { conn = getConnection(); } catch (SQLException se) { final File dbFile = new File(dbDir + File.separator + dbName + ".data.db"); final File dbDirectory = new File(dbDir); if (dbFile.exists() || (se.getErrorCode() == 90048)) { // Cache is corrupt or wrong version, so delete it FileUtils.deleteQuietly(dbDirectory); if (!dbDirectory.exists()) { logger.debug("The cache has been deleted because it was corrupt or had the wrong version"); } else { if (!PMS.isHeadless()) { JOptionPane.showMessageDialog( (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())), String.format(Messages.getString("DLNAMediaDatabase.5"), dbDir), Messages.getString("Dialog.Error"), JOptionPane.ERROR_MESSAGE); } logger.debug("Damaged cache can't be deleted. Stop the program and delete the folder \"" + dbDir + "\" manually"); configuration.setUseCache(false); return; } } else { logger.debug("Cache connection error: " + se.getMessage()); configuration.setUseCache(false); return; } } try { conn = getConnection(); stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT count(*) FROM FILES"); if (rs.next()) { dbCount = rs.getInt(1); } rs.close(); stmt.close(); stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT VALUE FROM METADATA WHERE KEY = 'VERSION'"); if (rs.next()) { version = rs.getString(1); } } catch (SQLException se) { if (se.getErrorCode() != 42102) { // Don't log exception "Table "FILES" not found" which will be corrected in following step logger.error(null, se); } } finally { close(rs); close(stmt); close(conn); } boolean force_reinit = !PMS.getVersion().equals(version); // here we can force a deletion for a specific version if (force || dbCount == -1 || force_reinit) { logger.debug("Database will be (re)initialized"); try { conn = getConnection(); executeUpdate(conn, "DROP TABLE FILES"); executeUpdate(conn, "DROP TABLE METADATA"); executeUpdate(conn, "DROP TABLE REGEXP_RULES"); executeUpdate(conn, "DROP TABLE AUDIOTRACKS"); executeUpdate(conn, "DROP TABLE SUBTRACKS"); } catch (SQLException se) { if (se.getErrorCode() != 42102) { // Don't log exception "Table "FILES" not found" which will be corrected in following step logger.error(null, se); } } try { StringBuilder sb = new StringBuilder(); sb.append("CREATE TABLE FILES ("); sb.append(" ID INT AUTO_INCREMENT"); sb.append(", FILENAME VARCHAR2(1024) NOT NULL"); sb.append(", MODIFIED TIMESTAMP NOT NULL"); sb.append(", TYPE INT"); sb.append(", DURATION DOUBLE"); sb.append(", BITRATE INT"); sb.append(", WIDTH INT"); sb.append(", HEIGHT INT"); sb.append(", SIZE NUMERIC"); sb.append(", CODECV VARCHAR2(").append(SIZE_CODECV).append(")"); sb.append(", FRAMERATE VARCHAR2(").append(SIZE_FRAMERATE).append(")"); sb.append(", ASPECT VARCHAR2(").append(SIZE_ASPECT).append(")"); sb.append(", ASPECTRATIOCONTAINER VARCHAR2(").append(SIZE_ASPECTRATIO_CONTAINER).append(")"); sb.append(", ASPECTRATIOVIDEOTRACK VARCHAR2(").append(SIZE_ASPECTRATIO_VIDEOTRACK).append(")"); sb.append(", REFRAMES TINYINT"); sb.append(", AVCLEVEL VARCHAR2(").append(SIZE_AVC_LEVEL).append(")"); sb.append(", BITSPERPIXEL INT"); sb.append(", THUMB BINARY"); sb.append(", CONTAINER VARCHAR2(").append(SIZE_CONTAINER).append(")"); sb.append(", MODEL VARCHAR2(").append(SIZE_MODEL).append(")"); sb.append(", EXPOSURE INT"); sb.append(", ORIENTATION INT"); sb.append(", ISO INT"); sb.append(", MUXINGMODE VARCHAR2(").append(SIZE_MUXINGMODE).append(")"); sb.append(", FRAMERATEMODE VARCHAR2(").append(SIZE_FRAMERATE_MODE).append(")"); sb.append(", constraint PK1 primary key (FILENAME, MODIFIED, ID))"); executeUpdate(conn, sb.toString()); sb = new StringBuilder(); sb.append("CREATE TABLE AUDIOTRACKS ("); sb.append(" FILEID INT NOT NULL"); sb.append(", ID INT NOT NULL"); sb.append(", LANG VARCHAR2(").append(SIZE_LANG).append(")"); sb.append(", FLAVOR VARCHAR2(").append(SIZE_FLAVOR).append(")"); sb.append(", NRAUDIOCHANNELS NUMERIC"); sb.append(", SAMPLEFREQ VARCHAR2(").append(SIZE_SAMPLEFREQ).append(")"); sb.append(", CODECA VARCHAR2(").append(SIZE_CODECA).append(")"); sb.append(", BITSPERSAMPLE INT"); sb.append(", ALBUM VARCHAR2(").append(SIZE_ALBUM).append(")"); sb.append(", ARTIST VARCHAR2(").append(SIZE_ARTIST).append(")"); sb.append(", SONGNAME VARCHAR2(").append(SIZE_SONGNAME).append(")"); sb.append(", GENRE VARCHAR2(").append(SIZE_GENRE).append(")"); sb.append(", YEAR INT"); sb.append(", TRACK INT"); sb.append(", DELAY INT"); sb.append(", MUXINGMODE VARCHAR2(").append(SIZE_MUXINGMODE).append(")"); sb.append(", BITRATE INT"); sb.append(", constraint PKAUDIO primary key (FILEID, ID))"); executeUpdate(conn, sb.toString()); sb = new StringBuilder(); sb.append("CREATE TABLE SUBTRACKS ("); sb.append(" FILEID INT NOT NULL"); sb.append(", ID INT NOT NULL"); sb.append(", LANG VARCHAR2(").append(SIZE_LANG).append(")"); sb.append(", FLAVOR VARCHAR2(").append(SIZE_FLAVOR).append(")"); sb.append(", TYPE INT"); sb.append(", constraint PKSUB primary key (FILEID, ID))"); executeUpdate(conn, sb.toString()); executeUpdate(conn, "CREATE TABLE METADATA (KEY VARCHAR2(255) NOT NULL, VALUE VARCHAR2(255) NOT NULL)"); executeUpdate(conn, "INSERT INTO METADATA VALUES ('VERSION', '" + PMS.getVersion() + "')"); executeUpdate(conn, "CREATE INDEX IDXARTIST on AUDIOTRACKS (ARTIST asc);"); executeUpdate(conn, "CREATE INDEX IDXALBUM on AUDIOTRACKS (ALBUM asc);"); executeUpdate(conn, "CREATE INDEX IDXGENRE on AUDIOTRACKS (GENRE asc);"); executeUpdate(conn, "CREATE INDEX IDXYEAR on AUDIOTRACKS (YEAR asc);"); executeUpdate(conn, "CREATE TABLE REGEXP_RULES ( ID VARCHAR2(255) PRIMARY KEY, RULE VARCHAR2(255), ORDR NUMERIC);"); executeUpdate(conn, "INSERT INTO REGEXP_RULES VALUES ( '###', '(?i)^\\W.+', 0 );"); executeUpdate(conn, "INSERT INTO REGEXP_RULES VALUES ( '0-9', '(?i)^\\d.+', 1 );"); // Retrieve the alphabet property value and split it String[] chars = Messages.getString("DLNAMediaDatabase.1").split(","); for (int i = 0; i < chars.length; i++) { // Create regexp rules for characters with a sort order based on the property value executeUpdate(conn, "INSERT INTO REGEXP_RULES VALUES ( '" + chars[i] + "', '(?i)^" + chars[i] + ".+', " + (i + 2) + " );"); } logger.debug("Database initialized"); } catch (SQLException se) { logger.info("Error in table creation: " + se.getMessage()); } finally { close(conn); } } else { logger.debug("Database file count: " + dbCount); logger.debug("Database version: " + version); } }
From source file:net.pms.newgui.NetworkTab.java
public JComponent build() { FormLayout layout = new FormLayout("left:pref, 2dlu, p, 2dlu , p, 2dlu, p, 2dlu, pref:grow", "p, 0dlu, p, 0dlu, p, 3dlu, p, 3dlu, p, 3dlu,p, 3dlu, p, 15dlu, p, 3dlu,p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p,3dlu, p, 3dlu, p, 15dlu, p,3dlu, p, 3dlu, p, 15dlu, p, 3dlu, p"); PanelBuilder builder = new PanelBuilder(layout); builder.setBorder(Borders.DLU4_BORDER); builder.setOpaque(true);/*w w w. j a v a 2s.c om*/ CellConstraints cc = new CellConstraints(); smcheckBox = new JCheckBox(Messages.getString("NetworkTab.3")); smcheckBox.setContentAreaFilled(false); smcheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { PMS.getConfiguration().setMinimized((e.getStateChange() == ItemEvent.SELECTED)); } }); if (PMS.getConfiguration().isMinimized()) { smcheckBox.setSelected(true); } JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), cc.xyw(1, 1, 9)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); builder.addLabel(Messages.getString("NetworkTab.0"), cc.xy(1, 7)); final KeyedComboBoxModel kcbm = new KeyedComboBoxModel( new Object[] { "bg", "ca", "zhs", "zht", "cz", "da", "nl", "en", "fi", "fr", "de", "el", "is", "it", "ja", "no", "pl", "pt", "br", "ro", "ru", "sl", "es", "sv" }, new Object[] { "Bulgarian", "Catalan", "Chinese (Simplified)", "Chinese (Traditional)", "Czech", "Danish", "Dutch", "English", "Finnish", "French", "German", "Greek", "Icelandic", "Italian", "Japanese", "Norwegian", "Polish", "Portuguese", "Portuguese (Brazilian)", "Romanian", "Russian", "Slovenian", "Spanish", "Swedish" }); langs = new JComboBox(kcbm); langs.setEditable(false); //langs.setSelectedIndex(0); String defaultLang = null; if (configuration.getLanguage() != null && configuration.getLanguage().length() > 0) { defaultLang = configuration.getLanguage(); } else { defaultLang = Locale.getDefault().getLanguage(); } if (defaultLang == null) { defaultLang = "en"; } kcbm.setSelectedKey(defaultLang); if (langs.getSelectedIndex() == -1) { langs.setSelectedIndex(0); } langs.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { configuration.setLanguage((String) kcbm.getSelectedKey()); } } }); builder.add(langs, cc.xyw(3, 7, 7)); builder.add(smcheckBox, cc.xyw(1, 9, 9)); JButton service = new JButton(Messages.getString("NetworkTab.4")); service.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (PMS.get().installWin32Service()) { JOptionPane.showMessageDialog( (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())), Messages.getString("NetworkTab.11") + Messages.getString("NetworkTab.12"), "Information", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog( (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())), Messages.getString("NetworkTab.14"), "Error", JOptionPane.ERROR_MESSAGE); } } }); builder.add(service, cc.xy(1, 11)); if (System.getProperty(LooksFrame.START_SERVICE) != null || !Platform.isWindows()) { service.setEnabled(false); } host = new JTextField(PMS.getConfiguration().getServerHostname()); host.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { configuration.setHostname(host.getText()); PMS.get().getFrame().setReloadable(true); } }); // host.setEnabled( StringUtils.isBlank(configuration.getNetworkInterface())) ; port = new JTextField(configuration.getServerPort() != 5001 ? "" + configuration.getServerPort() : ""); port.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { try { String p = port.getText(); if (StringUtils.isEmpty(p)) { p = "5001"; } int ab = Integer.parseInt(p); configuration.setServerPort(ab); PMS.get().getFrame().setReloadable(true); } catch (NumberFormatException nfe) { } } }); cmp = builder.addSeparator(Messages.getString("NetworkTab.22"), cc.xyw(1, 21, 9)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); ArrayList<String> names = new ArrayList<String>(); names.add(""); ArrayList<String> interfaces = new ArrayList<String>(); interfaces.add(""); Enumeration<NetworkInterface> enm; try { enm = NetworkInterface.getNetworkInterfaces(); while (enm.hasMoreElements()) { NetworkInterface ni = enm.nextElement(); // check for interface has at least one ip address. if (ni.getInetAddresses().hasMoreElements()) { names.add(ni.getName()); String displayName = ni.getDisplayName(); if (displayName == null) { displayName = ni.getName(); } interfaces.add(displayName.trim()); } } } catch (SocketException e1) { logger.error(null, e1); } final KeyedComboBoxModel networkInterfaces = new KeyedComboBoxModel(names.toArray(), interfaces.toArray()); networkinterfacesCBX = new JComboBox(networkInterfaces); networkInterfaces.setSelectedKey(configuration.getNetworkInterface()); networkinterfacesCBX.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { configuration.setNetworkInterface((String) networkInterfaces.getSelectedKey()); //host.setEnabled( StringUtils.isBlank(configuration.getNetworkInterface())) ; PMS.get().getFrame().setReloadable(true); } } }); ip_filter = new JTextField(PMS.getConfiguration().getIpFilter()); ip_filter.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { configuration.setIpFilter(ip_filter.getText()); PMS.get().getFrame().setReloadable(true); } }); builder.addLabel(Messages.getString("NetworkTab.20"), cc.xy(1, 23)); builder.add(networkinterfacesCBX, cc.xyw(3, 23, 7)); builder.addLabel(Messages.getString("NetworkTab.23"), cc.xy(1, 25)); builder.add(host, cc.xyw(3, 25, 7)); builder.addLabel(Messages.getString("NetworkTab.24"), cc.xy(1, 27)); builder.add(port, cc.xyw(3, 27, 7)); builder.addLabel(Messages.getString("NetworkTab.30"), cc.xy(1, 29)); builder.add(ip_filter, cc.xyw(3, 29, 7)); cmp = builder.addSeparator(Messages.getString("NetworkTab.31"), cc.xyw(1, 31, 9)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); newHTTPEngine = new JCheckBox(Messages.getString("NetworkTab.32")); newHTTPEngine.setSelected(PMS.getConfiguration().isHTTPEngineV2()); newHTTPEngine.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { PMS.getConfiguration().setHTTPEngineV2((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(newHTTPEngine, cc.xyw(1, 33, 9)); preventSleep = new JCheckBox(Messages.getString("NetworkTab.33")); preventSleep.setSelected(PMS.getConfiguration().isPreventsSleep()); preventSleep.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { PMS.getConfiguration().setPreventsSleep((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(preventSleep, cc.xyw(1, 35, 9)); cmp = builder.addSeparator(Messages.getString("NetworkTab.34"), cc.xyw(1, 37, 9)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); JPanel panel = builder.getPanel(); JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); return scrollPane; }
From source file:components.IntegerEditor.java
/** * Lets the user know that the text they entered is * bad. Returns true if the user elects to revert to * the last good value. Otherwise, returns false, * indicating that the user wants to continue editing. *//* w w w.j a v a2 s . co m*/ protected boolean userSaysRevert() { Toolkit.getDefaultToolkit().beep(); ftf.selectAll(); Object[] options = { "Edit", "Revert" }; int answer = JOptionPane.showOptionDialog(SwingUtilities.getWindowAncestor(ftf), "The value must be an integer between " + minimum + " and " + maximum + ".\n" + "You can either continue editing " + "or revert to the last valid value.", "Invalid Text Entered", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[1]); if (answer == 1) { //Revert! ftf.setValue(ftf.getValue()); return true; } return false; }
From source file:fr.duminy.components.swing.form.JFormPane.java
/** * Display this form in a dialog./*from w ww .j ava2 s.c om*/ * * @param parentComponent The parent component of the dialog. * @return The final value entered by the user in the dialog, or null if it was cancelled. */ public B showDialog(Component parentComponent) { Window parentWindow; if (parentComponent == null) { parentWindow = JOptionPane.getRootFrame(); } else if (parentComponent instanceof Window) { parentWindow = (Window) parentComponent; } else { parentWindow = SwingUtilities.getWindowAncestor(parentComponent); } final JDialog dialog = new JDialog(parentWindow, title, Dialog.ModalityType.APPLICATION_MODAL); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setContentPane(this); dialog.setResizable(false); setBorder(null); final MutableObject<Boolean> validated = new MutableObject<>(false); FormListener<B> listener = new FormListener<B>() { @Override public void formValidated(Form<B> form) { validated.setValue(true); dialog.dispose(); } @Override public void formCancelled(Form<B> form) { dialog.dispose(); } }; try { addFormListener(listener); dialog.pack(); dialog.setVisible(true); return validated.getValue() ? getValue() : null; } finally { removeFormListener(listener); } }
From source file:Utilities.java
/** * Finds out the monitor where the user currently has the input focus. * This method is usually used to help the client code to figure out on * which monitor it should place newly created windows/frames/dialogs. * * @return the GraphicsConfiguration of the monitor which currently has the * input focus//w ww .ja va 2 s.co m */ private static GraphicsConfiguration getCurrentGraphicsConfiguration() { Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (focusOwner != null) { Window w = SwingUtilities.getWindowAncestor(focusOwner); if (w != null) { return w.getGraphicsConfiguration(); } } return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); }
From source file:net.pms.newgui.GeneralTab.java
public JComponent build() { // Apply the orientation for the locale Locale locale = new Locale(configuration.getLanguage()); ComponentOrientation orientation = ComponentOrientation.getOrientation(locale); String colSpec = FormLayoutUtil.getColSpec(COL_SPEC, orientation); FormLayout layout = new FormLayout(colSpec, ROW_SPEC); PanelBuilder builder = new PanelBuilder(layout); builder.setBorder(Borders.DLU4_BORDER); builder.setOpaque(true);//from w w w.j a v a 2 s.co m CellConstraints cc = new CellConstraints(); smcheckBox = new JCheckBox(Messages.getString("NetworkTab.3")); smcheckBox.setContentAreaFilled(false); smcheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setMinimized((e.getStateChange() == ItemEvent.SELECTED)); } }); if (configuration.isMinimized()) { smcheckBox.setSelected(true); } JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), FormLayoutUtil.flip(cc.xyw(1, 1, 9), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); builder.addLabel(Messages.getString("NetworkTab.0"), FormLayoutUtil.flip(cc.xy(1, 7), colSpec, orientation)); final KeyedComboBoxModel kcbm = new KeyedComboBoxModel( new Object[] { "ar", "bg", "ca", "zhs", "zht", "cz", "da", "nl", "en", "fi", "fr", "de", "el", "iw", "is", "it", "ja", "ko", "no", "pl", "pt", "br", "ro", "ru", "sl", "es", "sv", "tr" }, new Object[] { "Arabic", "Bulgarian", "Catalan", "Chinese (Simplified)", "Chinese (Traditional)", "Czech", "Danish", "Dutch", "English", "Finnish", "French", "German", "Greek", "Hebrew", "Icelandic", "Italian", "Japanese", "Korean", "Norwegian", "Polish", "Portuguese", "Portuguese (Brazilian)", "Romanian", "Russian", "Slovenian", "Spanish", "Swedish", "Turkish" }); langs = new JComboBox(kcbm); langs.setEditable(false); String defaultLang = null; if (configuration.getLanguage() != null && configuration.getLanguage().length() > 0) { defaultLang = configuration.getLanguage(); } else { defaultLang = Locale.getDefault().getLanguage(); } if (defaultLang == null) { defaultLang = "en"; } kcbm.setSelectedKey(defaultLang); if (langs.getSelectedIndex() == -1) { langs.setSelectedIndex(0); } langs.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { configuration.setLanguage((String) kcbm.getSelectedKey()); } } }); builder.add(langs, FormLayoutUtil.flip(cc.xyw(3, 7, 7), colSpec, orientation)); builder.add(smcheckBox, FormLayoutUtil.flip(cc.xyw(1, 9, 9), colSpec, orientation)); JButton service = new JButton(Messages.getString("NetworkTab.4")); service.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (PMS.get().installWin32Service()) { JOptionPane.showMessageDialog( (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())), Messages.getString("NetworkTab.11") + Messages.getString("NetworkTab.12"), Messages.getString("Dialog.Information"), JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog( (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())), Messages.getString("NetworkTab.14"), Messages.getString("Dialog.Error"), JOptionPane.ERROR_MESSAGE); } } }); builder.add(service, FormLayoutUtil.flip(cc.xy(1, 11), colSpec, orientation)); if (System.getProperty(LooksFrame.START_SERVICE) != null || !Platform.isWindows()) { service.setEnabled(false); } JButton checkForUpdates = new JButton(Messages.getString("NetworkTab.8")); checkForUpdates.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { LooksFrame frame = (LooksFrame) PMS.get().getFrame(); frame.checkForUpdates(); } }); builder.add(checkForUpdates, FormLayoutUtil.flip(cc.xy(1, 13), colSpec, orientation)); autoUpdateCheckBox = new JCheckBox(Messages.getString("NetworkTab.9")); autoUpdateCheckBox.setContentAreaFilled(false); autoUpdateCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setAutoUpdate((e.getStateChange() == ItemEvent.SELECTED)); } }); if (configuration.isAutoUpdate()) { autoUpdateCheckBox.setSelected(true); } builder.add(autoUpdateCheckBox, FormLayoutUtil.flip(cc.xyw(7, 13, 3), colSpec, orientation)); if (!Build.isUpdatable()) { checkForUpdates.setEnabled(false); autoUpdateCheckBox.setEnabled(false); } host = new JTextField(configuration.getServerHostname()); host.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setHostname(host.getText()); } }); port = new JTextField(configuration.getServerPort() != 5001 ? "" + configuration.getServerPort() : ""); port.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { try { String p = port.getText(); if (StringUtils.isEmpty(p)) { p = "5001"; } int ab = Integer.parseInt(p); configuration.setServerPort(ab); } catch (NumberFormatException nfe) { logger.debug("Could not parse port from \"" + port.getText() + "\""); } } }); cmp = builder.addSeparator(Messages.getString("NetworkTab.22"), FormLayoutUtil.flip(cc.xyw(1, 21, 9), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); final KeyedComboBoxModel networkInterfaces = createNetworkInterfacesModel(); networkinterfacesCBX = new JComboBox(networkInterfaces); networkInterfaces.setSelectedKey(configuration.getNetworkInterface()); networkinterfacesCBX.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { configuration.setNetworkInterface((String) networkInterfaces.getSelectedKey()); } } }); ip_filter = new JTextField(configuration.getIpFilter()); ip_filter.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setIpFilter(ip_filter.getText()); } }); maxbitrate = new JTextField(configuration.getMaximumBitrate()); maxbitrate.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { PMS.getConfiguration().setMaximumBitrate(maxbitrate.getText()); } }); builder.addLabel(Messages.getString("NetworkTab.20"), FormLayoutUtil.flip(cc.xy(1, 23), colSpec, orientation)); builder.add(networkinterfacesCBX, FormLayoutUtil.flip(cc.xyw(3, 23, 7), colSpec, orientation)); builder.addLabel(Messages.getString("NetworkTab.23"), FormLayoutUtil.flip(cc.xy(1, 25), colSpec, orientation)); builder.add(host, FormLayoutUtil.flip(cc.xyw(3, 25, 7), colSpec, orientation)); builder.addLabel(Messages.getString("NetworkTab.24"), FormLayoutUtil.flip(cc.xy(1, 27), colSpec, orientation)); builder.add(port, FormLayoutUtil.flip(cc.xyw(3, 27, 7), colSpec, orientation)); builder.addLabel(Messages.getString("NetworkTab.30"), FormLayoutUtil.flip(cc.xy(1, 29), colSpec, orientation)); builder.add(ip_filter, FormLayoutUtil.flip(cc.xyw(3, 29, 7), colSpec, orientation)); builder.addLabel(Messages.getString("NetworkTab.35"), FormLayoutUtil.flip(cc.xy(1, 31), colSpec, orientation)); builder.add(maxbitrate, FormLayoutUtil.flip(cc.xyw(3, 31, 7), colSpec, orientation)); cmp = builder.addSeparator(Messages.getString("NetworkTab.31"), FormLayoutUtil.flip(cc.xyw(1, 33, 9), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); newHTTPEngine = new JCheckBox(Messages.getString("NetworkTab.32")); newHTTPEngine.setSelected(configuration.isHTTPEngineV2()); newHTTPEngine.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setHTTPEngineV2((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(newHTTPEngine, FormLayoutUtil.flip(cc.xyw(1, 35, 9), colSpec, orientation)); preventSleep = new JCheckBox(Messages.getString("NetworkTab.33")); preventSleep.setSelected(configuration.isPreventsSleep()); preventSleep.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setPreventsSleep((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(preventSleep, FormLayoutUtil.flip(cc.xyw(1, 37, 9), colSpec, orientation)); JCheckBox fdCheckBox = new JCheckBox(Messages.getString("NetworkTab.38")); fdCheckBox.setContentAreaFilled(false); fdCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setRendererForceDefault((e.getStateChange() == ItemEvent.SELECTED)); } }); if (configuration.isRendererForceDefault()) { fdCheckBox.setSelected(true); } builder.addLabel(Messages.getString("NetworkTab.36"), FormLayoutUtil.flip(cc.xy(1, 39), colSpec, orientation)); ArrayList<RendererConfiguration> allConfs = RendererConfiguration.getAllRendererConfigurations(); ArrayList<Object> keyValues = new ArrayList<Object>(); ArrayList<Object> nameValues = new ArrayList<Object>(); keyValues.add(""); nameValues.add(Messages.getString("NetworkTab.37")); if (allConfs != null) { for (RendererConfiguration renderer : allConfs) { if (renderer != null) { keyValues.add(renderer.getRendererName()); nameValues.add(renderer.getRendererName()); } } } final KeyedComboBoxModel renderersKcbm = new KeyedComboBoxModel( (Object[]) keyValues.toArray(new Object[keyValues.size()]), (Object[]) nameValues.toArray(new Object[nameValues.size()])); renderers = new JComboBox(renderersKcbm); renderers.setEditable(false); String defaultRenderer = configuration.getRendererDefault(); renderersKcbm.setSelectedKey(defaultRenderer); if (renderers.getSelectedIndex() == -1) { renderers.setSelectedIndex(0); } builder.add(renderers, FormLayoutUtil.flip(cc.xyw(3, 39, 7), colSpec, orientation)); builder.add(fdCheckBox, FormLayoutUtil.flip(cc.xyw(1, 41, 9), colSpec, orientation)); cmp = builder.addSeparator(Messages.getString("NetworkTab.34"), FormLayoutUtil.flip(cc.xyw(1, 43, 9), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); pPlugins = new JPanel(new GridLayout()); builder.add(pPlugins, FormLayoutUtil.flip(cc.xyw(1, 45, 9), 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); return scrollPane; }
From source file:com.opendoorlogistics.studio.scripts.list.ScriptsPanel.java
private List<MyAction> createActions(AppPermissions appPermissions) { ArrayList<MyAction> ret = new ArrayList<>(); if (appPermissions.isScriptEditingAllowed()) { ret.add(new MyAction(SimpleActionConfig.addItem.setItemName("script"), false, false, false) { @Override//from ww w .ja v a 2s. co m public void actionPerformed(ActionEvent e) { Script script = new SetupComponentWizard(SwingUtilities.getWindowAncestor(ScriptsPanel.this), api, scriptUIManager.getAvailableFieldsQuery()).showModal(); // Script script =new ScriptWizardActions(api,SwingUtilities.getWindowAncestor(ScriptsPanel.this)).promptUser(); if (script != null) { scriptUIManager.launchScriptEditor(script, null, isOkDirectory() ? directory : null); } } }); ret.add(new MyAction(SimpleActionConfig.editItem.setItemName("script"), false, false, true) { @Override public void actionPerformed(ActionEvent e) { ScriptNode node = scriptsTree.getSelectedValue(); if (node != null && node.isAvailable()) { ScriptsPanel.this.scriptUIManager.launchScriptEditor(node.getFile(), node.getLaunchEditorId()); } } }); ret.add(new MyAction(SimpleActionConfig.deleteItem.setItemName("script"), false, false, false) { @Override public void actionPerformed(ActionEvent e) { ScriptNode node = scriptsTree.getSelectedValue(); if (node == null) { return; } if (JOptionPane.showConfirmDialog(ScriptsPanel.this, "Really delete script " + node.getFile().getName() + " from disk?", "Delete script", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION) { if (!node.getFile().delete()) { JOptionPane.showMessageDialog(ScriptsPanel.this, "Could not delete file"); } else { onDirectoryChanged(directory); } } } @Override public void updateEnabledState() { ScriptNode selected = scriptsTree.getSelectedValue(); boolean enabled = true; if (selected == null) { enabled = false; } if (enabled && selected.isScriptRoot() == false) { // can only delete the root enabled = false; } setEnabled(enabled); } }); ret.add(new MyAction(SimpleActionConfig.testCompileScript, true, false, true) { @Override public void actionPerformed(ActionEvent e) { ScriptNode node = scriptsTree.getSelectedValue(); if (node != null) { scriptUIManager.testCompileScript(node.getFile(), node.getLaunchExecutorId()); } } }); ret.add(new MyAction(SimpleActionConfig.runScript, true, true, true) { @Override public void actionPerformed(ActionEvent e) { ScriptNode node = scriptsTree.getSelectedValue(); if (node != null) { scriptUIManager.executeScript(node.getFile(), node.getLaunchExecutorId()); } } @Override public void updateEnabledState() { setEnabled(ScriptNode.isRunnable(scriptsTree.getSelectedValue(), scriptUIManager)); } }); } return ret; }