Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit 28a96ef

Browse files
authored
Update the CycleEditor synced with local copy (#59)
1 parent 1cd8f06 commit 28a96ef

File tree

11 files changed

+1929
-222
lines changed

11 files changed

+1929
-222
lines changed

CycleEditor/src/com/google/androidstudio/motionlayoutcycles/AnimationPanel.java

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,10 @@
1616

1717
package com.google.androidstudio.motionlayoutcycles;
1818

19-
import com.google.androidstudio.motionlayoutcycles.CycleSetModel.*;
20-
import com.google.androidstudio.motionlayoutcycles.CycleView.Prop;
21-
import java.awt.BasicStroke;
22-
import java.awt.Color;
23-
import java.awt.FlowLayout;
24-
import java.awt.Graphics;
25-
import java.awt.Graphics2D;
26-
import java.awt.Insets;
27-
import java.awt.Stroke;
28-
import java.awt.geom.AffineTransform;
29-
import javax.swing.JButton;
30-
import javax.swing.JPanel;
31-
import javax.swing.Timer;
32-
import javax.swing.border.CompoundBorder;
33-
import javax.swing.border.EmptyBorder;
34-
import javax.swing.border.EtchedBorder;
19+
import javax.swing.*;
3520
import javax.swing.border.LineBorder;
36-
import javax.swing.border.MatteBorder;
21+
import java.awt.*;
22+
import java.awt.geom.AffineTransform;
3723

3824
/**
3925
* This panel simulates and Android view parameter for controlling a button
@@ -151,55 +137,55 @@ public void paint(Graphics g) {
151137
Color text = Color.BLACK;
152138
if (myAttributeMask != 0) {
153139

154-
if ((myAttributeMask & (1 << Prop.PATH_ROTATE.ordinal())) != 0) {
140+
if ((myAttributeMask & (1 << CycleView.Prop.PATH_ROTATE.ordinal())) != 0) {
155141
at = new AffineTransform();
156-
at.rotate(Math.toRadians(myCycleModel.getValue(Prop.PATH_ROTATE, myEasedPercent)), buttonCX,
142+
at.rotate(Math.toRadians(myCycleModel.getValue(CycleView.Prop.PATH_ROTATE, myEasedPercent)), buttonCX,
157143
buttonCY);
158144
g2d.transform(at);
159145
}
160-
if ((myAttributeMask & (1 << Prop.ALPHA.ordinal())) != 0) {
146+
if ((myAttributeMask & (1 << CycleView.Prop.ALPHA.ordinal())) != 0) {
161147
int alpha = Math
162-
.max(0, Math.min(255, (int) (myCycleModel.getValue(Prop.ALPHA, myEasedPercent) * 255)));
148+
.max(0, Math.min(255, (int) (myCycleModel.getValue(CycleView.Prop.ALPHA, myEasedPercent) * 255)));
163149
background = new Color(background.getRed(), background.getGreen(), background.getBlue(),
164150
alpha);
165151
border = new Color(border.getRed(), border.getGreen(), border.getBlue(), alpha);
166152
text = new Color(text.getRed(), text.getGreen(), text.getBlue(), alpha);
167153
}
168154

169-
if ((myAttributeMask & (1 << Prop.SCALE_X.ordinal())) != 0) {
155+
if ((myAttributeMask & (1 << CycleView.Prop.SCALE_X.ordinal())) != 0) {
170156
at = new AffineTransform();
171157
at.translate(w / 2.0, buttonCY);
172-
at.scale(myCycleModel.getValue(Prop.SCALE_X, myEasedPercent), 1);
158+
at.scale(myCycleModel.getValue(CycleView.Prop.SCALE_X, myEasedPercent), 1);
173159
at.translate(-w / 2.0, -buttonCY);
174160

175161
g2d.transform(at);
176162
}
177163

178-
if ((myAttributeMask & (1 << Prop.SCALE_Y.ordinal())) != 0) {
164+
if ((myAttributeMask & (1 << CycleView.Prop.SCALE_Y.ordinal())) != 0) {
179165

180166
at = new AffineTransform();
181167
at.translate(buttonCX, buttonCY);
182-
at.scale(1, myCycleModel.getValue(Prop.SCALE_Y, myEasedPercent));
168+
at.scale(1, myCycleModel.getValue(CycleView.Prop.SCALE_Y, myEasedPercent));
183169
at.translate(-buttonCX, -buttonCY);
184170
g2d.transform(at);
185171
}
186172

187-
if ((myAttributeMask & (1 << Prop.TRANSLATION_X.ordinal())) != 0) {
173+
if ((myAttributeMask & (1 << CycleView.Prop.TRANSLATION_X.ordinal())) != 0) {
188174

189175
at = new AffineTransform();
190-
at.translate(myCycleModel.getValue(Prop.TRANSLATION_X, myEasedPercent), 0);
176+
at.translate(myCycleModel.getValue(CycleView.Prop.TRANSLATION_X, myEasedPercent), 0);
191177
g2d.transform(at);
192178
}
193179

194-
if ((myAttributeMask & (1 << Prop.TRANSLATION_Y.ordinal())) != 0) {
180+
if ((myAttributeMask & (1 << CycleView.Prop.TRANSLATION_Y.ordinal())) != 0) {
195181

196182
at = new AffineTransform();
197-
at.translate(0, myCycleModel.getValue(Prop.TRANSLATION_Y, myEasedPercent));
183+
at.translate(0, myCycleModel.getValue(CycleView.Prop.TRANSLATION_Y, myEasedPercent));
198184
g2d.transform(at);
199185
}
200-
if ((myAttributeMask & (1 << Prop.ROTATION.ordinal())) != 0) {
186+
if ((myAttributeMask & (1 << CycleView.Prop.ROTATION.ordinal())) != 0) {
201187
at = new AffineTransform();
202-
at.rotate(Math.toRadians(myCycleModel.getValue(Prop.ROTATION, myEasedPercent)), buttonCX,
188+
at.rotate(Math.toRadians(myCycleModel.getValue(CycleView.Prop.ROTATION, myEasedPercent)), buttonCX,
203189
buttonCY);
204190
g2d.transform(at);
205191
}
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
/*
2+
* Copyright (C) 2019 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.androidstudio.motionlayoutcycles;
17+
18+
import static javax.swing.SwingConstants.TRAILING;
19+
20+
import java.awt.BorderLayout;
21+
import java.awt.Container;
22+
import java.awt.GridBagConstraints;
23+
import java.awt.GridBagLayout;
24+
import java.awt.Insets;
25+
import java.awt.event.ActionListener;
26+
import java.awt.event.MouseAdapter;
27+
import java.awt.event.MouseEvent;
28+
import javax.swing.JButton;
29+
import javax.swing.JComboBox;
30+
import javax.swing.JLabel;
31+
import javax.swing.JPanel;
32+
import javax.swing.JSlider;
33+
import javax.swing.JTabbedPane;
34+
import javax.swing.JTextField;
35+
import javax.swing.UIManager;
36+
import javax.swing.border.EmptyBorder;
37+
import javax.swing.plaf.basic.BasicArrowButton;
38+
39+
/**
40+
* The gui to edit a single cycle
41+
*/
42+
public class CycleEdit extends JPanel {
43+
44+
private static final boolean DEBUG = false;
45+
JComboBox<String> baseMovement = new JComboBox<>(AnimationPanel.MOVE_NAMES);
46+
JComboBox<String> duration = new JComboBox<>(AnimationPanel.DURATION);
47+
CycleModel myCycleModel;
48+
JComboBox<String> attrName;
49+
50+
class TabUI extends JPanel {
51+
52+
JButton tabButton = new JButton();
53+
JButton tabTitle = new JButton();
54+
55+
TabUI(String name) {
56+
super(new BorderLayout());
57+
setBackground(null);
58+
tabButton.setBorder(null);
59+
60+
add(tabTitle, BorderLayout.CENTER);
61+
add(tabButton, BorderLayout.EAST);
62+
tabTitle.setBorder(null);
63+
tabTitle.setFocusPainted(false);
64+
tabTitle.setContentAreaFilled(false);
65+
tabTitle.setBorderPainted(true);
66+
tabTitle.setBackground(null);
67+
tabTitle.setMargin(new Insets(0, 0, 0, 0));
68+
tabTitle.setText(name);
69+
70+
tabButton.setBorder(null);
71+
tabButton.setIcon(UIManager.getIcon("InternalFrame.paletteCloseIcon"));
72+
tabButton.setFocusPainted(false);
73+
tabButton.setContentAreaFilled(false);
74+
tabButton.setBorderPainted(true);
75+
tabButton.setBackground(null);
76+
tabButton.setMargin(new Insets(0, 0, 0, 0));
77+
}
78+
79+
public void addRaiseAction(ActionListener al) {
80+
tabTitle.addActionListener(al);
81+
}
82+
83+
public void addKillAction(ActionListener al) {
84+
tabButton.addActionListener(al);
85+
}
86+
}
87+
88+
void updateTabName(String name) {
89+
if (DEBUG) {
90+
System.out.println(">>>>>" + name + " " + MainPanel.getTabbIndex(this));
91+
StackTraceElement[] s = new Throwable().getStackTrace();
92+
System.out.println(" .(" + s[1].getFileName() + ":" + s[1].getLineNumber() + ") ");
93+
System.out.println(" .(" + s[2].getFileName() + ":" + s[2].getLineNumber() + ") ");
94+
}
95+
Container tabb = getParent();
96+
while (!(tabb instanceof JTabbedPane)) {
97+
tabb = tabb.getParent();
98+
}
99+
100+
JTabbedPane tabbedPane = (JTabbedPane) tabb;
101+
int index = MainPanel.getTabbIndex(this);
102+
tabbedPane.setTitleAt(index, name);
103+
// tabUI = new TabUI(name);
104+
// tabbedPane.setTabComponentAt(index, tabUI);
105+
}
106+
107+
public void removeCycle() {
108+
myCycleModel.myCycle.myModelSet.removeCycle(myCycleModel.myCycle);
109+
listener.actionPerformed(null);
110+
}
111+
112+
ActionListener listener;
113+
114+
public void setRemoveCallback(ActionListener l) {
115+
listener = l;
116+
}
117+
118+
public CycleEdit(CycleView cycleView, CycleModel cycleModel, AnimationPanel animationPanel) {
119+
super(new GridBagLayout());
120+
JPanel control = this;
121+
122+
setBorder(new EmptyBorder(5, 10, 10, 20));
123+
myCycleModel = cycleModel;
124+
125+
cycleView.addMouseListener(new MouseAdapter() {
126+
@Override
127+
public void mouseClicked(MouseEvent e) {
128+
myCycleModel.selectClosest(cycleView.last_click);
129+
}
130+
});
131+
BasicArrowButton next = new BasicArrowButton(BasicArrowButton.EAST);
132+
BasicArrowButton prev = new BasicArrowButton(BasicArrowButton.WEST);
133+
myCycleModel.delete = next;
134+
cycleView.addMouseListener(new MouseAdapter() {
135+
@Override
136+
public void mouseClicked(MouseEvent e) {
137+
myCycleModel.selectClosest(cycleView.last_click);
138+
}
139+
});
140+
JTextField number = new JTextField("XX");
141+
number.setPreferredSize(number.getPreferredSize());
142+
GridBagConstraints gbc = new GridBagConstraints();
143+
number.setText("" + myCycleModel.selected);
144+
number.setEditable(false);
145+
gbc.insets = new Insets(10, 5, 0, 0);
146+
next.addActionListener((e) -> {
147+
myCycleModel.changeSelection(+1);
148+
});
149+
prev.addActionListener((e) -> {
150+
myCycleModel.changeSelection(-1);
151+
});
152+
myCycleModel.mKeyCycleNo = number;
153+
154+
gbc.gridy = 0;
155+
gbc.gridx = 2;
156+
gbc.gridwidth = 1;
157+
158+
control.add(new JLabel("KeyCycle:", TRAILING), gbc);
159+
gbc.gridx = 3;
160+
gbc.anchor = GridBagConstraints.EAST;
161+
control.add(prev, gbc);
162+
gbc.gridx++;
163+
control.add(number, gbc);
164+
gbc.gridx++;
165+
gbc.anchor = GridBagConstraints.WEST;
166+
control.add(next, gbc);
167+
gbc.gridy++;
168+
169+
JButton del = new JButton("Delete");
170+
JButton add = new JButton("Add");
171+
myCycleModel.add = add;
172+
myCycleModel.delete = del;
173+
del.addActionListener((e) -> {
174+
myCycleModel.delete();
175+
});
176+
add.addActionListener((e) -> {
177+
myCycleModel.add();
178+
});
179+
gbc.gridwidth = 1;
180+
gbc.gridx = 3;
181+
control.add(add, gbc);
182+
gbc.gridx += 2;
183+
control.add(del, gbc);
184+
gbc.gridy++;
185+
gbc.gridwidth = 3;
186+
JSlider pos = new JSlider();
187+
gbc.gridx = 0;
188+
gbc.anchor = GridBagConstraints.NORTHEAST;
189+
control.add(new JLabel("Pos:", TRAILING), gbc);
190+
gbc.gridx += 3;
191+
gbc.anchor = GridBagConstraints.WEST;
192+
control.add(pos, gbc);
193+
gbc.gridy++;
194+
195+
JSlider period = new JSlider();
196+
gbc.gridx = 0;
197+
gbc.anchor = GridBagConstraints.NORTHEAST;
198+
control.add(new JLabel("Period:", TRAILING), gbc);
199+
gbc.gridx += 3;
200+
gbc.anchor = GridBagConstraints.WEST;
201+
202+
control.add(period, gbc);
203+
gbc.gridy++;
204+
205+
JSlider amp = new JSlider();
206+
gbc.gridx = 0;
207+
gbc.anchor = GridBagConstraints.NORTHEAST;
208+
attrName = new JComboBox<>(CycleView.MainAttribute.ShortNames);
209+
attrName.setSelectedIndex(myCycleModel.mAttrIndex);
210+
attrName.addActionListener(e -> {
211+
myCycleModel.setAttr(attrName.getSelectedIndex());
212+
updateTabName(myCycleModel.getAttName());
213+
animationPanel.setMode();
214+
});
215+
216+
control.add(attrName, gbc);
217+
218+
gbc.gridx += 3;
219+
gbc.anchor = GridBagConstraints.WEST;
220+
control.add(amp, gbc);
221+
222+
gbc.gridy++;
223+
JSlider off = new JSlider();
224+
gbc.gridx = 0;
225+
gbc.anchor = GridBagConstraints.NORTHEAST;
226+
control.add(new JLabel("Offset:", TRAILING), gbc);
227+
228+
gbc.gridx += 3;
229+
gbc.anchor = GridBagConstraints.WEST;
230+
control.add(off, gbc);
231+
232+
gbc.gridy++;
233+
gbc.gridx = 0;
234+
gbc.anchor = GridBagConstraints.EAST;
235+
control.add(new JLabel("WaveType:", TRAILING), gbc);
236+
237+
JComboBox<String> mode = new JComboBox<>(myCycleModel.waveShapeName);
238+
gbc.gridx += 3;
239+
gbc.anchor = GridBagConstraints.WEST;
240+
control.add(mode, gbc);
241+
242+
gbc.gridy++;
243+
gbc.gridx = 0;
244+
gbc.anchor = GridBagConstraints.NORTHEAST;
245+
control.add(new JLabel("Target:", TRAILING), gbc);
246+
247+
gbc.gridx += 3;
248+
gbc.anchor = GridBagConstraints.WEST;
249+
JTextField target = new JTextField("XXXXXXXXXXXXXXXXXXXXX");
250+
target.setPreferredSize(target.getPreferredSize());
251+
target.setText("button");
252+
control.add(target, gbc);
253+
254+
myCycleModel.setTarget(target);
255+
myCycleModel.setUIElements(pos, period, amp, off, mode);
256+
myCycleModel.setCycle(cycleView);
257+
}
258+
}

0 commit comments

Comments
 (0)