/** * Init JWhiteBoard interface * * @throws Exception */ public void go() throws Exception { if (!noChannel && !useState) channel.connect(groupName); mainFrame = new JFrame(); mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); drawPanel = new DrawPanel(useState); drawPanel.setBackground(backgroundColor); subPanel = new JPanel(); mainFrame.getContentPane().add("Center", drawPanel); clearButton = new JButton("Clean"); clearButton.setFont(defaultFont); clearButton.addActionListener(this); leaveButton = new JButton("Exit"); leaveButton.setFont(defaultFont); leaveButton.addActionListener(this); subPanel.add("South", clearButton); subPanel.add("South", leaveButton); mainFrame.getContentPane().add("South", subPanel); mainFrame.setBackground(backgroundColor); clearButton.setForeground(Color.blue); leaveButton.setForeground(Color.blue); mainFrame.pack(); mainFrame.setLocation(15, 25); mainFrame.setBounds(new Rectangle(250, 250)); if (!noChannel && useState) { channel.connect(groupName, null, stateTimeout); } mainFrame.setVisible(true); }
// Initialize all the GUI components and display the frame private static void initGUI() { // Set up the status bar statusField = new JLabel(); statusField.setText(statusMessages[DISCONNECTED]); statusColor = new JTextField(1); statusColor.setBackground(Color.red); statusColor.setEditable(false); statusBar = new JPanel(new BorderLayout()); statusBar.add(statusColor, BorderLayout.WEST); statusBar.add(statusField, BorderLayout.CENTER); // Set up the options pane JPanel optionsPane = initOptionsPane(); // Set up the chat pane JPanel chatPane = new JPanel(new BorderLayout()); chatText = new JTextArea(10, 20); chatText.setLineWrap(true); chatText.setEditable(false); chatText.setForeground(Color.blue); JScrollPane chatTextPane = new JScrollPane( chatText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); chatLine = new JTextField(); chatLine.setEnabled(false); chatLine.addActionListener( new ActionAdapter() { public void actionPerformed(ActionEvent e) { String s = chatLine.getText(); if (!s.equals("")) { appendToChatBox("OUTGOING: " + s + "\n"); chatLine.selectAll(); // Send the string sendString(s); } } }); chatPane.add(chatLine, BorderLayout.SOUTH); chatPane.add(chatTextPane, BorderLayout.CENTER); chatPane.setPreferredSize(new Dimension(200, 200)); // Set up the main pane JPanel mainPane = new JPanel(new BorderLayout()); mainPane.add(statusBar, BorderLayout.SOUTH); mainPane.add(optionsPane, BorderLayout.WEST); mainPane.add(chatPane, BorderLayout.CENTER); // Set up the main frame mainFrame = new JFrame("Simple TCP Chat"); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setContentPane(mainPane); mainFrame.setSize(mainFrame.getPreferredSize()); mainFrame.setLocation(200, 200); mainFrame.pack(); mainFrame.setVisible(true); }
public static void main(String[] args) { TableModelDemo applet = new TableModelDemo(); JFrame frame = new JFrame(); // EXIT_ON_CLOSE == 3 frame.setDefaultCloseOperation(3); frame.setTitle("TableModelDemo"); frame.getContentPane().add(applet, BorderLayout.CENTER); applet.init(); applet.start(); frame.setSize(500, 220); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation( (d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2); frame.setVisible(true); }
private void showVideo() throws IOException { if (videoFrame == null) { videoFrame = new JFrame("Remote Car Video"); video = new VideoPanel(car.getIp(), car.getCameraPort()); videoFrame.getContentPane().add(video); videoFrame.setResizable(false); videoFrame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.out.println("closing"); super.windowClosed(e); video.disconnect(); btnCamera.setSelected(false); } @Override public void windowOpened(WindowEvent e) { System.out.println("opened"); super.windowOpened(e); try { video.connect(); } catch (MalformedURLException e1) { e1.printStackTrace(); } video.play(); } @Override public void windowActivated(WindowEvent e) { video.play(); } @Override public void windowIconified(WindowEvent e) { video.pause(); } }); } Point location = this.getLocation(); Dimension dim = this.getSize(); videoFrame.setLocation(location.x + dim.width + 2, location.y); videoFrame.setVisible(true); videoFrame.pack(); sendCommand(Command.TOGGLE_CAMERA); }
@Override public void actionPerformed(ActionEvent event) { JFrame frame = new JFrame(); frame.setTitle( "The current best solution for " + optimizationParameters.getProblem().getName()); frame.setSize(400, 300); frame.setLocation(450, 250); Population pop = optimizationParameters.getOptimizer().getPopulation(); frame .getContentPane() .add( optimizationParameters .getProblem() .drawIndividual( pop.getGeneration(), pop.getFunctionCalls(), pop.getBestEAIndividual())); frame.validate(); frame.setVisible(true); }
public Animation() { String[] keys = {"no Animator found"}; if (tryDir(".")) // || tryDir("BLM305") || tryDir("CSE470")) keys = map.keySet().toArray(keys); System.out.println(map.size() + " classes loaded"); menu = new JComboBox(keys); pan.setLayout(new BorderLayout(GAP, GAP - 4)); pan.setBorder(new javax.swing.border.EmptyBorder(GAP, GAP, GAP, GAP)); pan.setBackground(COLOR); last = new JPanel(); last.setPreferredSize(DIM); pan.add(last, "Center"); ref.setFont(NORM); ref.setEditable(false); ref.setColumns(35); ref.setDragEnabled(true); pan.add(ref, "North"); pan.add(bottomPanel(), "South"); pan.setToolTipText("A collective project for BLM320"); menu.setToolTipText("Animator classes"); who.setToolTipText("author()"); ref.setToolTipText("description()"); Closer ear = new Closer(); menu.addActionListener(ear); stop.addActionListener(ear); frm.addWindowListener(ear); if (map.size() > 0) setItem(0); frm.setContentPane(pan); frm.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frm.setLocation(scaled(120), scaled(90)); frm.pack(); // setSize() is called here frm.setVisible(true); start(); }
// If the applet is called as an application public static void main(String[] args) { // Create the frame mainFrame = new JFrame("Uintah User Interface"); // Add a window listener mainFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // instantiate UintahGui uintahGui = new UintahGui(); uintahGui.init(); // Add the stuff to the frame mainFrame.setLocation(20, 50); mainFrame.setContentPane(uintahGui); mainFrame.pack(); mainFrame.setVisible(true); }
// --------------------------------initGUI------------------------------------ public void initGUI() { bDeployed = bOpponentDeployed = false; listAT = new LinkedList(); frame.setJMenuBar(new GameMenuBar(this)); panParty = new PartyPanel(200, 480); panStatus = new JPanel(null); oMap = new Map(600, 350); panChat = new ChatPanel(600, 200); Container contentPane = frame.getContentPane(); panParty.setOpaque(true); panStatus.setOpaque(true); panChat.setOpaque(true); panStatus.setPreferredSize(new Dimension(200, 70)); contentPane.add(panStatus); contentPane.add(panParty); contentPane.add(oMap); contentPane.add(panChat); SpringLayout oLayout = new SpringLayout(); contentPane.setLayout(oLayout); oLayout.putConstraint(SpringLayout.WEST, panParty, 0, SpringLayout.WEST, contentPane); oLayout.putConstraint(SpringLayout.NORTH, panParty, 0, SpringLayout.NORTH, contentPane); oLayout.putConstraint(SpringLayout.WEST, panStatus, 0, SpringLayout.WEST, contentPane); oLayout.putConstraint(SpringLayout.SOUTH, panStatus, 0, SpringLayout.SOUTH, contentPane); oLayout.putConstraint(SpringLayout.EAST, oMap, 0, SpringLayout.EAST, contentPane); oLayout.putConstraint(SpringLayout.NORTH, oMap, 0, SpringLayout.NORTH, contentPane); oLayout.putConstraint(SpringLayout.WEST, panChat, 0, SpringLayout.EAST, panStatus); oLayout.putConstraint(SpringLayout.NORTH, panChat, 0, SpringLayout.SOUTH, oMap); oLayout.putConstraint(SpringLayout.EAST, contentPane, 0, SpringLayout.EAST, panChat); oLayout.putConstraint(SpringLayout.SOUTH, contentPane, 0, SpringLayout.SOUTH, panChat); panChat.validate(); panChat.setVisible(true); Insets oInsets = panStatus.getInsets(); int nX = oInsets.left + 5; int nY = oInsets.top + 5; lblStatus1 = new JLabel("Not Connected..."); lblStatus2 = new JLabel("No Party Formed..."); lblStatus3 = new JLabel(); Dimension oSize = lblStatus1.getPreferredSize(); lblStatus1.setBounds(nX, nY, 180, oSize.height); nY += oSize.height + 7; lblStatus2.setBounds(nX, nY, 180, oSize.height); nY += oSize.height + 7; lblStatus3.setBounds(nX, nY, 180, oSize.height); panStatus.add(lblStatus1); panStatus.add(lblStatus2); panStatus.add(lblStatus3); frame.pack(); frame.setResizable(false); frame.setLocation( ((scrBounds.x + scrBounds.width - frame.getWidth()) / 2), ((scrBounds.y + scrBounds.height - frame.getHeight()) / 2)); oMap.addKeyListener(oMap); oMap.setButtonEvents(this); }
public ODEWizardScalaSci() { editingClassName = "Lorenz"; systemOrder = 3; // the order of ODE system copyTemplateButton = new JButton("1. Copy and Edit Template", new ImageIcon("/scalaLab.jar/yellow-ball.gif")); generateEditingButton = new JButton("2. Generate Java Class", new ImageIcon("./blue-ball.gif")); saveJavaClassButton = new JButton("3. Save Java Class", new ImageIcon("scalaLab.jar/red-ball.gif")); compileJavaClassButton = new JButton("4.a. Java Compile - External Compiler", new ImageIcon("blue-ball.gif")); compileJavaInternalCompilerButton = new JButton("4.b. Java Compile - Internal Compiler", new ImageIcon("blue-ball.gif")); generateScriptCodeButton = new JButton("Generate scalaSci Script", new ImageIcon("red-ball.gif")); ODEWizardFrame = new JFrame("ODE Wizard for scalaSci with Java implementation of. ODEs"); editPanel = new JPanel(); editPanel.setLayout(new GridLayout(1, 2)); paramPanel = new JPanel(new GridLayout(1, 4)); availODEMethods.add("ODErke"); availODEMethods.add("ODEmultistep"); availODEMethods.add("ODEdiffsys"); ODEselectMethodLabel = new JLabel("ODE method: "); ODEselectMethodComboBox = new JComboBox(availODEMethods); ODEselectMethodComboBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ODESolveMethod = ODEselectMethodComboBox.getSelectedIndex(); updateTemplateText(); templateTextArea.setText(templateText); currentlySelectedLabel.setText( "Selected Method: " + (String) availODEMethods.get(ODESolveMethod)); } }); JLabel javaFileTextLabel = new JLabel("Java File Name: "); javaFileTextBox = new JTextField(editingClassName); javaFileTextBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { editingClassName = javaFileTextBox.getText(); String updatedStatusText = prepareStatusText(); statusAreaTop.setText(updatedStatusText); } }); JLabel systemOrderLabel = new JLabel("System order: "); systemOrderText = new JTextField(String.valueOf(systemOrder)); systemOrderText.addActionListener(new editSystemOrder()); JPanel javaFilePanel = new JPanel(); javaFilePanel.add(javaFileTextLabel); javaFilePanel.add(javaFileTextBox); JPanel systemOrderPanel = new JPanel(); systemOrderPanel.add(systemOrderLabel); systemOrderPanel.add(systemOrderText); paramMethodPanel = new JPanel(); paramMethodPanel.add(ODEselectMethodLabel); paramMethodPanel.add(ODEselectMethodComboBox); paramPanel.add(paramMethodPanel); paramPanel.add(javaFilePanel); paramPanel.add(systemOrderPanel); currentlySelectedLabel = new JLabel("Selected Method: " + (String) availODEMethods.get(ODESolveMethod)); paramPanel.add(currentlySelectedLabel); statusPanel = new JPanel(new GridLayout(2, 1)); statusAreaTop = new JTextArea(); statusAreaTop.setFont(new Font("Arial", Font.BOLD, 16)); String statusText = prepareStatusText(); statusAreaTop.setText(statusText); statusAreaBottom = new JTextArea(); statusAreaBottom.setText( "Step1: Copy and edit the template ODE (implements the famous Lorenz chaotic system),\n" + "Then set the name of your Java Class (instead of \"Lorenz\"), without the extension .java\n" + "Also set the proper order (i.e. number of equations and variables) of your system. "); statusPanel.add(statusAreaTop); statusPanel.add(statusAreaBottom); templateTextArea = new JTextArea(); updateTemplateText(); templateTextArea.setFont(new Font("Arial", Font.ITALIC, 12)); templateTextArea.setText(templateText); templateScrollPane = new JScrollPane(); templateViewPort = templateScrollPane.getViewport(); templateViewPort.add(templateTextArea); ODEWizardTextArea = new JTextArea(); ODEWizardText = ""; ODEWizardTextArea.setText(ODEWizardText); ODEWizardTextArea.setFont(new Font("Arial", Font.BOLD, 12)); ODEWizardScrollPane = new JScrollPane(); wizardViewPort = ODEWizardScrollPane.getViewport(); wizardViewPort.add(ODEWizardTextArea); editPanel.add(ODEWizardScrollPane); editPanel.add(templateScrollPane); // Step 1: copy template of ODE implementation from the // templateTextArea to ODEWizardTextArea copyTemplateButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ODEWizardTextArea.setText(templateTextArea.getText()); generateEditingButton.setEnabled(true); statusAreaBottom.setText( "Step2: If you have implemented correctly your ODE, the wizard completes the ready to compile Java class"); } }); // Step 2: generate Java Class from template JPanel buttonPanel = new JPanel(); generateEditingButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String editingODE = ODEWizardTextArea.getText(); String classImplementationString = // "package javaPluggins; \n"+ "import numal.*; \n\n" + "public class " + editingClassName + " extends Object \n implements " + implementingInterfaces[ODESolveMethod] + " \n \n " + "{ \n"; classImplementationString += (editingODE + "}\n"); ODEWizardTextArea.setText(classImplementationString); saveJavaClassButton.setEnabled(true); statusAreaBottom.setText( "Step3: The generated Java source is ready, you can check it, and then proceed to save."); } }); // Step 3: save generated Java Class on disk saveJavaClassButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String currentWorkingDirectory = Directory.Current().get().path(); JFileChooser chooser = new JFileChooser(currentWorkingDirectory); chooser.setSelectedFile(new File(editingClassName + ".java")); int ret = chooser.showSaveDialog(ODEWizardFrame); if (ret != JFileChooser.APPROVE_OPTION) { return; } File f = chooser.getSelectedFile(); try { PrintWriter out = new PrintWriter(f); String javaCodeText = ODEWizardTextArea.getText(); out.write(javaCodeText); out.close(); // update the notion of the working directory String fullPathOfSavedFile = f.getAbsolutePath(); GlobalValues.workingDir = fullPathOfSavedFile.substring( 0, fullPathOfSavedFile.lastIndexOf(File.separatorChar) + 1); compileJavaClassButton.setEnabled(true); compileJavaInternalCompilerButton.setEnabled(true); statusAreaBottom.setText( "Step4: The Java source file was saved to disk, \n " + "you can proceed to compile and load the corresponding class file"); } catch (java.io.FileNotFoundException enf) { System.out.println("File " + f.getName() + " not found"); enf.printStackTrace(); } catch (Exception eOther) { System.out.println("Exception trying to create PrintWriter"); eOther.printStackTrace(); } } }); // Step 4: Compile the generated Java class compileJavaClassButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String currentWorkingDirectory = GlobalValues.workingDir; JFileChooser chooser = new JFileChooser(currentWorkingDirectory); int ret = chooser.showOpenDialog(ODEWizardFrame); if (ret != JFileChooser.APPROVE_OPTION) { return; } File f = chooser.getSelectedFile(); String javaFile = null; try { javaFile = f.getCanonicalPath(); } catch (IOException ex) { System.out.println("I/O Exception in getCanonicalPath"); ex.printStackTrace(); } // extract the path specification of the generated Java class that implements the ODE // solution method, // in order to update the ScalaSci class path String SelectedFileWithPath = f.getAbsolutePath(); String SelectedFilePathOnly = SelectedFileWithPath.substring( 0, SelectedFileWithPath.lastIndexOf(File.separatorChar)); if (GlobalValues.ScalaSciClassPath.length() == 0) GlobalValues.ScalaSciClassPath = "."; if (GlobalValues.ScalaSciClassPath.indexOf(SelectedFilePathOnly) == -1) { GlobalValues.ScalaSciClassPathComponents.add(0, SelectedFilePathOnly); GlobalValues.ScalaSciClassPath = GlobalValues.ScalaSciClassPath + File.pathSeparator + SelectedFilePathOnly; } // update also the ScalaSciClassPath property StringBuilder fileStr = new StringBuilder(); Enumeration enumDirs = GlobalValues.ScalaSciClassPathComponents.elements(); while (enumDirs.hasMoreElements()) { Object ce = enumDirs.nextElement(); fileStr.append(File.pathSeparator + (String) ce); } GlobalValues.settings.setProperty("ScalaSciClassPath", fileStr.toString()); ClassLoader parentClassLoader = getClass().getClassLoader(); GlobalValues.extensionClassLoader = new ExtensionClassLoader(GlobalValues.ScalaSciClassPath, parentClassLoader); // update GUI components to account for the updated ScalaSci classpath scalaExec.scalaLab.scalaLab.updateTree(); boolean compilationSucccess = true; String tempFileName = ""; tempFileName = javaFile + ".java"; // public classes and Java files should have the same name String[] command = new String[6]; command[0] = "javac"; command[1] = "-cp"; command[2] = GlobalValues.jarFilePath + File.pathSeparator + GlobalValues.homeDir; command[3] = "-d"; // where to place output class files command[4] = SelectedFilePathOnly; // the path to save the compiled class files command[5] = javaFile; // full filename to compile String compileCommandString = command[0] + " " + command[1] + " " + command[2] + " " + command[3] + " " + command[4] + " " + command[5]; System.out.println("compileCommand Java= " + compileCommandString); try { Runtime rt = Runtime.getRuntime(); Process javaProcess = rt.exec(command); // an error message? StreamGobbler errorGobbler = new StreamGobbler(javaProcess.getErrorStream(), "ERROR"); // any output? StreamGobbler outputGobbler = new StreamGobbler(javaProcess.getInputStream(), "OUTPUT"); // kick them off errorGobbler.start(); outputGobbler.start(); // any error??? javaProcess.waitFor(); int rv = javaProcess.exitValue(); String commandString = command[0] + " " + command[1] + " " + command[2]; if (rv == 0) { System.out.println("Process: " + commandString + " exited successfully "); generateScriptCodeButton.setEnabled(true); statusAreaBottom.setText( "Step5: You can proceed now to create a draft script that utilizes your Java-based ODE integrator"); } else System.out.println( "Process: " + commandString + " exited with error, error value = " + rv); } catch (IOException exio) { System.out.println("IOException trying to executing " + command); exio.printStackTrace(); } catch (InterruptedException ie) { System.out.println("Interrupted Exception trying to executing " + command); ie.printStackTrace(); } } }); // Compile with the internal compiler compileJavaInternalCompilerButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String currentWorkingDirectory = GlobalValues.workingDir; JFileChooser chooser = new JFileChooser(currentWorkingDirectory); int ret = chooser.showOpenDialog(ODEWizardFrame); if (ret != JFileChooser.APPROVE_OPTION) { return; } File f = chooser.getSelectedFile(); String javaFile = null; try { javaFile = f.getCanonicalPath(); } catch (IOException ex) { System.out.println("I/O Exception in getCanonicalPath"); ex.printStackTrace(); } // extract the path specification of the generated Java class that implements the ODE // solution method, // in order to update the ScalaSci class path String SelectedFileWithPath = f.getAbsolutePath(); String SelectedFilePathOnly = SelectedFileWithPath.substring( 0, SelectedFileWithPath.lastIndexOf(File.separatorChar)); if (GlobalValues.ScalaSciClassPath.length() == 0) GlobalValues.ScalaSciClassPath = "."; if (GlobalValues.ScalaSciClassPath.indexOf(SelectedFilePathOnly) == -1) { GlobalValues.ScalaSciClassPathComponents.add(0, SelectedFilePathOnly); GlobalValues.ScalaSciClassPath = GlobalValues.ScalaSciClassPath + File.pathSeparator + SelectedFilePathOnly; } // update also the ScalaSciClassPath property StringBuilder fileStr = new StringBuilder(); Enumeration enumDirs = GlobalValues.ScalaSciClassPathComponents.elements(); while (enumDirs.hasMoreElements()) { Object ce = enumDirs.nextElement(); fileStr.append(File.pathSeparator + (String) ce); } GlobalValues.settings.setProperty("ScalaSciClassPath", fileStr.toString()); ClassLoader parentClassLoader = getClass().getClassLoader(); GlobalValues.extensionClassLoader = new ExtensionClassLoader(GlobalValues.ScalaSciClassPath, parentClassLoader); // update GUI components to account for the updated ScalaSci classpath scalaExec.scalaLab.scalaLab.updateTree(); String[] command = new String[11]; String toolboxes = ""; for (int k = 0; k < GlobalValues.ScalaSciClassPathComponents.size(); k++) toolboxes = toolboxes + File.pathSeparator + GlobalValues.ScalaSciClassPathComponents.elementAt(k); // compile the temporary file command[0] = "java"; command[1] = "-classpath"; command[2] = "." + File.pathSeparator + GlobalValues.jarFilePath + File.pathSeparator + toolboxes + File.pathSeparator + SelectedFilePathOnly; command[3] = "com.sun.tools.javac.Main"; // the name of the Java compiler class command[4] = "-classpath"; command[5] = command[2]; command[6] = "-sourcepath"; command[7] = command[2]; command[8] = "-d"; // where to place output class files command[9] = SelectedFilePathOnly; command[10] = SelectedFileWithPath; String compileCommandString = command[0] + " " + command[1] + " " + command[2] + " " + command[3] + " " + command[4] + " " + command[5] + " " + command[6] + " " + command[7] + " " + command[8] + " " + command[9] + " " + command[10]; System.out.println("compileCommand Java= " + compileCommandString); try { Runtime rt = Runtime.getRuntime(); Process javaProcess = rt.exec(command); // an error message? StreamGobbler errorGobbler = new StreamGobbler(javaProcess.getErrorStream(), "ERROR"); // any output? StreamGobbler outputGobbler = new StreamGobbler(javaProcess.getInputStream(), "OUTPUT"); // kick them off errorGobbler.start(); outputGobbler.start(); // any error??? javaProcess.waitFor(); int rv = javaProcess.exitValue(); if (rv == 0) { System.out.println("Process: exited successfully "); JavaCompile javaCompileObj = null; try { javaCompileObj = new JavaCompile(); } catch (Exception ex) { JOptionPane.showMessageDialog( null, "Unable to compile. Please check if your system's PATH variable includes the path to your javac compiler", "Cannot compile - Check PATH", JOptionPane.INFORMATION_MESSAGE); ex.printStackTrace(); } generateScriptCodeButton.setEnabled(true); statusAreaBottom.setText( "Step5: You can proceed now to create a draft ScalaSci-Script that utilizes your Java-based ODE integrator"); } else System.out.println("Process: exited with error, error value = " + rv); } catch (IOException exio) { System.out.println("IOException trying to executing " + command); exio.printStackTrace(); } catch (InterruptedException ie) { System.out.println("Interrupted Exception trying to executing " + command); ie.printStackTrace(); } } }); // Step 5: Generate Script Code generateScriptCodeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { new scriptCodeGenerationFrame("ODE Script code", editingClassName, systemOrder); } }); buttonPanel.add(copyTemplateButton); // Step 1 buttonPanel.setEnabled(true); buttonPanel.add(generateEditingButton); // Step 2 generateEditingButton.setEnabled(false); buttonPanel.add(saveJavaClassButton); // Step 3 saveJavaClassButton.setEnabled(false); buttonPanel.add(compileJavaClassButton); // Step 4 buttonPanel.add(compileJavaInternalCompilerButton); compileJavaClassButton.setEnabled(false); compileJavaInternalCompilerButton.setEnabled(false); buttonPanel.add(generateScriptCodeButton); // Step 5 generateScriptCodeButton.setEnabled(false); ODEWizardFrame.add(buttonPanel, BorderLayout.NORTH); ODEWizardFrame.add(editPanel, BorderLayout.CENTER); JPanel bottomPanel = new JPanel(new GridLayout(2, 1)); bottomPanel.add(paramPanel); bottomPanel.add(statusPanel); ODEWizardFrame.add(bottomPanel, BorderLayout.SOUTH); ODEWizardFrame.setLocation(100, 100); ODEWizardFrame.setSize(1400, 800); ODEWizardFrame.setVisible(true); }
/** * Inizialize frame components * * @throws CMSException * @throws FileNotFoundException * @throws IOException * @throws GeneralSecurityException */ private void initComponents() throws CMSException, FileNotFoundException, IOException, GeneralSecurityException { // ********************************* panel4 = new JPanel(); label2 = new JLabel(); textPane1 = new JTextPane(); panel5 = new JPanel(); textArea1 = new JTextArea(); textArea2 = new JTextArea(); progressBar = new JProgressBar(); textPane2 = new JTextPane(); textField1 = new JTextField(); button1 = new JButton(); panel6 = new JPanel(); button2 = new JButton(); button3 = new JButton(); button4 = new JButton(); GridBagConstraints gbc; // ======== this ======== Container contentPane = getContentPane(); contentPane.setLayout(new GridBagLayout()); ((GridBagLayout) contentPane.getLayout()).columnWidths = new int[] {165, 0, 0}; ((GridBagLayout) contentPane.getLayout()).rowHeights = new int[] {105, 50, 0}; ((GridBagLayout) contentPane.getLayout()).columnWeights = new double[] {0.0, 1.0, 1.0E-4}; ((GridBagLayout) contentPane.getLayout()).rowWeights = new double[] {1.0, 0.0, 1.0E-4}; // ======== panel4 ======== { panel4.setBackground(Color.white); panel4.setLayout(new GridBagLayout()); ((GridBagLayout) panel4.getLayout()).columnWidths = new int[] {160, 0}; ((GridBagLayout) panel4.getLayout()).rowHeights = new int[] {0, 0, 0}; ((GridBagLayout) panel4.getLayout()).columnWeights = new double[] {0.0, 1.0E-4}; ((GridBagLayout) panel4.getLayout()).rowWeights = new double[] {1.0, 1.0, 1.0E-4}; // ---- label2 ---- label2.setIcon( new ImageIcon( "images" + System.getProperty("file.separator") + "logo-freesigner-piccolo.png")); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets.bottom = 5; panel4.add(label2, gbc); // ---- textPane1 ---- textPane1.setFont(new Font("Verdana", Font.BOLD, 12)); textPane1.setText("Lettura\ncertificati\nda token"); textPane1.setEditable(false); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; gbc.anchor = GridBagConstraints.NORTHWEST; panel4.add(textPane1, gbc); } gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.BOTH; gbc.insets.bottom = 5; gbc.insets.right = 5; contentPane.add(panel4, gbc); // ======== panel5 ======== { panel5.setBackground(Color.white); panel5.setLayout(new GridBagLayout()); ((GridBagLayout) panel5.getLayout()).columnWidths = new int[] {0, 205, 0, 0}; ((GridBagLayout) panel5.getLayout()).rowHeights = new int[] {100, 0, 30, 30, 0}; ((GridBagLayout) panel5.getLayout()).columnWeights = new double[] {1.0, 0.0, 1.0, 1.0E-4}; ((GridBagLayout) panel5.getLayout()).rowWeights = new double[] {0.0, 0.0, 1.0, 1.0, 1.0E-4}; // ---- textArea1 ---- textArea1.setFont(new Font("Verdana", Font.BOLD, 14)); textArea1.setText("Lettura certificati da token"); textArea1.setEditable(false); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 3; gbc.fill = GridBagConstraints.VERTICAL; gbc.insets.bottom = 5; panel5.add(textArea1, gbc); // ---- textArea2 ---- textArea2.setFont(new Font("Verdana", Font.PLAIN, 12)); textArea2.setText("Ricerca certificati...\n"); textArea2.setEditable(false); textArea2.setColumns(30); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth = 3; gbc.fill = GridBagConstraints.BOTH; panel5.add(textArea2, gbc); progressBar.setValue(0); progressBar.setMaximum(1); progressBar.setStringPainted(true); progressBar.setBounds(0, 0, 300, 150); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 2; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets.bottom = 5; gbc.insets.right = 5; gbc.gridwidth = 3; panel5.add(progressBar, gbc); } gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 0; gbc.fill = GridBagConstraints.BOTH; gbc.insets.bottom = 5; contentPane.add(panel5, gbc); // ======== panel6 ======== { panel6.setBackground(Color.white); panel6.setLayout(new GridBagLayout()); ((GridBagLayout) panel6.getLayout()).columnWidths = new int[] {0, 0, 0, 0}; ((GridBagLayout) panel6.getLayout()).rowHeights = new int[] {0, 0}; ((GridBagLayout) panel6.getLayout()).columnWeights = new double[] {1.0, 1.0, 1.0, 1.0E-4}; ((GridBagLayout) panel6.getLayout()).rowWeights = new double[] {1.0, 1.0E-4}; // ---- button2 ---- button2.setText("Indietro"); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.insets.right = 5; button2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { frame.hide(); FreeSignerSignApplet nuovo = new FreeSignerSignApplet(); } }); // panel6.add(button2, gbc); // ---- button4 ---- button4.setText("Annulla"); gbc = new GridBagConstraints(); gbc.gridx = 2; gbc.gridy = 0; // panel6.add(button4, gbc); } gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 1; gbc.fill = GridBagConstraints.BOTH; contentPane.add(panel6, gbc); contentPane.setBackground(Color.white); frame = new JFrame(); frame.setContentPane(contentPane); frame.setTitle("Freesigner"); frame.setSize(300, 150); frame.setResizable(false); frame.pack(); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((d.width - frame.getWidth()) / 2, (d.height - frame.getHeight()) / 2); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); timer = new Timer( 10, new ActionListener() { public void actionPerformed(ActionEvent evt) { frame.show(); if (task.getMessage() != null) { String s = new String(); s = task.getMessage(); s = s.substring(0, Math.min(60, s.length())); textArea2.setText(s + " "); progressBar.setValue(task.getStatus()); } if (task.isDone()) { timer.stop(); // Finalizzo la cryptoki, onde evitare // successivi errori PKCS11 "cryptoki alreadi initialized" if ((task != null)) task.libFinalize(); ArrayList slotInfos = task.getSlotInfos(); if ((slotInfos == null) || slotInfos.isEmpty()) { frame.show(); JOptionPane.showMessageDialog( frame, "Controllare la presenza sul sistema\n" + "della libreria PKCS11 impostata.", "Nessun lettore rilevato", JOptionPane.WARNING_MESSAGE); frame.hide(); } else { String st = task.getCRLerror(); if (st.length() > 0) { timer.stop(); JOptionPane.showMessageDialog( frame, "C'è stato un errore nella verifica CRL.\n" + st, "Errore verifica CRL", JOptionPane.ERROR_MESSAGE); frame.hide(); FreeSignerSignApplet nuovo = new FreeSignerSignApplet(); } if (task.getDifferentCerts() == 0) { if (task.getCIr() != null) { JOptionPane.showMessageDialog( frame, "La carta " + task.getCardDescription() + " nel lettore " + conf.getReader() + " non contiene certificati", "Attenzione", JOptionPane.WARNING_MESSAGE); } else JOptionPane.showMessageDialog( frame, task.getMessage(), "Errore:", JOptionPane.ERROR_MESSAGE); } frame.hide(); // confFrame.createTreeAndTokenNodes(task.getSlotInfos()); } } } }); }
// compile a Java file with the installed javac compiler public boolean compileFile(String sourceFile) { boolean compilationResult = true; // no errors JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); if (compiler == null) { // Sterg-SOS why not loaded? System.out.println( "ToolProvider.getSystemJavaCompiler: no compiler provided. Unable to compile"); } DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null); StringWriter compileWriter = new StringWriter(); List<File> sourceFileList = new ArrayList<File>(); sourceFileList.add(new File(sourceFile)); Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(sourceFileList); String pathOfFile = sourceFile.substring(0, sourceFile.lastIndexOf(File.separatorChar)); String classpath = GlobalValues.jarFilePath + File.pathSeparatorChar + pathOfFile + File.pathSeparatorChar + "."; Iterable<String> options = Arrays.asList("-cp", classpath); CompilationTask task = compiler.getTask(compileWriter, fileManager, null, options, null, compilationUnits); boolean compileResult = task.call(); if (compileResult == false) { compilationResult = false; // compilation errors JFrame compResultsFrame = new JFrame("Compilation Results"); String diagnString = compileWriter.toString(); JTextArea compResultsArea = new JTextArea(diagnString); compResultsArea.setFont(new Font("Arial", Font.BOLD, 16)); JPanel compResultsPanel = new JPanel(); compResultsPanel.add(compResultsArea); compResultsFrame.add(compResultsPanel); compResultsFrame.setSize(800, 200); compResultsFrame.setLocation(100, 200); compResultsFrame.setVisible(true); int response = JOptionPane.showOptionDialog( null, "File " + sourceFile + " has compilation errors ", "Edit File? ", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (response == JOptionPane.YES_OPTION) { // edit it with scalalabEditor new scalalabEdit.EditorPaneEdit(sourceFile); } } try { fileManager.close(); } catch (IOException e) { } return compilationResult; }
public WebcamCaptureAndFadePanel(String saveDir, String layout) { System.out.println("Using " + saveDir + " as directory for the images."); saveDirectory = saveDir; getImages(); images_used = new ArrayList<Integer>(); images_lastadded = new ArrayList<Integer>(); images_nevershown = new ArrayList<Integer>(); Vector devices = (Vector) CaptureDeviceManager.getDeviceList(null).clone(); Enumeration enumeration = devices.elements(); System.out.println("- Available cameras -"); ArrayList<String> names = new ArrayList<String>(); while (enumeration.hasMoreElements()) { CaptureDeviceInfo cdi = (CaptureDeviceInfo) enumeration.nextElement(); String name = cdi.getName(); if (name.startsWith("vfw:")) { names.add(name); System.out.println(name); } } // String str1 = "vfw:Logitech USB Video Camera:0"; // String str2 = "vfw:Microsoft WDM Image Capture (Win32):0"; if (names.size() == 0) { JOptionPane.showMessageDialog( null, "Ingen kamera funnet. " + "Du må koble til et kamera for å kjøre programmet.", "Feil", JOptionPane.ERROR_MESSAGE); System.exit(0); } else if (names.size() > 1) { JOptionPane.showMessageDialog( null, "Fant mer enn 1 kamera. " + "Velger da:\n" + names.get(0), "Advarsel", JOptionPane.WARNING_MESSAGE); } String str2 = names.get(0); di = CaptureDeviceManager.getDevice(str2); ml = di.getLocator(); try { player = Manager.createRealizedPlayer(ml); formatControl = (FormatControl) player.getControl("javax.media.control.FormatControl"); /* Format[] formats = formatControl.getSupportedFormats(); for (int i=0; i<formats.length; i++) System.out.println(formats[i].toString()); */ player.start(); } catch (javax.media.NoPlayerException e) { JOptionPane.showMessageDialog( null, "Klarer ikke å starte" + " programmet pga. feil med kamera. Sjekk at det er koblet til.", "IOException", JOptionPane.ERROR_MESSAGE); System.exit(0); } catch (Exception e) { e.printStackTrace(); System.exit(0); } /* * Layout * * Add * - comp * - imagepanels */ if (layout.equals("1024v2")) { layout1024v2(); } else if (layout.equals("1280")) { layout1280(); } else { layout1024(); } // Capture Window if (captureWindow) { cw = new JFrame("Capture from webcam"); cw.setAlwaysOnTop(true); cw.setSize(sizeCaptureWindow_x, sizeCaptureWindow_y); cw.addKeyListener(new captureWindowKeyListner()); cw.setUndecorated(true); // Add webcam if ((comp = player.getVisualComponent()) != null) { cw.add(comp); } // Add panel to window and set location of window cw.setLocation(cwLocation_x, cwLocation_y); } // Text window cwText = new rotatedText(""); /* * Timer for update */ Timer thread = new Timer(); thread.schedule(new frameUpdateTask(), 0, (1000 / fps)); }
public static void main(String[] args) { System.setProperty("com.apple.mrj.application.apple.menu.about.name", "What's Wrong ..."); changeUI(USE_SYSTEM_UI); final NLPCanvas canvas = new NLPCanvas(); // create the filter pipeline EdgeTokenFilter edgeTokenFilter = new EdgeTokenFilter(); EdgeLabelFilter edgeLabelFilter = new EdgeLabelFilter(); TokenFilter tokenFilter = new TokenFilter(); EdgeTypeFilter edgeTypeFilter = new EdgeTypeFilter(); FilterPipeline filterPipeline = new FilterPipeline(tokenFilter, edgeTypeFilter, edgeLabelFilter, edgeTokenFilter); // set filter of canvas to be the pipeline canvas.setFilter(filterPipeline); int canvasWidth = 900; int canvasHeight = 300; int canvasX = 50; int canvasY = 50; int canvasBottom = canvasHeight + canvasY; final CorpusLoader gold = new CorpusLoader("Select Gold"); final CorpusLoader guess = new CorpusLoader("Select Guess"); gold.loadProperties(properties); guess.loadProperties(properties); // Menu JMenuBar menuBar = new JMenuBar(); JMenu file = new JMenu("File"); JMenuItem exportEps = new JMenuItem("Export EPS"); final JFileChooser fc = new JFileChooser(); exportEps.setAccelerator(KeyStroke.getKeyStroke('E', java.awt.event.InputEvent.ALT_MASK)); exportEps.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { int returnVal = fc.showSaveDialog(canvas); if (returnVal == JFileChooser.APPROVE_OPTION) try { canvas.exportToEPS(fc.getSelectedFile()); } catch (IOException e1) { e1.printStackTrace(); } } }); file.add(exportEps); file.setMnemonic('F'); JMenuItem quit = new JMenuItem("Quit"); // quit.setMnemonic('Q'); file.add(quit); quit.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); JMenu window = new JMenu("Window"); menuBar.add(file); menuBar.add(window); // Toolbar JToolBar toolBar = new JToolBar("Blub"); toolBar.add(new JButton("Test")); // dummy Frame // JFrame dummy = new JFrame(); // dummy.setVisible(false); // canvas frame JFrame canvasFrame = new JFrame("What's Wrong With My NLP?"); canvasFrame.setSize(canvasWidth, canvasHeight); canvasFrame.getContentPane().setLayout(new BorderLayout()); canvasFrame.getContentPane().add(new JScrollPane(canvas), BorderLayout.CENTER); canvasFrame.setJMenuBar(menuBar); // canvasFrame.getContentPane().add(toolBar, BorderLayout.NORTH); canvasFrame.setLocation(canvasX, canvasY); canvasFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // window.add(new WindowMenuItem(canvasFrame,"Canvas")); // desktop.add(canvasFrame); // file selection frame final ControllerDialog fileWindow = new ControllerDialog("File Selection", USE_SYSTEM_UI); fileWindow .getContentPane() .setLayout(new BoxLayout(fileWindow.getContentPane(), BoxLayout.Y_AXIS)); fileWindow.getContentPane().add(gold); fileWindow.getContentPane().add(new JSeparator()); fileWindow.getContentPane().add(guess); fileWindow.setLocation(canvasX + 20, canvasBottom + 20); fileWindow.pack(); fileWindow.setVisible(USE_SYSTEM_UI); // fileWindow.toBack(); window.add(new WindowMenuItem(fileWindow)); // fileFrame.setResizable(false); // desktop.add(fileFrame); // filter frame ControllerDialog filterWindow = new ControllerDialog("Edge Filters", false); filterWindow .getContentPane() .setLayout(new BoxLayout(filterWindow.getContentPane(), BoxLayout.Y_AXIS)); filterWindow.getContentPane().add(new EdgeTypeFilterPanel(canvas, edgeTypeFilter)); filterWindow.getContentPane().add(new JSeparator()); filterWindow .getContentPane() .add(new DependencyFilterPanel(canvas, edgeLabelFilter, edgeTokenFilter)); filterWindow.pack(); filterWindow.setLocation(canvasX + 250, canvasBottom + 15); filterWindow.setVisible(USE_SYSTEM_UI); window.add(new WindowMenuItem(filterWindow)); // token filter frame ControllerDialog tokenFilterWindow = new ControllerDialog("Token Filters", false); tokenFilterWindow .getContentPane() .setLayout(new BoxLayout(tokenFilterWindow.getContentPane(), BoxLayout.Y_AXIS)); tokenFilterWindow.getContentPane().add(new TokenFilterPanel(canvas, tokenFilter)); tokenFilterWindow.pack(); tokenFilterWindow.setLocation(canvasX + 360, canvasBottom + 230); tokenFilterWindow.setVisible(USE_SYSTEM_UI); window.add(new WindowMenuItem(tokenFilterWindow)); // appearance ControllerDialog appearance = new ControllerDialog("Appearance", false); appearance .getContentPane() .setLayout(new BoxLayout(appearance.getContentPane(), BoxLayout.Y_AXIS)); appearance.getContentPane().add(new AppearancePanel(canvas)); appearance.pack(); appearance.setLocation(canvasX + 500, canvasBottom + 25); appearance.setVisible(USE_SYSTEM_UI); window.add(new WindowMenuItem(appearance)); // description ControllerDialog description = new ControllerDialog("Description", true); // description.getContentPane().setLayout(new BoxLayout(appearance.getContentPane(), // BoxLayout.Y_AXIS)); JTextArea text = new JTextArea(15, 40); description.getContentPane().add(new JScrollPane(text)); description.pack(); description.setLocation(canvasX + 700, canvasBottom + 25); description.setVisible(USE_SYSTEM_UI); canvas.setTextArea(text); window.add(new WindowMenuItem(description)); // navigator ControllerDialog navigatorWindow = new ControllerDialog("Search Corpus", USE_SYSTEM_UI); navigatorWindow .getContentPane() .setLayout(new BoxLayout(navigatorWindow.getContentPane(), BoxLayout.Y_AXIS)); CorpusNavigator navigator = new CorpusNavigator(canvas, gold, guess, edgeTypeFilter); navigatorWindow.getContentPane().add(navigator); navigatorWindow.pack(); navigatorWindow.setMinimumSize(navigatorWindow.getSize()); navigatorWindow.setLocation(canvasX + 800, canvasBottom + 20); navigatorWindow.setVisible(USE_SYSTEM_UI); window.add(new WindowMenuItem(navigatorWindow, "Navigator")); // statusbar JPanel statusBar = new JPanel(); JLabel status = new JLabel("What's Wrong With My NLP version " + VERSION); status.setForeground(Color.LIGHT_GRAY); statusBar.setLayout(new GridBagLayout()); statusBar.setBorder(BorderFactory.createEmptyBorder(1, 10, 1, 10)); statusBar.add(status); statusBar.add(navigator.getSpinnerPanel(), new SimpleGridBagConstraints(0, USE_SYSTEM_UI)); statusBar.add( navigator.getSpinnerPanel(), new SimpleGridBagConstraints(1, 0, 1.0, 0.0, EAST, NONE)); // final preparation of canvas canvasFrame.getContentPane().add(statusBar, BorderLayout.SOUTH); canvasFrame.setVisible(USE_SYSTEM_UI); canvasFrame.requestFocus(); // canvasFrame.requestFocusInWindow(); Runtime.getRuntime() .addShutdownHook( new Thread( new Runnable() { public void run() { gold.saveProperties(properties); guess.saveProperties(properties); try { properties.store( new FileOutputStream(System.getProperty("user.home") + "/.whatswrong"), "Whats wrong with you NLP properties"); } catch (IOException e) { e.printStackTrace(); } } })); }