Ticket #2311: template_visualization.patch
File template_visualization.patch, 10.1 KB (added by tanya, 15 years ago) |
---|
-
src/main/java/org/sophie2/main/app/layout/left/pages/PagePreviewPaletteLogic.java
### Eclipse Workspace Patch 1.0 #P org.sophie2.main.app.layout
1 1 package org.sophie2.main.app.layout.left.pages; 2 2 3 import java.awt.Point; 3 4 import java.awt.Rectangle; 4 5 6 import javax.swing.JList; 7 8 import org.sophie2.base.commons.util.ImmList; 5 9 import org.sophie2.base.commons.util.position.ImmArea; 6 10 import org.sophie2.base.commons.util.position.ImmPoint; 7 11 import org.sophie2.base.commons.util.position.ImmRect; … … 150 154 }, 151 155 152 156 /** 153 * Handles pre-importing template data in drag'n'drop operation. 157 * Handles dropping a page template over the {@link PagePreviewPalette}. 158 * Applies the template to the page over which it was dropped or creates a new page 159 * if it was dropped over the blank space between page items. 154 160 */ 155 161 ON_DND_PRE_IMPORT_TEMPLATE { 156 162 … … 169 175 } 170 176 171 177 public boolean handle(EventR3 event) { 172 178 173 179 PagePreviewPalette palette = event.getSource(PagePreviewPalette.class); 174 180 BookView bookView = AppViewUtil.getCurrentBookView(palette); 175 181 if (bookView.getViewOptions().isPreviewMode()) { … … 203 209 204 210 if (innerRect.contains(point)) { 205 211 212 palette.removeSeparators(); 213 206 214 MainPageView mainPageView = pageItem.pageView().get().mainPartView().get(); 207 215 208 216 ImmRect rect = new ImmRect (ImmPoint.ZERO, book.getPageSize()); … … 219 227 220 228 CreatePageByTemplateHandler handler = CreatePageByTemplateHandler.get(); 221 229 handler.setView(pageItem.pageView().get().mainPartView().get()); 222 if (topPaddingRect.contains(point)) { 230 if (topPaddingRect.contains(point)) { 231 223 232 // a page should be inserted before the current pageItem 224 233 handler.setAfter(false); 234 235 palette.visualizeSeparators(index, true); 225 236 } else { 226 237 assert bottomPaddingRect.contains(point) || !bounds.contains(point.toPoint()); 227 238 228 239 // a page should be inserted after the current pageItem 229 240 handler.setAfter(true); 241 242 palette.visualizeSeparators(index, false); 230 243 } 231 244 232 245 preImport.setHandler(handler); … … 238 251 /** 239 252 * Handles pre-importing a page in a drag'n'drop operation. 240 253 */ 241 ON_DND_P RE_IMPORT_PAGE{254 ON_DND_PAGE_REORDER { 242 255 243 256 public void defineFilter(EventFilterBuilder filter) { 244 257 filter.setSourceClass(PagePreviewPalette.class); … … 262 275 ImmPoint.class); 263 276 264 277 PagePreviewPalette palette = event.getSource(PagePreviewPalette.class); 265 finalint dropIndex = palette.mainComponent().get().locationToIndex(point.toPoint());278 int dropIndex = palette.mainComponent().get().locationToIndex(point.toPoint()); 266 279 267 280 BookH book = AppViewUtil.getCurrentBook(palette); 268 281 final int dragIndex = book.getIndexOf(data.getResourceRef()); … … 271 284 return false; 272 285 } 273 286 274 RootPageView pageView = palette.items().get().get(dropIndex).pageView().get(); 287 288 JList list = palette.mainComponent().get(); 289 290 Point dropPoint = point.toPoint(); 291 Rectangle dropRect = list.getCellBounds(dropIndex, dropIndex); 292 293 double dropPos = dropPoint.getY(); 294 double rectBegin = dropRect.getY(); 295 double rectEnd = dropRect.getY() + dropRect.getHeight(); 296 297 if (rectEnd - dropPos < dropPos - rectBegin) { 298 dropIndex++; 299 } 300 301 ImmList<PageItem> items = palette.items().get(); 302 303 palette.removeSeparators(); 304 305 int index = dropIndex; 306 boolean north = true; 307 if (dropIndex == items.size()) { 308 index = dropIndex - 1; 309 north = false; 310 } 311 palette.visualizeSeparators(index , north); 312 313 palette.mainComponent().get().validate(); 314 palette.mainComponent().get().repaint(); 315 316 317 if (dragIndex < dropIndex) { 318 dropIndex--; 319 } 320 321 RootPageView pageView = items.get(dropIndex).pageView().get(); 275 322 PageReorderHandler handler = PageReorderHandler.get(); 276 323 handler.setView(pageView); 277 324 preImport.setHandler(handler); -
src/main/java/org/sophie2/main/app/layout/right/library/CreatePageByTemplateHandler.java
6 6 import org.sophie2.main.app.commons.book.BookView; 7 7 import org.sophie2.main.app.commons.element.ElementDropHandler; 8 8 import org.sophie2.main.app.commons.page.MainPageView; 9 import org.sophie2.main.app.layout.left.pages.PagePreviewPalette; 9 10 import org.sophie2.main.dnd.TemplateRefData; 10 11 11 12 /** … … 79 80 } 80 81 81 82 bookView.addNewPage(index, templateRef); 83 84 PagePreviewPalette palette = getView().findNearestElement(null, PagePreviewPalette.class); 85 palette.removeSeparators(); 82 86 } 83 87 88 @Override 89 public void handleExit() { 90 if (getView() != null) { 91 PagePreviewPalette palette = getView().findNearestElement(null, 92 PagePreviewPalette.class); 93 94 palette.removeSeparators(); 95 } 96 } 84 97 85 98 86 99 } -
src/main/java/org/sophie2/main/app/layout/left/pages/PagePreviewPalette.java
1 1 package org.sophie2.main.app.layout.left.pages; 2 2 3 import java.awt.BorderLayout; 3 4 import java.awt.event.KeyEvent; 4 5 import java.util.HashMap; 5 6 import java.util.Map; … … 177 178 public PageItem(RootPageView pageView) { 178 179 getBean().init(pageView(), pageView); 179 180 this.result.setName(getElementId() + "/thumbnailHolder"); 181 this.rollOverPanelSouth.setName(getElementId() + "/thumbnailHolder"); 182 this.rollOverPanelNorth.setName(getElementId() + "/thumbnailHolder"); 180 183 } 181 184 182 185 private JPanel centerPanel = new JPanel(); … … 184 187 185 188 private PageThumbnail thumbnail = new PageThumbnail(); 186 189 190 /** 191 * These panel are used to be set at the north and at the south part of the result panel. 192 * When skinned, they play the role of separators. 193 */ 194 private JPanel rollOverPanelNorth = new JPanel(); 195 private JPanel rollOverPanelSouth = new JPanel(); 196 197 198 /** 199 * Used for skinning of the north and the south panels of the 200 * {@link PageItem}. 201 * 202 * @param name 203 * The name to be set for the skin. 204 * @param north 205 * Boolean parameter to indicate if north or south panel 206 * should be skinned. If <b>true</b> the north panel should 207 * be skinned, otherwise the south one. 208 */ 209 @SuppressWarnings("synthetic-access") 210 public void setSkinIcon(String name, Boolean north) { 211 if (north) { 212 this.rollOverPanelNorth.setName(getElementId() + name); 213 } else { 214 this.rollOverPanelSouth.setName(getElementId() + name); 215 } 216 } 217 187 218 @Override 188 219 public JPanel render() { 189 220 190 221 this.centerPanel.removeAll(); 191 222 this.result.removeAll(); 192 223 this.thumbnail.removeAll(); 224 this.rollOverPanelSouth.removeAll(); 225 this.rollOverPanelNorth.removeAll(); 193 226 194 227 BaseScene scene = new BaseScene(); 195 228 RootPageView pageView = pageView().get(); … … 208 241 this.centerPanel.add(this.thumbnail); 209 242 JLabel pageNumberLabel = new JLabel("" + pageNumber); 210 243 this.centerPanel.add(pageNumberLabel); 211 this.result.add(this.centerPanel); 244 this.result.setLayout(new BorderLayout()); 245 246 JPanel tmp = new JPanel(); 247 tmp.add(this.centerPanel); 248 this.result.add(tmp, BorderLayout.CENTER); 249 this.result.add(this.rollOverPanelSouth, BorderLayout.SOUTH); 250 this.result.add(this.rollOverPanelNorth, BorderLayout.NORTH); 212 251 } 213 252 } 214 253 return this.result; … … 463 502 } 464 503 } 465 504 505 /** 506 * Removes the separators between {@link PageItem}s in drag'n'drop operation. 507 */ 508 public void removeSeparators() { 509 for (ListPaletteItem listItem : this.items().get()) { 510 PageItem item = (PageItem) listItem; 511 item.setSkinIcon("/thumbnailHolder", false); 512 item.setSkinIcon("/thumbnailHolder", true); 513 } 514 } 515 516 /** 517 * Visualizes separator between {@link PageItem}s in drag'n'drop operation. 518 * 519 * @param index 520 * The index of {@link PageItem} over which is mouse cursor is. 521 * @param before 522 * Define whether separator before the item should be visualized 523 * or not. If it is <b>false</b>, then the separator before the 524 * next item will be visualized. 525 */ 526 public void visualizeSeparators(int index, boolean before) { 527 528 int size = this.items().get().size(); 529 530 PageItem pageItem = null; 531 boolean north; 532 if (before) { 533 pageItem = this.items().get().get(index); 534 north = true; 535 } else if (index < size - 1) { 536 pageItem = this.items().get().get(index + 1); 537 north = true; 538 } else { 539 pageItem = this.items().get().get(index); 540 north = false; 541 } 542 543 pageItem.setSkinIcon("/thumbnailDragOver", north); 544 } 545 546 466 547 @Own 467 548 private Prop<LogicR3Button> removePageButton() { 468 549 class removePageButton extends AutoProperty<LogicR3Button> { -
src/main/java/org/sophie2/main/app/layout/left/pages/PageReorderHandler.java
55 55 } 56 56 57 57 }.register(book.getAccess()); 58 59 PagePreviewPalette palette = getView().findNearestElement(null, PagePreviewPalette.class); 60 palette.removeSeparators(); 61 } 62 63 @Override 64 public void handleExit() { 65 if (getView() != null) { 66 PagePreviewPalette palette = getView().findNearestElement(null, 67 PagePreviewPalette.class); 68 palette.removeSeparators(); 69 } 58 70 } 59 71 }