示例#1
0
  /**
   * Connect to the site at certain index of tab page.
   *
   * @param site site to be connected.
   * @param index the index of tab page corresponding to this site.
   */
  public void connect(final Site site, final int index) {
    final SessionPane session = new SessionPane(site, terminalImage);

    // index 為連線後放在第幾個分頁,若為 -1 表開新分頁。
    if (index == -1) {
      model.getSessions().add(session);

      // 一開始預設 icon 是連線中斷
      final ImageIcon icon = closedIcon;

      tabbedPane.addTab(site.getName(), icon, session, site.getHost());
      tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
    } else {
      model.getSessions().setElementAt(session, index);
      tabbedPane.setComponentAt(index, session);
    }

    // 每個 session 都是一個 thread, 解決主程式被 block 住的問題。
    new Thread(session).start();
  }
示例#2
0
  @Override
  public void observe(Event event) {
    if (event instanceof ServerNewGameStateEvent) {
      MachineState s = ((ServerNewGameStateEvent) event).getState();
      // TODO: Perhaps this should run in a separate thread, as in the
      // VisualizationPanel, in case these states are very large.
      JPanel statePanel = new JPanel();
      List<String> sentences = new ArrayList<String>();
      for (GdlSentence sentence : s.getContents()) sentences.add(sentence.toString());
      // The list of sentences is more useful when sorted alphabetically.
      Collections.sort(sentences);
      StringBuffer sentencesList = new StringBuffer();
      for (String sentence : sentences) sentencesList.append(sentence).append("\n");
      JTextArea statesTextArea = new JTextArea(sentencesList.toString());
      statesTextArea.setEditable(false);
      JScrollPane scrollPane = new JScrollPane(statesTextArea);
      scrollPane.setPreferredSize(new Dimension(400, 500));
      statePanel.add(scrollPane);

      // Add the panel as a new tab
      // Reusing the VisualizationPanel code, to make it easier in case this gets
      // moved off into a new thread
      int stepNum = stepCount;
      stepCount++;
      boolean atEnd = (tabs.getSelectedIndex() == tabs.getTabCount() - 1);

      for (int i = tabs.getTabCount(); i < stepNum; i++)
        tabs.add(new Integer(i + 1).toString(), new JPanel());
      tabs.setComponentAt(stepNum - 1, statePanel);
      tabs.setTitleAt(stepNum - 1, new Integer(stepNum).toString());

      if (atEnd) {
        tabs.setSelectedIndex(tabs.getTabCount() - 1);
      }
    }
  }
示例#3
0
  public static void createTabItem(ActionContext actionContext) {
    Thing self = (Thing) actionContext.get("self");
    JTabbedPane parent = (JTabbedPane) actionContext.get("parent");

    Thing thing = self.getThing("Component@0");
    if (thing != null) {
      try {
        Bindings bindings = actionContext.push();
        bindings.put("parent", null);

        for (Thing child : thing.getChilds()) {
          Component c = (Component) child.doAction("create", actionContext);
          if (c != null) {
            int index = parent.getTabCount();
            parent.setComponentAt(index, c);

            Color background = AwtCreator.createColor(thing, "background", actionContext);
            if (background != null) {
              parent.setBackgroundAt(index, background);
            }

            Icon disabledIcon = SwingCreator.createIcon(thing, "disabledIcon", actionContext);
            if (disabledIcon != null) {
              parent.setDisabledIconAt(index, disabledIcon);
            }

            Integer displayedMnemonicIndex =
                JavaCreator.createInteger(thing, "displayedMnemonicIndex");
            if (displayedMnemonicIndex != null) {
              parent.setDisplayedMnemonicIndexAt(index, displayedMnemonicIndex);
            }

            Boolean enabled = JavaCreator.createBoolean(thing, "enabled");
            if (enabled != null) {
              parent.setEnabledAt(index, enabled);
            }

            Color foreground = AwtCreator.createColor(thing, "foreground", actionContext);
            if (foreground != null) {
              parent.setForeground(foreground);
            }

            Icon icon = SwingCreator.createIcon(thing, "icon", actionContext);
            if (icon != null) {
              parent.setIconAt(index, icon);
            }

            Integer mnemonic = AwtCreator.createMnemonic(thing, "mnemonic");
            if (mnemonic != null) {
              parent.setMnemonicAt(index, mnemonic);
            }

            Boolean selected = JavaCreator.createBoolean(thing, "selected");
            if (selected != null && selected) {
              parent.setSelectedIndex(index);
            }

            String title = JavaCreator.createText(thing, "title", actionContext);
            if (title != null) {
              parent.setTitleAt(index, title);
            }

            String toolTipText = JavaCreator.createText(thing, "toolTipText", actionContext);
            if (toolTipText != null) {
              parent.setToolTipTextAt(index, toolTipText);
            }
            break;
          }
        }
      } finally {
        actionContext.pop();
      }
    }
  }