Skip to content

Commit

Permalink
Use a CheckBox to indicate should it rotate image or not
Browse files Browse the repository at this point in the history
  • Loading branch information
walkingice committed Aug 20, 2011
1 parent c319615 commit 81723dc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 55 deletions.
57 changes: 9 additions & 48 deletions src/org/zeroxlab/aster/AsterMainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public void run() {

public final static int MENU_ROTATE = 1;
public final static int MENU_NOT_ROTATE = 2;
private static boolean sRotate;

private enum ExecutionState { NORMAL, EXECUTION }

Expand All @@ -73,7 +72,6 @@ private enum ExecutionState { NORMAL, EXECUTION }
private CmdConn mCmdConn;

private MyListener mCmdFillListener;
private RotationStateListener mRSListener;

public AsterMainPanel() {
GridBagLayout gridbag = new GridBagLayout();
Expand Down Expand Up @@ -144,7 +142,7 @@ public void mouseClicked(MouseEvent e) {
mCmdManager = new AsterCommandManager();

mCmdConn = new CmdConn();
setRotationStateListener(mCmdConn);
mWorkspace.addRotationListener(mCmdConn);
ActionExecutor executor = new ActionExecutor();
ActionDashboard.getInstance().setListener(executor);

Expand Down Expand Up @@ -305,24 +303,6 @@ public void actionPerformed(ActionEvent ev) {
quitItem.setMnemonic(KeyEvent.VK_Q);
fileMenu.add(quitItem);

JMenu viewMenu = new JMenu("View");
ButtonGroup group = new ButtonGroup();
RotationMenuListener rListener = new RotationMenuListener();
JRadioButtonMenuItem rb;
rb = new JRadioButtonMenuItem("Rotate Image");
rb.addActionListener(rListener);
rb.setMnemonic(MENU_ROTATE);
group.add(rb);
viewMenu.add(rb);

rb = new JRadioButtonMenuItem("Not Rotate Image");
rb.addActionListener(rListener);
rb.setMnemonic(MENU_NOT_ROTATE);
rb.setSelected(true);
group.add(rb);
viewMenu.add(rb);
menu.add(viewMenu);

JMenu helpMenu = new JMenu("Help");
helpMenu.setMnemonic(KeyEvent.VK_H);
// About
Expand All @@ -339,14 +319,6 @@ public void actionPerformed(ActionEvent ev) {
return menu;
}

public static boolean needRotate() {
return sRotate;
}

public void setRotationStateListener(RotationStateListener l) {
mRSListener = l;
}

private void resetRecall(String fileName) {
AsterCommand oldRecall = mActionList.getModel().getRecall();
AsterCommand newRecall = new Recall();
Expand All @@ -365,22 +337,6 @@ interface RotationStateListener {
public void rotationUpdated(boolean needRotate);
}

class RotationMenuListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof AbstractButton) {
AbstractButton button = (AbstractButton)e.getSource();
boolean state = (button.getMnemonic() == MENU_ROTATE);
if (state != sRotate) {
if (mRSListener!= null) {
mRSListener.rotationUpdated(state);
}
}

sRotate = state;
}
}
}

class AboutMsg {
public String toString() {
String msg = "";
Expand Down Expand Up @@ -504,7 +460,7 @@ public void processResult(ExecutionResult result) {
}
}

class CmdConn implements Runnable, RotationStateListener {
class CmdConn implements Runnable, ItemListener {

private boolean mKeepWalking = true;
private AsterCommand mCmd;
Expand Down Expand Up @@ -573,8 +529,13 @@ private void updateScreen() {
mWorkspace.repaint(mWorkspace.getBounds());
}

public void rotationUpdated(boolean needRotate) {
mLandscape = needRotate;
public void itemStateChanged(ItemEvent e) {
Object source = e.getSource();
if (source instanceof JCheckBox) {
JCheckBox rotate = (JCheckBox) source;
// a NOT ROTATED image should be Portrait
mLandscape = rotate.isSelected();
}
}
}
}
31 changes: 24 additions & 7 deletions src/org/zeroxlab/aster/AsterWorkspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
Expand All @@ -48,6 +49,7 @@
import javax.swing.event.ChangeListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JPanel;

Expand Down Expand Up @@ -80,6 +82,7 @@ public class AsterWorkspace extends JPanel implements ComponentListener
private static JButton sMenu;
private static JButton sBack;
private static JButton sSearch;
private static JCheckBox sRotate;

private BufferedImage mSourceImage;
private BufferedImage mDrawingBuffer;
Expand Down Expand Up @@ -171,6 +174,11 @@ public void actionPerformed(ActionEvent e) {
sDone.setEnabled(false);
add(sDone);

sRotate = new JCheckBox("Rotate");
sRotate.setSize(80, 20);
sRotate.setForeground(Color.WHITE);
add(sRotate);

sMKContainer = initShortcutButtons();
add(sMKContainer);
}
Expand Down Expand Up @@ -203,6 +211,18 @@ private JComponent initShortcutButtons() {
return box;
}

public void addRotationListener(ItemListener listener) {
sRotate.addItemListener(listener);
}

public static void setRotate(boolean rotate) {
sRotate.setSelected(rotate);
}

public static boolean isRotate() {
return sRotate.isSelected();
}

public ImageIcon createScaledIcon(String resourceName, int width, int height) {
ImageIcon icon = null;
try {
Expand All @@ -227,6 +247,7 @@ public void setImage(BufferedImage img) {
public void fillCmd(AsterCommand cmd, FillListener listener) {
sRecordingCmd = cmd;
sFillListener = listener;
sRotate.setSelected(cmd.isLandscape());
AsterOperation[] ops = sRecordingCmd.getOperations();
if (ops == null || ops.length == 0) {
System.err.println("You are asking me to fill an empty command");
Expand Down Expand Up @@ -301,6 +322,7 @@ public void componentResized(ComponentEvent e) {
updateDrawingBuffer(mSourceImage);
sRegion.setVisible(false);
sDone.setEnabled(false);
sRotate.setLocation(mWidth - sRotate.getWidth(), 10);
sMKContainer.setLocation(mWidth - (MK_CONTAINER_WIDTH + 10), mHeight - (MK_CONTAINER_HEIGHT + 10));
repaint();
}
Expand Down Expand Up @@ -705,9 +727,7 @@ public SimpleBindings getSettings() {
Point rb = convertPointW2Img(sRegion.pR.x, sRegion.pR.y);
this.setClip(lt.x, lt.y, rb.x, rb.y);
settings.put("Image", buf);
if (AsterMainPanel.needRotate()) {
settings.put("Landscape", true);
}
settings.put("Landscape", sRotate.isSelected());
return settings;
}
}
Expand Down Expand Up @@ -797,10 +817,7 @@ public SimpleBindings getSettings() {
settings.put("Image", buf);
Point lt = convertPointW2Img(sRegion.pL.x, sRegion.pL.y);
Point rb = convertPointW2Img(sRegion.pR.x, sRegion.pR.y);
this.setClip(lt.x, lt.y, rb.x, rb.y);
if (AsterMainPanel.needRotate()) {
settings.put("Landscape", true);
}
settings.put("Landscape", sRotate.isSelected());
return settings;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/org/zeroxlab/aster/cmds/AsterCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ synchronized public boolean isExecuting() {
return mExecuting;
}

synchronized public boolean isLandscape() {
return mLandscape;
}

protected String[] splitArgs(String argline) {
String[] args = argline.split(",");
for (int i = 0; i < args.length; ++i)
Expand Down

0 comments on commit 81723dc

Please sign in to comment.