private void initGUI() { JPanel pCommand = new JPanel(); pResult = new JPanel(); nsSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pCommand, pResult); pCommand.setLayout(new BorderLayout()); pResult.setLayout(new BorderLayout()); Font fFont = new Font("Dialog", Font.PLAIN, 12); txtCommand = new JTextArea(5, 40); txtCommand.setMargin(new Insets(5, 5, 5, 5)); txtCommand.addKeyListener(this); txtCommandScroll = new JScrollPane(txtCommand); txtResult = new JTextArea(20, 40); txtResult.setMargin(new Insets(5, 5, 5, 5)); txtResultScroll = new JScrollPane(txtResult); txtCommand.setFont(fFont); txtResult.setFont(new Font("Courier", Font.PLAIN, 12)); /* // button replaced by toolbar butExecute = new JButton("Execute"); butExecute.addActionListener(this); pCommand.add(butExecute, BorderLayout.EAST); */ pCommand.add(txtCommandScroll, BorderLayout.CENTER); gResult = new GridSwing(); gResultTable = new JTable(gResult); gScrollPane = new JScrollPane(gResultTable); // getContentPane().setLayout(new BorderLayout()); pResult.add(gScrollPane, BorderLayout.CENTER); // Set up the tree rootNode = new DefaultMutableTreeNode("Connection"); treeModel = new DefaultTreeModel(rootNode); tTree = new JTree(treeModel); tScrollPane = new JScrollPane(tTree); tScrollPane.setPreferredSize(new Dimension(120, 400)); tScrollPane.setMinimumSize(new Dimension(70, 100)); txtCommandScroll.setPreferredSize(new Dimension(360, 100)); txtCommandScroll.setMinimumSize(new Dimension(180, 100)); gScrollPane.setPreferredSize(new Dimension(460, 300)); ewSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tScrollPane, nsSplitPane); fMain.getContentPane().add(ewSplitPane, BorderLayout.CENTER); doLayout(); fMain.pack(); }
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); }
public ReplyView(MikroEventModel e, EventViewManager m) { super(); evm = m; textArea = new JTextArea("@" + evm.event.getAuthor() + " ", 4, 45); Font f = new Font("Nimbus Sans L Bold", Font.PLAIN, 15); textArea.setFont(f); textArea.setLineWrap(true); ((AbstractDocument) textArea.getDocument()).setDocumentFilter(new DocumentSizeFilter(140)); buttonPanel = new JPanel(); submitButton = new JButton("Post"); cancelButton = new JButton("Cancel"); submitButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { evm.reply(textArea.getText()); } }); cancelButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { evm.setEventView(); } }); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); buttonPanel.add(Box.createHorizontalGlue()); buttonPanel.add(submitButton); buttonPanel.add(Box.createHorizontalStrut(5)); buttonPanel.add(cancelButton); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(textArea); this.add(buttonPanel); }
public void setSelectedFont(Font font) { selectedFont = font; family = font.getFamily(); style = font.getStyle(); size = font.getSize(); preview.setFont(font); }
public void mousePressed(MouseEvent e) { if (e.getButton() == e.BUTTON3) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); int index = list.locationToIndex(e.getPoint()); GetImageFile gif = new GetImageFile(files[index]); JTextArea area = new JTextArea( "File: " + gif.getImageString() + "\n" + "Score: " + nf.format(scores[index]) + "\n" + "Pairs: " + nrpairs[index]); area.setEditable(false); area.setBorder(BorderFactory.createLineBorder(Color.black)); area.setFont(new Font("times", Font.PLAIN, 12)); PopupFactory factory = PopupFactory.getSharedInstance(); popup = factory.getPopup( null, area, (int) e.getComponent().getLocationOnScreen().getX() + e.getX() + 25, (int) e.getComponent().getLocationOnScreen().getY() + e.getY()); popup.show(); } }
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); }
public TestHTML() { int d = (Frame.getFrames().length == 0) ? JFrame.EXIT_ON_CLOSE : JFrame.DISPOSE_ON_CLOSE; JPanel pan = new JPanel(); pan.setLayout(new BorderLayout(GAP, GAP - 4)); pan.setBorder(new EmptyBorder(GAP, GAP, GAP, GAP)); pan.setBackground(COL); pan.setFont(font); lab = new JLabel(MSG); // , SwingConstants.CENTER); lab.setName("title"); lab.setFont(new Font("Serif", 3, 16)); // lab.setForeground(Color.black); pan.add(lab, "North"); text = new JTextArea("JTextArea\n"); text.setName("area"); text.setLineWrap(true); text.setFont(font); JScrollPane scr1 = new JScrollPane(text); scr1.setPreferredSize(new Dimension(300, 500)); pan.add(scr1, "Center"); html = new JEditorPane(); html.setContentType("text/html"); html.setEditable(false); html.addMouseListener(this); html.addMouseMotionListener(this); JScrollPane scr2 = new JScrollPane(html); scr2.setPreferredSize(new Dimension(350, 500)); pan.add(scr2, "East"); but = new JButton("Copy text from JTextArea to JEditorPane"); but.addActionListener(this); pan.add(but, "South"); frm = new JFrame(MSG); frm.setContentPane(pan); frm.setDefaultCloseOperation(d); frm.setLocation(100, 150); frm.pack(); frm.setVisible(true); }
/** 创建对话框面板 */ 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 GUI() { String[] keys = {"no Quotation found"}; if (tryDir(".") || tryDir("BLM305") || tryDir("CSE470")) keys = Q.keySet().toArray(keys); menu = new JComboBox<String>(keys); if (Q.size() > 0) setMessage(0); JPanel pan = new JPanel(); pan.setLayout(new BorderLayout(GAP, GAP - 4)); pan.setBorder(new javax.swing.border.EmptyBorder(GAP, GAP, GAP, GAP)); pan.setBackground(COLOR); pan.add(topPanel(), "North"); txt.setFont(LARGE); txt.setEditable(false); txt.setRows(5); txt.setColumns(30); txt.setWrapStyleWord(true); txt.setLineWrap(true); txt.setDragEnabled(true); pan.add(new JScrollPane(txt), "Center"); ref.setFont(SMALL); ref.setEditable(false); ref.setColumns(35); ref.setDragEnabled(true); pan.add(ref, "South"); pan.setToolTipText("A project realized collectively by the class"); menu.setToolTipText("Quotation classes"); who.setToolTipText("author()+year()"); txt.setToolTipText("text()"); ref.setToolTipText("reference()"); frm.setContentPane(pan); frm.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frm.setLocation(scaled(120), scaled(90)); frm.pack(); frm.setVisible(true); }
public OutputPopup(JFrame parent, AlignViewport av, Controller c, String title) { super(parent, av, c, title); sp = new JScrollPane(); ta = new JTextArea(10, 60); f = new JComboBox(); ta.setFont(new Font("Courier", Font.PLAIN, 10)); format = new JLabel("Alignment format"); for (int i = 0; i < FormatProperties.getFormats().size(); i++) { f.addItem((String) FormatProperties.getFormats().elementAt(i)); } sp.add(ta); gbc.fill = GridBagConstraints.BOTH; gbc.weighty = 1.0; add(sp, gb, gbc, 0, 0, 2, 2); gbc.fill = GridBagConstraints.HORIZONTAL; add(format, gb, gbc, 0, 2, 1, 1); add(f, gb, gbc, 1, 2, 1, 1); add(status, gb, gbc, 0, 3, 2, 2); setApplyAction(new AreaOutputAction("area output", av, c)); pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setLocation( (screenSize.width - getSize().width) / 2, (screenSize.height - getSize().height) / 2); show(); }
/* 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); } }); }
private void createUI() { setTitle(strings.getString("window.title")); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); mailBodyArea = new JTextArea(20, 70); mailBodyArea.setLineWrap(true); mailBodyArea.setWrapStyleWord(true); mailBodyArea.setFont(new Font("monospaced", Font.PLAIN, 12)); scrollPane = new JScrollPane(mailBodyArea); mailSubjectField = new JTextField(20); mailToField = new JTextField(20); mailFromField = new JTextField(20); mailSubjectLabel = new JLabel(strings.getString("subject.label")); mailToLabel = new JLabel(strings.getString("to.label")); setToFieldEditable(false); toLabelListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { mouseClicked_searchSource(); } public void mouseEntered(MouseEvent e) { setCursor(new Cursor(Cursor.HAND_CURSOR)); } public void mouseExited(MouseEvent e) { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } }; mailFromLabel = new JLabel(strings.getString("from.label")); sendMailButton = new JButton(strings.getString("sendmail.text")); sendMailButton.setIcon( new ImageIcon(getClass().getResource(strings.getString("sendmail.icon")))); sendMailButton.setToolTipText(strings.getString("sendmail.tooltip")); cancelButton = new JButton(strings.getString("cancel.text")); cancelButton.setIcon(new ImageIcon(getClass().getResource(strings.getString("cancel.icon")))); cancelButton.setToolTipText(strings.getString("cancel.tooltip")); cancelButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { actionPerformed_cancel(); } }); sendMailButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { actionPerformed_sendMail(); } }); Container pane = this.getContentPane(); container.setLayout(gridbag); c.fill = GridBagConstraints.HORIZONTAL; c.insets = new Insets(5, 5, 0, 5); c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.EAST; pane.add(mailFromLabel, c); c.gridx = 1; pane.add(mailFromField, c); c.gridx = 0; c.gridy = 1; pane.add(mailToLabel, c); c.gridx = 1; pane.add(mailToField, c); c.gridx = 0; c.gridy = 2; pane.add(mailSubjectLabel, c); c.gridx = 1; pane.add(mailSubjectField, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 2; pane.add(scrollPane, c); JPanel bPane = new JPanel(); bPane.add(sendMailButton); bPane.add(cancelButton); c.gridx = 0; c.gridy = 4; pane.add(bPane, c); mailToField.requestFocus(); }
public IRCBOT(boolean uList, String channel, int chatNum) { // chatter = new ChatDisplay("<html><body bgcolor='black'><table border=0pt width=100%>"); winNum = chatNum; URL iconURL = getClass().getResource("P_300x300.png"); ImageIcon icon = new ImageIcon(iconURL); setIconImage(icon.getImage()); Action doNothing = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) {} }; channelName = channel; standardWindow = uList; chatInput = new JTextArea(4, 55); chatInput.setWrapStyleWord(true); chatInput.setLineWrap(true); chatInput.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "doNothing"); chatScreen = new JTextPane(); chatScreen.setContentType("text/html"); chatScreen.setEditorKit(kit); chatScreen.setDocument(doc); userList = new JTextPane(); registeredUserList = new JTextPane(); sendButton = new JButton("SEND"); g_start = new JButton("START"); g_end = new JButton("END"); g_reroll = new JButton("secret"); JLabel l_giveaway = new JLabel("Giveaway", JLabel.CENTER); JLabel l_chat = new JLabel("Chat", JLabel.CENTER); JLabel l_uList = new JLabel("User List", JLabel.CENTER); sendButton.addActionListener(this); g_start.addActionListener(this); g_end.addActionListener(this); g_reroll.addActionListener(this); g_start.setEnabled(false); // disabled for basic irc client g_end.setEnabled(false); g_reroll.setEnabled(false); // String start = "<html><body>"; Dimension min = new Dimension(100, 1); Dimension pref = new Dimension(150, 1); Dimension max = new Dimension(600, 600); // chatScreen.setMinimumSize(min); // userList.setMinimumSize(min); // chatInput.addKeyListener(KeyBoardListener); JPanel mainPanel = new JPanel(new BorderLayout(5, 5)); JPanel left = new JPanel(new BorderLayout(5, 5)); JPanel mid = new JPanel(new BorderLayout(5, 5)); JPanel right = new JPanel(new BorderLayout(5, 5)); JPanel giveaway_buttons = new JPanel(new BorderLayout(5, 5)); JPanel sendBar = new JPanel(); scrollChat = new JScrollPane(chatScreen); JScrollPane scrollChatInput = new JScrollPane(chatInput); userListScroll = new JScrollPane(userList); JScrollPane regUserListScroll = new JScrollPane(registeredUserList); userListScroll.setMinimumSize(min); // userListScroll.setPreferredSize(pref); // userListScroll.setMaximumSize(new Dimension(800,600)); // userListScroll.setPreferredSize(new Dimension(100,100)); // scrollChat.setPreferredSize(pref); scrollChat.setMinimumSize(min); // scrollChat.setMaximumSize(new Dimension(500,500)); regUserListScroll.setPreferredSize(pref); mid.add(l_chat, BorderLayout.NORTH); mid.add(scrollChat, BorderLayout.CENTER); right.add(l_uList, BorderLayout.NORTH); right.add(userListScroll, BorderLayout.CENTER); giveaway_buttons.add(g_start, BorderLayout.WEST); giveaway_buttons.add(g_end, BorderLayout.CENTER); giveaway_buttons.add(g_reroll, BorderLayout.PAGE_END); left.add(giveaway_buttons, BorderLayout.PAGE_END); JSplitPane chat_userList = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mid, right); chat_userList.setOneTouchExpandable(true); chat_userList.setDividerLocation(500); chat_userList.setResizeWeight(0.5); chat_userList.setContinuousLayout(true); // chat_userList.setPreferredSize(new Dimension(100,100)); chat_userList.setMinimumSize(min); // chat_userList.setMaximumSize(max); userListScroll.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER); // scroll.add(chatScreen); sendBar.add(scrollChatInput); sendBar.add(sendButton); if (standardWindow) { mainPanel.add(chat_userList, BorderLayout.CENTER); mainPanel.add(sendBar, BorderLayout.PAGE_END); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); settings = new JMenuItem("Settings"); settings.addActionListener(this); fileMenu.add(settings); menuBar.add(fileMenu); left.add(l_giveaway, BorderLayout.NORTH); left.add(regUserListScroll, BorderLayout.CENTER); // left.setBorder(new EmptyBorder(0,5,0,0)); // chat_userList.setBorder(new EtchedBorder(0,0,0,5)); mainPanel.add(left, BorderLayout.WEST); mainPanel.add(menuBar, BorderLayout.PAGE_START); // mainPanel.setBorder(new EmptyBorder(0,10,10,10)); } else { mainPanel.add(scrollChat, BorderLayout.CENTER); } registeredUserList.setEditable(false); userList.setEditable(false); chatScreen.setEditable(false); registeredUserList.setFont(new Font("Courier New", Font.PLAIN, 12)); chatScreen.setFont(new Font("Courier New", Font.PLAIN, 12)); chatInput.setFont(new Font("Courier New", Font.PLAIN, 12)); getContentPane().add(mainPanel); setSize(800, 500); setVisible(true); setResizable(true); setLocationRelativeTo(null); setTitle("IRC Chatter"); setMinimumSize(new Dimension(500, 200)); addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // System.out.println("\n\n\n\n\n\\n\nCLOSEDWINDOW\n\n\n\n\n\n\n\n"); if (sock.isSafe() == true) sock.outputText("PART " + channelName + "\r\n"); // System.out.println("\n\n\n\n\n\\n\nCLOSEDWINDOW\n\n\n\n\n\n\n\n"); } }); chatInput.addKeyListener(this); chatInput.requestFocus(); }
/** Constructs the <tt>LoginWindow</tt>. */ private void init() { String title; if (windowTitle != null) title = windowTitle; else title = DesktopUtilActivator.getResources() .getI18NString("service.gui.AUTHENTICATION_WINDOW_TITLE", new String[] {server}); String text; if (windowText != null) text = windowText; else text = DesktopUtilActivator.getResources() .getI18NString("service.gui.AUTHENTICATION_REQUESTED_SERVER", new String[] {server}); String uinText; if (usernameLabelText != null) uinText = usernameLabelText; else uinText = DesktopUtilActivator.getResources().getI18NString("service.gui.IDENTIFIER"); String passText; if (passwordLabelText != null) passText = passwordLabelText; else passText = DesktopUtilActivator.getResources().getI18NString("service.gui.PASSWORD"); setTitle(title); infoTextArea.setEditable(false); infoTextArea.setOpaque(false); infoTextArea.setLineWrap(true); infoTextArea.setWrapStyleWord(true); infoTextArea.setFont(infoTextArea.getFont().deriveFont(Font.BOLD)); infoTextArea.setText(text); infoTextArea.setAlignmentX(0.5f); JLabel uinLabel = new JLabel(uinText); uinLabel.setFont(uinLabel.getFont().deriveFont(Font.BOLD)); JLabel passwdLabel = new JLabel(passText); passwdLabel.setFont(passwdLabel.getFont().deriveFont(Font.BOLD)); TransparentPanel labelsPanel = new TransparentPanel(new GridLayout(0, 1, 8, 8)); labelsPanel.add(uinLabel); labelsPanel.add(passwdLabel); TransparentPanel textFieldsPanel = new TransparentPanel(new GridLayout(0, 1, 8, 8)); textFieldsPanel.add(uinValue); textFieldsPanel.add(passwdField); JPanel southFieldsPanel = new TransparentPanel(new GridLayout(1, 2)); this.rememberPassCheckBox.setOpaque(false); this.rememberPassCheckBox.setBorder(null); southFieldsPanel.add(rememberPassCheckBox); if (signupLink != null && signupLink.length() > 0) southFieldsPanel.add( createWebSignupLabel( DesktopUtilActivator.getResources().getI18NString("plugin.simpleaccregwizz.SIGNUP"), signupLink)); else southFieldsPanel.add(new JLabel()); boolean allowRememberPassword = true; String allowRemPassStr = DesktopUtilActivator.getResources().getSettingsString(PNAME_ALLOW_SAVE_PASSWORD); if (allowRemPassStr != null) { allowRememberPassword = Boolean.parseBoolean(allowRemPassStr); } allowRememberPassword = DesktopUtilActivator.getConfigurationService() .getBoolean(PNAME_ALLOW_SAVE_PASSWORD, allowRememberPassword); setAllowSavePassword(allowRememberPassword); JPanel buttonPanel = new TransparentPanel(new FlowLayout(FlowLayout.CENTER)); buttonPanel.add(loginButton); buttonPanel.add(cancelButton); JPanel southEastPanel = new TransparentPanel(new BorderLayout()); southEastPanel.add(buttonPanel, BorderLayout.EAST); TransparentPanel mainPanel = new TransparentPanel(new BorderLayout(10, 10)); mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 20)); JPanel mainFieldsPanel = new TransparentPanel(new BorderLayout(0, 10)); mainFieldsPanel.add(labelsPanel, BorderLayout.WEST); mainFieldsPanel.add(textFieldsPanel, BorderLayout.CENTER); mainFieldsPanel.add(southFieldsPanel, BorderLayout.SOUTH); mainPanel.add(infoTextArea, BorderLayout.NORTH); mainPanel.add(mainFieldsPanel, BorderLayout.CENTER); mainPanel.add(southEastPanel, BorderLayout.SOUTH); this.getContentPane().add(mainPanel, BorderLayout.EAST); this.loginButton.setName("ok"); this.cancelButton.setName("cancel"); if (loginButton.getPreferredSize().width > cancelButton.getPreferredSize().width) cancelButton.setPreferredSize(loginButton.getPreferredSize()); else loginButton.setPreferredSize(cancelButton.getPreferredSize()); this.loginButton.setMnemonic( DesktopUtilActivator.getResources().getI18nMnemonic("service.gui.OK")); this.cancelButton.setMnemonic( DesktopUtilActivator.getResources().getI18nMnemonic("service.gui.CANCEL")); this.loginButton.addActionListener(this); this.cancelButton.addActionListener(this); this.getRootPane().setDefaultButton(loginButton); }
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 public FACFrame() { // SET PROPERTIES OF THE MAIN FRAME setTitle("Fully Associative Cache"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setIconImage(Toolkit.getDefaultToolkit().createImage(FACFrame.class.getResource("cam.gif"))); // CREATE COMPONENTS AND SET THEIR PROPERTIES // NAVIGATION BUTTONS restart = new JButton("Restart"); next = new JButton("Next"); back = new JButton("Back"); quit = new JButton("Quit"); // CACHE HITS AND MISSES INFO. lCacheHits = new JLabel("Cache Hits"); lCacheMisses = new JLabel("Cache Misses"); tCacheHits = new JTextField(5); tCacheMisses = new JTextField(5); tCacheHits.setEditable(false); tCacheHits.setFont(new Font("Monospaced", Font.BOLD, 14)); tCacheHits.setText(" 0"); tCacheMisses.setEditable(false); tCacheMisses.setFont(new Font("Monospaced", Font.BOLD, 14)); tCacheMisses.setText(" 0"); // PROGRESS UPDATE AREA tProgress = new JTextArea(3, 45); tProgress.setEditable(false); tProgress.setLineWrap(true); tProgress.setWrapStyleWord(true); tProgress.setCaretPosition(0); tProgress.setFont(new Font("Serif", Font.BOLD + Font.ITALIC, 16)); tProgress.setText( "Welcome to Fully Associative Cache!\nThe system specs are as follows -" + "\n 16 Blocks in Cache\n 32 Blocks in Main Memory\n 8 Words per Block" + "\n The replacement algorithm shown is the Least-Recently-Used algorithm" + "\n as it is the most commonly used one." + "\nPlease generate the Address Reference String." + "\nThen click on \"Next\" to continue."); progressScroll = new JScrollPane(); progressScroll.getViewport().add(tProgress); progressScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); lProgress = new JLabel("PROGRESS UPDATE"); // ADDRESS REFERENCE STRING addRefStrList = new JList(); addRefStrList.setEnabled(false); addRefStrScroll = new JScrollPane(); addRefStrScroll.getViewport().setView(addRefStrList); addRefStrScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); addRefStrScroll.setPreferredSize(new Dimension(140, 300)); // BUTTONS USED TO ADDRESS GENERATION autoGen = new JButton("Auto Generate Add. Ref. Str."); selfGen = new JButton("Self Generate Add. Ref. Str."); // BITS IN MAIN MEMORY ADDRESS lBits = new JLabel(" TAG WORD"); tTag = new JTextField(9); tTag.setEditable(false); tWord = new JTextField(7); tWord.setEditable(false); // SET THE FONT STYLES FOR THE BITS IN MAIN MEMORY ADDRESS tTag.setFont(new Font("Monospaced", Font.BOLD, 14)); tWord.setFont(new Font("Monospaced", Font.BOLD, 14)); // REGISTER LISTENERS restart.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { reStart(); } }); next.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { nextClicked = true; step(); } }); back.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { nextClicked = false; step(); } }); quit.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { int confirmQuit = JOptionPane.showConfirmDialog( null, "Really Quit?", "Quit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); switch (confirmQuit) { case JOptionPane.YES_OPTION: removeInstance(); case JOptionPane.NO_OPTION: break; } } }); autoGen.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { autoGenerateString(); } }); selfGen.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { selfGenerateString(); } }); // DISABLE NAVIGATION BUTTONS FOR NOW next.setEnabled(false); back.setEnabled(false); // CREATE PANELS cachePanel = new FACachePanel(); memoryPanel = new MemoryPanel(); bottomPanel = new JPanel(); cache = new JPanel(); cacheHitsMisses = new JPanel(); pAutoSelfGen = new JPanel(); pAddRefStr = new JPanel(); pEastPanel = new JPanel(); pBitsInMM = new JPanel(); // ADD COMPONENTS TO THE PANELS // PANEL WITH PROGRESS UPDATE TEXT AREA AND NAVIGATION BUTTONS bottomPanel.add(lProgress); bottomPanel.add(progressScroll); bottomPanel.add(restart); bottomPanel.add(next); bottomPanel.add(back); bottomPanel.add(quit); // PANEL WITH CACHE BLOCKS, HITS AND MISSES INFO. cacheHitsMisses.add(lCacheHits); cacheHitsMisses.add(tCacheHits); cacheHitsMisses.add(lCacheMisses); cacheHitsMisses.add(tCacheMisses); cacheHMBorder = BorderFactory.createEtchedBorder(); cacheHitsMisses.setBorder(BorderFactory.createTitledBorder(cacheHMBorder, "")); cache.setLayout(new BorderLayout()); cache.add(cachePanel, "Center"); cache.add(cacheHitsMisses, "South"); // PANEL WITH ADDRESS REFERENCE STRING AND STRING GENERATION BUTTONS pAutoSelfGen.setLayout(new GridLayout(2, 1)); pAutoSelfGen.add(autoGen); pAutoSelfGen.add(selfGen); pAddRefStr.setLayout(new BorderLayout()); pAddRefStr.setPreferredSize(new Dimension(160, 400)); pAddRefStr.add(addRefStrScroll, "Center"); pAddRefStr.add(pAutoSelfGen, "South"); addRefStrBorder = BorderFactory.createEtchedBorder(); pAddRefStr.setBorder( BorderFactory.createTitledBorder(addRefStrBorder, " Address Reference String ")); // PANEL WITH THE MAIN MEMORY ADDRESS BITS INFO. pBitsInMM.setLayout(new BorderLayout()); bitsInMMBorder = BorderFactory.createEtchedBorder(); pBitsInMM.setBorder(BorderFactory.createTitledBorder(bitsInMMBorder, " Main Memory Address ")); pBitsInMM.add(tTag, "Center"); pBitsInMM.add(tWord, "East"); pBitsInMM.add(lBits, "South"); // PANEL CONTAINING THE ADDRESS REF. STRING PANEL AND BITS IN MM PANEL pEastPanel.setLayout(new BorderLayout()); pEastPanel.setPreferredSize(new Dimension(310, 650)); pEastPanel.add(pAddRefStr, "Center"); pEastPanel.add(pBitsInMM, "South"); // ADD COMPONENTS TO THE FRAME CONTAINER Container c = getContentPane(); c.setLayout(new BorderLayout()); c.add(cache, "West"); c.add(memoryPanel, "Center"); c.add(pEastPanel, "East"); c.add(bottomPanel, "South"); // INITIALIZE ARRAYS THAT HOLDS STATUS OF EMPTY AND LRU CACHE BLOCKS for (int i = 0; i < 16; i++) { statusCacheEmpty[i] = true; statusCacheLRU[i] = 0; } /* * CALL THE FUNCTION TO GENERATE THE ARRAY addresses, WHICH CONTAINS ALL THE POSSIBLE MEMORY ADDRESSES * THIS ARRAY WILL BE USEFUL IN THE AUTO GENERATION OF ADDRESSES AS WELL AS FOR VALIDATION OF * ADDRESS STRINGS INPUT BY THE USER IF HE/SHE CHOOSES SELF GENERATION. */ createAddresses(); pack(); } // END CONSTRUCTOR
/** * 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()); } } } }); }
// initializes the internal component of the translator protected void jbInit() { this.getContentPane().setLayout(new GridBagLayout()); loadButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { loadButton_actionPerformed(e); } }); loadButton.setMaximumSize(new Dimension(39, 39)); loadButton.setMinimumSize(new Dimension(39, 39)); loadButton.setPreferredSize(new Dimension(39, 39)); loadButton.setSize(new Dimension(39, 39)); loadButton.setToolTipText("Load Source File"); loadButton.setIcon(loadIcon); saveButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { saveButton_actionPerformed(e); } }); saveButton.setMaximumSize(new Dimension(39, 39)); saveButton.setMinimumSize(new Dimension(39, 39)); saveButton.setPreferredSize(new Dimension(39, 39)); saveButton.setSize(new Dimension(39, 39)); saveButton.setToolTipText("Save Destination File"); saveButton.setIcon(saveIcon); singleStepButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { singleStepButton_actionPerformed(e); } }); singleStepButton.setMaximumSize(new Dimension(39, 39)); singleStepButton.setMinimumSize(new Dimension(39, 39)); singleStepButton.setPreferredSize(new Dimension(39, 39)); singleStepButton.setSize(new Dimension(39, 39)); singleStepButton.setToolTipText("Single Step"); singleStepButton.setIcon(singleStepIcon); ffwdButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ffwdButton_actionPerformed(e); } }); ffwdButton.setMaximumSize(new Dimension(39, 39)); ffwdButton.setMinimumSize(new Dimension(39, 39)); ffwdButton.setPreferredSize(new Dimension(39, 39)); ffwdButton.setSize(new Dimension(39, 39)); ffwdButton.setToolTipText("Fast Forward"); ffwdButton.setIcon(ffwdIcon); rewindButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { rewindButton_actionPerformed(e); } }); rewindButton.setMaximumSize(new Dimension(39, 39)); rewindButton.setMinimumSize(new Dimension(39, 39)); rewindButton.setPreferredSize(new Dimension(39, 39)); rewindButton.setSize(new Dimension(39, 39)); rewindButton.setToolTipText("Rewind"); rewindButton.setIcon(rewindIcon); stopButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { stopButton_actionPerformed(e); } }); stopButton.setMaximumSize(new Dimension(39, 39)); stopButton.setMinimumSize(new Dimension(39, 39)); stopButton.setPreferredSize(new Dimension(39, 39)); stopButton.setSize(new Dimension(39, 39)); stopButton.setToolTipText("Stop"); stopButton.setIcon(stopIcon); fullTranslationButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { fullTranslationButton_actionPerformed(e); } }); fullTranslationButton.setMaximumSize(new Dimension(39, 39)); fullTranslationButton.setMinimumSize(new Dimension(39, 39)); fullTranslationButton.setPreferredSize(new Dimension(39, 39)); fullTranslationButton.setSize(new Dimension(39, 39)); fullTranslationButton.setToolTipText("Fast Translation"); fullTranslationButton.setIcon(fullTranslationIcon); messageLbl.setFont(Utilities.statusLineFont); messageLbl.setLineWrap(true); messageLbl.setEditable(false); messageLbl.setCursor(null); messageLbl.setOpaque(false); messageLbl.setFocusable(false); messageLblPane.setBorder(BorderFactory.createLoweredBevelBorder()); // messageLblPane.setBounds(new Rectangle(0, 672, TRANSLATOR_WIDTH - 8, 20)); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.ipadx = 0; c.ipady = 0; c.weightx = 1; c.weighty = 0; c.gridwidth = 3; c.anchor = GridBagConstraints.CENTER; c.gridx = 0; c.gridy = 2; this.getContentPane().add(messageLblPane, c); // arrowLabel.setBounds(new Rectangle(290, 324, 88, 71)); arrowLabel.setIcon(arrowIcon); // source.setVisibleRows(31); // destination.setVisibleRows(31); // source.setBounds(new Rectangle(35,100,source.getWidth(),source.getHeight())); // destination.setBounds(new Rectangle(375,100,destination.getWidth(),destination.getHeight())); c.fill = GridBagConstraints.BOTH; c.ipadx = 0; c.ipady = 0; c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.anchor = GridBagConstraints.CENTER; c.gridx = 0; c.gridy = 1; this.getContentPane().add(source, c); c.fill = GridBagConstraints.NONE; c.ipadx = 0; c.ipady = 0; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.anchor = GridBagConstraints.CENTER; c.gridx = 1; c.gridy = 1; this.getContentPane().add(arrowLabel, c); c.fill = GridBagConstraints.BOTH; c.ipadx = 0; c.ipady = 0; c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.anchor = GridBagConstraints.CENTER; c.gridx = 2; c.gridy = 1; this.getContentPane().add(destination, c); // Adding the tool bar to this container. toolBar.setFloatable(false); toolBar.setLocation(0, 0); toolBar.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 0)); toolBar.setBorder(BorderFactory.createEtchedBorder()); arrangeToolBar(); c.fill = GridBagConstraints.HORIZONTAL; c.ipadx = 0; c.ipady = 0; c.weightx = 1; c.weighty = 0; c.gridwidth = 3; c.anchor = GridBagConstraints.CENTER; c.gridx = 0; c.gridy = 0; this.getContentPane().add(toolBar, c); toolBar.revalidate(); toolBar.repaint(); repaint(); // Creating the menu bar arrangeMenu(); setJMenuBar(menuBar); // initializing the window size and visibility setDefaultCloseOperation(3); setSize(new Dimension(TRANSLATOR_WIDTH, TRANSLATOR_HEIGHT)); setVisible(true); }
/** Constructor for the class, sets up two fresh tabbed text areas for program feedback. */ public MessagesPane() { super(); this.setMinimumSize(new Dimension(0, 0)); assemble = new JTextArea(); run = new JTextArea(); assemble.setEditable(false); run.setEditable(false); // Set both text areas to mono font. For assemble // pane, will make messages more readable. For run // pane, will allow properly aligned "text graphics" // DPS 15 Dec 2008 Font monoFont = new Font(Font.MONOSPACED, Font.PLAIN, 12); assemble.setFont(monoFont); run.setFont(monoFont); JButton assembleTabClearButton = new JButton("Clear"); assembleTabClearButton.setToolTipText("Clear the Mars Messages area"); assembleTabClearButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { assemble.setText(""); } }); assembleTab = new JPanel(new BorderLayout()); assembleTab.add(createBoxForButton(assembleTabClearButton), BorderLayout.WEST); assembleTab.add( new JScrollPane( assemble, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER); assemble.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { String text; int lineStart = 0; int lineEnd = 0; try { int line = assemble.getLineOfOffset(assemble.viewToModel(e.getPoint())); lineStart = assemble.getLineStartOffset(line); lineEnd = assemble.getLineEndOffset(line); text = assemble.getText(lineStart, lineEnd - lineStart); } catch (BadLocationException ble) { text = ""; } if (text.length() > 0) { // If error or warning, parse out the line and column number. if (text.startsWith(ErrorList.ERROR_MESSAGE_PREFIX) || text.startsWith(ErrorList.WARNING_MESSAGE_PREFIX)) { assemble.select(lineStart, lineEnd); assemble.setSelectionColor(Color.YELLOW); assemble.repaint(); int separatorPosition = text.indexOf(ErrorList.MESSAGE_SEPARATOR); if (separatorPosition >= 0) { text = text.substring(0, separatorPosition); } String[] stringTokens = text.split("\\s"); // tokenize with whitespace delimiter String lineToken = ErrorList.LINE_PREFIX.trim(); String columnToken = ErrorList.POSITION_PREFIX.trim(); String lineString = ""; String columnString = ""; for (int i = 0; i < stringTokens.length; i++) { if (stringTokens[i].equals(lineToken) && i < stringTokens.length - 1) lineString = stringTokens[i + 1]; if (stringTokens[i].equals(columnToken) && i < stringTokens.length - 1) columnString = stringTokens[i + 1]; } int line = 0; int column = 0; try { line = Integer.parseInt(lineString); } catch (NumberFormatException nfe) { line = 0; } try { column = Integer.parseInt(columnString); } catch (NumberFormatException nfe) { column = 0; } // everything between FILENAME_PREFIX and LINE_PREFIX is filename. int fileNameStart = text.indexOf(ErrorList.FILENAME_PREFIX) + ErrorList.FILENAME_PREFIX.length(); int fileNameEnd = text.indexOf(ErrorList.LINE_PREFIX); String fileName = ""; if (fileNameStart < fileNameEnd && fileNameStart >= ErrorList.FILENAME_PREFIX.length()) { fileName = text.substring(fileNameStart, fileNameEnd).trim(); } if (fileName != null && fileName.length() > 0) { selectEditorTextLine(fileName, line, column); selectErrorMessage(fileName, line, column); } } } } }); JButton runTabClearButton = new JButton("Clear"); runTabClearButton.setToolTipText("Clear the Run I/O area"); runTabClearButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { run.setText(""); } }); runTab = new JPanel(new BorderLayout()); runTab.add(createBoxForButton(runTabClearButton), BorderLayout.WEST); runTab.add( new JScrollPane( run, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER); this.addTab("Mars Messages", assembleTab); this.addTab("Run I/O", runTab); this.setToolTipTextAt( 0, "Messages produced by Run menu. Click on assemble error message to select erroneous line"); this.setToolTipTextAt(1, "Simulated MIPS console input and output"); }
/** Create a font chooser dialog for the specified frame. */ public FontChooser(Frame owner) { super(owner, "Choose a Font"); // Set dialog frame and title // This dialog must be used as a modal dialog. In order to be used // as a modeless dialog, it would have to fire a PropertyChangeEvent // whenever the selected font changed, so that applications could be // notified of the user's selections. setModal(true); // Figure out what fonts are available on the system GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); fontFamilies = env.getAvailableFontFamilyNames(); // Set initial values for the properties family = fontFamilies[0]; style = Font.PLAIN; size = 18; selectedFont = new Font(family, style, size); // Create ItemChooser objects that allow the user to select font // family, style, and size. families = new ItemChooser("Family", fontFamilies, null, 0, ItemChooser.COMBOBOX); styles = new ItemChooser("Style", styleNames, styleValues, 0, ItemChooser.COMBOBOX); sizes = new ItemChooser("Size", sizeNames, null, 4, ItemChooser.COMBOBOX); // Now register event listeners to handle selections families.addItemChooserListener( new ItemChooser.Listener() { public void itemChosen(ItemChooser.Event e) { setFontFamily((String) e.getSelectedValue()); } }); styles.addItemChooserListener( new ItemChooser.Listener() { public void itemChosen(ItemChooser.Event e) { setFontStyle(((Integer) e.getSelectedValue()).intValue()); } }); sizes.addItemChooserListener( new ItemChooser.Listener() { public void itemChosen(ItemChooser.Event e) { setFontSize(Integer.parseInt((String) e.getSelectedValue())); } }); // Create a component to preview the font. preview = new JTextArea(defaultPreviewString, 5, 40); preview.setFont(selectedFont); // Create buttons to dismiss the dialog, and set handlers on them okay = new JButton("Okay"); cancel = new JButton("Cancel"); okay.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { hide(); } }); cancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { selectedFont = null; hide(); } }); // Put the ItemChoosers in a Box Box choosersBox = Box.createHorizontalBox(); choosersBox.add(Box.createHorizontalStrut(15)); choosersBox.add(families); choosersBox.add(Box.createHorizontalStrut(15)); choosersBox.add(styles); choosersBox.add(Box.createHorizontalStrut(15)); choosersBox.add(sizes); choosersBox.add(Box.createHorizontalStrut(15)); choosersBox.add(Box.createGlue()); // Put the dismiss buttons in another box Box buttonBox = Box.createHorizontalBox(); buttonBox.add(Box.createGlue()); buttonBox.add(okay); buttonBox.add(Box.createGlue()); buttonBox.add(cancel); buttonBox.add(Box.createGlue()); // Put the choosers at the top, the buttons at the bottom, and // the preview in the middle. Container contentPane = getContentPane(); contentPane.add(new JScrollPane(preview), BorderLayout.CENTER); contentPane.add(choosersBox, BorderLayout.NORTH); contentPane.add(buttonBox, BorderLayout.SOUTH); // Set the dialog size based on the component size. pack(); }
// This method is called when the family, style, or size changes protected void changeFont() { selectedFont = new Font(family, style, size); preview.setFont(selectedFont); }
/** * Initialisiere die obere Leiste, in welcher Messergebnisse und Einschätzungen geladen,<br> * eine Formel eingegeben (berechnet oder durch ausprobieren der Platzhalter ausgewertet),<br> * die Bewertungsergebnisse angezeigt werden. */ private void initTopPane() { setLayout(new BorderLayout()); JPanel topPane = new JPanel(new GridLayout(12, 2)); initResultSelectionPanel(topPane); initEstimationsSelectionPanel(topPane); topPane.add(new JLabel("Variables:")); variablesArea = new JTextArea(1, 30); variablesArea.setEditable(false); variablesArea.setLineWrap(true); Font fnt = new Font("Monospaced", Font.PLAIN, 11); variablesArea.setFont(fnt); topPane.add(new JScrollPane(variablesArea)); topPane.add(new JLabel("Mode: ")); modeCombo = new JComboBox(new String[] {"Test effort estimation", "Bug count estimation"}); modeCombo.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent itemEvent) { mode = modeCombo.getSelectedIndex() == 0 ? PredictionType.TestEffort : PredictionType.BugCount; benchmarkTableModel.setMode(mode); benchmarkTable.updateUI(); } }); topPane.add(modeCombo); topPane.add(new JLabel("Option:")); zeroIsInvalidCheckbox = new JCheckBox("Zero is invalid", false); topPane.add(zeroIsInvalidCheckbox); topPane.add(new JLabel("Prediction equation:")); JPanel equationPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); equationField = new JTextField("0"); equationField.setColumns(35); equationField.getDocument().addDocumentListener(new EquationChangeListener()); equationPanel.add(equationField); JButton computeBtn = new JButton("Compute"); computeBtn.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { eqtnChanged(); } }); equationPanel.add(computeBtn); JButton enumerateBtn = new JButton("Enumerate"); enumerateBtn.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String winner = null; try { winner = Benchmark.enumerate( equationField.getText(), metricsData, respProjs, mode, zeroIsInvalidCheckbox.isSelected()); } catch (Exception e1) { e1.printStackTrace(); } if (winner == null) { return; } equationField.setText(winner); eqtnChanged(); } }); equationPanel.add(enumerateBtn); topPane.add(equationPanel); topPane.add(new JLabel("# Correct order predictions:")); numCorrLbl = new JLabel("0"); topPane.add(numCorrLbl); topPane.add(new JLabel("Total number of valid order estimations:")); numEstimationsLbl = new JLabel("0"); topPane.add(numEstimationsLbl); topPane.add(new JLabel("Percentage of correct orderings:")); percCorrLbl = new JLabel("0%"); topPane.add(percCorrLbl); topPane.add(new JLabel("# Correct order predictions weighted:")); weightedNumCorrLbl = new JLabel("0"); topPane.add(weightedNumCorrLbl); topPane.add(new JLabel("Total weight sum of valid estimators:")); weightSumLbl = new JLabel("0"); topPane.add(weightSumLbl); topPane.add(new JLabel("Percentage of weighted correct orderings:")); percWeightCorrLbl = new JLabel("0%"); topPane.add(percWeightCorrLbl); add(topPane, BorderLayout.NORTH); }
public static JTextArea getTextArea(String s) { JTextArea ret = new JTextArea(s); ret.setFont(new Font("Courier", Font.PLAIN, 12)); ret.setTabSize(4); return ret; }
/** ** 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); }
public PartitionModelPanel(final PartitionSubstitutionModel partitionModel) { super(12, (OSType.isMac() ? 6 : 24)); this.model = partitionModel; initCodonPartitionComponents(); PanelUtils.setupComponent(nucSubstCombo); nucSubstCombo.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { model.setNucSubstitutionModel((NucModelType) nucSubstCombo.getSelectedItem()); } }); nucSubstCombo.setToolTipText("<html>Select the type of nucleotide substitution model.</html>"); PanelUtils.setupComponent(aaSubstCombo); aaSubstCombo.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { AminoAcidModelType type = (AminoAcidModelType) aaSubstCombo.getSelectedItem(); model.setAaSubstitutionModel(type); citationText.setText(type.getCitation().toString()); } }); aaSubstCombo.setToolTipText("<html>Select the type of amino acid substitution model.</html>"); PanelUtils.setupComponent(binarySubstCombo); binarySubstCombo.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { model.setBinarySubstitutionModel((BinaryModelType) binarySubstCombo.getSelectedItem()); useAmbiguitiesTreeLikelihoodCheck.setSelected( binarySubstCombo.getSelectedItem() == BinaryModelType.BIN_COVARION); useAmbiguitiesTreeLikelihoodCheck.setEnabled( binarySubstCombo.getSelectedItem() != BinaryModelType.BIN_COVARION); } }); binarySubstCombo.setToolTipText("<html>Select the type of binary substitution model.</html>"); PanelUtils.setupComponent(useAmbiguitiesTreeLikelihoodCheck); useAmbiguitiesTreeLikelihoodCheck.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { model.setUseAmbiguitiesTreeLikelihood(useAmbiguitiesTreeLikelihoodCheck.isSelected()); } }); useAmbiguitiesTreeLikelihoodCheck.setToolTipText( "<html>Detemine useAmbiguities in < treeLikelihood > .</html>"); PanelUtils.setupComponent(frequencyCombo); frequencyCombo.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { model.setFrequencyPolicy((FrequencyPolicyType) frequencyCombo.getSelectedItem()); } }); frequencyCombo.setToolTipText( "<html>Select the policy for determining the base frequencies.</html>"); PanelUtils.setupComponent(heteroCombo); heteroCombo.setToolTipText( "<html>Select the type of site-specific rate<br>heterogeneity model.</html>"); heteroCombo.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { boolean gammaHetero = heteroCombo.getSelectedIndex() == 1 || heteroCombo.getSelectedIndex() == 3; model.setGammaHetero(gammaHetero); model.setInvarHetero( heteroCombo.getSelectedIndex() == 2 || heteroCombo.getSelectedIndex() == 3); if (gammaHetero) { gammaCatLabel.setEnabled(true); gammaCatCombo.setEnabled(true); } else { gammaCatLabel.setEnabled(false); gammaCatCombo.setEnabled(false); } if (codingCombo.getSelectedIndex() != 0) { heteroUnlinkCheck.setEnabled(heteroCombo.getSelectedIndex() != 0); heteroUnlinkCheck.setSelected(heteroCombo.getSelectedIndex() != 0); } } }); PanelUtils.setupComponent(gammaCatCombo); gammaCatCombo.setToolTipText( "<html>Select the number of categories to use for<br>the discrete gamma rate heterogeneity model.</html>"); gammaCatCombo.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { model.setGammaCategories(gammaCatCombo.getSelectedIndex() + 4); } }); setYang96Button = new JButton("Use Yang96 model"); setYang96Button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { setYang96Model(); } }); PanelUtils.setupComponent(setYang96Button); setYang96Button.setToolTipText( "<html>Sets a 3 codon-position model with independent GTR and Gamma as described in<br>" + "Yang (1996) <i>J Mol Evol</i> <b>42</b>: 587–596. This model is named 3' in this paper.</html>"); setSRD06Button = new JButton("Use SRD06 model"); setSRD06Button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { setSRD06Model(); } }); PanelUtils.setupComponent(setSRD06Button); setSRD06Button.setToolTipText( "<html>Sets the SRD06 model as described in<br>" + "Shapiro, Rambaut & Drummond (2006) <i>MBE</i> <b>23</b>: 7-9.</html>"); citationText = new JTextArea(1, 40); citationText.setLineWrap(true); citationText.setWrapStyleWord(true); citationText.setEditable(false); citationText.setFont(this.getFont()); citationText.setOpaque(false); AminoAcidModelType type = (AminoAcidModelType) aaSubstCombo.getSelectedItem(); citationText.setText(type.getCitation().toString()); dolloCheck.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (dolloCheck.isSelected()) { binarySubstCombo.setSelectedIndex(0); binarySubstCombo.setEnabled(false); useAmbiguitiesTreeLikelihoodCheck.setSelected(true); useAmbiguitiesTreeLikelihoodCheck.setEnabled(false); frequencyCombo.setEnabled(false); frequencyCombo.setSelectedItem(FrequencyPolicyType.EMPIRICAL); heteroCombo.setSelectedIndex(0); heteroCombo.setEnabled(false); model.setBinarySubstitutionModel(BinaryModelType.BIN_DOLLO); model.setDolloModel(true); DolloComponentOptions comp = (DolloComponentOptions) model.getOptions().getComponentOptions(DolloComponentOptions.class); comp.createParameters(model.getOptions()); comp.setActive(true); } else { binarySubstCombo.setEnabled(true); useAmbiguitiesTreeLikelihoodCheck.setEnabled(true); frequencyCombo.setEnabled(true); heteroCombo.setEnabled(true); model.setBinarySubstitutionModel( (BinaryModelType) binarySubstCombo.getSelectedItem()); model.setDolloModel(false); } } }); PanelUtils.setupComponent(dolloCheck); // dolloCheck.addChangeListener(new ChangeListener() { // public void stateChanged(ChangeEvent e) { // model.setDolloModel(true); // } // }); dolloCheck.setEnabled(true); dolloCheck.setToolTipText( "<html>Activates a Stochastic Dollo model as described in<br>" + "Alekseyenko, Lee & Suchard (2008) <i>Syst Biol</i> <b>57</b>: 772-784.</html>"); PanelUtils.setupComponent(discreteTraitSiteModelCombo); discreteTraitSiteModelCombo.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { model.setDiscreteSubstType( (DiscreteSubstModelType) discreteTraitSiteModelCombo.getSelectedItem()); } }); PanelUtils.setupComponent(continuousTraitSiteModelCombo); continuousTraitSiteModelCombo.setToolTipText( "<html>Select the model of continuous random walk, either homogenous<br>" + "or relaxed random walk (RRW) with a choice of distributions.</html>"); continuousTraitSiteModelCombo.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { model.setContinuousSubstModelType( (ContinuousSubstModelType) continuousTraitSiteModelCombo.getSelectedItem()); } }); PanelUtils.setupComponent(latLongCheck); latLongCheck.setToolTipText( "<html>Specify whether this is a geographical trait representing <br>" + "latitude and longitude. Provides appropriate statistics to log file.</html>"); latLongCheck.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { model.setIsLatitudeLongitude(latLongCheck.isSelected()); } }); latLongCheck.setEnabled(false); PanelUtils.setupComponent(useLambdaCheck); useLambdaCheck.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { ContinuousComponentOptions component = (ContinuousComponentOptions) model.getOptions().getComponentOptions(ContinuousComponentOptions.class); component.setUseLambda(model, useLambdaCheck.isSelected()); } }); useLambdaCheck.setToolTipText( "<html>Estimate degree of phylogenetic correlation in continuous traits using <br>" + "a tree transform. Inspired by Pagel (1999), described in Lemey et al (2013) <i>in prep</i></html>"); PanelUtils.setupComponent(activateBSSVS); activateBSSVS.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { model.setActivateBSSVS(activateBSSVS.isSelected()); } }); activateBSSVS.setToolTipText( "<html>Activates Bayesian stochastic search variable selection on the rates as described in<br>" + "Lemey, Rambaut, Drummond & Suchard (2009) <i>PLoS Computational Biology</i> <b>5</b>: e1000520</html>"); // ============ micro-sat ================ microsatName.setColumns(30); microsatName.addKeyListener( new java.awt.event.KeyListener() { public void keyTyped(KeyEvent e) {} public void keyPressed(KeyEvent e) {} public void keyReleased(KeyEvent e) { model.getMicrosatellite().setName(microsatName.getText()); } }); microsatMax.setColumns(10); microsatMax.addKeyListener( new java.awt.event.KeyListener() { public void keyTyped(KeyEvent e) {} public void keyPressed(KeyEvent e) {} public void keyReleased(KeyEvent e) { model.getMicrosatellite().setMax(Integer.parseInt(microsatMax.getText())); } }); microsatMin.setColumns(10); microsatMin.addKeyListener( new java.awt.event.KeyListener() { public void keyTyped(KeyEvent e) {} public void keyPressed(KeyEvent e) {} public void keyReleased(KeyEvent e) { model.getMicrosatellite().setMin(Integer.parseInt(microsatMin.getText())); } }); PanelUtils.setupComponent(shareMicroSatCheck); shareMicroSatCheck.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { model.getOptions().shareMicroSat = shareMicroSatCheck.isSelected(); if (shareMicroSatCheck.isSelected()) { model.getOptions().shareMicroSat(); } else { model.getOptions().unshareMicroSat(); } setOptions(); } }); PanelUtils.setupComponent(rateProportionCombo); rateProportionCombo.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { model.setRatePorportion( (MicroSatModelType.RateProportionality) rateProportionCombo.getSelectedItem()); } }); // rateProportionCombo.setToolTipText("<html>Select the type of microsatellite substitution // model.</html>"); PanelUtils.setupComponent(mutationBiasCombo); mutationBiasCombo.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { model.setMutationBias( (MicroSatModelType.MutationalBias) mutationBiasCombo.getSelectedItem()); } }); PanelUtils.setupComponent(phaseCombo); phaseCombo.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ev) { model.setPhase((MicroSatModelType.Phase) phaseCombo.getSelectedItem()); } }); setupPanel(); setOpaque(false); }
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); }