source: src/main/java/weka/gui/scripting/JythonPanel.java @ 9

Last change on this file since 9 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 4.4 KB
Line 
1/*
2 *    This program is free software; you can redistribute it and/or modify
3 *    it under the terms of the GNU General Public License as published by
4 *    the Free Software Foundation; either version 2 of the License, or
5 *    (at your option) any later version.
6 *
7 *    This program is distributed in the hope that it will be useful,
8 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 *    GNU General Public License for more details.
11 *
12 *    You should have received a copy of the GNU General Public License
13 *    along with this program; if not, write to the Free Software
14 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17/*
18 * JythonPanel.java
19 * Copyright (C) 2009 University of Waikato, Hamilton, New Zealand
20 */
21
22package weka.gui.scripting;
23
24import weka.core.Utils;
25import weka.gui.BrowserHelper;
26import weka.gui.ComponentHelper;
27import weka.gui.visualize.VisualizeUtils;
28
29import java.awt.BorderLayout;
30import java.awt.Color;
31import java.awt.Font;
32import java.awt.GridLayout;
33import java.util.Properties;
34
35import javax.swing.BorderFactory;
36import javax.swing.ImageIcon;
37import javax.swing.JLabel;
38import javax.swing.JPanel;
39import javax.swing.JTextPane;
40import javax.swing.text.Document;
41
42/**
43 * A scripting panel for <a href="http://www.jython.org/" target="_blank">Jython</a>.
44 *
45 * @author  fracpete (fracpete at waikato dot ac dot nz)
46 * @version $Revision: 5837 $
47 */
48public class JythonPanel
49  extends FileScriptingPanel {
50 
51  /** for serialization. */
52  private static final long serialVersionUID = -827358576217085413L;
53 
54  /** the Groovy setup. */
55  public final static String PROPERTIES_FILE = "weka/gui/scripting/Jython.props";
56 
57  /**
58   * Creates a new JTextPane for the code.
59   *
60   * @return            the text pane
61   */
62  protected JTextPane newCodePane() {
63    JTextPane           result;
64    SyntaxDocument      doc;
65    Properties          props;
66   
67    try {
68      props = Utils.readProperties(PROPERTIES_FILE);
69    }
70    catch (Exception e) {
71      e.printStackTrace();
72      props = new Properties();
73    }
74   
75    result = new JTextPane();
76    if (props.getProperty("Syntax", "false").equals("true")) {
77      doc    = new SyntaxDocument(props);
78      result.setDocument(doc);
79      result.setBackground(doc.getBackgroundColor());
80    }
81    else {
82      result.setForeground(VisualizeUtils.processColour(props.getProperty("ForegroundColor", "black"), Color.BLACK));
83      result.setBackground(VisualizeUtils.processColour(props.getProperty("BackgroundColor", "white"), Color.WHITE));
84      result.setFont(new Font(props.getProperty("FontName", "monospaced"), Font.PLAIN, Integer.parseInt(props.getProperty("FontSize", "12"))));
85    }
86   
87    return result;
88  }
89 
90  /**
91   * Returns an icon to be used in a frame.
92   *
93   * @return            the icon
94   */
95  public ImageIcon getIcon() {
96    return ComponentHelper.getImageIcon(IMAGES_DIR + "/jython_small.png");
97  }
98 
99  /**
100   * Returns a panel to be displayed with the AboutAction.
101   *
102   * @return            the panel with some information on the scripting panel
103   */
104  protected JPanel getAboutPanel() {
105    JPanel      result;
106    JPanel      panel;
107   
108    result = new JPanel(new BorderLayout());
109    result.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
110   
111    // image
112    result.add(new JLabel(ComponentHelper.getImageIcon(IMAGES_DIR + "/jython_medium.png")), BorderLayout.CENTER);
113   
114    // links
115    panel = new JPanel(new GridLayout(5, 1));
116    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
117    result.add(panel, BorderLayout.SOUTH);
118   
119    panel.add(new JLabel("Jython homepage"));
120    panel.add(BrowserHelper.createLink("http://www.jython.org/", null));
121    panel.add(new JLabel(" "));
122    panel.add(new JLabel("Weka and Jython"));
123    panel.add(BrowserHelper.createLink("http://weka.wikispaces.com/Using+Weka+from+Jython", null));
124   
125    return result;
126  }
127
128  /**
129   * Returns the title (without the filename).
130   *
131   * @return            the plain title
132   */
133  public String getPlainTitle() {
134    return "Jython Console";
135  }
136
137  /**
138   * Returns an initialized script object.
139   *
140   * @param doc         the document to use as basis
141   * @return            the initialized script
142   */
143  protected Script newScript(Document doc) {
144    return new JythonScript(doc);
145  }
146 
147  /**
148   * Displays the panel in a frame.
149   *
150   * @param args        can take a file as first argument
151   */
152  public static void main(String[] args) {
153    showPanel(new JythonPanel(), args);
154  }
155}
Note: See TracBrowser for help on using the repository browser.