private static Component createDescription(Example example, ExampleGroup group) {
    Color foreground = group.getPreferredForeground();

    WebLabel titleLabel = new WebLabel(example.getTitle(), JLabel.TRAILING);
    titleLabel.setDrawShade(true);
    titleLabel.setForeground(foreground);
    if (foreground.equals(Color.WHITE)) {
      titleLabel.setShadeColor(Color.BLACK);
    }

    if (example.getDescription() == null) {
      return titleLabel;
    } else {
      WebLabel descriptionLabel = new WebLabel(example.getDescription(), WebLabel.TRAILING);
      descriptionLabel.setForeground(Color.GRAY);
      SwingUtils.changeFontSize(descriptionLabel, -1);

      WebPanel vertical =
          new WebPanel(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, 0, 0, true, false));
      vertical.setOpaque(false);
      vertical.add(titleLabel);
      vertical.add(descriptionLabel);

      return vertical;
    }
  }
  // TODO not used
  private void showNotification() {
    final WebDialog dialog = new WebDialog();
    dialog.setUndecorated(true);
    dialog.setBackground(Color.BLACK);
    dialog.setBackground(StyleConstants.transparent);

    WebNotificationPopup popup = new WebNotificationPopup(PopupStyle.dark);
    popup.setIcon(Utils.getIcon("kontalk_small.png"));
    popup.setMargin(View.MARGIN_DEFAULT);
    popup.setDisplayTime(6000);
    popup.addNotificationListener(
        new NotificationListener() {
          @Override
          public void optionSelected(NotificationOption option) {}

          @Override
          public void accepted() {}

          @Override
          public void closed() {
            dialog.dispose();
          }
        });

    // content
    WebPanel panel = new WebPanel();
    panel.setMargin(View.MARGIN_DEFAULT);
    panel.setOpaque(false);
    WebLabel title = new WebLabel("A new Message!");
    title.setFontSize(View.FONT_SIZE_BIG);
    title.setForeground(Color.WHITE);
    panel.add(title, BorderLayout.NORTH);
    String text = "this is some message, and some longer text was added";
    WebLabel message = new WebLabel(text);
    message.setForeground(Color.WHITE);
    panel.add(message, BorderLayout.CENTER);
    popup.setContent(panel);

    // popup.packPopup();
    dialog.setSize(popup.getPreferredSize());

    // set position on screen
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    Rectangle screenBounds = gc.getBounds();
    // get height of the task bar
    // doesn't work on all environments
    // Insets toolHeight = toolkit.getScreenInsets(popup.getGraphicsConfiguration());
    int toolHeight = 40;
    dialog.setLocation(
        screenBounds.width - dialog.getWidth() - 10,
        screenBounds.height - toolHeight - dialog.getHeight());

    dialog.setVisible(true);
    NotificationManager.showNotification(dialog, popup);
  }
  /**
   * Constructs cell renderer for the specified file list.
   *
   * @param fileList file list in which this cell renderer is used
   */
  public WebFileListCellRenderer(final WebFileList fileList) {
    super();

    this.fileList = fileList;

    iconLabel = new WebLabel();
    iconLabel.setHorizontalAlignment(JLabel.CENTER);
    iconLabel.setPreferredSize(new Dimension(imageSide, imageSide));

    nameLabel = new WebLabel();
    nameLabel.setFont(nameLabel.getFont().deriveFont(Font.PLAIN));
    nameLabel.setForeground(Color.BLACK);
    nameLabel.setVerticalAlignment(JLabel.CENTER);

    descriptionLabel = new WebLabel(WebLabel.LEADING);
    descriptionLabel.setFont(descriptionLabel.getFont().deriveFont(Font.PLAIN));
    descriptionLabel.setForeground(Color.GRAY);

    sizeLabel = new WebLabel(WebLabel.LEADING);
    sizeLabel.setFont(sizeLabel.getFont().deriveFont(Font.PLAIN));
    sizeLabel.setForeground(new Color(49, 77, 179));

    setLayout(new FileCellLayout());
    add(iconLabel);
    add(nameLabel);
    add(descriptionLabel);
    add(sizeLabel);

    fileList.addPropertyChangeListener(
        WebLookAndFeel.COMPONENT_ENABLED_PROPERTY,
        new PropertyChangeListener() {
          @Override
          public void propertyChange(final PropertyChangeEvent evt) {
            final boolean enabled = fileList.isEnabled();
            iconLabel.setEnabled(enabled);
            nameLabel.setEnabled(enabled);
            descriptionLabel.setEnabled(enabled);
            sizeLabel.setEnabled(enabled);
          }
        });

    fileList.addPropertyChangeListener(
        WebLookAndFeel.COMPONENT_ORIENTATION_PROPERTY,
        new PropertyChangeListener() {
          @Override
          public void propertyChange(final PropertyChangeEvent evt) {
            final ComponentOrientation orientation = fileList.getComponentOrientation();
            nameLabel.setComponentOrientation(orientation);
            descriptionLabel.setComponentOrientation(orientation);
            sizeLabel.setComponentOrientation(orientation);
          }
        });

    updateFilesView();
  }
  void showPasswordDialog(boolean wasWrong) {
    WebPanel passPanel = new WebPanel();
    WebLabel passLabel = new WebLabel(Tr.tr("Please enter your key password:"******"Wrong password"));
      wrongLabel.setForeground(Color.RED);
      passPanel.add(wrongLabel, BorderLayout.SOUTH);
    }
    WebOptionPane passPane =
        new WebOptionPane(
            passPanel, WebOptionPane.QUESTION_MESSAGE, WebOptionPane.OK_CANCEL_OPTION);
    JDialog dialog = passPane.createDialog(mMainFrame, Tr.tr("Enter password"));
    dialog.setModal(true);
    dialog.addWindowFocusListener(
        new WindowAdapter() {
          @Override
          public void windowGainedFocus(WindowEvent e) {
            passField.requestFocusInWindow();
          }
        });
    // blocking
    dialog.setVisible(true);

    Object value = passPane.getValue();
    if (value != null && value.equals(WebOptionPane.OK_OPTION))
      mControl.connect(passField.getPassword());
  }
  public IMChatListElement(Icon icon, String title, WebButton removeBtn) {
    this.removeBtn = removeBtn;

    // 图片和标题
    WebLabel titleLabel = new WebLabel(title, icon);
    titleLabel.setMargin(0, 0, 0, 4);
    titleLabel.setAlignmentX(WebLabel.LEFT_ALIGNMENT);
    titleLabel.setOpaque(false);
    titleLabel.setForeground(Color.WHITE);
    this.add(titleLabel, BorderLayout.CENTER);
    this.add(removeBtn, BorderLayout.LINE_END);

    setPainter(new ChatListElementPainter());
  }
Exemple #6
0
  private Component createValueLabel(DetailsDecoration property, int maxLength) {

    String value = property.getFormatedValue();
    boolean abbreviate = (value.length() > maxLength);
    String abbreviatedValue;

    if (value.matches("[0-9\\.]+e-?[0-9]+")) {
      value =
          "<html><body>" + value.replaceAll("e(-?[0-9]+)", "·10<sup>$1</sup>") + "</body></html>";
    }

    if (abbreviate) {
      abbreviatedValue = StringUtils.abbreviate(value, maxLength);
    } else {
      abbreviatedValue = value;
    }

    WebLabel label;
    if (StringUtils.isEmpty(property.getValueLink())) {
      label = new WebLabel(abbreviatedValue);
    } else {
      DetailsWebLinkLabel webLabel = new DetailsWebLinkLabel(abbreviatedValue);
      webLabel.setLink(property.getValueLink(), false);
      label = webLabel;
    }

    SwingUtils.changeFontSize(label, -1);

    if (abbreviate) {
      TooltipManager.setTooltip(label, value, TooltipWay.down, 0);
    }

    label.setCursor(new Cursor(Cursor.HAND_CURSOR));
    label.addMouseListener(new PropertyMouseListener(property));

    if (property.isSelected()) {
      SwingUtils.setBoldFont(label);
    }

    if (property.getBgColor() != null) {
      WebPanel colorBox = new WebPanel();
      colorBox.setPreferredSize(new Dimension(15, 15));
      colorBox.setBackground(property.getBgColor());
      return new GroupPanel(4, colorBox, label);
    }

    label.setForeground(property.isVisible() ? Color.BLACK : Color.lightGray);
    return label;
  }
Exemple #7
0
    private void initComponent() {
      // 小于一天就显示时间,否则就显示日期
      String time = DATE_FORMAT.format(msg.getDate());
      if (System.currentTimeMillis() - msg.getDate().getTime() < 24 * 3600 * 1000) {
        time = TIME_FORMAT.format(msg.getDate());
      }
      infoLabl = new WebLabel(msg.getSender().getNickname() + " " + time);
      infoLabl.setForeground(new Color(70, 160, 220));
      infoLabl.setMargin(5);
      contnetPane = new RichTextPane();
      contnetPane.setRichItems(msg.getContents());
      contnetPane.setEditable(false);

      add(infoLabl, BorderLayout.PAGE_START);
      add(contnetPane, BorderLayout.CENTER);
    }
Exemple #8
0
  private Component createNameLabel(DetailsDecoration detail) {

    if (detail instanceof JComponentDetailsDecoration) {
      Component c = createComponentNameLabel((JComponentDetailsDecoration) detail);
      if (c != null) {
        c.setForeground(detail.isVisible() ? Color.BLACK : Color.lightGray);
        return c;
      }
    }

    WebLabel label = new WebLabel(StringUtils.capitalize(detail.getName()), JLabel.TRAILING);

    label.setDrawShade(true);
    SwingUtils.changeFontSize(label, -1);

    if (detail.isSelected()) {
      SwingUtils.setBoldFont(label);
    }

    label.setCursor(new Cursor(Cursor.HAND_CURSOR));
    label.addMouseListener(new PropertyMouseListener(detail));

    if (StringUtils.isNotEmpty(detail.getDescription())) {
      String description =
          "<html><body width=\"300px\">" + detail.getDescription() + "</body></html>";
      TooltipManager.setTooltip(label, description, TooltipWay.down, 0);
    }

    if (!StringUtils.isEmpty(detail.getDescriptionLink())) {
      DetailsWebLinkLabel webLabel = new DetailsWebLinkLabel("", JLabel.TRAILING);
      webLabel.setIcon(IconNames.INFO_ICON);
      webLabel.setLink(detail.getDescriptionLink(), false);
      TooltipManager.setTooltip(webLabel, detail.getDescriptionLink(), TooltipWay.down, 0);
      return new GroupPanel(GroupingType.fillFirst, 5, webLabel, label);
    }

    label.setForeground(detail.isVisible() ? Color.BLACK : Color.lightGray);
    return label;
  }
Exemple #9
0
    /** initialization */
    private void initComponent() {
      headerPl = new WebPanel();
      contentPl = new WebPanel();
      footerPl = new WebPanel();
      localMsgPl = new GroupPanel(false);
      onlineMsgPl = new GroupPanel(false);

      WebScrollPane localMsgScroll =
          new WebScrollPane(localMsgPl) {
            private static final long serialVersionUID = 1L;

            {
              setHorizontalScrollBarPolicy(WebScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              setBorder(null);
              setMargin(0);
              setShadeWidth(0);
              setRound(0);
              setDrawBorder(false);
            }
          };

      /*
      WebScrollPane onlineMsgScroll = new WebScrollPane(onlineMsgPl) {
      	private static final long serialVersionUID = 1L;

      	{
      		setHorizontalScrollBarPolicy(WebScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
      		setBorder(null);
      		setMargin(0);
      		setShadeWidth(0);
      		setRound(0);
      		setDrawBorder(false);
      	}
      };
      WebTabbedPane msgTab = new WebTabbedPane();
      msgTab.add("Local", localMsgScroll);
      msgTab.add("Online", onlineMsgScroll);
      msgTab.setTabbedPaneStyle(TabbedPaneStyle.attached);
      msgTab.setTabStretchType(TabStretchType.always);
      msgTab.setOpaque(false);
      msgTab.setPainter(SkinUtils.getPainter(Type.NPICON, "transparent"));
      msgTab.setBackgroundAt(0, Color.WHITE);
      msgTab.setBackgroundAt(1, Color.WHITE);
      contentPl.add(msgTab);
      */
      contentPl.add(localMsgScroll);

      WebButton searcherBtn =
          WebButton.createIconWebButton(
              IMImageUtil.getScaledInstance(SkinUtils.getImageIcon("searchNormal"), 18, 18),
              StyleConstants.smallRound,
              true);
      WebButton pagePrev =
          WebButton.createIconWebButton(
              IMImageUtil.getScaledInstance(
                  SkinUtils.getImageIcon("chat/msghistory/arrow/left"), 18, 18),
              StyleConstants.smallRound,
              true);
      WebButton pageNext =
          WebButton.createIconWebButton(
              IMImageUtil.getScaledInstance(
                  SkinUtils.getImageIcon("chat/msghistory/arrow/right"), 18, 18),
              StyleConstants.smallRound,
              true);
      WebTextField pageFld = new WebTextField();
      pageFld.setPreferredSize(new Dimension(30, 20));
      pageTotal = new WebLabel("/0 Page");
      pageTotal.setForeground(Color.GRAY);

      footerPl.add(searcherBtn, BorderLayout.LINE_START);
      footerPl.add(new GroupPanel(true, pagePrev, pageTotal, pageNext), BorderLayout.LINE_END);
      footerPl.setOpaque(true);
      footerPl.setBackground(Color.LIGHT_GRAY);

      pagePrev.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
              if (currentPage == 1) {
                return;
              } else {
                currentPage--;
              }

              // 显示消息
              IMEvent imEvent = new IMEvent(IMEventType.MSG_HISTORY_FIND, namedObject.getEntity());
              imEvent.putData("start", firstKey);
              imEvent.putData("limit", limit);
              imEvent.putData("direct", "older");
              IMEventService events = getContext().getSerivce(IMService.Type.EVENT);
              events.broadcast(imEvent);
            }
          });
      pageNext.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
              if (currentPage == totalPage) {
                return;
              } else {
                currentPage++;
              }
              // 显示消息
              IMEvent imEvent = new IMEvent(IMEventType.MSG_HISTORY_FIND, namedObject.getEntity());
              imEvent.putData("start", lastKey);
              imEvent.putData("limit", limit);
              imEvent.putData("direct", "newer");
              IMEventService events = getContext().getSerivce(IMService.Type.EVENT);
              events.broadcast(imEvent);
            }
          });
    }