Java Code Examples for javax.swing.JPanel#addMouseListener()

The following examples show how to use javax.swing.JPanel#addMouseListener() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * set up the thumb image UI
 *
 * @param f
 * @return
 */
JPanel getPanel(final String f) {
    setThumbImage(f);
    JPanel p = new JPanel() {
        @Override
        public void paintComponent(Graphics g) {
            g.drawImage(thumbs.get(f), 0, 0, null);
        }
    };
    p.setPreferredSize(THUMB_SIZE);
    p.setBorder(new LineBorder(Color.LIGHT_GRAY, 3));
    JComponent c = getThumbSelector(f);
    JComponent cl = setupThumbClose(p);
    setupAlignment(p, c, cl);
    p.setName(f);
    p.addMouseListener(thumbselected);
    p.addMouseListener(Listeners.thumbPrevFocus);
    thumbList.add(p);
    return p;
}
 
Example 2
private static JPanel createBox(final Color color, final Consumer<Color> consumer, final boolean alphaHidden)
{
	final JPanel box = new JPanel();
	String hex = alphaHidden ? ColorUtil.colorToHexCode(color) : ColorUtil.colorToAlphaHexCode(color);

	box.setBackground(color);
	box.setOpaque(true);
	box.setPreferredSize(new Dimension(BOX_SIZE, BOX_SIZE));
	box.setToolTipText("#" + hex.toUpperCase());
	box.addMouseListener(new MouseAdapter()
	{
		@Override
		public void mouseClicked(MouseEvent e)
		{
			consumer.accept(color);
		}
	});

	return box;
}
 
Example 3
protected void setupGlassPane(JPanel glassPane) {
    this.glassPane = glassPane;
    if (mouse != null) {
        glassPane.addMouseListener(mouse);
        if (enableInteraction) {
            glassPane.addMouseMotionListener(mouse);
        }
    }
}
 
Example 4
protected void setupGlassPane(JPanel glassPane) {
    this.glassPane = glassPane;
    if (mouse != null) {
        glassPane.addMouseListener(mouse);
        if (enableInteraction) {
            glassPane.addMouseMotionListener(mouse);
        }
    }
}
 
Example 5
public BinaryPanel(final MainPanel mainPanel) {
    super(new BorderLayout());
    this.mainPanel = mainPanel;

    add(new JScrollPane(hexEditor), BorderLayout.CENTER);

    JPanel bottomPanel = new JPanel(new BorderLayout());
    JPanel buttonsPanel = new JPanel(new FlowLayout());
    bottomPanel.add(buttonsPanel, BorderLayout.EAST);
    add(bottomPanel, BorderLayout.SOUTH);

    // todo: honfika: dynamically resize the hex data
    /*addComponentListener(new ComponentAdapter() {

     @Override
     public void componentResized(ComponentEvent e) {
     setBinaryData(binaryDataTag);
     }
     });*/
    swfInsidePanel = new JPanel();
    swfInsidePanel.setBackground(new Color(253, 205, 137));
    swfInsidePanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    swfInsidePanel.add(new JLabel(AppStrings.translate("binarydata.swfInside")));
    swfInsidePanel.setFocusable(true);
    swfInsidePanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    swfInsidePanel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            mainPanel.loadFromBinaryTag(binaryDataTag);
            swfInsidePanel.setVisible(false);
        }

    });
    add(swfInsidePanel, BorderLayout.NORTH);
    swfInsidePanel.setVisible(false);
}
 
Example 6
Source Project: qupla   File: GameOfLifeEntity.java    License: Apache License 2.0 4 votes vote down vote up
public GameOfLifeEntity()
{
  super(0);

  final Dispatcher dispatcher = Dispatcher.getInstance();
  golGen = dispatcher.getEnvironment("GolGen", null);
  golHash = dispatcher.getEnvironment("GolHash", null);
  golIds = dispatcher.getEnvironment("GolIds", null);
  golSend = dispatcher.getEnvironment("GolSend", null);
  golView = dispatcher.getEnvironment("GolView", null);
  join(golView);

  gridImage = new BufferedImage(GRID_SIZE, GRID_SIZE, BufferedImage.TYPE_3BYTE_BGR);

  gridView = new JPanel();
  gridView.setPreferredSize(new Dimension(200, 200));
  gridView.setVisible(true);
  final MouseInputAdapter mouseAdapter = getMouseInputAdapter();
  gridView.addMouseListener(mouseAdapter);
  gridView.addMouseMotionListener(mouseAdapter);

  final JLabel label = new JLabel();
  label.setText("GoL ID:");

  entry = new JTextField();
  addChangeListener();

  final JPanel idPanel = new JPanel();
  idPanel.setLayout(new BoxLayout(idPanel, BoxLayout.X_AXIS));
  idPanel.add(label);
  idPanel.add(entry);

  frame = new JFrame("Game of Life");
  frame.addWindowListener(ViewEntity.windowAdapter);
  frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  frame.setLayout(new BorderLayout());
  frame.add(idPanel, BorderLayout.PAGE_START);
  frame.add(gridView, BorderLayout.CENTER);
  frame.addComponentListener(new ComponentAdapter()
  {
    public void componentResized(ComponentEvent evt)
    {
      drawGridImage();
    }
  });
  frame.setVisible(true);
  frame.setSize(400, 400);
}
 
Example 7
public static void main(String... args) {
	final int x = 50;
	final int y = 50;
	JFrame f = new JFrame();

	final BasicTextField tf1 = new BasicTextField();
	tf1.setText("111");
	tf1.setPosition(x,  y);
	tf1.setJustification(JUSTIFY_RIGHT, JUSTIFY_BOTTOM);

	final BasicTextField tf2 = new BasicTextField();
	tf2.setText("222");
	tf2.setPosition(x,  y);
	tf2.setJustification(JUSTIFY_LEFT, JUSTIFY_BOTTOM);

	final BasicTextField tf3 = new BasicTextField();
	tf3.setText("333");
	tf3.setPosition(x,  y);
	tf3.setJustification(JUSTIFY_RIGHT, JUSTIFY_TOP);

	final BasicTextField tf4 = new BasicTextField();
	tf4.setText("444");
	tf4.setPosition(x,  y);
	tf4.setJustification(JUSTIFY_LEFT, JUSTIFY_TOP);
	JPanel p = new JPanel() {
		private static final long serialVersionUID = 1420261164629448825L;

		@Override
		public void paintComponent(Graphics g) {
			g.drawLine(0, y, getWidth(), y);
			g.drawLine(x, 0, x, getHeight());
			tf1.paint(g);
			tf2.paint(g);
			tf3.paint(g);
			tf4.paint(g);
		}
	};
	p.addMouseListener(tf1);
	p.addMouseListener(tf2);
	p.addMouseListener(tf3);
	p.addMouseListener(tf4);
	p.addKeyListener(tf1);
	p.addKeyListener(tf2);
	p.addKeyListener(tf3);
	p.addKeyListener(tf4);
	p.setPreferredSize(new Dimension(300, 300));
	f.getContentPane().add(p);
	f.pack();
	f.setVisible(true);
}
 
Example 8
public final void defineLayout (final String currentLang)
{
    panel.removeAll();

    final Set<String> relevant = new TreeSet<String>();
    relevant.addAll(desired);
    relevant.addAll(nonDesired);

    final String        gap = "$lcgap";
    final StringBuilder columns = new StringBuilder();

    for (int i = 0; i < relevant.size(); i++) {
        if (columns.length() > 0) {
            columns.append(",");
        }

        columns.append(gap)
               .append(",")
               .append("pref");
    }

    final CellConstraints cst = new CellConstraints();
    final FormLayout   layout = new FormLayout(
        columns.toString(),
        "center:16dlu");
    final PanelBuilder builder = new PanelBuilder(layout, panel);
    PanelBuilder.setOpaqueDefault(true);
    builder.background(Color.WHITE);

    int                   col = 2;

    for (String lang : relevant) {
        final FormLayout langLayout = new FormLayout(
            "$lcgap,center:pref,$lcgap",
            "center:12dlu");
        final JPanel     comp = new JPanel();
        comp.setBackground(getBackground(lang, currentLang));

        final PanelBuilder langBuilder = new PanelBuilder(
            langLayout,
            comp);
        langBuilder.addROLabel(lang, CC.xy(2, 1));
        comp.addMouseListener(createPopupListener(lang));
        comp.setToolTipText("Use right-click to remove this language");

        builder.add(comp, cst.xy(col, 1));
        col += 2;
    }

    panel.revalidate();
    panel.repaint();
}
 
Example 9
@Override
protected void initComponents() {
    init = true;

    computePanel = new MultipleRoiComputePanel(this, getRaster());
    exportButton = getExportButton();

    final JPanel exportAndHelpPanel = GridBagUtils.createPanel();
    GridBagConstraints helpPanelConstraints = GridBagUtils.createConstraints("anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2,weightx=1,ipadx=0");
    GridBagUtils.addToPanel(exportAndHelpPanel, new JSeparator(), helpPanelConstraints, "fill=HORIZONTAL,gridwidth=2,insets.left=5,insets.right=5");
    GridBagUtils.addToPanel(exportAndHelpPanel, exportButton, helpPanelConstraints, "gridy=1,anchor=WEST,fill=NONE");
    GridBagUtils.addToPanel(exportAndHelpPanel, getHelpButton(), helpPanelConstraints, "gridx=1,gridy=1,anchor=EAST,fill=NONE");

    final JPanel rightPanel = GridBagUtils.createPanel();
    GridBagConstraints extendedOptionsPanelConstraints = GridBagUtils.createConstraints("anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2,weightx=1,insets.right=-2");
    GridBagUtils.addToPanel(rightPanel, computePanel, extendedOptionsPanelConstraints, "gridy=0,fill=BOTH,weighty=1");
    GridBagUtils.addToPanel(rightPanel, createAccuracyPanel(), extendedOptionsPanelConstraints, "gridy=1,fill=BOTH,weighty=1");
    GridBagUtils.addToPanel(rightPanel, exportAndHelpPanel, extendedOptionsPanelConstraints, "gridy=2,anchor=SOUTHWEST,fill=HORIZONTAL,weighty=0");

    final ImageIcon collapseIcon = UIUtils.loadImageIcon("icons/PanelRight12.png");
    final ImageIcon collapseRolloverIcon = ToolButtonFactory.createRolloverIcon(collapseIcon);
    final ImageIcon expandIcon = UIUtils.loadImageIcon("icons/PanelLeft12.png");
    final ImageIcon expandRolloverIcon = ToolButtonFactory.createRolloverIcon(expandIcon);

    hideAndShowButton = ToolButtonFactory.createButton(collapseIcon, false);
    hideAndShowButton.setToolTipText("Collapse Options Panel");
    hideAndShowButton.setName("switchToChartButton");
    hideAndShowButton.addActionListener(new ActionListener() {

        private boolean rightPanelShown;

        @Override
        public void actionPerformed(ActionEvent e) {
            rightPanel.setVisible(rightPanelShown);
            if (rightPanelShown) {
                hideAndShowButton.setIcon(collapseIcon);
                hideAndShowButton.setRolloverIcon(collapseRolloverIcon);
                hideAndShowButton.setToolTipText("Collapse Options Panel");
            } else {
                hideAndShowButton.setIcon(expandIcon);
                hideAndShowButton.setRolloverIcon(expandRolloverIcon);
                hideAndShowButton.setToolTipText("Expand Options Panel");
            }
            rightPanelShown = !rightPanelShown;
        }
    });


    contentPanel = new JPanel(new GridLayout(-1, 1));
    contentPanel.setBackground(Color.WHITE);
    contentPanel.addMouseListener(popupHandler);

    final JScrollPane contentScrollPane = new JScrollPane(contentPanel);
    contentScrollPane.setBorder(null);
    contentScrollPane.setBackground(Color.WHITE);

    backgroundPanel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    GridBagUtils.addToPanel(backgroundPanel, contentScrollPane, gbc, "fill=BOTH, weightx=1.0, weighty=1.0, anchor=NORTH");
    GridBagUtils.addToPanel(backgroundPanel, rightPanel, gbc, "gridx=1, fill=VERTICAL, weightx=0.0");

    JLayeredPane layeredPane = new JLayeredPane();
    layeredPane.add(backgroundPanel);
    layeredPane.add(hideAndShowButton);
    add(layeredPane);
}
 
Example 10
Source Project: swing_library   File: SidebarSection.java    License: MIT License 4 votes vote down vote up
/**
	 * Construct a new sidebar section with the specified owner and model. 
	 * 
	 * @param owner - SideBar
	 * @param model
	 */
	public SidebarSection(SideBar owner, 
			JComponent titleComponent, 
			JComponent component, Icon icon) {
		
		if (owner.thisMode == SideBar.SideBarMode.INNER_LEVEL)
			minComponentHeight = 30;
		else
			minComponentHeight = 40;
		
		
		this.contentPane = component;
		
		sideBarOwner = owner;
		
		titlePanel = new JPanel();
		titlePanel.addMouseListener(new MouseAdapter() {
			public void mouseReleased(MouseEvent e) {
				
				if (SidebarSection.this != sideBarOwner.getCurrentSection()) {
					if (sideBarOwner.getCurrentSection() != null)
						sideBarOwner.getCurrentSection().collapse(true);
					
					expand(); //expand this!
				}
				else {
					collapse(true);
				}
			}
		});

		//absolute layout
//		setLayout(null);
		setLayout(new BorderLayout());
		
		add(titlePanel, BorderLayout.NORTH);

		titlePanel.setLayout(new BorderLayout());
		titlePanel.setPreferredSize(new Dimension(this.getPreferredSize().width, minComponentHeight));
		titlePanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
		
		arrowPanel = new ArrowPanel(BasicArrowButton.EAST);
		arrowPanel.setPreferredSize(new Dimension(40, 40));
		
		
		if (sideBarOwner.showArrow)
			//add into tab panel the arrow and labels.
			titlePanel.add(arrowPanel, BorderLayout.EAST);
		
		
		titlePanel.add(new JLabel(icon), BorderLayout.WEST);
		
		titleComponent.setBorder(new CompoundBorder(BorderFactory.createEmptyBorder(2, 8, 2, 2), titleComponent.getBorder()));
		titlePanel.add(titleComponent);

//		this.setMinimumSize(new Dimension(minComponentWidth, minComponentHeight));
//		component.setPreferredSize(new Dimension(0,0));
		
		add(component, BorderLayout.CENTER);
		
		revalidate();
	}
 
Example 11
Source Project: osp   File: OSPControl.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 *  Constructs an OSPControl.
 *
 * @param  _model
 */
public OSPControl(Object _model) {
  super(ControlsRes.getString("OSPControl.Default_Title")); //$NON-NLS-1$
  model = _model;
  if(model!=null) {
    // added by D Brown 2006-09-10
    // modified by D Brown 2007-10-17
    if(OSPRuntime.getTranslator()!=null) {
      OSPRuntime.getTranslator().associate(this, model.getClass());
    }
    String name = model.getClass().getName();
    setTitle(name.substring(1+name.lastIndexOf("."))+ControlsRes.getString("OSPControl.Controller")); //$NON-NLS-1$ //$NON-NLS-2$
  }
  Font labelFont = new Font("Dialog", Font.BOLD, 12); //$NON-NLS-1$
  inputLabel = new JLabel(ControlsRes.getString("OSPControl.Input_Parameters"), SwingConstants.CENTER); //$NON-NLS-1$
  inputLabel.setFont(labelFont);
  messageTextArea = new JTextArea(5, 5) {
    public void paintComponent(Graphics g) {
      if(OSPRuntime.antiAliasText) {
        Graphics2D g2 = (Graphics2D) g;
        RenderingHints rh = g2.getRenderingHints();
        rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      }
      super.paintComponent(g);
    }

  };
  JScrollPane messageScrollPane = new JScrollPane(messageTextArea);
  // contains a view of the control
  JPanel topPanel = new JPanel(new BorderLayout());
  topPanel.add(inputLabel, BorderLayout.NORTH);
  topPanel.add(controlScrollPane, BorderLayout.CENTER);
  buttonPanel.setVisible(true);
  topPanel.add(buttonPanel, BorderLayout.SOUTH); // buttons are added using addButton method.
  // clear panel acts like a button to clear the message area
  JPanel clearPanel = new JPanel(new BorderLayout());
  clearPanel.addMouseListener(new ClearMouseAdapter());
  clearLabel = new JLabel(ControlsRes.getString("OSPControl.Clear")); //$NON-NLS-1$
  clearLabel.setFont(new Font(clearLabel.getFont().getFamily(), Font.PLAIN, 9));
  clearLabel.setForeground(Color.black);
  clearPanel.add(clearLabel, BorderLayout.WEST);
  // contains the messages
  JPanel bottomPanel = new JPanel(new BorderLayout());
  messageLabel = new JLabel(ControlsRes.getString("OSPControl.Messages"), SwingConstants.CENTER); //$NON-NLS-1$
  messageLabel.setFont(labelFont);
  bottomPanel.add(messageLabel, BorderLayout.NORTH);
  bottomPanel.add(messageScrollPane, BorderLayout.CENTER);
  bottomPanel.add(clearPanel, BorderLayout.SOUTH);
  Container cp = getContentPane();
  splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, bottomPanel);
  splitPane.setOneTouchExpandable(true);
  cp.add(splitPane, BorderLayout.CENTER);
  messageTextArea.setEditable(false);
  controlScrollPane.setPreferredSize(new Dimension(350, 200));
  controlScrollPane.setMinimumSize(new Dimension(0, 50));
  messageScrollPane.setPreferredSize(new Dimension(350, 75));
  if((OSPRuntime.getTranslator()!=null)&&(model!=null)) {
    OSPRuntime.getTranslator().associate(table, model.getClass());
  }
  Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  setLocation((d.width-getSize().width)/2, (d.height-getSize().height)/2); // center the frame
  init();
  ToolsRes.addPropertyChangeListener("locale", this);                      //$NON-NLS-1$
}