use of java.awt.event.FocusListener in project freeplane by freeplane.
the class MMapController method addFreeNode.
public NodeModel addFreeNode(final Point pt, final boolean newNodeIsLeft) {
final ModeController modeController = Controller.getCurrentModeController();
final TextController textController = TextController.getController();
if (textController instanceof MTextController) {
((MTextController) textController).stopEditing();
modeController.forceNewTransaction();
}
final NodeModel target = getRootNode();
final NodeModel targetNode = target;
final boolean parentFolded = isFolded(targetNode);
if (parentFolded) {
unfold(targetNode);
}
if (!isWriteable(target)) {
UITools.errorMessage(TextUtils.getText("node_is_write_protected"));
return null;
}
final NodeModel newNode = newNode("", target.getMap());
LogicalStyleModel.createExtension(newNode).setStyle(MapStyleModel.FLOATING_STYLE);
newNode.addExtension(modeController.getExtension(FreeNode.class));
if (!addNewNode(newNode, target, target.getChildCount(), newNodeIsLeft))
return null;
final Quantity<LengthUnits> x = LengthUnits.pixelsInPt(pt.x);
final Quantity<LengthUnits> y = LengthUnits.pixelsInPt(pt.y);
((MLocationController) MLocationController.getController(modeController)).moveNodePosition(newNode, x, y);
final Component component = Controller.getCurrentController().getMapViewManager().getComponent(newNode);
if (component == null)
return newNode;
component.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent e) {
}
public void focusGained(FocusEvent e) {
e.getComponent().removeFocusListener(this);
((MTextController) textController).edit(newNode, targetNode, true, false, false);
}
});
select(newNode);
return newNode;
}
use of java.awt.event.FocusListener in project jmulticard by ctt-gob-es.
the class Utils method remarcar.
/**
* Configura el formato del remarcado del componente al ser seleccionado.
* @param component El componente seleccionado.
*/
static void remarcar(final JComponent component) {
if (GeneralConfig.isRemarked()) {
if (component instanceof JButton) {
final JButton button = (JButton) component;
button.addFocusListener(new FocusListener() {
@Override
public void focusLost(final FocusEvent e) {
if (button.getParent() instanceof JPanel) {
((JPanel) button.getParent()).setBorder(BorderFactory.createEmptyBorder());
}
}
@Override
public void focusGained(final FocusEvent e) {
if (GeneralConfig.isHighContrast() || isHighContrast()) {
if (button.getParent() instanceof JPanel) {
((JPanel) button.getParent()).setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
}
} else {
if (button.getParent() instanceof JPanel) {
((JPanel) button.getParent()).setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
}
}
}
});
}
if (component instanceof JTextField) {
final JTextField textField = (JTextField) component;
textField.addFocusListener(new FocusListener() {
@Override
public void focusLost(final FocusEvent e) {
textField.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
}
@Override
public void focusGained(final FocusEvent e) {
if (GeneralConfig.isHighContrast() || isHighContrast()) {
textField.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
} else {
textField.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
}
}
});
}
if (component instanceof JComboBox) {
final JComboBox<?> comboBox = (JComboBox<?>) component;
comboBox.addFocusListener(new FocusListener() {
@Override
public void focusLost(final FocusEvent e) {
comboBox.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
}
@Override
public void focusGained(final FocusEvent e) {
if (GeneralConfig.isHighContrast() || isHighContrast()) {
comboBox.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
} else {
comboBox.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
}
}
});
}
if (component instanceof JLabel) {
final JLabel label = (JLabel) component;
label.addFocusListener(new FocusListener() {
@Override
public void focusLost(final FocusEvent e) {
label.setBorder(BorderFactory.createEmptyBorder());
}
@Override
public void focusGained(final FocusEvent e) {
if (GeneralConfig.isHighContrast() || isHighContrast()) {
label.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
} else {
label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
}
}
});
}
if (component instanceof JCheckBox) {
final JCheckBox checkBox = (JCheckBox) component;
checkBox.addFocusListener(new FocusListener() {
@Override
public void focusLost(final FocusEvent e) {
((JPanel) checkBox.getParent()).setBorder(BorderFactory.createEmptyBorder());
}
@Override
public void focusGained(final FocusEvent e) {
if (GeneralConfig.isHighContrast() || isHighContrast()) {
((JPanel) checkBox.getParent()).setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
} else {
((JPanel) checkBox.getParent()).setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
}
}
});
}
}
}
use of java.awt.event.FocusListener in project runelite by runelite.
the class NotesPanel method init.
void init(NotesConfig config) {
// this may or may not qualify as a hack
// but this lets the editor pane expand to fill the whole parent panel
getParent().setLayout(new BorderLayout());
getParent().add(this, BorderLayout.CENTER);
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(2, 6, 6, 6));
final JLabel notesHeader = new JLabel("Notes");
add(notesHeader, BorderLayout.NORTH);
notesEditor.setContentType("text/plain");
// load note text
String data = config.notesData();
notesEditor.setText(data);
notesEditor.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
notesChanged(notesEditor.getDocument());
}
private void notesChanged(Document doc) {
try {
// get document text and save to config whenever editor is changed
String data = doc.getText(0, doc.getLength());
config.notesData(data);
} catch (BadLocationException ex) {
log.warn("Notes Document Bad Location: " + ex);
}
}
});
add(notesEditor, BorderLayout.CENTER);
}
use of java.awt.event.FocusListener in project org.alloytools.alloy by AlloyTools.
the class Browsable method showAsTree.
/**
* Display this node and its subnodes as a tree; if listener!=null, it will
* receive OurTree.Event.SELECT events when nodes are selected.
*/
public final JFrame showAsTree(Listener listener) {
final OurTree tree = new OurTree(12) {
private static final long serialVersionUID = 0;
private final boolean onWindows = Util.onWindows();
{
do_start();
}
@Override
public String convertValueToText(Object val, boolean selected, boolean expanded, boolean leaf, int row, boolean focus) {
String c = ">";
String x = (val instanceof Browsable) ? ((Browsable) val).getHTML() : Util.encode(String.valueOf(val));
if (onWindows)
c = selected ? " style=\"color:#ffffff;\">" : " style=\"color:#000000;\">";
return "<html><span" + c + x + "</span></html>";
}
@Override
public List<?> do_ask(Object parent) {
if (parent instanceof Browsable)
return ((Browsable) parent).getSubnodes();
else
return new ArrayList<Browsable>();
}
@Override
public Object do_root() {
return Browsable.this;
}
};
tree.setBorder(new EmptyBorder(3, 3, 3, 3));
final JScrollPane scr = new JScrollPane(tree, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scr.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
tree.requestFocusInWindow();
}
@Override
public void focusLost(FocusEvent e) {
}
});
final JFrame x = new JFrame("Parse Tree");
x.setLayout(new BorderLayout());
x.add(scr, BorderLayout.CENTER);
x.pack();
x.setSize(500, 500);
x.setLocationRelativeTo(null);
x.setVisible(true);
if (listener != null)
tree.listeners.add(listener);
return x;
}
use of java.awt.event.FocusListener in project org.alloytools.alloy by AlloyTools.
the class VizGUI method updateDisplay.
/**
* Helper method that refreshes the right-side visualization panel with the
* latest settings.
*/
private void updateDisplay() {
if (myState == null)
return;
// First, update the toolbar
currentMode.set();
for (JButton button : solutionButtons) button.setEnabled(settingsOpen != 1);
switch(currentMode) {
case Tree:
treeButton.setEnabled(false);
break;
case TEXT:
txtButton.setEnabled(false);
break;
case TABLE:
tableButton.setEnabled(false);
break;
// case DOT: dotButton.setEnabled(false); break;
default:
vizButton.setEnabled(false);
}
final boolean isMeta = myState.getOriginalInstance().isMetamodel;
vizButton.setVisible(frame != null);
treeButton.setVisible(frame != null);
txtButton.setVisible(frame != null);
// dotButton.setVisible(frame!=null);
// xmlButton.setVisible(frame!=null);
magicLayout.setVisible((settingsOpen == 0 || settingsOpen == 1) && currentMode == VisualizerMode.Viz);
projectionButton.setVisible((settingsOpen == 0 || settingsOpen == 1) && currentMode == VisualizerMode.Viz);
openSettingsButton.setVisible(settingsOpen == 0 && currentMode == VisualizerMode.Viz);
loadSettingsButton.setVisible(frame == null && settingsOpen == 1 && currentMode == VisualizerMode.Viz);
saveSettingsButton.setVisible(frame == null && settingsOpen == 1 && currentMode == VisualizerMode.Viz);
saveAsSettingsButton.setVisible(frame == null && settingsOpen == 1 && currentMode == VisualizerMode.Viz);
resetSettingsButton.setVisible(frame == null && settingsOpen == 1 && currentMode == VisualizerMode.Viz);
closeSettingsButton.setVisible(settingsOpen == 1 && currentMode == VisualizerMode.Viz);
updateSettingsButton.setVisible(settingsOpen == 1 && currentMode == VisualizerMode.Viz);
openEvaluatorButton.setVisible(!isMeta && settingsOpen == 0 && evaluator != null);
closeEvaluatorButton.setVisible(!isMeta && settingsOpen == 2 && evaluator != null);
enumerateMenu.setEnabled(!isMeta && settingsOpen == 0 && enumerator != null);
enumerateButton.setVisible(!isMeta && settingsOpen == 0 && enumerator != null);
toolbar.setVisible(true);
// on the right
if (frame != null)
frame.setTitle(makeVizTitle());
switch(currentMode) {
case Tree:
{
final VizTree t = new VizTree(myState.getOriginalInstance().originalA4, makeVizTitle(), fontSize);
final JScrollPane scroll = OurUtil.scrollpane(t, Color.BLACK, Color.WHITE, new OurBorder(true, false, true, false));
scroll.addFocusListener(new FocusListener() {
@Override
public final void focusGained(FocusEvent e) {
t.requestFocusInWindow();
}
@Override
public final void focusLost(FocusEvent e) {
}
});
content = scroll;
break;
}
case TEXT:
{
String textualOutput = myState.getOriginalInstance().originalA4.toString();
content = getTextComponent(textualOutput);
break;
}
case TABLE:
{
String textualOutput = myState.getOriginalInstance().originalA4.format();
content = getTextComponent(textualOutput);
break;
}
// }
default:
{
if (myGraphPanel == null) {
myGraphPanel = new VizGraphPanel(myState, false);
} else {
myGraphPanel.seeDot(false);
myGraphPanel.remakeAll();
}
}
content = myGraphPanel;
}
// Now that we've re-constructed "content", let's set its font size
if (currentMode != VisualizerMode.Tree) {
content.setFont(OurUtil.getVizFont().deriveFont((float) fontSize));
content.invalidate();
content.repaint();
content.validate();
}
// Now, display them!
final Box instanceTopBox = Box.createHorizontalBox();
instanceTopBox.add(toolbar);
final JPanel instanceArea = new JPanel(new BorderLayout());
instanceArea.add(instanceTopBox, BorderLayout.NORTH);
instanceArea.add(content, BorderLayout.CENTER);
instanceArea.setVisible(true);
if (!Util.onMac()) {
instanceTopBox.setBackground(background);
instanceArea.setBackground(background);
}
JComponent left = null;
if (settingsOpen == 1) {
if (myCustomPanel == null)
myCustomPanel = new VizCustomizationPanel(splitpane, myState);
else
myCustomPanel.remakeAll();
left = myCustomPanel;
} else if (settingsOpen > 1) {
if (myEvaluatorPanel == null)
myEvaluatorPanel = new OurConsole(evaluator, true, "The ", true, "Alloy Evaluator ", false, "allows you to type\nin Alloy expressions and see their values.\nFor example, ", true, "univ", false, " shows the list of all atoms.\n(You can press UP and DOWN to recall old inputs).\n");
try {
evaluator.compute(new File(xmlFileName));
}// exception should not happen
catch (Exception ex) {
}
left = myEvaluatorPanel;
left.setBorder(new OurBorder(false, false, false, false));
}
if (frame != null && frame.getContentPane() == splitpane)
lastDividerPosition = splitpane.getDividerLocation();
splitpane.setRightComponent(instanceArea);
splitpane.setLeftComponent(left);
if (left != null) {
Dimension dim = left.getPreferredSize();
if (lastDividerPosition < 50 && frame != null)
lastDividerPosition = frame.getWidth() / 2;
if (lastDividerPosition < dim.width)
lastDividerPosition = dim.width;
if (settingsOpen == 2 && lastDividerPosition > 400)
lastDividerPosition = 400;
splitpane.setDividerLocation(lastDividerPosition);
}
if (frame != null)
frame.setContentPane(splitpane);
if (settingsOpen != 2)
content.requestFocusInWindow();
else
myEvaluatorPanel.requestFocusInWindow();
repopulateProjectionPopup();
if (frame != null)
frame.validate();
else
splitpane.validate();
}
Aggregations