List of usage examples for java.awt.event FocusListener FocusListener
FocusListener
From source file:com.sec.ose.osi.ui.frm.login.JPanLogin.java
/** * This method initializes jTextFieldServerIP * // w w w . j a v a 2 s. c o m * @return javax.swing.JTextField */ private JTextField getJTextFieldServerIP() { if (jTextFieldServerIP == null) { jTextFieldServerIP = new JTextField(); jTextFieldServerIP.setPreferredSize(new Dimension(200, 22)); jTextFieldServerIP.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent e) { mEventHandler.handle(EventHandler.TF_SERVER_IP); } }); jTextFieldServerIP.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { mEventHandler.handle(EventHandler.ENTER_KEY_TYTPED); } } }); jTextFieldServerIP.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { jTextFieldServerIP.selectAll(); } @Override public void focusLost(FocusEvent e) { jTextFieldServerIP.select(0, 0); } }); } return jTextFieldServerIP; }
From source file:self.philbrown.javaQuery.$.java
/** * Refreshes the listeners for focus changes *//*from w ww. j av a 2 s . c om*/ private void setupFocusListener() { for (final Component view : views) { view.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent event) { if (onFocus != null) onFocus.invoke($.with(view)); } @Override public void focusLost(FocusEvent event) { if (offFocus != null) offFocus.invoke($.with(view)); } }); } }
From source file:edu.brown.gui.CatalogViewer.java
/** * //from ww w .j ava 2 s. c om */ protected void viewerInit() { // ---------------------------------------------- // MENU // ---------------------------------------------- JMenu menu; JMenuItem menuItem; // // File Menu // menu = new JMenu("File"); menu.getPopupMenu().setLightWeightPopupEnabled(false); menu.setMnemonic(KeyEvent.VK_F); menu.getAccessibleContext().setAccessibleDescription("File Menu"); menuBar.add(menu); menuItem = new JMenuItem("Open Catalog From File"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From File"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_FILE); menu.add(menuItem); menuItem = new JMenuItem("Open Catalog From Jar"); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From Project Jar"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_JAR); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem("Quit", KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Quit Program"); menuItem.addActionListener(this.menuHandler); menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.QUIT); menu.add(menuItem); // ---------------------------------------------- // CATALOG TREE PANEL // ---------------------------------------------- this.catalogTree = new JTree(); this.catalogTree.setEditable(false); this.catalogTree.setCellRenderer(new CatalogViewer.CatalogTreeRenderer()); this.catalogTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); this.catalogTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) CatalogViewer.this.catalogTree .getLastSelectedPathComponent(); if (node == null) return; Object user_obj = node.getUserObject(); String new_text = ""; // <html>"; boolean text_mode = true; if (user_obj instanceof WrapperNode) { CatalogType catalog_obj = ((WrapperNode) user_obj).getCatalogType(); new_text += CatalogViewer.this.getAttributesText(catalog_obj); } else if (user_obj instanceof AttributesNode) { AttributesNode wrapper = (AttributesNode) user_obj; new_text += wrapper.getAttributes(); } else if (user_obj instanceof PlanTreeCatalogNode) { final PlanTreeCatalogNode wrapper = (PlanTreeCatalogNode) user_obj; text_mode = false; CatalogViewer.this.mainPanel.remove(0); CatalogViewer.this.mainPanel.add(wrapper.getPanel(), BorderLayout.CENTER); CatalogViewer.this.mainPanel.validate(); CatalogViewer.this.mainPanel.repaint(); if (SwingUtilities.isEventDispatchThread() == false) { SwingUtilities.invokeLater(new Runnable() { public void run() { wrapper.centerOnRoot(); } }); } else { wrapper.centerOnRoot(); } } else { new_text += CatalogViewer.this.getSummaryText(); } // Text Mode if (text_mode) { if (CatalogViewer.this.text_mode == false) { CatalogViewer.this.mainPanel.remove(0); CatalogViewer.this.mainPanel.add(CatalogViewer.this.textInfoPanel); } CatalogViewer.this.textInfoTextArea.setText(new_text); // Scroll to top CatalogViewer.this.textInfoTextArea.grabFocus(); } CatalogViewer.this.text_mode = text_mode; } }); this.generateCatalogTree(this.catalog, this.catalog_file_path.getName()); // // Text Information Panel // this.textInfoPanel = new JPanel(); this.textInfoPanel.setLayout(new BorderLayout()); this.textInfoTextArea = new JTextArea(); this.textInfoTextArea.setEditable(false); this.textInfoTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); this.textInfoTextArea.setText(this.getSummaryText()); this.textInfoTextArea.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { // TODO Auto-generated method stub } @Override public void focusGained(FocusEvent e) { CatalogViewer.this.scrollTextInfoToTop(); } }); this.textInfoScroller = new JScrollPane(this.textInfoTextArea); this.textInfoPanel.add(this.textInfoScroller, BorderLayout.CENTER); this.mainPanel = new JPanel(new BorderLayout()); this.mainPanel.add(textInfoPanel, BorderLayout.CENTER); // // Search Toolbar // JPanel searchPanel = new JPanel(); searchPanel.setLayout(new BorderLayout()); JPanel innerSearchPanel = new JPanel(); innerSearchPanel.setLayout(new BoxLayout(innerSearchPanel, BoxLayout.X_AXIS)); innerSearchPanel.add(new JLabel("Search: ")); this.searchField = new JTextField(30); innerSearchPanel.add(this.searchField); searchPanel.add(innerSearchPanel, BorderLayout.EAST); this.searchField.addKeyListener(new KeyListener() { private String last = null; @Override public void keyReleased(KeyEvent e) { String value = CatalogViewer.this.searchField.getText().toLowerCase().trim(); if (!value.isEmpty() && (this.last == null || !this.last.equals(value))) { CatalogViewer.this.search(value); } this.last = value; } @Override public void keyTyped(KeyEvent e) { // Do nothing... } @Override public void keyPressed(KeyEvent e) { // Do nothing... } }); // Putting it all together JScrollPane scrollPane = new JScrollPane(this.catalogTree); JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); topPanel.add(searchPanel, BorderLayout.NORTH); topPanel.add(scrollPane, BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, topPanel, this.mainPanel); splitPane.setDividerLocation(400); this.add(splitPane, BorderLayout.CENTER); }
From source file:com.tascape.qa.th.android.driver.App.java
/** * The method starts a GUI to let an user inspect element tree and take screenshot when the user is interacting * with the app-under-test manually. Please make sure to set timeout long enough for manual interaction. * * @param timeoutMinutes timeout in minutes to fail the manual steps * * @throws Exception if case of error//from w ww . j av a 2s . co m */ public void interactManually(int timeoutMinutes) throws Exception { LOG.info("Start manual UI interaction"); long end = System.currentTimeMillis() + timeoutMinutes * 60000L; AtomicBoolean visible = new AtomicBoolean(true); AtomicBoolean pass = new AtomicBoolean(false); String tName = Thread.currentThread().getName() + "m"; SwingUtilities.invokeLater(() -> { JDialog jd = new JDialog((JFrame) null, "Manual Device UI Interaction - " + device.getProductDetail()); jd.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); JPanel jpContent = new JPanel(new BorderLayout()); jd.setContentPane(jpContent); jpContent.setPreferredSize(new Dimension(1088, 828)); jpContent.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JPanel jpInfo = new JPanel(); jpContent.add(jpInfo, BorderLayout.PAGE_START); jpInfo.setLayout(new BorderLayout()); { JButton jb = new JButton("PASS"); jb.setForeground(Color.green.darker()); jb.setFont(jb.getFont().deriveFont(Font.BOLD)); jpInfo.add(jb, BorderLayout.LINE_START); jb.addActionListener(event -> { pass.set(true); jd.dispose(); visible.set(false); }); } { JButton jb = new JButton("FAIL"); jb.setForeground(Color.red); jb.setFont(jb.getFont().deriveFont(Font.BOLD)); jpInfo.add(jb, BorderLayout.LINE_END); jb.addActionListener(event -> { pass.set(false); jd.dispose(); visible.set(false); }); } JLabel jlTimeout = new JLabel("xxx seconds left", SwingConstants.CENTER); jpInfo.add(jlTimeout, BorderLayout.CENTER); jpInfo.add(jlTimeout, BorderLayout.CENTER); new SwingWorker<Long, Long>() { @Override protected Long doInBackground() throws Exception { while (System.currentTimeMillis() < end) { Thread.sleep(1000); long left = (end - System.currentTimeMillis()) / 1000; this.publish(left); } return 0L; } @Override protected void process(List<Long> chunks) { Long l = chunks.get(chunks.size() - 1); jlTimeout.setText(l + " seconds left"); if (l < 850) { jlTimeout.setForeground(Color.red); } } }.execute(); JPanel jpResponse = new JPanel(new BorderLayout()); JPanel jpProgress = new JPanel(new BorderLayout()); jpResponse.add(jpProgress, BorderLayout.PAGE_START); JTextArea jtaJson = new JTextArea(); jtaJson.setEditable(false); jtaJson.setTabSize(4); Font font = jtaJson.getFont(); jtaJson.setFont(new Font("Courier New", font.getStyle(), font.getSize())); JTree jtView = new JTree(); JTabbedPane jtp = new JTabbedPane(); jtp.add("tree", new JScrollPane(jtView)); jtp.add("json", new JScrollPane(jtaJson)); jpResponse.add(jtp, BorderLayout.CENTER); JPanel jpScreen = new JPanel(); jpScreen.setMinimumSize(new Dimension(200, 200)); jpScreen.setLayout(new BoxLayout(jpScreen, BoxLayout.PAGE_AXIS)); JScrollPane jsp1 = new JScrollPane(jpScreen); jpResponse.add(jsp1, BorderLayout.LINE_START); JPanel jpJs = new JPanel(new BorderLayout()); JTextArea jtaJs = new JTextArea(); jpJs.add(new JScrollPane(jtaJs), BorderLayout.CENTER); JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jpResponse, jpJs); jSplitPane.setResizeWeight(0.88); jpContent.add(jSplitPane, BorderLayout.CENTER); JPanel jpLog = new JPanel(); jpLog.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); jpLog.setLayout(new BoxLayout(jpLog, BoxLayout.LINE_AXIS)); JCheckBox jcbTap = new JCheckBox("Enable Click", null, false); jpLog.add(jcbTap); jpLog.add(Box.createHorizontalStrut(8)); JButton jbLogUi = new JButton("Log Screen"); jpResponse.add(jpLog, BorderLayout.PAGE_END); { jpLog.add(jbLogUi); jbLogUi.addActionListener((ActionEvent event) -> { jtaJson.setText("waiting for screenshot..."); Thread t = new Thread(tName) { @Override public void run() { LOG.debug("\n\n"); try { WindowHierarchy wh = device.loadWindowHierarchy(); jtView.setModel(getModel(wh)); jtaJson.setText(""); jtaJson.append(wh.root.toJson().toString(2)); jtaJson.append("\n"); File png = device.takeDeviceScreenshot(); BufferedImage image = ImageIO.read(png); int w = device.getDisplayWidth(); int h = device.getDisplayHeight(); BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = resizedImg.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(image, 0, 0, w, h, null); g2.dispose(); JLabel jLabel = new JLabel(new ImageIcon(resizedImg)); jpScreen.removeAll(); jsp1.setPreferredSize(new Dimension(w + 30, h)); jpScreen.add(jLabel); jLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { LOG.debug("clicked at {},{}", e.getPoint().getX(), e.getPoint().getY()); if (jcbTap.isSelected()) { device.click(e.getPoint().x, e.getPoint().y); device.waitForIdle(); jbLogUi.doClick(); } } }); } catch (Exception ex) { LOG.error("Cannot log screen", ex); jtaJson.append("Cannot log screen"); } jtaJson.append("\n\n\n"); LOG.debug("\n\n"); jd.setSize(jd.getBounds().width + 1, jd.getBounds().height + 1); jd.setSize(jd.getBounds().width - 1, jd.getBounds().height - 1); } }; t.start(); }); } jpLog.add(Box.createHorizontalStrut(38)); { JButton jbLogMsg = new JButton("Log Message"); jpLog.add(jbLogMsg); JTextField jtMsg = new JTextField(10); jpLog.add(jtMsg); jtMsg.addFocusListener(new FocusListener() { @Override public void focusLost(final FocusEvent pE) { } @Override public void focusGained(final FocusEvent pE) { jtMsg.selectAll(); } }); jtMsg.addKeyListener(new KeyAdapter() { @Override public void keyPressed(java.awt.event.KeyEvent e) { if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) { jbLogMsg.doClick(); } } }); jbLogMsg.addActionListener(event -> { Thread t = new Thread(tName) { @Override public void run() { String msg = jtMsg.getText(); if (StringUtils.isNotBlank(msg)) { LOG.info("{}", msg); jtMsg.selectAll(); } } }; t.start(); try { t.join(); } catch (InterruptedException ex) { LOG.error("Cannot take screenshot", ex); } jtMsg.requestFocus(); }); } jpLog.add(Box.createHorizontalStrut(38)); { JButton jbClear = new JButton("Clear"); jpLog.add(jbClear); jbClear.addActionListener(event -> { jtaJson.setText(""); }); } JPanel jpAction = new JPanel(); jpContent.add(jpAction, BorderLayout.PAGE_END); jpAction.setLayout(new BoxLayout(jpAction, BoxLayout.LINE_AXIS)); jpJs.add(jpAction, BorderLayout.PAGE_END); jd.pack(); jd.setVisible(true); jd.setLocationRelativeTo(null); jbLogUi.doClick(); }); while (visible.get()) { if (System.currentTimeMillis() > end) { LOG.error("Manual UI interaction timeout"); break; } Thread.sleep(500); } if (pass.get()) { LOG.info("Manual UI Interaction returns PASS"); } else { Assert.fail("Manual UI Interaction returns FAIL"); } }
From source file:org.apache.taverna.activities.rest.ui.config.RESTActivityConfigurationPanel.java
private JPanel createGeneralTab() { JPanel jpGeneral = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); // All components to be anchored WEST c.anchor = GridBagConstraints.WEST; c.gridx = 0;//from w w w . j av a 2 s. c o m c.gridy = 0; c.gridwidth = 1; c.insets = new Insets(7, 7, 3, 3); c.weightx = 0.0; c.fill = GridBagConstraints.NONE; JLabel labelMethod = new JLabel("HTTP Method:", infoIcon, JLabel.LEFT); labelMethod.setToolTipText( "<html>HTTP method determines how a request to the remote server will be made.<br><br>" + "Supported HTTP methods are normally used for different purposes:<br>" + "<b>GET</b> - to fetch data;<br>" + "<b>POST</b> - to create new resources;<br>" + "<b>PUT</b> - to update existing resources;<br>" + "<b>DELETE</b> - to remove existing resources.<br><br>" + "Documentation of the server that is about to be used may suggest the<br>" + "HTTP method that should be used.</html>"); jpGeneral.add(labelMethod, c); // the HTTP method combo-box will always contain the same values - it is // the selected // method which is important; therefore, can prepopulate as the set of // values is known c.gridx++; c.insets = new Insets(7, 3, 3, 7); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; cbHTTPMethod = new JComboBox<>(HTTP_METHOD.values()); cbHTTPMethod.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean contentTypeSelEnabled = RESTActivity .hasMessageBodyInputPort((HTTP_METHOD) cbHTTPMethod.getSelectedItem()); jlContentTypeExplanation.setVisible(contentTypeSelEnabled); jlContentType.setVisible(contentTypeSelEnabled); cbContentType.setVisible(contentTypeSelEnabled); jlSendDataAs.setVisible(contentTypeSelEnabled); cbSendDataAs.setVisible(contentTypeSelEnabled); jlContentTypeExplanationPlaceholder.setVisible(!contentTypeSelEnabled); jlContentTypeLabelPlaceholder.setVisible(!contentTypeSelEnabled); jlContentTypeFieldPlaceholder.setVisible(!contentTypeSelEnabled); jlSendDataAsLabelPlaceholder.setVisible(!contentTypeSelEnabled); jlSendDataAsFieldPlaceholder.setVisible(!contentTypeSelEnabled); } }); jpGeneral.add(cbHTTPMethod, c); c.gridx = 0; c.gridy++; c.insets = new Insets(3, 7, 3, 3); c.fill = GridBagConstraints.NONE; c.weightx = 0.0; JLabel labelString = new JLabel("URL Template:", infoIcon, JLabel.LEFT); labelString.setToolTipText("<html>URL template enables to define a URL with <b>configurable<br>" + "parameters</b> that will be used to access a remote server.<br><br>" + "The template may contain zero or more <b>parameters</b> - each<br>" + "enclosed within curly braces <b>\"{\"</b> and <b>\"}\"</b>.<br>" + "Taverna will automatically create an individual input port for<br>" + "this activity for each parameter.<br><br>" + "Values extracted from these input ports during the workflow<br>" + "execution these will be used to replace the parameters to<br>" + "produce complete URLs.<br><br>" + "For example, if the URL template is configured as<br>" + "\"<i>http://www.myexperiment.org/user.xml?id={userID}</i>\", a<br>" + "single input port with the name \"<i>userID</i>\" will be created.</html>"); labelString.setLabelFor(tfURLSignature); jpGeneral.add(labelString, c); c.gridx++; c.insets = new Insets(3, 3, 3, 7); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; tfURLSignature = new JTextField(40); tfURLSignature.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { tfURLSignature.selectAll(); } public void focusLost(FocusEvent e) { /* do nothing */ } }); jpGeneral.add(tfURLSignature, c); c.gridx = 0; c.gridwidth = 2; c.gridy++; c.weightx = 0.0; c.fill = GridBagConstraints.NONE; c.insets = new Insets(18, 7, 3, 7); JLabel jlAcceptsExplanation = new JLabel( "Preferred MIME type for data to be fetched from the remote server --"); jpGeneral.add(jlAcceptsExplanation, c); c.gridwidth = 1; c.gridx = 0; c.gridy++; c.insets = new Insets(3, 7, 3, 3); c.weightx = 0.0; c.fill = GridBagConstraints.NONE; JLabel jlAccepts = new JLabel("'Accept' header:", infoIcon, JLabel.LEFT); jlAccepts.setToolTipText( "<html>Select a MIME type from the drop-down menu or type your own.<br>Select blank if you do not want this header to be set.</br>"); jlAccepts.setLabelFor(cbAccepts); jpGeneral.add(jlAccepts, c); c.gridx++; c.insets = new Insets(3, 3, 3, 7); c.weightx = 1.0; c.fill = GridBagConstraints.HORIZONTAL; cbAccepts = new JComboBox<>(getMediaTypes()); cbAccepts.setEditable(true); cbAccepts.getEditor().getEditorComponent().addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { cbAccepts.getEditor().selectAll(); } public void focusLost(FocusEvent e) { /* do nothing */ } }); jpGeneral.add(cbAccepts, c); c.gridx = 0; c.gridwidth = 2; c.gridy++; c.insets = new Insets(18, 7, 3, 7); c.weightx = 0.0; c.fill = GridBagConstraints.NONE; jlContentTypeExplanation = new JLabel("MIME type of data that will be sent to the remote server --"); jpGeneral.add(jlContentTypeExplanation, c); c.gridwidth = 1; c.gridx = 0; c.gridy++; c.insets = new Insets(3, 7, 3, 3); c.weightx = 0.0; c.fill = GridBagConstraints.NONE; jlContentType = new JLabel("'Content-Type' header:", infoIcon, JLabel.LEFT); jlContentType.setToolTipText( "<html>Select a MIME type from the drop-down menu or type your own.<br>Select blank if you do not want this header to be set.</html>"); jlContentType.setLabelFor(cbContentType); jpGeneral.add(jlContentType, c); c.gridx++; c.insets = new Insets(3, 3, 3, 7); c.weightx = 1.0; c.fill = GridBagConstraints.HORIZONTAL; cbContentType = new JComboBox<>(getMediaTypes()); cbContentType.setEditable(true); cbContentType.getEditor().getEditorComponent().addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { cbContentType.getEditor().selectAll(); } public void focusLost(FocusEvent e) { /* do nothing */ } }); cbContentType.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // change selection in the "Send data as" combo-box, based on // the selection of Content-Type String selectedContentType = (String) cbContentType.getSelectedItem(); if (selectedContentType.startsWith("text")) { cbSendDataAs.setSelectedItem(DATA_FORMAT.String); } else { cbSendDataAs.setSelectedItem(DATA_FORMAT.Binary); } } }); jpGeneral.add(cbContentType, c); c.gridx = 0; c.gridwidth = 2; c.gridy++; c.insets = new Insets(18, 7, 3, 7); c.weightx = 0.0; c.fill = GridBagConstraints.NONE; jlContentTypeExplanationPlaceholder = new JLabel(); jlContentTypeExplanationPlaceholder.setPreferredSize(jlContentTypeExplanation.getPreferredSize()); jpGeneral.add(jlContentTypeExplanationPlaceholder, c); c.gridwidth = 1; c.gridx = 0; c.gridy++; c.insets = new Insets(3, 7, 3, 3); c.weightx = 0.0; c.fill = GridBagConstraints.NONE; jlContentTypeLabelPlaceholder = new JLabel(); jlContentTypeLabelPlaceholder.setPreferredSize(jlContentType.getPreferredSize()); jpGeneral.add(jlContentTypeLabelPlaceholder, c); c.gridx++; c.insets = new Insets(3, 3, 3, 7); c.weightx = 1.0; c.fill = GridBagConstraints.HORIZONTAL; jlContentTypeFieldPlaceholder = new JLabel(); jlContentTypeFieldPlaceholder.setPreferredSize(cbContentType.getPreferredSize()); jpGeneral.add(jlContentTypeFieldPlaceholder, c); c.gridx = 0; c.gridy++; c.weightx = 0.0; c.fill = GridBagConstraints.NONE; c.insets = new Insets(3, 7, 8, 3); jlSendDataAs = new JLabel("Send data as:", infoIcon, JLabel.LEFT); jlSendDataAs.setToolTipText("Select the format for the data to be sent to the remote server"); jlSendDataAs.setLabelFor(cbSendDataAs); jpGeneral.add(jlSendDataAs, c); c.gridx++; c.insets = new Insets(3, 3, 8, 7); c.weightx = 1.0; c.fill = GridBagConstraints.HORIZONTAL; cbSendDataAs = new JComboBox<>(DATA_FORMAT.values()); cbSendDataAs.setEditable(false); jpGeneral.add(cbSendDataAs, c); c.gridx = 0; c.gridy++; c.insets = new Insets(3, 7, 8, 3); c.weightx = 0.0; c.fill = GridBagConstraints.NONE; jlSendDataAsLabelPlaceholder = new JLabel(); jlSendDataAsLabelPlaceholder.setPreferredSize(jlSendDataAs.getPreferredSize()); jpGeneral.add(jlSendDataAsLabelPlaceholder, c); c.gridx++; c.insets = new Insets(3, 3, 8, 7); c.weightx = 1.0; c.fill = GridBagConstraints.HORIZONTAL; jlSendDataAsFieldPlaceholder = new JLabel(); jlSendDataAsFieldPlaceholder.setPreferredSize(cbSendDataAs.getPreferredSize()); jpGeneral.add(jlSendDataAsFieldPlaceholder, c); JPanel finalPanel = new JPanel(new BorderLayout()); finalPanel.add(jpGeneral, BorderLayout.NORTH); return (finalPanel); }
From source file:com.projity.pm.graphic.frames.GraphicManager.java
/** * @param projectUrl TODO// ww w . j a v a 2s . c o m * @param server TODO * @throws java.awt.HeadlessException */ public GraphicManager(/*String[] projectUrl,*/ String server, Container container) throws HeadlessException { graphicManagers.add(this); lastGraphicManager = this; container.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { // System.out.println("GainFocus " + GraphicManager.this.hashCode()); setMeAsLastGraphicManager(); } public void focusLost(FocusEvent e) { // System.out.println("LostFocus " + GraphicManager.this.hashCode()); } }); projectFactory = ProjectFactory.getInstance(); projectFactory.getPortfolio().addObjectListener(this); //this.projectUrl = projectUrl; GraphicManager.server = server; this.container = container; if (container instanceof Frame) frame = (Frame) container; else if (container instanceof JApplet) frame = JOptionPane.getFrameForComponent(container); if (container instanceof FrameHolder) ((FrameHolder) container).setGraphicManager(this); // else if (container instanceof BootstrapApplet){ else { try { FrameHolder holder = (FrameHolder) Class.forName("com.projity.bootstrap.BootstrapApplet") .getMethod("getObject", null).invoke(container, null); holder.setGraphicManager(this); } catch (Exception e) { } } registerForMacOSXEvents(); }
From source file:org.openmicroscopy.shoola.agents.util.SelectionWizardUI.java
/** Initializes the components composing the display.*/ private void initComponents() { filterAnywhere = true;//from w ww . jav a 2s.com filterArea = new JTextField(); originalColor = filterArea.getForeground(); setTextFieldDefault(DEFAULT_FILTER_TEXT); StringBuilder builder = new StringBuilder(); builder.append("Filter"); if (TagAnnotationData.class.equals(type)) { builder.append(" Tags."); } else if (FileAnnotationData.class.equals(type)) { builder.append(" Attachments."); } else if (DatasetData.class.equals(type)) { builder.append(" Datasets."); } else builder.append("."); filterArea.setToolTipText(builder.toString()); filterArea.getDocument().addDocumentListener(this); filterArea.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent evt) { String value = filterArea.getText(); if (StringUtils.isBlank(value)) { setTextFieldDefault(DEFAULT_FILTER_TEXT); } } @Override public void focusGained(FocusEvent evt) { } }); filterArea.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent evt) { String value = filterArea.getText(); if (DEFAULT_FILTER_TEXT.equals(value)) { setTextFieldDefault(null); } } }); filterArea.addKeyListener(new KeyAdapter() { /** * Adds the items to the selected list. * @see KeyListener#keyPressed(KeyEvent) */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER && filterArea.isFocusOwner()) { addItem(); //reset filter setTextFieldDefault(DEFAULT_FILTER_TEXT); availableItemsListbox.requestFocus(); } } }); sorter = new ViewerSorter(); availableItemsListbox = new JTree(); initializeTree(availableItemsListbox, user); availableItemsListbox.addKeyListener(new KeyAdapter() { /** * Adds the items to the selected list. * @see KeyListener#keyPressed(KeyEvent) */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER && availableItemsListbox.isFocusOwner()) { addItem(); } } }); availableItemsListbox.addMouseListener(new MouseAdapter() { /** * Adds the items to the selected list. * @see MouseListener#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { if (e.getClickCount() == 2) { if (availableItemsListbox.isFocusOwner()) addItem(); } } }); availableItemsListbox.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent evt) { firePropertyChange(AVAILABLE_SELECTION_CHANGE, Boolean.TRUE, Boolean.FALSE); } }); selectedItemsListbox = new JTree(); initializeTree(selectedItemsListbox, user); selectedItemsListbox.addKeyListener(new KeyAdapter() { /** * Removes the selected elements from the selected list. * @see KeyListener#keyPressed(KeyEvent) */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER && selectedItemsListbox.isFocusOwner()) { removeItem(); } } }); selectedItemsListbox.addMouseListener(new MouseAdapter() { /** * Removes the selected elements from the selected list. * @see MouseListener#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { if (e.getClickCount() == 2) { if (selectedItemsListbox.isFocusOwner()) removeItem(); } } }); IconManager icons = IconManager.getInstance(); addButton = new JButton(icons.getIcon(IconManager.RIGHT_ARROW)); removeButton = new JButton(icons.getIcon(IconManager.LEFT_ARROW)); addAllButton = new JButton(icons.getIcon(IconManager.DOUBLE_RIGHT_ARROW)); removeAllButton = new JButton(icons.getIcon(IconManager.DOUBLE_LEFT_ARROW)); addButton.setActionCommand("" + ADD); addButton.addActionListener(this); addAllButton.setActionCommand("" + ADD_ALL); addAllButton.addActionListener(this); removeButton.setActionCommand("" + REMOVE); removeButton.addActionListener(this); removeAllButton.setActionCommand("" + REMOVE_ALL); removeAllButton.addActionListener(this); setImmutableElements(null); }
From source file:gov.nih.nci.nbia.StandaloneDMV3.java
private JPanel constructLoginPanel() { JPanel contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(36, 36, 36, 36)); contentPane.setLayout(null);/* www. j av a 2s. c om*/ JPanel guestPanel = new JPanel(); guestPanel.setBounds(38, 40, 825, 140); guestPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.RAISED, new Color(153, 180, 209), null), " For Guest ", TitledBorder.CENTER, TitledBorder.TOP, null, new Color(0, 120, 215))); contentPane.add(guestPanel); guestPanel.setLayout(null); JButton guestBtn = new JButton(GuestBtnLbl); guestBtn.setBounds(606, 50, 140, 36); guestBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { submitRequest(null, null); } }); guestPanel.add(guestBtn); JLabel guestLbl = new JLabel("Log in as a guest to download public data only"); guestLbl.setBounds(70, 50, 460, 42); guestPanel.add(guestLbl); JPanel loginUserPanel = new JPanel(); loginUserPanel.setBounds(40, 258, 825, 306); contentPane.add(loginUserPanel); loginUserPanel .setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(153, 180, 209), null), " Login to Download Authorized Data ", TitledBorder.CENTER, TitledBorder.TOP, null, new Color(0, 120, 215))); loginUserPanel.setLayout(null); JLabel lblNewLabel_1 = new JLabel("User Name"); lblNewLabel_1.setBounds(70, 80, 118, 36); loginUserPanel.add(lblNewLabel_1); JButton submitBtn = new JButton(SubmitBtnLbl); submitBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { userId = userNameFld.getText(); password = passwdFld.getText(); if ((userId.length() < 1) || (password.length() < 1)) { statusLbl.setText("Please enter a valid user name and password."); statusLbl.setForeground(Color.red); } else { submitRequest(userId, password); } } }); submitBtn.setBounds(606, 238, 140, 36); loginUserPanel.add(submitBtn); userNameFld = new JTextField(); userNameFld.setBounds(200, 80, 333, 36); loginUserPanel.add(userNameFld); userNameFld.setColumns(10); JLabel lblPassword = new JLabel("Password"); lblPassword.setBounds(70, 156, 118, 36); loginUserPanel.add(lblPassword); passwdFld = new JPasswordField(); passwdFld.setBounds(200, 156, 333, 36); loginUserPanel.add(passwdFld); statusLbl = new JLabel(""); statusLbl.setBounds(70, 226, 463, 36); loginUserPanel.add(statusLbl); JLabel lblOr = new JLabel("--- OR ---"); lblOr.setBounds(419, 212, 81, 26); contentPane.add(lblOr); JLabel versionLabel = new JLabel("Release " + DownloaderProperties.getAppVersion() + " Build \"" + DownloaderProperties.getBuildTime() + "\""); versionLabel.setHorizontalAlignment(SwingConstants.CENTER); versionLabel.setForeground(new Color(70, 130, 180)); versionLabel.setBounds(315, 584, 260, 20); contentPane.add(versionLabel); userNameFld.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { passwdFld.requestFocus(); } }); userNameFld.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { statusLbl.setText(""); } @Override public void focusLost(FocusEvent e) { } }); passwdFld.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { userId = userNameFld.getText(); password = passwdFld.getText(); if ((userId.length() < 1) || (password.length() < 1)) { statusLbl.setText("Please enter a valid user name and password."); statusLbl.setForeground(Color.red); } else submitRequest(userId, password); } }); passwdFld.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { statusLbl.setText(""); } @Override public void focusLost(FocusEvent e) { } }); return contentPane; }
From source file:com.kstenschke.copypastestack.ToolWindow.java
private void initWrapOptions() { boolean isActiveWrap = Preferences.getIsActiveWrap(); this.form.checkBoxWrap.setSelected(isActiveWrap); this.form.checkBoxWrap.addActionListener(new ActionListener() { @Override/*w w w.java 2s. c o m*/ public void actionPerformed(ActionEvent e) { boolean isActive = form.checkBoxWrap.isSelected(); form.panelWrap.setVisible(isActive); if (isActive) { form.textFieldWrapBefore.requestFocusInWindow(); } Preferences.saveIsActiveWrap(isActive); } }); this.form.panelWrap.setVisible(isActiveWrap); this.form.textFieldWrapBefore.setText(Preferences.getWrapBefore()); FocusListener focusListenerWrapComponents = new FocusListener() { @Override public void focusGained(FocusEvent e) { } @Override public void focusLost(FocusEvent e) { Preferences.saveWrapBefore(form.textFieldWrapBefore.getText()); Preferences.saveWrapAfter(form.textFieldWrapAfter.getText()); Preferences.saveWrapDelimiter(form.textFieldWrapDelimiter.getText()); } }; this.form.textFieldWrapBefore.addFocusListener(focusListenerWrapComponents); this.form.textFieldWrapAfter.setText(Preferences.getWrapAfter()); this.form.textFieldWrapAfter.addFocusListener(focusListenerWrapComponents); this.form.textFieldWrapDelimiter.setText(Preferences.getWrapDelimiter()); this.form.textFieldWrapDelimiter.addFocusListener(focusListenerWrapComponents); }
From source file:com.sec.ose.osi.ui.frm.login.JPanLogin.java
private JTextField getJTextProxyHost() { if (jTextFieldProxyHost == null) { jTextFieldProxyHost = new JTextField(); jTextFieldProxyHost.setPreferredSize(new Dimension(130, 22)); jTextFieldProxyHost.addFocusListener(new FocusListener() { @Override/* www . j av a 2 s .co m*/ public void focusGained(FocusEvent e) { jTextFieldProxyHost.selectAll(); } @Override public void focusLost(FocusEvent e) { jTextFieldProxyHost.select(0, 0); } }); } return jTextFieldProxyHost; }