@Override
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      if (list instanceof CheckList) {
        // calculate the max width of the logo
        int maxWidth = 0;
        for (int i = 0; i < list.getModel().getSize(); i++) {
          Object obj = list.getModel().getElementAt(i);
          if (obj instanceof MediaScraper) {
            MediaScraper ms = (MediaScraper) obj;
            ImageIcon logo = getIcon(ms.getLogoURL());
            maxWidth = Math.max(maxWidth, logo.getIconWidth());
          }
        }

        CheckList cbl = (CheckList) list;
        ListCheckModel model = cbl.getModel();
        boolean checked = model.isChecked(value);
        boolean locked = model.isLocked(value);
        setSelected(checked);

        if (locked || cbl.isEnabled() == false) {
          setEnabled(false);
        } else {
          setEnabled(true);
        }

        if (getHighlight().equals(Highlight.MOUSE_OVER_AND_CHECKED_ITEMS)
            && (checked || isSelected)) {
          panel.setBackground(selectionBackground);
          panel.setForeground(selectionForeground);
        } else if (getHighlight().equals(Highlight.MOUSE_OVER) && isSelected) {
          panel.setBackground(selectionBackground);
          panel.setForeground(selectionForeground);
        } else if (getHighlight().equals(Highlight.CHECKED_ITEMS) && checked) {
          panel.setBackground(selectionBackground);
          panel.setForeground(selectionForeground);
        } else {
          panel.setBackground(background);
          panel.setForeground(foreground);
        }
        if (value instanceof MediaScraper) {
          MediaScraper scraper = (MediaScraper) value;
          int currentWidth = 0;
          ImageIcon logo = getIcon(scraper.getLogoURL());
          if (logo != null) {
            currentWidth = logo.getIconWidth();
          }

          label.setIcon(logo);
          label.setIconTextGap(maxWidth + 4 - currentWidth); // 4 = default iconTextGap
        } else {
          label.setIcon(null);
          label.setIconTextGap(4); // 4 = default iconTextGap
        }
      }
      label.setText(getText(value));
      return panel;
    }
Ejemplo n.º 2
0
  public void updateShowHideCalendars(ArrayList<User> users) {
    GroupLayout layout = new GroupLayout(showHideCalendarsPanel);
    showHideCalendarsPanel.setLayout(layout);

    labels = new ArrayList<JLabel>(); // emptying the list
    for (int i = 0; i < users.size(); i++) {
      JLabel temp = new JLabel();
      temp.addMouseListener(mouseTempListener(temp));

      temp.setText(users.get(i).getName());
      temp.setBackground(Color.white);

      temp.setOpaque(true);
      temp.setIcon(tick);
      temp.setIconTextGap(10);
      temp.setBorder(BorderFactory.createEmptyBorder(3, 10, 3, 10));
      labels.add(temp);
    }

    ParallelGroup showHideCalendarsHorizontalGroup =
        layout.createParallelGroup(GroupLayout.Alignment.LEADING);
    for (int i = 0; i < labels.size(); i++) {
      showHideCalendarsHorizontalGroup.addComponent(
          labels.get(i), GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE);
    }

    SequentialGroup showHideCalendarsVerticalGroup = layout.createSequentialGroup();
    for (int i = 0; i < labels.size(); i++) {
      showHideCalendarsVerticalGroup.addComponent(
          labels.get(i), GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE);
    }

    layout.setHorizontalGroup(showHideCalendarsHorizontalGroup);
    layout.setVerticalGroup(showHideCalendarsVerticalGroup);
  }
Ejemplo n.º 3
0
  private void createGUI() {

    dataSourcePanel = new DataSourcePanel(app, mode);

    lblTitle = new JLabel();
    lblTitle.setIconTextGap(10);

    btnOK = new JButton();
    btnOK.addActionListener(this);

    btnCancel = new JButton();
    btnCancel.addActionListener(this);

    JPanel titlePanel = LayoutUtil.flowPanel(lblTitle);
    // titlePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(titlePanel, BorderLayout.NORTH);
    mainPanel.add(dataSourcePanel, BorderLayout.CENTER);
    mainPanel.add(LayoutUtil.flowPanelRight(5, 0, 0, btnCancel, btnOK), BorderLayout.SOUTH);

    mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(mainPanel, BorderLayout.CENTER);
    setLabels();
  }
Ejemplo n.º 4
0
 @Override
 public void setIconTextGap(int iconTextGap) {
   super.setIconTextGap(iconTextGap);
   if (myEditorPane != null) {
     setLayout(new BorderLayout(iconTextGap, 0));
     add(myIconLabel, BorderLayout.WEST);
     add(myEditorPane, BorderLayout.CENTER);
   }
 }
Ejemplo n.º 5
0
 protected JLabel createTitleLabel(int preferredWidth) {
   JLabel result = new JLabel(getTitle());
   result.setHorizontalAlignment(SwingConstants.CENTER);
   if (getIcon() != null) {
     result.setIcon(getIcon());
     result.setIconTextGap(10);
   }
   result.setBackground(titleBgColor);
   result.setForeground(titleForeColor);
   result.setOpaque(true);
   result.setBorder(titleBorder);
   result.validate();
   Dimension d = result.getPreferredSize();
   result.setPreferredSize(new Dimension(Math.max(d.width, preferredWidth), d.height));
   result.setMinimumSize(result.getPreferredSize());
   return result;
 }
Ejemplo n.º 6
0
 @Nullable
 @Override
 protected JComponent createCenterPanel() {
   JLabel label =
       new JLabel(
           "<html><body>"
               + "The encoding you've chosen ('"
               + charset.displayName()
               + "') may change the contents of '"
               + virtualFile.getName()
               + "'.<br>"
               + "Do you want to reload the file from disk or<br>"
               + "convert the text and save in the new encoding?"
               + "</body></html>");
   label.setIcon(Messages.getQuestionIcon());
   label.setIconTextGap(10);
   return label;
 }
Ejemplo n.º 7
0
  public JPopupMenu createMenu(
      JPopupMenu popupMenu,
      TableLine[] lines,
      boolean markAsSpam,
      boolean markAsNot,
      ResultPanel resultPanel) {
    JPopupMenu menu = new JPopupMenu();
    List<JLabel> labels = new ArrayList<JLabel>(5);
    for (TableLine line : lines) {
      SharedSearchResult result = (SharedSearchResult) line.getSearchResult();
      JLabel label = new JLabel(I18n.tr("Path") + ": " + result.getFileDesc().getPath());
      menu.insert(label, labels.size());
      labels.add(label);
      if (labels.size() == 5 && lines.length > labels.size()) {
        int numberOfMore = lines.length - labels.size();
        label = new JLabel(I18n.trn("... {0} more.", "... {0} more.", numberOfMore, numberOfMore));
        menu.insert(label, labels.size());
        labels.add(label);
        break;
      }
    }
    menu.addSeparator();

    // TODO: fix this hidden coupling, SharedSearchResult needs to be tied MyFilesResultPanel
    //        explicitly
    JMenuItem menuItem =
        new JMenuItem(((MySharedFilesResultPanel) resultPanel).getUnshareAction(lines.length));
    menu.add(menuItem);

    // configure label to have the same borders and margins as a menu item
    Insets margin = menuItem.getMargin();
    Insets border = menuItem.getInsets();
    for (JLabel label : labels) {
      label.setBorder(
          BorderFactory.createEmptyBorder(
              border.top, margin.left + border.left, border.bottom, margin.right + border.right));
      label.setIconTextGap(menuItem.getIconTextGap());
      // if icon is null, icon text gap value is ignored
      label.setIcon(new GUIUtils.EmptyIcon("empty", 0, 0));
    }

    return menu;
  }
Ejemplo n.º 8
0
 public CategoryLabel(String name, Topology topo, Color color) {
   super(name, new CategoryIcon(topo, color), SwingConstants.LEFT);
   super.setIconTextGap(2 * Const.CELL_ICON_TEXT_GAP);
 }
Ejemplo n.º 9
0
 public CategoryLabel(final Category objdef) {
   super(objdef.getName(), new CategoryIcon(objdef), SwingConstants.LEFT);
   super.setIconTextGap(2 * Const.CELL_ICON_TEXT_GAP);
 }
Ejemplo n.º 10
0
  public static void main(String[] args) {
    try {
      System.setProperty("sun.java2d.noddraw", "true");
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }
    JFrame f = new JFrame("Balloon Test");
    final String BALLOON_TEXT =
        "<html><center>"
            + "This is some sample balloon text<br>"
            + "which has been formatted with html.<br>"
            + "Click to dismiss.</center></html>";
    final JLabel content = new JLabel(BALLOON_TEXT);
    content.setIconTextGap(10);
    content.setBorder(new EmptyBorder(0, 8, 0, 8));
    content.setSize(content.getPreferredSize());
    content.setIcon(new InfoIcon());
    JLabel label = new JLabel("Click anywhere for more information");
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.addMouseListener(
        new MouseAdapter() {
          private MouseListener listener =
              new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                  hidePopup(e);
                }
              };
          private Popup popup;

          private void hidePopup(MouseEvent e) {
            e.getComponent().removeMouseListener(listener);
            if (popup != null) popup.hide();
          }

          public void mousePressed(MouseEvent e) {
            hidePopup(e);
            popup = BalloonManager.getBalloon(e.getComponent(), content, e.getX(), e.getY());
            popup.show();
            content.getParent().addMouseListener(listener);
          }
        });
    f.getContentPane().add(label);
    f.pack();
    f.setSize(new Dimension(300, 300));
    f.setLocation(100, 100);
    try {
      // Force a load of JNA
      WindowUtils.setWindowMask(f, WindowUtils.MASK_NONE);
      f.setVisible(true);
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } catch (UnsatisfiedLinkError e) {
      e.printStackTrace();
      String msg = e.getMessage() + "\nError loading the JNA library";
      JTextArea area = new JTextArea(msg);
      area.setOpaque(false);
      area.setFont(UIManager.getFont("Label.font"));
      area.setEditable(false);
      area.setColumns(80);
      area.setRows(8);
      area.setWrapStyleWord(true);
      area.setLineWrap(true);
      JOptionPane.showMessageDialog(
          null,
          new JScrollPane(area),
          "Library Load Error: "
              + System.getProperty("os.name")
              + "/"
              + System.getProperty("os.arch"),
          JOptionPane.ERROR_MESSAGE);
      System.exit(1);
    }
  }