20 package net.sf.gridarta.gui.panel.selectedsquare;
22 import java.awt.BorderLayout;
23 import java.awt.Color;
24 import java.awt.Container;
25 import java.awt.FlowLayout;
26 import java.awt.GridLayout;
27 import java.awt.Insets;
28 import java.awt.Point;
29 import java.awt.event.InputEvent;
30 import java.awt.event.MouseAdapter;
31 import java.awt.event.MouseEvent;
32 import java.awt.event.MouseListener;
33 import java.awt.geom.RectangularShape;
35 import javax.swing.AbstractButton;
36 import javax.swing.Action;
37 import javax.swing.DefaultListModel;
38 import javax.swing.Icon;
39 import javax.swing.ImageIcon;
40 import javax.swing.JButton;
41 import javax.swing.JLabel;
42 import javax.swing.JList;
43 import javax.swing.JPanel;
44 import javax.swing.JScrollPane;
45 import javax.swing.JViewport;
46 import javax.swing.ListSelectionModel;
47 import javax.swing.ScrollPaneConstants;
48 import javax.swing.event.ListSelectionListener;
68 import org.jetbrains.annotations.NotNull;
69 import org.jetbrains.annotations.Nullable;
121 private final DefaultListModel<G>
model =
new DefaultListModel<>();
133 private final Container
arrows =
new JPanel();
155 public void mapSizeChanged(@NotNull
final Size2D newSize) {
167 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
179 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
184 public void modifiedChanged() {
197 public void activeMapViewChanged(@Nullable
final MapView<G, A, R> mapView) {
200 if (mapView ==
null) {
204 mapModel = mapView.getMapControl().getMapModel();
243 public void mapCursorChangedPos(@NotNull
final Point location) {
248 public void mapCursorChangedMode() {
253 public void mapCursorChangedGameObject(@Nullable
final MapSquare<G, A, R> mapSquare, @Nullable
final G gameObject) {
260 public void mapCursorChangedSize() {
274 public void mousePressed(
final MouseEvent e) {
276 if (e.getClickCount() > 1) {
278 if (gameObject !=
null) {
306 public SelectedSquareView(@NotNull
final SelectedSquareModel<G, A, R> selectedSquareModel, @NotNull
final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory, @NotNull
final ObjectChooser<G, A, R> objectChooser, @NotNull
final MapViewManager<G, A, R> mapViewManager, @NotNull
final MapViewSettings mapViewSettings, @Nullable
final ImageIcon compassIcon, @NotNull
final FaceObjectProviders faceObjectProviders, @NotNull
final Icon unknownSquareIcon, @NotNull
final Action... actions) {
312 setLayout(
new BorderLayout());
316 list.setBackground(Color.lightGray);
317 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
318 final JScrollPane scrollPane =
new JScrollPane(
list);
319 scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
320 scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
321 add(scrollPane, BorderLayout.CENTER);
323 for (
final Action tmpAction : actions) {
324 final AbstractButton button =
new JButton(tmpAction);
325 button.setMargin(
new Insets(0, 0, 0, 0));
330 if (compassIcon !=
null) {
331 final Container compass =
new JPanel();
332 compass.add(
new JLabel(compassIcon));
333 add(compass, BorderLayout.NORTH);
337 list.setFocusable(
false);
351 if (mapSquareListBottom) {
352 arrows.setLayout(
new GridLayout(4, 1));
353 add(
arrows, BorderLayout.WEST);
355 arrows.setLayout(
new FlowLayout());
356 add(
arrows, BorderLayout.SOUTH);
369 final int lastIndex =
model.getSize() - 1;
374 final RectangularShape bounds =
list.getCellBounds(lastIndex, lastIndex);
375 final int lowestY = (int) (bounds.getY() + bounds.getHeight());
376 if ((
int) e.getPoint().getY() >= lowestY) {
377 return lastIndex + 1;
380 final int listIndex =
list.locationToIndex(e.getPoint());
381 assert listIndex >= 0;
391 list.setEnabled(
false);
395 list.setEnabled(
true);
407 return actualIndex >=
model.getSize() ? null :
model.getElementAt(actualIndex);
417 if (
list.getSelectedIndex() != actualIndex) {
418 list.setSelectedIndex(actualIndex);
435 final int size =
model.getSize();
436 return index < size ? index : Math.max(0, size - 1);
445 if (mapCursor !=
null && index <
model.getSize()) {
457 if (gameObject !=
null) {
459 if (mapCursor !=
null) {
471 private static boolean isSelect(@NotNull
final InputEvent e) {
472 return (e.getModifiers() & InputEvent.BUTTON1_MASK) != 0;
480 private static boolean isInsert(@NotNull
final InputEvent e) {
481 return (e.getModifiers() & (InputEvent.BUTTON3_MASK | InputEvent.CTRL_MASK)) == InputEvent.BUTTON3_MASK;
489 private static boolean isDelete(@NotNull
final InputEvent e) {
490 return (e.getModifiers() & InputEvent.BUTTON2_MASK) != 0 || (e.getModifiers() & (InputEvent.BUTTON3_MASK | InputEvent.CTRL_MASK)) == (InputEvent.BUTTON3_MASK | InputEvent.CTRL_MASK);
494 if (this.mapModel !=
null) {
498 if (this.mapModel !=
null) {
502 if (this.mapCursor !=
null) {
506 if (this.mapCursor !=
null) {