[Pixelle-commit] SF.net SVN: pixelle:[274] trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs /Algor
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-07-18 18:49:32
|
Revision: 274
http://pixelle.svn.sourceforge.net/pixelle/?rev=274&view=rev
Author: dbrosius
Date: 2009-07-18 18:49:24 +0000 (Sat, 18 Jul 2009)
Log Message:
-----------
hook up location shortcuts
Modified Paths:
--------------
trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/AlgorithmEditor.java
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/AlgorithmEditor.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/AlgorithmEditor.java 2009-07-18 18:42:04 UTC (rev 273)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/AlgorithmEditor.java 2009-07-18 18:49:24 UTC (rev 274)
@@ -50,20 +50,20 @@
*/
public class AlgorithmEditor extends JDialog {
private static final long serialVersionUID = 7704059483753204128L;
-
+
private JEditorPane algo;
private JButton ok;
private JButton cancel;
- private String origValue;
+ private final String origValue;
private JLabel shortcutTrigger;
private JPopupMenu shortcuts;
private boolean isOK = false;
-
+
public AlgorithmEditor(PixelleComponent component, Point pt, Dimension dim, String value) {
origValue = value;
initComponents();
initListeners();
-
+
setTitle(component.toString());
pt.y -= dim.height + 5; // 5 is clearly a fudge
setLocation(pt);
@@ -71,32 +71,33 @@
setSize(dim);
algo.setText(value);
}
-
+
public String getValue() {
- if (isOK)
+ if (isOK) {
return algo.getText();
-
+ }
+
return origValue;
}
-
+
private void initComponents() {
Container cp = getContentPane();
cp.setLayout(new BorderLayout(4, 4));
-
+
algo = new JEditorPane();
cp.add(new JScrollPane(algo), BorderLayout.CENTER);
-
+
ok = new JButton(PixelleBundle.getString(PixelleBundle.OK));
cancel = new JButton(PixelleBundle.getString(PixelleBundle.CANCEL));
GuiUtils.sizeUniformly(Sizing.Both, ok, cancel);
-
+
shortcutTrigger = new JLabel(PixelleBundle.getString(PixelleBundle.SHORTCUTS));
shortcutTrigger.setBorder(BorderFactory.createEtchedBorder());
shortcutTrigger.setEnabled(true);
shortcutTrigger.setOpaque(true);
-
- shortcuts = buildShortCutsMenu();
-
+
+ buildShortCutsMenu();
+
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
p.add(Box.createHorizontalStrut(20));
@@ -107,42 +108,46 @@
p.add(Box.createHorizontalStrut(10));
p.add(cancel);
p.add(Box.createHorizontalStrut(20));
-
+
cp.add(p, BorderLayout.SOUTH);
}
-
+
private void initListeners() {
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
-
+
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
isOK = true;
dispose();
}
});
-
+
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
dispose();
}
});
-
- shortcutTrigger.addMouseListener(new MouseAdapter() {
+
+ shortcutTrigger.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
shortcuts.show(e.getComponent(), e.getX(), e.getY());
}
});
}
-
+
public String getText() {
return algo.getText();
}
-
- private JPopupMenu buildShortCutsMenu()
+
+ private void buildShortCutsMenu()
{
- JPopupMenu menu = new JPopupMenu(PixelleBundle.getString(PixelleBundle.SHORTCUTS));
-
+ if (shortcuts != null) {
+ return;
+ }
+
+ shortcuts = new JPopupMenu(PixelleBundle.getString(PixelleBundle.SHORTCUTS));
+
JMenu posMenu = new JMenu(PixelleBundle.getString(PixelleBundle.POSITIONS));
JMenuItem leftItem = new JMenuItem(PixelleBundle.getString(PixelleBundle.LEFT));
JMenuItem topItem = new JMenuItem(PixelleBundle.getString(PixelleBundle.TOP));
@@ -150,14 +155,28 @@
JMenuItem bottomItem = new JMenuItem(PixelleBundle.getString(PixelleBundle.BOTTOM));
JMenuItem centerXItem = new JMenuItem(PixelleBundle.getString(PixelleBundle.CENTERX));
JMenuItem centerYItem = new JMenuItem(PixelleBundle.getString(PixelleBundle.CENTERY));
- posMenu.add(leftItem);
- posMenu.add(topItem);
- posMenu.add(rightItem);
+ posMenu.add(leftItem);
+ posMenu.add(topItem);
+ posMenu.add(rightItem);
posMenu.add(bottomItem);
posMenu.add(centerXItem);
posMenu.add(centerYItem);
- menu.add(posMenu);
-
- return menu;
+ shortcuts.add(posMenu);
+
+ addSimpleShortCutListener(leftItem, "0");
+ addSimpleShortCutListener(topItem, "0");
+ addSimpleShortCutListener(rightItem, "width");
+ addSimpleShortCutListener(bottomItem, "height");
+ addSimpleShortCutListener(centerXItem, "(width/2)");
+ addSimpleShortCutListener(centerYItem, "(height/2)");
}
+
+ private void addSimpleShortCutListener(JMenuItem mi, final String sc) {
+ mi.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ algo.replaceSelection(sc);
+ }
+ });
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|