List of usage examples for java.awt KeyboardFocusManager getCurrentKeyboardFocusManager
public static KeyboardFocusManager getCurrentKeyboardFocusManager()
From source file:org.nekorp.workflow.desktop.view.AppMainWindow.java
/** * call this somewhere in your GUI construction *//*from w w w . j av a2 s . c o m*/ private void setupKeyShortcut() { KeyStroke key1 = KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK); actionMap.put(key1, new AbstractAction("guardar") { @Override public void actionPerformed(ActionEvent e) { if (editorMonitor.hasChange()) { try { aplication.guardaServicio(); } catch (IllegalArgumentException ex) { //no lo guardo. } } } }); // key1 = KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK); // actionMap.put(key1, new AbstractAction("deshacer") { // @Override // public void actionPerformed(ActionEvent e) { // if (editorMonitor.hasChange()) { // editorMonitor.undo(); // } // } // }); // key1 = KeyStroke.getKeyStroke(KeyEvent.VK_Y, KeyEvent.CTRL_DOWN_MASK); // actionMap.put(key1, new AbstractAction("rehacer") { // @Override // public void actionPerformed(ActionEvent e) { // editorMonitor.redo(); // } // }); // add more actions.. KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); kfm.addKeyEventDispatcher(new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent e) { KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(e); if (actionMap.containsKey(keyStroke)) { final Action a = actionMap.get(keyStroke); final ActionEvent ae = new ActionEvent(e.getSource(), e.getID(), null); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { a.actionPerformed(ae); } }); return true; } return false; } }); }
From source file:org.kepler.gui.KeplerGraphFrame.java
/** * Override the dispose method to unattach any listeners that may keep this * model from getting garbage collected. Also remove KARManager's mapping of * this JFrame to KARfile if necessary./*from w ww .j av a2 s .c o m*/ */ @Override public void dispose() { if (_topPack instanceof KeplerMenuHandler) { KeplerMenuHandler topPack = (KeplerMenuHandler) _topPack; MenuMapper mm = topPack.menuMapper; mm.clear(); /* * mm.printDebugInfo(); Map<String,Action> m = * mm.getPTIIMenuActionsMap(); m.clear(); KeplerMenuHandler kmh = * (KeplerMenuHandler) _topPack; kmh.clear(); _topPack = null; */ } JMenuBar keplerMenuBar = getJMenuBar(); /* int removed = */MemoryCleaner.removeActionListeners(keplerMenuBar); // System.out.println("KeplerGraphFrame menubar action listeners removed: " // + removed); CanvasDropTargetListener listener = CanvasDropTargetListener.getInstance(); if (listener != null && _dropTarget != null) { _dropTarget.deRegisterAdditionalListener(listener); } if (_horizontalScrollBarListener != null && _horizontalScrollBar != null) { _horizontalScrollBar.removeAdjustmentListener(_horizontalScrollBarListener); _horizontalScrollBarListener = null; } if (_verticalScrollBarListener != null && _verticalScrollBarListener != null) { _verticalScrollBar.removeAdjustmentListener(_verticalScrollBarListener); _verticalScrollBarListener = null; } // remove JFrame => KARFile mapping from KARManager KARManager karManager = KARManager.getInstance(); karManager.remove(this); TabManager tabManager = TabManager.getInstance(); tabManager.removeAllFrameTabs(this); // this isn't safe. see: // http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5095#c14 // it is safe now after changes in r26444. ObjectManager.getInstance().removeNamedObjs(this.getModel()); ViewManager.getInstance().removeOpenFrame(this); LibraryManager.getInstance().removeAllFrameTabs(this); // now call dispose on updaters in order synchronized (_updaterSet) { Iterator<KeplerGraphFrameUpdater> itr = _updaterSet.iterator(); while (itr.hasNext()) { KeplerGraphFrameUpdater updater = itr.next(); updater.dispose(this); } } ModelToFrameManager m2fm = ModelToFrameManager.getInstance(); m2fm.remove(this); // see if this was the last window if (m2fm.numberOfOpenFrames() == 0) { ShutdownNotifier.shutdown(); } KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); focusManager.clearGlobalFocusOwner(); focusManager.downFocusCycle(); super.dispose(); }
From source file:pipeline.GUI_utils.ListOfPointsView.java
@Override public void close() { spreadsheetEngine = null;// w w w. j a va2 s . com tableModel = null; table = null; coloringComboBox = null; realTimeUpdateCheckbox = null; if (frame != null && frame.isVisible()) frame.setVisible(false); if (frame != null) frame.dispose(); closed = true; synchronized (dirty) { dirty.notifyAll(); } frame = null; g = null; KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner(); }
From source file:fs.MainWindow.java
public MainWindow() { initComponents();// www .ja v a 2s . c o m //inicializacao do modelo numerido usado na definicao dos parametros. jS_QuantizationValue.setModel(new SpinnerNumberModel(2, 1, Integer.MAX_VALUE, 1)); jS_MaxResultListSE.setModel(new SpinnerNumberModel(3, 1, Integer.MAX_VALUE, 1)); jS_MaxSetSizeSE.setModel(new SpinnerNumberModel(3, 1, Integer.MAX_VALUE, 1)); jS_MaxSetSizeCV.setModel(new SpinnerNumberModel(3, 1, Integer.MAX_VALUE, 1)); jS_NrExecutionsCV.setModel(new SpinnerNumberModel(10, 1, Integer.MAX_VALUE, 1)); jS_ThresholdEntropy.setModel(new SpinnerNumberModel(0.3, 0, 1, 0.05)); jS_QEntropyCV.setModel(new SpinnerNumberModel(1d, 0.1d, Double.MAX_VALUE, 0.1d)); jS_AlphaCV.setModel(new SpinnerNumberModel(1d, 0d, Double.MAX_VALUE, 0.1d)); jS_QEntropySE.setModel(new SpinnerNumberModel(1d, 0.1d, Double.MAX_VALUE, 0.1d)); jS_AlphaSE.setModel(new SpinnerNumberModel(1d, 0d, Double.MAX_VALUE, 0.1d)); //captura teclas pressionadas, se for F1 aciona o JFrame Help. KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_F1 && e.getID() == KeyEvent.KEY_PRESSED) { if (help != null) { help.setVisible(false); help.dispose(); } if (jTabbedPane1.getSelectedIndex() == 0) { help = new HelpInput(); } else if (jTabbedPane1.getSelectedIndex() == 1) { help = new HelpQuantization(); } else if (jTabbedPane1.getSelectedIndex() == 2) { help = new HelpFS(); } else if (jTabbedPane1.getSelectedIndex() == 3) { help = new HelpCV(); } help.setVisible(true); return true; } return false; } }); }
From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfRelationsPanel.java
/** * Builds and answer the relations tab for the given layout. * * @param errors List of errors.//from w w w. j a v a 2s . c o m * @return the relations tab. */ protected JComponent buildEditorPanel(List<String> errors) { // Checks and initialize the errors list. if (errors == null) { errors = new ArrayList<String>(0); } else if (Utilities.isDev && errors.size() > 0) { LOG.info("Errors in form:"); for (String error : errors) { LOG.info(error); } } // Define the layout for the form. FormLayout layout = new FormLayout("right:max(50dlu;p), 4dlu, 100dlu, 7dlu, right:p, 4dlu, 100dlu", EDITOR_ROW_SPEC); layout.setColumnGroups(new int[][] { { 1, 3, 5, 7 } }); // Construct the panel. PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); // Constraints for the cells; // Create object parts if needed. if (this.eaccpf.getCpfDescription() == null) { this.eaccpf.setCpfDescription(new CpfDescription()); } if (this.eaccpf.getCpfDescription().getRelations() == null) { this.eaccpf.getCpfDescription().setRelations(new Relations()); } // Call method to build the text of the entity type. builder = this.buildEntityTypeText(builder, cc); // init globals initCPFGlobals(); // Set section title. /*this.setNextRow(); builder.addLabel(this.labels.getString("eaccpf.relations.cpf.section"), cc.xyw(1, this.rowNb, 7));*/ //Call method to build sets relations section. builder = buildSetRelationsSection(builder, cc); // Call method to build cpf relations section. builder = this.buildCPFRelationsSection(builder, cc); // Button to add new CPF/identity relation. this.setNextRow(); JButton addFurtherCPFBtn = new ButtonTab(this.labels.getString("eaccpf.relations.add.further.cpf")); addFurtherCPFBtn.addActionListener(new AddFurtherCPF(this.eaccpf, this.tabbedPane, this.model)); builder.add(addFurtherCPFBtn, cc.xy(1, this.rowNb)); // Call method to build resource relations section. builder = buildResourceRelationsSection(builder, cc); // Call method to build functions relations section. builder = buildFunctionsRelationsSection(builder, cc); // Call method to build the main buttons zone. this.buildButtons(builder, cc); // Define the change tab listener. this.removeChangeListener(); this.tabbedPane.addChangeListener(new ChangeTabListener(this.eaccpf, this.tabbedPane, this.model, 2)); JPanel panel = builder.getPanel(); KeyboardFocusManager.getCurrentKeyboardFocusManager() .addPropertyChangeListener(new FocusManagerListener(panel)); return panel; }
From source file:org.datavyu.views.DatavyuView.java
/** * Constructor.//from ww w . j av a 2 s . c o m * * @param app * The SingleFrameApplication that invoked this main FrameView. */ public DatavyuView(final SingleFrameApplication app) { super(app); KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); manager.addKeyEventDispatcher(new KeyEventDispatcher() { /** * Dispatches the keystroke to the correct action. * * @param evt The event that triggered this action. * @return true if the KeyboardFocusManager should take no further * action with regard to the KeyEvent; false otherwise. */ @Override public boolean dispatchKeyEvent(final KeyEvent evt) { // Pass the keyevent onto the keyswitchboard so that it can // route it to the correct action. // spreadsheetMenuSelected(null); return Datavyu.getApplication().dispatchKeyEvent(evt); } }); // generated GUI builder code initComponents(); // BugzID:492 - Set the shortcut for new cell, so a keystroke that won't // get confused for the "carriage return". The shortcut for new cells // is handled in Datavyu.java newCellMenuItem.setAccelerator(KeyStroke.getKeyStroke('\u21A9')); // BugzID:521 + 468 - Define accelerator keys based on Operating system. int keyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); weakTemporalOrderMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, keyMask)); strongTemporalOrderMenuItem .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.SHIFT_MASK | keyMask)); // Set zoom in to keyMask + '+' zoomInMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, keyMask)); // Set zoom out to keyMask + '-' zoomOutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, keyMask)); // Set reset zoom to keyMask + '0' resetZoomMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0, keyMask)); // Set the save accelerator to keyMask + 'S' saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, keyMask)); // Set the save as accelerator to keyMask + shift + 'S' saveAsMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, keyMask | InputEvent.SHIFT_MASK)); // Set the open accelerator to keyMask + 'o'; openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, keyMask)); // Set the new accelerator to keyMask + 'N'; newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, keyMask)); // Set the new accelerator to keyMask + 'L'; newCellLeftMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, keyMask)); // Set the new accelerator to keyMask + 'R'; newCellRightMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, keyMask)); // Set the show spreadsheet accelrator to F5. showSpreadsheetMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); // Set the undo accelerator to keyMask + 'Z'; undoSpreadSheetMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, keyMask)); // Set the redo accelerator to keyMask + 'Y' redoSpreadSheetMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, keyMask)); if (panel != null) { panel.deregisterListeners(); panel.removeFileDropEventListener(this); } panel = new SpreadsheetPanel(Datavyu.getProjectController().getDB(), null); panel.registerListeners(); panel.addFileDropEventListener(this); setComponent(panel); System.out.println(getComponent()); // initialize the undo/redo system spreadsheetUndoManager = new SpreadsheetUndoManager(); undoSupport = new UndoableEditSupport(); undoSupport.addUndoableEditListener(new UndoAdapter()); refreshUndoRedo(); ////// //Jakrabbit Menu pushMenuItem.setVisible(false); pullMenuItem.setVisible(false); jSeparator10.setVisible(false); }
From source file:eu.apenet.dpt.standalone.gui.eag2012.EagControlPanel.java
@Override protected JComponent buildEditorPanel(List<String> errors) { if (errors == null) errors = new ArrayList<String>(0); else if (Utilities.isDev && errors.size() > 0) { LOG.info("Errors in form:"); for (String error : errors) { LOG.info(error);/* w w w. j a va2 s . c om*/ } } FormLayout layout = new FormLayout("right:max(50dlu;p), 4dlu, 100dlu, 7dlu, right:p, 4dlu, 100dlu", EDITOR_ROW_SPEC); layout.setColumnGroups(new int[][] { { 1, 3, 5, 7 } }); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); rowNb = 1; builder.addLabel(labels.getString("eag2012.commons.idUsedInApe") + "*", cc.xy(1, rowNb)); JTextField recordIdTf = new JTextField(eag.getControl().getRecordId().getValue()); recordIdTf.setEnabled(false); builder.add(recordIdTf, cc.xy(3, rowNb)); setNextRow(); builder.addLabel(labels.getString("eag2012.commons.personResponsible"), cc.xy(1, rowNb)); int sizeEvents = eag.getControl().getMaintenanceHistory().getMaintenanceEvent().size(); if (sizeEvents > 0) { MaintenanceEvent event = eag.getControl().getMaintenanceHistory().getMaintenanceEvent() .get(sizeEvents - 1); personInstitutionRespTf = new TextFieldWithLanguage(event.getAgent().getContent(), event.getAgent().getLang()); } else { personInstitutionRespTf = new TextFieldWithLanguage("", ""); } personInstitutionRespTf.getTextField().setEnabled(false); builder.add(personInstitutionRespTf.getTextField(), cc.xy(3, rowNb)); builder.addLabel(labels.getString("eag2012.commons.language"), cc.xy(5, rowNb)); builder.add(personInstitutionRespTf.getLanguageBox(), cc.xy(7, rowNb)); setNextRow(); builder.addSeparator(labels.getString("eag2012.control.usedLanguages"), cc.xyw(1, rowNb, 7)); setNextRow(); if (eag.getControl().getLanguageDeclarations() == null) eag.getControl().setLanguageDeclarations(new LanguageDeclarations()); if (eag.getControl().getLanguageDeclarations().getLanguageDeclaration().size() == 0) { LanguageDeclaration languageDeclaration = new LanguageDeclaration(); languageDeclaration.setLanguage(new Language()); languageDeclaration.setScript(new Script()); eag.getControl().getLanguageDeclarations().getLanguageDeclaration().add(languageDeclaration); } int i = 0; languageWithScriptTfs = new ArrayList<LanguageWithScript>( eag.getControl().getLanguageDeclarations().getLanguageDeclaration().size()); for (LanguageDeclaration languageDeclaration : eag.getControl().getLanguageDeclarations() .getLanguageDeclaration()) { builder.addLabel(labels.getString("eag2012.commons.language"), cc.xy(1, rowNb)); LanguageWithScript languageWithScript = new LanguageWithScript( languageDeclaration.getLanguage().getLanguageCode(), languageDeclaration.getScript().getScriptCode(), labels); languageWithScriptTfs.add(languageWithScript); builder.add(languageWithScript.getLanguageBox(), cc.xy(3, rowNb)); builder.addLabel(labels.getString("eag2012.control.descriptionScript"), cc.xy(5, rowNb)); builder.add(languageWithScript.getScriptBox(), cc.xy(7, rowNb)); setNextRow(); } if (errors.contains("languageWithScriptTfs")) { builder.add(createErrorLabel(labels.getString("eag2012.errors.noscript")), cc.xy(3, rowNb)); } JButton addLanguagesBtn = new ButtonTab(labels.getString("eag2012.control.addFurtherLangsAnsScripts")); builder.add(addLanguagesBtn, cc.xy(5, rowNb)); addLanguagesBtn.addActionListener(new AddLanguagesBtnAction(eag, tabbedPane, model)); setNextRow(); builder.addSeparator(labels.getString("eag2012.control.conventions"), cc.xyw(1, rowNb, 7)); setNextRow(); if (eag.getControl().getConventionDeclaration().size() == 0) eag.getControl().getConventionDeclaration().add(new ConventionDeclaration()); rulesConventionTfs = new ArrayList<TextFieldWithLanguage>( eag.getControl().getConventionDeclaration().size()); for (ConventionDeclaration conventionDeclaration : eag.getControl().getConventionDeclaration()) { builder.addLabel(labels.getString("eag2012.control.abbreviation"), cc.xy(1, rowNb)); TextFieldWithLanguage textFieldWithLanguage = new TextFieldWithLanguage( conventionDeclaration.getAbbreviation().getContent(), "", conventionDeclaration.getCitation().get(0).getContent()); rulesConventionTfs.add(textFieldWithLanguage); builder.add(textFieldWithLanguage.getTextField(), cc.xy(3, rowNb)); builder.addLabel(labels.getString("eag2012.control.fullName"), cc.xy(5, rowNb)); builder.add(textFieldWithLanguage.getExtraField(), cc.xy(7, rowNb)); setNextRow(); } JButton addConventionBtn = new ButtonTab(labels.getString("eag2012.commons.addCnventions")); builder.add(addConventionBtn, cc.xy(5, rowNb)); addConventionBtn.addActionListener(new AddConventionBtnAction(eag, tabbedPane, model)); setNextRow(); builder.addSeparator("", cc.xyw(1, rowNb, 7)); setNextRow(); JButton exitBtn = new ButtonTab(labels.getString("eag2012.commons.exit")); builder.add(exitBtn, cc.xy(1, rowNb)); exitBtn.addActionListener(new ExitBtnAction(eag, tabbedPane, model)); JButton previousTabBtn = new ButtonTab(labels.getString("eag2012.commons.previousTab")); builder.add(previousTabBtn, cc.xy(3, rowNb)); previousTabBtn.addActionListener(new ChangeTabBtnAction(eag, tabbedPane, model, false)); JButton nextTabBtn = new ButtonTab(labels.getString("eag2012.commons.nextTab")); builder.add(nextTabBtn, cc.xy(5, rowNb)); nextTabBtn.addActionListener(new ChangeTabBtnAction(eag, tabbedPane, model, true)); setNextRow(); JButton saveBtn = new ButtonTab(labels.getString("eag2012.commons.save")); builder.add(saveBtn, cc.xy(5, rowNb)); saveBtn.addActionListener(new SaveBtnAction(eag, tabbedPane, model)); setNextRow(); builder.addSeparator("", cc.xyw(1, rowNb, 7)); setNextRow(); JButton nextInstitutionTabBtn = new ButtonTab(labels.getString("eag2012.controls.nextInstitution")); nextInstitutionTabBtn.addActionListener(new NextInstitutionTabBtnAction(eag, tabbedPane, model)); builder.add(nextInstitutionTabBtn, cc.xy(5, rowNb)); // Define the change tab listener. this.removeChangeListener(); this.tabbedPane.addChangeListener(new ChangeTabListener(this.eag, this.tabbedPane, this.model, 5)); JPanel panel = builder.getPanel(); KeyboardFocusManager.getCurrentKeyboardFocusManager() .addPropertyChangeListener(new FocusManagerListener(panel)); return panel; }
From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfIdentityPanel.java
/** * Builds and answer the identity tab for the given layout. * * @param errors List of errors./*from ww w . j ava 2s. co m*/ * @return the identity tab. */ protected JComponent buildEditorPanel(List<String> errors) { // Checks and initialize the errors list. if (errors == null) { errors = new ArrayList<String>(0); } else if (Utilities.isDev && errors.size() > 0) { LOG.info("Errors in form:"); for (String error : errors) { LOG.info(error); } } // Define the layout for the form. FormLayout layout = new FormLayout("right:max(50dlu;p), 4dlu, 100dlu, 7dlu, right:p, 4dlu, 100dlu", EDITOR_ROW_SPEC); layout.setColumnGroups(new int[][] { { 1, 3, 5, 7 } }); // Construct the panel. PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); // Constraints for the cells; // Create object parts if needed. if (this.eaccpf.getCpfDescription() == null) { this.eaccpf.setCpfDescription(new CpfDescription()); } if (this.eaccpf.getCpfDescription().getIdentity() == null) { this.eaccpf.getCpfDescription().setIdentity(new Identity()); } // Call method to build the text of the entity type. builder = this.buildEntityTypeText(builder, cc); // Call method to build the name section. builder = this.buildNameSection(builder, cc, errors); // Call method to build the identifier section. builder = this.buildIdentifierSection(builder, cc); // Call method to build the dates of existence section. builder = this.buildDatesOfExistenceSection(builder, cc, errors); // Call method to build the main buttons zone. this.buildButtons(builder, cc); // Define the change tab listener. this.removeChangeListener(); this.tabbedPane.addChangeListener(new ChangeTabListener(this.eaccpf, this.tabbedPane, this.model, 0)); JPanel panel = builder.getPanel(); KeyboardFocusManager.getCurrentKeyboardFocusManager() .addPropertyChangeListener(new FocusManagerListener(panel)); return panel; }
From source file:org.opendatakit.briefcase.ui.CharsetConverterDialog.java
@Override public void actionPerformed(ActionEvent e) { Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); String actionCommand = e.getActionCommand(); if (BROWSE_COMMAND.equals(actionCommand)) { WrappedFileChooser dlg = new WrappedFileChooser(window, new FileChooser(true, "Select the file to convert...", "Select")); String path = getFilePath(); if (path != null && path.trim().length() != 0) { dlg.setSelectedFile(new File(path.trim())); }/*from w ww . j a va 2 s. co m*/ int retVal = dlg.showDialog(); if (retVal == JFileChooser.APPROVE_OPTION) { if (dlg.getSelectedFile() != null) { String selectedPath = dlg.getSelectedFile().getAbsolutePath(); tfFile.setText(selectedPath); updatePreview(); } } } else if (CONVERT_COMMAND.equals(actionCommand)) { String filePath = getFilePath(); if (filePath == null || filePath.trim().length() == 0) { return; } File destinationPath; if (cbOverride.isSelected()) { destinationPath = new File(filePath); } else { WrappedFileChooser dlg = new WrappedFileChooser(window, new FileChooser(false, "Select the file to convert to...", "Save")); dlg.setSelectedFile(new File(filePath)); int retVal = dlg.showDialog(); if (retVal == JFileChooser.APPROVE_OPTION && dlg.getSelectedFile() != null) { destinationPath = dlg.getSelectedFile(); } else { return; } } File file = new File(filePath); try { List<String> lines = FileUtils.readLines(file, getCharsetName()); FileUtils.writeLines(destinationPath, "UTF-8", lines, LINE_SEPARATOR); JOptionPane.showMessageDialog(this, DONE_MESSAGE, DONE_TITLE, JOptionPane.INFORMATION_MESSAGE); cancelButton.setText("Close"); } catch (Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), "Error converting file...", JOptionPane.ERROR_MESSAGE); } } else if (CANCEL_COMMAND.equals(actionCommand)) { closeDialog(); } }
From source file:com.intuit.tank.tools.debugger.AgentDebuggerFrame.java
/** * @throws HeadlessException/*from w ww .j a v a2s . c o m*/ */ public AgentDebuggerFrame(final boolean isStandalone, String serviceUrl) throws HeadlessException { super("Intuit Tank Agent Debugger"); workingDir = PanelBuilder.createWorkingDir(this, serviceUrl); setSize(new Dimension(1024, 800)); setBounds(new Rectangle(getSize())); setPreferredSize(getSize()); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setLayout(new BorderLayout()); this.standalone = isStandalone; addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent e) { quit(); } }); errorIcon = ActionProducer.getIcon("bullet_error.png", IconSize.SMALL); modifiedIcon = ActionProducer.getIcon("bullet_code_change.png", IconSize.SMALL); skippedIcon = ActionProducer.getIcon("skip.png", IconSize.SMALL); this.glassPane = new InfiniteProgressPanel(); setGlassPane(glassPane); debuggerActions = new ActionProducer(this, serviceUrl); requestResponsePanel = new RequestResponsePanel(this); requestResponsePanel.init(); testPlanChooser = new JComboBox(); testPlanChooser.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent event) { if (event.getItem() != null) { HDTestPlan selected = (HDTestPlan) event.getItem(); if (!selected.equals(currentTestPlan)) { setCurrentTestPlan(selected); } } } }); tankClientChooser = new JComboBox<TankClientChoice>(); debuggerActions.setChoiceComboBoxOptions(tankClientChooser); actionComponents = new ActionComponents(standalone, testPlanChooser, tankClientChooser, debuggerActions); addScriptChangedListener(actionComponents); setJMenuBar(actionComponents.getMenuBar()); Component topPanel = PanelBuilder.createTopPanel(actionComponents); Component bottomPanel = PanelBuilder.createBottomPanel(this); Component contentPanel = PanelBuilder.createContentPanel(this); final JPopupMenu popup = actionComponents.getPopupMenu(); scriptEditorTA.setPopupMenu(null); scriptEditorTA.addMouseListener(new MouseAdapter() { int lastHash; @Override public void mousePressed(MouseEvent e) { maybeShow(e); } @Override public void mouseReleased(MouseEvent e) { maybeShow(e); } private void maybeShow(MouseEvent e) { if (lastHash == getHash(e)) { return; } if (e.isPopupTrigger()) { // select the line try { int offset = scriptEditorTA.viewToModel(e.getPoint()); Rectangle modelToView = scriptEditorTA.modelToView(offset); Point point = new Point(modelToView.x + 1, e.getPoint().y); if (modelToView.contains(point)) { if (!multiSelect) { int line = scriptEditorTA.getLineOfOffset(offset); scriptEditorTA.setCurrentLine(line); } popup.show(e.getComponent(), e.getX(), e.getY()); } } catch (BadLocationException e1) { e1.printStackTrace(); } } else if (e.isShiftDown()) { int line = scriptEditorTA.getCaretLineNumber(); int start = Math.min(line, lastLine); int end = Math.max(line, lastLine); multiSelect = end - start > 1; if (multiSelect) { multiSelectStart = start; multiSelectEnd = end; try { scriptEditorTA.setEnabled(true); scriptEditorTA.select(scriptEditorTA.getLineStartOffset(start), scriptEditorTA.getLineEndOffset(end)); scriptEditorTA.setEnabled(false); } catch (BadLocationException e1) { e1.printStackTrace(); multiSelect = false; } } } else { multiSelect = false; lastLine = scriptEditorTA.getCaretLineNumber(); } lastHash = getHash(e); } private int getHash(MouseEvent e) { return new HashCodeBuilder().append(e.getButton()).append(e.getSource().hashCode()) .append(e.getPoint()).toHashCode(); } }); JSplitPane mainSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT); mainSplit.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); mainSplit.setTopComponent(contentPanel); mainSplit.setBottomComponent(bottomPanel); mainSplit.setDividerLocation(600); mainSplit.setResizeWeight(0.8D); mainSplit.setDividerSize(5); add(topPanel, BorderLayout.NORTH); add(mainSplit, BorderLayout.CENTER); WindowUtil.centerOnScreen(this); pack(); KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); manager.addKeyEventDispatcher(new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED) { handleKeyEvent(e); } return false; } }); }