List of usage examples for java.awt.event MouseListener MouseListener
MouseListener
From source file:com.devoteam.srit.xmlloader.core.report.derived.DerivedCounter.java
public void addMouseListenerForGraph(JPanel panel) { if (/*this instanceof StatAverage || this instanceof StatFlow*/ true) { panel.addMouseListener(new MouseListener() { java.awt.Color lastColor; public void mouseClicked(MouseEvent e) { }/*from w w w .j a va 2 s . co m*/ public void mousePressed(MouseEvent e) { JFrameRTStats.instance().getJPanelBottom().removeAll(); JPanel longpanel = generateLongRTStats(); longpanel.setAlignmentX(java.awt.Component.LEFT_ALIGNMENT); longpanel.setAlignmentY(java.awt.Component.TOP_ALIGNMENT); JFrameRTStats.instance().getJPanelBottom().add(longpanel); // We add graphics to jPanelBottom JFrameRTStats.instance().getJPanelBottom().add(getChartPanel()); // We save the StatKey selected ModelTreeRTStats.instance().setStatSelected(id); // We update the panel for display the graph JFrameRTStats.instance().updatePanel(); } public void mouseReleased(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); } public void mouseEntered(MouseEvent e) { lastColor = e.getComponent().getBackground(); e.getComponent().setBackground(ModelTreeRTStats.instance().getColorByString("selectForGraph")); } public void mouseExited(MouseEvent e) { e.getComponent().setBackground(lastColor); } }); } }
From source file:org.languagetool.gui.LanguageToolSupport.java
private void init() { try {//from ww w .j a v a 2 s .c om config = new Configuration(new File(System.getProperty("user.home")), CONFIG_FILE, null); } catch (IOException ex) { throw new RuntimeException("Could not load configuration", ex); } Language defaultLanguage = config.getLanguage(); if (defaultLanguage == null) { defaultLanguage = Languages.getLanguageForLocale(Locale.getDefault()); } /** * Warm-up: we have a lot of lazy init in LT, which causes the first check to * be very slow (several seconds) for languages with a lot of data and a lot of * rules. We just assume that the default language is the language that the user * often uses and init the LT object for that now, not just when it's first used. * This makes the first check feel much faster: */ reloadLanguageTool(defaultLanguage); checkExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setDaemon(true); t.setPriority(Thread.MIN_PRIORITY); t.setName(t.getName() + "-lt-background"); return t; } }); check = new AtomicInteger(0); this.textComponent.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { mustDetectLanguage = config.getAutoDetect(); recalculateSpans(e.getOffset(), e.getLength(), false); if (backgroundCheckEnabled) { checkDelayed(null); } } @Override public void removeUpdate(DocumentEvent e) { mustDetectLanguage = config.getAutoDetect(); recalculateSpans(e.getOffset(), e.getLength(), true); if (backgroundCheckEnabled) { checkDelayed(null); } } @Override public void changedUpdate(DocumentEvent e) { mustDetectLanguage = config.getAutoDetect(); if (backgroundCheckEnabled) { checkDelayed(null); } } }); mouseListener = new MouseListener() { @Override public void mouseClicked(MouseEvent me) { } @Override public void mousePressed(MouseEvent me) { if (me.isPopupTrigger()) { showPopup(me); } } @Override public void mouseReleased(MouseEvent me) { if (me.isPopupTrigger()) { showPopup(me); } } @Override public void mouseEntered(MouseEvent me) { } @Override public void mouseExited(MouseEvent me) { } }; this.textComponent.addMouseListener(mouseListener); actionListener = e -> _actionPerformed(e); mustDetectLanguage = config.getAutoDetect(); if (!this.textComponent.getText().isEmpty() && backgroundCheckEnabled) { checkImmediately(null); } }
From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultTreeView.java
@Override public void refreshView(final ViewState state) { Rectangle visibleRect = null; if (this.tree != null) { visibleRect = this.tree.getVisibleRect(); }/*from w w w.j av a 2s . c om*/ this.removeAll(); this.actionsMenu = this.createPopupMenu(state); DefaultMutableTreeNode root = new DefaultMutableTreeNode("WORKFLOWS"); for (ModelGraph graph : state.getGraphs()) { root.add(this.buildTree(graph, state)); } tree = new JTree(root); tree.setShowsRootHandles(true); tree.setRootVisible(false); tree.add(this.actionsMenu); if (state.getSelected() != null) { // System.out.println("SELECTED: " + state.getSelected()); TreePath treePath = this.getTreePath(root, state.getSelected()); if (state.getCurrentMetGroup() != null) { treePath = this.getTreePath(treePath, state); } else if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_STATIC_METADATA))) { DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); for (int i = 0; i < baseNode.getChildCount(); i++) { if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject() .equals("static-metadata")) { treePath = new TreePath(((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath()); break; } } } else if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_PRECONDITIONS))) { if (treePath == null) { treePath = this.getTreePath(root, state.getSelected().getPreConditions()); } DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); for (int i = 0; i < baseNode.getChildCount(); i++) { if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject() .equals("pre-conditions")) { treePath = new TreePath(((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath()); break; } } } else if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_POSTCONDITIONS))) { if (treePath == null) { treePath = this.getTreePath(root, state.getSelected().getPostConditions()); } DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); for (int i = 0; i < baseNode.getChildCount(); i++) { if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject() .equals("post-conditions")) { treePath = new TreePath(((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath()); break; } } } this.tree.expandPath(treePath); this.tree.setSelectionPath(treePath); } tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { if (e.getPath().getLastPathComponent() instanceof DefaultMutableTreeNode) { DefaultTreeView.this.resetProperties(state); DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent(); if (node.getUserObject() instanceof ModelGraph) { state.setSelected((ModelGraph) node.getUserObject()); state.setCurrentMetGroup(null); DefaultTreeView.this.notifyListeners(); } else if (node.getUserObject().equals("static-metadata") || node.getUserObject().equals("pre-conditions") || node.getUserObject().equals("post-conditions")) { state.setSelected((ModelGraph) ((DefaultMutableTreeNode) node.getParent()).getUserObject()); state.setCurrentMetGroup(null); state.setProperty(EXPAND_STATIC_METADATA, Boolean.toString(node.getUserObject().equals("static-metadata"))); state.setProperty(EXPAND_PRECONDITIONS, Boolean.toString(node.getUserObject().equals("pre-conditions"))); state.setProperty(EXPAND_POSTCONDITIONS, Boolean.toString(node.getUserObject().equals("post-conditions"))); DefaultTreeView.this.notifyListeners(); } else if (node.getUserObject() instanceof ConcurrentHashMap) { DefaultMutableTreeNode metNode = null; String group = null; Object[] path = e.getPath().getPath(); for (int i = path.length - 1; i >= 0; i--) { if (((DefaultMutableTreeNode) path[i]).getUserObject() instanceof ModelGraph) { metNode = (DefaultMutableTreeNode) path[i]; break; } else if (((DefaultMutableTreeNode) path[i]) .getUserObject() instanceof ConcurrentHashMap) { if (group == null) { group = (String) ((ConcurrentHashMap<String, String>) ((DefaultMutableTreeNode) path[i]) .getUserObject()).keySet().iterator().next(); } else { group = (String) ((ConcurrentHashMap<String, String>) ((DefaultMutableTreeNode) path[i]) .getUserObject()).keySet().iterator().next() + "/" + group; } } } ModelGraph graph = (ModelGraph) metNode.getUserObject(); state.setSelected(graph); state.setCurrentMetGroup(group); DefaultTreeView.this.notifyListeners(); } else { state.setSelected(null); DefaultTreeView.this.notifyListeners(); } } } }); tree.setCellRenderer(new TreeCellRenderer() { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; if (node.getUserObject() instanceof String) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JLabel label = new JLabel((String) node.getUserObject()); label.setForeground(Color.blue); panel.add(label, BorderLayout.CENTER); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else if (node.getUserObject() instanceof ModelGraph) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JLabel iconLabel = new JLabel( ((ModelGraph) node.getUserObject()).getModel().getExecutionType() + ": "); iconLabel.setForeground(((ModelGraph) node.getUserObject()).getModel().getColor()); iconLabel.setBackground(Color.white); JLabel idLabel = new JLabel(((ModelGraph) node.getUserObject()).getModel().getModelName()); idLabel.setBackground(Color.white); panel.add(iconLabel, BorderLayout.WEST); panel.add(idLabel, BorderLayout.CENTER); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else if (node.getUserObject() instanceof ConcurrentHashMap) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); String group = (String) ((ConcurrentHashMap<String, String>) node.getUserObject()).keySet() .iterator().next(); JLabel nameLabel = new JLabel(group + " : "); nameLabel.setForeground(Color.blue); nameLabel.setBackground(Color.white); JLabel valueLabel = new JLabel( ((ConcurrentHashMap<String, String>) node.getUserObject()).get(group)); valueLabel.setForeground(Color.darkGray); valueLabel.setBackground(Color.white); panel.add(nameLabel, BorderLayout.WEST); panel.add(valueLabel, BorderLayout.EAST); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else { return new JLabel(); } } }); tree.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3 && DefaultTreeView.this.tree.getSelectionPath() != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) DefaultTreeView.this.tree .getSelectionPath().getLastPathComponent(); if (node.getUserObject() instanceof String && !(node.getUserObject().equals("pre-conditions") || node.getUserObject().equals("post-conditions"))) { return; } orderSubMenu.setEnabled(node.getUserObject() instanceof ModelGraph && !((ModelGraph) node.getUserObject()).isCondition() && ((ModelGraph) node.getUserObject()).getParent() != null); DefaultTreeView.this.actionsMenu.show(DefaultTreeView.this.tree, e.getX(), e.getY()); } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); this.scrollPane = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); this.add(this.scrollPane, BorderLayout.CENTER); if (visibleRect != null) { this.tree.scrollRectToVisible(visibleRect); } this.revalidate(); }
From source file:org.richie.codeGen.ui.configui.ConstantConfigWin.java
private void addTableListener() { table.addMouseListener(new MouseListener() { @Override//ww w . java2s. c o m public void mouseReleased(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseClicked(MouseEvent e) { int col = table.getSelectedColumn(); int row = table.getSelectedRow(); if (col == 4) { constantConfigModel.removeRow(row); table.updateUI(); } } }); }
From source file:com.jsystem.j2autoit.AutoItAgent.java
private static void createAndShowGUI() { //Check the SystemTray support if (!SystemTray.isSupported()) { Log.error("SystemTray is not supported\n"); return;/*from ww w . j a v a 2 s . c o m*/ } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("images/jsystem_ico.gif", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); // Create a popup menu components final MenuItem aboutItem = new MenuItem("About"); final MenuItem startAgentItem = new MenuItem("Start J2AutoIt Agent"); final MenuItem stopAgentItem = new MenuItem("Stop J2AutoIt Agent"); final MenuItem exitItem = new MenuItem("Exit"); final MenuItem changePortItem = new MenuItem("Setting J2AutoIt Port"); final MenuItem deleteTemporaryFilesItem = new MenuItem("Delete J2AutoIt Script"); final MenuItem temporaryHistoryFilesItem = new MenuItem("History Size"); final MenuItem displayLogFile = new MenuItem("Log"); final MenuItem forceShutDownTimeOutItem = new MenuItem("Force ShutDown TimeOut"); final MenuItem writeConfigurationToFile = new MenuItem("Save Configuration To File"); final CheckboxMenuItem debugModeItem = new CheckboxMenuItem("Debug Mode", isDebug); final CheckboxMenuItem forceAutoItShutDownItem = new CheckboxMenuItem("Force AutoIt Script ShutDown", isForceAutoItShutDown); final CheckboxMenuItem autoDeleteHistoryItem = new CheckboxMenuItem("Auto Delete History", isAutoDeleteFiles); final CheckboxMenuItem useAutoScreenShot = new CheckboxMenuItem("Auto Screenshot", isUseScreenShot); //Add components to popup menu popup.add(aboutItem); popup.add(writeConfigurationToFile); popup.addSeparator(); popup.add(forceAutoItShutDownItem); popup.add(forceShutDownTimeOutItem); popup.addSeparator(); popup.add(debugModeItem); popup.add(displayLogFile); popup.add(useAutoScreenShot); popup.addSeparator(); popup.add(autoDeleteHistoryItem); popup.add(deleteTemporaryFilesItem); popup.add(temporaryHistoryFilesItem); popup.addSeparator(); popup.add(changePortItem); popup.addSeparator(); popup.add(startAgentItem); popup.add(stopAgentItem); popup.addSeparator(); popup.add(exitItem); trayIcon.setToolTip("J2AutoIt Agent"); trayIcon.setImageAutoSize(true); trayIcon.setPopupMenu(popup); final DisplayLogFile displayLog = new DisplayLogFile(); try { tray.add(trayIcon); } catch (AWTException e) { Log.error("TrayIcon could not be added.\n"); return; } trayIcon.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { startAgentItem.setEnabled(!serverState); stopAgentItem.setEnabled(serverState); deleteTemporaryFilesItem.setEnabled(isDebug && HistoryFile.containEntries()); autoDeleteHistoryItem.setEnabled(isDebug); temporaryHistoryFilesItem.setEnabled(isDebug && isAutoDeleteFiles); displayLogFile.setEnabled(isDebug); forceShutDownTimeOutItem.setEnabled(isForceAutoItShutDown); } @Override public void mouseReleased(MouseEvent e) { } }); writeConfigurationToFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { AutoItProperties.DEBUG_MODE_KEY.setValue(isDebug.toString()); AutoItProperties.AUTO_DELETE_TEMPORARY_SCRIPT_FILE_KEY.setValue(isAutoDeleteFiles.toString()); AutoItProperties.AUTO_IT_SCRIPT_HISTORY_SIZE_KEY.setValue(DEFAULT_HistorySize.toString()); AutoItProperties.FORCE_AUTO_IT_PROCESS_SHUTDOWN_KEY.setValue(isForceAutoItShutDown.toString()); AutoItProperties.AGENT_PORT_KEY.setValue(webServicePort.toString()); AutoItProperties.SERVER_UP_ON_INIT_KEY.setValue(serverState.toString()); if (!AutoItProperties.savePropertiesFileSafely()) { Log.error("Fail to save properties file"); } } }); debugModeItem.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { isDebug = (e.getStateChange() == ItemEvent.SELECTED); deleteTemporaryFilesItem.setEnabled(isDebug && HistoryFile.containEntries()); Log.infoLog("Keeping the temp file is " + (isDebug ? "en" : "dis") + "able\n"); trayIcon.displayMessage((isDebug ? "Debug" : "Normal") + " Mode", "The system will " + (isDebug ? "not " : "") + "delete \nthe temporary autoIt scripts." + (isDebug ? "\nSee log file for more info." : ""), MessageType.INFO); } }); useAutoScreenShot.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { isUseScreenShot = (e.getStateChange() == ItemEvent.SELECTED); Log.infoLog("Auto screenshot is " + (isUseScreenShot ? "" : "in") + "active\n"); } }); forceAutoItShutDownItem.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { isForceAutoItShutDown = (e.getStateChange() == ItemEvent.SELECTED); Log.infoLog((isForceAutoItShutDown ? "Force" : "Soft") + " AutoIt Script ShutDown\n"); trayIcon.displayMessage("AutoIt Script Termination", (isForceAutoItShutDown ? "Hard shutdown" : "Soft shutdown"), MessageType.INFO); } }); autoDeleteHistoryItem.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { isAutoDeleteFiles = (e.getStateChange() == ItemEvent.SELECTED); Log.infoLog((isAutoDeleteFiles ? "Auto" : "Manual") + " AutoIt Script Deletion\n"); trayIcon.displayMessage("AutoIt Script Deletion", (isAutoDeleteFiles ? "Auto" : "Manual") + " Mode", MessageType.INFO); if (isAutoDeleteFiles) { HistoryFile.init(); } else { HistoryFile.close(); } } }); forceShutDownTimeOutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { String timeOutAsString = JOptionPane.showInputDialog( "Please Insert Force ShutDown TimeOut (in seconds)", String.valueOf(shutDownTimeOut / 1000)); try { shutDownTimeOut = 1000 * Long.parseLong(timeOutAsString); } catch (Exception e2) { } Log.infoLog("Setting the force shutdown time out to : " + (shutDownTimeOut / 1000) + " seconds.\n"); } }); displayLogFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { try { displayLog.reBuild(Log.getCurrentLogs()); displayLog.actionPerformed(actionEvent); } catch (Exception e2) { } } }); temporaryHistoryFilesItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { String historySize = JOptionPane.showInputDialog("Please Insert History AutoIt Script Files", String.valueOf(HistoryFile.getHistory_Size())); try { int temp = Integer.parseInt(historySize); if (temp > 0) { if (HistoryFile.getHistory_Size() != temp) { HistoryFile.setHistory_Size(temp); Log.infoLog("The history files size is " + historySize + NEW_LINE); } } else { Log.warning("Illegal History Size: " + historySize + NEW_LINE); } } catch (Exception exception) { Log.throwableLog(exception.getMessage(), exception); } } }); deleteTemporaryFilesItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { HistoryFile.forceDeleteAll(); } }); startAgentItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { runWebServer(); } }); stopAgentItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { shutDownWebServer(); } }); aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { JOptionPane.showMessageDialog(null, "J2AutoIt Agent By JSystem And Aqua Software"); } }); changePortItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { String portAsString = JOptionPane.showInputDialog("Please Insert new Port", String.valueOf(webServicePort)); if (portAsString != null) { try { int temp = Integer.parseInt(portAsString); if (temp > 1000) { if (temp != webServicePort) { webServicePort = temp; shutDownWebServer(); startAutoItWebServer(webServicePort); runWebServer(); } } else { Log.warning("Port number should be greater then 1000\n"); } } catch (Exception exception) { Log.error("Illegal port number\n"); return; } } } }); exitItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { tray.remove(trayIcon); shutDownWebServer(); Log.info("Exiting from J2AutoIt Agent\n"); System.exit(0); } }); }
From source file:GUI.simplePanel.java
public simplePanel() { self = this;/* ww w.j a va 2 s . 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:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java
@Override public void refreshView(final ViewState state) { this.removeAll(); tableMenu = new JPopupMenu("TableMenu"); this.add(tableMenu); override = new JMenuItem(OVERRIDE); override.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition()); String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state); Metadata staticMet = state.getSelected().getModel().getStaticMetadata(); if (staticMet == null) { staticMet = new Metadata(); }//from w w w .j a v a 2 s .c o m if (e.getActionCommand().equals(OVERRIDE)) { if (!staticMet.containsKey(key)) { staticMet.addMetadata(key, (String) DefaultPropView.this.table.getValueAt(row, 2)); String envReplace = (String) DefaultPropView.this.table.getValueAt(row, 3); if (Boolean.valueOf(envReplace)) { staticMet.addMetadata(key + "/envReplace", envReplace); } state.getSelected().getModel().setStaticMetadata(staticMet); DefaultPropView.this.notifyListeners(); } } } }); delete = new JMenuItem(DELETE); delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition()); String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state); Metadata staticMet = state.getSelected().getModel().getStaticMetadata(); if (staticMet == null) { staticMet = new Metadata(); } staticMet.removeMetadata(key); staticMet.removeMetadata(key + "/envReplace"); state.getSelected().getModel().setStaticMetadata(staticMet); DefaultPropView.this.notifyListeners(); } }); tableMenu.add(override); tableMenu.add(delete); if (state.getSelected() != null) { JPanel masterPanel = new JPanel(); masterPanel.setLayout(new BoxLayout(masterPanel, BoxLayout.Y_AXIS)); masterPanel.add(this.getModelIdPanel(state.getSelected(), state)); masterPanel.add(this.getModelNamePanel(state.getSelected(), state)); if (!state.getSelected().getModel().isParentType()) { masterPanel.add(this.getInstanceClassPanel(state.getSelected(), state)); } masterPanel.add(this.getExecutionTypePanel(state.getSelected(), state)); masterPanel.add(this.getPriorityPanel(state)); masterPanel.add(this.getExecusedIds(state.getSelected())); if (state.getSelected().getModel().getExecutionType().equals("condition")) { masterPanel.add(this.getTimeout(state.getSelected(), state)); masterPanel.add(this.getOptional(state.getSelected(), state)); } JScrollPane scrollPane = new JScrollPane(table = this.createTable(state), JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.getHorizontalScrollBar().setUnitIncrement(10); scrollPane.getVerticalScrollBar().setUnitIncrement(10); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setBorder(new EtchedBorder()); final JLabel metLabel = new JLabel("Static Metadata"); metLabel.setAlignmentX(Component.CENTER_ALIGNMENT); final JLabel extendsLabel = new JLabel("<extends>"); extendsLabel.setFont(new Font("Serif", Font.PLAIN, 10)); extendsLabel.setAlignmentX(Component.CENTER_ALIGNMENT); extendsLabel.addMouseListener(new MouseListener() { private JScrollPane availableScroller; private JScrollPane mineScroller; private JList mineList; private JList availableList; private DefaultListModel mineModel; private DefaultListModel availableModel; public void mouseClicked(MouseEvent e) { final JPopupMenu popup = new JPopupMenu(); popup.setLayout(new BorderLayout()); JPanel main = new JPanel(); main.setLayout(new BoxLayout(main, BoxLayout.X_AXIS)); JPanel mine = new JPanel(); mine.setBorder(new EtchedBorder()); mine.setLayout(new BorderLayout()); JLabel mineLabel = new JLabel("Mine"); mineScroller = new JScrollPane(mineList = createJList(mineModel = new DefaultListModel(), state.getSelected().getModel().getExtendsConfig())); mineScroller.setPreferredSize(new Dimension(250, 80)); mine.add(mineLabel, BorderLayout.NORTH); mine.add(mineScroller, BorderLayout.CENTER); JPanel available = new JPanel(); available.setBorder(new EtchedBorder()); available.setLayout(new BorderLayout()); JLabel availableLabel = new JLabel("Available"); Vector<String> availableGroups = new Vector<String>(state.getGlobalConfigGroups().keySet()); availableGroups.removeAll(state.getSelected().getModel().getExtendsConfig()); availableScroller = new JScrollPane(availableList = this .createJList(availableModel = new DefaultListModel(), availableGroups)); availableScroller.setPreferredSize(new Dimension(250, 80)); available.add(availableLabel, BorderLayout.NORTH); available.add(availableScroller, BorderLayout.CENTER); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.Y_AXIS)); JButton addButton = new JButton("<---"); addButton.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { String selected = availableList.getSelectedValue().toString(); Vector<String> extendsConfig = new Vector<String>( state.getSelected().getModel().getExtendsConfig()); extendsConfig.add(selected); state.getSelected().getModel().setExtendsConfig(extendsConfig); availableModel.remove(availableList.getSelectedIndex()); mineModel.addElement(selected); popup.revalidate(); DefaultPropView.this.notifyListeners(); } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); JButton removeButton = new JButton("--->"); removeButton.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { String selected = mineList.getSelectedValue().toString(); Vector<String> extendsConfig = new Vector<String>( state.getSelected().getModel().getExtendsConfig()); extendsConfig.remove(selected); state.getSelected().getModel().setExtendsConfig(extendsConfig); mineModel.remove(mineList.getSelectedIndex()); availableModel.addElement(selected); popup.revalidate(); DefaultPropView.this.notifyListeners(); } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); buttons.add(addButton); buttons.add(removeButton); main.add(mine); main.add(buttons); main.add(available); popup.add(main, BorderLayout.CENTER); popup.show(extendsLabel, e.getX(), e.getY()); } public void mouseEntered(MouseEvent e) { extendsLabel.setForeground(Color.blue); } public void mouseExited(MouseEvent e) { extendsLabel.setForeground(Color.black); } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } private JList createJList(DefaultListModel model, final List<String> list) { for (String value : list) { model.addElement(value); } JList jList = new JList(model); jList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); jList.setLayoutOrientation(JList.VERTICAL); return jList; } }); JLabel metGroupLabel = new JLabel("(Sub-Group: " + (state.getCurrentMetGroup() != null ? state.getCurrentMetGroup() : "<base>") + ")"); metGroupLabel.setAlignmentX(Component.CENTER_ALIGNMENT); JPanel labelPanel = new JPanel(); labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS)); JPanel top = new JPanel(); top.setLayout(new BoxLayout(top, BoxLayout.Y_AXIS)); top.add(extendsLabel); top.add(metLabel); labelPanel.add(top); labelPanel.add(metGroupLabel); panel.add(labelPanel, BorderLayout.NORTH); panel.add(scrollPane, BorderLayout.CENTER); masterPanel.add(panel); this.add(masterPanel); } else { this.add(new JPanel()); } this.revalidate(); }
From source file:Display.java
@SuppressWarnings("unchecked") Display() {/* www . j a v a2 s . c om*/ super(Reference.NAME); cardLayout = new CardLayout(); panel.setLayout(cardLayout); final int java7Update = Utils.Validators.java7Update.check(); final int java8Update = Utils.Validators.java8Update.check(); try { URL host = new URL(Reference.PROTOCOL, Reference.SOURCE_HOST, Reference.PORT, Reference.JSON_ARRAY); JSONParser parser = new JSONParser(); Object json = parser.parse(new URLReader(host)); final JSONArray array = (JSONArray) json; JSONObject nameObject1 = (JSONObject) array.get(0); XPackInstaller.selected_url = nameObject1.get("url").toString(); XPackInstaller.javaVersion = Integer.parseInt(nameObject1.get("version").toString()); XPackInstaller.profile = nameObject1.get("profile").toString(); XPackInstaller.canAcceptOptional = Boolean .parseBoolean(nameObject1.get("canAcceptOptional").toString()); if (!XPackInstaller.canAcceptOptional) { checkOptifine.setEnabled(false); checkOptifine.setSelected(false); zainstalujMoCreaturesCheckBox.setEnabled(false); zainstalujMoCreaturesCheckBox.setSelected(false); optionalText.setEnabled(false); } else { checkOptifine.setEnabled(true); zainstalujMoCreaturesCheckBox.setEnabled(true); optionalText.setEnabled(true); } for (Object anArray : array) { comboBox1.addItem(new JSONObject((JSONObject) anArray).get("name")); } comboBox1.addActionListener(e -> { int i = 0; while (true) { JSONObject nameObject = (JSONObject) array.get(i); String name1 = nameObject.get("name").toString(); if (name1 == comboBox1.getSelectedItem()) { XPackInstaller.canAcceptOptional = Boolean .parseBoolean(nameObject.get("canAcceptOptional").toString()); XPackInstaller.selected_url = nameObject.get("url").toString(); XPackInstaller.javaVersion = Integer.parseInt(nameObject.get("version").toString()); XPackInstaller.profile = nameObject.get("profile").toString(); if (!XPackInstaller.canAcceptOptional) { checkOptifine.setEnabled(false); checkOptifine.setSelected(false); zainstalujMoCreaturesCheckBox.setEnabled(false); zainstalujMoCreaturesCheckBox.setSelected(false); optionalText.setEnabled(false); } else { checkOptifine.setEnabled(true); zainstalujMoCreaturesCheckBox.setEnabled(true); optionalText.setEnabled(true); } break; } i++; } int javaStatus; if (XPackInstaller.javaVersion == 8) { javaStatus = java8Update; } else { javaStatus = java7Update; } if (javaStatus == 0) { javaversion.setText("TAK"); javaversion.setForeground(Reference.COLOR_DARK_GREEN); } else if (javaStatus == 1) { javaversion.setText("NIE"); javaversion.setForeground(Reference.COLOR_DARK_ORANGE); } else if (javaStatus == 2) { if (XPackInstaller.javaVersion == 8) { javaversion.setText("Nie posiadasz JRE8 w wersji 25 lub nowszej!"); } else { javaversion.setText("Nie posiadasz najnowszej wersji JRE7!"); } javaversion.setForeground(Color.RED); } if (osarch.getText().equals("TAK") && Ram.getText().equals("TAK") && javaarch.getText().equals("TAK") && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) { XPackInstaller.canGoForward = true; button2.setText("Dalej"); } else { XPackInstaller.canGoForward = false; button2.setText("Anuluj"); } }); } catch (FileNotFoundException | ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(panel, "Brak poczenia z Internetem!", "Bd", JOptionPane.ERROR_MESSAGE); System.exit(0); } pobierzOryginalnyLauncherMCCheckBox.addActionListener(e -> { if (pobierzOryginalnyLauncherMCCheckBox.isSelected()) { PathLauncherLabel.setEnabled(true); textField1.setEnabled(true); button3.setEnabled(true); XPackInstaller.installLauncher = true; labelLauncher.setEnabled(true); progressBar3.setEnabled(true); } else { PathLauncherLabel.setEnabled(false); textField1.setEnabled(false); button3.setEnabled(false); XPackInstaller.installLauncher = false; labelLauncher.setEnabled(false); progressBar3.setEnabled(false); } }); button3.addActionListener(e -> { JFileChooser chooser = new JFileChooser(System.getProperty("user.home")); chooser.setApproveButtonText("Wybierz"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setDialogTitle("Wybierz ciek"); int returnValue = chooser.showOpenDialog(getContentPane()); if (returnValue == JFileChooser.APPROVE_OPTION) { try { XPackInstaller.launcher_path = chooser.getSelectedFile().getCanonicalPath(); } catch (IOException x) { x.printStackTrace(); } textField1.setText(XPackInstaller.launcher_path); } }); slider1.setMaximum(Utils.Utils.humanReadableRAM() - 2); slider1.addChangeListener(e -> XPackInstaller.allocatedRAM = slider1.getValue()); button1.addActionListener(e -> { if (pobierzOryginalnyLauncherMCCheckBox.isSelected()) { File launcher = new File(XPackInstaller.launcher_path + File.separator + "Minecraft.exe"); if (textField1.getText().equals("")) { JOptionPane.showMessageDialog(panel, "Nie wybrae cieki instalacji Launcher'a!", "Bd", JOptionPane.ERROR_MESSAGE); } else if (launcher.exists()) { JOptionPane.showMessageDialog(panel, "W podanym katalogu istanieje ju plik o nazwie 'Minecraft.exe'!", "Bad", JOptionPane.ERROR_MESSAGE); } else { cardLayout.next(panel); } } else { cardLayout.next(panel); if (osarch.getText().equals("NIE") && Ram.getText().equals("TAK") && javaarch.getText().equals("NIE") && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) { XPackInstaller.canGoForward = false; button2.setText("Anuluj"); JOptionPane.showMessageDialog(gui, "Prosimy sprawdzi\u0107 czy na komputerze nie ma zainstalowanych dw\u00f3ch \u015brodowisk Java: w wersji 32-bitowej i 64-bitowej.\nJe\u015bli zainstalowane s\u0105 obie wersje prosimy o odinstalowanie wersji 32-bitowej. To rozwi\u0105\u017ce problem.", "B\u0142\u0105d konfiguracji Javy", JOptionPane.ERROR_MESSAGE); } } }); if (Utils.Validators.systemArchitecture.check()) { osarch.setText("TAK"); osarch.setForeground(Reference.COLOR_DARK_GREEN); } else { osarch.setText("NIE"); osarch.setForeground(Color.RED); } if (Utils.Validators.ramAmount.check()) { Ram.setText("TAK"); Ram.setForeground(Reference.COLOR_DARK_GREEN); } else { Ram.setText("NIE"); Ram.setForeground(Color.RED); } if (Utils.Validators.javaArchitecture.check()) { javaarch.setText("TAK"); javaarch.setForeground(Reference.COLOR_DARK_GREEN); } else { javaarch.setText("NIE"); javaarch.setForeground(Color.RED); } int javaStatus; if (XPackInstaller.javaVersion == 8) { javaStatus = java8Update; } else { javaStatus = java7Update; } if (javaStatus == 0) { javaversion.setText("TAK"); javaversion.setForeground(Reference.COLOR_DARK_GREEN); } else if (javaStatus == 1) { javaversion.setText("NIE"); javaversion.setForeground(Reference.COLOR_DARK_ORANGE); } else if (javaStatus == 2) { javaversion.setText("Nie posiadasz najnowszej wersji JRE!"); javaversion.setForeground(Color.RED); } if (osarch.getText().equals("TAK") && Ram.getText().equals("TAK") && javaarch.getText().equals("TAK") && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) { XPackInstaller.canGoForward = true; button2.setText("Dalej"); } else { XPackInstaller.canGoForward = false; button2.setText("Anuluj"); } button2.addActionListener(e -> { if (XPackInstaller.canGoForward) { cardLayout.next(panel); } else { System.exit(1); } }); wsteczButton.addActionListener(e -> cardLayout.previous(panel)); try { editorPane1.setPage("http://xpack.pl/licencja.html"); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(panel, "Brak poczenia z Internetem!", "Bd", JOptionPane.ERROR_MESSAGE); System.exit(0); } licenseC.addActionListener(e -> { if (licenseC.isSelected()) { dalejButton.setEnabled(true); } else { dalejButton.setEnabled(false); } }); try { File mainDir = new File(System.getenv("appdata") + File.separator + "XPackInstaller"); if (mainDir.exists()) { FileUtils.deleteDirectory(mainDir); if (!mainDir.mkdir()) { JOptionPane.showMessageDialog(gui, "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd", JOptionPane.ERROR_MESSAGE); System.out.println("Nie udao si utworzy katalogu!"); System.exit(1); } } else { if (!mainDir.mkdir()) { JOptionPane.showMessageDialog(gui, "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd", JOptionPane.ERROR_MESSAGE); System.out.println("Nie udao si utworzy katalogu!"); System.exit(1); } } File optionalDir = new File(mainDir.getAbsolutePath() + File.separator + "OptionalMods"); if (!optionalDir.mkdir()) { JOptionPane.showMessageDialog(gui, "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd", JOptionPane.ERROR_MESSAGE); System.out.println("Nie udao si utworzy katalogu!"); System.exit(1); } dalejButton.addActionListener(e -> { cardLayout.next(panel); try { progressBar1.setValue(0); if (checkOptifine.isSelected() && zainstalujMoCreaturesCheckBox.isSelected()) { DownloadTask task2 = new DownloadTask(gui, "mod", Reference.downloadOptifine, optionalDir.getAbsolutePath()); task2.addPropertyChangeListener(evt -> { if (evt.getPropertyName().equals("progress")) { labelmodpack.setText("Pobieranie Optifine HD w toku..."); if (task2.isDone()) { task3(); } optifineProgress = (Integer) evt.getNewValue(); progressBar1.setValue(optifineProgress); } }); task2.execute(); } else if (checkOptifine.isSelected()) { DownloadTask task2 = new DownloadTask(gui, "mod", Reference.downloadOptifine, optionalDir.getAbsolutePath()); task2.addPropertyChangeListener(evt -> { if (evt.getPropertyName().equals("progress")) { labelmodpack.setText("Pobieranie Optifine HD w toku..."); if (task2.isDone()) { task(); } optifineProgress = (Integer) evt.getNewValue(); progressBar1.setValue(optifineProgress); } }); task2.execute(); } else if (zainstalujMoCreaturesCheckBox.isSelected()) { task3(); } else { task(); } } catch (Exception exx) { exx.printStackTrace(); } }); } catch (IOException e) { e.printStackTrace(); } final JScrollBar bar = scrollPane1.getVerticalScrollBar(); bar.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } }); bar.addMouseWheelListener(e -> { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } }); scrollPane1.setWheelScrollingEnabled(true); scrollPane1.addMouseWheelListener(e -> { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } }); panel.add(panel3); panel.add(panel1); panel.add(panel2); panel.add(panel4); add(panel); }
From source file:gov.noaa.ncdc.iosp.avhrr.util.AvhrrLevel1B2Netcdf.java
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor.// w w w . ja v a 2s . c o m */ // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { // Create a file chooser this.setTitle("NCDC sat2netcdf converter"); aboutDialog = new javax.swing.JDialog(); aboutButton = new javax.swing.JButton(); aboutLabel = new javax.swing.JLabel(); aboutDialog.setTitle("About"); aboutDialog.setName("aboutDialog"); // NOI18N aboutDialog.setSize(250, 200); aboutButton.setText("OK"); aboutButton.setName("aboutButton"); // NOI18N aboutButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDialog.hide(); } }); aboutLabel.setText( "<html>\nNCDC sat2netcdf Converter<br> </br>\nCopyright (c) 2008 Work of U.S. Government.<br></br>\nNCDC<br></br>\nContact: ncdc.satorder@noaa.gov\n</html>"); fc = new JFileChooser(); fc.setMultiSelectionEnabled(true); // output directory file chooser outFc = new JFileChooser(); outFc.setMultiSelectionEnabled(false); outFc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); activityMonitor = new Timer(100, new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { convertMonitorActionPerformed(evt); } }); menuBar = new JMenuBar(); logMenu = new JMenu("Log"); logMenuItem = new JMenuItem("View Log"); logMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { logDialog.show(); } }); logMenu.add(logMenuItem); menuBar.add(logMenu); helpMenu = new JMenu("Help"); menuBar.add(helpMenu); helpMenuItem = new JMenuItem("Help"); helpMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { helpMenuActionPerformed(evt); } }); helpMenu.add(helpMenuItem); aboutMenuItem = new JMenuItem("About"); aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { aboutDialog.show(); } }); helpMenu.add(aboutMenuItem); this.setJMenuBar(menuBar); jButton4 = new javax.swing.JButton(); openButton = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jLabel1 = new javax.swing.JLabel(); outdirButton = new javax.swing.JButton(); outdirText = new javax.swing.JTextField(); jPanel1 = new javax.swing.JPanel(); allChanCheckBox = new javax.swing.JCheckBox(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); chan1CheckBox = new javax.swing.JCheckBox(); chan2CheckBox = new javax.swing.JCheckBox(); chan3CheckBox = new javax.swing.JCheckBox(); chan4CheckBox = new javax.swing.JCheckBox(); chan5CheckBox = new javax.swing.JCheckBox(); rawCheckBox = new javax.swing.JCheckBox(); radCheckBox = new javax.swing.JCheckBox(); tempCheckBox = new javax.swing.JCheckBox(); allVarCheckBox = new javax.swing.JCheckBox(); qualityCheckBox = new javax.swing.JCheckBox(); calCheckBox = new javax.swing.JCheckBox(); latlonCheckBox = new javax.swing.JCheckBox(); metaCheckBox = new javax.swing.JCheckBox(); jLabel2 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); convertButton = new javax.swing.JButton(); exitButton = new javax.swing.JButton(); jButton4.setText("jButton4"); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); openButton.setText("Select Files"); openButton.setName("selectButton"); // NOI18N openButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { openButtonActionPerformed(evt); } }); fm = new FileModel(); jTable1 = new JTable(fm); jTable1.setName("table"); // NOI18N jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); setTableCellRenderer(jTable1, new ToolCellRenderer()); // remove popup for table removeItem = new JMenuItem("Remove"); removeItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { int[] selected = jTable1.getSelectedRows(); for (int i : selected) { logTextArea.append("Removed File: " + fm.getFileAtRow(i).getName() + "\n"); } fm.removeRows(selected); } }); popup = new JPopupMenu(); popup.add(removeItem); // Add listener to the jtable so the popup menu can come up. // MouseListener popupListener = new PopupListener(jTable1); // jTable1.addMouseListener(popupListener); jTable1.addMouseListener(new MouseListener() { public void mousePressed(MouseEvent e) { int button = e.getButton(); int[] selected = jTable1.getSelectedRows(); if (button != 1 && selected.length > 0) { popup.show(e.getComponent(), e.getX(), e.getY()); } } public void mouseClicked(MouseEvent e) { int button = e.getButton(); int column = jTable1.getSelectedColumn(); if (0 == column && 1 == button) { updateOutputSize(); } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); TableColumn col = jTable1.getColumnModel().getColumn(1); col.setPreferredWidth(250); col = jTable1.getColumnModel().getColumn(3); col.setPreferredWidth(100); jScrollPane1.setViewportView(jTable1); jLabel1.setText("Select output directory"); outdirButton.setText("Browse"); outdirButton.setName("outdirButton"); // NOI18N outdirButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { outdirButtonActionPerformed(evt); } }); outdirText.setName("outdirText"); // NOI18N try { outdirText.setText(new File(".").getCanonicalPath()); } catch (IOException ioe) { ioe.printStackTrace(); } jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); jPanel1.setName("optionPanel"); // NOI18N allChanCheckBox.setText("All Channels"); allChanCheckBox.setSelected(true); allChanCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleChannelBoxes("jCheckBox1", allChanCheckBox); updateFileSize(); } }); jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel3.setText("Channels"); jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel4.setText("Calibration"); jLabel4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel5.setText("Additional Data"); jLabel5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); chan1CheckBox.setText("Channel 1"); chan1CheckBox.setSelected(true); chan1CheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleChannelBoxes("chan1CheckBox", chan1CheckBox); updateFileSize(); } }); chan2CheckBox.setText("Channel 2"); chan2CheckBox.setSelected(true); chan2CheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleChannelBoxes("chan2CheckBox", chan2CheckBox); updateFileSize(); } }); chan3CheckBox.setText("Channel 3A/B"); chan3CheckBox.setSelected(true); chan3CheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleChannelBoxes("chan3CheckBox", chan3CheckBox); updateFileSize(); } }); chan4CheckBox.setLabel("Channel 4"); chan4CheckBox.setSelected(true); chan4CheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleChannelBoxes("chan4CheckBox", chan4CheckBox); updateFileSize(); } }); chan5CheckBox.setLabel("Channel 5"); chan5CheckBox.setSelected(true); chan5CheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleChannelBoxes("chan5CheckBox", chan5CheckBox); updateFileSize(); } }); rawCheckBox.setText("Raw Data"); rawCheckBox.setSelected(true); rawCheckBox.setToolTipText("Counts for each pixel"); rawCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleCalibrationCheckBoxes(rawCheckBox); updateFileSize(); } }); radCheckBox.setText("Radiance"); radCheckBox.setToolTipText("Radiance Values"); radCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleCalibrationCheckBoxes(radCheckBox); updateFileSize(); } }); tempCheckBox.setText("Brightness Temperature"); tempCheckBox.setToolTipText("Albedo for visible channels, Brightness Temperature for IR channels"); tempCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleCalibrationCheckBoxes(tempCheckBox); updateFileSize(); } }); allVarCheckBox.setText("All Variables"); allVarCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleAllVariablesCheckBox(); updateFileSize(); } }); qualityCheckBox.setText("Quality Flags"); qualityCheckBox.setToolTipText("Quality Variables"); qualityCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleOtherCheckbox(qualityCheckBox); updateFileSize(); } }); calCheckBox.setText("Calibration Coefficients"); calCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleOtherCheckbox(calCheckBox); updateFileSize(); } }); jLabel2.setText("Select output options"); convertButton.setText("Convert"); convertButton.setName("convertButton"); // NOI18N convertButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { convertButtonActionPerformed(evt); } }); exitButton.setText("Exit"); exitButton.setName("exitButton"); // NOI18N exitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitButtonActionPerformed(evt); } }); // help dialog helpDialog = new javax.swing.JDialog(); helpCloseButton = new javax.swing.JButton("Close"); helpScrollPane = new javax.swing.JScrollPane(); // helpEditorPane = new javax.swing.JEditorPane("text/rtf", helpText); helpEditorPane = new javax.swing.JEditorPane(); helpEditorPane.setContentType("text/html"); InputStream stream = null; try { stream = AvhrrLevel1B2Netcdf.class.getResourceAsStream("/help.html"); if (stream != null) { helpEditorPane.read(stream, "html"); } } catch (IOException e1) { e1.printStackTrace(); } helpScrollPane.setViewportView(helpEditorPane); helpDialog.setSize(450, 500); helpCloseButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { helpDialog.dispose(); } }); // Log Dialog logDialog = new javax.swing.JDialog(); logScrollPane = new javax.swing.JScrollPane(); logTextArea = new javax.swing.JTextArea(); logCloseButton = new javax.swing.JButton(); clearButton = new javax.swing.JButton(); logDialog.setTitle("Log"); logDialog.setName("logDialog"); // NOI18N logDialog.setSize(450, 500); logScrollPane.setName("logScrollPane"); // NOI18N logTextArea.setColumns(20); logTextArea.setRows(5); logTextArea.setName("logTextArea"); // NOI18N logScrollPane.setViewportView(logTextArea); logCloseButton.setText("Close"); logCloseButton.setName("logCloseButton"); // NOI18N logCloseButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { logDialog.hide(); } }); clearButton.setText("Clear"); clearButton.setName("clearButton"); // NOI18N clearButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { logTextArea.setText(""); } }); latlonCheckBox.setText("Lat/Lon"); latlonCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleLatLonCheckbox(); updateFileSize(); } }); metaCheckBox.setText("Other metadata"); metaCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleMetadataCheckbox(); updateFileSize(); } }); jLabel2.setText("Select output options"); convertButton.setText("Convert"); convertButton.setName("convertButton"); exitButton.setText("Exit"); exitButton.setName("exitButton"); exitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitButtonActionPerformed(evt); } }); jLabel2.setText("Select output options"); // NOI18N convertButton.setText("Convert"); // NOI18N convertButton.setName("convertButton"); // NOI18N exitButton.setText("Exit"); // NOI18N exitButton.setName("exitButton"); // NOI18N exitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitButtonActionPerformed(evt); } }); jLabel6.setFont(new java.awt.Font("Dialog", 1, 11)); jLabel6.setText("Estimated output size: "); org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1Layout.createSequentialGroup().addContainerGap().add(jPanel1Layout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(chan5CheckBox) .add(jPanel1Layout.createSequentialGroup().add(jPanel1Layout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1Layout.createSequentialGroup().add(jPanel1Layout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1Layout .createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.LEADING, allChanCheckBox, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .add(chan1CheckBox).add(chan2CheckBox)).add(36, 36, 36) .add(jPanel1Layout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(radCheckBox) .add(tempCheckBox, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE) .add(rawCheckBox).add(jLabel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .add(chan3CheckBox).add(chan4CheckBox)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(metaCheckBox).add(latlonCheckBox).add(allVarCheckBox) .add(jLabel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 113, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(qualityCheckBox).add(calCheckBox)))) .add(67, 67, 67))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1Layout.createSequentialGroup().addContainerGap() .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel3).add(jLabel5).add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(allChanCheckBox).add(allVarCheckBox).add(rawCheckBox)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(chan1CheckBox).add(qualityCheckBox).add(radCheckBox)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(chan2CheckBox).add(calCheckBox).add(tempCheckBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(chan3CheckBox).add(latlonCheckBox)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(chan4CheckBox).add(metaCheckBox)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(chan5CheckBox) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jLabel2.setText("Select output options"); // NOI18N convertButton.setText("Convert"); // NOI18N convertButton.setName("convertButton"); // NOI18N exitButton.setText("Exit"); // NOI18N exitButton.setName("exitButton"); // NOI18N exitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitButtonActionPerformed(evt); } }); jLabel6.setFont(new java.awt.Font("Dialog", 1, 11)); jLabel6.setText("Estimated output size: "); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup().addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 531, Short.MAX_VALUE) .add(layout.createSequentialGroup().add(outdirButton) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(outdirText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 453, Short.MAX_VALUE)) .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 531, Short.MAX_VALUE) .add(openButton) .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 291, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(layout.createSequentialGroup().add(convertButton) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(jLabel6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE)) .add(exitButton).add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 531, Short.MAX_VALUE)) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(layout .createSequentialGroup().addContainerGap().add(openButton) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(jLabel1) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(outdirButton).add( outdirText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 27, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false).add(convertButton) .add(jLabel6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED).add(exitButton).add(12, 12, 12))); // log dialog layout org.jdesktop.layout.GroupLayout logDialogLayout = new org.jdesktop.layout.GroupLayout( logDialog.getContentPane()); logDialog.getContentPane().setLayout(logDialogLayout); logDialogLayout.setHorizontalGroup( logDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add( org.jdesktop.layout.GroupLayout.TRAILING, logDialogLayout.createSequentialGroup().addContainerGap() .add(logDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(org.jdesktop.layout.GroupLayout.LEADING, logScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 520, Short.MAX_VALUE) .add(logDialogLayout.createSequentialGroup().add(clearButton) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(logCloseButton))) .addContainerGap())); logDialogLayout.setVerticalGroup(logDialogLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, logDialogLayout.createSequentialGroup() .addContainerGap() .add(logScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE) .add(18, 18, 18) .add(logDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(logCloseButton).add(clearButton)) .addContainerGap())); // help dialog layout org.jdesktop.layout.GroupLayout helpDialogLayout = new org.jdesktop.layout.GroupLayout( helpDialog.getContentPane()); helpDialog.getContentPane().setLayout(helpDialogLayout); helpDialogLayout.setHorizontalGroup( helpDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add( org.jdesktop.layout.GroupLayout.TRAILING, helpDialogLayout.createSequentialGroup().addContainerGap() .add(helpDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(org.jdesktop.layout.GroupLayout.LEADING, helpScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 520, Short.MAX_VALUE) .add(helpDialogLayout.createSequentialGroup() .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(helpCloseButton))) .addContainerGap())); helpDialogLayout.setVerticalGroup(helpDialogLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, helpDialogLayout.createSequentialGroup() .addContainerGap() .add(helpScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE) .add(18, 18, 18).add(helpDialogLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(helpCloseButton)) .addContainerGap())); // about dialog layout org.jdesktop.layout.GroupLayout aboutDialogLayout = new org.jdesktop.layout.GroupLayout( aboutDialog.getContentPane()); aboutDialog.getContentPane().setLayout(aboutDialogLayout); aboutDialogLayout.setHorizontalGroup( aboutDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add( org.jdesktop.layout.GroupLayout.TRAILING, aboutDialogLayout.createSequentialGroup().addContainerGap() .add(aboutDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(org.jdesktop.layout.GroupLayout.LEADING, aboutLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE) .add(aboutButton)) .addContainerGap())); aboutDialogLayout.setVerticalGroup( aboutDialogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add( org.jdesktop.layout.GroupLayout.TRAILING, aboutDialogLayout.createSequentialGroup().addContainerGap() .add(aboutLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 103, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 35, Short.MAX_VALUE) .add(aboutButton).add(21, 21, 21))); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); pack(); JOptionPane.showMessageDialog(this, "Warning! \nThis program is untested.\nPlease read help file for\nsupported files, limitations and license.\n"); // + "Please view Help for more information."); }
From source file:vn.topmedia.monitor.form.MDIMain.java
public void goToTray() { if (SystemTray.isSupported()) { SystemTray tray = SystemTray.getSystemTray(); normal = Toolkit.getDefaultToolkit().getImage("normal.gif"); MouseListener mouseListener = new MouseListener() { public void mouseClicked(MouseEvent e) { // System.out.println("Tray Icon - Mouse clicked!"); }//from w ww .java2s . co m public void mouseEntered(MouseEvent e) { // System.out.println("Tray Icon - Mouse entered!"); } public void mouseExited(MouseEvent e) { // System.out.println("Tray Icon - Mouse exited!"); } public void mousePressed(MouseEvent e) { // System.out.println("Tray Icon - Mouse pressed!"); showMonitor(0); } public void mouseReleased(MouseEvent e) { // System.out.println("Tray Icon - Mouse released!"); } }; ActionListener exitListener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Exiting..."); mnuItmExit.doClick(); } }; ActionListener showMonitorListener = new ActionListener() { public void actionPerformed(ActionEvent e) { showMonitor(2); } }; popup = new PopupMenu(); //--------------------------- MenuItem showItem; showItem = new MenuItem("Show"); showItem.addActionListener(showMonitorListener); popup.add(showItem); //----------------- popup.addSeparator(); //------------------------ MenuItem defaultItem = new MenuItem("Exit"); defaultItem.addActionListener(exitListener); popup.add(defaultItem); //------------------------ trayIcon = new TrayIcon(normal, "ExMonitor 1.3", popup); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { showMonitor(2); } }; trayIcon.setImageAutoSize(true); trayIcon.addActionListener(actionListener); trayIcon.addMouseListener(mouseListener); try { tray.add(trayIcon); } catch (AWTException e) { System.err.println("TrayIcon could not be added."); } } else { // System Tray is not supported } }