示例#1
0
 // Many of the following methods have been added purely
 // so InternalFunctions can work.  Originally, the code in
 // that class was inline here, so its functions had direct
 // access.  I removed it so that students do not need to wade
 // through all the functions!  But, that leaves the question as
 // to what to do with the following methods, but I don't think
 // there's much you can do ...
 public void changeSize(int width, int height) {
   setSize(width, height);
   Component top = splitPane.getTopComponent();
   Component bottom = splitPane.getBottomComponent();
   int totalHeight = top.getHeight() + bottom.getHeight();
   int topHeight = (totalHeight * topProportion) / 100;
   int bottomHeight = (totalHeight * bottomProportion) / 100;
   top.setPreferredSize(new Dimension(width - 10, topHeight));
   bottom.setPreferredSize(new Dimension(width - 10, bottomHeight));
   splitPane.resetToPreferredSizes();
   pack();
 }
示例#2
0
文件: GUIUtil.java 项目: Uefix/cibot
  public static void forceSize(Component component, Dimension size) {
    Preconditions.checkArgument(component != null);
    Preconditions.checkArgument(size != null);

    component.setMinimumSize(size);
    component.setPreferredSize(size);
    component.setMaximumSize(size);
    component.setSize(size);
  }
示例#3
0
  private void setupUI1() {
    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    left = new JPanel();
    left.setPreferredSize(new Dimension(100, 100));

    JPanel rightPanel = new JPanel();
    rightPanel.setPreferredSize(new Dimension(100, 50));
    Component right = new JScrollPane(rightPanel);

    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);

    frame = new JFrame();
    frame.add(split);
    frame.pack();
  }
示例#4
0
  public InterpreterFrame() {
    super("Simple Lisp Interpreter");

    // Create the menu
    menubar = buildMenuBar();
    setJMenuBar(menubar);
    // Create the toolbar
    toolbar = buildToolBar();
    // disable cut and copy actions
    cutAction.setEnabled(false);
    copyAction.setEnabled(false);
    // Setup text area for editing source code
    // and setup document listener so interpreter
    // is notified when current file modified and
    // when the cursor is moved.
    textView = buildEditor();
    textView.getDocument().addDocumentListener(this);
    textView.addCaretListener(this);

    // set default key bindings
    bindKeyToCommand("ctrl C", "(buffer-copy)");
    bindKeyToCommand("ctrl X", "(buffer-cut)");
    bindKeyToCommand("ctrl V", "(buffer-paste)");
    bindKeyToCommand("ctrl E", "(buffer-eval)");
    bindKeyToCommand("ctrl O", "(file-open)");
    bindKeyToCommand("ctrl S", "(file-save)");
    bindKeyToCommand("ctrl Q", "(exit)");

    // Give text view scrolling capability
    Border border =
        BorderFactory.createCompoundBorder(
            BorderFactory.createEmptyBorder(3, 3, 3, 3),
            BorderFactory.createLineBorder(Color.gray));
    JScrollPane topSplit = addScrollers(textView);
    topSplit.setBorder(border);

    // Create tabbed pane for console/problems
    consoleView = makeConsoleArea(10, 50, true);
    problemsView = makeConsoleArea(10, 50, false);
    tabbedPane = buildProblemsConsole();

    // Plug the editor and problems/console together
    // using a split pane. This allows one to change
    // their relative size using the split-bar in
    // between them.
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topSplit, tabbedPane);

    // Create status bar
    statusView = new JLabel(" Status");
    lineNumberView = new JLabel("0:0");
    statusbar = buildStatusBar();

    // Now, create the outer panel which holds
    // everything together
    outerpanel = new JPanel();
    outerpanel.setLayout(new BorderLayout());
    outerpanel.add(toolbar, BorderLayout.PAGE_START);
    outerpanel.add(splitPane, BorderLayout.CENTER);
    outerpanel.add(statusbar, BorderLayout.SOUTH);
    getContentPane().add(outerpanel);

    // tell frame to fire a WindowsListener event
    // but not to close when "x" button clicked.
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(this);
    // set minimised icon to use
    setIconImage(makeImageIcon("spi.png").getImage());

    // setup additional internal functions
    InternalFunctions.setup_internals(interpreter, this);

    // set default window size
    Component top = splitPane.getTopComponent();
    Component bottom = splitPane.getBottomComponent();
    top.setPreferredSize(new Dimension(100, 400));
    bottom.setPreferredSize(new Dimension(100, 200));
    pack();

    // load + run user configuration file (if there is one)
    String homedir = System.getProperty("user.home");
    try {
      interpreter.load(homedir + "/.simplelisp");
    } catch (FileNotFoundException e) {
      // do nothing if file does not exist!
      System.out.println("Didn't find \"" + homedir + "/.simplelisp\"");
    }

    textView.grabFocus();
    setVisible(true);

    // redirect all I/O to problems/console
    redirectIO();

    // start highlighter thread
    highlighter = new DisplayThread(250);
    highlighter.setDaemon(true);
    highlighter.start();
  }
示例#5
0
 /**
  * Sets the scaled component height, adopting the original component width.
  *
  * @param comp component
  * @param h height
  */
 public static void setHeight(final Component comp, final int h) {
   comp.setPreferredSize(new Dimension(comp.getPreferredSize().width, (int) (h * scale)));
 }
示例#6
0
 /**
  * Sets the scaled component width, adopting the original component height.
  *
  * @param comp component
  * @param w width
  */
 public static void setWidth(final Component comp, final int w) {
   comp.setPreferredSize(new Dimension((int) (w * scale), comp.getPreferredSize().height));
 }