• R/O
  • HTTP
  • SSH
  • HTTPS

TinyBannavi: Commit

タイニー番組ナビゲータ本体


Commit MetaInfo

Revisiónacda55c6634caab31e1f78d63708ececf90f8214 (tree)
Tiempo2014-07-02 10:18:44
Autorpeeweedee <peeweedee@user...>
Commiterpeeweedee

Log Message

・プルダウンメニューの一部にキーボードショートカットをつける

Cambiar Resumen

Diferencia incremental

--- a/TinyBannavi/src/tainavi/AbsListedView.java
+++ b/TinyBannavi/src/tainavi/AbsListedView.java
@@ -6,14 +6,7 @@ import java.awt.Component;
66 import java.awt.Desktop;
77 import java.awt.Dimension;
88 import java.awt.Point;
9-import java.awt.event.ActionEvent;
10-import java.awt.event.ActionListener;
11-import java.awt.event.ComponentAdapter;
12-import java.awt.event.ComponentEvent;
13-import java.awt.event.ComponentListener;
14-import java.awt.event.MouseAdapter;
15-import java.awt.event.MouseEvent;
16-import java.awt.event.MouseListener;
9+import java.awt.event.*;
1710 import java.io.File;
1811 import java.io.IOException;
1912 import java.net.URI;
@@ -3269,7 +3262,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
32693262 JPopupMenu pop = new JPopupMenu();
32703263
32713264 {
3272- JMenuItem menuItem = new JMenuItem("番組追跡の編集【"+keyword+"】");
3265+ JMenuItem menuItem = new JMenuItemWithShortcut("番組追跡の編集【"+keyword+"】");
3266+ menuItem.setMnemonic(KeyEvent.VK_E);
32733267 menuItem.addActionListener(new ActionListener() {
32743268 public void actionPerformed(ActionEvent e) {
32753269 editTraceKey(keyword);
@@ -3279,7 +3273,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
32793273 }
32803274
32813275 {
3282- JMenuItem menuItem = new JMenuItem("番組追跡の削除【"+keyword+"】");
3276+ JMenuItem menuItem = new JMenuItemWithShortcut("番組追跡の削除【"+keyword+"】");
3277+ menuItem.setMnemonic(KeyEvent.VK_D);
32833278 menuItem.addActionListener(new ActionListener() {
32843279 public void actionPerformed(ActionEvent e) {
32853280 removeTraceKey(keyword);
@@ -3299,6 +3294,7 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
32993294 for (String o : TVProgram.OKINIIRI) {
33003295 final String okini = o;
33013296 JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(okini, okini.equals(tk.getOkiniiri()));
3297+ menuItem.setMnemonic(KeyEvent.VK_0 + okini.length());
33023298 bg.add(menuItem);
33033299 menuItem.addActionListener(new ActionListener() {
33043300 public void actionPerformed(ActionEvent e) {
@@ -3321,7 +3317,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
33213317 JPopupMenu pop = new JPopupMenu();
33223318
33233319 {
3324- JMenuItem menuItem = new JMenuItem("キーワードの編集【"+keyword+"】");
3320+ JMenuItem menuItem = new JMenuItemWithShortcut("キーワードの編集【"+keyword+"】");
3321+ menuItem.setMnemonic(KeyEvent.VK_E);
33253322 menuItem.addActionListener(new ActionListener() {
33263323 public void actionPerformed(ActionEvent e) {
33273324 editSearchKey(keyword);
@@ -3330,7 +3327,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
33303327 pop.add(menuItem);
33313328 }
33323329 {
3333- JMenuItem menuItem = new JMenuItem("キーワードの削除【"+keyword+"】");
3330+ JMenuItem menuItem = new JMenuItemWithShortcut("キーワードの削除【"+keyword+"】");
3331+ menuItem.setMnemonic(KeyEvent.VK_D);
33343332 menuItem.addActionListener(new ActionListener() {
33353333 public void actionPerformed(ActionEvent e) {
33363334 removeSearchKey(keyword);
@@ -3345,7 +3343,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
33453343 for ( SearchGroup gr : srGrps ) {
33463344 final String groupName = gr.getName();
33473345 if (srGrps.isFind(groupName,keyword) ) {
3348- JMenuItem menuItem = new JMenuItem("キーワードグループから登録解除【"+groupName+"】");
3346+ JMenuItem menuItem = new JMenuItemWithShortcut("キーワードグループから登録解除【"+groupName+"】");
3347+ menuItem.setMnemonic(KeyEvent.VK_R);
33493348 menuItem.setForeground(Color.RED);
33503349 menuItem.addActionListener(new ActionListener() {
33513350 public void actionPerformed(ActionEvent e) {
@@ -3355,7 +3354,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
33553354 pop.add(menuItem);
33563355 }
33573356 else {
3358- JMenuItem menuItem = new JMenuItem("キーワードグループに追加【"+groupName+"】");
3357+ JMenuItem menuItem = new JMenuItemWithShortcut("キーワードグループに追加【"+groupName+"】");
3358+ menuItem.setMnemonic(KeyEvent.VK_A);
33593359 menuItem.addActionListener(new ActionListener() {
33603360 public void actionPerformed(ActionEvent e) {
33613361 addSearchKeyGroupItem(groupName,keyword);
@@ -3377,6 +3377,7 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
33773377 for (String o : TVProgram.OKINIIRI) {
33783378 final String okini = o;
33793379 JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(okini, okini.equals(sr.getOkiniiri()));
3380+ menuItem.setMnemonic(KeyEvent.VK_0 + okini.length());
33803381 bg.add(menuItem);
33813382 menuItem.addActionListener(new ActionListener() {
33823383 public void actionPerformed(ActionEvent e) {
@@ -3396,7 +3397,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
33963397 private void showPopupForSortTraceKey(int x, int y) {
33973398 JPopupMenu pop = new JPopupMenu();
33983399 {
3399- JMenuItem menuItem = new JMenuItem("番組追跡の並べ替え");
3400+ JMenuItem menuItem = new JMenuItemWithShortcut("番組追跡の並べ替え");
3401+ menuItem.setMnemonic(KeyEvent.VK_S);
34003402 menuItem.addActionListener(new ActionListener() {
34013403 public void actionPerformed(ActionEvent e) {
34023404 sortTraceKey();
@@ -3411,7 +3413,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
34113413 private void showPopupForSortSearchKey(int x, int y) {
34123414 JPopupMenu pop = new JPopupMenu();
34133415 {
3414- JMenuItem menuItem = new JMenuItem("キーワード検索の並べ替え");
3416+ JMenuItem menuItem = new JMenuItemWithShortcut("キーワード検索の並べ替え");
3417+ menuItem.setMnemonic(KeyEvent.VK_S);
34153418 menuItem.addActionListener(new ActionListener() {
34163419 public void actionPerformed(ActionEvent e) {
34173420 sortSearchKey();
@@ -3426,7 +3429,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
34263429 private void showPopupForSortExtension(int x, int y) {
34273430 JPopupMenu pop = new JPopupMenu();
34283431 {
3429- JMenuItem menuItem = new JMenuItem("延長警告の並べ替え");
3432+ JMenuItem menuItem = new JMenuItemWithShortcut("延長警告の並べ替え");
3433+ menuItem.setMnemonic(KeyEvent.VK_S);
34303434 menuItem.addActionListener(new ActionListener() {
34313435 public void actionPerformed(ActionEvent e) {
34323436 sortExtension();
@@ -3443,7 +3447,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
34433447 JPopupMenu pop = new JPopupMenu();
34443448
34453449 {
3446- JMenuItem menuItem = new JMenuItem("キーワードグループの追加");
3450+ JMenuItem menuItem = new JMenuItemWithShortcut("キーワードグループの追加");
3451+ menuItem.setMnemonic(KeyEvent.VK_A);
34473452 menuItem.addActionListener(new ActionListener() {
34483453 public void actionPerformed(ActionEvent e) {
34493454 addSearchKeyGroup();
@@ -3459,7 +3464,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
34593464 JPopupMenu pop = new JPopupMenu();
34603465
34613466 {
3462- JMenuItem menuItem = new JMenuItem("キーワードグループの編集【"+name+"】");
3467+ JMenuItem menuItem = new JMenuItemWithShortcut("キーワードグループの編集【"+name+"】");
3468+ menuItem.setMnemonic(KeyEvent.VK_E);
34633469 menuItem.addActionListener(new ActionListener() {
34643470 public void actionPerformed(ActionEvent e) {
34653471 editSeachkeyGroup(name);
@@ -3471,7 +3477,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
34713477 pop.addSeparator();
34723478
34733479 {
3474- JMenuItem menuItem = new JMenuItem("キーワードグループの削除【"+name+"】");
3480+ JMenuItem menuItem = new JMenuItemWithShortcut("キーワードグループの削除【"+name+"】");
3481+ menuItem.setMnemonic(KeyEvent.VK_D);
34753482 menuItem.addActionListener(new ActionListener() {
34763483 public void actionPerformed(ActionEvent e) {
34773484 removeSearchKeyGroup(name);
@@ -3487,7 +3494,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
34873494 JPopupMenu pop = new JPopupMenu();
34883495
34893496 {
3490- JMenuItem menuItem = new JMenuItem("キーワードの編集【"+member+"】");
3497+ JMenuItem menuItem = new JMenuItemWithShortcut("キーワードの編集【"+member+"】");
3498+ menuItem.setMnemonic(KeyEvent.VK_E);
34913499 menuItem.addActionListener(new ActionListener() {
34923500 public void actionPerformed(ActionEvent e) {
34933501 editSearchKeyGroupItem(name,member);
@@ -3496,7 +3504,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
34963504 pop.add(menuItem);
34973505 }
34983506 {
3499- JMenuItem menuItem = new JMenuItem("キーワードの削除【"+member+"】");
3507+ JMenuItem menuItem = new JMenuItemWithShortcut("キーワードの削除【"+member+"】");
3508+ menuItem.setMnemonic(KeyEvent.VK_D);
35003509 menuItem.addActionListener(new ActionListener() {
35013510 public void actionPerformed(ActionEvent e) {
35023511 removeSearchKeyGroupItem(null,member);
@@ -3511,8 +3520,9 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
35113520 for ( SearchGroup gr : srGrps ) {
35123521 final String groupName = gr.getName();
35133522 if (srGrps.isFind(groupName,member) ) {
3514- JMenuItem menuItem = new JMenuItem("キーワードグループから登録解除【"+groupName+"】");
3523+ JMenuItem menuItem = new JMenuItemWithShortcut("キーワードグループから登録解除【"+groupName+"】");
35153524 menuItem.setForeground(Color.RED);
3525+ menuItem.setMnemonic(KeyEvent.VK_R);
35163526 menuItem.addActionListener(new ActionListener() {
35173527 public void actionPerformed(ActionEvent e) {
35183528 removeSearchKeyGroupItem(groupName, member);
@@ -3521,7 +3531,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
35213531 pop.add(menuItem);
35223532 }
35233533 else {
3524- JMenuItem menuItem = new JMenuItem("キーワードグループに追加【"+groupName+"】");
3534+ JMenuItem menuItem = new JMenuItemWithShortcut("キーワードグループに追加【"+groupName+"】");
3535+ menuItem.setMnemonic(KeyEvent.VK_A);
35253536 menuItem.addActionListener(new ActionListener() {
35263537 public void actionPerformed(ActionEvent e) {
35273538 addSearchKeyGroupItem(groupName,member);
@@ -3541,7 +3552,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
35413552 JPopupMenu pop = new JPopupMenu();
35423553
35433554 {
3544- JMenuItem menuItem = new JMenuItem("延長警告の編集【"+keyword+"】");
3555+ JMenuItem menuItem = new JMenuItemWithShortcut("延長警告の編集【"+keyword+"】");
3556+ menuItem.setMnemonic(KeyEvent.VK_E);
35453557 menuItem.addActionListener(new ActionListener() {
35463558 public void actionPerformed(ActionEvent e) {
35473559 editExtension(keyword);
@@ -3550,7 +3562,8 @@ public abstract class AbsListedView extends JPanel implements TickTimerListener
35503562 pop.add(menuItem);
35513563 }
35523564 {
3553- JMenuItem menuItem = new JMenuItem("延長警告の削除【"+keyword+"】");
3565+ JMenuItem menuItem = new JMenuItemWithShortcut("延長警告の削除【"+keyword+"】");
3566+ menuItem.setMnemonic(KeyEvent.VK_D);
35543567 menuItem.addActionListener(new ActionListener() {
35553568 public void actionPerformed(ActionEvent e) {
35563569 removeExtension(keyword);
--- a/TinyBannavi/src/tainavi/CommonSwingUtils.java
+++ b/TinyBannavi/src/tainavi/CommonSwingUtils.java
@@ -1,13 +1,6 @@
11 package tainavi;
22
3-import java.awt.Color;
4-import java.awt.Component;
5-import java.awt.Dimension;
6-import java.awt.Font;
7-import java.awt.Graphics2D;
8-import java.awt.Insets;
9-import java.awt.Point;
10-import java.awt.Rectangle;
3+import java.awt.*;
114 import java.awt.image.BufferedImage;
125 import java.beans.PropertyChangeEvent;
136 import java.beans.PropertyChangeListener;
@@ -261,4 +254,55 @@ public class CommonSwingUtils {
261254 e.printStackTrace();
262255 }
263256 }
257+
258+ /**
259+ * 左端で折り返す文字列の描画
260+ */
261+ public static int drawWrappedString(Graphics2D g, int x, int baseline, int width, int height, String message, FontMetrics fm, int fontHeight, boolean center) {
262+ int top = 0;
263+ int bottom = top;
264+ int length = message.length();
265+ int strWidth = 0;
266+ int cWidth = 0;
267+ int drawX = 0;
268+ while ( bottom < length && baseline < height) {
269+ String str;
270+ if ( cWidth == 0 ) {
271+ char c = message.charAt(bottom);
272+ cWidth = fm.charWidth(c);
273+ }
274+ if ( (strWidth+cWidth) > width ) {
275+ // 越えちゃった
276+ str = message.substring(top, bottom);
277+ // センタリング有無
278+ if ( center ) {
279+ drawX = (width-strWidth) / 2;
280+ }
281+ // 次の頭(cWidthは次のループで利用)
282+ top = bottom;
283+ strWidth = cWidth;
284+ }
285+ else if ( bottom+1 == length ) {
286+ // 残り全部
287+ str = message.substring(top, bottom+1);
288+ // センタリング有無
289+ if ( center ) {
290+ drawX = (width-strWidth) / 2;
291+ }
292+ // 次はない
293+ bottom++;
294+ }
295+ else {
296+ // まだ足りない
297+ bottom++;
298+ strWidth += cWidth;
299+ cWidth = 0;
300+ continue;
301+ }
302+ g.drawString(str, x+drawX, baseline);
303+ baseline += fontHeight;
304+ }
305+ return baseline;
306+ }
307+
264308 }
--- /dev/null
+++ b/TinyBannavi/src/tainavi/JMenuItemWithShortcut.java
@@ -0,0 +1,27 @@
1+package tainavi;
2+
3+import javax.swing.*;
4+import java.awt.event.KeyEvent;
5+
6+/**
7+ * Created by unknown on 2014/07/02.
8+ */
9+public class JMenuItemWithShortcut extends JMenuItem {
10+
11+ public JMenuItemWithShortcut(String s) {
12+ super(s);
13+ }
14+
15+ @Override
16+ public String getText() {
17+ int n = this.getMnemonic();
18+ int k = 0;
19+ if ( n >= KeyEvent.VK_0 && n >= KeyEvent.VK_0 ) {
20+ k = '0' + (n - KeyEvent.VK_0);
21+ }
22+ if ( n >= KeyEvent.VK_A && n >= KeyEvent.VK_Z ) {
23+ k = 'a' + (n - KeyEvent.VK_A);
24+ }
25+ return ((k > 0) ? String.format("(%c) ", n) : "") + super.getText();
26+ }
27+}
--- a/TinyBannavi/src/tainavi/JTXTButton.java
+++ b/TinyBannavi/src/tainavi/JTXTButton.java
@@ -65,7 +65,7 @@ public class JTXTButton extends JLabel {
6565 }
6666 };
6767
68- private static final float DRAWTAB = 2.0F;
68+ private static final float DRAWTAB = 2.0F;
6969
7070
7171 /*******************************************************************************
@@ -306,7 +306,7 @@ public class JTXTButton extends JLabel {
306306 FontMetrics fm = g2.getFontMetrics(startFont);
307307 float hi = Float.valueOf(fm.getHeight());
308308 float as = Float.valueOf(fm.getAscent());
309-
309+
310310 float startx = Float.valueOf(DRAWTAB);
311311 float startw = draww;
312312 float xposstartx = 0.0F;
@@ -369,7 +369,7 @@ public class JTXTButton extends JLabel {
369369 GlyphVector gv = wgv.getGv();
370370 g2.setPaint(Color.RED);
371371 g2.drawGlyphVector(gv, titlex, baseline);
372-
372+
373373 xpos = wgv.getLastX(); // 後続有り
374374 baseline += wgv.getLastY();
375375 }
@@ -396,7 +396,23 @@ public class JTXTButton extends JLabel {
396396 else {
397397 detail = tvd.detail;
398398 }
399-
399+
400+ /*
401+ FontMetrics fm = g2.getFontMetrics(detailFont);
402+ int hi = fm.getAscent() + fm.getDescent();
403+ int as = fm.getAscent();
404+ int detailx = (int) (DRAWTAB+detailTab);
405+ int detailw = (int) (draww-detailTab);
406+
407+ if ( baseline == 0.0F ) {
408+ baseline = as; // 初期垂直位置
409+ }
410+
411+ g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
412+ g2.setColor(detailFontColor);
413+ CommonSwingUtils.drawWrappedString(g2, detailx, (int)baseline, detailw, (int)drawh, detail, fm, hi, false);
414+ */
415+
400416 FontMetrics fm = g2.getFontMetrics(detailFont);
401417 float as = Float.valueOf(fm.getAscent());
402418 float detailx = Float.valueOf(DRAWTAB+detailTab);
@@ -405,7 +421,7 @@ public class JTXTButton extends JLabel {
405421 if ( baseline == 0.0F ) {
406422 baseline = as; // 初期垂直位置
407423 }
408-
424+
409425 WrappedGlyphVector wgv = getWrappedGlyphVector(detail, detailw, 0.0f, detailFont, as, frc);
410426 g2.setPaint(detailFontColor);
411427
Show on old repository browser