List of usage examples for java.awt.event KeyListener KeyListener
KeyListener
From source file:org.genedb.jogra.plugins.TermRationaliser.java
/** * Return a new JFrame which is the main interface to the Rationaliser. *///ww w . j a v a2s . c o m public JFrame getMainPanel() { /* JFRAME */ frame.setTitle(WINDOW_TITLE); frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); frame.setLayout(new BorderLayout()); /* MENU */ JMenuBar menuBar = new JMenuBar(); JMenu actions_menu = new JMenu("Actions"); JMenuItem actions_mitem_1 = new JMenuItem("Refresh lists"); actions_mitem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { initModels(); } }); actions_menu.add(actions_mitem_1); JMenu about_menu = new JMenu("About"); JMenuItem about_mitem_1 = new JMenuItem("About"); about_mitem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JOptionPane.showMessageDialog(null, "Term Rationaliser \n" + "Wellcome Trust Sanger Institute, UK \n" + "2009", "Term Rationaliser", JOptionPane.PLAIN_MESSAGE); } }); about_menu.add(about_mitem_1); menuBar.add(about_menu); menuBar.add(actions_menu); frame.add(menuBar, BorderLayout.NORTH); /* MAIN BOX */ Box center = Box.createHorizontalBox(); //A box that displays contents from left to right center.add(Box.createHorizontalStrut(5)); //Invisible fixed-width component /* FROM LIST AND PANEL */ fromList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); //Allow multiple products to be selected fromList.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_RIGHT) { synchroniseLists(fromList, toList); //synchronise from left to right } } @Override public void keyReleased(KeyEvent arg0) { } @Override public void keyTyped(KeyEvent arg0) { } }); Box fromPanel = this.createRationaliserPanel(FROM_LIST_NAME, fromList); //Box on left hand side fromPanel.add(Box.createVerticalStrut(55)); //Add some space center.add(fromPanel); //Add to main box center.add(Box.createHorizontalStrut(3)); //Add some space /* MIDDLE PANE */ Box middlePane = Box.createVerticalBox(); ClassLoader classLoader = this.getClass().getClassLoader(); //Needed to access the images later on ImageIcon leftButtonIcon = new ImageIcon(classLoader.getResource("left_arrow.gif")); ImageIcon rightButtonIcon = new ImageIcon(classLoader.getResource("right_arrow.gif")); leftButtonIcon = new ImageIcon(leftButtonIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)); //TODO: Investigate simpler way to resize an icon! rightButtonIcon = new ImageIcon(rightButtonIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)); //TODO: Investigate simpler way to resize an icon! JButton rightSynch = new JButton(rightButtonIcon); rightSynch.setToolTipText("Synchronise TO list. \n Shortcut: Right-arrow key"); rightSynch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { synchroniseLists(fromList, toList); } }); JButton leftSynch = new JButton(leftButtonIcon); leftSynch.setToolTipText("Synchronise FROM list. \n Shortcut: Left-arrow key"); leftSynch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { synchroniseLists(toList, fromList); } }); middlePane.add(rightSynch); middlePane.add(leftSynch); center.add(middlePane); //Add middle pane to main box center.add(Box.createHorizontalStrut(3)); /* TO LIST AND PANEL */ toList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //Single product selection in TO list toList.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_LEFT) { synchroniseLists(toList, fromList); //synchronise from right to left } } @Override public void keyReleased(KeyEvent arg0) { } @Override public void keyTyped(KeyEvent arg0) { } }); Box toPanel = this.createRationaliserPanel(TO_LIST_NAME, toList); Box newTerm = Box.createVerticalBox(); textField = new JTextArea(1, 1); //textfield to let the user edit the name of an existing term textField.setMaximumSize(new Dimension(Toolkit.getDefaultToolkit().getScreenSize().height, 10)); textField.setForeground(Color.BLUE); JScrollPane jsp = new JScrollPane(textField); //scroll pane so that there is a horizontal scrollbar jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); newTerm.add(jsp); TitledBorder editBorder = BorderFactory.createTitledBorder("Edit term name"); editBorder.setTitleColor(Color.DARK_GRAY); newTerm.setBorder(editBorder); toPanel.add(newTerm); //add textfield to panel center.add(toPanel); //add panel to main box center.add(Box.createHorizontalStrut(5)); frame.add(center); //add the main panel to the frame initModels(); //load the lists with data /* BOTTOM HALF OF FRAME */ Box main = Box.createVerticalBox(); TitledBorder border = BorderFactory.createTitledBorder("Information"); border.setTitleColor(Color.DARK_GRAY); /* INFORMATION BOX */ Box info = Box.createVerticalBox(); Box scope = Box.createHorizontalBox(); scope.add(Box.createHorizontalStrut(5)); scope.add(scopeLabel); //label showing the scope of the terms scope.add(Box.createHorizontalGlue()); Box productCount = Box.createHorizontalBox(); productCount.add(Box.createHorizontalStrut(5)); productCount.add(productCountLabel); //display the label showing the number of terms productCount.add(Box.createHorizontalGlue()); info.add(scope); info.add(productCount); info.setBorder(border); /* ACTION BUTTONS */ Box actionButtons = Box.createHorizontalBox(); actionButtons.add(Box.createHorizontalGlue()); actionButtons.add(Box.createHorizontalStrut(10)); JButton findFix = new JButton(new FindClosestMatchAction()); actionButtons.add(findFix); actionButtons.add(Box.createHorizontalStrut(10)); RationaliserAction ra = new RationaliserAction(); // RationaliserAction2 ra2 = new RationaliserAction2(); JButton go = new JButton(ra); actionButtons.add(go); actionButtons.add(Box.createHorizontalGlue()); /* MORE INFORMATION TOGGLE */ Box buttonBox = Box.createHorizontalBox(); final JButton toggle = new JButton("Hide information <<"); buttonBox.add(Box.createHorizontalStrut(5)); buttonBox.add(toggle); buttonBox.add(Box.createHorizontalGlue()); Box textBox = Box.createHorizontalBox(); final JScrollPane scrollPane = new JScrollPane(information); scrollPane.setPreferredSize(new Dimension(frame.getWidth(), 100)); scrollPane.setVisible(true); textBox.add(Box.createHorizontalStrut(5)); textBox.add(scrollPane); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (toggle.getText().equals("Show information >>")) { scrollPane.setVisible(true); toggle.setText("Hide information <<"); frame.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight() + 100)); frame.pack(); } else if (toggle.getText().equals("Hide information <<")) { scrollPane.setVisible(false); toggle.setText("Show information >>"); frame.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight() - 100)); frame.pack(); } } }; toggle.addActionListener(actionListener); main.add(Box.createVerticalStrut(5)); main.add(info); main.add(Box.createVerticalStrut(5)); main.add(Box.createVerticalStrut(5)); main.add(actionButtons); main.add(Box.createVerticalStrut(10)); main.add(buttonBox); main.add(textBox); frame.add(main, BorderLayout.SOUTH); frame.pack(); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.setVisible(true); //initModels(); return frame; }
From source file:org.datanucleus.ide.idea.ui.v10x.DNEConfigFormV10x.java
private void createUIComponents() { ///*from ww w .j av a 2s. com*/ // ComboBox for selecting persistence implementation this.persistenceImplComboBox = new JComboBox(); this.persistenceImplComboBox.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { if ("comboBoxChanged".equals(e.getActionCommand())) { final EnhancerSupport selectedEnhancerSupport = getByEnhancerSupportName( DNEConfigFormV10x.this.guiState, (String) DNEConfigFormV10x.this.persistenceImplComboBox.getSelectedItem()); final PersistenceApi selectedApi = DNEConfigFormV10x.this.jDORadioButton.isSelected() ? PersistenceApi.JDO : PersistenceApi.JPA; final PersistenceApi supportedSelectedApi = selectedEnhancerSupport.isSupported(selectedApi) ? selectedApi : selectedEnhancerSupport.getDefaultPersistenceApi(); if (selectedApi != supportedSelectedApi) { JOptionPane.showMessageDialog(null, "Selected persistence implementation does not support " + selectedApi + ',' + "\nreverting to " + supportedSelectedApi); } DNEConfigFormV10x.this.jDORadioButton.setSelected(PersistenceApi.JDO == supportedSelectedApi); DNEConfigFormV10x.this.jPARadioButton.setSelected(PersistenceApi.JPA == supportedSelectedApi); DNEConfigFormV10x.this.jDORadioButton .setEnabled(selectedEnhancerSupport.isSupported(PersistenceApi.JDO)); DNEConfigFormV10x.this.jPARadioButton .setEnabled(selectedEnhancerSupport.isSupported(PersistenceApi.JPA)); DNEConfigFormV10x.this.persistenceImplComboBox .setSelectedItem(selectedEnhancerSupport.getName()); DNEConfigFormV10x.this.configPanel.repaint(); } } }); // // TextBox for metadata-file extensions this.metadataExtensionTextField = new JHintingTextField(); ((JHintingTextField) this.metadataExtensionTextField).setEmptyTextHint(METADATA_FILE_DISABLED); this.metadataExtensionTextField.addKeyListener(new KeyListener() { public void keyTyped(final KeyEvent e) { // do nothing } public void keyPressed(final KeyEvent e) { // do nothing } public void keyReleased(final KeyEvent e) { final String text = DNEConfigFormV10x.this.metadataExtensionTextField.getText(); final String trimmedText = text.trim(); final boolean isEmpty = trimmedText.isEmpty(); DNEConfigFormV10x.this.addToCompilerResourceCheckBox.setEnabled(!isEmpty); } }); }
From source file:self.philbrown.javaQuery.$.java
/** * Refreshes the listeners for key events *//*from www.j av a 2 s. c o m*/ private void setupKeyListener() { for (final Component view : views) { view.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent event) { if (keyDown != null) keyDown.invoke($.with(view), event.getKeyCode(), event); } @Override public void keyReleased(KeyEvent event) { if (keyUp != null) keyUp.invoke($.with(view), event.getKeyCode(), event); } @Override public void keyTyped(KeyEvent event) { if (keyPress != null) keyPress.invoke($.with(view), event.getKeyCode(), event); } }); } }
From source file:edu.brown.gui.CatalogViewer.java
/** * /*www .ja v a2 s .com*/ */ 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:org.apache.cayenne.modeler.CayenneModelerFrame.java
/** Initializes main toolbar. */ protected void initToolbar() { JToolBar toolBar = new JToolBar(); toolBar.add(getAction(NewProjectAction.class).buildButton()); toolBar.add(getAction(OpenProjectAction.class).buildButton()); toolBar.add(getAction(SaveAction.class).buildButton()); toolBar.addSeparator();// ww w .ja v a 2s .c om toolBar.add(getAction(RemoveAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(CutAction.class).buildButton()); toolBar.add(getAction(CopyAction.class).buildButton()); toolBar.add(getAction(PasteAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(UndoAction.class).buildButton()); toolBar.add(getAction(RedoAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(CreateNodeAction.class).buildButton()); toolBar.add(getAction(CreateDataMapAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(CreateDbEntityAction.class).buildButton()); toolBar.add(getAction(CreateProcedureAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(CreateObjEntityAction.class).buildButton()); toolBar.add(getAction(CreateEmbeddableAction.class).buildButton()); toolBar.add(getAction(CreateQueryAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(NavigateBackwardAction.class).buildButton()); toolBar.add(getAction(NavigateForwardAction.class).buildButton()); JPanel east = new JPanel(new BorderLayout()); // is used to place search feature // components the most right on a // toolbar final JTextField findField = new JTextField(10); findField.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() != KeyEvent.VK_ENTER) { findField.setBackground(Color.white); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } }); findField.setAction(getAction(FindAction.class)); JLabel findLabel = new JLabel("Search:"); findLabel.setLabelFor(findField); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { public void eventDispatched(AWTEvent event) { if (event instanceof KeyEvent) { if (((KeyEvent) event).getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() && ((KeyEvent) event).getKeyCode() == KeyEvent.VK_F) { findField.requestFocus(); } } } }, AWTEvent.KEY_EVENT_MASK); JPanel box = new JPanel(); // is used to place label and text field one after // another box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS)); box.add(findLabel); box.add(findField); east.add(box, BorderLayout.EAST); toolBar.add(east); getContentPane().add(toolBar, BorderLayout.NORTH); }
From source file:GUI.simplePanel.java
public simplePanel() { self = this;/*w ww .j a va 2s.co m*/ final Microphone mic = new Microphone(FLACFileWriter.FLAC);//Instantiate microphone and have final GSpeechDuplex dup = new GSpeechDuplex("AIzaSyBc-PCGLbT2M_ZBLUPEl9w2OY7jXl90Hbc");//Instantiate the API dup.addResponseListener(new GSpeechResponseListener() {// Adds the listener public void onResponse(GoogleResponse gr) { System.out.println("got response"); jTextArea1.setText(gr.getResponse() + "\n" + jTextArea1.getText()); getjLabel1().setText("Awaiting Command"); if (gr.getResponse().contains("temperature")) { try { String reply = util.httpRequest.sendPost("127.0.0.1", 8383, "", "/getServices"); JSONObject obj; obj = new JSONObject(reply); JSONArray services = obj.getJSONArray("services"); boolean found = false; for (int i = 0; i < services.length(); i++) { if (found) { return; } Object pref = services.getJSONObject(i).get("url"); String url = (String) pref; if (url.contains("temp")) { // http://127.0.0.1:8181/sensor/1/temp String serviceHost = (url.split(":")[1].substring(2)); int Port = Integer.parseInt((url.split(":")[2]).split("/")[0]); String servicePath = (url.split(":")[2].substring(url.split(":")[2].indexOf("/"))); String serviceReply = util.httpRequest.sendPost(serviceHost, Port, "", servicePath); JSONObject temperature; obj = new JSONObject(serviceReply); String temp = obj.getJSONObject("sensor").getString("Temperature"); JOptionPane.showMessageDialog(self, "Temperature is " + temp.substring(0, temp.indexOf(".") + 2) + " Celsius"); found = true; } } } catch (Exception e) { e.printStackTrace(); } } else if (gr.getResponse().contains("light") || gr.getResponse().startsWith("li")) { try { String reply = util.httpRequest.sendPost("127.0.0.1", 8383, "", "/getServices"); JSONObject obj; obj = new JSONObject(reply); JSONArray services = obj.getJSONArray("services"); boolean found = false; for (int i = 0; i < services.length(); i++) { if (found) { return; } Object pref = services.getJSONObject(i).get("url"); String url = (String) pref; if (url.contains("light")) { // http://127.0.0.1:8181/sensor/1/temp String serviceHost = (url.split(":")[1].substring(2)); int Port = Integer.parseInt((url.split(":")[2]).split("/")[0]); String servicePath = (url.split(":")[2].substring(url.split(":")[2].indexOf("/"))); String serviceReply = util.httpRequest.sendPost(serviceHost, Port, "", servicePath); JSONObject temperature; obj = new JSONObject(serviceReply); String temp = obj.getJSONObject("sensor").getString("Light"); JOptionPane.showMessageDialog(self, "Light levels are at " + temp + " of 1023 "); found = true; } } } catch (Exception e) { e.printStackTrace(); } } else if ((gr.getResponse().contains("turn on") || gr.getResponse().contains("turn off")) && gr.getResponse().contains("number")) { int numberIndex = gr.getResponse().indexOf("number ") + "number ".length(); String number = gr.getResponse().substring(numberIndex).split(" ")[0]; if (number.equals("for") || number.equals("four")) { number = "4"; } if (number.equals("to") || number.equals("two") || number.equals("cho")) { number = "2"; } if (number.equals("one")) { number = "1"; } if (number.equals("three")) { number = "3"; } try { String reply = util.httpRequest.sendPost("127.0.0.1", 8383, "", "/getServices"); JSONObject obj; obj = new JSONObject(reply); JSONArray services = obj.getJSONArray("services"); boolean found = false; for (int i = 0; i < services.length(); i++) { if (found) { return; } Object pref = services.getJSONObject(i).get("url"); String url = (String) pref; if (url.contains("sensor/" + number)) { // http://127.0.0.1:8181/sensor/1/temp String serviceHost = (url.split(":")[1].substring(2)); int Port = Integer.parseInt((url.split(":")[2]).split("/")[0]); String servicePath = (url.split(":")[2].substring(url.split(":")[2].indexOf("/"))); String serviceReply = util.httpRequest.sendPost(serviceHost, Port, "", servicePath); JSONObject temperature; obj = new JSONObject(serviceReply); String temp = obj.getJSONObject("sensor").getString("Switch"); if (!(temp.equals("0") || temp.equals("1"))) { JOptionPane.showMessageDialog(self, "Sensor does not provide a switch service man"); } else if (gr.getResponse().contains("turn on") && temp.equals("1")) { JOptionPane.showMessageDialog(self, "Switch is already on at sensor " + number + "!"); } else if (gr.getResponse().contains("turn off") && temp.equals("0")) { JOptionPane.showMessageDialog(self, "Switch is already off at sensor " + number + "!"); } else if (gr.getResponse().contains("turn on") && temp.equals("0")) { String serviceReply2 = util.httpRequest.sendPost(serviceHost, Port, "", "/sensor/" + number + "/switch"); JOptionPane.showMessageDialog(self, "Request for switch sent"); } else if (gr.getResponse().contains("turn off") && temp.equals("1")) { String serviceReply2 = util.httpRequest.sendPost(serviceHost, Port, "", "/sensor/" + number + "/switch"); JOptionPane.showMessageDialog(self, "Request for switch sent"); } found = true; } } } catch (Exception e) { e.printStackTrace(); } } else if (gr.getResponse().contains("change") && gr.getResponse().contains("number")) { int numberIndex = gr.getResponse().indexOf("number ") + "number ".length(); String number = gr.getResponse().substring(numberIndex).split(" ")[0]; if (number.equals("for") || number.equals("four")) { number = "4"; } if (number.equals("to") || number.equals("two") || number.equals("cho")) { number = "2"; } if (number.equals("one")) { number = "1"; } if (number.equals("three")) { number = "3"; } try { String reply = util.httpRequest.sendPost("127.0.0.1", 8383, "", "/getServices"); JSONObject obj; obj = new JSONObject(reply); JSONArray services = obj.getJSONArray("services"); boolean found = false; for (int i = 0; i < services.length(); i++) { if (found) { return; } Object pref = services.getJSONObject(i).get("url"); String url = (String) pref; if (url.contains("sensor/" + number)) { // http://127.0.0.1:8181/sensor/1/temp String serviceHost = (url.split(":")[1].substring(2)); int Port = Integer.parseInt((url.split(":")[2]).split("/")[0]); String servicePath = (url.split(":")[2].substring(url.split(":")[2].indexOf("/"))); String serviceReply = util.httpRequest.sendPost(serviceHost, Port, "", servicePath); JSONObject temperature; obj = new JSONObject(serviceReply); String temp = obj.getJSONObject("sensor").getString("Switch"); if (!(temp.equals("0") || temp.equals("1"))) { JOptionPane.showMessageDialog(self, "Sensor does not provide a switch service man"); } else { String serviceReply2 = util.httpRequest.sendPost(serviceHost, Port, "", "/sensor/" + number + "/switch"); JOptionPane.showMessageDialog(self, "Request for switch sent"); } found = true; } } } catch (Exception e) { JOptionPane.showMessageDialog(self, e.getLocalizedMessage()); } } else if (gr.getResponse().contains("get all")) { try { String reply = util.httpRequest.sendPost("127.0.0.1", 8383, "", "/getServices"); JSONObject obj; obj = new JSONObject(reply); JSONArray services = obj.getJSONArray("services"); boolean found = false; String servicesString = ""; for (int i = 0; i < services.length(); i++) { Object pref = services.getJSONObject(i).get("url"); String url = (String) pref; servicesString += url + "\n"; } JOptionPane.showMessageDialog(self, servicesString); } catch (Exception e) { e.printStackTrace(); } } else { try { ChatterBotFactory factory = new ChatterBotFactory(); ChatterBot bot1 = factory.create(CLEVERBOT); ChatterBotSession bot1session = bot1.createSession(); String s = gr.getResponse(); String response = bot1session.think(s); JOptionPane.showMessageDialog(self, response); } catch (Exception e) { } } System.out.println("Google thinks you said: " + gr.getResponse()); System.out.println("with " + ((gr.getConfidence() != null) ? (Double.parseDouble(gr.getConfidence()) * 100) : null) + "% confidence."); System.out.println("Google also thinks that you might have said:" + gr.getOtherPossibleResponses()); } }); initComponents(); jTextField1.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { String input = jTextField1.getText(); jTextField1.setText(""); textParser(input); } //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void keyReleased(KeyEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); jButton1.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void mousePressed(MouseEvent e) { // it record FLAC file. File file = new File("CRAudioTest.flac");//The File to record the buffer to. //You can also create your own buffer using the getTargetDataLine() method. System.out.println("Start Talking Honey"); try { mic.captureAudioToFile(file);//Begins recording } catch (Exception ex) { ex.printStackTrace();//Prints an error if something goes wrong. } //System.out.println("You can stop now"); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void mouseReleased(MouseEvent e) { try { mic.close();//Stops recording //Sends 10 second voice recording to Google byte[] data = Files.readAllBytes(mic.getAudioFile().toPath());//Saves data into memory. dup.recognize(data, (int) mic.getAudioFormat().getSampleRate(), self); //mic.getAudioFile().delete();//Deletes Buffer file //REPEAT } catch (Exception ex) { ex.printStackTrace();//Prints an error if something goes wrong. } System.out.println("You can stop now"); } @Override public void mouseEntered(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void mouseExited(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); setVisible(true); }
From source file:com.rapidminer.gui.properties.RegexpPropertyDialog.java
public RegexpPropertyDialog(final Collection<String> items, String predefinedRegexp, String description) { super(ApplicationFrame.getApplicationFrame(), "parameter.regexp", ModalityType.APPLICATION_MODAL, new Object[] {}); this.items = items; this.supportsItems = items != null; this.infoText = "<html>" + I18N.getMessage(I18N.getGUIBundle(), getKey() + ".title") + ": <br/>" + description + "</html>"; Dimension size = new Dimension(420, 500); this.setMinimumSize(size); this.setPreferredSize(size); JPanel panel = new JPanel(createGridLayout(1, supportsItems ? 2 : 1)); // create regexp text field regexpTextField = new JTextField(predefinedRegexp); regexpTextField.setToolTipText(//from w w w.j av a 2 s . c o m I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.tip")); regexpTextField.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { fireRegularExpressionUpdated(); } @Override public void keyTyped(KeyEvent e) { } }); regexpTextField.requestFocus(); // create replacement text field replacementTextField = new JTextField(); replacementTextField.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.replacement.tip")); replacementTextField.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { fireRegularExpressionUpdated(); } @Override public void keyTyped(KeyEvent e) { } }); // create inline search documents inlineSearchDocument = new RegexpSearchStyledDocument(); inlineReplaceDocument = new RegexpReplaceStyledDocument(); // create search results list DefaultListCellRenderer resultCellRenderer = new DefaultListCellRenderer() { private static final long serialVersionUID = 1L; @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); setBackground(list.getBackground()); setForeground(list.getForeground()); setBorder(getNoFocusBorder()); return this; } private Border getNoFocusBorder() { Border border = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray); return border; } }; JList<RegExpResult> regexpFindingsList = new JList<RegExpResult>(resultsListModel); regexpFindingsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); regexpFindingsList.setLayoutOrientation(JList.VERTICAL); regexpFindingsList.setCellRenderer(resultCellRenderer); // regexp panel on left side of dialog JPanel regexpPanel = new JPanel(new GridBagLayout()); regexpPanel.setBorder(createTitledBorder( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.border"))); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(4, 4, 4, 0); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.fill = GridBagConstraints.BOTH; regexpPanel.add(regexpTextField, c); // make shortcut button final Action nullAction = new DefaultAction(); PlainArrowDropDownButton autoWireDropDownButton = PlainArrowDropDownButton.makeDropDownButton(nullAction); for (String[] popupItem : (String[][]) ArrayUtils.addAll(regexpConstructs, regexpShortcuts)) { String shortcut = popupItem[0].length() > 14 ? popupItem[0].substring(0, 14) + "..." : popupItem[0]; autoWireDropDownButton .add(new InsertionAction("<html><table border=0 cellpadding=0 cellspacing=0><tr><td width=100>" + shortcut + "</td><td>" + popupItem[1] + "</td></tr></table></html>", popupItem[0])); } c.insets = new Insets(4, 0, 4, 0); c.gridx = 1; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; regexpPanel.add(autoWireDropDownButton.getDropDownArrowButton(), c); // make delete button c.insets = new Insets(4, 0, 4, 4); c.gridx = 2; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; JButton clearRegexpTextFieldButton = new JButton(SwingTools.createIcon("16/delete2.png")); clearRegexpTextFieldButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { regexpTextField.setText(""); fireRegularExpressionUpdated(); regexpTextField.requestFocusInWindow(); } }); regexpPanel.add(clearRegexpTextFieldButton, c); errorMessage = new JLabel(NO_ERROR_MESSAGE, NO_ERROR_ICON, SwingConstants.LEFT); errorMessage.setFocusable(false); c.insets = new Insets(4, 8, 4, 4); c.gridx = 0; c.gridy = 1; c.weightx = 0; c.weighty = 0; c.gridwidth = GridBagConstraints.REMAINDER; regexpPanel.add(errorMessage, c); // create replacement panel JPanel replacementPanel = new JPanel(new GridBagLayout()); replacementPanel.setBorder(createTitledBorder( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.replacement.border"))); JPanel testerPanel = new JPanel(new GridBagLayout()); c.insets = new Insets(4, 4, 4, 0); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; replacementPanel.add(replacementTextField, c); // create inline search panel JPanel inlineSearchPanel = new JPanel(new GridBagLayout()); c.insets = new Insets(8, 4, 4, 4); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; inlineSearchPanel.add( new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.inline_search.search")), c); c.insets = new Insets(0, 0, 0, 0); c.gridx = 0; c.gridy = 1; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; inlineSearchPanel.add(new JScrollPane(new JTextPane(inlineSearchDocument)), c); c.insets = new Insets(8, 4, 4, 4); c.gridx = 0; c.gridy = 2; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; inlineSearchPanel.add( new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.inline_search.replaced")), c); c.insets = new Insets(0, 0, 0, 0); c.gridx = 0; c.gridy = 3; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; JTextPane replaceTextPane = new JTextPane(inlineReplaceDocument); replaceTextPane.setEditable(false); inlineSearchPanel.add(new JScrollPane(replaceTextPane), c); // create regexp options panel ItemListener defaultOptionListener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { fireRegexpOptionsChanged(); } }; cbCaseInsensitive = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.case_insensitive")); cbCaseInsensitive.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.case_insensitive.tip")); cbCaseInsensitive.addItemListener(defaultOptionListener); cbMultiline = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.multiline_mode")); cbMultiline.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.multiline_mode.tip")); cbMultiline.addItemListener(defaultOptionListener); cbDotall = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.dotall_mode")); cbDotall.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.dotall_mode.tip")); cbDotall.addItemListener(defaultOptionListener); cbUnicodeCase = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.unicode_case")); cbUnicodeCase.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.unicode_case.tip")); cbUnicodeCase.addItemListener(defaultOptionListener); JPanel regexpOptionsPanelWrapper = new JPanel(new BorderLayout()); JPanel regexpOptionsPanel = new JPanel(new GridBagLayout()); regexpOptionsPanelWrapper.add(regexpOptionsPanel, BorderLayout.NORTH); c.insets = new Insets(12, 4, 0, 4); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; regexpOptionsPanel.add(cbMultiline, c); c.insets = new Insets(8, 4, 0, 4); c.gridy = 1; regexpOptionsPanel.add(cbCaseInsensitive, c); c.gridy = 2; regexpOptionsPanel.add(cbUnicodeCase, c); c.gridy = 3; regexpOptionsPanel.add(cbDotall, c); // create tabbed panel c.insets = new Insets(8, 4, 4, 4); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.BOTH; testExp = new JTabbedPane(); testExp.add( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.inline_search.title"), new JScrollPane(inlineSearchPanel)); testExp.add( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.result_list.title"), new JScrollPane(regexpFindingsList)); testExp.add( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.title"), regexpOptionsPanelWrapper); testerPanel.add(testExp, c); JPanel groupPanel = new JPanel(new GridBagLayout()); c.insets = new Insets(4, 4, 4, 4); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; groupPanel.add(regexpPanel, c); c.insets = new Insets(4, 4, 4, 4); c.gridx = 0; c.gridy = 1; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; groupPanel.add(replacementPanel, c); c.insets = new Insets(4, 4, 4, 4); c.gridx = 0; c.gridy = 2; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; groupPanel.add(testerPanel, c); panel.add(groupPanel, 1, 0); if (supportsItems) { // item shortcuts list itemShortcutsList = new JList<String>(items.toArray(new String[items.size()])); itemShortcutsList.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.item_shortcuts.tip")); itemShortcutsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); itemShortcutsList.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { String text = regexpTextField.getText(); int cursorPosition = regexpTextField.getCaretPosition(); int index = itemShortcutsList.getSelectedIndex(); if (index > -1 && index < itemShortcutsList.getModel().getSize()) { String insertionString = itemShortcutsList.getModel().getElementAt(index).toString(); String newText = text.substring(0, cursorPosition) + insertionString + (cursorPosition < text.length() ? text.substring(cursorPosition) : ""); regexpTextField.setText(newText); regexpTextField.setCaretPosition(cursorPosition + insertionString.length()); regexpTextField.requestFocus(); fireRegularExpressionUpdated(); } } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); JScrollPane itemShortcutsPane = new JScrollPane(itemShortcutsList); itemShortcutsPane.setBorder(createTitledBorder( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.item_shortcuts.border"))); // matched items list matchedItemsListModel = new DefaultListModel<String>(); JList<String> matchedItemsList = new JList<String>(matchedItemsListModel); matchedItemsList.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.matched_items.tip")); // add custom cell renderer to disallow selections matchedItemsList.setCellRenderer(new DefaultListCellRenderer() { private static final long serialVersionUID = -5795848004756768378L; @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return super.getListCellRendererComponent(list, value, index, false, false); } }); JScrollPane matchedItemsPanel = new JScrollPane(matchedItemsList); matchedItemsPanel.setBorder(createTitledBorder( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.matched_items.border"))); // item panel on right side of dialog JPanel itemPanel = new JPanel(createGridLayout(1, 2)); itemPanel.add(itemShortcutsPane, 0, 0); itemPanel.add(matchedItemsPanel, 0, 1); panel.add(itemPanel, 0, 1); } okButton = makeOkButton("regexp_property_dialog_apply"); fireRegularExpressionUpdated(); layoutDefault(panel, supportsItems ? NORMAL : NARROW, okButton, makeCancelButton()); }
From source file:com.mirth.connect.client.ui.alert.AlertChannelPane.java
private void initComponents() { setBackground(UIConstants.BACKGROUND_COLOR); setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Channels")); setLayout(new MigLayout("insets 0", "[grow][grow]", "[][][grow]")); filterLabel = new JLabel("Filter: "); filterTextField = new JTextField(); filterTextField.addKeyListener(new KeyListener() { @Override// w w w.j a v a 2 s .c o m public void keyTyped(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { updateFilter(filterTextField.getText()); } }); expandLabel = new JLabel("<html><u>Expand All</u></html>"); expandLabel.setForeground(Color.blue); expandLabel.setToolTipText("Expand all nodes below."); expandLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); expandLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { channelTreeTable.expandAll(); } }); collapseLabel = new JLabel("<html><u>Collapse All</u></html>"); collapseLabel.setForeground(Color.blue); collapseLabel.setToolTipText("Collapse all nodes below."); collapseLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); collapseLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { channelTreeTable.collapseAll(); } }); enableButton = new JButton("Enable"); enableButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { toggleSelectedRows(true); PlatformUI.MIRTH_FRAME.setSaveEnabled(true); } }); disableButton = new JButton("Disable"); disableButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { toggleSelectedRows(false); PlatformUI.MIRTH_FRAME.setSaveEnabled(true); } }); channelTreeTable = new MirthTreeTable(); channelScrollPane = new JScrollPane(channelTreeTable); add(filterLabel, "span 2, split"); add(filterTextField, "growx, span, wrap"); add(enableButton, "split 2, alignx left, width 50"); add(disableButton, "alignx left, width 50"); add(expandLabel, "split 2, alignx right"); add(collapseLabel, "alignx right, wrap"); add(channelScrollPane, "height 100:100:, width 100:100:, grow, span"); }
From source file:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.imagem.analise_geral.PanelAnaliseGeral.java
/** * Inicia os componentes/* w w w. j ava 2 s . c o m*/ * * @param erros */ private void initComponentsEscalavel(ArrayList<FerramentaAnaliseGeralModel> erros) { incValueProgress(); hashCodeInicial = null; PainelStatusBar.hideProgTarReq(); Ferramenta_Imagens.carregaTexto(TokenLang.LANG); JPanel regraFonteBtn = new JPanel(); regraFonteBtn.setLayout(new BorderLayout()); PainelStatusBar.setValueProgress(3); boxCode = new G_TextAreaSourceCode(); boxCode.setTipoHTML(); incValueProgress(); parentFrame.setJMenuBar(this.criaMenuBar()); PainelStatusBar.setValueProgress(6); // parentFrame.setTitle("Associador de rtulos"); tableLinCod = new TabelaAnaliseGeral(this, erros); arTextPainelCorrecao = new ArTextPainelCorrecao(this); incValueProgress(); // scrollPaneCorrecaoLabel = new ConteudoCorrecaoLabel(); analiseSistematica = new JButton(); salvar = new JButton(); cancelar = new JButton(); salvarMod = new JButton(); salvarPag = new JButton(); aplicarPag = new JButton(); aplicarTod = new JButton(); strConteudoalt = new String(); incValueProgress(); btnSalvar = new JMenuItem(GERAL.BTN_SALVAR); PainelStatusBar.setValueProgress(10); pnRegra = new JPanel(); lbRegras1 = new JLabel(); lbRegras2 = new JLabel(); pnSetaDescricao = new JPanel(); spTextoDescricao = new JScrollPane(); tArParticipRotulo = new TArParticipRotulo(this); conteudoDoAlt = new JTextArea(); pnListaErros = new JPanel(); scrollPanetabLinCod = new JScrollPane(); incValueProgress(); /** * Mostra pro usurio a imagem que est sem descrio */ imagemSemDesc = new XHTMLPanel(); pnBotoes = new JPanel(); salvar.setEnabled(false); // salvaAlteracoes = new SalvaAlteracoes(boxCode.getTextPane(), salvar, // btnSalvar, parentFrame); adicionar = new JButton(); aplicar = new JButton(); conteudoParticRotulo = new ArrayList<String>(); analiseSistematica.setEnabled(false); boxCode.getTextPane().setText(TxtBuffer.getContent()); PainelStatusBar.setValueProgress(20); String fullUrl = this.enderecoImagem; System.out.println("\t\t\t\t\tendereo da imagem: " + fullUrl); SetImage setImage = new SetImage(this, fullUrl); setImage.start(); incValueProgress(); setBackground(CoresDefault.getCorPaineis()); Container contentPane = this;// ?? contentPane.setLayout(new GridLayout(2, 1)); incValueProgress(); // ======== pnRegra ======== { pnRegra.setBorder(criaBorda(Ferramenta_Imagens.TITULO_REGRA)); pnRegra.setLayout(new GridLayout(2, 1)); pnRegra.add(lbRegras1); lbRegras1.setText(Ferramenta_Imagens.REGRAP1); lbRegras2.setText(Ferramenta_Imagens.REGRAP2); lbRegras1.setHorizontalAlignment(SwingConstants.CENTER); lbRegras2.setHorizontalAlignment(SwingConstants.CENTER); pnRegra.add(lbRegras1); pnRegra.add(lbRegras2); pnRegra.setPreferredSize(new Dimension(700, 60)); incValueProgress(); } PainelStatusBar.setValueProgress(30); // G_URLIcon.setIcon(lbTemp, // "http://pitecos.blogs.sapo.pt/arquivo/pai%20natal%20o5.%20jpg.jpg"); JScrollPane sp = new JScrollPane(); sp.setViewportView(imagemSemDesc); sp.setPreferredSize(new Dimension(500, 300)); // ======== pnDescricao ======== incValueProgress(); // ---- Salvar ---- salvarMod.setText(GERAL.SALVAR_MODIFICADAS); salvarMod.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { salvarModificadosActionPerformed(e); } }); incValueProgress(); salvarMod.setToolTipText(GERAL.DICA_SALVAR_MODIFICADOS); salvarMod.getAccessibleContext().setAccessibleDescription(GERAL.DICA_SALVAR_MODIFICADOS); salvarMod.getAccessibleContext().setAccessibleName(GERAL.DICA_SALVAR_MODIFICADOS); salvarMod.setBounds(10, 0, 150, 25); PainelStatusBar.setValueProgress(40); salvarPag.setText(GERAL.SALVAR_ULTIMA); salvarPag.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { salvarPaginaActionPerformed(e); } }); incValueProgress(); salvarPag.setToolTipText(GERAL.DICA_SALVAR_ULTIMA_MODIFICADA); salvarPag.getAccessibleContext().setAccessibleDescription(GERAL.DICA_SALVAR_ULTIMA_MODIFICADA); salvarPag.getAccessibleContext().setAccessibleName(Ferramenta_Imagens.DICA_ABRIR_HTML); salvarPag.setBounds(165, 0, 150, 25); incValueProgress(); salvarMod.setEnabled(false); salvarPag.setEnabled(false); ArrayList<JButton> btnsSalvar = new ArrayList<JButton>(); btnsSalvar.add(salvarMod); btnsSalvar.add(salvarPag); btnsSalvar.add(salvar); salvaAlteracoes = new SalvaAlteracoes(boxCode.getTextPane(), btnsSalvar, btnSalvar, parentFrame); aplicarPag.setText(GERAL.APLICAR_PAGINA); aplicarPag.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { aplicarPaginaActionPerformed(e); } }); incValueProgress(); PainelStatusBar.setValueProgress(50); aplicarPag.setToolTipText(GERAL.DICA_APLICA_PAGINA); aplicarPag.getAccessibleContext().setAccessibleDescription(GERAL.DICA_APLICA_PAGINA); aplicarPag.getAccessibleContext().setAccessibleName(GERAL.DICA_APLICA_PAGINA); aplicarPag.setBounds(320, 0, 150, 25); incValueProgress(); aplicarTod.setText(GERAL.APLICA_TODOS); aplicarTod.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Thread t = new Thread(new Runnable() { public void run() { aplicarATodosActionPerformed(); } }); t.start(); } }); incValueProgress(); aplicarTod.setToolTipText(GERAL.DICA_APLICA_ULTIMA_TODOS); aplicarTod.getAccessibleContext().setAccessibleDescription(GERAL.DICA_APLICA_ULTIMA_TODOS); aplicarTod.getAccessibleContext().setAccessibleName(GERAL.DICA_APLICA_ULTIMA_TODOS); aplicarTod.setBounds(475, 0, 150, 25); aplicarPag.setEnabled(false); aplicarTod.setEnabled(false); PainelStatusBar.setValueProgress(60); incValueProgress(); cancelar.setText(GERAL.TELA_ANTERIOR); cancelar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { CancelarActionPerformed(e); } }); cancelar.setToolTipText(Ferramenta_Imagens.DICA_BTN_CANCELAR); cancelar.getAccessibleContext().setAccessibleDescription(Ferramenta_Imagens.DICA_BTN_CANCELAR); cancelar.getAccessibleContext().setAccessibleName(Ferramenta_Imagens.DICA_BTN_CANCELAR); cancelar.setBounds(630, 0, 150, 25); incValueProgress(); pnSetaDescricao.setBorder(criaBorda(Ferramenta_Imagens.TITULO_DIGITE_O_ALT)); GridBagConstraints cons = new GridBagConstraints(); GridBagLayout layout = new GridBagLayout(); cons.fill = GridBagConstraints.BOTH; cons.weighty = 1; cons.weightx = 0.80; PainelStatusBar.setValueProgress(70); incValueProgress(); pnSetaDescricao.setLayout(layout); cons.anchor = GridBagConstraints.SOUTHEAST; cons.insets = new Insets(0, 0, 0, 10); // ======== spParticRotulo ======== conteudoDoAlt.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent arg0) { } public void keyTyped(KeyEvent arg0) { } public void keyReleased(KeyEvent arg0) { if (conteudoDoAlt.getText().length() == 0 || tableLinCod.getNumLinhas() < 1) { System.out.println("conteudo vazio"); aplicarPag.setEnabled(false); aplicarTod.setEnabled(false); } else if (tableLinCod.getSelectedRow() != -1) { System.out.println("com conteudo"); aplicarPag.setEnabled(true); aplicarTod.setEnabled(true); } else { aplicarTod.setEnabled(true); } } }); { spTextoDescricao.setViewportView(conteudoDoAlt); } incValueProgress(); // lbRegras1.setText(Reparo_Imagens.REGRAP2); // lbRegras1.setHorizontalAlignment(SwingConstants.CENTER); // pnRegra.add(lbRegras1); pnSetaDescricao.add(spTextoDescricao, cons); cons.weightx = 0.20; pnSetaDescricao.setPreferredSize(new Dimension(400, 60)); // ======== pnListaErros ======== { PainelStatusBar.setValueProgress(80); pnListaErros.setBorder(criaBorda(Ferramenta_Imagens.LISTA_ERROS)); pnListaErros.setLayout(new BorderLayout()); // ======== scrollPanetabLinCod ======== { scrollPanetabLinCod.setViewportView(tableLinCod); } pnListaErros.add(scrollPanetabLinCod, BorderLayout.CENTER); } // ======== pnBotoes ======== incValueProgress(); { // pnBotoes.setBorder(criaBorda("")); pnBotoes.setLayout(null); // ---- adicionar ---- adicionar.setText(Ferramenta_Imagens.BTN_ADICIONAR); adicionar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { adicionarActionPerformed(e); } }); PainelStatusBar.setValueProgress(90); adicionar.setToolTipText(Ferramenta_Imagens.DICA_ADICIONAR); adicionar.getAccessibleContext().setAccessibleDescription(Ferramenta_Imagens.DICA_ADICIONAR); adicionar.getAccessibleContext().setAccessibleName(Ferramenta_Imagens.DICA_ADICIONAR); adicionar.setBounds(10, 5, 150, 25); // pnBotoes.add(adicionar); incValueProgress(); // ---- aplicarRotulo ---- aplicar.setEnabled(false); aplicar.setText(Ferramenta_Imagens.BTN_APLICAR); aplicar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { aplicarRotuloActionPerformed(e); } }); incValueProgress(); aplicar.setToolTipText(Ferramenta_Imagens.DICA_APLICAR); aplicar.getAccessibleContext().setAccessibleDescription(Ferramenta_Imagens.DICA_APLICAR); aplicar.getAccessibleContext().setAccessibleName(Ferramenta_Imagens.DICA_APLICAR); aplicar.setBounds(10, 5, 150, 25); // pnBotoes.add(aplicar); } /* * Colocar os controles */ pnRegra.setBackground(CoresDefault.getCorPaineis()); regraFonteBtn.add(pnRegra, BorderLayout.NORTH); boxCode.setBorder(criaBorda("")); boxCode.setBackground(CoresDefault.getCorPaineis()); incValueProgress(); JSplitPane splitPane = null; Dimension minimumSize = new Dimension(0, 0); // JScrollPane ajudaScrollPane = new // JScrollPane(ajuda,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); PainelStatusBar.setValueProgress(93); sp.setMinimumSize(minimumSize); sp.setPreferredSize(new Dimension(150, 90)); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp, boxCode); splitPane.setOneTouchExpandable(true); // splitPane.set // splitPane.setDividerLocation(0.95); int w = parentFrame.getWidth(); int s = w / 4; splitPane.setDividerLocation(s); incValueProgress(); // regraFonteBtn.add(scrollPaneCorrecaoLabel, BorderLayout.CENTER); regraFonteBtn.add(splitPane, BorderLayout.CENTER); pnBotoes.setPreferredSize(new Dimension(600, 35)); pnBotoes.setBackground(CoresDefault.getCorPaineis()); // regraFonteBtn.add(pnBotoes, BorderLayout.SOUTH); regraFonteBtn.setBackground(CoresDefault.getCorPaineis()); contentPane.add(regraFonteBtn); PainelStatusBar.setValueProgress(96); JPanel textoErrosBtn = new JPanel(); textoErrosBtn.setLayout(new BorderLayout()); pnSetaDescricao.setBackground(CoresDefault.getCorPaineis()); pnSetaDescricao.add(pnBotoes, cons); textoErrosBtn.add(pnSetaDescricao, BorderLayout.NORTH); textoErrosBtn.add(pnListaErros, BorderLayout.CENTER); JPanel pnSalvarCancelar = new JPanel(); pnSalvarCancelar.setLayout(null); pnSalvarCancelar.setPreferredSize(new Dimension(600, 35)); incValueProgress(); pnSalvarCancelar.add(salvarMod); pnSalvarCancelar.add(salvarPag); pnSalvarCancelar.add(aplicarPag); pnSalvarCancelar.add(aplicarTod); pnSalvarCancelar.add(cancelar); pnSalvarCancelar.setBackground(CoresDefault.getCorPaineis()); incValueProgress(); textoErrosBtn.add(pnSalvarCancelar, BorderLayout.SOUTH); PainelStatusBar.setValueProgress(100); pnListaErros.setBackground(CoresDefault.getCorPaineis()); textoErrosBtn.add(pnListaErros, BorderLayout.CENTER); contentPane.setBackground(CoresDefault.getCorPaineis()); incValueProgress(); contentPane.add(textoErrosBtn); System.out.println("\t\t\t" + TxtBuffer.getContent()); incValueProgress(); this.setVisible(true); }
From source file:org.ut.biolab.medsavant.client.project.ProjectWizard.java
private AbstractWizardPage getVCFFieldsPage() { //setup page/*from ww w . j a v a 2s . c o m*/ final DefaultWizardPage page = new DefaultWizardPage(PAGENAME_VCF) { @Override public void setupWizardButtons() { fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK); fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.BACK); fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH); fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT); } }; page.addText("Add extra fields to parse from INFO text in VCF files. "); JScrollPane scrollpane = new JScrollPane(); scrollpane.setPreferredSize(new Dimension(300, 250)); scrollpane.getViewport().setBackground(Color.white); final JTable table = new JTable() { @Override public Class<?> getColumnClass(int column) { if (column == 2) { return Boolean.class; } else { return String.class; } } }; variantFormatModel = new DefaultTableModel(); variantFormatModel.addColumn("Key"); variantFormatModel.addColumn("Type"); variantFormatModel.addColumn("Filterable"); variantFormatModel.addColumn("Alias"); variantFormatModel.addColumn("Description"); if (modify) { try { int firstRef = manager.getReferenceIDsForProject(LoginController.getSessionID(), projectID)[0]; CustomField[] fields = manager.getCustomVariantFields(LoginController.getSessionID(), projectID, firstRef, manager.getNewestUpdateID(LoginController.getSessionID(), projectID, firstRef, false)); for (CustomField f : fields) { //casing of f.getColumnName should match database. variantFormatModel.addRow(new Object[] { f.getColumnName(), f.getTypeString(), f.isFilterable(), f.getAlias(), f.getDescription() }); } } catch (Exception ex) { LOG.error("Error getting reference IDs for project.", ex); } } else { variantFormatModel .addRow(new Object[] { AA.getColumnName(), AA.getTypeString(), true, AA.getAlias(), "" }); variantFormatModel .addRow(new Object[] { AC.getColumnName(), AC.getTypeString(), true, AC.getAlias(), "" }); variantFormatModel .addRow(new Object[] { AF.getColumnName(), AF.getTypeString(), true, AF.getAlias(), "" }); variantFormatModel .addRow(new Object[] { AN.getColumnName(), AN.getTypeString(), true, AN.getAlias(), "" }); variantFormatModel .addRow(new Object[] { BQ.getColumnName(), BQ.getTypeString(), true, BQ.getAlias(), "" }); variantFormatModel.addRow( new Object[] { CIGAR.getColumnName(), CIGAR.getTypeString(), true, CIGAR.getAlias(), "" }); variantFormatModel .addRow(new Object[] { DB.getColumnName(), DB.getTypeString(), true, DB.getAlias(), "" }); variantFormatModel .addRow(new Object[] { DP.getColumnName(), DP.getTypeString(), true, DP.getAlias(), "" }); //variantFormatModel.addRow(new Object[]{END.getColumnName(), END.getTypeString(), true, END.getAlias(), ""}); variantFormatModel .addRow(new Object[] { H2.getColumnName(), H2.getTypeString(), true, H2.getAlias(), "" }); variantFormatModel .addRow(new Object[] { MQ.getColumnName(), MQ.getTypeString(), true, MQ.getAlias(), "" }); variantFormatModel .addRow(new Object[] { MQ0.getColumnName(), MQ0.getTypeString(), true, MQ0.getAlias(), "" }); variantFormatModel .addRow(new Object[] { NS.getColumnName(), NS.getTypeString(), true, NS.getAlias(), "" }); variantFormatModel .addRow(new Object[] { SB.getColumnName(), SB.getTypeString(), true, SB.getAlias(), "" }); variantFormatModel.addRow(new Object[] { SOMATIC.getColumnName(), SOMATIC.getTypeString(), true, SOMATIC.getAlias(), "" }); variantFormatModel.addRow(new Object[] { VALIDATED.getColumnName(), VALIDATED.getTypeString(), true, VALIDATED.getAlias(), "" }); variantFormatModel .addRow(new Object[] { JANNOVAR_EFFECT.getColumnName(), JANNOVAR_EFFECT.getTypeString(), JANNOVAR_EFFECT.isFilterable(), JANNOVAR_EFFECT.getAlias(), "" }); variantFormatModel .addRow(new Object[] { JANNOVAR_SYMBOL.getColumnName(), JANNOVAR_SYMBOL.getTypeString(), JANNOVAR_SYMBOL.isFilterable(), JANNOVAR_SYMBOL.getAlias(), "" }); variantFormatModel.addRow(new Object[] { FORMAT.getColumnName(), FORMAT.getTypeString(), FORMAT.isFilterable(), FORMAT.getAlias(), "" }); variantFormatModel.addRow(new Object[] { SAMPLE_INFO.getColumnName(), SAMPLE_INFO.getTypeString(), SAMPLE_INFO.isFilterable(), SAMPLE_INFO.getAlias(), "" }); } table.setModel(variantFormatModel); table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); scrollpane.getViewport().add(table); page.addComponent(scrollpane); table.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { variantFieldsChanged = true; } @Override public void keyPressed(KeyEvent e) { variantFieldsChanged = true; } @Override public void keyReleased(KeyEvent e) { variantFieldsChanged = true; } }); JButton addFieldButton = new JButton("Add Field"); addFieldButton.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { variantFormatModel.addRow(new Object[2]); table.setModel(variantFormatModel); variantFieldsChanged = true; } }); page.addComponent(addFieldButton); JButton removeFieldButton = new JButton("Remove Field"); removeFieldButton.setEnabled(false); removeFieldButton.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { int row = table.getSelectedRow(); if (row >= 0) { variantFormatModel.removeRow(row); table.setModel(variantFormatModel); variantFieldsChanged = true; } } }); table.getSelectionModel().addListSelectionListener(new RemovalEnabler(0, removeFieldButton)); page.addComponent(removeFieldButton); return page; }