Added multiply values function. Need to play with keystrokes to make '*' commit when focus is in set value field

git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@180 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
Jared Gould 2006-07-26 21:46:43 +00:00
parent 26a4af0e19
commit 51ee51df97
5 changed files with 52 additions and 1 deletions

View File

@ -292,4 +292,8 @@ public class DataCell extends JLabel implements MouseListener, Serializable {
public void refreshValue() {
setBinValue(binValue);
}
public void multiply(double factor) {
setRealValue(Double.parseDouble(getText()) * factor+"");
}
}

View File

@ -194,6 +194,11 @@ public abstract class Table extends JPanel implements Serializable {
paste();
}
};
Action multiplyAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
getFrame().getToolBar().multiply();
}
};
// set input mapping
InputMap im = getInputMap(WHEN_IN_FOCUSED_WINDOW);
@ -218,6 +223,7 @@ public abstract class Table extends JPanel implements Serializable {
KeyStroke num7 = KeyStroke.getKeyStroke('7');
KeyStroke num8 = KeyStroke.getKeyStroke('8');
KeyStroke num9 = KeyStroke.getKeyStroke('9');
KeyStroke mulKey = KeyStroke.getKeyStroke('*');
KeyStroke numPoint = KeyStroke.getKeyStroke('.');
KeyStroke copy = KeyStroke.getKeyStroke("control C");
KeyStroke paste = KeyStroke.getKeyStroke("control V");
@ -245,6 +251,7 @@ public abstract class Table extends JPanel implements Serializable {
im.put(numPoint, "numPointAction");
im.put(copy, "copyAction");
im.put(paste, "pasteAction");
im.put(mulKey, "mulAction");
getActionMap().put(im.get(right), rightAction);
getActionMap().put(im.get(left), leftAction);
@ -267,6 +274,7 @@ public abstract class Table extends JPanel implements Serializable {
getActionMap().put(im.get(num8), num8Action);
getActionMap().put(im.get(num9), num9Action);
getActionMap().put(im.get(numPoint), numPointAction);
getActionMap().put(im.get(mulKey), multiplyAction);
getActionMap().put(im.get(copy), copyAction);
getActionMap().put(im.get(paste), pasteAction);
@ -620,6 +628,16 @@ public abstract class Table extends JPanel implements Serializable {
}
}
public void multiply(double factor) {
if (!isStatic && !locked) {
for (DataCell cell : data) {
if (cell.isSelected()) {
cell.multiply(factor);
}
}
}
}
public void setRealValue(String realValue) {
if (!isStatic && !locked) {
for (DataCell cell : data) {

View File

@ -96,6 +96,11 @@ public class Table2D extends Table {
axis.increment(increment);
}
public void multiply(double factor) {
super.multiply(factor);
axis.multiply(factor);
}
public void clearSelection() {
axis.clearSelection(true);
for (int i = 0; i < data.length; i++) {

View File

@ -348,6 +348,20 @@ public class Table3D extends Table {
yAxis.increment(increment);
}
public void multiply(double factor) {
if (!isStatic && !locked) {
for (int x = 0; x < this.getSizeX(); x++) {
for (int y = 0; y < this.getSizeY(); y++) {
if (data[x][y].isSelected()) {
data[x][y].multiply(factor);
}
}
}
}
xAxis.multiply(factor);
yAxis.multiply(factor);
}
public void clearSelection() {
xAxis.clearSelection(true);
yAxis.clearSelection(true);

View File

@ -34,6 +34,7 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
private JButton incrementCoarse = new JButton(new ImageIcon("./graphics/icon-inccoarse.png"));
private JButton decrementCoarse = new JButton(new ImageIcon("./graphics/icon-deccoarse.png"));
private JButton setValue = new JButton("Set");
private JButton multiply = new JButton("Mul");
private JFormattedTextField incrementByFine = new JFormattedTextField(new DecimalFormat("#.####"));
private JFormattedTextField incrementByCoarse = new JFormattedTextField(new DecimalFormat("#.####"));
@ -60,6 +61,7 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
this.add(setValueText);
this.add(new JLabel(" "));
this.add(setValue);
this.add(multiply);
this.add(new JLabel(" "));
this.add(scaleSelection);
@ -73,6 +75,8 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
decrementCoarse.setBorder(new LineBorder(new Color(150,150,150), 1));
setValue.setMaximumSize(new Dimension(33,23));
setValue.setBorder(new LineBorder(new Color(150,150,150), 1));
multiply.setMaximumSize(new Dimension(33,23));
multiply.setBorder(new LineBorder(new Color(150,150,150), 1));
scaleSelection.setMaximumSize(new Dimension(80,23));
scaleSelection.setFont(new Font("Tahoma", Font.PLAIN, 11));
@ -94,12 +98,14 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
setValueText.setToolTipText("Set Absolute Value");
incrementByFine.setToolTipText("Fine Value Adjustment");
incrementByCoarse.setToolTipText("Coarse Value Adjustment");
multiply.setToolTipText("Multiply Value");
incrementFine.addMouseListener(this);
decrementFine.addMouseListener(this);
incrementCoarse.addMouseListener(this);
decrementCoarse.addMouseListener(this);
setValue.addMouseListener(this);
multiply.addMouseListener(this);
scaleSelection.addItemListener(this);
try {
@ -160,6 +166,7 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
else if (e.getSource() == decrementCoarse) decrementCoarse();
else if (e.getSource() == incrementFine) incrementFine();
else if (e.getSource() == decrementFine) decrementFine();
else if (e.getSource() == multiply) multiply();
else if (e.getSource() == setValue) setValue();
table.colorize();
@ -169,6 +176,9 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
table.setRealValue(setValueText.getText()+"");
}
public void multiply() {
table.multiply(Double.parseDouble(setValueText.getText()));
}
public void incrementFine() {
table.increment(Double.parseDouble(incrementByFine.getValue()+""));