List of usage examples for java.awt.event FocusListener FocusListener
FocusListener
From source file:com.sec.ose.osi.ui.frm.login.JPanLogin.java
private JTextField getJTextProxyPort() { if (jTextFieldProxyPort == null) { jTextFieldProxyPort = new JTextField(); jTextFieldProxyPort.setPreferredSize(new Dimension(50, 22)); jTextFieldProxyPort.addFocusListener(new FocusListener() { @Override/*from w w w . ja v a 2 s. c o m*/ public void focusGained(FocusEvent e) { jTextFieldProxyPort.selectAll(); } @Override public void focusLost(FocusEvent e) { jTextFieldProxyPort.select(0, 0); } }); } return jTextFieldProxyPort; }
From source file:net.rptools.maptool.launcher.MapToolLauncher.java
private JPanel buildAdvancedPanel() { final JPanel p = new JPanel(); p.setLayout(new BorderLayout()); p.setBorder(new LineBorder(Color.BLACK)); final JPanel controlPanel = new JPanel(); controlPanel.setLayout(new BorderLayout()); final JPanel argPanel = new JPanel(); argPanel.setLayout(new BorderLayout()); jtfArgs.setInfo(CopiedFromOtherJars.getText("msg.info.javaArgumentsHere")); //$NON-NLS-1$ jtfArgs.setText(extraArgs);/*from ww w.j a va 2s . c om*/ jtfArgs.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaArgumentsHere")); //$NON-NLS-1$ jtfArgs.setCaretPosition(0); jtfArgs.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { jbLaunch.requestFocusInWindow(); } } }); jtfArgs.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent arg0) { jtfArgs.selectAll(); } @Override public void focusLost(FocusEvent arg0) { jtfArgs.setCaretPosition(0); if (!jtfArgs.getText().trim().equals(extraArgs)) { extraArgs = jtfArgs.getText(); jcbEnableAssertions.setSelected(extraArgs.contains(ASSERTIONS_OPTION)); if (extraArgs.contains(DATADIR_OPTION)) { extraArgs = cleanExtraArgs(extraArgs); } updateCommand(); } } }); argPanel.add(jtfArgs, BorderLayout.CENTER); controlPanel.add(argPanel, BorderLayout.NORTH); final JPanel holdPanel = new JPanel(); holdPanel.setLayout(new GridLayout(0, 1)); jcbRelativePath.setText(CopiedFromOtherJars.getText("msg.info.useRelativePathnames")); //$NON-NLS-1$ jcbRelativePath.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.useRelativePathnames")); //$NON-NLS-1$ jcbRelativePath.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { updateCommand(); } }); // jcbRelativePath.setSelected(false); // since initComponents() is called after reading the config, don't do this here jcbConsole.setText(CopiedFromOtherJars.getText("msg.info.launchWithConsole")); //$NON-NLS-1$ jcbConsole.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.launchWithConsole")); //$NON-NLS-1$ jcbConsole.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { startConsole = jcbConsole.isSelected(); updateCommand(); } }); jcbConsole.setSelected(startConsole); jbPath.setText(jbPathText); jbPath.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.dirForAltJava")); //$NON-NLS-1$ jbPath.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (jbPath.getText().equalsIgnoreCase(CopiedFromOtherJars.getText("msg.info.setJavaVersion"))) { //$NON-NLS-1$ final JFileChooser jfc = new JFileChooser(); if (!javaDir.isEmpty()) { jfc.setCurrentDirectory(new File(javaDir)); } else { jfc.setCurrentDirectory(new File(".")); //$NON-NLS-1$ } jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); final int returnVal = jfc.showOpenDialog(jbPath); if (returnVal == JFileChooser.APPROVE_OPTION) { final File f = jfc.getSelectedFile(); final String test = f.getPath() + File.separator; // Lee: naive search for java command. will improve in the future final List<String> fileList = Arrays.asList(f.list()); boolean javaFound = false; for (final String fileName : fileList) { final File check = new File(f, fileName); final String lc = check.getName().toLowerCase(); if (lc.equals("java") || (IS_WINDOWS && lc.startsWith("java."))) { //$NON-NLS-1$ //$NON-NLS-2$ javaFound = true; break; } } if (javaFound) { jbPath.setText(CopiedFromOtherJars.getText("msg.info.resetToDefaultJava")); //$NON-NLS-1$ javaDir = test; updateCommand(); } else { logMsg(Level.SEVERE, "Java executable not found in {0}", //$NON-NLS-1$ "msg.error.javaCommandNotFound", f); //$NON-NLS-2$ } } } else { jbPath.setText(CopiedFromOtherJars.getText("msg.info.setJavaVersion")); //$NON-NLS-1$ javaDir = EMPTY; } } }); holdPanel.add(jcbRelativePath); holdPanel.add(jcbConsole); holdPanel.add(jbPath); controlPanel.add(holdPanel, BorderLayout.SOUTH); final JPanel logPanel = new JPanel(); logPanel.setLayout(new GridLayout(0, 1)); logPanel.setBorder( new TitledBorder(new LineBorder(Color.BLACK), CopiedFromOtherJars.getText("msg.logPanel.border"))); //$NON-NLS-1$ for (final LoggingConfig config : logConfigs) { config.chkbox.setText(config.getProperty("desc")); //$NON-NLS-1$ config.chkbox.setToolTipText(config.getProperty("ttip")); //$NON-NLS-1$ logPanel.add(config.chkbox); } p.add(logPanel, BorderLayout.CENTER); p.add(controlPanel, BorderLayout.SOUTH); return p; }
From source file:ca.phon.app.project.ProjectWindow.java
private MultiActionButton createCorpusButton() { MultiActionButton retVal = new MultiActionButton(); ImageIcon newIcn = IconManager.getInstance().getIcon("places/folder", IconSize.SMALL); String s1 = "Corpus"; String s2 = "Enter corpus name and press enter. Press escape to cancel."; retVal.getTopLabel().setText(WorkspaceTextStyler.toHeaderText(s1)); retVal.getTopLabel().setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); retVal.getTopLabel().setFont(FontPreferences.getTitleFont()); retVal.getTopLabel().setIcon(newIcn); retVal.setAlwaysDisplayActions(true); retVal.setOpaque(false);/* w w w.j a v a2 s .co m*/ ImageIcon cancelIcn = IconManager.getInstance().getIcon("actions/button_cancel", IconSize.SMALL); ImageIcon cancelIcnL = cancelIcn; PhonUIAction btnSwapAct = new PhonUIAction(this, "onSwapNewAndCreateCorpus", retVal); btnSwapAct.putValue(Action.ACTION_COMMAND_KEY, "CANCEL_CREATE_ITEM"); btnSwapAct.putValue(Action.NAME, "Cancel create"); btnSwapAct.putValue(Action.SHORT_DESCRIPTION, "Cancel create"); btnSwapAct.putValue(Action.SMALL_ICON, cancelIcn); btnSwapAct.putValue(Action.LARGE_ICON_KEY, cancelIcnL); retVal.addAction(btnSwapAct); JPanel corpusNamePanel = new JPanel(new BorderLayout()); corpusNamePanel.setOpaque(false); final JTextField corpusNameField = new JTextField(); corpusNameField.setDocument(new NameDocument()); corpusNameField.setText("Corpus Name"); corpusNamePanel.add(corpusNameField, BorderLayout.CENTER); ActionMap actionMap = retVal.getActionMap(); actionMap.put(btnSwapAct.getValue(Action.ACTION_COMMAND_KEY), btnSwapAct); InputMap inputMap = retVal.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); inputMap.put(ks, btnSwapAct.getValue(Action.ACTION_COMMAND_KEY)); retVal.setActionMap(actionMap); retVal.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); PhonUIAction createNewCorpusAct = new PhonUIAction(this, "onCreateCorpus", corpusNameField); createNewCorpusAct.putValue(Action.SHORT_DESCRIPTION, "Create new corpus folder"); createNewCorpusAct.putValue(Action.SMALL_ICON, IconManager.getInstance().getIcon("actions/list-add", IconSize.SMALL)); JButton createBtn = new JButton(createNewCorpusAct); corpusNamePanel.add(createBtn, BorderLayout.EAST); corpusNameField.setAction(createNewCorpusAct); // swap bottom component in new project button retVal.setBottomLabelText(WorkspaceTextStyler.toDescText(s2)); retVal.add(corpusNamePanel, BorderLayout.CENTER); retVal.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { } @Override public void focusGained(FocusEvent e) { corpusNameField.requestFocus(); } }); return retVal; }
From source file:com.sec.ose.osi.ui.frm.login.JPanLogin.java
private JTextField getJTextProxyBypass() { if (jTextFieldProxyBypass == null) { jTextFieldProxyBypass = new JTextField(); jTextFieldProxyBypass.setPreferredSize(new Dimension(200, 22)); jTextFieldProxyBypass.addFocusListener(new FocusListener() { @Override/*w w w . ja v a2 s . c o m*/ public void focusGained(FocusEvent e) { jTextFieldProxyBypass.selectAll(); } @Override public void focusLost(FocusEvent e) { jTextFieldProxyBypass.select(0, 0); } }); } return jTextFieldProxyBypass; }
From source file:com.all.login.view.NewAccountFormPanel.java
private JCheckBox getAcceptConditionsCheckBox() { if (acceptConditionsCheckBox == null) { acceptConditionsCheckBox = new JCheckBox(); acceptConditionsCheckBox.setBounds(ACCEPT_CONDITION_CHECKBOX_BOUNDS); acceptConditionsCheckBox.setName(ACCEPT_CONDITIONS_CHECK_BOX_NORMAL_NAME); acceptConditionsCheckBox.setForeground(SynthColors.GRAY909090); acceptConditionsCheckBox.setIconTextGap(ICON_TEXT_GAP); acceptConditionsCheckBox.addActionListener(new ActionListener() { @Override/*from www. j a v a 2 s.c o m*/ public void actionPerformed(ActionEvent e) { if (acceptConditionsCheckBox.isSelected()) { acceptConditionsCheckBox.setSelected(false); } else { acceptConditionsCheckBox.setSelected(true); validateAllUserData(); } showFields(false); getDisclaimerPanel().setVisible(true); enableForm(false); } }); acceptConditionsCheckBox.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { acceptConditionsCheckBox.setName(ACCEPT_CONDITIONS_CHECK_BOX_NORMAL_NAME); acceptConditionsCheckBox.setForeground(SynthColors.GRAY909090); } @Override public void focusGained(FocusEvent e) { acceptConditionsCheckBox.setName(ACCEPT_CONDITIONS_CHECK_BOX_FOCUS_NAME); acceptConditionsCheckBox.setForeground(SynthColors.GRAY909090); } }); } return acceptConditionsCheckBox; }
From source file:edu.ku.brc.specify.tasks.subpane.wb.FormPane.java
/** * Creates the proper UI component for the Mapping item. * @param dbFieldType the field type/*from w w w. j a v a 2 s. co m*/ * @param caption the caption * @param fieldName the name of the field * @param dataFieldLength the length of the definition for that field * @param fieldType the field type * @return a UI component for editing */ protected JComponent createUIComp(final Class<?> dbFieldTypeArg, final String caption, final String fieldName, final Short fieldType, final Short fieldLength, final short columns, final short rows, final WorkbenchTemplateMappingItem wbtmi) { short uiType = WorkbenchTemplateMappingItem.UNKNOWN; //System.out.println(wbtmi.getCaption()+" "+wbtmi.getDataType()+" "+wbtmi.getFieldLength()); Class<?> dbFieldType = dbFieldTypeArg; if (dbFieldType == null) { // if we can't find a class for the field (i.e. Genus Species, or other 'fake' fields), we say it's a string dbFieldType = String.class; } JComponent comp; Component focusComp; // handle dates if (dbFieldType.equals(Calendar.class) || dbFieldType.equals(Date.class)) { //ValFormattedTextField txt = new ValFormattedTextField("Date"); //txt.setColumns(columns == -1 ? DEFAULT_TEXTFIELD_COLS : columns); ValTextField txt = new ValTextField(columns); txt.getDocument().addDocumentListener(docListener); comp = txt; focusComp = comp; uiType = WorkbenchTemplateMappingItem.TEXTFIELD_DATE; } // else if (dbFieldType.equals(Boolean.class)) // strings // { // ValCheckBox checkBox = new ValCheckBox(caption, false, false); // checkBox.addChangeListener(changeListener); // comp = checkBox; // focusComp = comp; // uiType = WorkbenchTemplateMappingItem.CHECKBOX; // } else if (useComboBox(wbtmi)) { //ValComboBox comboBox = new ValComboBox(getValues(wbtmi), true); final JComboBox comboBox = new JComboBox(getValues(wbtmi)); comboBox.setName("Form Combo"); comboBox.setEditable(true); comboBox.addActionListener(new ActionListener() { /* (non-Javadoc) * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @Override public void actionPerformed(ActionEvent arg0) { if (arg0.getSource() == comboBox) { //System.out.println("ComboBox Action!" + ((JComboBox )arg0.getSource()).getName()); stateChange(); } } }); // comboBox.getEditor().getEditorComponent().addFocusListener(new FocusListener() { // // /* (non-Javadoc) // * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent) // */ // @Override // public void focusGained(FocusEvent arg0) { // System.out.println("FOCUS GAINED"); // // } // // /* (non-Javadoc) // * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent) // */ // @Override // public void focusLost(FocusEvent arg0) { // System.out.println("FOCUS LOST"); // // } // // }); comp = comboBox; focusComp = comp; uiType = WorkbenchTemplateMappingItem.COMBOBOX; } else if (useTextField(fieldName, fieldType, fieldLength)) { ValTextField txt = new ValTextField(columns); txt.getDocument().addDocumentListener(docListener); txt.setInputVerifier(new LengthInputVerifier(caption, fieldLength)); comp = txt; focusComp = comp; uiType = WorkbenchTemplateMappingItem.TEXTFIELD; } else { JScrollPane taScrollPane = createTextArea(columns, rows); ((JTextArea) taScrollPane.getViewport().getView()) .setInputVerifier(new LengthInputVerifier(caption, fieldLength)); comp = taScrollPane; focusComp = taScrollPane.getViewport().getView(); uiType = WorkbenchTemplateMappingItem.TEXTAREA; } wbtmi.setFieldType(uiType); focusComp.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { selectControl(e.getSource()); } public void focusLost(FocusEvent e) { //stateChange(); } }); comp.setEnabled(!readOnly); focusComp.setEnabled(!readOnly); comp.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (!readOnly) { if ((e.isControlDown() || e.isMetaDown()) && e.getKeyCode() == KeyEvent.VK_N) { workbenchPane.addRowAfter(); } } super.keyTyped(e); } }); return comp; }
From source file:gov.nih.nci.nbia.StandaloneDMV3.java
/** * Create the panel.//from w w w . j ava 2s .c o m */ private JPanel createloginPanelV2() { JPanel contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(36, 36, 36, 36)); contentPane.setLayout(null); JPanel loginUserPanel = new JPanel(); loginUserPanel.setBounds(40, 91, 825, 306); contentPane.add(loginUserPanel); loginUserPanel .setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(153, 180, 209), null), "", 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)) { setStatus(statusLbl, "Please enter a valid user name and password.", Color.red); } else { setStatus(statusLbl, "Checking your access permission...", Color.blue); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { 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, 524, 36); statusLbl.setFont(new Font("SansSerif", Font.PLAIN, 13)); statusLbl.setVerticalAlignment(SwingConstants.BOTTOM); loginUserPanel.add(statusLbl); JLabel versionLabel = new JLabel("Release " + DownloaderProperties.getAppVersion() + " Build \"" + DownloaderProperties.getBuildTime() + "\""); versionLabel.setHorizontalAlignment(SwingConstants.CENTER); versionLabel.setForeground(new Color(70, 130, 180)); versionLabel.setBounds(318, 427, 266, 20); contentPane.add(versionLabel); JLabel infoLbl = new JLabel( "This download contains restricted data. Log in or contact the help desk for access."); infoLbl.setForeground(new Color(105, 105, 105)); infoLbl.setFont(new Font("SansSerif", Font.BOLD, 13)); infoLbl.setBounds(40, 34, 796, 42); contentPane.add(infoLbl); JLabel helpDeskLbl; helpDeskLbl = new JLabel(); ImageIcon image = new ImageIcon(this.getClass().getClassLoader().getResource("info.png")); helpDeskLbl = new JLabel(image); helpDeskLbl.setToolTipText("Click to get phone number/email address of the Help Desk."); helpDeskLbl.setBounds(826, 20, 36, 36); contentPane.add(helpDeskLbl); helpDeskLbl.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { System.out.println("mouse clicked"); //BrowserLauncher.openUrl(DownloaderProperties.getHelpDeskUrl()); BrowserLauncher.openUrlForHelpDesk(); } }); 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)) { setStatus(statusLbl, "Please enter a valid user name and password.", Color.red); } else { setStatus(statusLbl, "Checking your access permission...", Color.blue); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { 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:net.minelord.gui.panes.IRCPane.java
public void startClient(final String nick) { IRCLog = new ArrayList<String>(); SwingUtilities.invokeLater(new Runnable() { @Override/*w w w . jav a 2 s . c o m*/ public void run() { text = new JEditorPane("text/html", "<HTML>"); text.setEditable(false); kit = new HTMLEditorKit(); text.setEditorKit(kit); client.connect("irc.liberty-unleashed.co.uk", "#moomoohk", nick, instance); scroller = new JScrollPane(text); text.setEditable(false); connect(); scroller.setBounds(20, 20, 810, 250); add(scroller); input = new JTextField(); input.setBounds(20, 270, 810, 30); Color bgColor = Color.gray.darker().darker(); UIDefaults defaults = new UIDefaults(); defaults.put("EditorPane[Enabled].backgroundPainter", bgColor); text.putClientProperty("Nimbus.Overrides", defaults); text.putClientProperty("Nimbus.Overrides.InheritDefaults", true); text.setBackground(bgColor); input.setBackground(Color.gray); input.setForeground(Color.gray.darker().darker().darker()); input.setEnabled(false); text.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (event.getDescription().charAt(0) == '#') { String[] params = { event.getDescription() }; IRCCommand.getCommand("/join").execute(client, params); } else OSUtils.browse(event.getURL().toString()); } } }); text.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent paramFocusEvent) { } @Override public void focusGained(FocusEvent paramFocusEvent) { input.requestFocus(); } }); scroller.setViewportView(text); add(input); input.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent arg0) { } @Override public void keyReleased(KeyEvent arg0) { if (arg0.getKeyCode() == 10) { if (input.getText().length() > 0) { lastCommandSelector = lastCommands.size(); lastCommands.add(input.getText()); } sendMessage(input.getText()); input.setText(""); } if (arg0.getKeyCode() == 27) input.setText(""); if (arg0.getKeyCode() == 17) { int before = input.getText().length(); if (input.getText().charAt(0) == '/') { input.setText(completeNick(input.getText())); input.select( input.getText().length() - completeNick(input.getText()).length() + before, input.getText().length()); } else { input.setText(completeCommand(input.getText())); input.select(input.getText().length() - completeCommand(input.getText()).length() + before, input.getText().length()); } } if (arg0.getKeyCode() == 38) if (lastCommandSelector > 0) { lastCommandSelector--; input.setText(lastCommands.get(lastCommandSelector)); } if (arg0.getKeyCode() == 40) if (lastCommandSelector < lastCommands.size()) { lastCommandSelector++; if (lastCommandSelector == lastCommands.size()) input.setText(""); if (lastCommandSelector < lastCommands.size()) input.setText(lastCommands.get(lastCommandSelector)); return; } } @Override public void keyPressed(KeyEvent arg0) { } }); } }); }
From source file:ca.phon.app.project.ProjectWindow.java
private MultiActionButton createSessionButton() { MultiActionButton retVal = new MultiActionButton(); ImageIcon newIcn = IconManager.getInstance().getIcon("mimetypes/text-xml", IconSize.SMALL); String s1 = "Session"; String s2 = "Enter session name and press enter. Press escape to cancel."; retVal.getTopLabel().setText(WorkspaceTextStyler.toHeaderText(s1)); retVal.getTopLabel().setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); retVal.getTopLabel().setFont(FontPreferences.getTitleFont()); retVal.getTopLabel().setIcon(newIcn); retVal.setAlwaysDisplayActions(true); retVal.setOpaque(false);// ww w . j a v a 2 s. c o m ImageIcon cancelIcn = IconManager.getInstance().getIcon("actions/button_cancel", IconSize.SMALL); ImageIcon cancelIcnL = cancelIcn; PhonUIAction btnSwapAct = new PhonUIAction(this, "onSwapNewAndCreateSession", retVal); btnSwapAct.putValue(Action.ACTION_COMMAND_KEY, "CANCEL_CREATE_ITEM"); btnSwapAct.putValue(Action.NAME, "Cancel create"); btnSwapAct.putValue(Action.SHORT_DESCRIPTION, "Cancel create"); btnSwapAct.putValue(Action.SMALL_ICON, cancelIcn); btnSwapAct.putValue(Action.LARGE_ICON_KEY, cancelIcnL); retVal.addAction(btnSwapAct); JPanel sessionNamePanel = new JPanel(new BorderLayout()); sessionNamePanel.setOpaque(false); final JTextField sessionNameField = new JTextField(); sessionNameField.setDocument(new NameDocument()); sessionNameField.setText("Session Name"); sessionNamePanel.add(sessionNameField, BorderLayout.CENTER); ActionMap actionMap = retVal.getActionMap(); actionMap.put(btnSwapAct.getValue(Action.ACTION_COMMAND_KEY), btnSwapAct); InputMap inputMap = retVal.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); inputMap.put(ks, btnSwapAct.getValue(Action.ACTION_COMMAND_KEY)); retVal.setActionMap(actionMap); retVal.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); PhonUIAction createNewSessionAct = new PhonUIAction(this, "onCreateSession", sessionNameField); createNewSessionAct.putValue(Action.SHORT_DESCRIPTION, "Create new session in selected corpus"); createNewSessionAct.putValue(Action.SMALL_ICON, IconManager.getInstance().getIcon("actions/list-add", IconSize.SMALL)); JButton createBtn = new JButton(createNewSessionAct); sessionNamePanel.add(createBtn, BorderLayout.EAST); sessionNameField.setAction(createNewSessionAct); // swap bottom component in new project button retVal.setBottomLabelText(WorkspaceTextStyler.toDescText(s2)); retVal.add(sessionNamePanel, BorderLayout.CENTER); retVal.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { } @Override public void focusGained(FocusEvent e) { sessionNameField.requestFocus(); } }); return retVal; }
From source file:net.rptools.maptool.launcher.MapToolLauncher.java
/** * This method is called from within the constructor to initialize the form * components.//from w w w .j a v a 2s . c o m */ private void initComponents() { // Lee: for aesthetics and Linux won't display window controls on an untitled window. final String version = CopiedFromOtherJars.getVersion(); setTitle(CopiedFromOtherJars.getText("msg.title.mainWindow", version)); //$NON-NLS-1$ if (jbPathText == null) jbPathText = CopiedFromOtherJars.getText("msg.info.setJavaVersion"); //$NON-NLS-1$ if (jbMTJarText == null) jbMTJarText = CopiedFromOtherJars.getText("msg.info.selectMapToolJar"); //$NON-NLS-1$ if (mapToolJarName == null) mapToolJarName = CopiedFromOtherJars.getText("msg.info.selectMapToolJar"); //$NON-NLS-1$ final Container cp = getContentPane(); cp.setLayout(new BorderLayout()); final JPanel basicPanel = buildBasicPanel(); final JPanel langPanel = buildLanguagePanel(); final JPanel advancedPanel = buildAdvancedPanel(); final JPanel tsPanel = buildTroubleshootingPanel(); mtlOptions.addTab(CopiedFromOtherJars.getText("msg.tab.basic"), basicPanel); //$NON-NLS-1$ mtlOptions.addTab(CopiedFromOtherJars.getText("msg.tab.language"), langPanel); //$NON-NLS-1$ mtlOptions.addTab(CopiedFromOtherJars.getText("msg.tab.advanced"), advancedPanel); //$NON-NLS-1$ mtlOptions.addTab(CopiedFromOtherJars.getText("msg.tab.troubleshoot"), tsPanel); //$NON-NLS-1$ cp.add(mtlOptions, BorderLayout.CENTER); cp.add(jtfCommand, BorderLayout.SOUTH); // Lee: user must register MT executable jbLaunch.setEnabled( !mapToolJarName.equalsIgnoreCase(CopiedFromOtherJars.getText("msg.info.selectMapToolJar"))); //$NON-NLS-1$ jbLaunch.setText(CopiedFromOtherJars.getText("msg.info.launchMapTool")); //$NON-NLS-1$ jbLaunch.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { jbLaunchActionPerformed(evt); } catch (final IOException e) { e.printStackTrace(); } } }); jtfCommand.setEditable(false); jtfCommand.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); jtfCommand.setText(CopiedFromOtherJars.getText("msg.info.cmdLineShownHere")); //$NON-NLS-1$ jtfCommand.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent arg0) { jtfCommand.selectAll(); } @Override public void focusLost(FocusEvent arg0) { jtfCommand.setCaretPosition(0); } }); jcbKeepOpen.setSelected(false); jcbKeepOpen.setText(CopiedFromOtherJars.getText("msg.info.keepLauncherOpen")); //$NON-NLS-1$ jcbKeepOpen.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.keepLauncherOpen")); //$NON-NLS-1$ final JPanel lowerPanel = new JPanel(); lowerPanel.setLayout(new GridLayout(3, 1)); lowerPanel.setBorder(new LineBorder(Color.BLACK)); lowerPanel.add(jbLaunch); lowerPanel.add(jcbKeepOpen); lowerPanel.add(jtfCommand); cp.add(lowerPanel, BorderLayout.SOUTH); mtlOptions.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { final JTabbedPane source = (JTabbedPane) e.getSource(); final String tabName = source.getTitleAt(source.getSelectedIndex()); if (jbLaunch.isEnabled()) { jbLaunch.requestFocusInWindow(); } else { if (tabName.equals(CopiedFromOtherJars.getText("msg.tab.basic"))) { //$NON-NLS-1$ jbMTJar.requestFocusInWindow(); } else if (tabName.equals(CopiedFromOtherJars.getText("msg.tab.language"))) { //$NON-NLS-1$ // This should work as long as there's at least one language in the list. langGroup.getElements().nextElement().requestFocusInWindow(); } else if (tabName.equals(CopiedFromOtherJars.getText("msg.tab.advanced"))) { //$NON-NLS-1$ jcbConsole.requestFocusInWindow(); jtfArgs.setText(extraArgs); } else { jcbEnableAssertions.requestFocusInWindow(); } } } }); Dimension d = new Dimension(advancedPanel.getPreferredSize().width, 25); jtfArgs.setPreferredSize(d); // mtlOptions.setPreferredSize(new Dimension(350, getPreferredSize().height)); d.width = -1; d.height = -1; JLabel tabLabel = null; int tabs = mtlOptions.getTabCount(); while (tabs-- > 0) { Component tab = mtlOptions.getTabComponentAt(tabs); if (tab == null) { if (tabLabel == null) tabLabel = new JLabel(); tabLabel.setText(mtlOptions.getTitleAt(tabs)); tab = tabLabel; } Dimension dim = tab.getPreferredSize(); d.width = Math.max(dim.width, d.width); d.height = Math.max(dim.height, d.height); } // Set width to width of largest tab * number of tabs, then add 20%. d.width = d.width * 120 / 100 * mtlOptions.getTabCount(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setIconImage(icon.getImage()); // To prevent the tabs from wrapping or scrolling setMinimumSize(new Dimension(d.width, getSize().height)); pack(); setResizable(true); }