Java Code Examples for javax.swing.JLabel.addMouseListener()

The following are Jave code examples for showing how to use addMouseListener() of the javax.swing.JLabel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: LinkButtonPanel.java   View Source Code Vote up 6 votes
private void init() {
    this.setLayout(new FlowLayout(
            FlowLayout.LEADING, 0, 0));
    setLinkLikeButton(button);
    leftParenthesis = new JLabel("(");                              //NOI18N
    rightParenthesis = new JLabel(")");                             //NOI18N
    add(leftParenthesis);
    add(button);
    add(rightParenthesis);
    MouseListener ml = createLabelMouseListener();
    leftParenthesis.addMouseListener(ml);
    rightParenthesis.addMouseListener(ml);
    button.setEnabled(false);
    this.setMaximumSize(
            this.getPreferredSize());
}
 
Example 2
Project: Cognizant-Intelligent-Test-Scripter   File: PropertyEditor.java   View Source Code Vote up 6 votes
private void initReferenceLabel() {
    imageChooser.setFileFilter(new FileNameExtensionFilter("Image", "jpg", "png", "gif", "bmp"));
    referenceLabel = new JLabel() {
        @Override
        public void paint(Graphics grphcs) {
            super.paint(grphcs);
            paintPage(grphcs);
        }

    };
    referenceLabel.setHorizontalAlignment(SwingConstants.CENTER);
    referenceLabel.setComponentPopupMenu(referencePopup);
    jScrollPane2.setViewportView(referenceLabel);
    offsetAdapter = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            setOffsetMarker(e);
        }
    };
    referenceLabel.addMouseListener(offsetAdapter);
}
 
Example 3
Project: Star-Ride--RiverRaid   File: Top10.java   View Source Code Vote up 6 votes
/**
 * Metodo para inicializar componentes.
 */
 public void initComponents(){
    
    volverMenu = new JLabel();
    volverMenu.setBounds(680, 410, 100, 100);
    volverMenu.setIcon(AsignLabelDimension(new ImageIcon(pathBaseLabel+"Flecha-1.png"), volverMenu));
    volverMenu.addMouseListener(new MouseEvents());
    Position = new JLabel[10];
    Score = new JLabel[10];
    Name = new JLabel[10]; 
    Nombres = new String[10];
    Puntos = new int[10];
    StarJedi = cargarFuente("../Starjedi.ttf");
   
    
}
 
Example 4
Project: incubator-netbeans   File: Logo.java   View Source Code Vote up 5 votes
/** Creates a new instance of RecentProjects */
public Logo( String img, String url ) {
    super( new BorderLayout() );
    Icon image = new ImageIcon( ImageUtilities.loadImage(img, true) );
    JLabel label = new JLabel( image );
    label.setBorder( BorderFactory.createEmptyBorder() );
    label.setOpaque( false );
    label.addMouseListener( this );
    setOpaque( false );
    add( label, BorderLayout.CENTER );
    setCursor( Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) );
    this.url = url;
}
 
Example 5
Project: incubator-netbeans   File: LafPanel.java   View Source Code Vote up 5 votes
private JComponent createRestartNotificationDetails() {
    JPanel res = new JPanel( new BorderLayout( 10, 10) );
    res.setOpaque( false );
    JLabel lbl = new JLabel( NbBundle.getMessage( LafPanel.class, "Descr_Restart") ); //NOI18N
    lbl.setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
    res.add( lbl, BorderLayout.CENTER );
    final JCheckBox checkEditorColors = new JCheckBox( NbBundle.getMessage( LafPanel.class, "Hint_ChangeEditorColors" ) ); //NOI18N
    if( isChangeEditorColorsPossible() ) {
        checkEditorColors.setSelected( true );
        checkEditorColors.setOpaque( false );
        res.add( checkEditorColors, BorderLayout.SOUTH );
    }
    lbl.addMouseListener( new MouseAdapter() {
        @Override
        public void mouseClicked( MouseEvent e ) {
            if( null != restartNotification ) {
                restartNotification.clear();
                restartNotification = null;
            }
            if( checkEditorColors.isSelected() ) {
                switchEditorColorsProfile();
            }
            LifecycleManager.getDefault().markForRestart();
            LifecycleManager.getDefault().exit();
        }
    });
    return res;
}
 
Example 6
Project: JWT4B   File: JLabelLink.java   View Source Code Vote up 5 votes
private void addMouseHandler(final JLabel website) {
	website.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
			try {
				Desktop.getDesktop().browse(
						new URI(parseHREF(website.getText())));
			} catch (Exception ex) {
			}
		}
	});
}
 
Example 7
Project: rapidminer   File: IOObjectCacheEntryPanel.java   View Source Code Vote up 5 votes
/**
 * Creates a new {@link IOObjectCacheEntryPanel}.
 *
 * @param icon
 *            The {@link Icon} associated with the entry's type.
 * @param entryType
 *            Human readable representation of the entry's type (e.g., 'Data Table').
 * @param openAction
 *            The action to be performed when clicking in the entry.
 * @param removeAction
 *            An action triggering the removal of the entry.
 */
public IOObjectCacheEntryPanel(Icon icon, String entryType, Action openAction, Action removeAction) {
	super(ENTRY_LAYOUT);

	this.openAction = openAction;

	// add icon label
	JLabel iconLabel = new JLabel(icon);
	add(iconLabel, ICON_CONSTRAINTS);

	// add object type label
	JLabel typeLabel = new JLabel(entryType);
	typeLabel.setMaximumSize(new Dimension(MAX_TYPE_WIDTH, 24));
	typeLabel.setPreferredSize(typeLabel.getMaximumSize());
	typeLabel.setToolTipText(entryType);
	add(typeLabel, TYPE_CONSTRAINTS);

	// add link button performing the specified action, the label displays the entry's key name
	LinkLocalButton openButton = new LinkLocalButton(openAction);
	openButton.setMargin(new Insets(0, 0, 0, 0));
	add(openButton, KEY_CONSTRAINTS);

	// add removal button
	JButton removeButton = new JButton(removeAction);
	removeButton.setBorderPainted(false);
	removeButton.setOpaque(false);
	removeButton.setMinimumSize(buttonSize);
	removeButton.setPreferredSize(buttonSize);
	removeButton.setContentAreaFilled(false);
	removeButton.setText(null);
	add(removeButton, REMOVE_BUTTON_CONSTRAINTS);

	// register mouse listeners
	addMouseListener(hoverMouseListener);
	iconLabel.addMouseListener(dispatchMouseListener);
	typeLabel.addMouseListener(dispatchMouseListener);
	openButton.addMouseListener(dispatchMouseListener);
	removeButton.addMouseListener(dispatchMouseListener);
}
 
Example 8
Project: Tarski   File: OurTabbedSyntaxWidget.java   View Source Code Vote up 5 votes
/** Create a new tab with the given filename (if filename==null, we'll create a blank tab instead)
 * <p> If a text buffer with that filename already exists, we will just switch to it; else we'll read that file into a new tab.
 * @return false iff an error occurred
 */
public boolean newtab(String filename) {
   if (filename!=null) {
      filename = Util.canon(filename);
      for(int i=0; i<tabs.size(); i++) if (tabs.get(i).getFilename().equals(filename)) { if (i!=me) select(i); return true; }
   }
   final JLabel lb = OurUtil.label("", OurUtil.getVizFont().deriveFont(Font.BOLD), Color.BLACK, Color.WHITE);
   lb.setBorder(new OurBorder(BORDER, BORDER, Color.WHITE, BORDER));
   lb.addMouseListener(new MouseAdapter() {
      @Override public void mousePressed(MouseEvent e) { for(int i=0; i<tabs.size(); i++) if (tabs.get(i).obj1 == lb) select(i); }
   });
   JPanel h1 = OurUtil.makeH(4); h1.setBorder(new OurBorder(null, null, BORDER, null));
   JPanel h2 = OurUtil.makeH(3); h2.setBorder(new OurBorder(null, null, BORDER, null));
   JPanel pan = Util.onMac() ? OurUtil.makeVL(null, 2, OurUtil.makeHB(h1, lb, h2))
                             : OurUtil.makeVL(null, 2, OurUtil.makeHB(h1, lb, h2, GRAY), GRAY);
   pan.setAlignmentX(0.0f);
   pan.setAlignmentY(1.0f);
   OurSyntaxWidget text = new OurSyntaxWidget(syntaxHighlighting, "", fontName, fontSize, tabSize, lb, pan);
   tabBar.add(pan, tabs.size());
   tabs.add(text);
   text.listeners.add(listener); // add listener AFTER we've updated this.tabs and this.tabBar
   if (filename==null) {
      text.discard(false, getFilenames()); // forces the tab to re-derive a suitable fresh name
   } else {
      if (!text.load(filename)) return false;
      for(int i=tabs.size()-1; i>=0; i--) if (!tabs.get(i).isFile() && tabs.get(i).getText().length()==0) {
         tabs.get(i).discard(false, getFilenames()); close(i); break; // Remove the rightmost untitled empty tab
      }
   }
   select(tabs.size() - 1); // Must call this to switch to the new tab; and it will fire STATUS_CHANGE message which is important
   return true;
}
 
Example 9
Project: SimpleERP   File: Chooser.java   View Source Code Vote up 5 votes
private void initTitlePanel(){
    preYear = new JLabel("<<", JLabel.CENTER);
    preMonth = new JLabel("<", JLabel.CENTER);
    center = new JLabel("", JLabel.CENTER);
    centercontainer = new JLabel("", JLabel.CENTER);
    nextMonth = new JLabel(">", JLabel.CENTER);
    nextYear = new JLabel(">>", JLabel.CENTER);
    
    preYear.setToolTipText("Last Year");
    preMonth.setToolTipText("Last Month");
    nextMonth.setToolTipText("Next Month");
    nextYear.setToolTipText("Next Year");
    
    preYear.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 10, 0, 0));
    preMonth.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 15, 0, 0));
    nextMonth.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 0, 0, 15));
    nextYear.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 0, 0, 10));
    
    centercontainer.setLayout(new java.awt.BorderLayout());
    centercontainer.add(preMonth,java.awt.BorderLayout.WEST);
    centercontainer.add(center,java.awt.BorderLayout.CENTER);
    centercontainer.add(nextMonth,java.awt.BorderLayout.EAST);
    
    this.add(preYear,java.awt.BorderLayout.WEST);
    this.add(centercontainer,java.awt.BorderLayout.CENTER);
    this.add(nextYear,java.awt.BorderLayout.EAST);
    this.setPreferredSize(new java.awt.Dimension(210, 25));
    
    updateDate();
    
    preYear.addMouseListener(new MyMouseAdapter(preYear, Calendar.YEAR, -1));
    preMonth.addMouseListener(new MyMouseAdapter(preMonth, Calendar.MONTH, -1));
    nextMonth.addMouseListener(new MyMouseAdapter(nextMonth, Calendar.MONTH, 1));
    nextYear.addMouseListener(new MyMouseAdapter(nextYear, Calendar.YEAR, 1));
}
 
Example 10
Project: cc-unespar   File: Mouse.java   View Source Code Vote up 5 votes
public void telinha() {	
	janela = new JFrame();
	//janela.addMouseListener(this);
	//janela.setSize(img.getWidth(null), img.getHeight(null));
	JLabel background = new JLabel();
	ImageIcon icone = new ImageIcon(img);
	background.addMouseListener(this);
	background.setSize(img.getWidth(null), img.getHeight(null));
	background.setIcon(icone);
	janela.add(background);
	janela.setVisible(true);
	janela.setFocusable(true);
	janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
}
 
Example 11
Project: Equella   File: ClientLauncher.java   View Source Code Vote up 5 votes
private JComponent createServerList()
{
	JLabel profileLabel = new JLabel("Choose a Server:");

	configureLink = new JLabel("Configure...");
	configureLink.setForeground(Color.BLUE);
	configureLink.addMouseListener(this);

	profileChoice = new JComboBox();
	profileChoice.addActionListener(this);
	profileChoice.setRenderer(new DefaultListCellRenderer()
	{
		@Override
		public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
			boolean cellHasFocus)
		{
			super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
			ServerProfile p = (ServerProfile) value;
			if( p != null )
			{
				setText(p.getName() + " - " + p.getServer());
			}
			return this;
		}
	});

	final int height1 = profileChoice.getPreferredSize().height;
	final int width1 = configureLink.getPreferredSize().width;

	final int[] rows = {height1, height1,};
	final int[] cols = {TableLayout.FILL, width1,};

	JPanel all = new JPanel(new TableLayout(rows, cols));
	all.add(profileLabel, new Rectangle(0, 0, 1, 1));
	all.add(configureLink, new Rectangle(1, 0, 1, 1));
	all.add(profileChoice, new Rectangle(0, 1, 2, 1));

	return all;
}
 
Example 12
Project: hearthstone   File: EscolherCard.java   View Source Code Vote up 5 votes
/**
 * Preenche o painel com os cards para seleção
 */
private void preencher() {
    for (int index = 0; index < ids.length; index++) {
        final int i = index;
        JLabel label = new JLabel(Images.getCardIcon(Images.CARD_ORIGINAL, ids[index]));
        label.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent evt) {
                selecionado(ids[i]);
            }
        });
        jPanelCards.add(label);
    }
}
 
Example 13
Project: hearthstone   File: Muligar.java   View Source Code Vote up 5 votes
/**
 * preenche o painel com a lista de cards disponíveis para muligar
 */
private void preencher() {
    for (int index = 0; index < labelX.length; index++) {
        JPanel panel = new JPanel(new AbsoluteLayout());
        panel.setBackground(new Color(0, 0, 0, 0));
        JLabel label_card = new JLabel(Images.getCardIcon(Images.CARD_ORIGINAL, deck.get(index).getId()));
        labelX[index] = new JLabel();
        label_card.addMouseListener(eventoClicarNoCard(index));
        labelX[index].addMouseListener(eventoClicarNaImagemX(index));
        panel.add(labelX[index], new AbsoluteConstraints(20, 125));
        panel.add(label_card, new AbsoluteConstraints(0, 0));
        jPanelCards.add(panel);
    }
}
 
Example 14
Project: FreeCol   File: CornerMapControls.java   View Source Code Vote up 4 votes
/**
 * The basic constructor.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 */
public CornerMapControls(final FreeColClient freeColClient) {
    super(freeColClient, true);

    compassRose = new JLabel(new ImageIcon(ResourceManager.getImage("image.skin.compass")));
    compassRose.setFocusable(false);
    compassRose.setSize(compassRose.getPreferredSize());
    compassRose.addMouseListener(new MouseAdapter() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void mouseClicked(MouseEvent e) {
                Unit unit = getGUI().getActiveUnit();
                if (unit == null) return;
                int x = e.getX() - compassRose.getWidth()/2;
                int y = e.getY() - compassRose.getHeight()/2;
                double theta = Math.atan2(y, x) + Math.PI/2 + Math.PI/8;
                if (theta < 0) {
                    theta += 2*Math.PI;
                }
                igc().moveUnit(unit, Direction.angleToDirection(theta));
            }
        });

    miniMapPanel = new MiniMapPanel();
    miniMapPanel.setFocusable(false);
    
    /**
     * In order to make the setLocation setup work, we need to set
     * the layout to null first, then set the size of the minimap,
     * and then its location.
     */
    miniMapPanel.setLayout(null);
    miniMap.setSize(MAP_WIDTH, MAP_HEIGHT);
    // Add buttons:
    miniMapPanel.add(miniMapToggleBorders);
    miniMapPanel.add(miniMapToggleFogOfWarButton);
    miniMapPanel.add(miniMapZoomInButton);
    miniMapPanel.add(miniMapZoomOutButton);
    miniMapPanel.add(miniMap);

    String miniMapSkinKey = "image.skin.MiniMap";
    if (ResourceManager.hasImageResource(miniMapSkinKey)) {
        miniMapSkin = ResourceManager.getImage(miniMapSkinKey);
        miniMapPanel.setBorder(null);
        miniMapPanel.setSize(miniMapSkin.getWidth(null),
                             miniMapSkin.getHeight(null));
        miniMapPanel.setOpaque(false);
        // FIXME: LATER: The values below should be specified by a
        // skin-configuration-file.
        miniMap.setLocation(38, 75);
        miniMapToggleBorders.setLocation(4,114);
        miniMapToggleFogOfWarButton.setLocation(4, 144);
        miniMapZoomInButton.setLocation(4, 174);
        miniMapZoomOutButton.setLocation(264, 174);
    } else {
        miniMapSkin = null;
        int width = miniMapZoomOutButton.getWidth()
            + miniMapZoomInButton.getWidth() + 4 * GAP;
        miniMapPanel.setOpaque(true);
        miniMap.setBorder(new BevelBorder(BevelBorder.RAISED));
        miniMap.setLocation(width/2, GAP);
        miniMapZoomInButton.setLocation(GAP, 
            MAP_HEIGHT + GAP - miniMapZoomInButton.getHeight());
        miniMapZoomOutButton.setLocation(
            miniMapZoomInButton.getWidth() + MAP_WIDTH + 3 * GAP,
            MAP_HEIGHT + GAP - miniMapZoomOutButton.getHeight());
    }
}
 
Example 15
Project: incubator-netbeans   File: StatusLineComponent.java   View Source Code Vote up 4 votes
private void createLabel() {
    discardLabel();
    label = new JLabel();
    label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    label.addMouseListener(mouseListener);
}
 
Example 16
Project: incubator-netbeans   File: StatusLineComponent.java   View Source Code Vote up 4 votes
private void createExtraLabel() {
    discardExtraLabel();
    extraLabel = new JLabel();
    extraLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    extraLabel.addMouseListener(mouseListener);
}
 
Example 17
Project: Star-Ride--RiverRaid   File: Instrucciones.java   View Source Code Vote up 4 votes
/**
 * Inicializa con las imagenes predeterminadas
 */
public void initButtons(){
    
    volverMenu = new JLabel();
    volverMenu.setBounds(650, 450, 100, 100);
    volverMenu.setIcon(AsignLabelDimension(new ImageIcon(pathBaseLabel+"Flecha-1.png"), volverMenu));
    volverMenu.addMouseListener(new MouseEvent());
    
    left = new JLabel();
    left.setBounds(90, 370, 60, 60);
    left.setIcon(AsignLabelDimension(new ImageIcon(pathBaseLabel+"Izquierda-1.png"), left));

    up = new JLabel();
    up.setBounds(150, 310, 60, 60);
    up.setIcon(AsignLabelDimension(new ImageIcon(pathBaseLabel+"Arriba-1.png"), up));
    
    right = new JLabel();
    right.setBounds(210, 370, 60, 60);
    right.setIcon(AsignLabelDimension(new ImageIcon(pathBaseLabel+"Derecha-1.png"), right));
    
    
    keyboard = new JLabel();
    keyboard.setBounds(130, 430, 120, 70);
    keyboard.setIcon(AsignLabelDimension(new ImageIcon(pathBaseLabel+"KeyBoard-1.png"), keyboard));
    
    fuel = new JLabel();
    fuel.setBounds(450, 320, 50, 50);
    fuel.setIcon(new ImageIcon("Resources/EnergyFinal.gif"));
    
    
    pause = new JLabel();
    pause.setBounds(460, 380, 40, 40);
    pause.setIcon(AsignLabelDimension(new ImageIcon(pathBaseLabel+"escape2.png"), pause));
    
    enter = new JLabel();
    enter.setBounds(460, 430, 40, 40);
    enter.setIcon(AsignLabelDimension(new ImageIcon(pathBaseLabel+"enter.png"), enter));
    
    combustible = new JLabel();
    combustible.setBounds(510, 325, 150, 40);
    StarJedi = cargarFuente("../Starjedi.ttf");
    combustible.setForeground(Color.WHITE);
    combustible.setFont(StarJedi);
    combustible.setText("Combustible");
    
    reanudar = new JLabel();
    reanudar.setBounds(510, 430, 150, 40);
    reanudar.setForeground(Color.WHITE);
    reanudar.setFont(StarJedi);
    reanudar.setText("Reanudar Juego");
    
    pausa = new JLabel();
    pausa.setBounds(510, 375, 150, 40);
    pausa.setForeground(Color.WHITE);
    pausa.setFont(StarJedi);
    pausa.setText("Pausar Juego");
    
}
 
Example 18
Project: org.alloytools.alloy   File: OurTabbedSyntaxWidget.java   View Source Code Vote up 4 votes
/**
 * Create a new tab with the given filename (if filename==null, we'll create
 * a blank tab instead)
 * <p>
 * If a text buffer with that filename already exists, we will just switch
 * to it; else we'll read that file into a new tab.
 * 
 * @return false iff an error occurred
 */
public boolean newtab(String filename) {
	if (filename != null) {
		filename = Util.canon(filename);
		for (int i = 0; i < tabs.size(); i++)
			if (tabs.get(i).getFilename().equals(filename)) {
				if (i != me)
					select(i);
				return true;
			}
	}
	final JLabel lb = OurUtil.label("", OurUtil.getVizFont().deriveFont(Font.BOLD), Color.BLACK, Color.WHITE);
	lb.setBorder(new OurBorder(BORDER, BORDER, Color.WHITE, BORDER));
	lb.addMouseListener(new MouseAdapter() {
		@Override
		public void mousePressed(MouseEvent e) {
			for (int i = 0; i < tabs.size(); i++)
				if (tabs.get(i).obj1 == lb)
					select(i);
		}
	});
	JPanel h1 = OurUtil.makeH(4);
	h1.setBorder(new OurBorder(null, null, BORDER, null));
	JPanel h2 = OurUtil.makeH(3);
	h2.setBorder(new OurBorder(null, null, BORDER, null));
	JPanel pan = Util.onMac() ? OurUtil.makeVL(null, 2, OurUtil.makeHB(h1, lb, h2))
			: OurUtil.makeVL(null, 2, OurUtil.makeHB(h1, lb, h2, GRAY), GRAY);
	pan.setAlignmentX(0.0f);
	pan.setAlignmentY(1.0f);
	OurSyntaxWidget text = new OurSyntaxWidget(syntaxHighlighting, "", fontName, fontSize, tabSize, lb, pan);
	tabBar.add(pan, tabs.size());
	tabs.add(text);
	text.listeners.add(listener); // add listener AFTER we've updated
									// this.tabs and this.tabBar
	if (filename == null) {
		text.discard(false, getFilenames()); // forces the tab to re-derive
												// a suitable fresh name
	} else {
		if (!text.load(filename))
			return false;
		for (int i = tabs.size() - 1; i >= 0; i--)
			if (!tabs.get(i).isFile() && tabs.get(i).getText().length() == 0) {
				tabs.get(i).discard(false, getFilenames());
				close(i);
				break; // Remove the rightmost untitled empty tab
			}
	}
	select(tabs.size() - 1); // Must call this to switch to the new tab; and
								// it will fire STATUS_CHANGE message which
								// is important
	return true;
}
 
Example 19
Project: ramus   File: ButtonTabComponent.java   View Source Code Vote up 4 votes
public ButtonTabComponent(final CloseableTabbedPane pane,
                          JPopupMenu popupMenu) {
    // unset default FlowLayout' gaps
    super(new FlowLayout(FlowLayout.LEFT, 0, 0));
    if (pane == null) {
        throw new NullPointerException("TabbedPane is null");
    }
    this.pane = pane;
    setOpaque(false);

    // make JLabel read titles from JTabbedPane
    JLabel label = new JLabel() {
        /**
         *
         */
        private static final long serialVersionUID = 1524411103289809222L;

        public String getText() {
            int i = pane.indexOfTabComponent(ButtonTabComponent.this);
            if (i != -1) {
                return pane.getTitleAt(i);
            }
            return null;
        }
    };

    label.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            for (int i = 0; i < pane.getTabCount(); i++)
                if (pane.getTabComponentAt(i) == ButtonTabComponent.this)
                    pane.setSelectedIndex(i);
        }
    });

    add(label);
    // add more space between the label and the button
    label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
    // tab button
    JButton button = new TabButton();
    add(button);
    // add more space to the top of the component
    setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));

    setComponentPopupMenu(popupMenu);
}
 
Example 20
Project: freecol   File: CornerMapControls.java   View Source Code Vote up 4 votes
/**
 * The basic constructor.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 */
public CornerMapControls(final FreeColClient freeColClient) {
    super(freeColClient, true);

    compassRose = new JLabel(new ImageIcon(ResourceManager.getImage("image.skin.compass")));
    compassRose.setFocusable(false);
    compassRose.setSize(compassRose.getPreferredSize());
    compassRose.addMouseListener(new MouseAdapter() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void mouseClicked(MouseEvent e) {
                Unit unit = getGUI().getActiveUnit();
                if (unit == null) return;
                int x = e.getX() - compassRose.getWidth()/2;
                int y = e.getY() - compassRose.getHeight()/2;
                double theta = Math.atan2(y, x) + Math.PI/2 + Math.PI/8;
                if (theta < 0) {
                    theta += 2*Math.PI;
                }
                igc().moveUnit(unit, Direction.angleToDirection(theta));
            }
        });

    miniMapPanel = new MiniMapPanel();
    miniMapPanel.setFocusable(false);
    
    /**
     * In order to make the setLocation setup work, we need to set
     * the layout to null first, then set the size of the minimap,
     * and then its location.
     */
    miniMapPanel.setLayout(null);
    miniMap.setSize(MAP_WIDTH, MAP_HEIGHT);
    // Add buttons:
    miniMapPanel.add(miniMapToggleBorders);
    miniMapPanel.add(miniMapToggleFogOfWarButton);
    miniMapPanel.add(miniMapZoomInButton);
    miniMapPanel.add(miniMapZoomOutButton);
    miniMapPanel.add(miniMap);

    String miniMapSkinKey = "image.skin.MiniMap";
    if (ResourceManager.hasImageResource(miniMapSkinKey)) {
        miniMapSkin = ResourceManager.getImage(miniMapSkinKey);
        miniMapPanel.setBorder(null);
        miniMapPanel.setSize(miniMapSkin.getWidth(null),
                             miniMapSkin.getHeight(null));
        miniMapPanel.setOpaque(false);
        // FIXME: LATER: The values below should be specified by a
        // skin-configuration-file.
        miniMap.setLocation(38, 75);
        miniMapToggleBorders.setLocation(4,114);
        miniMapToggleFogOfWarButton.setLocation(4, 144);
        miniMapZoomInButton.setLocation(4, 174);
        miniMapZoomOutButton.setLocation(264, 174);
    } else {
        miniMapSkin = null;
        int width = miniMapZoomOutButton.getWidth()
            + miniMapZoomInButton.getWidth() + 4 * GAP;
        miniMapPanel.setOpaque(true);
        miniMap.setBorder(new BevelBorder(BevelBorder.RAISED));
        miniMap.setLocation(width/2, GAP);
        miniMapZoomInButton.setLocation(GAP, 
            MAP_HEIGHT + GAP - miniMapZoomInButton.getHeight());
        miniMapZoomOutButton.setLocation(
            miniMapZoomInButton.getWidth() + MAP_WIDTH + 3 * GAP,
            MAP_HEIGHT + GAP - miniMapZoomOutButton.getHeight());
    }
}