Ejemplo n.º 1
0
 /** Check icons initialization. */
 static {
   for (int i = 1; i <= 4; i++) {
     final ImageIcon icon = new ImageIcon(WebCheckBoxUI.class.getResource("icons/c" + i + ".png"));
     CHECK_STATES.add(icon);
     DISABLED_CHECK_STATES.add(
         ImageUtils.getDisabledCopy("WebCheckBox.disabled.check." + i, icon));
   }
 }
Ejemplo n.º 2
0
  static {
    CHECK_STATES.add(StyleConstants.EMPTY_ICON);
    for (int i = 1; i <= 3; i++) {
      CHECK_STATES.add(new ImageIcon(WebRadioButtonUI.class.getResource("icons/c" + i + ".png")));
    }

    DISABLED_CHECK =
        ImageUtils.getDisabledCopy(
            "WebRadioButton.disabled.check", CHECK_STATES.get(CHECK_STATES.size() - 1));
  }
Ejemplo n.º 3
0
 /** Private update methods */
 private void updateViewFromColor() {
   colorButton.setIcon(ImageUtils.createColorChooserIcon(color));
   updateText();
 }
Ejemplo n.º 4
0
  public WebColorChooserField(final Color color) {
    super();

    // Pipette color picker
    updatePipette();

    // Trailing color choose button
    colorButton = new WebButton(ImageUtils.createColorChooserIcon(color));
    colorButton.setFocusable(false);
    colorButton.setShadeWidth(0);
    colorButton.setMoveIconOnPress(false);
    colorButton.setRolloverDecoratedOnly(true);
    colorButton.setCursor(Cursor.getDefaultCursor());
    colorButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            showColorChooserPopup();
          }
        });
    setTrailingComponent(colorButton);

    // Actions
    addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            updateColorFromField();
          }
        });
    addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(final MouseEvent e) {
            if (isEnabled() && SwingUtilities.isRightMouseButton(e)) {
              showColorChooserPopup();
            }
          }
        });
    addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(final FocusEvent e) {
            updateColorFromField();
          }
        });
    addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(final KeyEvent e) {
            if (isEnabled()) {
              if (Hotkey.ESCAPE.isTriggered(e)) {
                updateViewFromColor();
              } else if (Hotkey.DOWN.isTriggered(e)) {
                showColorChooserPopup();
              }
            }
          }
        });

    // Initial data
    setFieldType(ColorChooserFieldType.rgb);
    setColor(color);

    // Initial styling settings
    updateMargin();
    setHorizontalAlignment(CENTER);
  }
Ejemplo n.º 5
0
  private Component createEntryViewer(JarEntry entry) {
    if (entry.getType().equals(JarEntryType.classEntry)
        || entry.getType().equals(JarEntryType.javaEntry)
        || entry.getType().equals(JarEntryType.fileEntry)) {
      String ext = FileUtils.getFileExtPart(entry.getName(), false).toLowerCase();
      if (GlobalConstants.IMAGE_FORMATS.contains(ext)) {
        // todo A better image viewer (actually a new component - WebImageViewer)

        // Image file viewer
        WebImage image = new WebImage();
        image.setIcon(ImageUtils.loadImage(getEntryInputStream(entry)));

        // Image scroll
        WebScrollPane imageScroll = new WebScrollPane(image, false);
        imageScroll.setVerticalScrollBarPolicy(WebScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        imageScroll.setHorizontalScrollBarPolicy(WebScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        return imageScroll;
      } else {
        // Source code viewer
        final RSyntaxTextArea source = new RSyntaxTextArea();

        // Syntax style
        boolean libraryCode = false;
        if (ext.equals("java") || ext.equals("class")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
          libraryCode = true;
        } else if (ext.equals("xml")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
        } else if (ext.equals("html")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_HTML);
        } else if (ext.equals("css")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CSS);
        } else if (ext.equals("js")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
        } else if (ext.equals("php")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PHP);
        } else if (ext.equals("sql")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
        } else {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
        }

        // Settings
        source.setEditable(false);
        source.setMargin(new Insets(0, 5, 0, 0));
        source.setAntiAliasingEnabled(true);
        source.setUseFocusableTips(true);
        source.setTabSize(4);
        // source.setLineWrap ( true );
        // source.setWrapStyleWord ( true );
        source.setCodeFoldingEnabled(allowCodeFolding.isSelected());
        source.setPaintTabLines(paintTabLines.isSelected());
        source.setWhitespaceVisible(showWhitespaces.isSelected());
        source.setEOLMarkersVisible(showEol.isSelected());
        source.addHyperlinkListener(
            new HyperlinkListener() {
              @Override
              public void hyperlinkUpdate(HyperlinkEvent e) {
                WebUtils.browseSiteSafely(e.getURL().toExternalForm());
              }
            });
        ((RSyntaxTextAreaHighlighter) source.getHighlighter()).setDrawsLayeredHighlights(false);

        // Source code
        source.setText(libraryCode ? loadSource(entry) : loadString(entry));
        source.setCaretPosition(0);

        // "Jump to source"-like action
        source.addMouseListener(
            new MouseAdapter() {
              @Override
              public void mousePressed(MouseEvent e) {
                // todo Fix when clicked in class "MyName" on string "MyName"
                // Additional feature to dive into related classes
                if (SwingUtilities.isMiddleMouseButton(e)
                    || SwingUtils.isCtrl(e) && SwingUtilities.isLeftMouseButton(e)) {
                  int pos = source.getUI().viewToModel(source, e.getPoint());
                  String word = TextUtils.getWord(source.getText(), pos);
                  if (word != null) {
                    JarEntry classByName = jarStructure.findEntryByName(word);
                    if (classByName != null
                        && (classByName.getType().equals(JarEntryType.classEntry)
                            || classByName.getType().equals(JarEntryType.javaEntry))) {
                      updateClassPath(classByName, true);
                    }
                  }
                }
              }
            });

        // Saving opened editor
        synchronized (activeEditorsLock) {
          activeEditors.put(entry, source);
        }

        // Special code viewer scroll pane
        RTextScrollPane sourceScroll = new RTextScrollPane(source);
        sourceScroll.setVerticalScrollBarPolicy(WebScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        ((WebScrollPaneUI) sourceScroll.getUI()).setDrawBorder(false);

        // Source code viewer theme
        loadTheme(theme.getSelectedItem().toString().toLowerCase(), source);

        return sourceScroll;
      }
    }
    return new WebLabel();
  }