private void performLabelTransformation() { if (getModel().isCustomButton()) { setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); _jLabel.setFont(IEHyperlinkWidget.getButtonFont()); _jLabel.setForeground(Color.WHITE); _jLabel.setBackground(getModel().getFlexoCSS().getButtonColor()); _jLabel.setOpaque(true); _jLabel.setBorder( BorderFactory.createMatteBorder(0, 15, 1, 15, getModel().getFlexoCSS().getButtonColor())); } else { setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); _jLabel.setFont(IECst.WOSTRING_FONT); _jLabel.setForeground(ColorCst.HYPERLINK_COLOR); _jLabel.setOpaque(false); _jLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 1, 10)); } }
public IEHyperlinkWidgetView( IEController ieController, IEHyperlinkWidget model, boolean addDnDSupport, IEWOComponentView view) { super(ieController, model, addDnDSupport, view); project = model.getProject(); _jLabel = new JLabel(getModel().getValue()) { /** * Overrides paint * * @see javax.swing.JComponent#paint(java.awt.Graphics) */ @Override public void paint(Graphics g) { super.paint(g); if (getModel().isCustomButton()) { Rectangle bounds = getBounds(); g.setColor(getBackgroundColor()); g.fillRect(0, 0, ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE); g.fillRect( 0, bounds.height - ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE); g.fillRect( bounds.width - ROUNDED_BORDER_SIZE, 0, ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE); g.fillRect( bounds.width - ROUNDED_BORDER_SIZE, bounds.height - ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE); } } /** * Overrides getPreferredSize * * @see javax.swing.JComponent#getPreferredSize() */ @Override public Dimension getPreferredSize() { if (getModel().isCustomButton()) { String s = getModel().getValue(); if (s == null) { return new Dimension(30, 15); } else { return new Dimension( (int) (getFontMetrics(getFont()).getStringBounds(s, getGraphics()).getWidth() + 32), 15); } } else { return super.getPreferredSize(); } } }; project.addObserver(this); performLabelTransformation(); _jLabel.setMinimumSize(new Dimension(30, 15)); _jLabel.setVerticalTextPosition(SwingConstants.CENTER); _jLabel.setHorizontalAlignment(SwingConstants.CENTER); TransparentMouseListener tml = new TransparentMouseListener(_jLabel, this); _jLabel.addMouseListener(tml); _jLabel.addMouseMotionListener(tml); add(_jLabel); setOpaque(false); validate(); }