Skip to content

Commit

Permalink
[add]Implementation of issue adakoda#16
Browse files Browse the repository at this point in the history
  • Loading branch information
hanaokaiwa committed Aug 29, 2016
1 parent ba8e3d7 commit c6bd81e
Show file tree
Hide file tree
Showing 2 changed files with 217 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/com/adakoda/android/asm/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.adakoda.android.asm;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Insets;
Expand Down Expand Up @@ -82,6 +83,8 @@ public class MainFrame extends JFrame {
{2, 1, 0, 3} // XRGB : FireFox OS(B2G)
};

private static final String SPECIFY_ZOOM_CAPTION = "Zoom...";

private MainPanel mPanel;
private JPopupMenu mPopupMenu;

Expand All @@ -100,6 +103,8 @@ public class MainFrame extends JFrame {
private MonitorThread mMonitorThread;

private String mBuildDevice = "";

private JRadioButtonMenuItem mSepcifyZoom;

public MainFrame(String[] args) {
initialize(args);
Expand Down Expand Up @@ -406,6 +411,7 @@ private void initializeZoomMenu() {
addRadioButtonMenuItemZoom(menuZoom, buttonGroup, 1.0, "100%", KeyEvent.VK_1, mZoom);
addRadioButtonMenuItemZoom(menuZoom, buttonGroup, 1.5, "150%", KeyEvent.VK_0, mZoom);
addRadioButtonMenuItemZoom(menuZoom, buttonGroup, 2.0, "200%", KeyEvent.VK_2, mZoom);
addRadioButtonMenuItemSpecifiedZoom(menuZoom, buttonGroup, -1, mZoom);
}

private void addRadioButtonMenuItemZoom(
Expand All @@ -419,6 +425,7 @@ private void addRadioButtonMenuItemZoom(
radioButtonMenuItemZoom.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setZoom(zoom);
mSepcifyZoom.setText(SPECIFY_ZOOM_CAPTION);
}
});
if (currentZoom == zoom) {
Expand All @@ -427,6 +434,67 @@ public void actionPerformed(ActionEvent e) {
buttonGroup.add(radioButtonMenuItemZoom);
menuZoom.add(radioButtonMenuItemZoom);
}

private void addRadioButtonMenuItemSpecifiedZoom(
JMenu menuZoom, ButtonGroup buttonGroup,
int nemonic, double currentZoom) {
mSepcifyZoom = new JRadioButtonMenuItem(SPECIFY_ZOOM_CAPTION);
final JRadioButtonMenuItem radioButtonMenuItemZoom = mSepcifyZoom;
if (nemonic != -1) {
radioButtonMenuItemZoom.setMnemonic(nemonic);
}
boolean selectedOther = false;
JRadioButtonMenuItem selectedItem = null;
if (null != menuZoom.getMenuComponents()) {
for (Component item : menuZoom.getMenuComponents()) {
if (item instanceof JRadioButtonMenuItem) {
if (((JRadioButtonMenuItem)item).isSelected()) {
selectedOther = true;
selectedItem = (JRadioButtonMenuItem)item;
break;
}
}
}
}
if (!selectedOther) {
radioButtonMenuItemZoom.setSelected(true);
int intCurrentZoom = (int) Math.round(currentZoom * 100.0);
radioButtonMenuItemZoom.setText(SPECIFY_ZOOM_CAPTION + "(" + intCurrentZoom + "%)");
selectedItem = radioButtonMenuItemZoom;
}
final JRadioButtonMenuItem finalSelectedItem = selectedItem;
radioButtonMenuItemZoom.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
specifyZoom(radioButtonMenuItemZoom, finalSelectedItem);
}
});
buttonGroup.add(radioButtonMenuItemZoom);
menuZoom.add(radioButtonMenuItemZoom);
}

private void specifyZoom(JRadioButtonMenuItem specifiedItem, JRadioButtonMenuItem selectedItem) {
stopMonitor();

SpecifyZoomDialog dialog = new SpecifyZoomDialog(this, true, mZoom);
dialog.setLocationRelativeTo(this);
dialog.setVisible(true);
if (dialog.isOK()) {
double specifiedZoom = dialog.getSpecifiedZoom();
if ((specifiedZoom > 0.0) && (mZoom != specifiedZoom)) {
mZoom = specifiedZoom;
savePrefs();
updateSize();
int intSpecifiedZoom = (int) Math.round(specifiedZoom * 100.0);
specifiedItem.setText(SPECIFY_ZOOM_CAPTION + "(" + intSpecifiedZoom + "%)");
} else {
selectedItem.setSelected(true);
}
} else {
selectedItem.setSelected(true);
}

startMonitor();
}

private void initializeFrameBufferMenu() {
JMenu menuZoom = new JMenu("FrameBuffer");
Expand Down
149 changes: 149 additions & 0 deletions src/com/adakoda/android/asm/SpecifyZoomDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Copyright (C) 2009-2013 adakoda
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.adakoda.android.asm;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.KeyStroke;
import javax.swing.SpinnerNumberModel;

@SuppressWarnings("serial")
public class SpecifyZoomDialog extends JDialog {
private JSpinner mSpinner;
private JLabel mLabel;
private JPanel mPanel;
private JButton mOK;
private JButton mCancel;

private boolean mIsOK = false;

private double mSpecifiedZoom = 0.0;

public SpecifyZoomDialog(Frame owner, boolean modal,
double currentZoom) {
super(owner, modal);

// Frame
{
setTitle("Specify Zoom");
setBounds(0, 0, 180, 84);
setResizable(false);
}

// Spinner
{
mPanel = new JPanel();
SpinnerNumberModel model = new SpinnerNumberModel((int)(currentZoom*100.0), 1, 300, 1);
mSpinner = new JSpinner(model);
mSpinner.setPreferredSize(new Dimension(140, 25));
mPanel.add(mSpinner);

mLabel = new JLabel("%");
mPanel.add(mLabel);
}

// OK
{
mOK = new JButton("OK");
mOK.setEnabled(true);
mOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
}

// Cancel
{
mCancel = new JButton("Cancel");
mCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
});
}

// Container
{
Container container1 = new Container();
GridLayout gridLayout = new GridLayout(1, 2, 0, 0);
container1.setLayout(gridLayout);
container1.add(mOK);
container1.add(mCancel);

Container containger = getContentPane();
containger.add(mPanel, BorderLayout.CENTER);
containger.add(container1, BorderLayout.SOUTH);
}

// Key
{
AbstractAction actionOK = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
onOK();
}
};
AbstractAction actionCancel = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
};

JComponent targetComponent = getRootPane();
InputMap inputMap = targetComponent.getInputMap();
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "OK");
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
"Cancel");
targetComponent.setInputMap(
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
targetComponent.getActionMap().put("OK", actionOK);
targetComponent.getActionMap().put("Cancel", actionCancel);
}
}

public double getSpecifiedZoom() {
return mSpecifiedZoom;
}

public boolean isOK() {
return mIsOK;
}

private void onOK() {
mSpecifiedZoom = ((Integer)mSpinner.getValue())/100.0;
mIsOK = true;
dispose();
}

private void onCancel() {
dispose();
}
}

0 comments on commit c6bd81e

Please sign in to comment.