/** * Ajusta el tamaño de la ventana al envelope pasado como parámetro * * @param ctx * @param newWrapperEnvelope * @param viewport */ public static void resizeViewToEnvelope( PlugInContext ctx, Envelope newWrapperEnvelope, IViewport viewport) { // ajustamos las proporciones de la ventana a las de la feature JInternalFrame activeInternalFrame = ctx.getActiveInternalFrame(); Dimension dimView = ((Dimension) ctx.getLayerViewPanel()).getSize(); Double widthView = dimView.getWidth(); Double heightView = dimView.getHeight(); int widthDiff = (int) (activeInternalFrame.getWidth() - widthView); int heightDiff = (int) (activeInternalFrame.getHeight() - heightView); Integer newWidth = (int) ((newWrapperEnvelope.getWidth() / viewport.getEnvelopeInModelCoordinates().getWidth()) * widthView); Integer newHeight = (int) ((newWrapperEnvelope.getHeight() / viewport.getEnvelopeInModelCoordinates().getHeight()) * heightView); Dimension newDimensionView = new Dimension(newWidth + widthDiff, newHeight + heightDiff); activeInternalFrame.setSize(newDimensionView); // zoom al envelope actual try { viewport.zoom(newWrapperEnvelope); } catch (NoninvertibleTransformException e) { log.warn("No se ha podido alcanzar el zoom " + newWrapperEnvelope); } }
private void cascata(JInternalFrame jIFrame, JInternalFrame jIFrameAnt) { if (dPane.getAllFrames().length > 0) { if (autoManager) { maxX = dPane.getWidth() - jIFrame.getWidth(); maxY = dPane.getHeight() - jIFrame.getHeight(); minX = 0; minY = 0; } if (jIFrameAnt.getY() < maxY) { y = jIFrameAnt.getY() + distanceXY; } else { y = minY; } if (jIFrameAnt.getX() < maxX) { x = jIFrameAnt.getX() + distanceXY; } else { x = minX; y = minY; } } else { x = minX; y = minY; } }
public void centrarFrm(JInternalFrame hijo, VistaMDI padre) { hijo.setLocation( padre.getWidth() / 2 - hijo.getWidth() / 2, padre.getHeight() / 2 - hijo.getHeight() / 2 - 20); // CENTRA EL FORMULARIO }
public Object showWindow(final MkWindow macWindow, String title, boolean isModal) { listMkWindow.add(macWindow); if (isModal) { JDialog modalFrame = new JDialog(this, title, true); // macWindow.setJanela(modalFrame); final MkRun onCloseWindow = macWindow.onCloseWindow; modalFrame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE); modalFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { if (onCloseWindow != null) { onCloseWindow.execute(); } disposeWindow(macWindow); } }); modalFrame.setLayout(new BorderLayout()); modalFrame.add(macWindow, BorderLayout.CENTER); modalFrame.pack(); Dimension desktopSize = desktopPane.getSize(); int x = (desktopSize.width - modalFrame.getWidth()) / 2; int y = (desktopSize.height - modalFrame.getHeight()) / 2; modalFrame.setLocation((x < 0 ? 0 : x), (y < 0 ? 0 : y)); if (macWindow.panelButton != null) { modalFrame.getRootPane().setDefaultButton((JButton) macWindow.panelButton.getComponent(0)); } modalFrame.setVisible(true); return modalFrame; } else { JInternalFrame internalFrame = new JInternalFrame(title, true, true, true, true); internalFrame.setContentPane(macWindow); internalFrame.pack(); // internalFrame.setBounds(internalFrame.getBounds()); //pq? desktopPane.add(internalFrame); internalFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); final MkRun onCloseWindow = macWindow.onCloseWindow; if (onCloseWindow != null) { internalFrame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE); internalFrame.addInternalFrameListener( new InternalFrameAdapter() { public void internalFrameClosing(InternalFrameEvent e) { onCloseWindow.execute(); } }); } Dimension desktopSize = desktopPane.getSize(); int x = (desktopSize.width - internalFrame.getWidth()) / 2; int y = (desktopSize.height - internalFrame.getHeight()) / 2; internalFrame.setLocation((x < 0 ? 0 : x), (y < 0 ? 0 : y)); internalFrame.setVisible(true); return internalFrame; } }
public void loadFrameConfiguration() { jif.setBounds( pref.getInt(jif.getTitle() + posXPreferenceKey, jif.getX()), pref.getInt(jif.getTitle() + posYPreferenceKey, jif.getY()), pref.getInt(jif.getTitle() + sizeXPreferenceKey, jif.getWidth()), pref.getInt(jif.getTitle() + sizeYPreferenceKey, jif.getHeight())); try { jif.setVisible(pref.getBoolean(jif.getTitle() + isVisiblePreferenceKey, true)); } catch (Exception e) { System.err.println("failed setting JInternalFrame to visible/invisible"); e.printStackTrace(); } }
// aqui se añade los internalframe al destop pane private void agregarMarcoInterno(JInternalFrame marco) { marco.setLocation(xSigMarco, ySigMarco); marco.setVisible(true); jDesktopPane.add(marco); try { marco.setSelected(true); } catch (PropertyVetoException ex) { } if (distanciaEntreMarcos == 0) distanciaEntreMarcos = marco.getHeight() - marco.getContentPane().getHeight(); xSigMarco += distanciaEntreMarcos; ySigMarco += distanciaEntreMarcos; if (xSigMarco + marco.getWidth() > jDesktopPane.getWidth()) xSigMarco = 0; if (ySigMarco + marco.getHeight() > jDesktopPane.getHeight()) ySigMarco = 0; }
private void saveSettings() { if (localSettings != null) { localSettings.objectDirectory = levelHolder.getPalette().getDirectoryPath(); localSettings.mainWidth = this.getWidth(); localSettings.mainHeight = this.getHeight(); localSettings.paletteX = palette.getX(); localSettings.paletteY = palette.getY(); localSettings.paletteWidth = palette.getWidth(); localSettings.paletteHeight = palette.getHeight(); localSettings.levelHolderX = levelHolderFrame.getX(); localSettings.levelHolderY = levelHolderFrame.getY(); localSettings.levelHolderWidth = levelHolderFrame.getWidth(); localSettings.levelHolderHeight = levelHolderFrame.getHeight(); localSettings.store(); } else { localSettings = new LocalSettings(); } }
/** * Sets the location for the 3 internal frames * * @author susiefu * @param direction * @param tilt * @param x * @param y */ protected void setFrameGeometry(String direction, int tilt, int x, int y) { Dimension editwindowsize = editFrame.getSize(); Dimension trisize = triangleFrame.getSize(); int tribase = (Math.round((Math.min(editwindowsize.width, editwindowsize.height))) / 10 > 15) ? Math.round((Math.min(editwindowsize.width, editwindowsize.height))) / 10 : 15; // How // wide // the // base // of // the // triangle // is int fudge = 1; // For the different directions if (direction == "SE") { // Default location if (tilt == 0) { triangleFrame.setLocation(x + tribase - trisize.width, y + 24 - trisize.height + fudge); } else { triangleFrame.setLocation(x, y + 24 - trisize.height + fudge); } } else if (direction == "S") { // SAME AS "SE" DIRECTION if (tilt == 0) { triangleFrame.setLocation(x + tribase - trisize.width, y + 24 - trisize.height + fudge); } else { triangleFrame.setLocation(x, y + 24 - trisize.height + fudge); } } else if (direction == "W") { if (tilt == 0) { triangleFrame.setLocation( x + editwindowsize.width - fudge, y + 24 - trisize.height + tribase); } else { triangleFrame.setLocation(x + editwindowsize.width - fudge, y + 24); } } else if (direction == "NW") { if (tilt == 0) { triangleFrame.setLocation( x + editwindowsize.width - trisize.width, y + 24 + editwindowsize.height - 2 * fudge); } else { triangleFrame.setLocation( x + editwindowsize.width - tribase, y + 25 + editwindowsize.height - 2 * fudge); } } else if (direction == "N") { if (tilt == 0) { triangleFrame.setLocation( x - trisize.width + tribase, y + 24 + editwindowsize.height - 2 * fudge); } else { triangleFrame.setLocation(x, y + 24 + editwindowsize.height - 2 * fudge); } } else if (direction == "E") { if (tilt == 0) { // Pointing up triangleFrame.setLocation(x - trisize.width + fudge, y + 24 - trisize.height + tribase); } else { triangleFrame.setLocation(x - trisize.width + fudge, y + 24); } } else if (direction == "NONE") { if (tilt == 0) { triangleFrame.setLocation(x + tribase - trisize.width, y + 24 - trisize.height + fudge); } else { triangleFrame.setLocation(x, y + 24 - trisize.height + fudge); } } editFrame.setLocation(x, y + 24); buttonFrame.setLocation( x + editwindowsize.width - buttonFrame.getWidth() + fudge, y + buttonFrame.getHeight() / 2 + fudge * 2); }
/** * Will update the triangle given the absolute location of the center of the moveButton. * * @author achang, adapted from code by susiefu */ public void updateTriangle(int x, int y) { Point realLocation = new Point(x, y); Dimension editFrameSize = editFrame.getSize(); Point editFrameLocation = editFrame.getLocation(); // new Point(realLocation.x - editFrameSize.width + buttonFrame.getWidth()*3/4, // realLocation.y + buttonFrame.getHeight()/2); int X_FUDGE = 15; int Y_FUDGE = 5; int tribase = (Math.round((Math.min(editFrameSize.width, editFrameSize.height))) / 10 > TRIANGLE_BASE) ? Math.round((Math.min(editFrameSize.width, editFrameSize.height))) / 10 : TRIANGLE_BASE; int tilt = -1; int cellX = getCellCenter().x; int cellY = getCellCenter().y; // System.out.println("kCW >> updateTriangle >> cellCenter="+getCellCenter()); int width, height; if (editFrameLocation.x + editFrameSize.width / 2 >= cellX && editFrameLocation.x - X_FUDGE <= cellX && editFrameLocation.y >= cellY) { // Right , bottom (DEFAULT) direction = "SE"; height = editFrameLocation.y - cellY; if (editFrameLocation.x >= cellX) { tilt = 0; // Pointing left width = Math.abs(editFrameLocation.x - cellX) + tribase; } else { tilt = 1; // Pointing right if (Math.abs(editFrameLocation.x - cellX) > tribase) { width = Math.abs(editFrameLocation.x - cellX); } else { width = tribase; } } } else if (editFrameLocation.x + editFrameSize.width / 2 < cellX && editFrameLocation.x + editFrameSize.width > cellX && editFrameLocation.y >= cellY + Y_FUDGE) { // Middle, // bottom direction = "S"; // SAME CODE AS "SE" DIRECTION BECAUSE OF OVERLAPPING // OF BUTTONS AND TRIANGLE height = editFrameLocation.y - cellY; if (editFrameLocation.x >= cellX) { tilt = 0; // Pointing left width = Math.abs(editFrameLocation.x - cellX) + tribase; } else { tilt = 1; // Pointing right if (Math.abs(editFrameLocation.x - cellX) > tribase) { width = Math.abs(editFrameLocation.x - cellX); } else { width = tribase; } } } else if (editFrameLocation.x + editFrameSize.width <= cellX && editFrameLocation.y + editFrameSize.height + 3 * Y_FUDGE >= cellY || editFrameLocation.x + 3 * editFrameSize.width / 2 < cellX && editFrameLocation.y + editFrameSize.height < cellY) { // Left, middle direction = "W"; width = Math.abs(editFrameLocation.x + editFrameSize.width - cellX); if (editFrameLocation.y >= cellY) { tilt = 0; // Pointing up height = Math.abs(editFrameLocation.y - cellY) + tribase; } else { tilt = 1; // Pointing down if (Math.abs(editFrameLocation.y - cellY) > tribase) { height = Math.abs(editFrameLocation.y - cellY); } else { height = tribase; } } } else if (editFrameLocation.x + editFrameSize.width / 2 <= cellX && editFrameLocation.x + 3 * editFrameSize.width / 2 >= cellX && editFrameLocation.y + editFrameSize.height + 3 * Y_FUDGE < cellY) { // Left, // top direction = "NW"; height = Math.abs(editFrameLocation.y + editFrameSize.height - cellY); if (editFrameLocation.x + editFrameSize.width > cellX) { tilt = 0; // Pointing left if (Math.abs(editFrameLocation.x + editFrameSize.width - cellX) > tribase) { width = Math.abs(editFrameLocation.x + editFrameSize.width - cellX); } else { width = tribase; } } else { tilt = 1; // Pointing right width = Math.abs(editFrameLocation.x + editFrameSize.width - cellX) + tribase; } } else if (editFrameLocation.x + editFrameSize.width / 2 > cellX && editFrameLocation.x - editFrameSize.width / 2 <= cellX && editFrameLocation.y + editFrameSize.height + Y_FUDGE < cellY) { // Middle, // top direction = "N"; height = Math.abs(editFrameLocation.y + editFrameSize.height - cellY); if (editFrameLocation.x >= cellX) { tilt = 0; // Pointing left width = Math.abs(editFrameLocation.x - cellX) + tribase; } else { tilt = 1; // Pointing right if (Math.abs(editFrameLocation.x - cellX) > tribase) { width = Math.abs(editFrameLocation.x - cellX); } else { width = tribase; } } } else if (editFrameLocation.x - X_FUDGE > cellX || editFrameLocation.y - editFrameSize.height / 2 >= cellY && editFrameLocation.x - X_FUDGE <= cellX) { // Right, middle direction = "E"; width = Math.abs(editFrameLocation.x - cellX); if (editFrameLocation.y >= cellY) { tilt = 0; // Pointing up height = Math.abs(editFrameLocation.y - cellY) + tribase; } else { tilt = 1; // Pointing down if (Math.abs(editFrameLocation.y - cellY) > tribase) { height = Math.abs(editFrameLocation.y - cellY); } else { height = tribase; } } } else { direction = "NONE"; height = editFrameLocation.y - cellY; if (editFrameLocation.x >= cellX) { tilt = 0; width = Math.abs(editFrameLocation.x - cellX) + tribase; } else { tilt = 1; if (Math.abs(editFrameLocation.x - cellX) > tribase) { width = Math.abs(editFrameLocation.x - cellX); } else { width = tribase; } } } triangleFrame.setSize(width, height); ((Triangle) triangleFrame.getContentPane()) .setGeometry(direction, tilt, width, height, tribase); setFrameGeometry( direction, tilt, realLocation.x - editFrameSize.width + buttonFrame.getWidth() * 3 / 4, realLocation.y - buttonFrame.getWidth() / 2); }
/** * Will update the triangle assuming that the cell center has moved but that the edit window and * button panel has not. * * @author achang */ public void updateTriangle() { Point buttonLocation = buttonFrame.getLocation(); updateTriangle( buttonFrame.getWidth() / 4 + buttonLocation.x, buttonFrame.getHeight() / 2 + buttonLocation.y); }