use of java.awt.event.MouseListener in project OpenNotebook by jaltekruse.
the class ColorAdjustmentPanel method addPanelContent.
@Override
public void addPanelContent() {
setLayout(new GridBagLayout());
if (mAtt.getName().equals(MathObject.FILL_COLOR)) {
checkbox = new JCheckBox("fill");
if (mAtt.getValue() != null)
checkbox.setSelected(true);
else
checkbox.setSelected(false);
checkbox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
if (justChangedColor) {
justChangedColor = false;
return;
}
if (mAtt.getValue() == null) {
mAtt.setValue(Color.WHITE);
}
colorLabel.setBackground(mAtt.getValue());
ColorAdjustmentPanel.this.repaint();
notebookPanel.getCurrentDocViewer().addUndoState();
notebookPanel.getCurrentDocViewer().repaintDoc();
notebookPanel.getCurrentDocViewer().updateObjectToolFrame();
} else {
mAtt.setValue(null);
colorLabel.setBackground(mAtt.getValue());
ColorAdjustmentPanel.this.repaint();
notebookPanel.getCurrentDocViewer().addUndoState();
notebookPanel.getCurrentDocViewer().repaintDoc();
notebookPanel.getCurrentDocViewer().updateObjectToolFrame();
}
}
});
}
colorLabel = new JLabel(" ");
colorLabel.setBorder(new LineBorder(Color.BLACK));
colorLabel.setOpaque(true);
colorLabel.setBackground(mAtt.getValue());
colorLabel.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent arg0) {
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
public void mousePressed(MouseEvent arg0) {
Color c = JColorChooser.showDialog(ColorAdjustmentPanel.this, "Choose color", ((ColorAttribute) mAtt).getValue());
((ColorAttribute) mAtt).setValue(c);
colorLabel.setBackground(mAtt.getValue());
if (checkbox != null) {
if (((ColorAttribute) mAtt).getValue() != null) {
justChangedColor = true;
checkbox.setSelected(true);
} else {
checkbox.setSelected(false);
}
}
notebookPanel.getCurrentDocViewer().addUndoState();
notebookPanel.getCurrentDocViewer().repaintDoc();
}
public void mouseReleased(MouseEvent arg0) {
}
});
GridBagConstraints con = new GridBagConstraints();
con.fill = GridBagConstraints.HORIZONTAL;
con.weightx = 1;
con.gridx = 0;
con.gridy = 0;
con.insets = new Insets(0, 0, 0, 3);
if (mAtt.getName().equals(MathObject.FILL_COLOR)) {
add(checkbox, con);
} else {
add(new JLabel(mAtt.getName()), con);
}
con.gridy = 0;
con.gridx = 1;
con.gridheight = 1;
add(colorLabel, con);
// con.gridx = 2;
// add(setColor, con);
}
use of java.awt.event.MouseListener in project OpenNotebook by jaltekruse.
the class ProblemListPanel method createPanelForProblems.
public JPanel createPanelForProblems() {
ProblemList panel = new ProblemList();
JPanel tempPanel;
GridBagConstraints con = new GridBagConstraints();
JComboBox frequencyChoices;
Component[] othersInRow = new Component[2];
;
int numProblemsToShow = notebookPanel.getDatabase().getAllProblems().size();
if (numProblemsToShow > 20) {
// limit the number of problems in the list
// to 20 at a time
numProblemsToShow = 20;
}
con.gridy = 0;
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
panel.setLayout(new GridBagLayout());
for (final ProblemGenerator g : notebookPanel.getDatabase().getAllProblems()) {
// add checkbox
con.fill = GridBagConstraints.NONE;
con.gridx = 0;
con.gridwidth = 1;
con.weightx = 0;
con.insets = new Insets(0, 0, 0, 0);
final JCheckBox checkbox = new JCheckBox();
checkbox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent ev) {
if (ev.getStateChange() == ItemEvent.SELECTED) {
selectedFrequencies.add(10);
selectedProblems.add(g);
} else {
selectedFrequencies.remove(selectedProblems.indexOf(g));
selectedProblems.remove(g);
}
previewPanel.getDoc().getPage(0).removeAllObjects();
// set the page size big to prevent problem generation from spawning pages
previewPanel.getDoc().setHeight(5000);
previewPanel.getDoc().setWidth(5000);
previewPanel.getDoc().generateProblem(g);
previewPanel.resizeViewWindow();
MathObject mObj = previewPanel.getDoc().getPage(0).getObjects().get(0);
previewPanel.getDoc().setWidth(mObj.getWidth() + 2 * problemBuffer);
previewPanel.getDoc().setHeight(mObj.getHeight() + 2 * problemBuffer);
mObj.setxPos(problemBuffer);
mObj.setyPos(problemBuffer);
previewPanel.resizeViewWindow();
}
});
frequencyChoices = new JComboBox(frequencies);
panel.add(checkbox, con);
othersInRow[0] = checkbox;
othersInRow[1] = frequencyChoices;
con.fill = GridBagConstraints.HORIZONTAL;
con.insets = new Insets(0, 5, 0, 0);
con.weightx = 1;
con.gridx = 1;
tempPanel = new ProblemDescriptionPanel(g, othersInRow);
tempPanel.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent arg0) {
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
@Override
public void mousePressed(MouseEvent arg0) {
checkbox.setSelected(!checkbox.isSelected());
}
public void mouseReleased(MouseEvent arg0) {
}
});
panel.add(tempPanel, con);
// // add frequency selection menu
// con.fill = GridBagConstraints.NONE;
// con.gridx = 2;
// con.weightx = 0;
// con.insets = new Insets(0, 5, 0, 5);
// frequencyChoices.setSelectedItem(AVERAGE);
// panel.add(frequencyChoices, con);
con.gridy++;
con.gridx = 0;
con.gridwidth = 2;
con.insets = new Insets(0, 0, 0, 0);
panel.add(new JSeparator(), con);
con.gridy++;
}
return panel;
}
use of java.awt.event.MouseListener in project azure-tools-for-java by Microsoft.
the class VMWizardModel method configStepList.
public void configStepList(JList list, int step) {
list.setListData(getStepTitleList());
list.setSelectedIndex(step);
list.setBorder(new EmptyBorder(10, 0, 10, 0));
list.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList mylist, Object o, int i, boolean b, boolean b1) {
return super.getListCellRendererComponent(mylist, " " + o.toString(), i, b, b1);
}
});
for (MouseListener mouseListener : list.getMouseListeners()) {
list.removeMouseListener(mouseListener);
}
for (MouseMotionListener mouseMotionListener : list.getMouseMotionListeners()) {
list.removeMouseMotionListener(mouseMotionListener);
}
list.setBackground(JBColor.background());
}
use of java.awt.event.MouseListener in project CoreNLP by stanfordnlp.
the class JarFileChooser method showListSelectionDialog.
public String showListSelectionDialog(List<String> files, Point location) {
Frame frame = new Frame();
// System.out.println(location);
// frame.setLocation(location);
final JDialog dialog = new JDialog(frame, "Jar File Chooser", true);
dialog.setLocation(location);
final JList<String> fileList = new JList<>(new Vector<>(files));
fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
MouseListener mouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
// double clicked
dialog.setVisible(false);
}
}
};
fileList.addMouseListener(mouseListener);
final JScrollPane scroll = new JScrollPane(fileList);
JButton okay = new javax.swing.JButton();
okay.setText("Okay");
okay.setToolTipText("Okay");
okay.addActionListener(evt -> dialog.setVisible(false));
JButton cancel = new javax.swing.JButton();
cancel.setText("Cancel");
cancel.setToolTipText("Cancel");
cancel.addActionListener(evt -> {
fileList.clearSelection();
dialog.setVisible(false);
});
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
dialog.setLayout(gridbag);
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
gridbag.setConstraints(scroll, constraints);
dialog.add(scroll);
constraints.gridwidth = GridBagConstraints.RELATIVE;
constraints.fill = GridBagConstraints.NONE;
constraints.weighty = 0.0;
gridbag.setConstraints(okay, constraints);
dialog.add(okay);
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(cancel, constraints);
dialog.add(cancel);
dialog.pack();
dialog.setSize(dialog.getPreferredSize());
dialog.setVisible(true);
if (fileList.isSelectionEmpty())
return null;
return files.get(fileList.getSelectedIndex());
}
use of java.awt.event.MouseListener in project java-swing-tips by aterai.
the class BottomRoundedCornerBorder method makeComboBox2.
private static JComboBox<String> makeComboBox2() {
return new JComboBox<String>(makeModel()) {
private transient MouseListener handler;
private transient PopupMenuListener listener;
@Override
public void updateUI() {
removeMouseListener(handler);
removePopupMenuListener(listener);
UIManager.put(KEY, new TopRoundedCornerBorder());
super.updateUI();
setUI(new BasicComboBoxUI() {
@Override
protected JButton createArrowButton() {
JButton b = new JButton(new ArrowIcon(BACKGROUND, FOREGROUND));
b.setContentAreaFilled(false);
b.setFocusPainted(false);
b.setBorder(BorderFactory.createEmptyBorder());
return b;
}
});
handler = new ComboRolloverHandler();
addMouseListener(handler);
listener = new HeavyWeightContainerListener();
addPopupMenuListener(listener);
Object o = getAccessibleContext().getAccessibleChild(0);
if (o instanceof JComponent) {
JComponent c = (JComponent) o;
c.setBorder(new BottomRoundedCornerBorder());
c.setForeground(FOREGROUND);
c.setBackground(BACKGROUND);
}
}
};
}
Aggregations