source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java@ 4269

Last change on this file since 4269 was 4222, checked in by stoecker, 13 years ago

fix #6569 - patch by Casiope - Improve translation for Mappaint

  • Property svn:eol-style set to native
File size: 25.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.BorderLayout;
7import java.awt.Component;
8import java.awt.Dimension;
9import java.awt.Font;
10import java.awt.GridBagLayout;
11import java.awt.Insets;
12import java.awt.Point;
13import java.awt.Rectangle;
14import java.awt.event.ActionEvent;
15import java.awt.event.ActionListener;
16import java.awt.event.KeyEvent;
17import java.awt.event.MouseEvent;
18import java.io.BufferedInputStream;
19import java.io.BufferedOutputStream;
20import java.io.BufferedReader;
21import java.io.File;
22import java.io.FileOutputStream;
23import java.io.IOException;
24import java.io.InputStream;
25import java.io.InputStreamReader;
26import java.util.ArrayList;
27import java.util.List;
28
29import javax.swing.AbstractAction;
30import javax.swing.DefaultButtonModel;
31import javax.swing.DefaultListSelectionModel;
32import javax.swing.JCheckBox;
33import javax.swing.JFileChooser;
34import javax.swing.JLabel;
35import javax.swing.JPanel;
36import javax.swing.JPopupMenu;
37import javax.swing.JScrollPane;
38import javax.swing.JTabbedPane;
39import javax.swing.JTable;
40import javax.swing.JTextArea;
41import javax.swing.JViewport;
42import javax.swing.ListSelectionModel;
43import javax.swing.SingleSelectionModel;
44import javax.swing.SwingConstants;
45import javax.swing.SwingUtilities;
46import javax.swing.UIManager;
47import javax.swing.border.EmptyBorder;
48import javax.swing.event.ChangeEvent;
49import javax.swing.event.ChangeListener;
50import javax.swing.event.ListSelectionEvent;
51import javax.swing.event.ListSelectionListener;
52import javax.swing.table.AbstractTableModel;
53import javax.swing.table.DefaultTableCellRenderer;
54import javax.swing.table.TableCellRenderer;
55import javax.swing.table.TableModel;
56
57import org.openstreetmap.josm.Main;
58import org.openstreetmap.josm.actions.SaveActionBase;
59import org.openstreetmap.josm.gui.ExtendedDialog;
60import org.openstreetmap.josm.gui.PleaseWaitRunnable;
61import org.openstreetmap.josm.gui.SideButton;
62import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
63import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener;
64import org.openstreetmap.josm.gui.mappaint.StyleSource;
65import org.openstreetmap.josm.gui.preferences.PreferenceDialog;
66import org.openstreetmap.josm.gui.preferences.SourceEntry;
67import org.openstreetmap.josm.gui.widgets.HtmlPanel;
68import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
69import org.openstreetmap.josm.tools.GBC;
70import org.openstreetmap.josm.tools.ImageProvider;
71import org.openstreetmap.josm.tools.Shortcut;
72import org.openstreetmap.josm.tools.Utils;
73
74public class MapPaintDialog extends ToggleDialog {
75
76 protected StylesTable tblStyles;
77 protected StylesModel model;
78 protected DefaultListSelectionModel selectionModel;
79
80 protected OnOffAction onoffAction;
81 protected ReloadAction reloadAction;
82 protected MoveUpDownAction upAction;
83 protected MoveUpDownAction downAction;
84 protected JCheckBox cbWireframe;
85
86 public MapPaintDialog() {
87 super(tr("Map Paint Styles"), "mapstyle", tr("configure the map painting style"),
88 Shortcut.registerShortcut("subwindow:mappaint", tr("Toggle: {0}", tr("MapPaint")), KeyEvent.VK_M, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150);
89 build();
90 }
91
92 protected void build() {
93 JPanel pnl = new JPanel();
94 pnl.setLayout(new BorderLayout());
95
96 model = new StylesModel();
97
98 cbWireframe = new JCheckBox();
99 JLabel wfLabel = new JLabel(tr("Wireframe View"), ImageProvider.get("dialogs/mappaint", "wireframe_small"), JLabel.HORIZONTAL);
100 wfLabel.setFont(wfLabel.getFont().deriveFont(Font.PLAIN));
101
102 cbWireframe.setModel(new DefaultButtonModel() {
103 @Override
104 public void setSelected(boolean b) {
105 super.setSelected(b);
106 tblStyles.setEnabled(!b);
107 onoffAction.updateEnabledState();
108 upAction.updateEnabledState();
109 downAction.updateEnabledState();
110 }
111 });
112 cbWireframe.addActionListener(new ActionListener() {
113 public void actionPerformed(ActionEvent e) {
114 Main.main.menu.wireFrameToggleAction.actionPerformed(null);
115 }
116 });
117 cbWireframe.setBorder(new EmptyBorder(new Insets(1,1,1,1)));
118
119 tblStyles = new StylesTable(model);
120 tblStyles.setSelectionModel(selectionModel= new DefaultListSelectionModel());
121 tblStyles.addMouseListener(new PopupMenuHandler());
122 tblStyles.putClientProperty("terminateEditOnFocusLost", true);
123 tblStyles.setBackground(UIManager.getColor("Panel.background"));
124 tblStyles.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
125 tblStyles.setTableHeader(null);
126 tblStyles.getColumnModel().getColumn(0).setMaxWidth(1);
127 tblStyles.getColumnModel().getColumn(0).setResizable(false);
128 tblStyles.getColumnModel().getColumn(0).setCellRenderer(new MyCheckBoxRenderer());
129 tblStyles.getColumnModel().getColumn(1).setCellRenderer(new StyleSourceRenderer());
130 tblStyles.setShowGrid(false);
131 tblStyles.setIntercellSpacing(new Dimension(0, 0));
132
133 JPanel p = new JPanel(new GridBagLayout());
134 p.add(cbWireframe, GBC.std(0, 0));
135 p.add(wfLabel, GBC.std(1, 0).weight(1, 0));
136 p.add(tblStyles, GBC.std(0, 1).span(2).fill());
137
138 pnl.add(new JScrollPane(p), BorderLayout.CENTER);
139
140 pnl.add(buildButtonRow(), BorderLayout.SOUTH);
141
142 add(pnl, BorderLayout.CENTER);
143 }
144
145 protected static class StylesTable extends JTable {
146
147 public StylesTable(TableModel dm) {
148 super(dm);
149 }
150
151 public void scrollToVisible(int row, int col) {
152 if (!(getParent() instanceof JViewport))
153 return;
154 JViewport viewport = (JViewport) getParent();
155 Rectangle rect = getCellRect(row, col, true);
156 Point pt = viewport.getViewPosition();
157 rect.setLocation(rect.x - pt.x, rect.y - pt.y);
158 viewport.scrollRectToVisible(rect);
159 }
160 }
161
162 protected JPanel buildButtonRow() {
163 JPanel p = getButtonPanel(4);
164 reloadAction = new ReloadAction();
165 onoffAction = new OnOffAction();
166 upAction = new MoveUpDownAction(false);
167 downAction = new MoveUpDownAction(true);
168 selectionModel.addListSelectionListener(onoffAction);
169 selectionModel.addListSelectionListener(reloadAction);
170 selectionModel.addListSelectionListener(upAction);
171 selectionModel.addListSelectionListener(downAction);
172 p.add(new SideButton(onoffAction));
173 p.add(new SideButton(upAction));
174 p.add(new SideButton(downAction));
175 p.add(new SideButton(new LaunchMapPaintPreferencesAction()));
176
177 return p;
178 }
179
180 @Override
181 public void showNotify() {
182 MapPaintStyles.addMapPaintSylesUpdateListener(model);
183 Main.main.menu.wireFrameToggleAction.addButtonModel(cbWireframe.getModel());
184 }
185
186 @Override
187 public void hideNotify() {
188 Main.main.menu.wireFrameToggleAction.removeButtonModel(cbWireframe.getModel());
189 MapPaintStyles.removeMapPaintSylesUpdateListener(model);
190 }
191
192 protected class StylesModel extends AbstractTableModel implements MapPaintSylesUpdateListener {
193
194 List<StyleSource> data = new ArrayList<StyleSource>();
195
196 public StylesModel() {
197 data = new ArrayList<StyleSource>(MapPaintStyles.getStyles().getStyleSources());
198 }
199
200 private StyleSource getRow(int i) {
201 return data.get(i);
202 }
203
204 @Override
205 public int getColumnCount() {
206 return 2;
207 }
208
209 @Override
210 public int getRowCount() {
211 return data.size();
212 }
213
214 @Override
215 public Object getValueAt(int row, int column) {
216 if (column == 0)
217 return getRow(row).active;
218 else
219 return getRow(row);
220 }
221
222 @Override
223 public boolean isCellEditable(int row, int column) {
224 return column == 0;
225 }
226
227 Class<?>[] columnClasses = {Boolean.class, StyleSource.class};
228
229 @Override
230 public Class<?> getColumnClass(int column) {
231 return columnClasses[column];
232 }
233
234 @Override
235 public void setValueAt(Object aValue, int row, int column) {
236 if (row < 0 || row >= getRowCount() || aValue == null)
237 return;
238 if (column == 0) {
239 MapPaintStyles.toggleStyleActive(row);
240 }
241 }
242
243 /**
244 * Make sure the first of the selected entry is visible in the
245 * views of this model.
246 */
247 public void ensureSelectedIsVisible() {
248 int index = selectionModel.getMinSelectionIndex();
249 if (index < 0) return;
250 if (index >= getRowCount()) return;
251 tblStyles.scrollToVisible(index, 0);
252 tblStyles.repaint();
253 }
254
255 /**
256 * MapPaintSylesUpdateListener interface
257 */
258
259 @Override
260 public void mapPaintStylesUpdated() {
261 data = new ArrayList<StyleSource>(MapPaintStyles.getStyles().getStyleSources());
262 fireTableDataChanged();
263 tblStyles.repaint();
264 }
265
266 @Override
267 public void mapPaintStyleEntryUpdated(int idx) {
268 data = new ArrayList<StyleSource>(MapPaintStyles.getStyles().getStyleSources());
269 fireTableRowsUpdated(idx, idx);
270 tblStyles.repaint();
271 }
272 }
273
274 private class MyCheckBoxRenderer extends JCheckBox implements TableCellRenderer {
275
276 public MyCheckBoxRenderer() {
277 setHorizontalAlignment(SwingConstants.CENTER);
278 setVerticalAlignment(SwingConstants.CENTER);
279 }
280
281 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,int row,int column) {
282 if (value == null)
283 return this;
284 boolean b = (Boolean) value;
285 setSelected(b);
286 setEnabled(!cbWireframe.isSelected());
287 return this;
288 }
289 }
290
291 private class StyleSourceRenderer extends DefaultTableCellRenderer {
292 @Override
293 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
294 if (value == null)
295 return this;
296 StyleSource s = (StyleSource) value;
297 JLabel label = (JLabel)super.getTableCellRendererComponent(table,
298 s.getDisplayString(), isSelected, hasFocus, row, column);
299 label.setIcon(s.getIcon());
300 label.setToolTipText(s.getToolTipText());
301 label.setEnabled(!cbWireframe.isSelected());
302 return label;
303 }
304 }
305
306 protected class OnOffAction extends AbstractAction implements ListSelectionListener {
307 public OnOffAction() {
308 putValue(SHORT_DESCRIPTION, tr("Turn selected styles on or off"));
309 putValue(SMALL_ICON, ImageProvider.get("apply"));
310 updateEnabledState();
311 }
312
313 protected void updateEnabledState() {
314 setEnabled(!cbWireframe.isSelected() && tblStyles.getSelectedRowCount() > 0);
315 }
316
317 @Override
318 public void valueChanged(ListSelectionEvent e) {
319 updateEnabledState();
320 }
321
322 @Override
323 public void actionPerformed(ActionEvent e) {
324 int[] pos = tblStyles.getSelectedRows();
325 MapPaintStyles.toggleStyleActive(pos);
326 selectionModel.clearSelection();
327 for (int p: pos) {
328 selectionModel.addSelectionInterval(p, p);
329 }
330 }
331 }
332
333 /**
334 * The action to move down the currently selected entries in the list.
335 */
336 protected class MoveUpDownAction extends AbstractAction implements ListSelectionListener {
337
338 final int increment;
339
340 public MoveUpDownAction(boolean isDown) {
341 increment = isDown ? 1 : -1;
342 putValue(SMALL_ICON, isDown ? ImageProvider.get("dialogs", "down") : ImageProvider.get("dialogs", "up"));
343 putValue(SHORT_DESCRIPTION, isDown ? tr("Move the selected entry one row down.") : tr("Move the selected entry one row up."));
344 updateEnabledState();
345 }
346
347 public void updateEnabledState() {
348 int[] sel = tblStyles.getSelectedRows();
349 setEnabled(!cbWireframe.isSelected() && MapPaintStyles.canMoveStyles(sel, increment));
350 }
351
352 @Override
353 public void actionPerformed(ActionEvent e) {
354 int[] sel = tblStyles.getSelectedRows();
355 MapPaintStyles.moveStyles(sel, increment);
356
357 selectionModel.clearSelection();
358 for (int row: sel) {
359 selectionModel.addSelectionInterval(row + increment, row + increment);
360 }
361 model.ensureSelectedIsVisible();
362 }
363
364 public void valueChanged(ListSelectionEvent e) {
365 updateEnabledState();
366 }
367 }
368
369 /**
370 * Opens preferences window and selects the mappaint tab.
371 */
372 class LaunchMapPaintPreferencesAction extends AbstractAction {
373 public LaunchMapPaintPreferencesAction() {
374 putValue(SMALL_ICON, ImageProvider.get("dialogs", "mappaintpreference"));
375 }
376
377 @Override
378 public void actionPerformed(ActionEvent e) {
379 final PreferenceDialog p =new PreferenceDialog(Main.parent);
380 p.selectMapPaintPreferenceTab();
381 p.setVisible(true);
382 }
383 }
384
385 protected class ReloadAction extends AbstractAction implements ListSelectionListener {
386 public ReloadAction() {
387 putValue(NAME, tr("Reload from file"));
388 putValue(SHORT_DESCRIPTION, tr("reload selected styles from file"));
389 putValue(SMALL_ICON, ImageProvider.get("dialogs", "refresh"));
390 setEnabled(getEnabledState());
391 }
392
393 protected boolean getEnabledState() {
394 if (cbWireframe.isSelected())
395 return false;
396 int[] pos = tblStyles.getSelectedRows();
397 if (pos.length == 0)
398 return false;
399 for (int i : pos) {
400 if (!model.getRow(i).isLocal())
401 return false;
402 }
403 return true;
404 }
405
406 @Override
407 public void valueChanged(ListSelectionEvent e) {
408 setEnabled(getEnabledState());
409 }
410
411 @Override
412 public void actionPerformed(ActionEvent e) {
413 final int[] rows = tblStyles.getSelectedRows();
414 MapPaintStyles.reloadStyles(rows);
415 Main.worker.submit(new Runnable() {
416 @Override
417 public void run() {
418 SwingUtilities.invokeLater(new Runnable() {
419 @Override
420 public void run() {
421 selectionModel.clearSelection();
422 for (int r: rows) {
423 selectionModel.addSelectionInterval(r, r);
424 }
425 }
426 });
427
428 }
429 });
430 }
431 }
432
433 protected class SaveAsAction extends AbstractAction {
434
435 public SaveAsAction() {
436 putValue(NAME, tr("Save as..."));
437 putValue(SHORT_DESCRIPTION, tr("Save a copy of this Style to file and add it to the list"));
438 putValue(SMALL_ICON, ImageProvider.get("copy"));
439 setEnabled(tblStyles.getSelectedRows().length == 1);
440 }
441
442 @Override
443 public void actionPerformed(ActionEvent e) {
444 int sel = tblStyles.getSelectionModel().getLeadSelectionIndex();
445 if (sel < 0 || sel >= model.getRowCount())
446 return;
447 final StyleSource s = model.getRow(sel);
448
449 String curDir = Main.pref.get("mappaint.clone-style.lastDirectory", System.getProperty("user.home"));
450
451 String suggestion = curDir + File.separator + s.getFileNamePart();
452 JFileChooser fc = new JFileChooser();
453 fc.setSelectedFile(new File(suggestion));
454
455 int answer = fc.showSaveDialog(Main.parent);
456 if (answer != JFileChooser.APPROVE_OPTION)
457 return;
458
459 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) {
460 Main.pref.put("mappaint.clone-style.lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
461 }
462 File file = fc.getSelectedFile();
463
464 if (!SaveActionBase.confirmOverride(file))
465 return;
466
467 Main.worker.submit(new SaveToFileTask(s, file));
468 }
469
470 private class SaveToFileTask extends PleaseWaitRunnable {
471 private StyleSource s;
472 private File file;
473
474 private boolean canceled;
475 private boolean error;
476
477 public SaveToFileTask(StyleSource s, File file) {
478 super(tr("Reloading style sources"));
479 this.s = s;
480 this.file = file;
481 }
482
483 @Override
484 protected void cancel() {
485 canceled = true;
486 }
487
488 @Override
489 protected void realRun() {
490 getProgressMonitor().indeterminateSubTask(
491 tr("Save style ''{0}'' as ''{1}''", s.getDisplayString(), file.getPath()));
492 BufferedInputStream bis = null;
493 BufferedOutputStream bos = null;
494 try {
495 bis = new BufferedInputStream(s.getSourceInputStream());
496 bos = new BufferedOutputStream(new FileOutputStream(file));
497 byte[] buffer = new byte[4096];
498 int length;
499 while ((length = bis.read(buffer)) > -1 && !canceled) {
500 bos.write(buffer, 0, length);
501 }
502 } catch (IOException e) {
503 error = true;
504 } finally {
505 Utils.close(bis);
506 Utils.close(bos);
507 }
508 }
509
510 @Override
511 protected void finish() {
512 SwingUtilities.invokeLater(new Runnable() {
513 @Override
514 public void run() {
515 if (!error && !canceled) {
516 SourceEntry se = new SourceEntry(s);
517 se.url = file.getPath();
518 MapPaintStyles.addStyle(se);
519 tblStyles.getSelectionModel().setSelectionInterval(model.getRowCount() - 1 , model.getRowCount() - 1);
520 model.ensureSelectedIsVisible();
521 }
522 }
523 });
524 }
525 }
526 }
527
528 protected class InfoAction extends AbstractAction {
529
530 boolean errorsTabLoaded;
531 boolean sourceTabLoaded;
532
533 public InfoAction() {
534 putValue(NAME, tr("Info"));
535 putValue(SHORT_DESCRIPTION, tr("view meta information, error log and source definition"));
536 putValue(SMALL_ICON, ImageProvider.get("info"));
537 setEnabled(tblStyles.getSelectedRows().length == 1);
538 }
539
540 @Override
541 public void actionPerformed(ActionEvent e) {
542 int sel = tblStyles.getSelectionModel().getLeadSelectionIndex();
543 if (sel < 0 || sel >= model.getRowCount())
544 return;
545 final StyleSource s = model.getRow(sel);
546 ExtendedDialog info = new ExtendedDialog(Main.parent, tr("Map Style info"), new String[] {tr("Close")});
547 info.setPreferredSize(new Dimension(600, 400));
548 info.setButtonIcons(new String[] {"ok.png"});
549
550 final JTabbedPane tabs = new JTabbedPane();
551
552 tabs.add("Info", buildInfoPanel(s));
553 JLabel lblInfo = new JLabel(tr("Info"));
554 lblInfo.setFont(lblInfo.getFont().deriveFont(Font.PLAIN));
555 tabs.setTabComponentAt(0, lblInfo);
556
557 final JPanel pErrors = new JPanel(new GridBagLayout());
558 tabs.add("Errors", pErrors);
559 JLabel lblErrors;
560 if (s.getErrors().isEmpty()) {
561 lblErrors = new JLabel(tr("Errors"));
562 lblErrors.setFont(lblInfo.getFont().deriveFont(Font.PLAIN));
563 lblErrors.setEnabled(false);
564 tabs.setTabComponentAt(1, lblErrors);
565 tabs.setEnabledAt(1, false);
566 } else {
567 lblErrors = new JLabel(tr("Errors"), ImageProvider.get("misc", "error"), JLabel.HORIZONTAL);
568 tabs.setTabComponentAt(1, lblErrors);
569 }
570
571 final JPanel pSource = new JPanel(new GridBagLayout());
572 tabs.addTab("Source", pSource);
573 JLabel lblSource = new JLabel(tr("Source"));
574 lblSource.setFont(lblSource.getFont().deriveFont(Font.PLAIN));
575 tabs.setTabComponentAt(2, lblSource);
576
577 tabs.getModel().addChangeListener(new ChangeListener() {
578 @Override
579 public void stateChanged(ChangeEvent e) {
580 if (!errorsTabLoaded && ((SingleSelectionModel) e.getSource()).getSelectedIndex() == 1) {
581 errorsTabLoaded = true;
582 buildErrorsPanel(s, pErrors);
583 }
584 if (!sourceTabLoaded && ((SingleSelectionModel) e.getSource()).getSelectedIndex() == 2) {
585 sourceTabLoaded = true;
586 buildSourcePanel(s, pSource);
587 }
588 }
589 });
590 info.setContent(tabs, false);
591 info.showDialog();
592 }
593
594 private JPanel buildInfoPanel(StyleSource s) {
595 JPanel p = new JPanel(new GridBagLayout());
596 StringBuilder text = new StringBuilder("<table cellpadding=3>");
597 text.append(tableRow(tr("Title:"), s.getDisplayString()));
598 if (s.url.startsWith("http://")) {
599 text.append(tableRow(tr("URL:"), s.url));
600 } else if (s.url.startsWith("resource://")) {
601 text.append(tableRow(tr("Built-in Style, internal path:"), s.url));
602 } else {
603 text.append(tableRow(tr("Path:"), s.url));
604 }
605 if (s.icon != null) {
606 text.append(tableRow(tr("Icon:"), s.icon));
607 }
608 if (s.getBackgroundColorOverride() != null) {
609 text.append(tableRow(tr("Background:"), Utils.toString(s.getBackgroundColorOverride())));
610 }
611 text.append(tableRow(tr("Style is currently active?"), s.active ? tr("Yes") : tr("No")));
612 text.append("</table>");
613 p.add(new JScrollPane(new HtmlPanel(text.toString())), GBC.eol().fill(GBC.BOTH));
614 return p;
615 }
616
617 private String tableRow(String firstColumn, String secondColumn) {
618 return "<tr><td><b>" + firstColumn + "</b></td><td>" + secondColumn + "</td></tr>";
619 }
620
621 private void buildSourcePanel(StyleSource s, JPanel p) {
622 JTextArea txtSource = new JTextArea();
623 txtSource.setFont(new Font("Monospaced", txtSource.getFont().getStyle(), txtSource.getFont().getSize()));
624 txtSource.setEditable(false);
625 p.add(new JScrollPane(txtSource), GBC.std().fill());
626
627 InputStream is = null;
628 try {
629 is = s.getSourceInputStream();
630 BufferedReader reader = new BufferedReader(new InputStreamReader(is));
631 String line;
632 while ((line = reader.readLine()) != null) {
633 txtSource.append(line + "\n");
634 }
635 } catch (IOException ex) {
636 txtSource.append("<ERROR: failed to read file!>");
637 } finally {
638 Utils.close(is);
639 }
640 }
641
642 private void buildErrorsPanel(StyleSource s, JPanel p) {
643 JTextArea txtErrors = new JTextArea();
644 txtErrors.setFont(new Font("Monospaced", txtErrors.getFont().getStyle(), txtErrors.getFont().getSize()));
645 txtErrors.setEditable(false);
646 p.add(new JScrollPane(txtErrors), GBC.std().fill());
647 for (Throwable t : s.getErrors()) {
648 txtErrors.append(t.toString() + "\n");
649 }
650 }
651 }
652
653 class PopupMenuHandler extends PopupMenuLauncher {
654 @Override
655 public void launch(MouseEvent evt) {
656 if (cbWireframe.isSelected())
657 return;
658 Point p = evt.getPoint();
659 int index = tblStyles.rowAtPoint(p);
660 if (index < 0) return;
661 if (!tblStyles.getCellRect(index, 1, false).contains(evt.getPoint()))
662 return;
663 if (!tblStyles.isRowSelected(index)) {
664 tblStyles.setRowSelectionInterval(index, index);
665 }
666 MapPaintPopup menu = new MapPaintPopup();
667 menu.show(tblStyles, p.x, p.y);
668 }
669 }
670
671 public class MapPaintPopup extends JPopupMenu {
672 public MapPaintPopup() {
673 add(reloadAction);
674 add(new SaveAsAction());
675 addSeparator();
676 add(new InfoAction());
677 }
678 }
679}
Note: See TracBrowser for help on using the repository browser.