/** Creates the error area component. */
 private void initErrorArea() {
   SimpleAttributeSet attribs = new SimpleAttributeSet();
   StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_RIGHT);
   StyleConstants.setFontFamily(attribs, errorPane.getFont().getFamily());
   StyleConstants.setForeground(attribs, Color.RED);
   errorPane.setParagraphAttributes(attribs, true);
   errorPane.setPreferredSize(new Dimension(100, 50));
   errorPane.setMinimumSize(new Dimension(100, 50));
   errorPane.setOpaque(false);
 }
示例#2
1
  public JWrapLabel(String txt) {
    super();
    setEditable(false);
    setText(txt);

    SimpleAttributeSet set = new SimpleAttributeSet();
    StyleConstants.setAlignment(set, StyleConstants.ALIGN_CENTER);
    StyleConstants.setFontFamily(set, "Arial");
    StyleConstants.setFontSize(set, 13);
    setParagraphAttributes(set, true);
  }
示例#3
1
  private void updateTemplateFromEditor(PrintfTemplate template) {
    ArrayList params = new ArrayList();
    String format = null;
    int text_length = editorPane.getDocument().getLength();
    try {
      format = editorPane.getDocument().getText(0, text_length);
    } catch (BadLocationException ex1) {
    }
    Element section_el = editorPane.getDocument().getDefaultRootElement();
    // Get number of paragraphs.
    int num_para = section_el.getElementCount();
    for (int p_count = 0; p_count < num_para; p_count++) {
      Element para_el = section_el.getElement(p_count);
      // Enumerate the content elements
      int num_cont = para_el.getElementCount();
      for (int c_count = 0; c_count < num_cont; c_count++) {
        Element content_el = para_el.getElement(c_count);
        AttributeSet attr = content_el.getAttributes();
        // Get the name of the style applied to this content element; may be null
        String sn = (String) attr.getAttribute(StyleConstants.NameAttribute);
        // Check if style name match
        if (sn != null && sn.startsWith("Parameter")) {
          // we extract the label.
          JLabel l = (JLabel) StyleConstants.getComponent(attr);
          if (l != null) {
            params.add(l.getName());
          }
        }
      }
    }

    template.setFormat(format);
    template.setTokens(params);
  }
 /**
  * Sets the insets from the paragraph attributes specified in the given attributes.
  *
  * @param attr the attributes
  */
 protected void setParagraphInsets(AttributeSet attr) {
   // Since version 1.1 doesn't have scaling and assumes
   // a pixel is equal to a point, we just cast the point
   // sizes to integers.
   top = (short) StyleConstants.getSpaceAbove(attr);
   left = (short) StyleConstants.getLeftIndent(attr);
   bottom = (short) StyleConstants.getSpaceBelow(attr);
   right = (short) StyleConstants.getRightIndent(attr);
 }
 private void initializeStyles() {
   errorStyle =
       doc.addStyle(
           "errorStyle",
           StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE));
   errorStyleRed = doc.addStyle("errorStyleRed", errorStyle);
   StyleConstants.setForeground(errorStyleRed, Color.RED);
   errorStyleMono = doc.addStyle("errorStyleMono", errorStyle);
   StyleConstants.setFontFamily(errorStyleMono, "Monospaced");
 }
    private void loadStyles(StyledDocument doc) {
      Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
      StyleConstants.setFontFamily(def, "Courier New");

      // Add normal style
      Style normal = doc.addStyle("normal", def);
      StyleConstants.setForeground(def, Color.LIGHT_GRAY);

      // Add highlighted style from normal
      Style red = doc.addStyle("red", normal);
      StyleConstants.setForeground(red, Color.RED);
    }
示例#7
0
  /** Creates the text area. */
  private void initTextArea() {
    textArea.setOpaque(false);
    textArea.setEditable(false);
    StyledDocument doc = textArea.getStyledDocument();

    MutableAttributeSet standard = new SimpleAttributeSet();
    StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER);
    StyleConstants.setFontFamily(standard, textArea.getFont().getFamily());
    StyleConstants.setFontSize(standard, 12);
    doc.setParagraphAttributes(0, 0, standard, true);

    parentWindow.addSearchFieldListener(this);
  }
  private void _applyFontStyleForSelection(Font font) {
    StyledDocument doc = mTextEditor.getStyledDocument();
    MutableAttributeSet attrs = mTextEditor.getInputAttributes();
    StyleConstants.setFontFamily(attrs, font.getFamily());
    StyleConstants.setFontSize(attrs, font.getSize());
    StyleConstants.setBold(attrs, ((font.getStyle() & Font.BOLD) != 0));
    StyleConstants.setItalic(attrs, ((font.getStyle() & Font.ITALIC) != 0));
    StyleConstants.setUnderline(attrs, ((font.getStyle() & Font.CENTER_BASELINE) != 0));

    int start = mTextEditor.getSelectionStart();
    int end = mTextEditor.getSelectionEnd();
    doc.setCharacterAttributes(start, (end - start), attrs, false);
  }
示例#9
0
  public JConsole() {
    super();

    setBackground(new Color(70, 70, 70));
    setForeground(Color.WHITE);
    text = new MyJTextPane();

    text.setAutoscrolls(true);
    final Font lFont = new Font("Monospaced", Font.PLAIN, 15);
    text.setText("");
    text.setFont(lFont);
    text.setMargin(new Insets(5, 3, 5, 3));
    text.addKeyListener(new MyKeyListener());
    setViewportView(text);

    contextMenu = new JPopupMenu();
    final ActionListener lActionListener = new MyActionListener();
    contextMenu.add(new JMenuItem(CMD_CUT)).addActionListener(lActionListener);
    contextMenu.add(new JMenuItem(CMD_COPY)).addActionListener(lActionListener);
    contextMenu.add(new JMenuItem(CMD_PASTE)).addActionListener(lActionListener);
    text.addMouseListener(new MyMouseListener());

    MutableAttributeSet attr = new SimpleAttributeSet();
    StyleConstants.setForeground(attr, Color.BLACK);

    attr = new SimpleAttributeSet();
    StyleConstants.setForeground(attr, Color.WHITE);
    attrOut = attr;

    attr = new SimpleAttributeSet();
    StyleConstants.setForeground(attr, Color.RED);
    StyleConstants.setItalic(attr, true);
    StyleConstants.setBold(attr, true);
    attrError = attr;

    try {
      fromConsoleStream = new PipedOutputStream();
      in = new PipedInputStream((PipedOutputStream) fromConsoleStream);

      final PipedOutputStream lOutPipe = new PipedOutputStream();
      out = new PrintStream(lOutPipe);

      final PipedOutputStream lErrPipe = new PipedOutputStream();
      err = new PrintStream(lErrPipe);

    } catch (IOException e) {
      e.printStackTrace();
    }
    requestFocus();
  }
 public void coloration() {
   String text = editor.getTextPaneEditor().getText().replaceAll("\n", " ");
   final StyledDocument doc = editor.getTextPaneEditor().getStyledDocument();
   final MutableAttributeSet normal = new SimpleAttributeSet();
   StyleConstants.setForeground(normal, Color.black);
   StyleConstants.setBold(normal, false);
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           doc.setCharacterAttributes(0, doc.getLength(), normal, true);
         }
       });
   colorationPrimitives(text, doc);
   colorationPolicyScript(text, doc);
 }
示例#11
0
 /**
  * Displays the string representation of the maze.
  *
  * @param mz String representing the maze.
  */
 public void displayMaze(String mz) {
   SimpleAttributeSet attr = new SimpleAttributeSet();
   StyleConstants.setLineSpacing(attr, -0.3f);
   mazeOutLabel.setParagraphAttributes(attr, false);
   mazeOutLabel.setText(mz);
   imagePanel.add(mazeOutLabel);
   pack();
 }
  void finishInit() {
    // Create 3 styles associated with the text panes
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
    StyleConstants.setFontFamily(def, "SansSerif");

    Style regular0 = jTextPane.addStyle("regular", def);
    Style regular1 = commentPane.addStyle("regular", def);

    Style s0 = jTextPane.addStyle("old", regular0);
    Style s1 = commentPane.addStyle("old", regular1);
    StyleConstants.setBackground(s0, Color.yellow);
    StyleConstants.setBackground(s1, Color.yellow);

    s0 = jTextPane.addStyle("new", regular0);
    StyleConstants.setBackground(s0, Color.pink);
    s1 = commentPane.addStyle("new", regular1);
    StyleConstants.setBackground(s1, Color.pink);
  }
 public void colorationPolicyScript(String text, final StyledDocument doc) {
   Pattern p = Pattern.compile("(GraphOScript)");
   Matcher m = p.matcher(text);
   while (m.find() == true) {
     MutableAttributeSet attri = new SimpleAttributeSet();
     StyleConstants.setForeground(attri, Color.orange);
     StyleConstants.setBold(attri, true);
     final int start = m.start(0);
     final int end = m.end(0);
     final int length = end - start;
     final MutableAttributeSet style = attri;
     SwingUtilities.invokeLater(
         new Runnable() {
           public void run() {
             doc.setCharacterAttributes(start, length, style, true);
           }
         });
   }
 }
示例#14
0
  /**
   * Constructor that takes an ID from a Conversation, and creates a window to display it.
   *
   * @param ID The Conversation object's ID.
   */
  public ChatWindow(int ID) {
    setLayout(new BorderLayout());
    this.ID = ID;
    textPane = new JTextPane();
    scrollPane = new JScrollPane(textPane);

    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

    StyleConstants.setForeground(chatFont, Color.BLACK);
    StyleConstants.setFontSize(chatFont, 20);

    StyleConstants.setForeground(nameFont, Color.BLACK);
    StyleConstants.setFontSize(nameFont, 20);
    StyleConstants.setBold(nameFont, true);

    add(scrollPane, BorderLayout.CENTER);
    textPane.setEditable(false);
  }
  private void applyFontSize() {
    Document document = myEditorPane.getDocument();
    if (!(document instanceof StyledDocument)) {
      return;
    }

    StyledDocument styledDocument = (StyledDocument) document;
    if (myFontSizeStyle == null) {
      myFontSizeStyle = styledDocument.addStyle("active", null);
    }

    EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    EditorColorsScheme scheme = colorsManager.getGlobalScheme();
    StyleConstants.setFontSize(myFontSizeStyle, scheme.getQuickDocFontSize().getSize());
    if (Registry.is("documentation.component.editor.font")) {
      StyleConstants.setFontFamily(myFontSizeStyle, scheme.getEditorFontName());
    }
    styledDocument.setCharacterAttributes(0, document.getLength(), myFontSizeStyle, false);
  }
示例#16
0
  /**
   * Sets the reason of a call failure if one occurs. The renderer should display this reason to the
   * user.
   *
   * @param reason the reason to display
   */
  public void setErrorReason(final String reason) {
    if (!SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              setErrorReason(reason);
            }
          });
      return;
    }

    if (errorMessageComponent == null) {
      errorMessageComponent = new JTextPane();

      JTextPane textPane = (JTextPane) errorMessageComponent;
      textPane.setEditable(false);
      textPane.setOpaque(false);

      StyledDocument doc = textPane.getStyledDocument();

      MutableAttributeSet standard = new SimpleAttributeSet();
      StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER);
      StyleConstants.setFontFamily(standard, textPane.getFont().getFamily());
      StyleConstants.setFontSize(standard, 12);
      doc.setParagraphAttributes(0, 0, standard, true);

      GridBagConstraints constraints = new GridBagConstraints();
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.gridx = 0;
      constraints.gridy = 4;
      constraints.weightx = 1;
      constraints.weighty = 0;
      constraints.insets = new Insets(5, 0, 0, 0);

      add(errorMessageComponent, constraints);
      this.revalidate();
    }

    errorMessageComponent.setText(reason);

    if (isVisible()) errorMessageComponent.repaint();
  }
示例#17
0
  /**
   * Update the font in the default style of the document.
   *
   * @param font the new font to use or null to remove the font attribute from the document's style
   */
  private void updateFont(Font font) {
    StyledDocument doc = (StyledDocument) getComponent().getDocument();
    Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);

    if (style == null) {
      return;
    }

    if (font == null) {
      style.removeAttribute(StyleConstants.FontFamily);
      style.removeAttribute(StyleConstants.FontSize);
      style.removeAttribute(StyleConstants.Bold);
      style.removeAttribute(StyleConstants.Italic);
    } else {
      StyleConstants.setFontFamily(style, font.getName());
      StyleConstants.setFontSize(style, font.getSize());
      StyleConstants.setBold(style, font.isBold());
      StyleConstants.setItalic(style, font.isItalic());
    }
  }
示例#18
0
  private void setTabSize(int charactersPerTab) {
    FontMetrics fm = this.getFontMetrics(this.getFont());
    int charWidth = fm.charWidth('w');
    int tabWidth = charWidth * charactersPerTab;

    TabStop[] tabs = new TabStop[10];

    for (int j = 0; j < tabs.length; j++) {
      int tab = j + 1;
      tabs[j] = new TabStop(tab * tabWidth);
    }

    TabSet tabSet = new TabSet(tabs);
    SimpleAttributeSet attributes = new SimpleAttributeSet();
    StyleConstants.setFontSize(attributes, 18);
    StyleConstants.setFontFamily(attributes, "Osaka-Mono");
    StyleConstants.setTabSet(attributes, tabSet);
    int length = getDocument().getLength();
    getStyledDocument().setParagraphAttributes(0, length, attributes, true);
  }
示例#19
0
 /*     */ protected void setPropertiesFromAttributes() /*     */ {
   /* 140 */ AttributeSet localAttributeSet = getAttributes();
   /* 141 */ if (localAttributeSet != null) {
     /* 142 */ Document localDocument = getDocument();
     /* 143 */ if ((localDocument instanceof StyledDocument)) {
       /* 144 */ StyledDocument localStyledDocument = (StyledDocument) localDocument;
       /* 145 */ this.font = localStyledDocument.getFont(localAttributeSet);
       /* 146 */ this.fg = localStyledDocument.getForeground(localAttributeSet);
       /* 147 */ if (localAttributeSet.isDefined(StyleConstants.Background))
         /* 148 */ this.bg = localStyledDocument.getBackground(localAttributeSet);
       /*     */ else {
         /* 150 */ this.bg = null;
         /*     */ }
       /* 152 */ setUnderline(StyleConstants.isUnderline(localAttributeSet));
       /* 153 */ setStrikeThrough(StyleConstants.isStrikeThrough(localAttributeSet));
       /* 154 */ setSuperscript(StyleConstants.isSuperscript(localAttributeSet));
       /* 155 */ setSubscript(StyleConstants.isSubscript(localAttributeSet));
       /*     */ } else {
       /* 157 */ throw new StateInvariantError("LabelView needs StyledDocument");
       /*     */ }
     /*     */ }
   /*     */ }
示例#20
0
  /**
   * Update the color in the default style of the document.
   *
   * @param color the new color to use or null to remove the color attribute from the document's
   *     style
   */
  private void updateForeground(Color color) {
    StyledDocument doc = (StyledDocument) getComponent().getDocument();
    Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);

    if (style == null) {
      return;
    }

    if (color == null) {
      style.removeAttribute(StyleConstants.Foreground);
    } else {
      StyleConstants.setForeground(style, color);
    }
  }
示例#21
0
  private static void insertQuestion(final JTextPane textPane, String str) {
    Document doc = textPane.getDocument();
    try {
      doc.insertString(doc.getLength(), str, null);

      final int pos = doc.getLength();
      System.out.println(pos);
      final JTextField field =
          new JTextField(4) {
            @Override
            public Dimension getMaximumSize() {
              return getPreferredSize();
            }
          };
      field.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
      field.addFocusListener(
          new FocusListener() {
            @Override
            public void focusGained(FocusEvent e) {
              try {
                Rectangle rect = textPane.modelToView(pos);
                rect.grow(0, 4);
                rect.setSize(field.getSize());
                // System.out.println(rect);
                // System.out.println(field.getLocation());
                textPane.scrollRectToVisible(rect);
              } catch (BadLocationException ex) {
                ex.printStackTrace();
              }
            }

            @Override
            public void focusLost(FocusEvent e) {
              /* not needed */
            }
          });
      Dimension d = field.getPreferredSize();
      int baseline = field.getBaseline(d.width, d.height);
      field.setAlignmentY(baseline / (float) d.height);

      SimpleAttributeSet a = new SimpleAttributeSet();
      StyleConstants.setLineSpacing(a, 1.5f);
      textPane.setParagraphAttributes(a, true);

      textPane.insertComponent(field);
      doc.insertString(doc.getLength(), "\n", null);
    } catch (BadLocationException e) {
      e.printStackTrace();
    }
  }
示例#22
0
  public StyleManager(
      SettingsManager settings_manager, DisplayManager display_manager, I18nManager i18n_manager) {
    this.settings_manager = settings_manager;
    this.display_manager = display_manager;
    this.i18n_manager = i18n_manager;

    Vector v = new Vector();

    style_names = new String[0];

    base_style = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
    StyleConstants.setFontFamily(
        base_style, settings_manager.getString("/gui/text windows/font face", "Lucida Console"));
    StyleConstants.setFontSize(
        base_style, settings_manager.getInt("/gui/text windows/font size", 14));

    // Read in more styles based on highlight settings.

    int i = 0;
    String i_str;
    String format;
    while (GOD_IS_GOOD) {
      i_str = Integer.toString(i);
      format =
          settings_manager.getString("/gui/text windows/highlighting/" + i_str + "/format", "");
      if (format.equals("")) {
        // No more highlight rules specified.
        break;
      }

      v.add(format);

      i++;
    }

    style_names = (String[]) v.toArray(style_names);
  }
示例#23
0
  /**
   * sets the number of characters per tab.
   *
   * @param charactersPerTab the characters per tab
   */
  public void setTabs(int charactersPerTab) {
    Font f = new Font(m_FontName, Font.PLAIN, m_FontSize);

    FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(f);
    int charWidth = fm.charWidth('w');
    int tabWidth = charWidth * charactersPerTab;

    TabStop[] tabs = new TabStop[MAX_TABS];

    for (int j = 0; j < tabs.length; j++) tabs[j] = new TabStop((j + 1) * tabWidth);

    TabSet tabSet = new TabSet(tabs);
    SimpleAttributeSet attributes = new SimpleAttributeSet();
    StyleConstants.setTabSet(attributes, tabSet);
    int length = getLength();
    setParagraphAttributes(0, length, attributes, false);
  }
示例#24
0
 void editorPane_keyPressed(KeyEvent e) {
   StyledDocument doc = editorPane.getStyledDocument();
   int pos = editorPane.getCaretPosition();
   int code = e.getKeyCode();
   Element el;
   switch (code) {
     case KeyEvent.VK_BACK_SPACE:
     case KeyEvent.VK_DELETE:
     case KeyEvent.VK_LEFT:
     case KeyEvent.VK_KP_LEFT:
       if (pos == 0) return;
       // we want to get the element to the left of position.
       el = doc.getCharacterElement(pos - 1);
       break;
     case KeyEvent.VK_RIGHT:
     case KeyEvent.VK_KP_RIGHT:
       // we want to get the element to the right of position.
       el = doc.getCharacterElement(pos + 1);
       break;
     default:
       return; // bail we don't handle it.
   }
   AttributeSet attr = el.getAttributes();
   String el_name = (String) attr.getAttribute(StyleConstants.NameAttribute);
   int el_range = el.getEndOffset() - el.getStartOffset() - 1;
   if (el_name.startsWith("Parameter") && StyleConstants.getComponent(attr) != null) {
     try {
       switch (code) {
         case KeyEvent.VK_BACK_SPACE:
         case KeyEvent.VK_DELETE:
           doc.remove(el.getStartOffset(), el_range);
           break;
         case KeyEvent.VK_LEFT:
         case KeyEvent.VK_KP_LEFT:
           editorPane.setCaretPosition(pos - el_range);
           break;
         case KeyEvent.VK_RIGHT:
         case KeyEvent.VK_KP_RIGHT:
           editorPane.setCaretPosition(pos + (el_range));
           break;
       }
     } catch (BadLocationException ex) {
     }
   }
 }
示例#25
0
  private void insertParameter(ConfigParamDescr descr, String format, int pos) {
    try {
      StyledDocument doc = (StyledDocument) editorPane.getDocument();

      // The component must first be wrapped in a style
      Style style = doc.addStyle("Parameter-" + numParameters, null);
      JLabel label = new JLabel(descr.getDisplayName());
      label.setAlignmentY(0.8f); // make sure we line up
      label.setFont(new Font("Helvetica", Font.PLAIN, 14));
      label.setForeground(Color.BLUE);
      label.setName(descr.getKey());
      label.setToolTipText("key: " + descr.getKey() + "    format: " + format);
      StyleConstants.setComponent(style, label);
      doc.insertString(pos, format, style);
      numParameters++;
    } catch (BadLocationException e) {
    }
  }
示例#26
0
 public void write(Writer out, Document doc, int pos, int len, Map<String, String> copiedImgs)
     throws IOException, BadLocationException {
   Debug.log(9, "SikuliEditorKit.write %d %d", pos, len);
   DefaultStyledDocument sdoc = (DefaultStyledDocument) doc;
   int i = pos;
   String absPath;
   while (i < pos + len) {
     Element e = sdoc.getCharacterElement(i);
     int start = e.getStartOffset(), end = e.getEndOffset();
     if (e.getName().equals(StyleConstants.ComponentElementName)) {
       // A image argument to be filled
       AttributeSet attr = e.getAttributes();
       Component com = StyleConstants.getComponent(attr);
       out.write(com.toString());
       if (copiedImgs != null
           && (com instanceof EditorPatternButton || com instanceof EditorPatternLabel)) {
         if (com instanceof EditorPatternButton) {
           absPath = ((EditorPatternButton) com).getFilename();
         } else {
           absPath = ((EditorPatternLabel) com).getFile();
         }
         String fname = (new File(absPath)).getName();
         copiedImgs.put(fname, absPath);
         Debug.log(3, "save image for copy&paste: " + fname + " -> " + absPath);
       }
     } else {
       if (start < pos) {
         start = pos;
       }
       if (end > pos + len) {
         end = pos + len;
       }
       out.write(doc.getText(start, end - start));
     }
     i = end;
   }
   out.close();
 }
示例#27
0
  protected void buildErrorPanel() {
    errorPanel = new JPanel();
    GroupLayout layout = new GroupLayout(errorPanel);
    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);
    errorPanel.setLayout(layout);
    //    errorPanel.setBorder(BorderFactory.createMatteBorder(2, 0, 0, 0, Color.BLACK));
    errorMessage = new JTextPane();
    errorMessage.setEditable(false);
    errorMessage.setContentType("text/html");
    errorMessage.setText(
        "<html><body>Could not connect to the Processing server.<br>"
            + "Contributions cannot be installed or updated without an Internet connection.<br>"
            + "Please verify your network connection again, then try connecting again.</body></html>");
    errorMessage.setFont(Toolkit.getSansFont(14, Font.PLAIN));
    errorMessage.setMaximumSize(new Dimension(550, 50));
    errorMessage.setOpaque(false);

    StyledDocument doc = errorMessage.getStyledDocument();
    SimpleAttributeSet center = new SimpleAttributeSet();
    StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
    doc.setParagraphAttributes(0, doc.getLength(), center, false);

    closeButton = new JButton("X");
    closeButton.setContentAreaFilled(false);
    closeButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            contribDialog.makeAndShowTab(false, false);
          }
        });
    tryAgainButton = new JButton("Try Again");
    tryAgainButton.setFont(Toolkit.getSansFont(14, Font.PLAIN));
    tryAgainButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            contribDialog.makeAndShowTab(false, true);
            contribDialog.downloadAndUpdateContributionListing(editor.getBase());
          }
        });
    layout.setHorizontalGroup(
        layout
            .createSequentialGroup()
            .addPreferredGap(
                LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.CENTER)
                    .addComponent(errorMessage)
                    .addComponent(
                        tryAgainButton,
                        StatusPanel.BUTTON_WIDTH,
                        StatusPanel.BUTTON_WIDTH,
                        StatusPanel.BUTTON_WIDTH))
            .addPreferredGap(
                LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
            .addComponent(closeButton));
    layout.setVerticalGroup(
        layout
            .createSequentialGroup()
            .addGroup(
                layout.createParallelGroup().addComponent(errorMessage).addComponent(closeButton))
            .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(tryAgainButton));
    errorPanel.setBackground(Color.PINK);
    errorPanel.validate();
  }
示例#28
0
  void createStyles() {
    // no attributes defined
    Style s = styles.addStyle(null, null);
    runAttr.put("none", s);
    s = styles.addStyle(null, null);
    StyleConstants.setItalic(s, true);
    StyleConstants.setForeground(s, new Color(153, 153, 102));
    runAttr.put("cquote", s); // catepillar quote

    s = styles.addStyle(null, null);
    StyleConstants.setItalic(s, true);
    StyleConstants.setForeground(s, new Color(51, 102, 153));
    runAttr.put("aquote", s); // alice quote

    try {
      ResourceBundle resources =
          ResourceBundle.getBundle("resources.Stylepad", Locale.getDefault());
      s = styles.addStyle(null, null);
      Icon alice = new ImageIcon(resources.getString("aliceGif"));
      StyleConstants.setIcon(s, alice);
      runAttr.put("alice", s); // alice

      s = styles.addStyle(null, null);
      Icon caterpillar = new ImageIcon(resources.getString("caterpillarGif"));
      StyleConstants.setIcon(s, caterpillar);
      runAttr.put("caterpillar", s); // caterpillar

      s = styles.addStyle(null, null);
      Icon hatter = new ImageIcon(resources.getString("hatterGif"));
      StyleConstants.setIcon(s, hatter);
      runAttr.put("hatter", s); // hatter

    } catch (MissingResourceException mre) {
      // can't display image
    }

    Style def = styles.getStyle(StyleContext.DEFAULT_STYLE);

    Style heading = styles.addStyle("heading", def);
    // StyleConstants.setFontFamily(heading, "SansSerif");
    StyleConstants.setBold(heading, true);
    StyleConstants.setAlignment(heading, StyleConstants.ALIGN_CENTER);
    StyleConstants.setSpaceAbove(heading, 10);
    StyleConstants.setSpaceBelow(heading, 10);
    StyleConstants.setFontSize(heading, 18);

    // Title
    Style sty = styles.addStyle("title", heading);
    StyleConstants.setFontSize(sty, 32);

    // edition
    sty = styles.addStyle("edition", heading);
    StyleConstants.setFontSize(sty, 16);

    // author
    sty = styles.addStyle("author", heading);
    StyleConstants.setItalic(sty, true);
    StyleConstants.setSpaceBelow(sty, 25);

    // subtitle
    sty = styles.addStyle("subtitle", heading);
    StyleConstants.setSpaceBelow(sty, 35);

    // normal
    sty = styles.addStyle("normal", def);
    StyleConstants.setLeftIndent(sty, 10);
    StyleConstants.setRightIndent(sty, 10);
    // StyleConstants.setFontFamily(sty, "SansSerif");
    StyleConstants.setFontSize(sty, 14);
    StyleConstants.setSpaceAbove(sty, 4);
    StyleConstants.setSpaceBelow(sty, 4);
  }
示例#29
0
  /**
   * Returns a JPanel that represents the mancala board using strategy pattern to insert style.
   *
   * @param strat concrete strategy
   * @return JPanel containing both users' pits as controllers
   */
  public JPanel boardContextDoWork(Strategy strat) {
    this.s = strat;
    Color boardColor = s.getBoardColor();
    Color fontColor = s.getFontColor();
    Font font = s.getFont();
    JPanel panCenter = new JPanel();
    JPanel panLeft = new JPanel();
    JPanel panRight = new JPanel();

    panCenter.setLayout(new GridLayout(2, 6, 10, 10));
    // B6 to B1 Controllers
    for (int i = 12; i > 6; i--) {
      final Pits temp = new Pits(i);
      final int pit = i;
      final JLabel tempLabel = new JLabel(temp);
      tempLabel.addMouseListener(
          new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
              if (Model.player == 1) {
                JFrame frame = new JFrame();
                JOptionPane.showMessageDialog(frame, "Player A's turn!");
              } else if (model.data[pit] == 0) {
                JFrame frame = new JFrame();
                JOptionPane.showMessageDialog(frame, "Pit is Empty try another one.");
              } else {
                if (temp.pitShape.contains(e.getPoint())) {
                  model.move(pit); // mutator
                  undoBtn.setText("Undo : " + model.getUndoCounter());
                  model.display();
                }
              }
            }
          });
      JPanel tempPanel = new JPanel(new BorderLayout());

      JTextPane textPane = new JTextPane();
      textPane.setEditable(false);
      textPane.setBackground(boardColor);
      textPane.setForeground(fontColor);
      textPane.setFont(font);
      textPane.setText("B" + (i - 6));
      StyledDocument doc = textPane.getStyledDocument();
      SimpleAttributeSet center = new SimpleAttributeSet();
      StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
      doc.setParagraphAttributes(0, doc.getLength(), center, false);
      tempPanel.add(textPane, BorderLayout.NORTH);
      tempPanel.add(tempLabel, BorderLayout.SOUTH);
      panCenter.add(tempPanel, BorderLayout.SOUTH);

      tempPanel.setBackground(boardColor);
    }
    // A1 to A6 Controllers
    for (int i = 0; i < 6; i++) {
      final Pits newPits = new Pits(i);
      JLabel label = new JLabel(newPits);
      final int pit = i;
      label.addMouseListener(
          new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
              if (Model.player == 2) {
                JFrame frame = new JFrame();
                JOptionPane.showMessageDialog(frame, "Player B's turn!");
              } else if (model.data[pit] == 0) {
                JFrame frame = new JFrame();
                JOptionPane.showMessageDialog(frame, "Pit is Empty try another one.");
              } else {
                if (newPits.pitShape.contains(e.getPoint())) {
                  model.move(pit); // mutator
                  undoBtn.setText("Undo : " + model.getUndoCounter());
                  model.display();
                }
              }
            }
          });
      JPanel tempPanel = new JPanel(new BorderLayout());

      tempPanel.add(label, BorderLayout.NORTH);
      JTextPane textPane = new JTextPane();
      textPane.setBackground(boardColor);
      textPane.setForeground(fontColor);
      textPane.setFont(font);
      textPane.setEditable(false);
      textPane.setText("A" + (i + 1));
      StyledDocument doc = textPane.getStyledDocument();
      SimpleAttributeSet center = new SimpleAttributeSet();
      StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
      doc.setParagraphAttributes(0, doc.getLength(), center, false);
      tempPanel.add(textPane, BorderLayout.SOUTH);
      tempPanel.setBackground(boardColor);
      panCenter.add(tempPanel, BorderLayout.SOUTH);
    }

    // left text pane
    JTextPane paneLeft = new JTextPane();
    paneLeft.setBackground(boardColor);
    paneLeft.setForeground(fontColor);
    paneLeft.setFont(font);
    paneLeft.setEditable(false);
    paneLeft.setText("M\nA\nN\nC\nA\nL\nA\n \nB");

    // right text pane
    JTextPane paneRight = new JTextPane();
    paneRight.setBackground(boardColor);
    paneRight.setForeground(fontColor);
    paneRight.setFont(font);
    paneRight.setEditable(false);
    paneRight.setText("M\nA\nN\nC\nA\nL\nA\n \nA");

    // Add text panes to left and right panels
    panLeft.setLayout(new BorderLayout());
    panRight.setLayout(new BorderLayout());
    panLeft.add(paneLeft, BorderLayout.WEST);
    panRight.add(paneRight, BorderLayout.EAST);
    panLeft.add(new JLabel(new Pits(13)), BorderLayout.EAST);
    panRight.add(new JLabel(new Pits(6)), BorderLayout.WEST);

    // add the 2 mancala panels and pit panel to larger displayPanel
    JPanel displayPanel = new JPanel();
    displayPanel.add(panLeft, BorderLayout.WEST);
    displayPanel.add(panCenter, BorderLayout.CENTER);
    displayPanel.add(panRight, BorderLayout.EAST);

    // set color
    panCenter.setBackground(boardColor);
    panLeft.setBackground(boardColor);
    panRight.setBackground(boardColor);
    displayPanel.setBackground(boardColor);

    // return display panel which contains the containers and elements created
    return displayPanel;
  }
示例#30
0
 private void highlightArea(int pos, int len, String col) {
   SimpleAttributeSet attrs = new SimpleAttributeSet();
   StyleConstants.setForeground(attrs, getColour(col));
   document.setCharacterAttributes(pos, len, attrs, true);
 }