public DistributedTextEditor() { area1.setFont(new Font("Monospaced", Font.PLAIN, 12)); area2.setFont(new Font("Monospaced", Font.PLAIN, 12)); ((AbstractDocument) area1.getDocument()).setDocumentFilter(dec); area2.setEditable(false); Container content = getContentPane(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); JScrollPane scroll1 = new JScrollPane( area1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); content.add(scroll1, BorderLayout.CENTER); JScrollPane scroll2 = new JScrollPane( area2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); content.add(scroll2, BorderLayout.CENTER); content.add(ipaddress, BorderLayout.CENTER); content.add(portNumber, BorderLayout.CENTER); JMenuBar JMB = new JMenuBar(); setJMenuBar(JMB); JMenu file = new JMenu("File"); JMenu edit = new JMenu("Edit"); JMB.add(file); JMB.add(edit); file.add(Listen); file.add(Connect); file.add(Disconnect); file.addSeparator(); file.add(Save); file.add(SaveAs); file.add(Quit); edit.add(Copy); edit.add(Paste); edit.getItem(0).setText("Copy"); edit.getItem(1).setText("Paste"); Save.setEnabled(false); SaveAs.setEnabled(false); Disconnect.setEnabled(false); setDefaultCloseOperation(EXIT_ON_CLOSE); pack(); area1.addKeyListener(k1); area1.addMouseListener(m1); setTitle("Disconnected"); setVisible(true); area1.insert("Welcome to Hjortehandlerne's distributed text editor. \n", 0); this.addWindowListener(w1); }
public ConsolePanel() { super(new BorderLayout()); text.setFont(StyleContext.getDefaultStyleContext().getFont("SansSerif", Font.PLAIN, 10)); JScrollPane scroller = new JScrollPane(text); scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); add(BorderLayout.CENTER, scroller); }
/** Initialisation */ private void initComponents() { setBackground(new java.awt.Color(114, 159, 255)); addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { closeDialog(); } }); getContentPane().setLayout(new java.awt.BorderLayout()); JPanel actionPanel = new JPanel(); actionPanel.setLayout(new java.awt.GridLayout(1, 0)); detailedArea.setEditable(false); detailedArea.setVisible(true); detailedArea.setSize(500, 300); detailedArea.setFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, 11)); StringWriter opDetail = new StringWriter(); actionPrint(new PrintWriter(opDetail)); detailedArea.setText(new String(opDetail.getBuffer())); JScrollPane scroll = new JScrollPane(detailedArea); actionPanel.add(scroll); getContentPane().add(actionPanel, "Center"); northToolBar = new javax.swing.JToolBar(); northToolBar.setLayout(new java.awt.FlowLayout()); northToolBar.setFloatable(false); jbn_Print = new javax.swing.JButton(); jbn_Print.setText(" Print "); jbn_Print.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbn_PrintActionPerformed(); } }); northToolBar.add(jbn_Print); jbn_OK = new javax.swing.JButton(); jbn_OK.setText(" Close "); jbn_OK.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbn_OKActionPerformed(); } }); northToolBar.add(jbn_OK); getContentPane().add(northToolBar, "South"); }
public GeneralGUI(Whois whois) { super("Internic Whois"); this.server = whois; Container pane = this.getContentPane(); // whois.internic.net assumes a monospaced font, 72 columns across Font f = new Font("Monospaced", Font.PLAIN, 12); names.setFont(f); names.setEditable(false); JPanel CenterPanel = new JPanel(); CenterPanel.setLayout(new GridLayout(1, 1, 10, 10)); JScrollPane jsp = new JScrollPane(names); CenterPanel.add(jsp); pane.add("Center", CenterPanel); // You don't want the buttons in the south and north // to fill the entire sections so add Panels there // and use FlowLayouts in the Panel JPanel NorthPanel = new JPanel(); JPanel NorthPanelTop = new JPanel(); NorthPanelTop.setLayout(new FlowLayout(FlowLayout.LEFT)); NorthPanelTop.add(new JLabel("Whois: ")); NorthPanelTop.add("North", searchString); NorthPanelTop.add(exactMatch); NorthPanelTop.add(findButton); NorthPanel.setLayout(new BorderLayout(2, 1)); NorthPanel.add("North", NorthPanelTop); JPanel NorthPanelBottom = new JPanel(); NorthPanelBottom.setLayout(new GridLayout(1, 3, 5, 5)); NorthPanelBottom.add(initRecordType()); NorthPanelBottom.add(initSearchFields()); NorthPanelBottom.add(initServerChoice()); NorthPanel.add("Center", NorthPanelBottom); JPanel SouthPanel = new JPanel(); pane.add("North", NorthPanel); ActionListener al = new LookupNames(); findButton.addActionListener(al); searchString.addActionListener(al); }
/** 创建对话框面板 */ private void createPanel() { textArea = new JTextArea(); textArea.setEditable(false); textArea.setFont(new Font("aFont", Font.PLAIN, 12)); receiveTxt(); JPanel panel = new JPanel(); JButton button = new JButton("确定"); panel.add(button); add(textArea, BorderLayout.CENTER); add(panel, BorderLayout.SOUTH); button.addActionListener( (ActionEvent e) -> { setVisible(false); }); }
public static void makescalaSciCodeFromParams(int odeSolveMethod) { switch (odeSolveMethod) { case ODEWizardScalaSci.ODErke: scriptText = " import scala._ \n import scalaSci._ \n import scalaSci.Vec._ \n" + " import scalaSci.Mat._ \n import java.util.Vector \n" + " import numal._ \n import scalaSci.math.plot.plot._ \n"; scriptText += " \n var n= " + systemOrder + "; // the number of equations of the system\n" + "var x = new Array[Double](1) // entry: x(0) is the initial value of the independent variable \n" + "var xe = new Array[Double](1) // entry: xe(0) is the final value of the independent variable \n" + "var y = new Array[Double](n+1) // entry: the dependent variable, the initial values at x = x0 \n" + "var data = new Array[Double](7) // in array data one should give: \n" + " // data(1): the relative tolerance \n" + " // data(2): the absolute tolerance \n" + " // after each step data(3:6) contains: \n" + " // data(3): the steplength used for the last step \n" + " // data(4): the number of integration steps performed \n" + " // data(5): the number of integration steps rejected \n " + " // data(6): the number of integration steps skipped \n" + " // if upon completion of rke data(6) > 0, then results should be considered most criticallly \n" + " fi = true; // if fi is true then the integration starts at x0 with a trial step xe-x0; \n" + " // if fi is false then the integration is continued with a step length data(3)* sign(xe-x0) \n" + "data(1) = 1.0e-6; data(2) = 1.0e-6; \n\n" + "var xOut:Vector[Array[Double]] = new Vector(); \n" + "var yOut:Vector[Array[Double]] = new Vector(); \n" + "// a Java class that implements the AP_rke_methods interface should be specified \n" + "// The AP_rke_methods interface requires the implementation of two procedures: \n" + "// void der(int n, double t, double v[]) \n" + "// this procedure performs an evaluation of the right-hand side of the system with dependent variable v[1:n] and \n" + "// and independent variable t; upon completion of der the right-hand side should be overwritten on v[1:n] \n" + "// void out(int n, double x[], double xe[], double y[], double data[]) \n" + "// after each integration step performed, out can be used to obtain information from the solution process, \n" + "// e.g., the values of x, y[1:n], and data[3:6]; out can also be used to update data, but x and xe remain unchanged \n\n"; scriptText += "\n var xStart = " + xStart + ";" + "\n var xEnd = " + xEnd + "; // start and end values of integration \n \n"; for (int k = 1; k <= systemOrder; k++) scriptText += "y(" + k + ") = " + Math.random() + "; \n"; scriptText += " x(0) = xStart; \n xe(0) = xEnd; \n"; scriptText += "var javaClassName = " + "\"" + editingClassName + "\"" + "; // name of the Java class that implements the ODE \n"; scriptText += "\n var invocationObject = Class.forName(javaClassName, false, GlobalValues.globalInterpreter.classLoader).newInstance(); \n" + "\n var lorenz2RKEObject = invocationObject.asInstanceOf[AP_rke_methods] \n"; scriptText += "tic() \n"; scriptText += "var fi = true \n"; scriptText += "\nAnalytic_problems.rke(x, xe, n, y, lorenz2RKEObject, data, fi, xOut, yOut); \n" + "\n var timeCompute = toc() \n"; scriptText += "var plotTitle = \"Lorenz attractor in ScalaSci, time = \"+timeCompute+ \" Runge-Kutta (rke()), integrating from \"+xStart+\", to tEnd= \"+xEnd \n"; scriptText += "var color = Color.RED \n"; scriptText += " figure3d(1); plotV(yOut, color, plotTitle) \n"; break; case ODEWizardScalaSci.ODEmultistep: scriptText = " import scala._ \n import scalaSci._ \n import scalaSci.Vec._ \n import scalaSci.Mat._ \n " + "import java.util.Vector \n import numal._ \n import scalaSci.math.plot.plot._\n"; scriptText += "\n var n= " + systemOrder + "; // the number of equations of the system \n" + "var first = new Array[Boolean](1); // if first is true then the procedure starts the integration with a first order Adams method \n" + "// and a steplength equal to hmin, upon completion of a call, first is set to false \n" + "first(0)=true; \n" + "var btmp = new Array[Boolean](2) \n" + "var itmp = new Array[Int](3) \n" + "var xtmp = new Array[Double](7) \n" + "var x = new Array[Double](1) \n" + "var y = new Array[Double](6*n+1) \n" + "var ymax = new Array[Double](4) \n" + "var save = new Array[Double](6*n+39) // in this array the procedure stores information which can be used in a continuing call \n" + " // with first = false; also the following messages are delivered: \n" + " // save[38] == 0; an Adams method has been used \n" + " // save[38] == 1; the procedure switched to Gear's method \n" + " // save[37] == 0; no error message \n" + " // save[37] == 1; with the hmin specified the procedure cannot handle the nonlinearity (decrease hmin!) \n" + " // save[36] ; number of times that the requested local error bound was exceeded \n" + " // save[35] ; if save[36] is nonzero then save[35] gives an estimate of the maximal local error bound, otherwise save[35]=0 \n\n" + "\n var jac = Array.ofDim[Double](n+1) \n" + "var k=0; while (k<=n) { jac(k) = new Array[Double](n+1); k += 1; } \n" + "var xOut:Vector[Array[Double]] = new Vector() \n" + "var yOut:Vector[Array[Double]] = new Vector() \n" + "var hmin=1.0e-10; var eps=1.0e-9 \n" + "\n y(1)=0.12; y(2)=0.3; y(3)=0.12; \n" + "ymax(1) = 0.00001; ymax(2) = 0.00001; ymax(3) = 0.00001; var tstart = 0.0; x(0) = tstart \n" + "var xendDefault =\"100.0\" // end point of integration, default value \n" + "var prompt = \"Specify the end integration value\" \n" + "var inVal = JOptionPane.showInputDialog(prompt, xendDefault) \n" + "var tend = inVal.toDouble \n"; scriptText += "var javaClassName = " + "\"" + editingClassName + "\"" + "; // name of the Java class that implements the ODE \n"; scriptText += "\n var invocationObject = Class.forName(javaClassName, false, GlobalValues.globalInterpreter.classLoader).newInstance(); \n"; scriptText += "\n var multistepObject = invocationObject.asInstanceOf[AP_multistep_methods] \n"; scriptText += "\ntic() \n" + "\nAnalytic_problems.multistep(x, tend,y,hmin,5,ymax,eps,first, save, multistepObject, jac, true,n,btmp,itmp,xtmp, xOut, yOut) \n" + "var runTime = toc() \n" + "var plotTitle = \"Lorenz system, method Multistep, ntegratin from \"+tstart+\", to tEnd= \"+tend+\", runTime = \"+runTime \n"; scriptText += "var color = Color.RED \n figure3d(1); plotV(yOut, color, plotTitle) "; break; case ODEWizardScalaSci.ODEdiffsys: scriptText = " import scala._ \n import scalaSci._ \n import scalaSci.Vec._ \n " + "import scalaSci.Mat._ \n import java.util.Vector \n import numal._ \n import scalaSci.math.plot.plot._ \n"; scriptText += "var tol = 0.0000000000004 \n var aeta = tol; var reta = tol\n " + "var n = 3; // the number of equations of the system \n" + "var x = new Array[Double](1) // entry: x(0) is the initial value of the independent variable \n" + "var y = new Array[Double](n+1) // entry: the dependent variable, the initial values at x = x0 \n" + "aeta = tol // aeta: required absolute precision in the integration process \n" + "reta = tol // reta: required relative precision in the integration process \n" + "var s = new Array[Double](n+1) \n" + "var h0=0.000001 // h0: the initial step to be taken \n" + "var xOut:Vector[Array[Double]] = new Vector() \n" + "var yOut:Vector[Array[Double]] = new Vector() \n" + "y(1)=0.4; y(2)= -0.3; y(3)=0.9; \n" + "\n x(0)=0; var xe = 720; \n" + "\nvar javaClassName = " + "\"" + editingClassName + "\"" + "; // name of the Java class that implements the ODE \n"; scriptText += "\n var invocationObject = Class.forName(javaClassName, false, GlobalValues.globalInterpreter.classLoader).newInstance(); \n" + "var diffSysObject = invocationObject.asInstanceOf[AP_diffsys_methods] \n" + "\n tic() \n" + "Analytic_problems.diffsys(x, xe, n, y, diffSysObject, aeta, reta , s, h0, xOut, yOut) \n" + "var timeCompute = toc() \n" + "var plotTitle = \"Double Scroll attractor with ScalaSci, time \"+timeCompute+ \" end point = \"+xe \n" + "var color = Color.RED \n" + " figure3d(1); plotV(yOut, color, plotTitle); \n"; break; default: scriptText = ""; } scriptTextArea.setFont(new Font("Arial", Font.PLAIN, 12)); scriptTextArea.setRows(30); scriptTextArea.setText(scriptText); scriptPanel = new JPanel(); scriptScrollPane = new JScrollPane(scriptTextArea); scriptPanel.add(scriptScrollPane); JButton scriptSaveButton = new JButton("Save Script Code"); scriptSaveButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String currentWorkingDirectory = GlobalValues.ScalaSciClassPath; JFileChooser chooser = new JFileChooser(currentWorkingDirectory); chooser.setSelectedFile(new File(editingClassName + ".gsci")); int ret = chooser.showSaveDialog(ODEWizardScalaSci.scriptFrame); if (ret != JFileChooser.APPROVE_OPTION) { return; } File f = chooser.getSelectedFile(); try { PrintWriter out = new PrintWriter(f); String scriptCodeText = scriptTextArea.getText(); out.write(scriptCodeText); out.close(); } catch (java.io.FileNotFoundException enf) { System.out.println("File " + f.getName() + " not found"); enf.printStackTrace(); } } }); JButton scriptRunButton = new JButton("Run Script Code"); scriptRunButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { GlobalValues.scalalabMainFrame.scalalabConsole.interpretLine(scriptText + "\n"); } }); JPanel buttonsPanel = new JPanel(); buttonsPanel.add(scriptSaveButton); buttonsPanel.add(scriptRunButton); ODEWizardScalaSciScala.scriptFrame = new JFrame("Your script code"); ODEWizardScalaSciScala.scriptFrame.setLayout(new BorderLayout()); ODEWizardScalaSciScala.scriptFrame.add(scriptPanel, BorderLayout.CENTER); ODEWizardScalaSciScala.scriptFrame.add(buttonsPanel, BorderLayout.SOUTH); ODEWizardScalaSciScala.scriptFrame.setSize( GlobalValues.figFrameSizeX, GlobalValues.figFrameSizeY); ODEWizardScalaSciScala.scriptFrame.setVisible(true); }
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); }
/** Constructor to create the frame and its components */ public CoreyTextEditor() { // Create a scroll pane area.setFont(new Font("Monospaced", Font.PLAIN, 12)); JScrollPane scroll = new JScrollPane( area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); add(scroll, BorderLayout.CENTER); // Adds the system default look and feel try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | UnsupportedLookAndFeelException | IllegalAccessException e) { e.printStackTrace(); } // Create a menu bar JMenuBar JMB = new JMenuBar(); setJMenuBar(JMB); JMenu file = new JMenu("File"); JMenu edit = new JMenu("Edit"); JMB.add(file); JMB.add(edit); // Finishing our menu bar file.add(New); file.add(Open); file.add(Save); file.add(SaveAs); file.addSeparator(); file.add(Quit); edit.add(Cut); edit.add(Copy); edit.add(Paste); edit.getItem(0).setText("Cut"); edit.getItem(0).setIcon(new ImageIcon("cut.gif")); edit.getItem(1).setText("Copy"); edit.getItem(1).setIcon(new ImageIcon("copy.gif")); edit.getItem(2).setText("Paste"); edit.getItem(2).setIcon(new ImageIcon("paste.gif")); // Time to make a toolbar! JToolBar tool = new JToolBar(); add(tool, BorderLayout.NORTH); tool.add(New); tool.add(Open); tool.add(Save); tool.addSeparator(); JButton cut = tool.add(Cut); JButton cop = tool.add(Copy); JButton pas = tool.add(Paste); cut.setText(null); cut.setIcon(new ImageIcon("cut.gif")); cop.setText(null); cop.setIcon(new ImageIcon("copy.gif")); pas.setText(null); pas.setIcon(new ImageIcon("paste.gif")); Save.setEnabled(false); SaveAs.setEnabled(false); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); pack(); /* KeyListener to change Save and SaveAs */ KeyListener k1 = new KeyAdapter() { public void keyPressed(KeyEvent e) { changed = true; Save.setEnabled(true); SaveAs.setEnabled(true); } }; area.addKeyListener(k1); setTitle(currentFile + " - CoreyTextEditor"); setVisible(true); }
/** ** Constructor. Sets up user interface and initializations */ public Secondtry() { operators = true; doClear = false; frame = new JFrame("Calculator"); frame.setLayout(new BorderLayout(10, 10)); display = new JTextArea(); display.setSize(245, 100); display.setFont(new Font("SansSerif", Font.BOLD, 28)); display.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); // create the numeric buttons for calculator for (int i = 0; i < 10; i++) { jb[i] = new JButton("" + (i)); jb[i].addActionListener(this); jb[i].setFont(new Font("SansSerif", Font.BOLD, 14)); } // create the square root button root = new JButton("\u221A"); root.addActionListener(this); root.setFont(new Font("SansSerif", Font.BOLD, 14)); // create the clear button clear = new JButton("C"); clear.addActionListener(this); clear.setFont(new Font("SansSerif", Font.BOLD, 14)); // create the plus button plus = new JButton("\u002B"); plus.addActionListener(this); plus.setFont(new Font("SansSerif", Font.BOLD, 14)); // create the minus button minus = new JButton("\u002D"); minus.addActionListener(this); minus.setFont(new Font("SansSerif", Font.BOLD, 14)); // create the multiply button mult = new JButton("\u002A"); mult.addActionListener(this); mult.setFont(new Font("SansSerif", Font.BOLD, 14)); // create the division button div = new JButton("\u002F"); div.addActionListener(this); div.setFont(new Font("SansSerif", Font.BOLD, 14)); // create the equals button equals = new JButton("\u003D"); equals.addActionListener(this); equals.setFont(new Font("SansSerif", Font.BOLD, 14)); equals.setPreferredSize(new Dimension(50, 60)); // create the point button point = new JButton("\u002E"); point.addActionListener(this); point.setFont(new Font("SansSerif", Font.BOLD, 14)); // button grid JPanel buttons = new JPanel(new GridLayout(5, 4, 4, 4)); // add buttons to grid buttons.add(clear); buttons.add(root); buttons.add(div); buttons.add(mult); // add numeric buttons to grid for (int i = 7; i < 10; i++) buttons.add(jb[i]); buttons.add(minus); // add numeric buttons to grid for (int i = 4; i < 7; i++) buttons.add(jb[i]); buttons.add(plus); // add numeric buttons to grid for (int i = 1; i < 4; i++) buttons.add(jb[i]); buttons.add(equals); buttons.add(jb[0]); buttons.add(point); frame.add(display, BorderLayout.CENTER); frame.add(buttons, BorderLayout.SOUTH); frame.setSize(300, 400); frame.setVisible(true); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
/** * 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()); } } } }); }
/** * Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR * call it in your code! * * @noinspection ALL */ private void $$$setupUI$$$() { rootPanel = new JPanel(); rootPanel.setLayout(new GridLayoutManager(3, 1, new Insets(0, 0, 0, 0), -1, -1)); final JToolBar toolBar1 = new JToolBar(); rootPanel.add( toolBar1, new GridConstraints( 0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 20), null, 0, false)); openSrcButton = new JButton(); openSrcButton.setText("Open Src"); openSrcButton.setToolTipText("Open source file"); toolBar1.add(openSrcButton); openBinButton = new JButton(); openBinButton.setEnabled(true); openBinButton.setText("Open Bin"); openBinButton.setToolTipText("Open and disassemble binaries"); toolBar1.add(openBinButton); saveSrcButton = new JButton(); saveSrcButton.setEnabled(true); saveSrcButton.setText("Save Src"); saveSrcButton.setToolTipText("Save sources"); toolBar1.add(saveSrcButton); saveBinButton = new JButton(); saveBinButton.setEnabled(true); saveBinButton.setText("Save Bin"); saveBinButton.setToolTipText("Save assembled binary"); toolBar1.add(saveBinButton); final JToolBar.Separator toolBar$Separator1 = new JToolBar.Separator(); toolBar1.add(toolBar$Separator1); asmButton = new JButton(); asmButton.setText("Asm"); asmButton.setToolTipText("Assemble sources"); toolBar1.add(asmButton); final JToolBar.Separator toolBar$Separator2 = new JToolBar.Separator(); toolBar1.add(toolBar$Separator2); hardResetButton = new JButton(); hardResetButton.setEnabled(true); hardResetButton.setText("Hard Reset"); hardResetButton.setToolTipText("Hard Reset - zeroize memory and reupload binary"); toolBar1.add(hardResetButton); resetButton = new JButton(); resetButton.setEnabled(true); resetButton.setText("Reset"); resetButton.setToolTipText("Reset CPU (registers to zero)"); toolBar1.add(resetButton); execButton = new JButton(); execButton.setEnabled(true); execButton.setText("Exec"); execButton.setToolTipText("Run forever"); toolBar1.add(execButton); pauseButton = new JButton(); pauseButton.setEnabled(false); pauseButton.setText("Pause"); pauseButton.setToolTipText("Pause execution"); toolBar1.add(pauseButton); runButton = new JButton(); runButton.setEnabled(true); runButton.setText("Run"); runButton.setToolTipText("Run until breakpoint/reserved"); toolBar1.add(runButton); stepButton = new JButton(); stepButton.setEnabled(true); stepButton.setText("Step"); stepButton.setToolTipText("Execute one instruction"); toolBar1.add(stepButton); final JToolBar.Separator toolBar$Separator3 = new JToolBar.Separator(); toolBar1.add(toolBar$Separator3); breakpointButton = new JButton(); breakpointButton.setEnabled(true); breakpointButton.setText("Breakpoint"); breakpointButton.setToolTipText("Toggle breakpoint on instruction address"); toolBar1.add(breakpointButton); final JPanel panel1 = new JPanel(); panel1.setLayout(new GridLayoutManager(2, 3, new Insets(0, 0, 0, 0), -1, -1)); rootPanel.add( panel1, new GridConstraints( 1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); final JLabel label1 = new JLabel(); label1.setText("Source"); panel1.add( label1, new GridConstraints( 0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final JLabel label2 = new JLabel(); label2.setText("Memory"); panel1.add( label2, new GridConstraints( 0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final JLabel label3 = new JLabel(); label3.setText("Registers"); panel1.add( label3, new GridConstraints( 0, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); memoryScrollPane = new JScrollPane(); panel1.add( memoryScrollPane, new GridConstraints( 1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(600, -1), null, 0, false)); memoryTable = new JTable(); memoryScrollPane.setViewportView(memoryTable); final JScrollPane scrollPane1 = new JScrollPane(); panel1.add( scrollPane1, new GridConstraints( 1, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(100, -1), null, 0, false)); registersTable = new JTable(); scrollPane1.setViewportView(registersTable); sourceScrollPane = new JScrollPane(); panel1.add( sourceScrollPane, new GridConstraints( 1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(500, 400), null, 0, false)); sourceTextarea = new JTextArea(); sourceTextarea.setFont(new Font("Courier New", sourceTextarea.getFont().getStyle(), 12)); sourceTextarea.setText( "; Input your program here\n set a, 1\n add a, 1\n ife a, 2\n set a, 3\n:mainloop\n ife [message + I], 0\n set pc, end\n set a, [message + I]\n add a, 0xA100\n set [0x8000 + I], a\n add i, 1\n set pc, mainloop\n:message dat \"Hello, world!\", 0\n:end set pc, end"); sourceScrollPane.setViewportView(sourceTextarea); final JPanel panel2 = new JPanel(); panel2.setLayout(new GridLayoutManager(2, 3, new Insets(0, 0, 0, 0), -1, -1)); panel2.setVisible(false); rootPanel.add( panel2, new GridConstraints( 2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); consoleTextarea = new JTextArea(); consoleTextarea.setEditable(true); panel2.add( consoleTextarea, new GridConstraints( 1, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(150, 200), null, 0, false)); final JLabel label4 = new JLabel(); label4.setText("Console"); panel2.add( label4, new GridConstraints( 0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); clearButton = new JButton(); clearButton.setText("Clear"); panel2.add( clearButton, new GridConstraints( 0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final Spacer spacer1 = new Spacer(); panel2.add( spacer1, new GridConstraints( 0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); }
// 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; }
/* Build up the GUI using Swing magic. Nothing very exciting here - the BagPanel class makes the code a bit cleaner/easier to read. */ private void guiInit() throws Exception { JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.setMinimumSize(new Dimension(500, 250)); mainPanel.setPreferredSize(new Dimension(500, 300)); /* The message area */ JScrollPane mssgPanel = new JScrollPane(); mssgPanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); mssgPanel.setAutoscrolls(true); mssgArea = new JTextArea(); mssgArea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 20)); mainPanel.add(mssgPanel, BorderLayout.CENTER); mssgPanel.getViewport().add(mssgArea, null); /* The button area */ BagPanel buttonPanel = new BagPanel(); GridBagConstraints c = buttonPanel.c; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; buttonPanel.makeLabel("Detection", JLabel.CENTER); c.gridwidth = GridBagConstraints.RELATIVE; detDarkCb = buttonPanel.makeCheckBox("Dark", true); c.gridwidth = GridBagConstraints.REMAINDER; detAccelCb = buttonPanel.makeCheckBox("Movement", false); buttonPanel.makeSeparator(SwingConstants.HORIZONTAL); buttonPanel.makeLabel("Theft Reports", JLabel.CENTER); c.gridwidth = GridBagConstraints.RELATIVE; repLedCb = buttonPanel.makeCheckBox("LED", true); c.gridwidth = GridBagConstraints.REMAINDER; repSirenCb = buttonPanel.makeCheckBox("Siren", false); c.gridwidth = GridBagConstraints.RELATIVE; repServerCb = buttonPanel.makeCheckBox("Server", false); c.gridwidth = GridBagConstraints.REMAINDER; repNeighboursCb = buttonPanel.makeCheckBox("Neighbours", false); buttonPanel.makeSeparator(SwingConstants.HORIZONTAL); buttonPanel.makeLabel("Interval", JLabel.CENTER); fieldInterval = buttonPanel.makeTextField(10, null); fieldInterval.setText(Integer.toString(Constants.DEFAULT_CHECK_INTERVAL)); ActionListener settingsAction = new ActionListener() { public void actionPerformed(ActionEvent e) { updateSettings(); } }; buttonPanel.makeButton("Update", settingsAction); mainPanel.add(buttonPanel, BorderLayout.EAST); /* The frame part */ frame = new JFrame("AntiTheft"); frame.setSize(mainPanel.getPreferredSize()); frame.getContentPane().add(mainPanel); frame.setVisible(true); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
public static JTextArea getTextArea(String s) { JTextArea ret = new JTextArea(s); ret.setFont(new Font("Courier", Font.PLAIN, 12)); ret.setTabSize(4); return ret; }
/** The graphic handling and deployment. */ private void initComponents() { jDesktopPane1 = new javax.swing.JDesktopPane(); jInternalFrame1 = new javax.swing.JInternalFrame(); tf = new javax.swing.JTextField(); b1 = new javax.swing.JButton(); jInternalFrame3 = new javax.swing.JInternalFrame(); ta = new javax.swing.JTextArea(); jsp_ta = new javax.swing.JScrollPane(ta); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem3 = new javax.swing.JMenuItem(); jSeparator1 = new javax.swing.JSeparator(); jMenuItem4 = new javax.swing.JMenuItem(); jInternalFrame1 .getContentPane() .setLayout( new javax.swing.BoxLayout( jInternalFrame1.getContentPane(), javax.swing.BoxLayout.X_AXIS)); jInternalFrame1.setIconifiable(true); jInternalFrame1.setMaximizable(true); jInternalFrame1.setResizable(true); jInternalFrame1.setTitle("Message editor"); jInternalFrame1.setToolTipText( "Move and resize all of these to make the chat room appearance match your preferences."); jInternalFrame1.setVisible(true); tf.setFont(new java.awt.Font("Lucida Sans", 0, 12)); jInternalFrame1.getContentPane().add(tf); b1.setText("Send Message"); jInternalFrame1.getContentPane().add(b1); jInternalFrame1.setBounds(10, 10, 440, 60); jDesktopPane1.add(jInternalFrame1, javax.swing.JLayeredPane.DEFAULT_LAYER); jInternalFrame3.setIconifiable(true); jInternalFrame3.setMaximizable(true); jInternalFrame3.setResizable(true); jInternalFrame3.setTitle("Messages"); jInternalFrame3.setToolTipText( "Move and resize all of these to make the chat room appearance match your preferences."); jInternalFrame3.setVisible(true); ta.setBackground(new Color(255, 255, 255)); ta.setEditable(false); ta.setFont(new java.awt.Font("Lucida Sans", 0, 12)); // jsp_ta.setAutoscrolls(true); jsp_ta.setDoubleBuffered(true); jInternalFrame3.getContentPane().add(jsp_ta, java.awt.BorderLayout.CENTER); jInternalFrame3.setBounds(10, 80, 420, 240); jDesktopPane1.add(jInternalFrame3, javax.swing.JLayeredPane.DEFAULT_LAYER); getContentPane().add(jDesktopPane1, java.awt.BorderLayout.CENTER); jMenu1.setText("Private room options"); jMenu1.setMnemonic(KeyEvent.VK_O); jMenu1.setToolTipText("Choose some options."); jMenuItem3.setText("Save conversation"); jMenuItem3.setMnemonic(KeyEvent.VK_S); jMenuItem3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); jMenu1.add(jMenuItem3); jMenu1.add(jSeparator1); jMenuItem4.setText("Exit"); jMenuItem4.setMnemonic(KeyEvent.VK_E); jMenuItem4.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK)); jMenu1.add(jMenuItem4); jMenuBar1.add(jMenu1); setJMenuBar(jMenuBar1); this.pack(); b1.addActionListener(this); tf.addActionListener(this); jMenuItem3.addActionListener(this); jMenuItem4.addActionListener(this); posx = (int) Math.random() * 640; posy = (int) Math.random() * 480; this.pack(); this.setSize(dimx, dimy); this.setLocation(posx, posy); this.show(); }
void jbInit() throws Exception { titledBorder1 = new TitledBorder( BorderFactory.createLineBorder(new Color(153, 153, 153), 2), "Assembler messages"); this.getContentPane().setLayout(borderLayout1); this.setIconifiable(true); this.setMaximizable(true); this.setResizable(true); this.setTitle("EDIT"); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); splitPane.setDividerLocation(470); sourceArea.setFont(new java.awt.Font("Monospaced", 0, 12)); controlPanel.setLayout(gridBagLayout1); controlPanel.setBorder(BorderFactory.createLoweredBevelBorder()); positionPanel.setLayout(gridBagLayout2); fileLabel.setText("Source file:"); fileText.setEditable(false); browseButton.setSelected(false); browseButton.setText("Browse ..."); assembleButton.setEnabled(false); assembleButton.setText("Assemble file"); saveButton.setEnabled(false); saveButton.setText("Save file"); lineLabel.setText("Line:"); lineText.setMinimumSize(new Dimension(50, 20)); lineText.setPreferredSize(new Dimension(50, 20)); lineText.setEditable(false); columnLabel.setText("Column:"); columnText.setMinimumSize(new Dimension(41, 20)); columnText.setPreferredSize(new Dimension(41, 20)); columnText.setEditable(false); columnText.setText(""); messageScrollPane.setBorder(titledBorder1); messageScrollPane.setMinimumSize(new Dimension(33, 61)); messageScrollPane.setPreferredSize(new Dimension(60, 90)); optionsButton.setEnabled(false); optionsButton.setText("Assembler options ..."); messageScrollPane.getViewport().add(messageList, null); messageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); this.getContentPane().add(splitPane, BorderLayout.CENTER); splitPane.add(textScrollPane, JSplitPane.TOP); splitPane.add(controlPanel, JSplitPane.BOTTOM); textScrollPane.getViewport().add(sourceArea, null); controlPanel.add( fileLabel, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); controlPanel.add( fileText, new GridBagConstraints( 1, 0, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0)); controlPanel.add( browseButton, new GridBagConstraints( 4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0)); controlPanel.add( optionsButton, new GridBagConstraints( 2, 1, 1, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); controlPanel.add( assembleButton, new GridBagConstraints( 3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); controlPanel.add( saveButton, new GridBagConstraints( 4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0)); controlPanel.add( positionPanel, new GridBagConstraints( 0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); positionPanel.add( lineLabel, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); positionPanel.add( lineText, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0)); positionPanel.add( columnLabel, new GridBagConstraints( 2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0)); positionPanel.add( columnText, new GridBagConstraints( 3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0)); controlPanel.add( messageScrollPane, new GridBagConstraints( 0, 2, 5, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); }
public void go() { // build gui frame = new JFrame("Quiz Card Buider"); JPanel mainPanel = new JPanel(); Font bigFont = new Font("sanserif", Font.BOLD, 24); question = new JTextArea(6, 20); question.setLineWrap(true); question.setWrapStyleWord(true); question.setFont(bigFont); JScrollPane qScroller = new JScrollPane(question); qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); answer = new JTextArea(6, 20); answer.setLineWrap(true); answer.setWrapStyleWord(true); answer.setFont(bigFont); JScrollPane aScroller = new JScrollPane(question); aScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); aScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); JButton nextButton = new JButton("Next Card"); cardList = new ArrayList<QuizCard>(); JLabel qLabel = new JLabel("Question"); JLabel aLabel = new JLabel("Answer"); mainPanel.add(qLabel); mainPanel.add(qScroller); mainPanel.add(aLabel); mainPanel.add(aScroller); mainPanel.add(nextButton); nextButton.addActionListener(new NextCardListener()); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenuItem newMenuItem = new JMenuItem("New"); JMenuItem saveMenuItem = new JMenuItem("Save"); newMenuItem.addActionListener(new NewMenuListener()); saveMenuItem.addActionListener(new SaveMenuListener()); fileMenu.add(newMenuItem); fileMenu.add(saveMenuItem); menuBar.add(fileMenu); frame.setJMenuBar(menuBar); frame.getContentPane().add(BorderLayout.CENTER, mainPanel); frame.setSize(500, 600); frame.setVisible(true); // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
public void go() { frame = new JFrame("Quiz Card Player"); JPanel mainPanel = new JPanel(); Font bigFont = new Font("sanserif", Font.BOLD, 24); display = new JTextArea(10, 20); display.setFont(bigFont); display.setLineWrap(true); display.setEditable(false); JScrollPane qScroller = new JScrollPane(display); qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); nextButton = new JButton("Show Questions"); nextButton.addActionListener(new NextCardListener()); mainPanel.add(qScroller); mainPanel.add(nextButton); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenuItem loadMenuItem = new JMenuItem("Load Card Set"); loadMenuItem.addActionListener(new OpenMenuListener()); fileMenu.add(loadMenuItem); menuBar.add(fileMenu); frame.setJMenuBar(menuBar); frame.getContentPane().add(BorderLayout.CENTER, mainPanel); frame.setSize(640, 500); frame.setVisible(true); }